Commit | Line | Data |
---|---|---|
284f4730 | 1 | /* Keyboard and mouse input; editor command loop. |
d925fb39 | 2 | Copyright (C) 1985,86,87,88,89,93,94,95,96,97 Free Software Foundation, Inc. |
284f4730 JB |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
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 | |
7b4aedb9 | 8 | the Free Software Foundation; either version 2, or (at your option) |
284f4730 JB |
9 | any later version. |
10 | ||
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. | |
15 | ||
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 | |
3b7ad313 EN |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
284f4730 JB |
20 | |
21 | /* Allow config.h to undefine symbols found here. */ | |
22 | #include <signal.h> | |
23 | ||
18160b98 | 24 | #include <config.h> |
284f4730 | 25 | #include <stdio.h> |
284f4730 JB |
26 | #include "termchar.h" |
27 | #include "termopts.h" | |
28 | #include "lisp.h" | |
29 | #include "termhooks.h" | |
30 | #include "macros.h" | |
ff11dfa1 | 31 | #include "frame.h" |
284f4730 JB |
32 | #include "window.h" |
33 | #include "commands.h" | |
34 | #include "buffer.h" | |
37cd9f30 | 35 | #include "charset.h" |
284f4730 | 36 | #include "disptab.h" |
f4255cd1 | 37 | #include "dispextern.h" |
284f4730 | 38 | #include "keyboard.h" |
497ba7a1 | 39 | #include "intervals.h" |
9ac0d9e0 | 40 | #include "blockinput.h" |
284f4730 JB |
41 | #include <setjmp.h> |
42 | #include <errno.h> | |
43 | ||
80e4aa30 RS |
44 | #ifdef MSDOS |
45 | #include "msdos.h" | |
46 | #include <time.h> | |
47 | #else /* not MSDOS */ | |
284f4730 JB |
48 | #ifndef VMS |
49 | #include <sys/ioctl.h> | |
284f4730 | 50 | #endif |
80e4aa30 | 51 | #endif /* not MSDOS */ |
284f4730 | 52 | |
52baf19e | 53 | #include "syssignal.h" |
6ef5b54f | 54 | #include "systty.h" |
52baf19e | 55 | |
c5e3b6c5 RS |
56 | /* This is to get the definitions of the XK_ symbols. */ |
57 | #ifdef HAVE_X_WINDOWS | |
58 | #include "xterm.h" | |
59 | #endif | |
60 | ||
e98a93eb GV |
61 | #ifdef HAVE_NTGUI |
62 | #include "w32term.h" | |
63 | #endif /* HAVE_NTGUI */ | |
64 | ||
0c2611c5 RS |
65 | /* Include systime.h after xterm.h to avoid double inclusion of time.h. */ |
66 | #include "systime.h" | |
67 | ||
52baf19e JB |
68 | extern int errno; |
69 | ||
9ac0d9e0 JB |
70 | /* Variables for blockinput.h: */ |
71 | ||
72 | /* Non-zero if interrupt input is blocked right now. */ | |
63927c41 | 73 | int interrupt_input_blocked; |
9ac0d9e0 JB |
74 | |
75 | /* Nonzero means an input interrupt has arrived | |
76 | during the current critical section. */ | |
63927c41 | 77 | int interrupt_input_pending; |
9ac0d9e0 JB |
78 | |
79 | ||
437f6112 RS |
80 | /* File descriptor to use for input. */ |
81 | extern int input_fd; | |
284f4730 | 82 | |
e98a93eb | 83 | #ifdef HAVE_WINDOW_SYSTEM |
284f4730 JB |
84 | /* Make all keyboard buffers much bigger when using X windows. */ |
85 | #define KBD_BUFFER_SIZE 4096 | |
86 | #else /* No X-windows, character input */ | |
87 | #define KBD_BUFFER_SIZE 256 | |
88 | #endif /* No X-windows */ | |
89 | ||
90 | /* Following definition copied from eval.c */ | |
91 | ||
92 | struct backtrace | |
93 | { | |
94 | struct backtrace *next; | |
95 | Lisp_Object *function; | |
96 | Lisp_Object *args; /* Points to vector of args. */ | |
97 | int nargs; /* length of vector. If nargs is UNEVALLED, | |
98 | args points to slot holding list of | |
99 | unevalled args */ | |
100 | char evalargs; | |
101 | }; | |
102 | ||
c5fdd383 KH |
103 | #ifdef MULTI_KBOARD |
104 | KBOARD *initial_kboard; | |
105 | KBOARD *current_kboard; | |
106 | KBOARD *all_kboards; | |
1e8bd3da | 107 | int single_kboard; |
6c6083a9 | 108 | #else |
c5fdd383 | 109 | KBOARD the_only_kboard; |
6c6083a9 | 110 | #endif |
612b78ef | 111 | |
284f4730 JB |
112 | /* Non-nil disable property on a command means |
113 | do not execute it; call disabled-command-hook's value instead. */ | |
2e894dab | 114 | Lisp_Object Qdisabled, Qdisabled_command_hook; |
284f4730 JB |
115 | |
116 | #define NUM_RECENT_KEYS (100) | |
117 | int recent_keys_index; /* Index for storing next element into recent_keys */ | |
118 | int total_keys; /* Total number of elements stored into recent_keys */ | |
5160df46 | 119 | Lisp_Object recent_keys; /* A vector, holding the last 100 keystrokes */ |
284f4730 | 120 | |
6569cc8d JB |
121 | /* Vector holding the key sequence that invoked the current command. |
122 | It is reused for each command, and it may be longer than the current | |
123 | sequence; this_command_key_count indicates how many elements | |
124 | actually mean something. | |
125 | It's easier to staticpro a single Lisp_Object than an array. */ | |
126 | Lisp_Object this_command_keys; | |
127 | int this_command_key_count; | |
284f4730 | 128 | |
6321824f RS |
129 | /* Number of elements of this_command_keys |
130 | that precede this key sequence. */ | |
131 | int this_single_command_key_start; | |
132 | ||
71918b75 RS |
133 | /* Record values of this_command_key_count and echo_length () |
134 | before this command was read. */ | |
135 | static int before_command_key_count; | |
136 | static int before_command_echo_length; | |
137 | /* Values of before_command_key_count and before_command_echo_length | |
138 | saved by reset-this-command-lengths. */ | |
139 | static int before_command_key_count_1; | |
140 | static int before_command_echo_length_1; | |
141 | /* Flag set by reset-this-command-lengths, | |
142 | saying to reset the lengths when add_command_key is called. */ | |
143 | static int before_command_restore_flag; | |
144 | ||
284f4730 JB |
145 | extern int minbuf_level; |
146 | ||
a59b172a RS |
147 | extern int message_enable_multibyte; |
148 | ||
284f4730 JB |
149 | extern struct backtrace *backtrace_list; |
150 | ||
151 | /* Nonzero means do menu prompting. */ | |
152 | static int menu_prompting; | |
153 | ||
154 | /* Character to see next line of menu prompt. */ | |
155 | static Lisp_Object menu_prompt_more_char; | |
156 | ||
157 | /* For longjmp to where kbd input is being done. */ | |
158 | static jmp_buf getcjmp; | |
159 | ||
160 | /* True while doing kbd input. */ | |
161 | int waiting_for_input; | |
162 | ||
163 | /* True while displaying for echoing. Delays C-g throwing. */ | |
164 | static int echoing; | |
165 | ||
1fc93d49 RS |
166 | /* True means we can start echoing at the next input pause |
167 | even though there is something in the echo area. */ | |
0c04a67e | 168 | static char *ok_to_echo_at_next_pause; |
1fc93d49 | 169 | |
03361bcc RS |
170 | /* Nonzero means disregard local maps for the menu bar. */ |
171 | static int inhibit_local_menu_bar_menus; | |
172 | ||
80e4aa30 | 173 | /* Nonzero means C-g should cause immediate error-signal. */ |
284f4730 JB |
174 | int immediate_quit; |
175 | ||
fa90970d RS |
176 | /* The user's ERASE setting. */ |
177 | Lisp_Object Vtty_erase_char; | |
178 | ||
284f4730 | 179 | /* Character to recognize as the help char. */ |
7e85b935 | 180 | Lisp_Object Vhelp_char; |
284f4730 | 181 | |
ecb7cb34 KH |
182 | /* List of other event types to recognize as meaning "help". */ |
183 | Lisp_Object Vhelp_event_list; | |
184 | ||
284f4730 JB |
185 | /* Form to execute when help char is typed. */ |
186 | Lisp_Object Vhelp_form; | |
187 | ||
7e85b935 RS |
188 | /* Command to run when the help character follows a prefix key. */ |
189 | Lisp_Object Vprefix_help_command; | |
190 | ||
9f9c0e27 RS |
191 | /* List of items that should move to the end of the menu bar. */ |
192 | Lisp_Object Vmenu_bar_final_items; | |
a73c5e29 | 193 | |
6526ab49 RS |
194 | /* Non-nil means show the equivalent key-binding for |
195 | any M-x command that has one. | |
196 | The value can be a length of time to show the message for. | |
197 | If the value is non-nil and not a number, we wait 2 seconds. */ | |
198 | Lisp_Object Vsuggest_key_bindings; | |
199 | ||
284f4730 JB |
200 | /* Character that causes a quit. Normally C-g. |
201 | ||
202 | If we are running on an ordinary terminal, this must be an ordinary | |
203 | ASCII char, since we want to make it our interrupt character. | |
204 | ||
205 | If we are not running on an ordinary terminal, it still needs to be | |
206 | an ordinary ASCII char. This character needs to be recognized in | |
207 | the input interrupt handler. At this point, the keystroke is | |
208 | represented as a struct input_event, while the desired quit | |
209 | character is specified as a lispy event. The mapping from struct | |
210 | input_events to lispy events cannot run in an interrupt handler, | |
211 | and the reverse mapping is difficult for anything but ASCII | |
212 | keystrokes. | |
213 | ||
214 | FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an | |
215 | ASCII character. */ | |
216 | int quit_char; | |
217 | ||
218 | extern Lisp_Object current_global_map; | |
219 | extern int minibuf_level; | |
220 | ||
9dd3131c RS |
221 | /* If non-nil, this is a map that overrides all other local maps. */ |
222 | Lisp_Object Voverriding_local_map; | |
223 | ||
d0a49716 RS |
224 | /* If non-nil, Voverriding_local_map applies to the menu bar. */ |
225 | Lisp_Object Voverriding_local_map_menu_flag; | |
226 | ||
7f07d5ca RS |
227 | /* Keymap that defines special misc events that should |
228 | be processed immediately at a low level. */ | |
229 | Lisp_Object Vspecial_event_map; | |
230 | ||
284f4730 JB |
231 | /* Current depth in recursive edits. */ |
232 | int command_loop_level; | |
233 | ||
234 | /* Total number of times command_loop has read a key sequence. */ | |
235 | int num_input_keys; | |
236 | ||
237 | /* Last input character read as a command. */ | |
238 | Lisp_Object last_command_char; | |
239 | ||
7d6de002 RS |
240 | /* Last input character read as a command, not counting menus |
241 | reached by the mouse. */ | |
242 | Lisp_Object last_nonmenu_event; | |
243 | ||
284f4730 JB |
244 | /* Last input character read for any purpose. */ |
245 | Lisp_Object last_input_char; | |
246 | ||
dbc4e1c1 | 247 | /* If not Qnil, a list of objects to be read as subsequent command input. */ |
24597608 | 248 | Lisp_Object Vunread_command_events; |
284f4730 | 249 | |
86e5706b RS |
250 | /* If not -1, an event to be read as subsequent command input. */ |
251 | int unread_command_char; | |
252 | ||
cd21b839 JB |
253 | /* If not Qnil, this is a switch-frame event which we decided to put |
254 | off until the end of a key sequence. This should be read as the | |
dbc4e1c1 | 255 | next command input, after any unread_command_events. |
8f805655 JB |
256 | |
257 | read_key_sequence uses this to delay switch-frame events until the | |
258 | end of the key sequence; Fread_char uses it to put off switch-frame | |
259 | events until a non-ASCII event is acceptable as input. */ | |
260 | Lisp_Object unread_switch_frame; | |
cd21b839 | 261 | |
9fa4395d RS |
262 | /* A mask of extra modifier bits to put into every keyboard char. */ |
263 | int extra_keyboard_modifiers; | |
264 | ||
284f4730 JB |
265 | /* Char to use as prefix when a meta character is typed in. |
266 | This is bound on entry to minibuffer in case ESC is changed there. */ | |
267 | ||
268 | Lisp_Object meta_prefix_char; | |
269 | ||
270 | /* Last size recorded for a current buffer which is not a minibuffer. */ | |
271 | static int last_non_minibuf_size; | |
272 | ||
06ef7355 | 273 | /* Number of idle seconds before an auto-save and garbage collection. */ |
284f4730 JB |
274 | static Lisp_Object Vauto_save_timeout; |
275 | ||
276 | /* Total number of times read_char has returned. */ | |
4abfba1f | 277 | int num_input_events; |
284f4730 | 278 | |
51172b6d | 279 | /* Total number of times read_char has returned, outside of macros. */ |
c43b1734 | 280 | int num_nonmacro_input_events; |
51172b6d | 281 | |
284f4730 JB |
282 | /* Auto-save automatically when this many characters have been typed |
283 | since the last time. */ | |
284 | ||
285 | static int auto_save_interval; | |
286 | ||
c43b1734 | 287 | /* Value of num_nonmacro_input_events as of last auto save. */ |
284f4730 JB |
288 | |
289 | int last_auto_save; | |
290 | ||
284f4730 | 291 | /* The command being executed by the command loop. |
6c7178b9 KH |
292 | Commands may set this, and the value set will be copied into |
293 | current_kboard->Vlast_command instead of the actual command. */ | |
284f4730 JB |
294 | Lisp_Object this_command; |
295 | ||
b453f72e KH |
296 | /* The value of point when the last command was executed. */ |
297 | int last_point_position; | |
298 | ||
047688cb RS |
299 | /* The buffer that was current when the last command was started. */ |
300 | Lisp_Object last_point_position_buffer; | |
301 | ||
4c52b668 KH |
302 | /* The frame in which the last input event occurred, or Qmacro if the |
303 | last event came from a macro. We use this to determine when to | |
304 | generate switch-frame events. This may be cleared by functions | |
305 | like Fselect_frame, to make sure that a switch-frame event is | |
306 | generated by the next character. */ | |
307 | Lisp_Object internal_last_event_frame; | |
4c52b668 KH |
308 | |
309 | /* A user-visible version of the above, intended to allow users to | |
310 | figure out where the last event came from, if the event doesn't | |
311 | carry that information itself (i.e. if it was a character). */ | |
312 | Lisp_Object Vlast_event_frame; | |
313 | ||
1113d9db JB |
314 | /* The timestamp of the last input event we received from the X server. |
315 | X Windows wants this for selection ownership. */ | |
284f4730 JB |
316 | unsigned long last_event_timestamp; |
317 | ||
318 | Lisp_Object Qself_insert_command; | |
319 | Lisp_Object Qforward_char; | |
320 | Lisp_Object Qbackward_char; | |
e58aa385 | 321 | Lisp_Object Qundefined; |
d925fb39 | 322 | Lisp_Object Qtimer_event_handler; |
284f4730 JB |
323 | |
324 | /* read_key_sequence stores here the command definition of the | |
325 | key sequence that it reads. */ | |
326 | Lisp_Object read_key_sequence_cmd; | |
327 | ||
328 | /* Form to evaluate (if non-nil) when Emacs is started. */ | |
329 | Lisp_Object Vtop_level; | |
330 | ||
331 | /* User-supplied string to translate input characters through. */ | |
332 | Lisp_Object Vkeyboard_translate_table; | |
333 | ||
334 | /* Keymap mapping ASCII function key sequences onto their preferred forms. */ | |
335 | extern Lisp_Object Vfunction_key_map; | |
336 | ||
e0301c07 RS |
337 | /* Another keymap that maps key sequences into key sequences. |
338 | This one takes precedence over ordinary definitions. */ | |
339 | extern Lisp_Object Vkey_translation_map; | |
a612e298 | 340 | |
86e5706b RS |
341 | /* Non-nil means deactivate the mark at end of this command. */ |
342 | Lisp_Object Vdeactivate_mark; | |
343 | ||
48e416d4 RS |
344 | /* Menu bar specified in Lucid Emacs fashion. */ |
345 | ||
346 | Lisp_Object Vlucid_menu_bar_dirty_flag; | |
347 | Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook; | |
348 | ||
cdb9d665 RS |
349 | Lisp_Object Qecho_area_clear_hook; |
350 | ||
86e5706b | 351 | /* Hooks to run before and after each command. */ |
59aadc81 RS |
352 | Lisp_Object Qpre_command_hook, Vpre_command_hook; |
353 | Lisp_Object Qpost_command_hook, Vpost_command_hook; | |
40932d1a | 354 | Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal; |
59aadc81 RS |
355 | /* Hook run after a command if there's no more input soon. */ |
356 | Lisp_Object Qpost_command_idle_hook, Vpost_command_idle_hook; | |
357 | ||
358 | /* Delay time in microseconds before running post-command-idle-hook. */ | |
359 | int post_command_idle_delay; | |
86e5706b | 360 | |
8a792f3a RS |
361 | /* List of deferred actions to be performed at a later time. |
362 | The precise format isn't relevant here; we just check whether it is nil. */ | |
363 | Lisp_Object Vdeferred_action_list; | |
364 | ||
365 | /* Function to call to handle deferred actions, when there are any. */ | |
366 | Lisp_Object Vdeferred_action_function; | |
3ef14e46 | 367 | Lisp_Object Qdeferred_action_function; |
8a792f3a | 368 | |
284f4730 JB |
369 | /* File in which we write all commands we read. */ |
370 | FILE *dribble; | |
371 | ||
372 | /* Nonzero if input is available. */ | |
373 | int input_pending; | |
374 | ||
b04904fb RS |
375 | /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should |
376 | keep 0200 bit in input chars. 0 to ignore the 0200 bit. */ | |
377 | ||
284f4730 JB |
378 | int meta_key; |
379 | ||
380 | extern char *pending_malloc_warning; | |
381 | ||
beecf6a1 KH |
382 | /* Circular buffer for pre-read keyboard input. */ |
383 | static struct input_event kbd_buffer[KBD_BUFFER_SIZE]; | |
384 | ||
385 | /* Vector to GCPRO the frames and windows mentioned in kbd_buffer. | |
386 | ||
387 | The interrupt-level event handlers will never enqueue an event on a | |
388 | frame which is not in Vframe_list, and once an event is dequeued, | |
389 | internal_last_event_frame or the event itself points to the frame. | |
390 | So that's all fine. | |
391 | ||
392 | But while the event is sitting in the queue, it's completely | |
393 | unprotected. Suppose the user types one command which will run for | |
394 | a while and then delete a frame, and then types another event at | |
395 | the frame that will be deleted, before the command gets around to | |
396 | it. Suppose there are no references to this frame elsewhere in | |
397 | Emacs, and a GC occurs before the second event is dequeued. Now we | |
398 | have an event referring to a freed frame, which will crash Emacs | |
399 | when it is dequeued. | |
400 | ||
401 | Similar things happen when an event on a scroll bar is enqueued; the | |
402 | window may be deleted while the event is in the queue. | |
403 | ||
404 | So, we use this vector to protect the frame_or_window field in the | |
405 | event queue. That way, they'll be dequeued as dead frames or | |
406 | windows, but still valid lisp objects. | |
407 | ||
408 | If kbd_buffer[i].kind != no_event, then | |
409 | (XVECTOR (kbd_buffer_frame_or_window)->contents[i] | |
410 | == kbd_buffer[i].frame_or_window. */ | |
411 | static Lisp_Object kbd_buffer_frame_or_window; | |
412 | ||
413 | /* Pointer to next available character in kbd_buffer. | |
414 | If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty. | |
415 | This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the | |
416 | next available char is in kbd_buffer[0]. */ | |
417 | static struct input_event *kbd_fetch_ptr; | |
418 | ||
419 | /* Pointer to next place to store character in kbd_buffer. This | |
420 | may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next | |
421 | character should go in kbd_buffer[0]. */ | |
422 | static volatile struct input_event *kbd_store_ptr; | |
423 | ||
424 | /* The above pair of variables forms a "queue empty" flag. When we | |
425 | enqueue a non-hook event, we increment kbd_store_ptr. When we | |
426 | dequeue a non-hook event, we increment kbd_fetch_ptr. We say that | |
427 | there is input available iff the two pointers are not equal. | |
428 | ||
429 | Why not just have a flag set and cleared by the enqueuing and | |
430 | dequeuing functions? Such a flag could be screwed up by interrupts | |
431 | at inopportune times. */ | |
432 | ||
f3253854 | 433 | /* If this flag is non-nil, we check mouse_moved to see when the |
a9d77f1f RS |
434 | mouse moves, and motion events will appear in the input stream. |
435 | Otherwise, mouse motion is ignored. */ | |
436 | static Lisp_Object do_mouse_tracking; | |
284f4730 | 437 | |
284f4730 JB |
438 | /* Symbols to head events. */ |
439 | Lisp_Object Qmouse_movement; | |
3c370943 | 440 | Lisp_Object Qscroll_bar_movement; |
cd21b839 | 441 | Lisp_Object Qswitch_frame; |
bbdc2092 | 442 | Lisp_Object Qdelete_frame; |
af17bd2b KH |
443 | Lisp_Object Qiconify_frame; |
444 | Lisp_Object Qmake_frame_visible; | |
cd21b839 | 445 | |
284f4730 JB |
446 | /* Symbols to denote kinds of events. */ |
447 | Lisp_Object Qfunction_key; | |
448 | Lisp_Object Qmouse_click; | |
07de30b9 GV |
449 | #ifdef WINDOWSNT |
450 | Lisp_Object Qmouse_wheel; | |
451 | #endif | |
284f4730 | 452 | /* Lisp_Object Qmouse_movement; - also an event header */ |
284f4730 JB |
453 | |
454 | /* Properties of event headers. */ | |
455 | Lisp_Object Qevent_kind; | |
88cb0656 | 456 | Lisp_Object Qevent_symbol_elements; |
284f4730 | 457 | |
598a9fa7 JB |
458 | Lisp_Object Qmenu_enable; |
459 | ||
0a7f1fc0 JB |
460 | /* An event header symbol HEAD may have a property named |
461 | Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS); | |
462 | BASE is the base, unmodified version of HEAD, and MODIFIERS is the | |
463 | mask of modifiers applied to it. If present, this is used to help | |
464 | speed up parse_modifiers. */ | |
465 | Lisp_Object Qevent_symbol_element_mask; | |
466 | ||
467 | /* An unmodified event header BASE may have a property named | |
468 | Qmodifier_cache, which is an alist mapping modifier masks onto | |
469 | modified versions of BASE. If present, this helps speed up | |
470 | apply_modifiers. */ | |
471 | Lisp_Object Qmodifier_cache; | |
472 | ||
5ec75a55 | 473 | /* Symbols to use for parts of windows. */ |
284f4730 | 474 | Lisp_Object Qmode_line; |
e5d77022 | 475 | Lisp_Object Qvertical_line; |
3c370943 | 476 | Lisp_Object Qvertical_scroll_bar; |
5ec75a55 RS |
477 | Lisp_Object Qmenu_bar; |
478 | ||
479 | extern Lisp_Object Qmenu_enable; | |
284f4730 | 480 | |
f4255cd1 JB |
481 | Lisp_Object recursive_edit_unwind (), command_loop (); |
482 | Lisp_Object Fthis_command_keys (); | |
03b4122a | 483 | Lisp_Object Qextended_command_history; |
c04cbc3b | 484 | EMACS_TIME timer_check (); |
284f4730 | 485 | |
2c834fb3 KH |
486 | extern char *x_get_keysym_name (); |
487 | ||
8eb4d8ef RS |
488 | static void record_menu_key (); |
489 | ||
6e4e64a8 RS |
490 | void swallow_events (); |
491 | ||
f4eef8b4 RS |
492 | Lisp_Object Qpolling_period; |
493 | ||
d9d4c147 | 494 | /* List of absolute timers. Appears in order of next scheduled event. */ |
c04cbc3b RS |
495 | Lisp_Object Vtimer_list; |
496 | ||
d9d4c147 KH |
497 | /* List of idle time timers. Appears in order of next scheduled event. */ |
498 | Lisp_Object Vtimer_idle_list; | |
499 | ||
87dd9b9b RS |
500 | /* Incremented whenever a timer is run. */ |
501 | int timers_run; | |
502 | ||
a9f16aa9 KH |
503 | extern Lisp_Object Vprint_level, Vprint_length; |
504 | ||
e3ee7487 RS |
505 | extern nonascii_insert_offset; |
506 | ||
ffd56f97 JB |
507 | /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt |
508 | happens. */ | |
509 | EMACS_TIME *input_available_clear_time; | |
284f4730 JB |
510 | |
511 | /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode. | |
512 | Default is 1 if INTERRUPT_INPUT is defined. */ | |
513 | int interrupt_input; | |
514 | ||
515 | /* Nonzero while interrupts are temporarily deferred during redisplay. */ | |
516 | int interrupts_deferred; | |
517 | ||
87dd9b9b | 518 | /* Nonzero means use ^S/^Q for flow control. */ |
284f4730 JB |
519 | int flow_control; |
520 | ||
284f4730 JB |
521 | /* Allow m- file to inhibit use of FIONREAD. */ |
522 | #ifdef BROKEN_FIONREAD | |
523 | #undef FIONREAD | |
524 | #endif | |
525 | ||
526 | /* We are unable to use interrupts if FIONREAD is not available, | |
527 | so flush SIGIO so we won't try. */ | |
528 | #ifndef FIONREAD | |
529 | #ifdef SIGIO | |
530 | #undef SIGIO | |
531 | #endif | |
532 | #endif | |
533 | ||
e98a93eb | 534 | /* If we support a window system, turn on the code to poll periodically |
34f04431 | 535 | to detect C-g. It isn't actually used when doing interrupt input. */ |
e98a93eb | 536 | #ifdef HAVE_WINDOW_SYSTEM |
284f4730 JB |
537 | #define POLL_FOR_INPUT |
538 | #endif | |
284f4730 JB |
539 | \f |
540 | /* Global variable declarations. */ | |
541 | ||
542 | /* Function for init_keyboard to call with no args (if nonzero). */ | |
543 | void (*keyboard_init_hook) (); | |
544 | ||
545 | static int read_avail_input (); | |
546 | static void get_input_pending (); | |
9fd7d808 | 547 | static int readable_events (); |
8150596a RS |
548 | static Lisp_Object read_char_x_menu_prompt (); |
549 | static Lisp_Object read_char_minibuf_menu_prompt (); | |
a612e298 | 550 | static Lisp_Object make_lispy_event (); |
514354e9 | 551 | #ifdef HAVE_MOUSE |
a612e298 | 552 | static Lisp_Object make_lispy_movement (); |
514354e9 | 553 | #endif |
a612e298 RS |
554 | static Lisp_Object modify_event_symbol (); |
555 | static Lisp_Object make_lispy_switch_frame (); | |
3d31316f | 556 | static int parse_solitary_modifier (); |
284f4730 JB |
557 | |
558 | /* > 0 if we are to echo keystrokes. */ | |
559 | static int echo_keystrokes; | |
560 | ||
8026024c KH |
561 | /* Nonzero means don't try to suspend even if the operating system seems |
562 | to support it. */ | |
563 | static int cannot_suspend; | |
564 | ||
284f4730 JB |
565 | #define min(a,b) ((a)<(b)?(a):(b)) |
566 | #define max(a,b) ((a)>(b)?(a):(b)) | |
567 | ||
568 | /* Install the string STR as the beginning of the string of echoing, | |
569 | so that it serves as a prompt for the next character. | |
570 | Also start echoing. */ | |
571 | ||
572 | echo_prompt (str) | |
573 | char *str; | |
574 | { | |
575 | int len = strlen (str); | |
7a80a6f6 | 576 | |
ba72822c KH |
577 | if (len > ECHOBUFSIZE - 4) |
578 | len = ECHOBUFSIZE - 4; | |
c5fdd383 KH |
579 | bcopy (str, current_kboard->echobuf, len); |
580 | current_kboard->echoptr = current_kboard->echobuf + len; | |
581 | *current_kboard->echoptr = '\0'; | |
284f4730 | 582 | |
c5fdd383 | 583 | current_kboard->echo_after_prompt = len; |
7a80a6f6 | 584 | |
3dbd9ee4 | 585 | echo_now (); |
284f4730 JB |
586 | } |
587 | ||
df0f2ba1 | 588 | /* Add C to the echo string, if echoing is going on. |
284f4730 JB |
589 | C can be a character, which is printed prettily ("M-C-x" and all that |
590 | jazz), or a symbol, whose name is printed. */ | |
591 | ||
592 | echo_char (c) | |
593 | Lisp_Object c; | |
594 | { | |
595 | extern char *push_key_description (); | |
596 | ||
c5fdd383 | 597 | if (current_kboard->immediate_echo) |
284f4730 | 598 | { |
c5fdd383 | 599 | char *ptr = current_kboard->echoptr; |
df0f2ba1 | 600 | |
c5fdd383 | 601 | if (ptr != current_kboard->echobuf) |
284f4730 JB |
602 | *ptr++ = ' '; |
603 | ||
604 | /* If someone has passed us a composite event, use its head symbol. */ | |
88cb0656 | 605 | c = EVENT_HEAD (c); |
284f4730 | 606 | |
8c18cbfb | 607 | if (INTEGERP (c)) |
284f4730 | 608 | { |
c5fdd383 | 609 | if (ptr - current_kboard->echobuf > ECHOBUFSIZE - 6) |
284f4730 JB |
610 | return; |
611 | ||
cb5df6ae | 612 | ptr = push_key_description (XINT (c), ptr); |
284f4730 | 613 | } |
8c18cbfb | 614 | else if (SYMBOLP (c)) |
284f4730 JB |
615 | { |
616 | struct Lisp_String *name = XSYMBOL (c)->name; | |
c5fdd383 | 617 | if ((ptr - current_kboard->echobuf) + name->size + 4 > ECHOBUFSIZE) |
284f4730 JB |
618 | return; |
619 | bcopy (name->data, ptr, name->size); | |
620 | ptr += name->size; | |
621 | } | |
622 | ||
c5fdd383 | 623 | if (current_kboard->echoptr == current_kboard->echobuf |
ecb7cb34 | 624 | && help_char_p (c)) |
284f4730 JB |
625 | { |
626 | strcpy (ptr, " (Type ? for further options)"); | |
627 | ptr += strlen (ptr); | |
628 | } | |
629 | ||
630 | *ptr = 0; | |
c5fdd383 | 631 | current_kboard->echoptr = ptr; |
284f4730 | 632 | |
3dbd9ee4 | 633 | echo_now (); |
284f4730 JB |
634 | } |
635 | } | |
636 | ||
637 | /* Temporarily add a dash to the end of the echo string if it's not | |
638 | empty, so that it serves as a mini-prompt for the very next character. */ | |
639 | ||
640 | echo_dash () | |
641 | { | |
c5fdd383 KH |
642 | if (!current_kboard->immediate_echo |
643 | && current_kboard->echoptr == current_kboard->echobuf) | |
284f4730 | 644 | return; |
7a80a6f6 | 645 | /* Do nothing if we just printed a prompt. */ |
c5fdd383 KH |
646 | if (current_kboard->echo_after_prompt |
647 | == current_kboard->echoptr - current_kboard->echobuf) | |
7a80a6f6 | 648 | return; |
4bafa972 | 649 | /* Do nothing if not echoing at all. */ |
c5fdd383 | 650 | if (current_kboard->echoptr == 0) |
4bafa972 | 651 | return; |
284f4730 JB |
652 | |
653 | /* Put a dash at the end of the buffer temporarily, | |
654 | but make it go away when the next character is added. */ | |
c5fdd383 KH |
655 | current_kboard->echoptr[0] = '-'; |
656 | current_kboard->echoptr[1] = 0; | |
284f4730 | 657 | |
3dbd9ee4 | 658 | echo_now (); |
284f4730 JB |
659 | } |
660 | ||
661 | /* Display the current echo string, and begin echoing if not already | |
662 | doing so. */ | |
663 | ||
07a59269 | 664 | void |
3dbd9ee4 | 665 | echo_now () |
284f4730 | 666 | { |
c5fdd383 | 667 | if (!current_kboard->immediate_echo) |
284f4730 JB |
668 | { |
669 | int i; | |
c5fdd383 | 670 | current_kboard->immediate_echo = 1; |
284f4730 JB |
671 | |
672 | for (i = 0; i < this_command_key_count; i++) | |
d0a57728 RS |
673 | { |
674 | Lisp_Object c; | |
675 | c = XVECTOR (this_command_keys)->contents[i]; | |
676 | if (! (EVENT_HAS_PARAMETERS (c) | |
677 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_movement))) | |
678 | echo_char (c); | |
679 | } | |
284f4730 JB |
680 | echo_dash (); |
681 | } | |
682 | ||
683 | echoing = 1; | |
c5fdd383 | 684 | message1_nolog (current_kboard->echobuf); |
284f4730 JB |
685 | echoing = 0; |
686 | ||
687 | if (waiting_for_input && !NILP (Vquit_flag)) | |
688 | quit_throw_to_read_char (); | |
689 | } | |
690 | ||
691 | /* Turn off echoing, for the start of a new command. */ | |
692 | ||
693 | cancel_echoing () | |
694 | { | |
c5fdd383 KH |
695 | current_kboard->immediate_echo = 0; |
696 | current_kboard->echoptr = current_kboard->echobuf; | |
697 | current_kboard->echo_after_prompt = -1; | |
1fc93d49 | 698 | ok_to_echo_at_next_pause = 0; |
284f4730 JB |
699 | } |
700 | ||
701 | /* Return the length of the current echo string. */ | |
702 | ||
703 | static int | |
704 | echo_length () | |
705 | { | |
c5fdd383 | 706 | return current_kboard->echoptr - current_kboard->echobuf; |
284f4730 JB |
707 | } |
708 | ||
709 | /* Truncate the current echo message to its first LEN chars. | |
710 | This and echo_char get used by read_key_sequence when the user | |
ff11dfa1 | 711 | switches frames while entering a key sequence. */ |
284f4730 JB |
712 | |
713 | static void | |
714 | echo_truncate (len) | |
715 | int len; | |
716 | { | |
c5fdd383 KH |
717 | current_kboard->echobuf[len] = '\0'; |
718 | current_kboard->echoptr = current_kboard->echobuf + len; | |
40932d1a | 719 | truncate_echo_area (len); |
284f4730 JB |
720 | } |
721 | ||
722 | \f | |
723 | /* Functions for manipulating this_command_keys. */ | |
724 | static void | |
725 | add_command_key (key) | |
726 | Lisp_Object key; | |
727 | { | |
6569cc8d JB |
728 | int size = XVECTOR (this_command_keys)->size; |
729 | ||
71918b75 RS |
730 | /* If reset-this-command-length was called recently, obey it now. |
731 | See the doc string of that function for an explanation of why. */ | |
732 | if (before_command_restore_flag) | |
733 | { | |
734 | this_command_key_count = before_command_key_count_1; | |
6321824f RS |
735 | if (this_command_key_count < this_single_command_key_start) |
736 | this_single_command_key_start = this_command_key_count; | |
71918b75 RS |
737 | echo_truncate (before_command_echo_length_1); |
738 | before_command_restore_flag = 0; | |
739 | } | |
740 | ||
6569cc8d | 741 | if (this_command_key_count >= size) |
284f4730 | 742 | { |
9b8eb840 | 743 | Lisp_Object new_keys; |
6569cc8d | 744 | |
9b8eb840 | 745 | new_keys = Fmake_vector (make_number (size * 2), Qnil); |
6569cc8d JB |
746 | bcopy (XVECTOR (this_command_keys)->contents, |
747 | XVECTOR (new_keys)->contents, | |
8f805655 | 748 | size * sizeof (Lisp_Object)); |
6569cc8d JB |
749 | |
750 | this_command_keys = new_keys; | |
284f4730 | 751 | } |
6569cc8d JB |
752 | |
753 | XVECTOR (this_command_keys)->contents[this_command_key_count++] = key; | |
284f4730 JB |
754 | } |
755 | \f | |
756 | Lisp_Object | |
757 | recursive_edit_1 () | |
758 | { | |
759 | int count = specpdl_ptr - specpdl; | |
760 | Lisp_Object val; | |
761 | ||
762 | if (command_loop_level > 0) | |
763 | { | |
764 | specbind (Qstandard_output, Qt); | |
765 | specbind (Qstandard_input, Qt); | |
766 | } | |
767 | ||
768 | val = command_loop (); | |
769 | if (EQ (val, Qt)) | |
770 | Fsignal (Qquit, Qnil); | |
cb252880 RS |
771 | /* Handle throw from read_minibuf when using minibuffer |
772 | while it's active but we're in another window. */ | |
773 | if (STRINGP (val)) | |
774 | Fsignal (Qerror, Fcons (val, Qnil)); | |
284f4730 | 775 | |
cb5df6ae | 776 | return unbind_to (count, Qnil); |
284f4730 JB |
777 | } |
778 | ||
779 | /* When an auto-save happens, record the "time", and don't do again soon. */ | |
5846638c | 780 | |
07a59269 | 781 | void |
284f4730 JB |
782 | record_auto_save () |
783 | { | |
c43b1734 | 784 | last_auto_save = num_nonmacro_input_events; |
284f4730 | 785 | } |
5846638c RS |
786 | |
787 | /* Make an auto save happen as soon as possible at command level. */ | |
788 | ||
789 | force_auto_save_soon () | |
790 | { | |
791 | last_auto_save = - auto_save_interval - 1; | |
241ceaf7 RS |
792 | |
793 | record_asynch_buffer_change (); | |
5846638c | 794 | } |
284f4730 | 795 | \f |
284f4730 JB |
796 | DEFUN ("recursive-edit", Frecursive_edit, Srecursive_edit, 0, 0, "", |
797 | "Invoke the editor command loop recursively.\n\ | |
798 | To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\ | |
799 | that tells this function to return.\n\ | |
800 | Alternately, `(throw 'exit t)' makes this function signal an error.\n\ | |
801 | This function is called by the editor initialization to begin editing.") | |
802 | () | |
803 | { | |
804 | int count = specpdl_ptr - specpdl; | |
805 | Lisp_Object val; | |
806 | ||
807 | command_loop_level++; | |
808 | update_mode_lines = 1; | |
809 | ||
810 | record_unwind_protect (recursive_edit_unwind, | |
811 | (command_loop_level | |
812 | && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer)) | |
813 | ? Fcurrent_buffer () | |
814 | : Qnil); | |
815 | recursive_edit_1 (); | |
816 | return unbind_to (count, Qnil); | |
817 | } | |
818 | ||
819 | Lisp_Object | |
820 | recursive_edit_unwind (buffer) | |
821 | Lisp_Object buffer; | |
822 | { | |
823 | if (!NILP (buffer)) | |
824 | Fset_buffer (buffer); | |
825 | ||
826 | command_loop_level--; | |
827 | update_mode_lines = 1; | |
828 | return Qnil; | |
829 | } | |
830 | \f | |
604ccd1d | 831 | static void |
1e8bd3da | 832 | any_kboard_state () |
604ccd1d | 833 | { |
1e8bd3da RS |
834 | #ifdef MULTI_KBOARD |
835 | #if 0 /* Theory: if there's anything in Vunread_command_events, | |
836 | it will right away be read by read_key_sequence, | |
837 | and then if we do switch KBOARDS, it will go into the side | |
838 | queue then. So we don't need to do anything special here -- rms. */ | |
604ccd1d | 839 | if (CONSP (Vunread_command_events)) |
4524b161 | 840 | { |
c5fdd383 KH |
841 | current_kboard->kbd_queue |
842 | = nconc2 (Vunread_command_events, current_kboard->kbd_queue); | |
843 | current_kboard->kbd_queue_has_data = 1; | |
4524b161 | 844 | } |
604ccd1d | 845 | Vunread_command_events = Qnil; |
1e8bd3da RS |
846 | #endif |
847 | single_kboard = 0; | |
848 | #endif | |
604ccd1d | 849 | } |
1e8bd3da RS |
850 | |
851 | /* Switch to the single-kboard state, making current_kboard | |
852 | the only KBOARD from which further input is accepted. */ | |
853 | ||
854 | void | |
855 | single_kboard_state () | |
856 | { | |
857 | #ifdef MULTI_KBOARD | |
858 | single_kboard = 1; | |
604ccd1d | 859 | #endif |
1e8bd3da RS |
860 | } |
861 | ||
862 | /* Maintain a stack of kboards, so other parts of Emacs | |
863 | can switch temporarily to the kboard of a given frame | |
864 | and then revert to the previous status. */ | |
865 | ||
866 | struct kboard_stack | |
867 | { | |
868 | KBOARD *kboard; | |
869 | struct kboard_stack *next; | |
870 | }; | |
871 | ||
872 | static struct kboard_stack *kboard_stack; | |
873 | ||
874 | void | |
875 | push_frame_kboard (f) | |
876 | FRAME_PTR f; | |
877 | { | |
ab48365b | 878 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
879 | struct kboard_stack *p |
880 | = (struct kboard_stack *) xmalloc (sizeof (struct kboard_stack)); | |
881 | ||
882 | p->next = kboard_stack; | |
883 | p->kboard = current_kboard; | |
884 | kboard_stack = p; | |
885 | ||
886 | current_kboard = FRAME_KBOARD (f); | |
ab48365b | 887 | #endif |
1e8bd3da RS |
888 | } |
889 | ||
890 | void | |
891 | pop_frame_kboard () | |
892 | { | |
ab48365b | 893 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
894 | struct kboard_stack *p = kboard_stack; |
895 | current_kboard = p->kboard; | |
896 | kboard_stack = p->next; | |
897 | xfree (p); | |
ab48365b | 898 | #endif |
1e8bd3da RS |
899 | } |
900 | \f | |
901 | /* Handle errors that are not handled at inner levels | |
902 | by printing an error message and returning to the editor command loop. */ | |
604ccd1d | 903 | |
284f4730 JB |
904 | Lisp_Object |
905 | cmd_error (data) | |
906 | Lisp_Object data; | |
a1341f75 | 907 | { |
a9f16aa9 | 908 | Lisp_Object old_level, old_length; |
e881d8b2 RS |
909 | char macroerror[50]; |
910 | ||
911 | if (!NILP (executing_macro)) | |
912 | { | |
913 | if (executing_macro_iterations == 1) | |
914 | sprintf (macroerror, "After 1 kbd macro iteration: "); | |
915 | else | |
916 | sprintf (macroerror, "After %d kbd macro iterations: ", | |
917 | executing_macro_iterations); | |
918 | } | |
919 | else | |
920 | *macroerror = 0; | |
a9f16aa9 | 921 | |
a1341f75 RS |
922 | Vstandard_output = Qt; |
923 | Vstandard_input = Qt; | |
924 | Vexecuting_macro = Qnil; | |
9f58e89e | 925 | executing_macro = Qnil; |
d8bcf58e | 926 | current_kboard->Vprefix_arg = Qnil; |
df0f2ba1 | 927 | cancel_echoing (); |
a9f16aa9 KH |
928 | |
929 | /* Avoid unquittable loop if data contains a circular list. */ | |
930 | old_level = Vprint_level; | |
931 | old_length = Vprint_length; | |
0c04a67e RS |
932 | XSETFASTINT (Vprint_level, 10); |
933 | XSETFASTINT (Vprint_length, 10); | |
e881d8b2 | 934 | cmd_error_internal (data, macroerror); |
a9f16aa9 KH |
935 | Vprint_level = old_level; |
936 | Vprint_length = old_length; | |
a1341f75 RS |
937 | |
938 | Vquit_flag = Qnil; | |
939 | ||
940 | Vinhibit_quit = Qnil; | |
c5fdd383 | 941 | #ifdef MULTI_KBOARD |
1e8bd3da | 942 | any_kboard_state (); |
ff4b06d3 | 943 | #endif |
a1341f75 RS |
944 | |
945 | return make_number (0); | |
946 | } | |
947 | ||
07a59269 | 948 | void |
a1341f75 RS |
949 | cmd_error_internal (data, context) |
950 | Lisp_Object data; | |
951 | char *context; | |
284f4730 | 952 | { |
284f4730 | 953 | Lisp_Object stream; |
284f4730 JB |
954 | |
955 | Vquit_flag = Qnil; | |
956 | Vinhibit_quit = Qt; | |
284f4730 JB |
957 | echo_area_glyphs = 0; |
958 | ||
ff11dfa1 | 959 | /* If the window system or terminal frame hasn't been initialized |
284f4730 JB |
960 | yet, or we're not interactive, it's best to dump this message out |
961 | to stderr and exit. */ | |
ff11dfa1 | 962 | if (! FRAME_MESSAGE_BUF (selected_frame) |
284f4730 JB |
963 | || noninteractive) |
964 | stream = Qexternal_debugging_output; | |
965 | else | |
966 | { | |
967 | Fdiscard_input (); | |
968 | bitch_at_user (); | |
969 | stream = Qt; | |
970 | } | |
971 | ||
a1341f75 RS |
972 | if (context != 0) |
973 | write_string_1 (context, -1, stream); | |
974 | ||
22a51344 | 975 | print_error_message (data, stream); |
284f4730 | 976 | |
ff11dfa1 | 977 | /* If the window system or terminal frame hasn't been initialized |
284f4730 | 978 | yet, or we're in -batch mode, this error should cause Emacs to exit. */ |
ff11dfa1 | 979 | if (! FRAME_MESSAGE_BUF (selected_frame) |
284f4730 JB |
980 | || noninteractive) |
981 | { | |
982 | Fterpri (stream); | |
983 | Fkill_emacs (make_number (-1)); | |
984 | } | |
284f4730 JB |
985 | } |
986 | \f | |
987 | Lisp_Object command_loop_1 (); | |
988 | Lisp_Object command_loop_2 (); | |
989 | Lisp_Object top_level_1 (); | |
990 | ||
991 | /* Entry to editor-command-loop. | |
992 | This level has the catches for exiting/returning to editor command loop. | |
993 | It returns nil to exit recursive edit, t to abort it. */ | |
994 | ||
995 | Lisp_Object | |
996 | command_loop () | |
997 | { | |
998 | if (command_loop_level > 0 || minibuf_level > 0) | |
999 | { | |
1000 | return internal_catch (Qexit, command_loop_2, Qnil); | |
1001 | } | |
1002 | else | |
1003 | while (1) | |
1004 | { | |
1005 | internal_catch (Qtop_level, top_level_1, Qnil); | |
1006 | internal_catch (Qtop_level, command_loop_2, Qnil); | |
df0f2ba1 | 1007 | |
284f4730 JB |
1008 | /* End of file in -batch run causes exit here. */ |
1009 | if (noninteractive) | |
1010 | Fkill_emacs (Qt); | |
1011 | } | |
1012 | } | |
1013 | ||
1014 | /* Here we catch errors in execution of commands within the | |
1015 | editing loop, and reenter the editing loop. | |
1016 | When there is an error, cmd_error runs and returns a non-nil | |
1017 | value to us. A value of nil means that cmd_loop_1 itself | |
1018 | returned due to end of file (or end of kbd macro). */ | |
1019 | ||
1020 | Lisp_Object | |
1021 | command_loop_2 () | |
1022 | { | |
1023 | register Lisp_Object val; | |
1024 | ||
1025 | do | |
1026 | val = internal_condition_case (command_loop_1, Qerror, cmd_error); | |
1027 | while (!NILP (val)); | |
1028 | ||
1029 | return Qnil; | |
1030 | } | |
1031 | ||
1032 | Lisp_Object | |
1033 | top_level_2 () | |
1034 | { | |
1035 | return Feval (Vtop_level); | |
1036 | } | |
1037 | ||
1038 | Lisp_Object | |
1039 | top_level_1 () | |
1040 | { | |
1041 | /* On entry to the outer level, run the startup file */ | |
1042 | if (!NILP (Vtop_level)) | |
1043 | internal_condition_case (top_level_2, Qerror, cmd_error); | |
1044 | else if (!NILP (Vpurify_flag)) | |
1045 | message ("Bare impure Emacs (standard Lisp code not loaded)"); | |
1046 | else | |
1047 | message ("Bare Emacs (standard Lisp code not loaded)"); | |
1048 | return Qnil; | |
1049 | } | |
1050 | ||
1051 | DEFUN ("top-level", Ftop_level, Stop_level, 0, 0, "", | |
1052 | "Exit all recursive editing levels.") | |
1053 | () | |
1054 | { | |
1055 | Fthrow (Qtop_level, Qnil); | |
1056 | } | |
1057 | ||
1058 | DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, "", | |
1059 | "Exit from the innermost recursive edit or minibuffer.") | |
1060 | () | |
1061 | { | |
1062 | if (command_loop_level > 0 || minibuf_level > 0) | |
1063 | Fthrow (Qexit, Qnil); | |
1064 | ||
1065 | error ("No recursive edit is in progress"); | |
1066 | } | |
1067 | ||
1068 | DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0, 0, "", | |
1069 | "Abort the command that requested this recursive edit or minibuffer input.") | |
1070 | () | |
1071 | { | |
1072 | if (command_loop_level > 0 || minibuf_level > 0) | |
1073 | Fthrow (Qexit, Qt); | |
1074 | ||
1075 | error ("No recursive edit is in progress"); | |
1076 | } | |
1077 | \f | |
1078 | /* This is the actual command reading loop, | |
1079 | sans error-handling encapsulation. */ | |
1080 | ||
1081 | Lisp_Object Fcommand_execute (); | |
1082 | static int read_key_sequence (); | |
68f297c5 | 1083 | void safe_run_hooks (); |
284f4730 JB |
1084 | |
1085 | Lisp_Object | |
1086 | command_loop_1 () | |
1087 | { | |
48e416d4 | 1088 | Lisp_Object cmd, tem; |
37cd9f30 | 1089 | int lose, lose2; |
284f4730 JB |
1090 | int nonundocount; |
1091 | Lisp_Object keybuf[30]; | |
1092 | int i; | |
1093 | int no_redisplay; | |
1094 | int no_direct; | |
86e5706b RS |
1095 | int prev_modiff; |
1096 | struct buffer *prev_buffer; | |
c5fdd383 | 1097 | #ifdef MULTI_KBOARD |
1e8bd3da | 1098 | int was_locked = single_kboard; |
bded54dd | 1099 | #endif |
284f4730 | 1100 | |
d9b641bb | 1101 | current_kboard->Vprefix_arg = Qnil; |
86e5706b | 1102 | Vdeactivate_mark = Qnil; |
284f4730 | 1103 | waiting_for_input = 0; |
df0f2ba1 | 1104 | cancel_echoing (); |
284f4730 | 1105 | |
284f4730 JB |
1106 | nonundocount = 0; |
1107 | no_redisplay = 0; | |
1108 | this_command_key_count = 0; | |
6321824f | 1109 | this_single_command_key_start = 0; |
284f4730 | 1110 | |
a612e298 RS |
1111 | /* Make sure this hook runs after commands that get errors and |
1112 | throw to top level. */ | |
a98ea3f9 RS |
1113 | /* Note that the value cell will never directly contain nil |
1114 | if the symbol is a local variable. */ | |
e98a93eb | 1115 | if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) |
a98ea3f9 | 1116 | safe_run_hooks (Qpost_command_hook); |
a612e298 | 1117 | |
8a792f3a RS |
1118 | if (!NILP (Vdeferred_action_list)) |
1119 | call0 (Vdeferred_action_function); | |
1120 | ||
e98a93eb | 1121 | if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks)) |
59aadc81 RS |
1122 | { |
1123 | if (NILP (Vunread_command_events) | |
1124 | && NILP (Vexecuting_macro) | |
41365083 | 1125 | && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1))) |
59aadc81 RS |
1126 | safe_run_hooks (Qpost_command_idle_hook); |
1127 | } | |
1128 | ||
51d5a2c9 | 1129 | /* Do this after running Vpost_command_hook, for consistency. */ |
6c7178b9 | 1130 | current_kboard->Vlast_command = this_command; |
51d5a2c9 | 1131 | |
284f4730 JB |
1132 | while (1) |
1133 | { | |
284f4730 JB |
1134 | /* Make sure the current window's buffer is selected. */ |
1135 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
1136 | set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer)); | |
1137 | ||
1138 | /* Display any malloc warning that just came out. Use while because | |
1139 | displaying one warning can cause another. */ | |
1140 | ||
1141 | while (pending_malloc_warning) | |
1142 | display_malloc_warning (); | |
1143 | ||
1144 | no_direct = 0; | |
1145 | ||
86e5706b RS |
1146 | Vdeactivate_mark = Qnil; |
1147 | ||
284f4730 | 1148 | /* If minibuffer on and echo area in use, |
eb8c3be9 | 1149 | wait 2 sec and redraw minibuffer. */ |
284f4730 | 1150 | |
93127526 RS |
1151 | if (minibuf_level && echo_area_glyphs |
1152 | && EQ (minibuf_window, echo_area_window)) | |
284f4730 | 1153 | { |
f1bed6d8 RS |
1154 | /* Bind inhibit-quit to t so that C-g gets read in |
1155 | rather than quitting back to the minibuffer. */ | |
1156 | int count = specpdl_ptr - specpdl; | |
1157 | specbind (Qinhibit_quit, Qt); | |
f1bed6d8 | 1158 | |
db08707d | 1159 | Fsit_for (make_number (2), Qnil, Qnil); |
e6aa7813 | 1160 | /* Clear the echo area. */ |
c6a67acd | 1161 | message2 (0, 0); |
cdb9d665 | 1162 | safe_run_hooks (Qecho_area_clear_hook); |
e6aa7813 | 1163 | |
db08707d RS |
1164 | unbind_to (count, Qnil); |
1165 | ||
e6aa7813 | 1166 | /* If a C-g came in before, treat it as input now. */ |
284f4730 JB |
1167 | if (!NILP (Vquit_flag)) |
1168 | { | |
1169 | Vquit_flag = Qnil; | |
24597608 | 1170 | Vunread_command_events = Fcons (make_number (quit_char), Qnil); |
284f4730 JB |
1171 | } |
1172 | } | |
1173 | ||
1174 | #ifdef C_ALLOCA | |
ff4b06d3 | 1175 | alloca (0); /* Cause a garbage collection now */ |
284f4730 JB |
1176 | /* Since we can free the most stuff here. */ |
1177 | #endif /* C_ALLOCA */ | |
1178 | ||
8f805655 | 1179 | #if 0 |
8f805655 JB |
1180 | /* Select the frame that the last event came from. Usually, |
1181 | switch-frame events will take care of this, but if some lisp | |
1182 | code swallows a switch-frame event, we'll fix things up here. | |
1183 | Is this a good idea? */ | |
8c18cbfb | 1184 | if (FRAMEP (internal_last_event_frame) |
3c370943 JB |
1185 | && XFRAME (internal_last_event_frame) != selected_frame) |
1186 | Fselect_frame (internal_last_event_frame, Qnil); | |
284f4730 | 1187 | #endif |
48e416d4 RS |
1188 | /* If it has changed current-menubar from previous value, |
1189 | really recompute the menubar from the value. */ | |
a646e520 RS |
1190 | if (! NILP (Vlucid_menu_bar_dirty_flag) |
1191 | && !NILP (Ffboundp (Qrecompute_lucid_menubar))) | |
48e416d4 RS |
1192 | call0 (Qrecompute_lucid_menubar); |
1193 | ||
71918b75 RS |
1194 | before_command_key_count = this_command_key_count; |
1195 | before_command_echo_length = echo_length (); | |
1196 | ||
d7437ef6 RS |
1197 | this_command = Qnil; |
1198 | ||
8f805655 | 1199 | /* Read next key sequence; i gets its length. */ |
ce98e608 | 1200 | i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0], |
f571ae0d | 1201 | Qnil, 0, 1, 1); |
8f805655 | 1202 | |
6fac1409 RS |
1203 | /* A filter may have run while we were reading the input. */ |
1204 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
1205 | set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer)); | |
1206 | ||
8f805655 JB |
1207 | ++num_input_keys; |
1208 | ||
284f4730 JB |
1209 | /* Now we have read a key sequence of length I, |
1210 | or else I is 0 and we found end of file. */ | |
1211 | ||
1212 | if (i == 0) /* End of file -- happens only in */ | |
1213 | return Qnil; /* a kbd macro, at the end. */ | |
dcc408a0 RS |
1214 | /* -1 means read_key_sequence got a menu that was rejected. |
1215 | Just loop around and read another command. */ | |
1216 | if (i == -1) | |
1217 | { | |
1218 | cancel_echoing (); | |
1219 | this_command_key_count = 0; | |
6321824f | 1220 | this_single_command_key_start = 0; |
ff4b06d3 | 1221 | goto finalize; |
dcc408a0 | 1222 | } |
284f4730 | 1223 | |
284f4730 JB |
1224 | last_command_char = keybuf[i - 1]; |
1225 | ||
75c0b143 RS |
1226 | /* If the previous command tried to force a specific window-start, |
1227 | forget about that, in case this command moves point far away | |
c422836d KH |
1228 | from that position. But also throw away beg_unchanged and |
1229 | end_unchanged information in that case, so that redisplay will | |
1230 | update the whole window properly. */ | |
1231 | if (!NILP (XWINDOW (selected_window)->force_start)) | |
1232 | { | |
1233 | XWINDOW (selected_window)->force_start = Qnil; | |
1234 | beg_unchanged = end_unchanged = 0; | |
1235 | } | |
75c0b143 | 1236 | |
284f4730 JB |
1237 | cmd = read_key_sequence_cmd; |
1238 | if (!NILP (Vexecuting_macro)) | |
1239 | { | |
1240 | if (!NILP (Vquit_flag)) | |
1241 | { | |
1242 | Vexecuting_macro = Qt; | |
1243 | QUIT; /* Make some noise. */ | |
1244 | /* Will return since macro now empty. */ | |
1245 | } | |
1246 | } | |
1247 | ||
1248 | /* Do redisplay processing after this command except in special | |
40932d1a RS |
1249 | cases identified below that set no_redisplay to 1. |
1250 | (actually, there's currently no way to prevent the redisplay, | |
1251 | and no_redisplay is ignored. | |
beecf6a1 | 1252 | Perhaps someday we will really implement it.) */ |
284f4730 JB |
1253 | no_redisplay = 0; |
1254 | ||
86e5706b RS |
1255 | prev_buffer = current_buffer; |
1256 | prev_modiff = MODIFF; | |
8746da95 | 1257 | last_point_position = PT; |
18cd2eeb | 1258 | XSETBUFFER (last_point_position_buffer, prev_buffer); |
86e5706b | 1259 | |
284f4730 JB |
1260 | /* Execute the command. */ |
1261 | ||
86e5706b | 1262 | this_command = cmd; |
a98ea3f9 RS |
1263 | /* Note that the value cell will never directly contain nil |
1264 | if the symbol is a local variable. */ | |
e98a93eb | 1265 | if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks)) |
a98ea3f9 | 1266 | safe_run_hooks (Qpre_command_hook); |
86e5706b | 1267 | |
258bf746 | 1268 | if (NILP (this_command)) |
284f4730 JB |
1269 | { |
1270 | /* nil means key is undefined. */ | |
1271 | bitch_at_user (); | |
c5fdd383 | 1272 | current_kboard->defining_kbd_macro = Qnil; |
284f4730 | 1273 | update_mode_lines = 1; |
d8bcf58e | 1274 | current_kboard->Vprefix_arg = Qnil; |
284f4730 JB |
1275 | } |
1276 | else | |
1277 | { | |
d8bcf58e | 1278 | if (NILP (current_kboard->Vprefix_arg) && ! no_direct) |
284f4730 JB |
1279 | { |
1280 | /* Recognize some common commands in common situations and | |
1281 | do them directly. */ | |
8001d352 | 1282 | if (EQ (this_command, Qforward_char) && PT < ZV) |
284f4730 | 1283 | { |
51ad8a68 | 1284 | struct Lisp_Char_Table *dp |
284f4730 | 1285 | = window_display_table (XWINDOW (selected_window)); |
8458ede6 RS |
1286 | lose = FETCH_BYTE (PT_BYTE); |
1287 | SET_PT (PT + 1); | |
0f7a8fee | 1288 | if ((dp |
82ba47d7 | 1289 | ? (VECTORP (DISP_CHAR_VECTOR (dp, lose)) |
9a5540db RS |
1290 | ? XVECTOR (DISP_CHAR_VECTOR (dp, lose))->size == 1 |
1291 | : (NILP (DISP_CHAR_VECTOR (dp, lose)) | |
1292 | && (lose >= 0x20 && lose < 0x7f))) | |
0f7a8fee | 1293 | : (lose >= 0x20 && lose < 0x7f)) |
37cd9f30 KH |
1294 | /* To extract the case of continuation on |
1295 | wide-column characters. */ | |
8458ede6 | 1296 | && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE)) == 1) |
284f4730 JB |
1297 | && (XFASTINT (XWINDOW (selected_window)->last_modified) |
1298 | >= MODIFF) | |
598ba4c7 RS |
1299 | && (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1300 | >= OVERLAY_MODIFF) | |
284f4730 | 1301 | && (XFASTINT (XWINDOW (selected_window)->last_point) |
8001d352 | 1302 | == PT - 1) |
284f4730 JB |
1303 | && !windows_or_buffers_changed |
1304 | && EQ (current_buffer->selective_display, Qnil) | |
1305 | && !detect_input_pending () | |
962ae636 | 1306 | && NILP (XWINDOW (selected_window)->column_number_displayed) |
284f4730 JB |
1307 | && NILP (Vexecuting_macro)) |
1308 | no_redisplay = direct_output_forward_char (1); | |
1309 | goto directly_done; | |
1310 | } | |
8001d352 | 1311 | else if (EQ (this_command, Qbackward_char) && PT > BEGV) |
284f4730 | 1312 | { |
51ad8a68 | 1313 | struct Lisp_Char_Table *dp |
284f4730 | 1314 | = window_display_table (XWINDOW (selected_window)); |
8458ede6 RS |
1315 | SET_PT (PT - 1); |
1316 | lose = FETCH_BYTE (PT_BYTE); | |
0f7a8fee | 1317 | if ((dp |
ca873d73 | 1318 | ? (VECTORP (DISP_CHAR_VECTOR (dp, lose)) |
9a5540db RS |
1319 | ? XVECTOR (DISP_CHAR_VECTOR (dp, lose))->size == 1 |
1320 | : (NILP (DISP_CHAR_VECTOR (dp, lose)) | |
1321 | && (lose >= 0x20 && lose < 0x7f))) | |
0f7a8fee | 1322 | : (lose >= 0x20 && lose < 0x7f)) |
284f4730 JB |
1323 | && (XFASTINT (XWINDOW (selected_window)->last_modified) |
1324 | >= MODIFF) | |
598ba4c7 RS |
1325 | && (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1326 | >= OVERLAY_MODIFF) | |
284f4730 | 1327 | && (XFASTINT (XWINDOW (selected_window)->last_point) |
8001d352 | 1328 | == PT + 1) |
284f4730 JB |
1329 | && !windows_or_buffers_changed |
1330 | && EQ (current_buffer->selective_display, Qnil) | |
1331 | && !detect_input_pending () | |
962ae636 | 1332 | && NILP (XWINDOW (selected_window)->column_number_displayed) |
284f4730 JB |
1333 | && NILP (Vexecuting_macro)) |
1334 | no_redisplay = direct_output_forward_char (-1); | |
1335 | goto directly_done; | |
1336 | } | |
258bf746 | 1337 | else if (EQ (this_command, Qself_insert_command) |
284f4730 | 1338 | /* Try this optimization only on ascii keystrokes. */ |
8c18cbfb | 1339 | && INTEGERP (last_command_char)) |
284f4730 | 1340 | { |
89599794 | 1341 | unsigned int c = XINT (last_command_char); |
fc9cce4e | 1342 | int value; |
284f4730 | 1343 | |
fc9cce4e RS |
1344 | if (NILP (Vexecuting_macro) |
1345 | && !EQ (minibuf_window, selected_window)) | |
284f4730 JB |
1346 | { |
1347 | if (!nonundocount || nonundocount >= 20) | |
1348 | { | |
1349 | Fundo_boundary (); | |
1350 | nonundocount = 0; | |
1351 | } | |
1352 | nonundocount++; | |
1353 | } | |
fc9cce4e RS |
1354 | lose = ((XFASTINT (XWINDOW (selected_window)->last_modified) |
1355 | < MODIFF) | |
598ba4c7 RS |
1356 | || (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1357 | < OVERLAY_MODIFF) | |
fc9cce4e RS |
1358 | || (XFASTINT (XWINDOW (selected_window)->last_point) |
1359 | != PT) | |
4c61f38e | 1360 | || MODIFF <= SAVE_MODIFF |
fc9cce4e RS |
1361 | || windows_or_buffers_changed |
1362 | || !EQ (current_buffer->selective_display, Qnil) | |
1363 | || detect_input_pending () | |
962ae636 | 1364 | || !NILP (XWINDOW (selected_window)->column_number_displayed) |
fc9cce4e RS |
1365 | || !NILP (Vexecuting_macro)); |
1366 | value = internal_self_insert (c, 0); | |
1367 | if (value) | |
1368 | lose = 1; | |
1369 | if (value == 2) | |
1370 | nonundocount = 0; | |
1371 | ||
1372 | if (!lose | |
8458ede6 | 1373 | && (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n')) |
284f4730 | 1374 | { |
51ad8a68 | 1375 | struct Lisp_Char_Table *dp |
284f4730 | 1376 | = window_display_table (XWINDOW (selected_window)); |
b8d9050d | 1377 | int lose = c; |
284f4730 | 1378 | |
e3ee7487 RS |
1379 | /* Add the offset to the character, for Finsert_char. |
1380 | We pass internal_self_insert the unmodified character | |
1381 | because it itself does this offsetting. */ | |
1382 | if (lose >= 0200 && lose <= 0377 | |
1383 | && ! NILP (current_buffer->enable_multibyte_characters)) | |
1384 | lose += nonascii_insert_offset; | |
1385 | ||
0f7a8fee JB |
1386 | if (dp) |
1387 | { | |
9b8eb840 | 1388 | Lisp_Object obj; |
0f7a8fee | 1389 | |
9b8eb840 | 1390 | obj = DISP_CHAR_VECTOR (dp, lose); |
054c8675 | 1391 | if (NILP (obj)) |
8e91f441 RS |
1392 | { |
1393 | /* Do it only for char codes | |
1394 | that by default display as themselves. */ | |
1395 | if (lose >= 0x20 && lose <= 0x7e) | |
1396 | no_redisplay = direct_output_for_insert (lose); | |
1397 | } | |
8c18cbfb | 1398 | else if (VECTORP (obj) |
054c8675 | 1399 | && XVECTOR (obj)->size == 1 |
8c18cbfb KH |
1400 | && (obj = XVECTOR (obj)->contents[0], |
1401 | INTEGERP (obj)) | |
054c8675 RS |
1402 | /* Insist face not specified in glyph. */ |
1403 | && (XINT (obj) & ((-1) << 8)) == 0) | |
bd48a052 RS |
1404 | no_redisplay |
1405 | = direct_output_for_insert (XINT (obj)); | |
0f7a8fee JB |
1406 | } |
1407 | else | |
1408 | { | |
1409 | if (lose >= 0x20 && lose <= 0x7e) | |
1410 | no_redisplay = direct_output_for_insert (lose); | |
1411 | } | |
284f4730 JB |
1412 | } |
1413 | goto directly_done; | |
1414 | } | |
1415 | } | |
1416 | ||
1417 | /* Here for a command that isn't executed directly */ | |
1418 | ||
1419 | nonundocount = 0; | |
d8bcf58e | 1420 | if (NILP (current_kboard->Vprefix_arg)) |
284f4730 | 1421 | Fundo_boundary (); |
158f7532 | 1422 | Fcommand_execute (this_command, Qnil, Qnil, Qnil); |
284f4730 | 1423 | |
284f4730 | 1424 | } |
a764a753 | 1425 | directly_done: ; |
284f4730 JB |
1426 | |
1427 | /* If there is a prefix argument, | |
6c7178b9 KH |
1428 | 1) We don't want Vlast_command to be ``universal-argument'' |
1429 | (that would be dumb), so don't set Vlast_command, | |
284f4730 JB |
1430 | 2) we want to leave echoing on so that the prefix will be |
1431 | echoed as part of this key sequence, so don't call | |
1432 | cancel_echoing, and | |
1433 | 3) we want to leave this_command_key_count non-zero, so that | |
1434 | read_char will realize that it is re-reading a character, and | |
217258d5 KH |
1435 | not echo it a second time. |
1436 | ||
1437 | If the command didn't actually create a prefix arg, | |
1438 | but is merely a frame event that is transparent to prefix args, | |
1439 | then the above doesn't apply. */ | |
1440 | if (NILP (current_kboard->Vprefix_arg) || CONSP (last_command_char)) | |
284f4730 | 1441 | { |
6c7178b9 | 1442 | current_kboard->Vlast_command = this_command; |
284f4730 JB |
1443 | cancel_echoing (); |
1444 | this_command_key_count = 0; | |
6321824f | 1445 | this_single_command_key_start = 0; |
284f4730 | 1446 | } |
86e5706b | 1447 | |
51603bd0 RS |
1448 | /* Note that the value cell will never directly contain nil |
1449 | if the symbol is a local variable. */ | |
1450 | if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) | |
1451 | safe_run_hooks (Qpost_command_hook); | |
1452 | ||
1453 | if (!NILP (Vdeferred_action_list)) | |
1454 | safe_run_hooks (Qdeferred_action_function); | |
1455 | ||
1456 | if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks)) | |
1457 | { | |
1458 | if (NILP (Vunread_command_events) | |
1459 | && NILP (Vexecuting_macro) | |
41365083 | 1460 | && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1))) |
51603bd0 RS |
1461 | safe_run_hooks (Qpost_command_idle_hook); |
1462 | } | |
1463 | ||
88ce066e | 1464 | if (!NILP (current_buffer->mark_active) && !NILP (Vrun_hooks)) |
86e5706b RS |
1465 | { |
1466 | if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode)) | |
1467 | { | |
1468 | current_buffer->mark_active = Qnil; | |
1469 | call1 (Vrun_hooks, intern ("deactivate-mark-hook")); | |
1470 | } | |
1471 | else if (current_buffer != prev_buffer || MODIFF != prev_modiff) | |
1472 | call1 (Vrun_hooks, intern ("activate-mark-hook")); | |
1473 | } | |
ff4b06d3 KH |
1474 | |
1475 | finalize: | |
1476 | /* Install chars successfully executed in kbd macro. */ | |
1477 | ||
d8bcf58e KH |
1478 | if (!NILP (current_kboard->defining_kbd_macro) |
1479 | && NILP (current_kboard->Vprefix_arg)) | |
ff4b06d3 KH |
1480 | finalize_kbd_macro_chars (); |
1481 | ||
c5fdd383 | 1482 | #ifdef MULTI_KBOARD |
604ccd1d | 1483 | if (!was_locked) |
1e8bd3da | 1484 | any_kboard_state (); |
ff4b06d3 | 1485 | #endif |
284f4730 JB |
1486 | } |
1487 | } | |
1c9784c9 | 1488 | |
0bc3db2b RS |
1489 | /* Subroutine for safe_run_hooks: run the hook HOOK. */ |
1490 | ||
1491 | static Lisp_Object | |
1492 | safe_run_hooks_1 (hook) | |
1493 | Lisp_Object hook; | |
1494 | { | |
1495 | return call1 (Vrun_hooks, Vinhibit_quit); | |
1496 | } | |
1497 | ||
1498 | /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */ | |
1499 | ||
1500 | static Lisp_Object | |
1501 | safe_run_hooks_error (data) | |
1502 | Lisp_Object data; | |
1503 | { | |
1504 | Fset (Vinhibit_quit, Qnil); | |
1505 | } | |
1506 | ||
1c9784c9 KH |
1507 | /* If we get an error while running the hook, cause the hook variable |
1508 | to be nil. Also inhibit quits, so that C-g won't cause the hook | |
1509 | to mysteriously evaporate. */ | |
0bc3db2b | 1510 | |
68f297c5 | 1511 | void |
1c9784c9 | 1512 | safe_run_hooks (hook) |
a98ea3f9 | 1513 | Lisp_Object hook; |
1c9784c9 | 1514 | { |
68553292 | 1515 | Lisp_Object value; |
1c9784c9 | 1516 | int count = specpdl_ptr - specpdl; |
0bc3db2b RS |
1517 | specbind (Qinhibit_quit, hook); |
1518 | ||
e702932d | 1519 | internal_condition_case (safe_run_hooks_1, Qt, safe_run_hooks_error); |
1c9784c9 KH |
1520 | |
1521 | unbind_to (count, Qnil); | |
1522 | } | |
284f4730 JB |
1523 | \f |
1524 | /* Number of seconds between polling for input. */ | |
1525 | int polling_period; | |
1526 | ||
eb8c3be9 | 1527 | /* Nonzero means polling for input is temporarily suppressed. */ |
284f4730 JB |
1528 | int poll_suppress_count; |
1529 | ||
36922b18 | 1530 | /* Nonzero if polling_for_input is actually being used. */ |
284f4730 JB |
1531 | int polling_for_input; |
1532 | ||
36922b18 RS |
1533 | #ifdef POLL_FOR_INPUT |
1534 | ||
284f4730 JB |
1535 | /* Handle an alarm once each second and read pending input |
1536 | so as to handle a C-g if it comces in. */ | |
1537 | ||
1538 | SIGTYPE | |
91c049d4 RS |
1539 | input_poll_signal (signalnum) /* If we don't have an argument, */ |
1540 | int signalnum; /* some compilers complain in signal calls. */ | |
284f4730 | 1541 | { |
87dd9b9b RS |
1542 | /* This causes the call to start_polling at the end |
1543 | to do its job. It also arranges for a quit or error | |
1544 | from within read_avail_input to resume polling. */ | |
1545 | poll_suppress_count++; | |
9ac0d9e0 JB |
1546 | if (interrupt_input_blocked == 0 |
1547 | && !waiting_for_input) | |
1548 | read_avail_input (0); | |
87dd9b9b RS |
1549 | /* Turn on the SIGALRM handler and request another alarm. */ |
1550 | start_polling (); | |
284f4730 JB |
1551 | } |
1552 | ||
1553 | #endif | |
1554 | ||
1555 | /* Begin signals to poll for input, if they are appropriate. | |
1556 | This function is called unconditionally from various places. */ | |
1557 | ||
07a59269 | 1558 | void |
284f4730 JB |
1559 | start_polling () |
1560 | { | |
1561 | #ifdef POLL_FOR_INPUT | |
34f04431 | 1562 | if (read_socket_hook && !interrupt_input) |
284f4730 JB |
1563 | { |
1564 | poll_suppress_count--; | |
1565 | if (poll_suppress_count == 0) | |
1566 | { | |
1567 | signal (SIGALRM, input_poll_signal); | |
1568 | polling_for_input = 1; | |
1569 | alarm (polling_period); | |
1570 | } | |
1571 | } | |
1572 | #endif | |
1573 | } | |
1574 | ||
1d3195db RS |
1575 | /* Nonzero if we are using polling to handle input asynchronously. */ |
1576 | ||
1577 | int | |
1578 | input_polling_used () | |
1579 | { | |
1580 | #ifdef POLL_FOR_INPUT | |
1581 | return read_socket_hook && !interrupt_input; | |
1582 | #else | |
1583 | return 0; | |
1584 | #endif | |
1585 | } | |
1586 | ||
284f4730 JB |
1587 | /* Turn off polling. */ |
1588 | ||
07a59269 | 1589 | void |
284f4730 JB |
1590 | stop_polling () |
1591 | { | |
1592 | #ifdef POLL_FOR_INPUT | |
34f04431 | 1593 | if (read_socket_hook && !interrupt_input) |
284f4730 JB |
1594 | { |
1595 | if (poll_suppress_count == 0) | |
1596 | { | |
1597 | polling_for_input = 0; | |
1598 | alarm (0); | |
1599 | } | |
1600 | poll_suppress_count++; | |
1601 | } | |
1602 | #endif | |
1603 | } | |
fe8aeef3 RS |
1604 | |
1605 | /* Set the value of poll_suppress_count to COUNT | |
1606 | and start or stop polling accordingly. */ | |
1607 | ||
1608 | void | |
1609 | set_poll_suppress_count (count) | |
1610 | int count; | |
1611 | { | |
1612 | #ifdef POLL_FOR_INPUT | |
1613 | if (count == 0 && poll_suppress_count != 0) | |
1614 | { | |
1615 | poll_suppress_count = 1; | |
1616 | start_polling (); | |
1617 | } | |
1618 | else if (count != 0 && poll_suppress_count == 0) | |
1619 | { | |
1620 | stop_polling (); | |
1621 | } | |
1622 | poll_suppress_count = count; | |
1623 | #endif | |
1624 | } | |
f4eef8b4 | 1625 | |
d0a57728 RS |
1626 | /* Bind polling_period to a value at least N. |
1627 | But don't decrease it. */ | |
1628 | ||
07a59269 | 1629 | void |
f4eef8b4 RS |
1630 | bind_polling_period (n) |
1631 | int n; | |
1632 | { | |
1633 | #ifdef POLL_FOR_INPUT | |
d0a57728 RS |
1634 | int new = polling_period; |
1635 | ||
1636 | if (n > new) | |
1637 | new = n; | |
1638 | ||
f4eef8b4 | 1639 | stop_polling (); |
d0a57728 RS |
1640 | specbind (Qpolling_period, make_number (new)); |
1641 | /* Start a new alarm with the new period. */ | |
f4eef8b4 RS |
1642 | start_polling (); |
1643 | #endif | |
1644 | } | |
284f4730 | 1645 | \f |
6da3dd3a RS |
1646 | /* Apply the control modifier to CHARACTER. */ |
1647 | ||
faf5e407 JB |
1648 | int |
1649 | make_ctrl_char (c) | |
1650 | int c; | |
1651 | { | |
d205953b JB |
1652 | /* Save the upper bits here. */ |
1653 | int upper = c & ~0177; | |
1654 | ||
1655 | c &= 0177; | |
1656 | ||
1657 | /* Everything in the columns containing the upper-case letters | |
1658 | denotes a control character. */ | |
1659 | if (c >= 0100 && c < 0140) | |
1660 | { | |
1661 | int oc = c; | |
1662 | c &= ~0140; | |
1663 | /* Set the shift modifier for a control char | |
1664 | made from a shifted letter. But only for letters! */ | |
1665 | if (oc >= 'A' && oc <= 'Z') | |
1666 | c |= shift_modifier; | |
1667 | } | |
1668 | ||
1669 | /* The lower-case letters denote control characters too. */ | |
1670 | else if (c >= 'a' && c <= 'z') | |
1671 | c &= ~0140; | |
1672 | ||
1673 | /* Include the bits for control and shift | |
1674 | only if the basic ASCII code can't indicate them. */ | |
1675 | else if (c >= ' ') | |
1676 | c |= ctrl_modifier; | |
1677 | ||
1678 | /* Replace the high bits. */ | |
1679 | c |= (upper & ~ctrl_modifier); | |
faf5e407 JB |
1680 | |
1681 | return c; | |
1682 | } | |
1683 | ||
1684 | ||
1685 | \f | |
284f4730 JB |
1686 | /* Input of single characters from keyboard */ |
1687 | ||
1688 | Lisp_Object print_help (); | |
1689 | static Lisp_Object kbd_buffer_get_event (); | |
e4fe371d | 1690 | static void record_char (); |
284f4730 | 1691 | |
c5fdd383 KH |
1692 | #ifdef MULTI_KBOARD |
1693 | static jmp_buf wrong_kboard_jmpbuf; | |
bded54dd | 1694 | #endif |
beecf6a1 | 1695 | |
284f4730 JB |
1696 | /* read a character from the keyboard; call the redisplay if needed */ |
1697 | /* commandflag 0 means do not do auto-saving, but do do redisplay. | |
1698 | -1 means do not do redisplay, but do do autosaving. | |
1699 | 1 means do both. */ | |
1700 | ||
7d6de002 RS |
1701 | /* The arguments MAPS and NMAPS are for menu prompting. |
1702 | MAPS is an array of keymaps; NMAPS is the length of MAPS. | |
1703 | ||
1704 | PREV_EVENT is the previous input event, or nil if we are reading | |
1705 | the first event of a key sequence. | |
1706 | ||
83d68044 | 1707 | If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1 |
6569cc8d | 1708 | if we used a mouse menu to read the input, or zero otherwise. If |
83d68044 | 1709 | USED_MOUSE_MENU is null, we don't dereference it. |
dcc408a0 RS |
1710 | |
1711 | Value is t if we showed a menu and the user rejected it. */ | |
7d6de002 | 1712 | |
284f4730 | 1713 | Lisp_Object |
7d6de002 | 1714 | read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu) |
284f4730 | 1715 | int commandflag; |
7d6de002 RS |
1716 | int nmaps; |
1717 | Lisp_Object *maps; | |
1718 | Lisp_Object prev_event; | |
1719 | int *used_mouse_menu; | |
284f4730 | 1720 | { |
7c3bc944 | 1721 | Lisp_Object c; |
284f4730 | 1722 | int count; |
410d4de9 | 1723 | jmp_buf local_getcjmp; |
284f4730 | 1724 | jmp_buf save_jump; |
a1341f75 | 1725 | int key_already_recorded = 0; |
017c7cb6 | 1726 | Lisp_Object tem, save; |
e4fe371d | 1727 | Lisp_Object also_record; |
7c3bc944 RS |
1728 | struct gcpro gcpro1; |
1729 | ||
e4fe371d | 1730 | also_record = Qnil; |
284f4730 | 1731 | |
71918b75 RS |
1732 | before_command_key_count = this_command_key_count; |
1733 | before_command_echo_length = echo_length (); | |
ef6661f7 | 1734 | c = Qnil; |
71918b75 | 1735 | |
7c3bc944 RS |
1736 | GCPRO1 (c); |
1737 | ||
7f07d5ca RS |
1738 | retry: |
1739 | ||
24597608 | 1740 | if (CONSP (Vunread_command_events)) |
284f4730 | 1741 | { |
24597608 RS |
1742 | c = XCONS (Vunread_command_events)->car; |
1743 | Vunread_command_events = XCONS (Vunread_command_events)->cdr; | |
284f4730 | 1744 | |
2479e91e RS |
1745 | /* Undo what read_char_x_menu_prompt did when it unread |
1746 | additional keys returned by Fx_popup_menu. */ | |
1747 | if (CONSP (c) | |
1748 | && (SYMBOLP (XCONS (c)->car) || INTEGERP (XCONS (c)->car)) | |
1749 | && NILP (XCONS (c)->cdr)) | |
1750 | c = XCONS (c)->car; | |
1751 | ||
284f4730 JB |
1752 | if (this_command_key_count == 0) |
1753 | goto reread_first; | |
1754 | else | |
1755 | goto reread; | |
1756 | } | |
1757 | ||
86e5706b RS |
1758 | if (unread_command_char != -1) |
1759 | { | |
18cd2eeb | 1760 | XSETINT (c, unread_command_char); |
86e5706b RS |
1761 | unread_command_char = -1; |
1762 | ||
1763 | if (this_command_key_count == 0) | |
1764 | goto reread_first; | |
1765 | else | |
1766 | goto reread; | |
1767 | } | |
1768 | ||
71918b75 RS |
1769 | /* If there is no function key translated before |
1770 | reset-this-command-lengths takes effect, forget about it. */ | |
1771 | before_command_restore_flag = 0; | |
1772 | ||
284f4730 JB |
1773 | if (!NILP (Vexecuting_macro)) |
1774 | { | |
fce33686 JB |
1775 | /* We set this to Qmacro; since that's not a frame, nobody will |
1776 | try to switch frames on us, and the selected window will | |
1777 | remain unchanged. | |
1778 | ||
1779 | Since this event came from a macro, it would be misleading to | |
eb8c3be9 | 1780 | leave internal_last_event_frame set to wherever the last |
3c370943 JB |
1781 | real event came from. Normally, a switch-frame event selects |
1782 | internal_last_event_frame after each command is read, but | |
1783 | events read from a macro should never cause a new frame to be | |
1784 | selected. */ | |
4c52b668 | 1785 | Vlast_event_frame = internal_last_event_frame = Qmacro; |
fce33686 | 1786 | |
663258f2 JB |
1787 | /* Exit the macro if we are at the end. |
1788 | Also, some things replace the macro with t | |
1789 | to force an early exit. */ | |
1790 | if (EQ (Vexecuting_macro, Qt) | |
1791 | || executing_macro_index >= XFASTINT (Flength (Vexecuting_macro))) | |
284f4730 | 1792 | { |
18cd2eeb | 1793 | XSETINT (c, -1); |
7c3bc944 | 1794 | RETURN_UNGCPRO (c); |
284f4730 | 1795 | } |
df0f2ba1 | 1796 | |
284f4730 | 1797 | c = Faref (Vexecuting_macro, make_number (executing_macro_index)); |
8c18cbfb | 1798 | if (STRINGP (Vexecuting_macro) |
86e5706b | 1799 | && (XINT (c) & 0x80)) |
bb9e9bed | 1800 | XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80)); |
86e5706b | 1801 | |
284f4730 JB |
1802 | executing_macro_index++; |
1803 | ||
1804 | goto from_macro; | |
1805 | } | |
1806 | ||
cd21b839 JB |
1807 | if (!NILP (unread_switch_frame)) |
1808 | { | |
1809 | c = unread_switch_frame; | |
1810 | unread_switch_frame = Qnil; | |
1811 | ||
1812 | /* This event should make it into this_command_keys, and get echoed | |
f4255cd1 JB |
1813 | again, so we go to reread_first, rather than reread. */ |
1814 | goto reread_first; | |
cd21b839 JB |
1815 | } |
1816 | ||
6e4e64a8 RS |
1817 | if (commandflag >= 0) |
1818 | { | |
1819 | if (input_pending | |
1820 | || detect_input_pending_run_timers (0)) | |
1821 | swallow_events (0); | |
1822 | ||
1823 | if (!input_pending) | |
1824 | redisplay (); | |
1825 | } | |
e9bf89a0 | 1826 | |
410d4de9 RS |
1827 | /* Message turns off echoing unless more keystrokes turn it on again. */ |
1828 | if (echo_area_glyphs && *echo_area_glyphs | |
1fc93d49 | 1829 | && echo_area_glyphs != current_kboard->echobuf |
0c04a67e | 1830 | && ok_to_echo_at_next_pause != echo_area_glyphs) |
410d4de9 RS |
1831 | cancel_echoing (); |
1832 | else | |
1833 | /* If already echoing, continue. */ | |
1834 | echo_dash (); | |
284f4730 | 1835 | |
410d4de9 RS |
1836 | /* Try reading a character via menu prompting in the minibuf. |
1837 | Try this before the sit-for, because the sit-for | |
1838 | would do the wrong thing if we are supposed to do | |
1839 | menu prompting. If EVENT_HAS_PARAMETERS then we are reading | |
1840 | after a mouse event so don't try a minibuf menu. */ | |
1841 | c = Qnil; | |
1842 | if (nmaps > 0 && INTERACTIVE | |
1843 | && !NILP (prev_event) && ! EVENT_HAS_PARAMETERS (prev_event) | |
1844 | /* Don't bring up a menu if we already have another event. */ | |
1845 | && NILP (Vunread_command_events) | |
1846 | && unread_command_char < 0 | |
4ec4ed6a | 1847 | && !detect_input_pending_run_timers (0)) |
410d4de9 RS |
1848 | { |
1849 | c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps); | |
1850 | if (! NILP (c)) | |
1851 | { | |
1852 | key_already_recorded = 1; | |
1853 | goto non_reread_1; | |
1854 | } | |
1855 | } | |
284f4730 | 1856 | |
410d4de9 RS |
1857 | /* Make a longjmp point for quits to use, but don't alter getcjmp just yet. |
1858 | We will do that below, temporarily for short sections of code, | |
1859 | when appropriate. local_getcjmp must be in effect | |
1860 | around any call to sit_for or kbd_buffer_get_event; | |
1861 | it *must not* be in effect when we call redisplay. */ | |
284f4730 | 1862 | |
410d4de9 | 1863 | if (_setjmp (local_getcjmp)) |
284f4730 | 1864 | { |
18cd2eeb | 1865 | XSETINT (c, quit_char); |
4c52b668 KH |
1866 | XSETFRAME (internal_last_event_frame, selected_frame); |
1867 | Vlast_event_frame = internal_last_event_frame; | |
04904c29 RS |
1868 | /* If we report the quit char as an event, |
1869 | don't do so more than once. */ | |
1870 | if (!NILP (Vinhibit_quit)) | |
1871 | Vquit_flag = Qnil; | |
284f4730 | 1872 | |
c5fdd383 | 1873 | #ifdef MULTI_KBOARD |
df0f2ba1 | 1874 | { |
c5fdd383 KH |
1875 | KBOARD *kb = FRAME_KBOARD (selected_frame); |
1876 | if (kb != current_kboard) | |
df0f2ba1 | 1877 | { |
c5fdd383 | 1878 | Lisp_Object *tailp = &kb->kbd_queue; |
1e8bd3da RS |
1879 | /* We shouldn't get here if we were in single-kboard mode! */ |
1880 | if (single_kboard) | |
df0f2ba1 KH |
1881 | abort (); |
1882 | while (CONSP (*tailp)) | |
1883 | tailp = &XCONS (*tailp)->cdr; | |
1884 | if (!NILP (*tailp)) | |
1885 | abort (); | |
1886 | *tailp = Fcons (c, Qnil); | |
c5fdd383 KH |
1887 | kb->kbd_queue_has_data = 1; |
1888 | current_kboard = kb; | |
ef6661f7 RS |
1889 | /* This is going to exit from read_char |
1890 | so we had better get rid of this frame's stuff. */ | |
1891 | UNGCPRO; | |
c5fdd383 | 1892 | longjmp (wrong_kboard_jmpbuf, 1); |
df0f2ba1 KH |
1893 | } |
1894 | } | |
1895 | #endif | |
284f4730 JB |
1896 | goto non_reread; |
1897 | } | |
1898 | ||
d9d4c147 KH |
1899 | timer_start_idle (); |
1900 | ||
284f4730 JB |
1901 | /* If in middle of key sequence and minibuffer not active, |
1902 | start echoing if enough time elapses. */ | |
410d4de9 | 1903 | |
c5fdd383 | 1904 | if (minibuf_level == 0 && !current_kboard->immediate_echo |
6c6083a9 | 1905 | && this_command_key_count > 0 |
27203ead | 1906 | && ! noninteractive |
284f4730 | 1907 | && echo_keystrokes > 0 |
1fc93d49 | 1908 | && (echo_area_glyphs == 0 || *echo_area_glyphs == 0 |
0c04a67e | 1909 | || ok_to_echo_at_next_pause == echo_area_glyphs)) |
284f4730 JB |
1910 | { |
1911 | Lisp_Object tem0; | |
1912 | ||
7d6de002 RS |
1913 | /* After a mouse event, start echoing right away. |
1914 | This is because we are probably about to display a menu, | |
1915 | and we don't want to delay before doing so. */ | |
dbc4e1c1 | 1916 | if (EVENT_HAS_PARAMETERS (prev_event)) |
3dbd9ee4 | 1917 | echo_now (); |
7d6de002 RS |
1918 | else |
1919 | { | |
410d4de9 RS |
1920 | save_getcjmp (save_jump); |
1921 | restore_getcjmp (local_getcjmp); | |
41365083 | 1922 | tem0 = sit_for (echo_keystrokes, 0, 1, 1, 0); |
410d4de9 | 1923 | restore_getcjmp (save_jump); |
303b5b3f RS |
1924 | if (EQ (tem0, Qt) |
1925 | && ! CONSP (Vunread_command_events)) | |
3dbd9ee4 | 1926 | echo_now (); |
7d6de002 | 1927 | } |
284f4730 JB |
1928 | } |
1929 | ||
410d4de9 | 1930 | /* Maybe auto save due to number of keystrokes. */ |
284f4730 JB |
1931 | |
1932 | if (commandflag != 0 | |
1933 | && auto_save_interval > 0 | |
c43b1734 | 1934 | && num_nonmacro_input_events - last_auto_save > max (auto_save_interval, 20) |
4ec4ed6a | 1935 | && !detect_input_pending_run_timers (0)) |
284f4730 | 1936 | { |
284f4730 | 1937 | Fdo_auto_save (Qnil, Qnil); |
ef8fd672 RS |
1938 | /* Hooks can actually change some buffers in auto save. */ |
1939 | redisplay (); | |
284f4730 JB |
1940 | } |
1941 | ||
8150596a | 1942 | /* Try reading using an X menu. |
24597608 RS |
1943 | This is never confused with reading using the minibuf |
1944 | because the recursive call of read_char in read_char_minibuf_menu_prompt | |
1945 | does not pass on any keymaps. */ | |
410d4de9 | 1946 | |
24597608 | 1947 | if (nmaps > 0 && INTERACTIVE |
5a8d99e0 KH |
1948 | && !NILP (prev_event) |
1949 | && EVENT_HAS_PARAMETERS (prev_event) | |
1950 | && !EQ (XCONS (prev_event)->car, Qmenu_bar) | |
24597608 RS |
1951 | /* Don't bring up a menu if we already have another event. */ |
1952 | && NILP (Vunread_command_events) | |
b8556aee | 1953 | && unread_command_char < 0) |
8eb4d8ef RS |
1954 | { |
1955 | c = read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu); | |
1956 | ||
1957 | /* Now that we have read an event, Emacs is not idle. */ | |
1958 | timer_stop_idle (); | |
1959 | ||
7c3bc944 | 1960 | RETURN_UNGCPRO (c); |
8eb4d8ef | 1961 | } |
7d6de002 | 1962 | |
410d4de9 RS |
1963 | /* Maybe autosave and/or garbage collect due to idleness. */ |
1964 | ||
26c1639e | 1965 | if (INTERACTIVE && NILP (c)) |
7d6de002 RS |
1966 | { |
1967 | int delay_level, buffer_size; | |
1968 | ||
410d4de9 RS |
1969 | /* Slow down auto saves logarithmically in size of current buffer, |
1970 | and garbage collect while we're at it. */ | |
7d6de002 RS |
1971 | if (! MINI_WINDOW_P (XWINDOW (selected_window))) |
1972 | last_non_minibuf_size = Z - BEG; | |
1973 | buffer_size = (last_non_minibuf_size >> 8) + 1; | |
1974 | delay_level = 0; | |
1975 | while (buffer_size > 64) | |
1976 | delay_level++, buffer_size -= buffer_size >> 2; | |
1977 | if (delay_level < 4) delay_level = 4; | |
1978 | /* delay_level is 4 for files under around 50k, 7 at 100k, | |
1979 | 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */ | |
1980 | ||
1981 | /* Auto save if enough time goes by without input. */ | |
1982 | if (commandflag != 0 | |
c43b1734 | 1983 | && num_nonmacro_input_events > last_auto_save |
8c18cbfb | 1984 | && INTEGERP (Vauto_save_timeout) |
7d6de002 RS |
1985 | && XINT (Vauto_save_timeout) > 0) |
1986 | { | |
1987 | Lisp_Object tem0; | |
410d4de9 RS |
1988 | |
1989 | save_getcjmp (save_jump); | |
1990 | restore_getcjmp (local_getcjmp); | |
d9d4c147 | 1991 | tem0 = sit_for (delay_level * XFASTINT (Vauto_save_timeout) / 4, |
41365083 | 1992 | 0, 1, 1, 0); |
410d4de9 RS |
1993 | restore_getcjmp (save_jump); |
1994 | ||
303b5b3f RS |
1995 | if (EQ (tem0, Qt) |
1996 | && ! CONSP (Vunread_command_events)) | |
7d6de002 | 1997 | { |
7d6de002 | 1998 | Fdo_auto_save (Qnil, Qnil); |
7d6de002 RS |
1999 | |
2000 | /* If we have auto-saved and there is still no input | |
2001 | available, garbage collect if there has been enough | |
2002 | consing going on to make it worthwhile. */ | |
4ec4ed6a | 2003 | if (!detect_input_pending_run_timers (0) |
7d6de002 | 2004 | && consing_since_gc > gc_cons_threshold / 2) |
ef8fd672 | 2005 | Fgarbage_collect (); |
410d4de9 | 2006 | |
ef8fd672 | 2007 | redisplay (); |
7d6de002 RS |
2008 | } |
2009 | } | |
2010 | } | |
284f4730 | 2011 | |
303b5b3f RS |
2012 | /* If this has become non-nil here, it has been set by a timer |
2013 | or sentinel or filter. */ | |
2014 | if (CONSP (Vunread_command_events)) | |
2015 | { | |
2016 | c = XCONS (Vunread_command_events)->car; | |
2017 | Vunread_command_events = XCONS (Vunread_command_events)->cdr; | |
2018 | } | |
2019 | ||
410d4de9 RS |
2020 | /* Read something from current KBOARD's side queue, if possible. */ |
2021 | ||
beecf6a1 | 2022 | if (NILP (c)) |
1e12dd87 | 2023 | { |
c5fdd383 | 2024 | if (current_kboard->kbd_queue_has_data) |
beecf6a1 | 2025 | { |
c5fdd383 | 2026 | if (!CONSP (current_kboard->kbd_queue)) |
4524b161 | 2027 | abort (); |
c5fdd383 KH |
2028 | c = XCONS (current_kboard->kbd_queue)->car; |
2029 | current_kboard->kbd_queue | |
2030 | = XCONS (current_kboard->kbd_queue)->cdr; | |
2031 | if (NILP (current_kboard->kbd_queue)) | |
2032 | current_kboard->kbd_queue_has_data = 0; | |
d9d4c147 | 2033 | input_pending = readable_events (0); |
4c52b668 KH |
2034 | if (EVENT_HAS_PARAMETERS (c) |
2035 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qswitch_frame)) | |
2036 | internal_last_event_frame = XCONS (XCONS (c)->cdr)->car; | |
2037 | Vlast_event_frame = internal_last_event_frame; | |
beecf6a1 | 2038 | } |
1e8bd3da RS |
2039 | } |
2040 | ||
c5fdd383 | 2041 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
2042 | /* If current_kboard's side queue is empty check the other kboards. |
2043 | If one of them has data that we have not yet seen here, | |
2044 | switch to it and process the data waiting for it. | |
2045 | ||
2046 | Note: if the events queued up for another kboard | |
2047 | have already been seen here, and therefore are not a complete command, | |
2048 | the kbd_queue_has_data field is 0, so we skip that kboard here. | |
2049 | That's to avoid an infinite loop switching between kboards here. */ | |
2050 | if (NILP (c) && !single_kboard) | |
2051 | { | |
2052 | KBOARD *kb; | |
2053 | for (kb = all_kboards; kb; kb = kb->next_kboard) | |
2054 | if (kb->kbd_queue_has_data) | |
2055 | { | |
2056 | current_kboard = kb; | |
ef6661f7 RS |
2057 | /* This is going to exit from read_char |
2058 | so we had better get rid of this frame's stuff. */ | |
2059 | UNGCPRO; | |
1e8bd3da RS |
2060 | longjmp (wrong_kboard_jmpbuf, 1); |
2061 | } | |
2062 | } | |
df0f2ba1 KH |
2063 | #endif |
2064 | ||
410d4de9 RS |
2065 | wrong_kboard: |
2066 | ||
2067 | stop_polling (); | |
2068 | ||
1e8bd3da RS |
2069 | /* Finally, we read from the main queue, |
2070 | and if that gives us something we can't use yet, we put it on the | |
2071 | appropriate side queue and try again. */ | |
410d4de9 | 2072 | |
1e8bd3da RS |
2073 | if (NILP (c)) |
2074 | { | |
2075 | KBOARD *kb; | |
2076 | ||
1e8bd3da | 2077 | /* Actually read a character, waiting if necessary. */ |
410d4de9 RS |
2078 | save_getcjmp (save_jump); |
2079 | restore_getcjmp (local_getcjmp); | |
83d68044 | 2080 | c = kbd_buffer_get_event (&kb, used_mouse_menu); |
410d4de9 RS |
2081 | restore_getcjmp (save_jump); |
2082 | ||
c5fdd383 | 2083 | #ifdef MULTI_KBOARD |
410d4de9 | 2084 | if (! NILP (c) && (kb != current_kboard)) |
1e8bd3da RS |
2085 | { |
2086 | Lisp_Object *tailp = &kb->kbd_queue; | |
2087 | while (CONSP (*tailp)) | |
2088 | tailp = &XCONS (*tailp)->cdr; | |
2089 | if (!NILP (*tailp)) | |
2090 | abort (); | |
2091 | *tailp = Fcons (c, Qnil); | |
2092 | kb->kbd_queue_has_data = 1; | |
46b84797 | 2093 | c = Qnil; |
1e8bd3da RS |
2094 | if (single_kboard) |
2095 | goto wrong_kboard; | |
2096 | current_kboard = kb; | |
ef6661f7 RS |
2097 | /* This is going to exit from read_char |
2098 | so we had better get rid of this frame's stuff. */ | |
2099 | UNGCPRO; | |
1e8bd3da | 2100 | longjmp (wrong_kboard_jmpbuf, 1); |
df0f2ba1 | 2101 | } |
1e8bd3da | 2102 | #endif |
beecf6a1 | 2103 | } |
1e8bd3da | 2104 | |
284f4730 | 2105 | /* Terminate Emacs in batch mode if at eof. */ |
8c18cbfb | 2106 | if (noninteractive && INTEGERP (c) && XINT (c) < 0) |
284f4730 JB |
2107 | Fkill_emacs (make_number (1)); |
2108 | ||
8c18cbfb | 2109 | if (INTEGERP (c)) |
80645119 JB |
2110 | { |
2111 | /* Add in any extra modifiers, where appropriate. */ | |
2112 | if ((extra_keyboard_modifiers & CHAR_CTL) | |
2113 | || ((extra_keyboard_modifiers & 0177) < ' ' | |
2114 | && (extra_keyboard_modifiers & 0177) != 0)) | |
faf5e407 | 2115 | XSETINT (c, make_ctrl_char (XINT (c))); |
80645119 JB |
2116 | |
2117 | /* Transfer any other modifier bits directly from | |
2118 | extra_keyboard_modifiers to c. Ignore the actual character code | |
2119 | in the low 16 bits of extra_keyboard_modifiers. */ | |
b8d9050d | 2120 | XSETINT (c, XINT (c) | (extra_keyboard_modifiers & ~0xff7f & ~CHAR_CTL)); |
80645119 | 2121 | } |
9fa4395d | 2122 | |
284f4730 JB |
2123 | non_reread: |
2124 | ||
2fb9049e | 2125 | timer_stop_idle (); |
d9d4c147 | 2126 | |
284f4730 JB |
2127 | start_polling (); |
2128 | ||
410d4de9 RS |
2129 | if (NILP (c)) |
2130 | { | |
2131 | if (commandflag >= 0 | |
4ec4ed6a | 2132 | && !input_pending && !detect_input_pending_run_timers (0)) |
410d4de9 RS |
2133 | redisplay (); |
2134 | ||
2135 | goto wrong_kboard; | |
2136 | } | |
2137 | ||
2138 | non_reread_1: | |
2139 | ||
dfd11da7 | 2140 | /* Buffer switch events are only for internal wakeups |
7c3bc944 RS |
2141 | so don't show them to the user. |
2142 | Also, don't record a key if we already did. */ | |
2143 | if (BUFFERP (c) || key_already_recorded) | |
2144 | RETURN_UNGCPRO (c); | |
a1341f75 | 2145 | |
7f07d5ca RS |
2146 | /* Process special events within read_char |
2147 | and loop around to read another event. */ | |
017c7cb6 RS |
2148 | save = Vquit_flag; |
2149 | Vquit_flag = Qnil; | |
7f07d5ca RS |
2150 | tem = get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map, 0, 0), |
2151 | c, 0, 0), 1); | |
017c7cb6 | 2152 | Vquit_flag = save; |
7f07d5ca RS |
2153 | |
2154 | if (!NILP (tem)) | |
2155 | { | |
ba8dfba8 RS |
2156 | int was_locked = single_kboard; |
2157 | ||
7f07d5ca | 2158 | last_input_char = c; |
158f7532 | 2159 | Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt); |
ba8dfba8 RS |
2160 | |
2161 | /* Resume allowing input from any kboard, if that was true before. */ | |
2162 | if (!was_locked) | |
2163 | any_kboard_state (); | |
2164 | ||
7f07d5ca RS |
2165 | goto retry; |
2166 | } | |
2167 | ||
dfd11da7 | 2168 | /* Wipe the echo area. */ |
cdb9d665 RS |
2169 | if (echo_area_glyphs) |
2170 | safe_run_hooks (Qecho_area_clear_hook); | |
dfd11da7 | 2171 | echo_area_glyphs = 0; |
284f4730 JB |
2172 | |
2173 | /* Handle things that only apply to characters. */ | |
8c18cbfb | 2174 | if (INTEGERP (c)) |
284f4730 JB |
2175 | { |
2176 | /* If kbd_buffer_get_event gave us an EOF, return that. */ | |
86e5706b | 2177 | if (XINT (c) == -1) |
7c3bc944 | 2178 | RETURN_UNGCPRO (c); |
284f4730 | 2179 | |
8c18cbfb | 2180 | if (STRINGP (Vkeyboard_translate_table) |
845fe94e | 2181 | && XSTRING (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) |
f4255cd1 | 2182 | XSETINT (c, XSTRING (Vkeyboard_translate_table)->data[XFASTINT (c)]); |
f9414d62 | 2183 | else if ((VECTORP (Vkeyboard_translate_table) |
845fe94e RS |
2184 | && XVECTOR (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) |
2185 | || (CHAR_TABLE_P (Vkeyboard_translate_table) | |
2186 | && CHAR_TABLE_ORDINARY_SLOTS > (unsigned) XFASTINT (c))) | |
f9414d62 RS |
2187 | { |
2188 | Lisp_Object d; | |
2189 | d = Faref (Vkeyboard_translate_table, c); | |
2190 | /* nil in keyboard-translate-table means no translation. */ | |
2191 | if (!NILP (d)) | |
2192 | c = d; | |
2193 | } | |
284f4730 JB |
2194 | } |
2195 | ||
e4fe371d RS |
2196 | /* If this event is a mouse click in the menu bar, |
2197 | return just menu-bar for now. Modify the mouse click event | |
2198 | so we won't do this twice, then queue it up. */ | |
2199 | if (EVENT_HAS_PARAMETERS (c) | |
2200 | && CONSP (XCONS (c)->cdr) | |
2201 | && CONSP (EVENT_START (c)) | |
2202 | && CONSP (XCONS (EVENT_START (c))->cdr)) | |
284f4730 | 2203 | { |
e4fe371d | 2204 | Lisp_Object posn; |
284f4730 | 2205 | |
e4fe371d RS |
2206 | posn = POSN_BUFFER_POSN (EVENT_START (c)); |
2207 | /* Handle menu-bar events: | |
2208 | insert the dummy prefix event `menu-bar'. */ | |
2209 | if (EQ (posn, Qmenu_bar)) | |
2210 | { | |
2211 | /* Change menu-bar to (menu-bar) as the event "position". */ | |
2212 | POSN_BUFFER_POSN (EVENT_START (c)) = Fcons (posn, Qnil); | |
284f4730 | 2213 | |
e4fe371d RS |
2214 | also_record = c; |
2215 | Vunread_command_events = Fcons (c, Vunread_command_events); | |
2216 | c = posn; | |
284f4730 | 2217 | } |
284f4730 JB |
2218 | } |
2219 | ||
e4fe371d RS |
2220 | record_char (c); |
2221 | if (! NILP (also_record)) | |
2222 | record_char (also_record); | |
51172b6d | 2223 | |
284f4730 JB |
2224 | from_macro: |
2225 | reread_first: | |
7c3bc944 | 2226 | |
71918b75 RS |
2227 | before_command_key_count = this_command_key_count; |
2228 | before_command_echo_length = echo_length (); | |
284f4730 | 2229 | |
b8556aee | 2230 | /* Don't echo mouse motion events. */ |
8ea231fc RS |
2231 | if (echo_keystrokes |
2232 | && ! (EVENT_HAS_PARAMETERS (c) | |
2233 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_movement))) | |
e4fe371d RS |
2234 | { |
2235 | echo_char (c); | |
2236 | if (! NILP (also_record)) | |
2237 | echo_char (also_record); | |
1fc93d49 RS |
2238 | /* Once we reread a character, echoing can happen |
2239 | the next time we pause to read a new one. */ | |
0c04a67e | 2240 | ok_to_echo_at_next_pause = echo_area_glyphs; |
e4fe371d | 2241 | } |
b8556aee | 2242 | |
db8c1663 | 2243 | /* Record this character as part of the current key. */ |
b8556aee | 2244 | add_command_key (c); |
e4fe371d RS |
2245 | if (! NILP (also_record)) |
2246 | add_command_key (also_record); | |
284f4730 JB |
2247 | |
2248 | /* Re-reading in the middle of a command */ | |
2249 | reread: | |
2250 | last_input_char = c; | |
c43b1734 | 2251 | num_input_events++; |
284f4730 JB |
2252 | |
2253 | /* Process the help character specially if enabled */ | |
ecb7cb34 | 2254 | if (!NILP (Vhelp_form) && help_char_p (c)) |
284f4730 JB |
2255 | { |
2256 | Lisp_Object tem0; | |
2257 | count = specpdl_ptr - specpdl; | |
2258 | ||
2259 | record_unwind_protect (Fset_window_configuration, | |
2260 | Fcurrent_window_configuration (Qnil)); | |
2261 | ||
2262 | tem0 = Feval (Vhelp_form); | |
8c18cbfb | 2263 | if (STRINGP (tem0)) |
284f4730 JB |
2264 | internal_with_output_to_temp_buffer ("*Help*", print_help, tem0); |
2265 | ||
2266 | cancel_echoing (); | |
3cb81011 KH |
2267 | do |
2268 | c = read_char (0, 0, 0, Qnil, 0); | |
8c18cbfb | 2269 | while (BUFFERP (c)); |
ff11dfa1 | 2270 | /* Remove the help from the frame */ |
284f4730 | 2271 | unbind_to (count, Qnil); |
410d4de9 | 2272 | |
284f4730 JB |
2273 | redisplay (); |
2274 | if (EQ (c, make_number (040))) | |
2275 | { | |
2276 | cancel_echoing (); | |
3cb81011 KH |
2277 | do |
2278 | c = read_char (0, 0, 0, Qnil, 0); | |
8c18cbfb | 2279 | while (BUFFERP (c)); |
284f4730 JB |
2280 | } |
2281 | } | |
2282 | ||
7c3bc944 | 2283 | RETURN_UNGCPRO (c); |
284f4730 JB |
2284 | } |
2285 | ||
8eb4d8ef RS |
2286 | /* Record a key that came from a mouse menu. |
2287 | Record it for echoing, for this-command-keys, and so on. */ | |
2288 | ||
2289 | static void | |
2290 | record_menu_key (c) | |
2291 | Lisp_Object c; | |
2292 | { | |
2293 | /* Wipe the echo area. */ | |
2294 | echo_area_glyphs = 0; | |
2295 | ||
2296 | record_char (c); | |
2297 | ||
2298 | before_command_key_count = this_command_key_count; | |
2299 | before_command_echo_length = echo_length (); | |
2300 | ||
2301 | /* Don't echo mouse motion events. */ | |
2302 | if (echo_keystrokes) | |
2303 | { | |
2304 | echo_char (c); | |
2305 | ||
2306 | /* Once we reread a character, echoing can happen | |
2307 | the next time we pause to read a new one. */ | |
2308 | ok_to_echo_at_next_pause = 0; | |
2309 | } | |
2310 | ||
2311 | /* Record this character as part of the current key. */ | |
2312 | add_command_key (c); | |
2313 | ||
2314 | /* Re-reading in the middle of a command */ | |
2315 | last_input_char = c; | |
c43b1734 | 2316 | num_input_events++; |
8eb4d8ef RS |
2317 | } |
2318 | ||
ecb7cb34 KH |
2319 | /* Return 1 if should recognize C as "the help character". */ |
2320 | ||
2321 | int | |
2322 | help_char_p (c) | |
2323 | Lisp_Object c; | |
2324 | { | |
2325 | Lisp_Object tail; | |
2326 | ||
2327 | if (EQ (c, Vhelp_char)) | |
2328 | return 1; | |
2329 | for (tail = Vhelp_event_list; CONSP (tail); tail = XCONS (tail)->cdr) | |
2330 | if (EQ (c, XCONS (tail)->car)) | |
2331 | return 1; | |
2332 | return 0; | |
2333 | } | |
2334 | ||
e4fe371d RS |
2335 | /* Record the input event C in various ways. */ |
2336 | ||
2337 | static void | |
2338 | record_char (c) | |
2339 | Lisp_Object c; | |
2340 | { | |
2341 | total_keys++; | |
2342 | XVECTOR (recent_keys)->contents[recent_keys_index] = c; | |
2343 | if (++recent_keys_index >= NUM_RECENT_KEYS) | |
2344 | recent_keys_index = 0; | |
2345 | ||
2346 | /* Write c to the dribble file. If c is a lispy event, write | |
2347 | the event's symbol to the dribble file, in <brackets>. Bleaugh. | |
2348 | If you, dear reader, have a better idea, you've got the source. :-) */ | |
2349 | if (dribble) | |
2350 | { | |
2351 | if (INTEGERP (c)) | |
2352 | { | |
2353 | if (XUINT (c) < 0x100) | |
2354 | putc (XINT (c), dribble); | |
2355 | else | |
6de34814 | 2356 | fprintf (dribble, " 0x%x", (int) XUINT (c)); |
e4fe371d RS |
2357 | } |
2358 | else | |
2359 | { | |
2360 | Lisp_Object dribblee; | |
2361 | ||
2362 | /* If it's a structured event, take the event header. */ | |
2363 | dribblee = EVENT_HEAD (c); | |
2364 | ||
2365 | if (SYMBOLP (dribblee)) | |
2366 | { | |
2367 | putc ('<', dribble); | |
2368 | fwrite (XSYMBOL (dribblee)->name->data, sizeof (char), | |
2369 | XSYMBOL (dribblee)->name->size, | |
2370 | dribble); | |
2371 | putc ('>', dribble); | |
2372 | } | |
2373 | } | |
2374 | ||
2375 | fflush (dribble); | |
2376 | } | |
2377 | ||
2378 | store_kbd_macro_char (c); | |
2379 | ||
c43b1734 | 2380 | num_nonmacro_input_events++; |
e4fe371d RS |
2381 | } |
2382 | ||
284f4730 JB |
2383 | Lisp_Object |
2384 | print_help (object) | |
2385 | Lisp_Object object; | |
2386 | { | |
622de3e9 | 2387 | struct buffer *old = current_buffer; |
284f4730 | 2388 | Fprinc (object, Qnil); |
622de3e9 KH |
2389 | set_buffer_internal (XBUFFER (Vstandard_output)); |
2390 | call0 (intern ("help-mode")); | |
2391 | set_buffer_internal (old); | |
284f4730 JB |
2392 | return Qnil; |
2393 | } | |
2394 | ||
2395 | /* Copy out or in the info on where C-g should throw to. | |
2396 | This is used when running Lisp code from within get_char, | |
2397 | in case get_char is called recursively. | |
2398 | See read_process_output. */ | |
2399 | ||
2400 | save_getcjmp (temp) | |
2401 | jmp_buf temp; | |
2402 | { | |
2403 | bcopy (getcjmp, temp, sizeof getcjmp); | |
2404 | } | |
2405 | ||
2406 | restore_getcjmp (temp) | |
2407 | jmp_buf temp; | |
2408 | { | |
2409 | bcopy (temp, getcjmp, sizeof getcjmp); | |
2410 | } | |
284f4730 | 2411 | \f |
2eb6bfbe RM |
2412 | #ifdef HAVE_MOUSE |
2413 | ||
284f4730 JB |
2414 | /* Restore mouse tracking enablement. See Ftrack_mouse for the only use |
2415 | of this function. */ | |
a9d77f1f | 2416 | |
284f4730 JB |
2417 | static Lisp_Object |
2418 | tracking_off (old_value) | |
2419 | Lisp_Object old_value; | |
2420 | { | |
71edead1 RS |
2421 | do_mouse_tracking = old_value; |
2422 | if (NILP (old_value)) | |
284f4730 | 2423 | { |
284f4730 JB |
2424 | /* Redisplay may have been preempted because there was input |
2425 | available, and it assumes it will be called again after the | |
2426 | input has been processed. If the only input available was | |
2427 | the sort that we have just disabled, then we need to call | |
2428 | redisplay. */ | |
d9d4c147 | 2429 | if (!readable_events (1)) |
284f4730 JB |
2430 | { |
2431 | redisplay_preserve_echo_area (); | |
d9d4c147 | 2432 | get_input_pending (&input_pending, 1); |
284f4730 JB |
2433 | } |
2434 | } | |
2435 | } | |
2436 | ||
2437 | DEFUN ("track-mouse", Ftrack_mouse, Strack_mouse, 0, UNEVALLED, 0, | |
4bb994d1 JB |
2438 | "Evaluate BODY with mouse movement events enabled.\n\ |
2439 | Within a `track-mouse' form, mouse motion generates input events that\n\ | |
2440 | you can read with `read-event'.\n\ | |
2441 | Normally, mouse motion is ignored.") | |
284f4730 JB |
2442 | (args) |
2443 | Lisp_Object args; | |
2444 | { | |
2445 | int count = specpdl_ptr - specpdl; | |
2446 | Lisp_Object val; | |
2447 | ||
a9d77f1f | 2448 | record_unwind_protect (tracking_off, do_mouse_tracking); |
284f4730 | 2449 | |
f3253854 | 2450 | do_mouse_tracking = Qt; |
df0f2ba1 | 2451 | |
284f4730 JB |
2452 | val = Fprogn (args); |
2453 | return unbind_to (count, val); | |
2454 | } | |
2eb6bfbe | 2455 | |
f3253854 KH |
2456 | /* If mouse has moved on some frame, return one of those frames. |
2457 | Return 0 otherwise. */ | |
2458 | ||
2459 | static FRAME_PTR | |
2460 | some_mouse_moved () | |
2461 | { | |
2462 | Lisp_Object tail, frame; | |
2463 | ||
2464 | FOR_EACH_FRAME (tail, frame) | |
2465 | { | |
2466 | if (XFRAME (frame)->mouse_moved) | |
2467 | return XFRAME (frame); | |
2468 | } | |
2469 | ||
2470 | return 0; | |
2471 | } | |
2472 | ||
2eb6bfbe | 2473 | #endif /* HAVE_MOUSE */ |
a612e298 RS |
2474 | \f |
2475 | /* Low level keyboard/mouse input. | |
2476 | kbd_buffer_store_event places events in kbd_buffer, and | |
0646c0dd | 2477 | kbd_buffer_get_event retrieves them. */ |
a612e298 RS |
2478 | |
2479 | /* Return true iff there are any events in the queue that read-char | |
2480 | would return. If this returns false, a read-char would block. */ | |
2481 | static int | |
d9d4c147 KH |
2482 | readable_events (do_timers_now) |
2483 | int do_timers_now; | |
a612e298 | 2484 | { |
4ec4ed6a RS |
2485 | if (do_timers_now) |
2486 | timer_check (do_timers_now); | |
2487 | ||
beecf6a1 KH |
2488 | if (kbd_fetch_ptr != kbd_store_ptr) |
2489 | return 1; | |
2490 | #ifdef HAVE_MOUSE | |
f3253854 | 2491 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
beecf6a1 KH |
2492 | return 1; |
2493 | #endif | |
1e8bd3da | 2494 | if (single_kboard) |
4c52b668 | 2495 | { |
c5fdd383 | 2496 | if (current_kboard->kbd_queue_has_data) |
4c52b668 KH |
2497 | return 1; |
2498 | } | |
2499 | else | |
2500 | { | |
c5fdd383 KH |
2501 | KBOARD *kb; |
2502 | for (kb = all_kboards; kb; kb = kb->next_kboard) | |
2503 | if (kb->kbd_queue_has_data) | |
4c52b668 KH |
2504 | return 1; |
2505 | } | |
beecf6a1 | 2506 | return 0; |
a612e298 RS |
2507 | } |
2508 | ||
2509 | /* Set this for debugging, to have a way to get out */ | |
2510 | int stop_character; | |
284f4730 | 2511 | |
c5fdd383 KH |
2512 | #ifdef MULTI_KBOARD |
2513 | static KBOARD * | |
2514 | event_to_kboard (event) | |
5798cf15 KH |
2515 | struct input_event *event; |
2516 | { | |
2517 | Lisp_Object frame; | |
2518 | frame = event->frame_or_window; | |
2519 | if (CONSP (frame)) | |
2520 | frame = XCONS (frame)->car; | |
2521 | else if (WINDOWP (frame)) | |
2522 | frame = WINDOW_FRAME (XWINDOW (frame)); | |
2523 | ||
2524 | /* There are still some events that don't set this field. | |
f5b56972 KH |
2525 | For now, just ignore the problem. |
2526 | Also ignore dead frames here. */ | |
2527 | if (!FRAMEP (frame) || !FRAME_LIVE_P (XFRAME (frame))) | |
5798cf15 KH |
2528 | return 0; |
2529 | else | |
c5fdd383 | 2530 | return FRAME_KBOARD (XFRAME (frame)); |
5798cf15 KH |
2531 | } |
2532 | #endif | |
2533 | ||
284f4730 JB |
2534 | /* Store an event obtained at interrupt level into kbd_buffer, fifo */ |
2535 | ||
2536 | void | |
2537 | kbd_buffer_store_event (event) | |
2538 | register struct input_event *event; | |
2539 | { | |
2540 | if (event->kind == no_event) | |
2541 | abort (); | |
2542 | ||
2543 | if (event->kind == ascii_keystroke) | |
2544 | { | |
e9bf89a0 | 2545 | register int c = event->code & 0377; |
284f4730 | 2546 | |
faf5e407 JB |
2547 | if (event->modifiers & ctrl_modifier) |
2548 | c = make_ctrl_char (c); | |
2549 | ||
9fd7d808 RS |
2550 | c |= (event->modifiers |
2551 | & (meta_modifier | alt_modifier | |
2552 | | hyper_modifier | super_modifier)); | |
2553 | ||
86e5706b | 2554 | if (c == quit_char) |
284f4730 | 2555 | { |
3e51c7b7 | 2556 | extern SIGTYPE interrupt_signal (); |
c5fdd383 KH |
2557 | #ifdef MULTI_KBOARD |
2558 | KBOARD *kb; | |
5798cf15 KH |
2559 | struct input_event *sp; |
2560 | ||
1e8bd3da | 2561 | if (single_kboard |
c5fdd383 KH |
2562 | && (kb = FRAME_KBOARD (XFRAME (event->frame_or_window)), |
2563 | kb != current_kboard)) | |
5798cf15 | 2564 | { |
c5fdd383 | 2565 | kb->kbd_queue |
5798cf15 KH |
2566 | = Fcons (make_lispy_switch_frame (event->frame_or_window), |
2567 | Fcons (make_number (c), Qnil)); | |
c5fdd383 | 2568 | kb->kbd_queue_has_data = 1; |
5798cf15 KH |
2569 | for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++) |
2570 | { | |
2571 | if (sp == kbd_buffer + KBD_BUFFER_SIZE) | |
2572 | sp = kbd_buffer; | |
2573 | ||
c5fdd383 | 2574 | if (event_to_kboard (sp) == kb) |
5798cf15 KH |
2575 | { |
2576 | sp->kind = no_event; | |
2577 | sp->frame_or_window = Qnil; | |
2578 | } | |
2579 | } | |
2580 | return; | |
2581 | } | |
2582 | #endif | |
3e51c7b7 | 2583 | |
284f4730 | 2584 | /* If this results in a quit_char being returned to Emacs as |
3c370943 | 2585 | input, set Vlast_event_frame properly. If this doesn't |
284f4730 | 2586 | get returned to Emacs as an event, the next event read |
ff11dfa1 | 2587 | will set Vlast_event_frame again, so this is safe to do. */ |
4bb994d1 | 2588 | { |
9b8eb840 | 2589 | Lisp_Object focus; |
4bb994d1 | 2590 | |
9b8eb840 | 2591 | focus = FRAME_FOCUS_FRAME (XFRAME (event->frame_or_window)); |
4bb994d1 | 2592 | if (NILP (focus)) |
beecf6a1 | 2593 | focus = event->frame_or_window; |
4c52b668 KH |
2594 | internal_last_event_frame = focus; |
2595 | Vlast_event_frame = focus; | |
4bb994d1 | 2596 | } |
3e51c7b7 | 2597 | |
ffd56f97 | 2598 | last_event_timestamp = event->timestamp; |
284f4730 JB |
2599 | interrupt_signal (); |
2600 | return; | |
2601 | } | |
2602 | ||
2603 | if (c && c == stop_character) | |
2604 | { | |
2605 | sys_suspend (); | |
2606 | return; | |
2607 | } | |
284f4730 | 2608 | } |
3fe8e9a2 RS |
2609 | /* Don't insert two buffer_switch_event's in a row. |
2610 | Just ignore the second one. */ | |
2611 | else if (event->kind == buffer_switch_event | |
2612 | && kbd_fetch_ptr != kbd_store_ptr | |
2613 | && kbd_store_ptr->kind == buffer_switch_event) | |
2614 | return; | |
284f4730 | 2615 | |
beecf6a1 KH |
2616 | if (kbd_store_ptr - kbd_buffer == KBD_BUFFER_SIZE) |
2617 | kbd_store_ptr = kbd_buffer; | |
284f4730 JB |
2618 | |
2619 | /* Don't let the very last slot in the buffer become full, | |
2620 | since that would make the two pointers equal, | |
2621 | and that is indistinguishable from an empty buffer. | |
2622 | Discard the event if it would fill the last slot. */ | |
beecf6a1 | 2623 | if (kbd_fetch_ptr - 1 != kbd_store_ptr) |
284f4730 | 2624 | { |
beecf6a1 | 2625 | volatile struct input_event *sp = kbd_store_ptr; |
612b78ef | 2626 | sp->kind = event->kind; |
27203ead RS |
2627 | if (event->kind == selection_request_event) |
2628 | { | |
2629 | /* We must not use the ordinary copying code for this case, | |
2630 | since `part' is an enum and copying it might not copy enough | |
2631 | in this case. */ | |
612b78ef | 2632 | bcopy (event, (char *) sp, sizeof (*event)); |
27203ead RS |
2633 | } |
2634 | else | |
2635 | { | |
612b78ef KH |
2636 | sp->code = event->code; |
2637 | sp->part = event->part; | |
2638 | sp->frame_or_window = event->frame_or_window; | |
2639 | sp->modifiers = event->modifiers; | |
2640 | sp->x = event->x; | |
2641 | sp->y = event->y; | |
2642 | sp->timestamp = event->timestamp; | |
27203ead | 2643 | } |
beecf6a1 KH |
2644 | (XVECTOR (kbd_buffer_frame_or_window)->contents[kbd_store_ptr |
2645 | - kbd_buffer] | |
7b4aedb9 | 2646 | = event->frame_or_window); |
284f4730 | 2647 | |
beecf6a1 | 2648 | kbd_store_ptr++; |
284f4730 JB |
2649 | } |
2650 | } | |
a612e298 | 2651 | \f |
07de30b9 GV |
2652 | /* Discard any mouse events in the event buffer by setting them to |
2653 | no_event. */ | |
2654 | void | |
2655 | discard_mouse_events () | |
2656 | { | |
2657 | struct input_event *sp; | |
2658 | for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++) | |
2659 | { | |
2660 | if (sp == kbd_buffer + KBD_BUFFER_SIZE) | |
2661 | sp = kbd_buffer; | |
2662 | ||
2663 | if (sp->kind == mouse_click | |
2664 | #ifdef WINDOWSNT | |
2665 | || sp->kind == w32_scroll_bar_click | |
2666 | #endif | |
2667 | || sp->kind == scroll_bar_click) | |
2668 | { | |
2669 | sp->kind = no_event; | |
2670 | } | |
2671 | } | |
2672 | } | |
2673 | \f | |
a612e298 RS |
2674 | /* Read one event from the event buffer, waiting if necessary. |
2675 | The value is a Lisp object representing the event. | |
2676 | The value is nil for an event that should be ignored, | |
2677 | or that was handled here. | |
2678 | We always read and discard one event. */ | |
284f4730 JB |
2679 | |
2680 | static Lisp_Object | |
83d68044 | 2681 | kbd_buffer_get_event (kbp, used_mouse_menu) |
410d4de9 | 2682 | KBOARD **kbp; |
83d68044 | 2683 | int *used_mouse_menu; |
284f4730 JB |
2684 | { |
2685 | register int c; | |
2686 | Lisp_Object obj; | |
c04cbc3b | 2687 | EMACS_TIME next_timer_delay; |
284f4730 JB |
2688 | |
2689 | if (noninteractive) | |
2690 | { | |
2691 | c = getchar (); | |
18cd2eeb | 2692 | XSETINT (obj, c); |
f5b56972 | 2693 | *kbp = current_kboard; |
284f4730 JB |
2694 | return obj; |
2695 | } | |
2696 | ||
2697 | /* Wait until there is input available. */ | |
2698 | for (;;) | |
2699 | { | |
beecf6a1 KH |
2700 | if (kbd_fetch_ptr != kbd_store_ptr) |
2701 | break; | |
2702 | #ifdef HAVE_MOUSE | |
f3253854 | 2703 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
284f4730 | 2704 | break; |
beecf6a1 | 2705 | #endif |
284f4730 JB |
2706 | |
2707 | /* If the quit flag is set, then read_char will return | |
2708 | quit_char, so that counts as "available input." */ | |
2709 | if (!NILP (Vquit_flag)) | |
2710 | quit_throw_to_read_char (); | |
2711 | ||
2712 | /* One way or another, wait until input is available; then, if | |
2713 | interrupt handlers have not read it, read it now. */ | |
2714 | ||
2715 | #ifdef OLDVMS | |
2716 | wait_for_kbd_input (); | |
2717 | #else | |
2718 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
2719 | #ifdef SIGIO | |
2720 | gobble_input (0); | |
2721 | #endif /* SIGIO */ | |
beecf6a1 KH |
2722 | if (kbd_fetch_ptr != kbd_store_ptr) |
2723 | break; | |
2724 | #ifdef HAVE_MOUSE | |
f3253854 | 2725 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
beecf6a1 KH |
2726 | break; |
2727 | #endif | |
2728 | { | |
2729 | Lisp_Object minus_one; | |
f76475ad | 2730 | |
beecf6a1 | 2731 | XSETINT (minus_one, -1); |
d9d4c147 | 2732 | wait_reading_process_input (0, 0, minus_one, 1); |
284f4730 | 2733 | |
beecf6a1 KH |
2734 | if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr) |
2735 | /* Pass 1 for EXPECT since we just waited to have input. */ | |
2736 | read_avail_input (1); | |
2737 | } | |
284f4730 JB |
2738 | #endif /* not VMS */ |
2739 | } | |
2740 | ||
303b5b3f RS |
2741 | if (CONSP (Vunread_command_events)) |
2742 | { | |
2743 | Lisp_Object first; | |
2744 | first = XCONS (Vunread_command_events)->car; | |
2745 | Vunread_command_events = XCONS (Vunread_command_events)->cdr; | |
2746 | *kbp = current_kboard; | |
2747 | return first; | |
2748 | } | |
2749 | ||
284f4730 JB |
2750 | /* At this point, we know that there is a readable event available |
2751 | somewhere. If the event queue is empty, then there must be a | |
2752 | mouse movement enabled and available. */ | |
beecf6a1 | 2753 | if (kbd_fetch_ptr != kbd_store_ptr) |
284f4730 | 2754 | { |
cd21b839 | 2755 | struct input_event *event; |
3e51c7b7 | 2756 | |
beecf6a1 KH |
2757 | event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE) |
2758 | ? kbd_fetch_ptr | |
2759 | : kbd_buffer); | |
3e51c7b7 | 2760 | |
cd21b839 | 2761 | last_event_timestamp = event->timestamp; |
cd21b839 | 2762 | |
c5fdd383 KH |
2763 | #ifdef MULTI_KBOARD |
2764 | *kbp = event_to_kboard (event); | |
2765 | if (*kbp == 0) | |
2766 | *kbp = current_kboard; /* Better than returning null ptr? */ | |
5798cf15 | 2767 | #else |
c5fdd383 | 2768 | *kbp = &the_only_kboard; |
5798cf15 | 2769 | #endif |
beecf6a1 | 2770 | |
4bb994d1 JB |
2771 | obj = Qnil; |
2772 | ||
48e416d4 | 2773 | /* These two kinds of events get special handling |
a612e298 RS |
2774 | and don't actually appear to the command loop. |
2775 | We return nil for them. */ | |
48e416d4 RS |
2776 | if (event->kind == selection_request_event) |
2777 | { | |
598a9fa7 | 2778 | #ifdef HAVE_X11 |
1e8bd3da RS |
2779 | struct input_event copy; |
2780 | ||
4581e928 RS |
2781 | /* Remove it from the buffer before processing it, |
2782 | since otherwise swallow_events will see it | |
2783 | and process it again. */ | |
1e8bd3da | 2784 | copy = *event; |
beecf6a1 | 2785 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 2786 | input_pending = readable_events (0); |
4581e928 | 2787 | x_handle_selection_request (©); |
598a9fa7 JB |
2788 | #else |
2789 | /* We're getting selection request events, but we don't have | |
2790 | a window system. */ | |
2791 | abort (); | |
2792 | #endif | |
48e416d4 RS |
2793 | } |
2794 | ||
1e12dd87 | 2795 | else if (event->kind == selection_clear_event) |
48e416d4 | 2796 | { |
598a9fa7 | 2797 | #ifdef HAVE_X11 |
e0301c07 RS |
2798 | struct input_event copy; |
2799 | ||
2800 | /* Remove it from the buffer before processing it. */ | |
2801 | copy = *event; | |
beecf6a1 | 2802 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 2803 | input_pending = readable_events (0); |
90c2bb0c | 2804 | x_handle_selection_clear (©); |
598a9fa7 JB |
2805 | #else |
2806 | /* We're getting selection request events, but we don't have | |
2807 | a window system. */ | |
2808 | abort (); | |
2809 | #endif | |
48e416d4 | 2810 | } |
e98a93eb | 2811 | #if defined (HAVE_X11) || defined (HAVE_NTGUI) |
990acea3 RS |
2812 | else if (event->kind == delete_window_event) |
2813 | { | |
bbdc2092 RS |
2814 | /* Make an event (delete-frame (FRAME)). */ |
2815 | obj = Fcons (event->frame_or_window, Qnil); | |
af17bd2b | 2816 | obj = Fcons (Qdelete_frame, Fcons (obj, Qnil)); |
beecf6a1 | 2817 | kbd_fetch_ptr = event + 1; |
af17bd2b KH |
2818 | } |
2819 | else if (event->kind == iconify_event) | |
2820 | { | |
2821 | /* Make an event (iconify-frame (FRAME)). */ | |
2822 | obj = Fcons (event->frame_or_window, Qnil); | |
2823 | obj = Fcons (Qiconify_frame, Fcons (obj, Qnil)); | |
beecf6a1 | 2824 | kbd_fetch_ptr = event + 1; |
af17bd2b KH |
2825 | } |
2826 | else if (event->kind == deiconify_event) | |
2827 | { | |
2828 | /* Make an event (make-frame-visible (FRAME)). */ | |
2829 | obj = Fcons (event->frame_or_window, Qnil); | |
2830 | obj = Fcons (Qmake_frame_visible, Fcons (obj, Qnil)); | |
beecf6a1 | 2831 | kbd_fetch_ptr = event + 1; |
990acea3 RS |
2832 | } |
2833 | #endif | |
a8015ab5 KH |
2834 | else if (event->kind == buffer_switch_event) |
2835 | { | |
2836 | /* The value doesn't matter here; only the type is tested. */ | |
18cd2eeb | 2837 | XSETBUFFER (obj, current_buffer); |
beecf6a1 | 2838 | kbd_fetch_ptr = event + 1; |
a8015ab5 | 2839 | } |
07de30b9 | 2840 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
099787c1 RS |
2841 | else if (event->kind == menu_bar_activate_event) |
2842 | { | |
2843 | kbd_fetch_ptr = event + 1; | |
d9d4c147 | 2844 | input_pending = readable_events (0); |
e649d076 RS |
2845 | if (FRAME_LIVE_P (XFRAME (event->frame_or_window))) |
2846 | x_activate_menubar (XFRAME (event->frame_or_window)); | |
099787c1 RS |
2847 | } |
2848 | #endif | |
a612e298 | 2849 | /* Just discard these, by returning nil. |
c5fdd383 | 2850 | With MULTI_KBOARD, these events are used as placeholders |
5798cf15 KH |
2851 | when we need to randomly delete events from the queue. |
2852 | (They shouldn't otherwise be found in the buffer, | |
2853 | but on some machines it appears they do show up | |
c5fdd383 | 2854 | even without MULTI_KBOARD.) */ |
07de30b9 GV |
2855 | /* On Windows NT/9X, no_event is used to delete extraneous |
2856 | mouse events during a popup-menu call. */ | |
a612e298 | 2857 | else if (event->kind == no_event) |
beecf6a1 | 2858 | kbd_fetch_ptr = event + 1; |
48e416d4 | 2859 | |
4bb994d1 JB |
2860 | /* If this event is on a different frame, return a switch-frame this |
2861 | time, and leave the event in the queue for next time. */ | |
1e12dd87 RS |
2862 | else |
2863 | { | |
9b8eb840 | 2864 | Lisp_Object frame; |
1e12dd87 | 2865 | Lisp_Object focus; |
7b4aedb9 | 2866 | |
9b8eb840 | 2867 | frame = event->frame_or_window; |
2470a66f KH |
2868 | if (CONSP (frame)) |
2869 | frame = XCONS (frame)->car; | |
2870 | else if (WINDOWP (frame)) | |
1e12dd87 | 2871 | frame = WINDOW_FRAME (XWINDOW (frame)); |
4bb994d1 | 2872 | |
1e12dd87 RS |
2873 | focus = FRAME_FOCUS_FRAME (XFRAME (frame)); |
2874 | if (! NILP (focus)) | |
2875 | frame = focus; | |
07d2b8de | 2876 | |
4c52b668 | 2877 | if (! EQ (frame, internal_last_event_frame) |
1e12dd87 RS |
2878 | && XFRAME (frame) != selected_frame) |
2879 | obj = make_lispy_switch_frame (frame); | |
4c52b668 | 2880 | internal_last_event_frame = frame; |
4bb994d1 | 2881 | |
1e12dd87 RS |
2882 | /* If we didn't decide to make a switch-frame event, go ahead |
2883 | and build a real event from the queue entry. */ | |
cd21b839 | 2884 | |
1e12dd87 RS |
2885 | if (NILP (obj)) |
2886 | { | |
2887 | obj = make_lispy_event (event); | |
e98a93eb | 2888 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
83d68044 KH |
2889 | /* If this was a menu selection, then set the flag to inhibit |
2890 | writing to last_nonmenu_event. Don't do this if the event | |
2891 | we're returning is (menu-bar), though; that indicates the | |
2892 | beginning of the menu sequence, and we might as well leave | |
2893 | that as the `event with parameters' for this selection. */ | |
2894 | if (event->kind == menu_bar_event | |
2895 | && !(CONSP (obj) && EQ (XCONS (obj)->car, Qmenu_bar)) | |
2896 | && used_mouse_menu) | |
2897 | *used_mouse_menu = 1; | |
2898 | #endif | |
1e12dd87 RS |
2899 | |
2900 | /* Wipe out this event, to catch bugs. */ | |
2901 | event->kind = no_event; | |
beecf6a1 | 2902 | XVECTOR (kbd_buffer_frame_or_window)->contents[event - kbd_buffer] = Qnil; |
1e12dd87 | 2903 | |
beecf6a1 | 2904 | kbd_fetch_ptr = event + 1; |
1e12dd87 | 2905 | } |
4bb994d1 | 2906 | } |
284f4730 | 2907 | } |
2eb6bfbe | 2908 | #ifdef HAVE_MOUSE |
a612e298 | 2909 | /* Try generating a mouse motion event. */ |
f3253854 | 2910 | else if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
284f4730 | 2911 | { |
f3253854 | 2912 | FRAME_PTR f = some_mouse_moved (); |
7b4aedb9 | 2913 | Lisp_Object bar_window; |
3c370943 | 2914 | enum scroll_bar_part part; |
e5d77022 JB |
2915 | Lisp_Object x, y; |
2916 | unsigned long time; | |
284f4730 | 2917 | |
c5fdd383 | 2918 | *kbp = current_kboard; |
e177ac3a RS |
2919 | /* Note that this uses F to determine which display to look at. |
2920 | If there is no valid info, it does not store anything | |
2921 | so x remains nil. */ | |
2922 | x = Qnil; | |
dd26ab75 | 2923 | (*mouse_position_hook) (&f, 0, &bar_window, &part, &x, &y, &time); |
4bb994d1 JB |
2924 | |
2925 | obj = Qnil; | |
284f4730 | 2926 | |
4bb994d1 JB |
2927 | /* Decide if we should generate a switch-frame event. Don't |
2928 | generate switch-frame events for motion outside of all Emacs | |
2929 | frames. */ | |
e177ac3a | 2930 | if (!NILP (x) && f) |
cd21b839 | 2931 | { |
9b8eb840 | 2932 | Lisp_Object frame; |
4bb994d1 | 2933 | |
9b8eb840 | 2934 | frame = FRAME_FOCUS_FRAME (f); |
4bb994d1 | 2935 | if (NILP (frame)) |
18cd2eeb | 2936 | XSETFRAME (frame, f); |
4bb994d1 | 2937 | |
4c52b668 | 2938 | if (! EQ (frame, internal_last_event_frame) |
80645119 | 2939 | && XFRAME (frame) != selected_frame) |
764cb3f9 | 2940 | obj = make_lispy_switch_frame (frame); |
4c52b668 | 2941 | internal_last_event_frame = frame; |
cd21b839 | 2942 | } |
4bb994d1 | 2943 | |
df0f2ba1 | 2944 | /* If we didn't decide to make a switch-frame event, go ahead and |
4bb994d1 | 2945 | return a mouse-motion event. */ |
e177ac3a | 2946 | if (!NILP (x) && NILP (obj)) |
7b4aedb9 | 2947 | obj = make_lispy_movement (f, bar_window, part, x, y, time); |
6cbff1cb | 2948 | } |
2eb6bfbe | 2949 | #endif /* HAVE_MOUSE */ |
284f4730 JB |
2950 | else |
2951 | /* We were promised by the above while loop that there was | |
2952 | something for us to read! */ | |
2953 | abort (); | |
2954 | ||
d9d4c147 | 2955 | input_pending = readable_events (0); |
284f4730 | 2956 | |
4c52b668 | 2957 | Vlast_event_frame = internal_last_event_frame; |
3c370943 | 2958 | |
284f4730 JB |
2959 | return (obj); |
2960 | } | |
a612e298 RS |
2961 | \f |
2962 | /* Process any events that are not user-visible, | |
2963 | then return, without reading any user-visible events. */ | |
3a3b9632 RS |
2964 | |
2965 | void | |
d9d4c147 KH |
2966 | swallow_events (do_display) |
2967 | int do_display; | |
3a3b9632 | 2968 | { |
87dd9b9b RS |
2969 | int old_timers_run; |
2970 | ||
beecf6a1 | 2971 | while (kbd_fetch_ptr != kbd_store_ptr) |
3a3b9632 RS |
2972 | { |
2973 | struct input_event *event; | |
2974 | ||
beecf6a1 KH |
2975 | event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE) |
2976 | ? kbd_fetch_ptr | |
2977 | : kbd_buffer); | |
3a3b9632 RS |
2978 | |
2979 | last_event_timestamp = event->timestamp; | |
2980 | ||
2981 | /* These two kinds of events get special handling | |
2982 | and don't actually appear to the command loop. */ | |
2983 | if (event->kind == selection_request_event) | |
2984 | { | |
2985 | #ifdef HAVE_X11 | |
4581e928 | 2986 | struct input_event copy; |
e0301c07 RS |
2987 | |
2988 | /* Remove it from the buffer before processing it, | |
2989 | since otherwise swallow_events called recursively could see it | |
2990 | and process it again. */ | |
4581e928 | 2991 | copy = *event; |
beecf6a1 | 2992 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 2993 | input_pending = readable_events (0); |
4581e928 | 2994 | x_handle_selection_request (©); |
3a3b9632 RS |
2995 | #else |
2996 | /* We're getting selection request events, but we don't have | |
2997 | a window system. */ | |
2998 | abort (); | |
2999 | #endif | |
3000 | } | |
3001 | ||
3002 | else if (event->kind == selection_clear_event) | |
3003 | { | |
3004 | #ifdef HAVE_X11 | |
e0301c07 RS |
3005 | struct input_event copy; |
3006 | ||
3007 | /* Remove it from the buffer before processing it, */ | |
3008 | copy = *event; | |
3009 | ||
beecf6a1 | 3010 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3011 | input_pending = readable_events (0); |
90c2bb0c | 3012 | x_handle_selection_clear (©); |
3a3b9632 RS |
3013 | #else |
3014 | /* We're getting selection request events, but we don't have | |
3015 | a window system. */ | |
3016 | abort (); | |
3017 | #endif | |
3018 | } | |
3019 | else | |
3020 | break; | |
3021 | } | |
3022 | ||
87dd9b9b | 3023 | old_timers_run = timers_run; |
d9d4c147 | 3024 | get_input_pending (&input_pending, 1); |
87dd9b9b RS |
3025 | |
3026 | if (timers_run != old_timers_run && do_display) | |
3027 | redisplay_preserve_echo_area (); | |
3a3b9632 | 3028 | } |
a612e298 | 3029 | \f |
d9d4c147 KH |
3030 | static EMACS_TIME timer_idleness_start_time; |
3031 | ||
3032 | /* Record the start of when Emacs is idle, | |
3033 | for the sake of running idle-time timers. */ | |
3034 | ||
07a59269 | 3035 | void |
d9d4c147 KH |
3036 | timer_start_idle () |
3037 | { | |
3038 | Lisp_Object timers; | |
3039 | ||
3040 | /* If we are already in the idle state, do nothing. */ | |
3041 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3042 | return; | |
3043 | ||
3044 | EMACS_GET_TIME (timer_idleness_start_time); | |
3045 | ||
3046 | /* Mark all idle-time timers as once again candidates for running. */ | |
3047 | for (timers = Vtimer_idle_list; CONSP (timers); timers = XCONS (timers)->cdr) | |
3048 | { | |
3049 | Lisp_Object timer; | |
3050 | ||
3051 | timer = XCONS (timers)->car; | |
3052 | ||
3053 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) | |
3054 | continue; | |
3055 | XVECTOR (timer)->contents[0] = Qnil; | |
3056 | } | |
3057 | } | |
3058 | ||
3059 | /* Record that Emacs is no longer idle, so stop running idle-time timers. */ | |
3060 | ||
07a59269 | 3061 | void |
d9d4c147 KH |
3062 | timer_stop_idle () |
3063 | { | |
3064 | EMACS_SET_SECS_USECS (timer_idleness_start_time, -1, -1); | |
3065 | } | |
3066 | ||
e044e87c RS |
3067 | /* This is only for debugging. */ |
3068 | struct input_event last_timer_event; | |
3069 | ||
c04cbc3b RS |
3070 | /* Check whether a timer has fired. To prevent larger problems we simply |
3071 | disregard elements that are not proper timers. Do not make a circular | |
3072 | timer list for the time being. | |
3073 | ||
3074 | Returns the number of seconds to wait until the next timer fires. If a | |
3075 | timer is triggering now, return zero seconds. | |
3076 | If no timer is active, return -1 seconds. | |
3077 | ||
4ec4ed6a RS |
3078 | If a timer is ripe, we run it, with quitting turned off. |
3079 | ||
3080 | DO_IT_NOW is now ignored. It used to mean that we should | |
3081 | run the timer directly instead of queueing a timer-event. | |
3082 | Now we always run timers directly. */ | |
c04cbc3b RS |
3083 | |
3084 | EMACS_TIME | |
3085 | timer_check (do_it_now) | |
3086 | int do_it_now; | |
3087 | { | |
3088 | EMACS_TIME nexttime; | |
9291c072 RS |
3089 | EMACS_TIME now, idleness_now; |
3090 | Lisp_Object timers, idle_timers, chosen_timer; | |
9291c072 | 3091 | struct gcpro gcpro1, gcpro2, gcpro3; |
c04cbc3b | 3092 | |
c04cbc3b RS |
3093 | EMACS_SET_SECS (nexttime, -1); |
3094 | EMACS_SET_USECS (nexttime, -1); | |
3095 | ||
9291c072 | 3096 | /* Always consider the ordinary timers. */ |
7ea13e12 | 3097 | timers = Vtimer_list; |
9291c072 RS |
3098 | /* Consider the idle timers only if Emacs is idle. */ |
3099 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3100 | idle_timers = Vtimer_idle_list; | |
3101 | else | |
3102 | idle_timers = Qnil; | |
3103 | chosen_timer = Qnil; | |
3104 | GCPRO3 (timers, idle_timers, chosen_timer); | |
7ea13e12 | 3105 | |
9291c072 | 3106 | if (CONSP (timers) || CONSP (idle_timers)) |
c04cbc3b | 3107 | { |
9291c072 RS |
3108 | EMACS_GET_TIME (now); |
3109 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3110 | EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time); | |
3111 | } | |
c04cbc3b | 3112 | |
9291c072 RS |
3113 | while (CONSP (timers) || CONSP (idle_timers)) |
3114 | { | |
3115 | int triggertime = EMACS_SECS (now); | |
3116 | Lisp_Object *vector; | |
3117 | Lisp_Object timer, idle_timer; | |
3118 | EMACS_TIME timer_time, idle_timer_time; | |
3119 | EMACS_TIME difference, timer_difference, idle_timer_difference; | |
3120 | ||
3121 | /* Skip past invalid timers and timers already handled. */ | |
3122 | if (!NILP (timers)) | |
c04cbc3b | 3123 | { |
d9d4c147 | 3124 | timer = XCONS (timers)->car; |
9291c072 RS |
3125 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) |
3126 | { | |
3127 | timers = XCONS (timers)->cdr; | |
3128 | continue; | |
3129 | } | |
3130 | vector = XVECTOR (timer)->contents; | |
d9d4c147 | 3131 | |
9291c072 RS |
3132 | if (!INTEGERP (vector[1]) || !INTEGERP (vector[2]) |
3133 | || !INTEGERP (vector[3]) | |
3134 | || ! NILP (vector[0])) | |
3135 | { | |
3136 | timers = XCONS (timers)->cdr; | |
3137 | continue; | |
3138 | } | |
3139 | } | |
3140 | if (!NILP (idle_timers)) | |
3141 | { | |
3142 | timer = XCONS (idle_timers)->car; | |
d9d4c147 | 3143 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) |
9291c072 RS |
3144 | { |
3145 | idle_timers = XCONS (idle_timers)->cdr; | |
3146 | continue; | |
3147 | } | |
d9d4c147 KH |
3148 | vector = XVECTOR (timer)->contents; |
3149 | ||
3150 | if (!INTEGERP (vector[1]) || !INTEGERP (vector[2]) | |
9291c072 RS |
3151 | || !INTEGERP (vector[3]) |
3152 | || ! NILP (vector[0])) | |
3153 | { | |
3154 | idle_timers = XCONS (idle_timers)->cdr; | |
3155 | continue; | |
3156 | } | |
3157 | } | |
d9d4c147 | 3158 | |
9291c072 RS |
3159 | /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE |
3160 | based on the next ordinary timer. | |
3161 | TIMER_DIFFERENCE is the distance in time from NOW to when | |
3162 | this timer becomes ripe (negative if it's already ripe). */ | |
3163 | if (!NILP (timers)) | |
3164 | { | |
3165 | timer = XCONS (timers)->car; | |
3166 | vector = XVECTOR (timer)->contents; | |
d9d4c147 KH |
3167 | EMACS_SET_SECS (timer_time, |
3168 | (XINT (vector[1]) << 16) | (XINT (vector[2]))); | |
3169 | EMACS_SET_USECS (timer_time, XINT (vector[3])); | |
9291c072 RS |
3170 | EMACS_SUB_TIME (timer_difference, timer_time, now); |
3171 | } | |
ba8dfba8 | 3172 | |
9291c072 RS |
3173 | /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE |
3174 | based on the next idle timer. */ | |
3175 | if (!NILP (idle_timers)) | |
3176 | { | |
3177 | idle_timer = XCONS (idle_timers)->car; | |
3178 | vector = XVECTOR (idle_timer)->contents; | |
3179 | EMACS_SET_SECS (idle_timer_time, | |
3180 | (XINT (vector[1]) << 16) | (XINT (vector[2]))); | |
3181 | EMACS_SET_USECS (idle_timer_time, XINT (vector[3])); | |
3182 | EMACS_SUB_TIME (idle_timer_difference, idle_timer_time, idleness_now); | |
3183 | } | |
ba8dfba8 | 3184 | |
9291c072 RS |
3185 | /* Decide which timer is the next timer, |
3186 | and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly. | |
3187 | Also step down the list where we found that timer. */ | |
d9d4c147 | 3188 | |
9291c072 RS |
3189 | if (! NILP (timers) && ! NILP (idle_timers)) |
3190 | { | |
3191 | EMACS_TIME temp; | |
3192 | EMACS_SUB_TIME (temp, timer_difference, idle_timer_difference); | |
3193 | if (EMACS_TIME_NEG_P (temp)) | |
3194 | { | |
3195 | chosen_timer = timer; | |
3196 | timers = XCONS (timers)->cdr; | |
3197 | difference = timer_difference; | |
c04cbc3b | 3198 | } |
d9d4c147 | 3199 | else |
d9d4c147 | 3200 | { |
9291c072 RS |
3201 | chosen_timer = idle_timer; |
3202 | idle_timers = XCONS (idle_timers)->cdr; | |
3203 | difference = idle_timer_difference; | |
d9d4c147 | 3204 | } |
7ea13e12 | 3205 | } |
9291c072 RS |
3206 | else if (! NILP (timers)) |
3207 | { | |
3208 | chosen_timer = timer; | |
3209 | timers = XCONS (timers)->cdr; | |
3210 | difference = timer_difference; | |
3211 | } | |
3212 | else | |
3213 | { | |
3214 | chosen_timer = idle_timer; | |
3215 | idle_timers = XCONS (idle_timers)->cdr; | |
3216 | difference = idle_timer_difference; | |
3217 | } | |
3218 | vector = XVECTOR (chosen_timer)->contents; | |
3219 | ||
3220 | /* If timer is rupe, run it if it hasn't been run. */ | |
3221 | if (EMACS_TIME_NEG_P (difference) | |
3222 | || (EMACS_SECS (difference) == 0 | |
3223 | && EMACS_USECS (difference) == 0)) | |
3224 | { | |
3225 | if (NILP (vector[0])) | |
3226 | { | |
d925fb39 RS |
3227 | Lisp_Object tem; |
3228 | int was_locked = single_kboard; | |
3229 | int count = specpdl_ptr - specpdl; | |
3230 | ||
9291c072 RS |
3231 | /* Mark the timer as triggered to prevent problems if the lisp |
3232 | code fails to reschedule it right. */ | |
3233 | vector[0] = Qt; | |
3234 | ||
d925fb39 | 3235 | specbind (Qinhibit_quit, Qt); |
9291c072 | 3236 | |
d925fb39 RS |
3237 | call1 (Qtimer_event_handler, chosen_timer); |
3238 | timers_run++; | |
9291c072 | 3239 | |
d925fb39 | 3240 | unbind_to (count, Qnil); |
4ec4ed6a | 3241 | |
d925fb39 RS |
3242 | /* Resume allowing input from any kboard, if that was true before. */ |
3243 | if (!was_locked) | |
3244 | any_kboard_state (); | |
9291c072 | 3245 | |
d925fb39 RS |
3246 | /* Since we have handled the event, |
3247 | we don't need to tell the caller to wake up and do it. */ | |
9291c072 RS |
3248 | } |
3249 | } | |
3250 | else | |
3251 | /* When we encounter a timer that is still waiting, | |
3252 | return the amount of time to wait before it is ripe. */ | |
3253 | { | |
3254 | UNGCPRO; | |
9291c072 RS |
3255 | return difference; |
3256 | } | |
c04cbc3b | 3257 | } |
9291c072 | 3258 | |
7ea13e12 RS |
3259 | /* No timers are pending in the future. */ |
3260 | /* Return 0 if we generated an event, and -1 if not. */ | |
3261 | UNGCPRO; | |
c04cbc3b RS |
3262 | return nexttime; |
3263 | } | |
3264 | \f | |
284f4730 | 3265 | /* Caches for modify_event_symbol. */ |
e9bf89a0 | 3266 | static Lisp_Object accent_key_syms; |
284f4730 JB |
3267 | static Lisp_Object func_key_syms; |
3268 | static Lisp_Object mouse_syms; | |
07de30b9 GV |
3269 | #ifdef WINDOWSNT |
3270 | static Lisp_Object mouse_wheel_syms; | |
3271 | #endif | |
284f4730 | 3272 | |
e9bf89a0 RS |
3273 | /* This is a list of keysym codes for special "accent" characters. |
3274 | It parallels lispy_accent_keys. */ | |
3275 | ||
3276 | static int lispy_accent_codes[] = | |
3277 | { | |
79a7046c | 3278 | #ifdef XK_dead_circumflex |
e9bf89a0 | 3279 | XK_dead_circumflex, |
79a7046c RS |
3280 | #else |
3281 | 0, | |
3282 | #endif | |
3283 | #ifdef XK_dead_grave | |
e9bf89a0 | 3284 | XK_dead_grave, |
79a7046c RS |
3285 | #else |
3286 | 0, | |
3287 | #endif | |
3288 | #ifdef XK_dead_tilde | |
e9bf89a0 | 3289 | XK_dead_tilde, |
79a7046c RS |
3290 | #else |
3291 | 0, | |
3292 | #endif | |
3293 | #ifdef XK_dead_diaeresis | |
e9bf89a0 | 3294 | XK_dead_diaeresis, |
79a7046c RS |
3295 | #else |
3296 | 0, | |
3297 | #endif | |
3298 | #ifdef XK_dead_macron | |
e9bf89a0 | 3299 | XK_dead_macron, |
79a7046c RS |
3300 | #else |
3301 | 0, | |
3302 | #endif | |
3303 | #ifdef XK_dead_degree | |
e9bf89a0 | 3304 | XK_dead_degree, |
79a7046c RS |
3305 | #else |
3306 | 0, | |
3307 | #endif | |
3308 | #ifdef XK_dead_acute | |
e9bf89a0 | 3309 | XK_dead_acute, |
79a7046c RS |
3310 | #else |
3311 | 0, | |
3312 | #endif | |
3313 | #ifdef XK_dead_cedilla | |
e9bf89a0 | 3314 | XK_dead_cedilla, |
79a7046c RS |
3315 | #else |
3316 | 0, | |
3317 | #endif | |
3318 | #ifdef XK_dead_breve | |
e9bf89a0 | 3319 | XK_dead_breve, |
79a7046c RS |
3320 | #else |
3321 | 0, | |
3322 | #endif | |
3323 | #ifdef XK_dead_ogonek | |
e9bf89a0 | 3324 | XK_dead_ogonek, |
79a7046c RS |
3325 | #else |
3326 | 0, | |
3327 | #endif | |
3328 | #ifdef XK_dead_caron | |
e9bf89a0 | 3329 | XK_dead_caron, |
79a7046c RS |
3330 | #else |
3331 | 0, | |
3332 | #endif | |
3333 | #ifdef XK_dead_doubleacute | |
e9bf89a0 | 3334 | XK_dead_doubleacute, |
79a7046c RS |
3335 | #else |
3336 | 0, | |
3337 | #endif | |
3338 | #ifdef XK_dead_abovedot | |
e9bf89a0 | 3339 | XK_dead_abovedot, |
79a7046c RS |
3340 | #else |
3341 | 0, | |
3342 | #endif | |
e9bf89a0 RS |
3343 | }; |
3344 | ||
3345 | /* This is a list of Lisp names for special "accent" characters. | |
3346 | It parallels lispy_accent_codes. */ | |
3347 | ||
3348 | static char *lispy_accent_keys[] = | |
3349 | { | |
3350 | "dead-circumflex", | |
3351 | "dead-grave", | |
3352 | "dead-tilde", | |
3353 | "dead-diaeresis", | |
3354 | "dead-macron", | |
3355 | "dead-degree", | |
3356 | "dead-acute", | |
3357 | "dead-cedilla", | |
3358 | "dead-breve", | |
3359 | "dead-ogonek", | |
3360 | "dead-caron", | |
3361 | "dead-doubleacute", | |
3362 | "dead-abovedot", | |
3363 | }; | |
3364 | ||
e98a93eb GV |
3365 | #ifdef HAVE_NTGUI |
3366 | #define FUNCTION_KEY_OFFSET 0x0 | |
3367 | ||
3368 | char *lispy_function_keys[] = | |
3369 | { | |
3370 | 0, /* 0 */ | |
3371 | ||
3372 | 0, /* VK_LBUTTON 0x01 */ | |
3373 | 0, /* VK_RBUTTON 0x02 */ | |
3374 | "cancel", /* VK_CANCEL 0x03 */ | |
3375 | 0, /* VK_MBUTTON 0x04 */ | |
3376 | ||
3377 | 0, 0, 0, /* 0x05 .. 0x07 */ | |
3378 | ||
3379 | "backspace", /* VK_BACK 0x08 */ | |
3380 | "tab", /* VK_TAB 0x09 */ | |
3381 | ||
3382 | 0, 0, /* 0x0A .. 0x0B */ | |
3383 | ||
3384 | "clear", /* VK_CLEAR 0x0C */ | |
3385 | "return", /* VK_RETURN 0x0D */ | |
3386 | ||
3387 | 0, 0, /* 0x0E .. 0x0F */ | |
3388 | ||
3389 | "shift", /* VK_SHIFT 0x10 */ | |
3390 | "control", /* VK_CONTROL 0x11 */ | |
3391 | "menu", /* VK_MENU 0x12 */ | |
3392 | "pause", /* VK_PAUSE 0x13 */ | |
3393 | "capital", /* VK_CAPITAL 0x14 */ | |
3394 | ||
3395 | 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */ | |
3396 | ||
3397 | 0, /* VK_ESCAPE 0x1B */ | |
3398 | ||
3399 | 0, 0, 0, 0, /* 0x1C .. 0x1F */ | |
3400 | ||
3401 | 0, /* VK_SPACE 0x20 */ | |
3402 | "prior", /* VK_PRIOR 0x21 */ | |
3403 | "next", /* VK_NEXT 0x22 */ | |
3404 | "end", /* VK_END 0x23 */ | |
3405 | "home", /* VK_HOME 0x24 */ | |
3406 | "left", /* VK_LEFT 0x25 */ | |
3407 | "up", /* VK_UP 0x26 */ | |
3408 | "right", /* VK_RIGHT 0x27 */ | |
3409 | "down", /* VK_DOWN 0x28 */ | |
3410 | "select", /* VK_SELECT 0x29 */ | |
3411 | "print", /* VK_PRINT 0x2A */ | |
3412 | "execute", /* VK_EXECUTE 0x2B */ | |
3413 | "snapshot", /* VK_SNAPSHOT 0x2C */ | |
3414 | "insert", /* VK_INSERT 0x2D */ | |
3415 | "delete", /* VK_DELETE 0x2E */ | |
3416 | "help", /* VK_HELP 0x2F */ | |
3417 | ||
3418 | /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ | |
3419 | ||
3420 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3421 | ||
3422 | 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */ | |
3423 | ||
3424 | /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ | |
3425 | ||
3426 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3427 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3428 | 0, 0, 0, 0, 0, 0, 0, 0, | |
3429 | ||
e376f90d RS |
3430 | "lwindow", /* VK_LWIN 0x5B */ |
3431 | "rwindow", /* VK_RWIN 0x5C */ | |
3432 | "apps", /* VK_APPS 0x5D */ | |
e98a93eb GV |
3433 | |
3434 | 0, 0, /* 0x5E .. 0x5F */ | |
3435 | ||
3436 | "kp-0", /* VK_NUMPAD0 0x60 */ | |
3437 | "kp-1", /* VK_NUMPAD1 0x61 */ | |
3438 | "kp-2", /* VK_NUMPAD2 0x62 */ | |
3439 | "kp-3", /* VK_NUMPAD3 0x63 */ | |
3440 | "kp-4", /* VK_NUMPAD4 0x64 */ | |
3441 | "kp-5", /* VK_NUMPAD5 0x65 */ | |
3442 | "kp-6", /* VK_NUMPAD6 0x66 */ | |
3443 | "kp-7", /* VK_NUMPAD7 0x67 */ | |
3444 | "kp-8", /* VK_NUMPAD8 0x68 */ | |
3445 | "kp-9", /* VK_NUMPAD9 0x69 */ | |
3446 | "kp-multiply", /* VK_MULTIPLY 0x6A */ | |
3447 | "kp-add", /* VK_ADD 0x6B */ | |
3448 | "kp-separator", /* VK_SEPARATOR 0x6C */ | |
3449 | "kp-subtract", /* VK_SUBTRACT 0x6D */ | |
3450 | "kp-decimal", /* VK_DECIMAL 0x6E */ | |
3451 | "kp-divide", /* VK_DIVIDE 0x6F */ | |
3452 | "f1", /* VK_F1 0x70 */ | |
3453 | "f2", /* VK_F2 0x71 */ | |
3454 | "f3", /* VK_F3 0x72 */ | |
3455 | "f4", /* VK_F4 0x73 */ | |
3456 | "f5", /* VK_F5 0x74 */ | |
3457 | "f6", /* VK_F6 0x75 */ | |
3458 | "f7", /* VK_F7 0x76 */ | |
3459 | "f8", /* VK_F8 0x77 */ | |
3460 | "f9", /* VK_F9 0x78 */ | |
3461 | "f10", /* VK_F10 0x79 */ | |
3462 | "f11", /* VK_F11 0x7A */ | |
3463 | "f12", /* VK_F12 0x7B */ | |
3464 | "f13", /* VK_F13 0x7C */ | |
3465 | "f14", /* VK_F14 0x7D */ | |
3466 | "f15", /* VK_F15 0x7E */ | |
3467 | "f16", /* VK_F16 0x7F */ | |
3468 | "f17", /* VK_F17 0x80 */ | |
3469 | "f18", /* VK_F18 0x81 */ | |
3470 | "f19", /* VK_F19 0x82 */ | |
3471 | "f20", /* VK_F20 0x83 */ | |
3472 | "f21", /* VK_F21 0x84 */ | |
3473 | "f22", /* VK_F22 0x85 */ | |
3474 | "f23", /* VK_F23 0x86 */ | |
3475 | "f24", /* VK_F24 0x87 */ | |
3476 | ||
3477 | 0, 0, 0, 0, /* 0x88 .. 0x8B */ | |
3478 | 0, 0, 0, 0, /* 0x8C .. 0x8F */ | |
3479 | ||
3480 | "kp-numlock", /* VK_NUMLOCK 0x90 */ | |
3481 | "scroll", /* VK_SCROLL 0x91 */ | |
3482 | ||
e376f90d RS |
3483 | "kp-space", /* VK_NUMPAD_CLEAR 0x92 */ |
3484 | "kp-enter", /* VK_NUMPAD_ENTER 0x93 */ | |
3485 | "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */ | |
3486 | "kp-next", /* VK_NUMPAD_NEXT 0x95 */ | |
3487 | "kp-end", /* VK_NUMPAD_END 0x96 */ | |
3488 | "kp-home", /* VK_NUMPAD_HOME 0x97 */ | |
3489 | "kp-left", /* VK_NUMPAD_LEFT 0x98 */ | |
3490 | "kp-up", /* VK_NUMPAD_UP 0x99 */ | |
3491 | "kp-right", /* VK_NUMPAD_RIGHT 0x9A */ | |
3492 | "kp-down", /* VK_NUMPAD_DOWN 0x9B */ | |
3493 | "kp-insert", /* VK_NUMPAD_INSERT 0x9C */ | |
3494 | "kp-delete", /* VK_NUMPAD_DELETE 0x9D */ | |
3495 | ||
3496 | 0, 0, /* 0x9E .. 0x9F */ | |
3497 | ||
e98a93eb GV |
3498 | /* |
3499 | * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys. | |
3500 | * Used only as parameters to GetAsyncKeyState() and GetKeyState(). | |
3501 | * No other API or message will distinguish left and right keys this way. | |
3502 | */ | |
3503 | /* 0xA0 .. 0xEF */ | |
3504 | ||
3505 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3506 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3507 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3508 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3509 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3510 | ||
3511 | /* 0xF0 .. 0xF5 */ | |
3512 | ||
3513 | 0, 0, 0, 0, 0, 0, | |
3514 | ||
3515 | "attn", /* VK_ATTN 0xF6 */ | |
3516 | "crsel", /* VK_CRSEL 0xF7 */ | |
3517 | "exsel", /* VK_EXSEL 0xF8 */ | |
3518 | "ereof", /* VK_EREOF 0xF9 */ | |
3519 | "play", /* VK_PLAY 0xFA */ | |
3520 | "zoom", /* VK_ZOOM 0xFB */ | |
3521 | "noname", /* VK_NONAME 0xFC */ | |
3522 | "pa1", /* VK_PA1 0xFD */ | |
3523 | "oem_clear", /* VK_OEM_CLEAR 0xFE */ | |
3524 | }; | |
3525 | ||
04f215f0 | 3526 | #else /* not HAVE_NTGUI */ |
e98a93eb | 3527 | |
37cd9f30 KH |
3528 | #ifdef XK_kana_A |
3529 | static char *lispy_kana_keys[] = | |
3530 | { | |
3531 | /* X Keysym value */ | |
3532 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */ | |
3533 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */ | |
3534 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */ | |
3535 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */ | |
3536 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */ | |
3537 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */ | |
3538 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */ | |
3539 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0, | |
3540 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */ | |
3541 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */ | |
3542 | 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket", | |
3543 | "kana-comma", "kana-conjunctive", "kana-WO", "kana-a", | |
3544 | "kana-i", "kana-u", "kana-e", "kana-o", | |
3545 | "kana-ya", "kana-yu", "kana-yo", "kana-tsu", | |
3546 | "prolongedsound", "kana-A", "kana-I", "kana-U", | |
3547 | "kana-E", "kana-O", "kana-KA", "kana-KI", | |
3548 | "kana-KU", "kana-KE", "kana-KO", "kana-SA", | |
3549 | "kana-SHI", "kana-SU", "kana-SE", "kana-SO", | |
3550 | "kana-TA", "kana-CHI", "kana-TSU", "kana-TE", | |
3551 | "kana-TO", "kana-NA", "kana-NI", "kana-NU", | |
3552 | "kana-NE", "kana-NO", "kana-HA", "kana-HI", | |
3553 | "kana-FU", "kana-HE", "kana-HO", "kana-MA", | |
3554 | "kana-MI", "kana-MU", "kana-ME", "kana-MO", | |
3555 | "kana-YA", "kana-YU", "kana-YO", "kana-RA", | |
3556 | "kana-RI", "kana-RU", "kana-RE", "kana-RO", | |
3557 | "kana-WA", "kana-N", "voicedsound", "semivoicedsound", | |
3558 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */ | |
3559 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */ | |
3560 | }; | |
3561 | #endif /* XK_kana_A */ | |
3562 | ||
04f215f0 RS |
3563 | #define FUNCTION_KEY_OFFSET 0xff00 |
3564 | ||
284f4730 JB |
3565 | /* You'll notice that this table is arranged to be conveniently |
3566 | indexed by X Windows keysym values. */ | |
3567 | static char *lispy_function_keys[] = | |
3568 | { | |
3569 | /* X Keysym value */ | |
3570 | ||
80e4aa30 | 3571 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */ |
86e5706b RS |
3572 | "backspace", |
3573 | "tab", | |
3574 | "linefeed", | |
3575 | "clear", | |
3576 | 0, | |
3577 | "return", | |
3578 | 0, 0, | |
3579 | 0, 0, 0, /* 0xff10 */ | |
3580 | "pause", | |
3581 | 0, 0, 0, 0, 0, 0, 0, | |
3582 | "escape", | |
3583 | 0, 0, 0, 0, | |
37cd9f30 KH |
3584 | 0, "kanji", "muhenkan", |
3585 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */ | |
86e5706b RS |
3586 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */ |
3587 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */ | |
3588 | ||
284f4730 JB |
3589 | "home", /* 0xff50 */ /* IsCursorKey */ |
3590 | "left", | |
3591 | "up", | |
3592 | "right", | |
3593 | "down", | |
3594 | "prior", | |
3595 | "next", | |
3596 | "end", | |
3597 | "begin", | |
3598 | 0, /* 0xff59 */ | |
3599 | 0, 0, 0, 0, 0, 0, | |
3600 | "select", /* 0xff60 */ /* IsMiscFunctionKey */ | |
3601 | "print", | |
3602 | "execute", | |
3603 | "insert", | |
3604 | 0, /* 0xff64 */ | |
3605 | "undo", | |
3606 | "redo", | |
3607 | "menu", | |
3608 | "find", | |
3609 | "cancel", | |
3610 | "help", | |
3611 | "break", /* 0xff6b */ | |
3612 | ||
9fdbfdf8 | 3613 | 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0, |
284f4730 | 3614 | 0, /* 0xff76 */ |
36ae397e | 3615 | 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */ |
284f4730 JB |
3616 | "kp-space", /* 0xff80 */ /* IsKeypadKey */ |
3617 | 0, 0, 0, 0, 0, 0, 0, 0, | |
3618 | "kp-tab", /* 0xff89 */ | |
3619 | 0, 0, 0, | |
3620 | "kp-enter", /* 0xff8d */ | |
3621 | 0, 0, 0, | |
3622 | "kp-f1", /* 0xff91 */ | |
3623 | "kp-f2", | |
3624 | "kp-f3", | |
3625 | "kp-f4", | |
872157e7 RS |
3626 | "kp-home", /* 0xff95 */ |
3627 | "kp-left", | |
3628 | "kp-up", | |
3629 | "kp-right", | |
3630 | "kp-down", | |
3631 | "kp-prior", /* kp-page-up */ | |
3632 | "kp-next", /* kp-page-down */ | |
3633 | "kp-end", | |
3634 | "kp-begin", | |
3635 | "kp-insert", | |
3636 | "kp-delete", | |
3637 | 0, /* 0xffa0 */ | |
3638 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
284f4730 JB |
3639 | "kp-multiply", /* 0xffaa */ |
3640 | "kp-add", | |
3641 | "kp-separator", | |
3642 | "kp-subtract", | |
3643 | "kp-decimal", | |
3644 | "kp-divide", /* 0xffaf */ | |
3645 | "kp-0", /* 0xffb0 */ | |
3646 | "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9", | |
3647 | 0, /* 0xffba */ | |
3648 | 0, 0, | |
3649 | "kp-equal", /* 0xffbd */ | |
3650 | "f1", /* 0xffbe */ /* IsFunctionKey */ | |
86e5706b RS |
3651 | "f2", |
3652 | "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */ | |
3653 | "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", | |
3654 | "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */ | |
3655 | "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34", | |
3656 | "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */ | |
3657 | 0, 0, 0, 0, 0, 0, 0, 0, | |
3658 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */ | |
3659 | 0, 0, 0, 0, 0, 0, 0, "delete" | |
04f215f0 | 3660 | }; |
284f4730 | 3661 | |
04f215f0 RS |
3662 | /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */ |
3663 | #define ISO_FUNCTION_KEY_OFFSET 0xfe00 | |
3664 | ||
3665 | static char *iso_lispy_function_keys[] = | |
3666 | { | |
3667 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */ | |
3668 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */ | |
3669 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */ | |
3670 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */ | |
3671 | "iso-lefttab", /* 0xfe20 */ | |
3672 | "iso-move-line-up", "iso-move-line-down", | |
3673 | "iso-partial-line-up", "iso-partial-line-down", | |
3674 | "iso-partial-space-left", "iso-partial-space-right", | |
3675 | "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */ | |
3676 | "iso-release-margin-left", "iso-release-margin-right", | |
3677 | "iso-release-both-margins", | |
3678 | "iso-fast-cursor-left", "iso-fast-cursor-right", | |
3679 | "iso-fast-cursor-up", "iso-fast-cursor-down", | |
3680 | "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */ | |
3681 | "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */ | |
3682 | }; | |
3683 | ||
3684 | #endif /* not HAVE_NTGUI */ | |
e98a93eb | 3685 | |
df0f2ba1 | 3686 | static char *lispy_mouse_names[] = |
284f4730 JB |
3687 | { |
3688 | "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5" | |
3689 | }; | |
3690 | ||
07de30b9 GV |
3691 | #ifdef WINDOWSNT |
3692 | /* mouse-wheel events are generated by the wheel on devices such as | |
3693 | the MS Intellimouse. The wheel sits in between the left and right | |
3694 | mouse buttons, and is typically used to scroll or zoom the window | |
3695 | underneath the pointer. mouse-wheel events specify the object on | |
3696 | which they operate, and a delta corresponding to the amount and | |
3697 | direction that the wheel is rotated. Clicking the mouse-wheel | |
3698 | generates a mouse-2 event. */ | |
3699 | static char *lispy_mouse_wheel_names[] = | |
3700 | { | |
3701 | "mouse-wheel" | |
3702 | }; | |
3703 | #endif /* WINDOWSNT */ | |
3704 | ||
3c370943 | 3705 | /* Scroll bar parts. */ |
4bb994d1 | 3706 | Lisp_Object Qabove_handle, Qhandle, Qbelow_handle; |
db08707d | 3707 | Lisp_Object Qup, Qdown; |
4bb994d1 | 3708 | |
3c370943 JB |
3709 | /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */ |
3710 | Lisp_Object *scroll_bar_parts[] = { | |
db08707d RS |
3711 | &Qabove_handle, &Qhandle, &Qbelow_handle, |
3712 | &Qup, &Qdown, | |
4bb994d1 JB |
3713 | }; |
3714 | ||
3715 | ||
7b4aedb9 | 3716 | /* A vector, indexed by button number, giving the down-going location |
3c370943 | 3717 | of currently depressed buttons, both scroll bar and non-scroll bar. |
7b4aedb9 JB |
3718 | |
3719 | The elements have the form | |
3720 | (BUTTON-NUMBER MODIFIER-MASK . REST) | |
3721 | where REST is the cdr of a position as it would be reported in the event. | |
3722 | ||
3723 | The make_lispy_event function stores positions here to tell the | |
3724 | difference between click and drag events, and to store the starting | |
3725 | location to be included in drag events. */ | |
3726 | ||
3727 | static Lisp_Object button_down_location; | |
88cb0656 | 3728 | |
fbcd35bd JB |
3729 | /* Information about the most recent up-going button event: Which |
3730 | button, what location, and what time. */ | |
3731 | ||
559f9d04 RS |
3732 | static int last_mouse_button; |
3733 | static int last_mouse_x; | |
3734 | static int last_mouse_y; | |
3735 | static unsigned long button_down_time; | |
fbcd35bd | 3736 | |
564dc952 JB |
3737 | /* The maximum time between clicks to make a double-click, |
3738 | or Qnil to disable double-click detection, | |
3739 | or Qt for no time limit. */ | |
3740 | Lisp_Object Vdouble_click_time; | |
fbcd35bd JB |
3741 | |
3742 | /* The number of clicks in this multiple-click. */ | |
3743 | ||
3744 | int double_click_count; | |
3745 | ||
284f4730 JB |
3746 | /* Given a struct input_event, build the lisp event which represents |
3747 | it. If EVENT is 0, build a mouse movement event from the mouse | |
88cb0656 JB |
3748 | movement buffer, which should have a movement event in it. |
3749 | ||
3750 | Note that events must be passed to this function in the order they | |
3751 | are received; this function stores the location of button presses | |
3752 | in order to build drag events when the button is released. */ | |
284f4730 JB |
3753 | |
3754 | static Lisp_Object | |
3755 | make_lispy_event (event) | |
3756 | struct input_event *event; | |
3757 | { | |
79a7046c RS |
3758 | int i; |
3759 | ||
0220c518 | 3760 | switch (SWITCH_ENUM_CAST (event->kind)) |
284f4730 | 3761 | { |
284f4730 JB |
3762 | /* A simple keystroke. */ |
3763 | case ascii_keystroke: | |
86e5706b | 3764 | { |
9343ab07 | 3765 | Lisp_Object lispy_c; |
e9bf89a0 | 3766 | int c = event->code & 0377; |
5a1c6df8 JB |
3767 | /* Turn ASCII characters into control characters |
3768 | when proper. */ | |
3769 | if (event->modifiers & ctrl_modifier) | |
d205953b JB |
3770 | c = make_ctrl_char (c); |
3771 | ||
3772 | /* Add in the other modifier bits. We took care of ctrl_modifier | |
3773 | just above, and the shift key was taken care of by the X code, | |
3774 | and applied to control characters by make_ctrl_char. */ | |
86e5706b RS |
3775 | c |= (event->modifiers |
3776 | & (meta_modifier | alt_modifier | |
3777 | | hyper_modifier | super_modifier)); | |
32454a9f RS |
3778 | /* Distinguish Shift-SPC from SPC. */ |
3779 | if ((event->code & 0377) == 040 | |
3780 | && event->modifiers & shift_modifier) | |
3781 | c |= shift_modifier; | |
559f9d04 | 3782 | button_down_time = 0; |
bb9e9bed | 3783 | XSETFASTINT (lispy_c, c); |
9343ab07 | 3784 | return lispy_c; |
86e5706b | 3785 | } |
284f4730 JB |
3786 | |
3787 | /* A function key. The symbol may need to have modifier prefixes | |
3788 | tacked onto it. */ | |
3789 | case non_ascii_keystroke: | |
559f9d04 | 3790 | button_down_time = 0; |
e9bf89a0 RS |
3791 | |
3792 | for (i = 0; i < sizeof (lispy_accent_codes) / sizeof (int); i++) | |
3793 | if (event->code == lispy_accent_codes[i]) | |
3794 | return modify_event_symbol (i, | |
3795 | event->modifiers, | |
80e4aa30 | 3796 | Qfunction_key, Qnil, |
e9bf89a0 RS |
3797 | lispy_accent_keys, &accent_key_syms, |
3798 | (sizeof (lispy_accent_keys) | |
3799 | / sizeof (lispy_accent_keys[0]))); | |
3800 | ||
270a208f | 3801 | /* Handle system-specific keysyms. */ |
80e4aa30 RS |
3802 | if (event->code & (1 << 28)) |
3803 | { | |
3804 | /* We need to use an alist rather than a vector as the cache | |
3805 | since we can't make a vector long enuf. */ | |
142e6c73 KH |
3806 | if (NILP (current_kboard->system_key_syms)) |
3807 | current_kboard->system_key_syms = Fcons (Qnil, Qnil); | |
2c834fb3 | 3808 | return modify_event_symbol (event->code, |
80e4aa30 | 3809 | event->modifiers, |
7c97ffdc KH |
3810 | Qfunction_key, |
3811 | current_kboard->Vsystem_key_alist, | |
142e6c73 KH |
3812 | 0, ¤t_kboard->system_key_syms, |
3813 | (unsigned)-1); | |
80e4aa30 RS |
3814 | } |
3815 | ||
37cd9f30 KH |
3816 | #ifdef XK_kana_A |
3817 | if (event->code >= 0x400 && event->code < 0x500) | |
3818 | return modify_event_symbol (event->code - 0x400, | |
3819 | event->modifiers & ~shift_modifier, | |
3820 | Qfunction_key, Qnil, | |
3821 | lispy_kana_keys, &func_key_syms, | |
3822 | (sizeof (lispy_kana_keys) | |
3823 | / sizeof (lispy_kana_keys[0]))); | |
3824 | #endif /* XK_kana_A */ | |
3825 | ||
111c4138 | 3826 | #ifdef ISO_FUNCTION_KEY_OFFSET |
04f215f0 RS |
3827 | if (event->code < FUNCTION_KEY_OFFSET |
3828 | && event->code >= ISO_FUNCTION_KEY_OFFSET) | |
3829 | return modify_event_symbol (event->code - ISO_FUNCTION_KEY_OFFSET, | |
3830 | event->modifiers, | |
3831 | Qfunction_key, Qnil, | |
3832 | iso_lispy_function_keys, &func_key_syms, | |
3833 | (sizeof (iso_lispy_function_keys) | |
3834 | / sizeof (iso_lispy_function_keys[0]))); | |
3835 | else | |
111c4138 | 3836 | #endif |
04f215f0 RS |
3837 | return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET, |
3838 | event->modifiers, | |
3839 | Qfunction_key, Qnil, | |
3840 | lispy_function_keys, &func_key_syms, | |
3841 | (sizeof (lispy_function_keys) | |
3842 | / sizeof (lispy_function_keys[0]))); | |
284f4730 | 3843 | |
514354e9 | 3844 | #ifdef HAVE_MOUSE |
df0f2ba1 | 3845 | /* A mouse click. Figure out where it is, decide whether it's |
88cb0656 | 3846 | a press, click or drag, and build the appropriate structure. */ |
284f4730 | 3847 | case mouse_click: |
3c370943 | 3848 | case scroll_bar_click: |
284f4730 | 3849 | { |
e9bf89a0 | 3850 | int button = event->code; |
559f9d04 | 3851 | int is_double; |
7b4aedb9 | 3852 | Lisp_Object position; |
dbc4e1c1 JB |
3853 | Lisp_Object *start_pos_ptr; |
3854 | Lisp_Object start_pos; | |
284f4730 | 3855 | |
7b4aedb9 | 3856 | if (button < 0 || button >= NUM_MOUSE_BUTTONS) |
88cb0656 JB |
3857 | abort (); |
3858 | ||
7b4aedb9 JB |
3859 | /* Build the position as appropriate for this mouse click. */ |
3860 | if (event->kind == mouse_click) | |
284f4730 | 3861 | { |
7b4aedb9 | 3862 | int part; |
598a9fa7 | 3863 | FRAME_PTR f = XFRAME (event->frame_or_window); |
0aafc975 | 3864 | Lisp_Object window; |
7b4aedb9 | 3865 | Lisp_Object posn; |
9e20143a RS |
3866 | int row, column; |
3867 | ||
5da3133a RS |
3868 | /* Ignore mouse events that were made on frame that |
3869 | have been deleted. */ | |
3870 | if (! FRAME_LIVE_P (f)) | |
3871 | return Qnil; | |
3872 | ||
9e20143a | 3873 | pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), |
6c6a9be8 | 3874 | &column, &row, NULL, 1); |
7b4aedb9 | 3875 | |
eef045bf RS |
3876 | #ifndef USE_X_TOOLKIT |
3877 | /* In the non-toolkit version, clicks on the menu bar | |
3878 | are ordinary button events in the event buffer. | |
3879 | Distinguish them, and invoke the menu. | |
3880 | ||
3881 | (In the toolkit version, the toolkit handles the menu bar | |
3882 | and Emacs doesn't know about it until after the user | |
3883 | makes a selection.) */ | |
2ee250ec RS |
3884 | if (row >= 0 && row < FRAME_MENU_BAR_LINES (f) |
3885 | && (event->modifiers & down_modifier)) | |
bb936752 | 3886 | { |
b7c49376 | 3887 | Lisp_Object items, item; |
0a0e8fe6 RS |
3888 | int hpos; |
3889 | int i; | |
3890 | ||
2ee250ec | 3891 | #if 0 |
0a0e8fe6 RS |
3892 | /* Activate the menu bar on the down event. If the |
3893 | up event comes in before the menu code can deal with it, | |
3894 | just ignore it. */ | |
3895 | if (! (event->modifiers & down_modifier)) | |
3896 | return Qnil; | |
2ee250ec | 3897 | #endif |
0aafc975 | 3898 | |
f2ae6b3f | 3899 | item = Qnil; |
5ec75a55 | 3900 | items = FRAME_MENU_BAR_ITEMS (f); |
35b3402f | 3901 | for (i = 0; i < XVECTOR (items)->size; i += 4) |
5ec75a55 RS |
3902 | { |
3903 | Lisp_Object pos, string; | |
b7c49376 | 3904 | string = XVECTOR (items)->contents[i + 1]; |
35b3402f | 3905 | pos = XVECTOR (items)->contents[i + 3]; |
b7c49376 RS |
3906 | if (NILP (string)) |
3907 | break; | |
9e20143a RS |
3908 | if (column >= XINT (pos) |
3909 | && column < XINT (pos) + XSTRING (string)->size) | |
b7c49376 RS |
3910 | { |
3911 | item = XVECTOR (items)->contents[i]; | |
3912 | break; | |
3913 | } | |
5ec75a55 | 3914 | } |
9e20143a | 3915 | |
5ec75a55 RS |
3916 | position |
3917 | = Fcons (event->frame_or_window, | |
3918 | Fcons (Qmenu_bar, | |
3919 | Fcons (Fcons (event->x, event->y), | |
3920 | Fcons (make_number (event->timestamp), | |
3921 | Qnil)))); | |
3922 | ||
b7c49376 | 3923 | return Fcons (item, Fcons (position, Qnil)); |
5ec75a55 | 3924 | } |
eef045bf | 3925 | #endif /* not USE_X_TOOLKIT */ |
0aafc975 | 3926 | |
9e20143a | 3927 | window = window_from_coordinates (f, column, row, &part); |
0aafc975 | 3928 | |
8c18cbfb | 3929 | if (!WINDOWP (window)) |
78ced549 RS |
3930 | { |
3931 | window = event->frame_or_window; | |
3932 | posn = Qnil; | |
3933 | } | |
284f4730 | 3934 | else |
7b4aedb9 | 3935 | { |
9e20143a | 3936 | int pixcolumn, pixrow; |
c8738c33 | 3937 | column -= WINDOW_LEFT_MARGIN (XWINDOW (window)); |
9e20143a RS |
3938 | row -= XINT (XWINDOW (window)->top); |
3939 | glyph_to_pixel_coords (f, column, row, &pixcolumn, &pixrow); | |
3940 | XSETINT (event->x, pixcolumn); | |
3941 | XSETINT (event->y, pixrow); | |
dbc4e1c1 | 3942 | |
7b4aedb9 JB |
3943 | if (part == 1) |
3944 | posn = Qmode_line; | |
3945 | else if (part == 2) | |
3946 | posn = Qvertical_line; | |
3947 | else | |
18cd2eeb KH |
3948 | XSETINT (posn, |
3949 | buffer_posn_from_coords (XWINDOW (window), | |
3950 | column, row)); | |
7b4aedb9 JB |
3951 | } |
3952 | ||
5ec75a55 RS |
3953 | position |
3954 | = Fcons (window, | |
3955 | Fcons (posn, | |
3956 | Fcons (Fcons (event->x, event->y), | |
3957 | Fcons (make_number (event->timestamp), | |
3958 | Qnil)))); | |
284f4730 | 3959 | } |
7b4aedb9 | 3960 | else |
88cb0656 | 3961 | { |
9e20143a RS |
3962 | Lisp_Object window; |
3963 | Lisp_Object portion_whole; | |
3964 | Lisp_Object part; | |
3965 | ||
3966 | window = event->frame_or_window; | |
3967 | portion_whole = Fcons (event->x, event->y); | |
3968 | part = *scroll_bar_parts[(int) event->part]; | |
7b4aedb9 | 3969 | |
db08707d RS |
3970 | position |
3971 | = Fcons (window, | |
3972 | Fcons (Qvertical_scroll_bar, | |
3973 | Fcons (portion_whole, | |
3974 | Fcons (make_number (event->timestamp), | |
3975 | Fcons (part, Qnil))))); | |
88cb0656 JB |
3976 | } |
3977 | ||
dbc4e1c1 JB |
3978 | start_pos_ptr = &XVECTOR (button_down_location)->contents[button]; |
3979 | ||
3980 | start_pos = *start_pos_ptr; | |
3981 | *start_pos_ptr = Qnil; | |
7b4aedb9 | 3982 | |
559f9d04 RS |
3983 | is_double = (button == last_mouse_button |
3984 | && XINT (event->x) == last_mouse_x | |
3985 | && XINT (event->y) == last_mouse_y | |
3986 | && button_down_time != 0 | |
3987 | && (EQ (Vdouble_click_time, Qt) | |
3988 | || (INTEGERP (Vdouble_click_time) | |
3989 | && ((int)(event->timestamp - button_down_time) | |
3990 | < XINT (Vdouble_click_time))))); | |
3991 | last_mouse_button = button; | |
3992 | last_mouse_x = XINT (event->x); | |
3993 | last_mouse_y = XINT (event->y); | |
3994 | ||
7b4aedb9 JB |
3995 | /* If this is a button press, squirrel away the location, so |
3996 | we can decide later whether it was a click or a drag. */ | |
3997 | if (event->modifiers & down_modifier) | |
559f9d04 RS |
3998 | { |
3999 | if (is_double) | |
4000 | { | |
4001 | double_click_count++; | |
4002 | event->modifiers |= ((double_click_count > 2) | |
4003 | ? triple_modifier | |
4004 | : double_modifier); | |
4005 | } | |
4006 | else | |
4007 | double_click_count = 1; | |
4008 | button_down_time = event->timestamp; | |
4009 | *start_pos_ptr = Fcopy_alist (position); | |
4010 | } | |
7b4aedb9 | 4011 | |
88cb0656 | 4012 | /* Now we're releasing a button - check the co-ordinates to |
7b4aedb9 | 4013 | see if this was a click or a drag. */ |
88cb0656 JB |
4014 | else if (event->modifiers & up_modifier) |
4015 | { | |
48e416d4 RS |
4016 | /* If we did not see a down before this up, |
4017 | ignore the up. Probably this happened because | |
4018 | the down event chose a menu item. | |
4019 | It would be an annoyance to treat the release | |
4020 | of the button that chose the menu item | |
4021 | as a separate event. */ | |
4022 | ||
8c18cbfb | 4023 | if (!CONSP (start_pos)) |
48e416d4 RS |
4024 | return Qnil; |
4025 | ||
88cb0656 | 4026 | event->modifiers &= ~up_modifier; |
48e416d4 | 4027 | #if 0 /* Formerly we treated an up with no down as a click event. */ |
8c18cbfb | 4028 | if (!CONSP (start_pos)) |
dbc4e1c1 JB |
4029 | event->modifiers |= click_modifier; |
4030 | else | |
48e416d4 | 4031 | #endif |
dbc4e1c1 JB |
4032 | { |
4033 | /* The third element of every position should be the (x,y) | |
4034 | pair. */ | |
9b8eb840 | 4035 | Lisp_Object down; |
dbc4e1c1 | 4036 | |
9b8eb840 | 4037 | down = Fnth (make_number (2), start_pos); |
fbcd35bd JB |
4038 | if (EQ (event->x, XCONS (down)->car) |
4039 | && EQ (event->y, XCONS (down)->cdr)) | |
4040 | { | |
bc536d84 | 4041 | event->modifiers |= click_modifier; |
fbcd35bd JB |
4042 | } |
4043 | else | |
4044 | { | |
559f9d04 | 4045 | button_down_time = 0; |
fbcd35bd JB |
4046 | event->modifiers |= drag_modifier; |
4047 | } | |
bc536d84 RS |
4048 | /* Don't check is_double; treat this as multiple |
4049 | if the down-event was multiple. */ | |
4050 | if (double_click_count > 1) | |
4051 | event->modifiers |= ((double_click_count > 2) | |
4052 | ? triple_modifier | |
4053 | : double_modifier); | |
dbc4e1c1 | 4054 | } |
88cb0656 JB |
4055 | } |
4056 | else | |
4057 | /* Every mouse event should either have the down_modifier or | |
7b4aedb9 | 4058 | the up_modifier set. */ |
88cb0656 JB |
4059 | abort (); |
4060 | ||
88cb0656 | 4061 | { |
7b4aedb9 | 4062 | /* Get the symbol we should use for the mouse click. */ |
9b8eb840 KH |
4063 | Lisp_Object head; |
4064 | ||
4065 | head = modify_event_symbol (button, | |
4066 | event->modifiers, | |
4067 | Qmouse_click, Qnil, | |
4068 | lispy_mouse_names, &mouse_syms, | |
4069 | (sizeof (lispy_mouse_names) | |
4070 | / sizeof (lispy_mouse_names[0]))); | |
88cb0656 | 4071 | if (event->modifiers & drag_modifier) |
dbc4e1c1 JB |
4072 | return Fcons (head, |
4073 | Fcons (start_pos, | |
4074 | Fcons (position, | |
4075 | Qnil))); | |
fbcd35bd JB |
4076 | else if (event->modifiers & (double_modifier | triple_modifier)) |
4077 | return Fcons (head, | |
4078 | Fcons (position, | |
4079 | Fcons (make_number (double_click_count), | |
4080 | Qnil))); | |
88cb0656 JB |
4081 | else |
4082 | return Fcons (head, | |
7b4aedb9 | 4083 | Fcons (position, |
88cb0656 JB |
4084 | Qnil)); |
4085 | } | |
284f4730 | 4086 | } |
db08707d RS |
4087 | |
4088 | #ifdef WINDOWSNT | |
fbd6baed | 4089 | case w32_scroll_bar_click: |
db08707d RS |
4090 | { |
4091 | int button = event->code; | |
4092 | int is_double; | |
4093 | Lisp_Object position; | |
4094 | Lisp_Object *start_pos_ptr; | |
4095 | Lisp_Object start_pos; | |
4096 | ||
4097 | if (button < 0 || button >= NUM_MOUSE_BUTTONS) | |
4098 | abort (); | |
4099 | ||
4100 | { | |
4101 | Lisp_Object window; | |
4102 | Lisp_Object portion_whole; | |
4103 | Lisp_Object part; | |
4104 | ||
4105 | window = event->frame_or_window; | |
4106 | portion_whole = Fcons (event->x, event->y); | |
4107 | part = *scroll_bar_parts[(int) event->part]; | |
4108 | ||
4109 | position = | |
4110 | Fcons (window, | |
4111 | Fcons (Qvertical_scroll_bar, | |
4112 | Fcons (portion_whole, | |
4113 | Fcons (make_number (event->timestamp), | |
4114 | Fcons (part, Qnil))))); | |
4115 | } | |
4116 | ||
fbd6baed | 4117 | /* Always treat W32 scroll bar events as clicks. */ |
db08707d RS |
4118 | event->modifiers |= click_modifier; |
4119 | ||
4120 | { | |
4121 | /* Get the symbol we should use for the mouse click. */ | |
4122 | Lisp_Object head; | |
4123 | ||
4124 | head = modify_event_symbol (button, | |
4125 | event->modifiers, | |
4126 | Qmouse_click, Qnil, | |
4127 | lispy_mouse_names, &mouse_syms, | |
4128 | (sizeof (lispy_mouse_names) | |
4129 | / sizeof (lispy_mouse_names[0]))); | |
4130 | return Fcons (head, | |
4131 | Fcons (position, | |
4132 | Qnil)); | |
4133 | } | |
4134 | } | |
07de30b9 GV |
4135 | case mouse_wheel: |
4136 | { | |
4137 | int part; | |
4138 | FRAME_PTR f = XFRAME (event->frame_or_window); | |
4139 | Lisp_Object window; | |
4140 | Lisp_Object posn; | |
4141 | Lisp_Object head, position; | |
4142 | int row, column; | |
4143 | ||
4144 | /* Ignore mouse events that were made on frame that | |
4145 | have been deleted. */ | |
4146 | if (! FRAME_LIVE_P (f)) | |
4147 | return Qnil; | |
4148 | pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), | |
4149 | &column, &row, NULL, 1); | |
4150 | window = window_from_coordinates (f, column, row, &part); | |
4151 | ||
4152 | if (!WINDOWP (window)) | |
4153 | { | |
4154 | window = event->frame_or_window; | |
4155 | posn = Qnil; | |
4156 | } | |
4157 | else | |
4158 | { | |
4159 | int pixcolumn, pixrow; | |
4160 | column -= XINT (XWINDOW (window)->left); | |
4161 | row -= XINT (XWINDOW (window)->top); | |
4162 | glyph_to_pixel_coords (f, column, row, &pixcolumn, &pixrow); | |
4163 | XSETINT (event->x, pixcolumn); | |
4164 | XSETINT (event->y, pixrow); | |
4165 | ||
4166 | if (part == 1) | |
4167 | posn = Qmode_line; | |
4168 | else if (part == 2) | |
4169 | posn = Qvertical_line; | |
4170 | else | |
4171 | XSETINT (posn, | |
4172 | buffer_posn_from_coords (XWINDOW (window), | |
4173 | column, row)); | |
4174 | } | |
db08707d | 4175 | |
07de30b9 GV |
4176 | { |
4177 | Lisp_Object head, position; | |
4178 | ||
4179 | position | |
4180 | = Fcons (window, | |
4181 | Fcons (posn, | |
4182 | Fcons (Fcons (event->x, event->y), | |
4183 | Fcons (make_number (event->timestamp), | |
4184 | Qnil)))); | |
4185 | ||
4186 | head = modify_event_symbol (0, event->modifiers, | |
4187 | Qmouse_wheel, Qnil, | |
4188 | lispy_mouse_wheel_names, | |
4189 | &mouse_wheel_syms, 1); | |
4190 | return Fcons (head, | |
4191 | Fcons (position, | |
4192 | Fcons (make_number (event->code), | |
4193 | Qnil))); | |
4194 | } | |
4195 | } | |
4196 | #endif /* WINDOWSNT */ | |
514354e9 | 4197 | #endif /* HAVE_MOUSE */ |
284f4730 | 4198 | |
e98a93eb | 4199 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
2470a66f KH |
4200 | case menu_bar_event: |
4201 | /* The event value is in the cdr of the frame_or_window slot. */ | |
4202 | if (!CONSP (event->frame_or_window)) | |
4203 | abort (); | |
4204 | return XCONS (event->frame_or_window)->cdr; | |
4205 | #endif | |
4206 | ||
284f4730 JB |
4207 | /* The 'kind' field of the event is something we don't recognize. */ |
4208 | default: | |
48e416d4 | 4209 | abort (); |
284f4730 JB |
4210 | } |
4211 | } | |
4212 | ||
514354e9 | 4213 | #ifdef HAVE_MOUSE |
6cbff1cb | 4214 | |
284f4730 | 4215 | static Lisp_Object |
7b4aedb9 | 4216 | make_lispy_movement (frame, bar_window, part, x, y, time) |
ff11dfa1 | 4217 | FRAME_PTR frame; |
7b4aedb9 | 4218 | Lisp_Object bar_window; |
3c370943 | 4219 | enum scroll_bar_part part; |
284f4730 | 4220 | Lisp_Object x, y; |
e5d77022 | 4221 | unsigned long time; |
284f4730 | 4222 | { |
3c370943 | 4223 | /* Is it a scroll bar movement? */ |
7b4aedb9 | 4224 | if (frame && ! NILP (bar_window)) |
4bb994d1 | 4225 | { |
9b8eb840 | 4226 | Lisp_Object part_sym; |
4bb994d1 | 4227 | |
9b8eb840 | 4228 | part_sym = *scroll_bar_parts[(int) part]; |
3c370943 | 4229 | return Fcons (Qscroll_bar_movement, |
7b4aedb9 | 4230 | (Fcons (Fcons (bar_window, |
3c370943 | 4231 | Fcons (Qvertical_scroll_bar, |
4bb994d1 JB |
4232 | Fcons (Fcons (x, y), |
4233 | Fcons (make_number (time), | |
cb5df6ae | 4234 | Fcons (part_sym, |
4bb994d1 JB |
4235 | Qnil))))), |
4236 | Qnil))); | |
4237 | } | |
4238 | ||
4239 | /* Or is it an ordinary mouse movement? */ | |
284f4730 JB |
4240 | else |
4241 | { | |
4bb994d1 | 4242 | int area; |
9e20143a | 4243 | Lisp_Object window; |
4bb994d1 | 4244 | Lisp_Object posn; |
9e20143a RS |
4245 | int column, row; |
4246 | ||
9e20143a | 4247 | if (frame) |
047688cb RS |
4248 | { |
4249 | /* It's in a frame; which window on that frame? */ | |
6c6a9be8 KH |
4250 | pixel_to_glyph_coords (frame, XINT (x), XINT (y), &column, &row, |
4251 | NULL, 1); | |
047688cb RS |
4252 | window = window_from_coordinates (frame, column, row, &area); |
4253 | } | |
9e20143a RS |
4254 | else |
4255 | window = Qnil; | |
4bb994d1 | 4256 | |
8c18cbfb | 4257 | if (WINDOWP (window)) |
4bb994d1 | 4258 | { |
9e20143a | 4259 | int pixcolumn, pixrow; |
c8738c33 | 4260 | column -= WINDOW_LEFT_MARGIN (XWINDOW (window)); |
9e20143a RS |
4261 | row -= XINT (XWINDOW (window)->top); |
4262 | glyph_to_pixel_coords (frame, column, row, &pixcolumn, &pixrow); | |
4263 | XSETINT (x, pixcolumn); | |
4264 | XSETINT (y, pixrow); | |
4bb994d1 JB |
4265 | |
4266 | if (area == 1) | |
4267 | posn = Qmode_line; | |
4268 | else if (area == 2) | |
4269 | posn = Qvertical_line; | |
4270 | else | |
18cd2eeb KH |
4271 | XSETINT (posn, |
4272 | buffer_posn_from_coords (XWINDOW (window), column, row)); | |
4bb994d1 | 4273 | } |
e9bf89a0 RS |
4274 | else if (frame != 0) |
4275 | { | |
18cd2eeb | 4276 | XSETFRAME (window, frame); |
e9bf89a0 RS |
4277 | posn = Qnil; |
4278 | } | |
284f4730 | 4279 | else |
4bb994d1 JB |
4280 | { |
4281 | window = Qnil; | |
4282 | posn = Qnil; | |
bb9e9bed KH |
4283 | XSETFASTINT (x, 0); |
4284 | XSETFASTINT (y, 0); | |
4bb994d1 | 4285 | } |
284f4730 | 4286 | |
4bb994d1 JB |
4287 | return Fcons (Qmouse_movement, |
4288 | Fcons (Fcons (window, | |
4289 | Fcons (posn, | |
4290 | Fcons (Fcons (x, y), | |
4291 | Fcons (make_number (time), | |
4292 | Qnil)))), | |
4293 | Qnil)); | |
4294 | } | |
284f4730 JB |
4295 | } |
4296 | ||
514354e9 | 4297 | #endif /* HAVE_MOUSE */ |
6cbff1cb | 4298 | |
cd21b839 JB |
4299 | /* Construct a switch frame event. */ |
4300 | static Lisp_Object | |
4301 | make_lispy_switch_frame (frame) | |
4302 | Lisp_Object frame; | |
4303 | { | |
4304 | return Fcons (Qswitch_frame, Fcons (frame, Qnil)); | |
4305 | } | |
0a7f1fc0 JB |
4306 | \f |
4307 | /* Manipulating modifiers. */ | |
284f4730 | 4308 | |
0a7f1fc0 | 4309 | /* Parse the name of SYMBOL, and return the set of modifiers it contains. |
284f4730 | 4310 | |
0a7f1fc0 JB |
4311 | If MODIFIER_END is non-zero, set *MODIFIER_END to the position in |
4312 | SYMBOL's name of the end of the modifiers; the string from this | |
4313 | position is the unmodified symbol name. | |
284f4730 | 4314 | |
0a7f1fc0 | 4315 | This doesn't use any caches. */ |
6da3dd3a | 4316 | |
0a7f1fc0 JB |
4317 | static int |
4318 | parse_modifiers_uncached (symbol, modifier_end) | |
284f4730 | 4319 | Lisp_Object symbol; |
0a7f1fc0 | 4320 | int *modifier_end; |
284f4730 JB |
4321 | { |
4322 | struct Lisp_String *name; | |
4323 | int i; | |
4324 | int modifiers; | |
284f4730 JB |
4325 | |
4326 | CHECK_SYMBOL (symbol, 1); | |
df0f2ba1 | 4327 | |
284f4730 JB |
4328 | modifiers = 0; |
4329 | name = XSYMBOL (symbol)->name; | |
4330 | ||
0a7f1fc0 | 4331 | for (i = 0; i+2 <= name->size; ) |
6da3dd3a RS |
4332 | { |
4333 | int this_mod_end = 0; | |
4334 | int this_mod = 0; | |
284f4730 | 4335 | |
6da3dd3a RS |
4336 | /* See if the name continues with a modifier word. |
4337 | Check that the word appears, but don't check what follows it. | |
4338 | Set this_mod and this_mod_end to record what we find. */ | |
fce33686 | 4339 | |
6da3dd3a RS |
4340 | switch (name->data[i]) |
4341 | { | |
4342 | #define SINGLE_LETTER_MOD(BIT) \ | |
4343 | (this_mod_end = i + 1, this_mod = BIT) | |
4344 | ||
6da3dd3a RS |
4345 | case 'A': |
4346 | SINGLE_LETTER_MOD (alt_modifier); | |
4347 | break; | |
284f4730 | 4348 | |
6da3dd3a RS |
4349 | case 'C': |
4350 | SINGLE_LETTER_MOD (ctrl_modifier); | |
4351 | break; | |
284f4730 | 4352 | |
6da3dd3a RS |
4353 | case 'H': |
4354 | SINGLE_LETTER_MOD (hyper_modifier); | |
4355 | break; | |
4356 | ||
6da3dd3a RS |
4357 | case 'M': |
4358 | SINGLE_LETTER_MOD (meta_modifier); | |
4359 | break; | |
4360 | ||
6da3dd3a RS |
4361 | case 'S': |
4362 | SINGLE_LETTER_MOD (shift_modifier); | |
4363 | break; | |
4364 | ||
4365 | case 's': | |
6da3dd3a RS |
4366 | SINGLE_LETTER_MOD (super_modifier); |
4367 | break; | |
4368 | ||
0a7f1fc0 | 4369 | #undef SINGLE_LETTER_MOD |
6da3dd3a RS |
4370 | } |
4371 | ||
4372 | /* If we found no modifier, stop looking for them. */ | |
4373 | if (this_mod_end == 0) | |
4374 | break; | |
4375 | ||
4376 | /* Check there is a dash after the modifier, so that it | |
4377 | really is a modifier. */ | |
4378 | if (this_mod_end >= name->size || name->data[this_mod_end] != '-') | |
4379 | break; | |
4380 | ||
4381 | /* This modifier is real; look for another. */ | |
4382 | modifiers |= this_mod; | |
4383 | i = this_mod_end + 1; | |
4384 | } | |
284f4730 | 4385 | |
0a7f1fc0 | 4386 | /* Should we include the `click' modifier? */ |
fbcd35bd JB |
4387 | if (! (modifiers & (down_modifier | drag_modifier |
4388 | | double_modifier | triple_modifier)) | |
0a7f1fc0 | 4389 | && i + 7 == name->size |
4bb994d1 | 4390 | && strncmp (name->data + i, "mouse-", 6) == 0 |
6569cc8d | 4391 | && ('0' <= name->data[i + 6] && name->data[i + 6] <= '9')) |
0a7f1fc0 JB |
4392 | modifiers |= click_modifier; |
4393 | ||
4394 | if (modifier_end) | |
4395 | *modifier_end = i; | |
4396 | ||
4397 | return modifiers; | |
4398 | } | |
4399 | ||
0a7f1fc0 JB |
4400 | /* Return a symbol whose name is the modifier prefixes for MODIFIERS |
4401 | prepended to the string BASE[0..BASE_LEN-1]. | |
4402 | This doesn't use any caches. */ | |
4403 | static Lisp_Object | |
4404 | apply_modifiers_uncached (modifiers, base, base_len) | |
4405 | int modifiers; | |
4406 | char *base; | |
4407 | int base_len; | |
4408 | { | |
4409 | /* Since BASE could contain nulls, we can't use intern here; we have | |
4410 | to use Fintern, which expects a genuine Lisp_String, and keeps a | |
4411 | reference to it. */ | |
4412 | char *new_mods = | |
fbcd35bd | 4413 | (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-")); |
0a7f1fc0 | 4414 | int mod_len; |
284f4730 | 4415 | |
284f4730 | 4416 | { |
0a7f1fc0 JB |
4417 | char *p = new_mods; |
4418 | ||
4419 | /* Only the event queue may use the `up' modifier; it should always | |
4420 | be turned into a click or drag event before presented to lisp code. */ | |
4421 | if (modifiers & up_modifier) | |
4422 | abort (); | |
4423 | ||
4424 | if (modifiers & alt_modifier) { *p++ = 'A'; *p++ = '-'; } | |
4425 | if (modifiers & ctrl_modifier) { *p++ = 'C'; *p++ = '-'; } | |
4426 | if (modifiers & hyper_modifier) { *p++ = 'H'; *p++ = '-'; } | |
4427 | if (modifiers & meta_modifier) { *p++ = 'M'; *p++ = '-'; } | |
4428 | if (modifiers & shift_modifier) { *p++ = 'S'; *p++ = '-'; } | |
86e5706b | 4429 | if (modifiers & super_modifier) { *p++ = 's'; *p++ = '-'; } |
fbcd35bd JB |
4430 | if (modifiers & double_modifier) { strcpy (p, "double-"); p += 7; } |
4431 | if (modifiers & triple_modifier) { strcpy (p, "triple-"); p += 7; } | |
559f9d04 RS |
4432 | if (modifiers & down_modifier) { strcpy (p, "down-"); p += 5; } |
4433 | if (modifiers & drag_modifier) { strcpy (p, "drag-"); p += 5; } | |
0a7f1fc0 JB |
4434 | /* The click modifier is denoted by the absence of other modifiers. */ |
4435 | ||
4436 | *p = '\0'; | |
4437 | ||
4438 | mod_len = p - new_mods; | |
4439 | } | |
284f4730 | 4440 | |
0a7f1fc0 | 4441 | { |
9b8eb840 | 4442 | Lisp_Object new_name; |
df0f2ba1 | 4443 | |
9b8eb840 | 4444 | new_name = make_uninit_string (mod_len + base_len); |
0a7f1fc0 JB |
4445 | bcopy (new_mods, XSTRING (new_name)->data, mod_len); |
4446 | bcopy (base, XSTRING (new_name)->data + mod_len, base_len); | |
284f4730 JB |
4447 | |
4448 | return Fintern (new_name, Qnil); | |
4449 | } | |
4450 | } | |
4451 | ||
4452 | ||
0a7f1fc0 JB |
4453 | static char *modifier_names[] = |
4454 | { | |
fbcd35bd | 4455 | "up", "down", "drag", "click", "double", "triple", 0, 0, |
f335fabe | 4456 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
86e5706b | 4457 | 0, 0, "alt", "super", "hyper", "shift", "control", "meta" |
0a7f1fc0 | 4458 | }; |
80645119 | 4459 | #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0])) |
0a7f1fc0 JB |
4460 | |
4461 | static Lisp_Object modifier_symbols; | |
4462 | ||
4463 | /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */ | |
4464 | static Lisp_Object | |
4465 | lispy_modifier_list (modifiers) | |
4466 | int modifiers; | |
4467 | { | |
4468 | Lisp_Object modifier_list; | |
4469 | int i; | |
4470 | ||
4471 | modifier_list = Qnil; | |
80645119 | 4472 | for (i = 0; (1<<i) <= modifiers && i < NUM_MOD_NAMES; i++) |
0a7f1fc0 | 4473 | if (modifiers & (1<<i)) |
80645119 JB |
4474 | modifier_list = Fcons (XVECTOR (modifier_symbols)->contents[i], |
4475 | modifier_list); | |
0a7f1fc0 JB |
4476 | |
4477 | return modifier_list; | |
4478 | } | |
4479 | ||
4480 | ||
4481 | /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK), | |
4482 | where UNMODIFIED is the unmodified form of SYMBOL, | |
4483 | MASK is the set of modifiers present in SYMBOL's name. | |
4484 | This is similar to parse_modifiers_uncached, but uses the cache in | |
4485 | SYMBOL's Qevent_symbol_element_mask property, and maintains the | |
4486 | Qevent_symbol_elements property. */ | |
3d31316f | 4487 | |
0a7f1fc0 JB |
4488 | static Lisp_Object |
4489 | parse_modifiers (symbol) | |
4490 | Lisp_Object symbol; | |
4491 | { | |
9b8eb840 | 4492 | Lisp_Object elements; |
0a7f1fc0 | 4493 | |
9b8eb840 | 4494 | elements = Fget (symbol, Qevent_symbol_element_mask); |
0a7f1fc0 JB |
4495 | if (CONSP (elements)) |
4496 | return elements; | |
4497 | else | |
4498 | { | |
4499 | int end; | |
ec0faad2 | 4500 | int modifiers = parse_modifiers_uncached (symbol, &end); |
9b8eb840 | 4501 | Lisp_Object unmodified; |
0a7f1fc0 JB |
4502 | Lisp_Object mask; |
4503 | ||
9b8eb840 KH |
4504 | unmodified = Fintern (make_string (XSYMBOL (symbol)->name->data + end, |
4505 | XSYMBOL (symbol)->name->size - end), | |
4506 | Qnil); | |
4507 | ||
ec0faad2 | 4508 | if (modifiers & ~(((EMACS_INT)1 << VALBITS) - 1)) |
734fef94 | 4509 | abort (); |
bb9e9bed | 4510 | XSETFASTINT (mask, modifiers); |
0a7f1fc0 JB |
4511 | elements = Fcons (unmodified, Fcons (mask, Qnil)); |
4512 | ||
4513 | /* Cache the parsing results on SYMBOL. */ | |
4514 | Fput (symbol, Qevent_symbol_element_mask, | |
4515 | elements); | |
4516 | Fput (symbol, Qevent_symbol_elements, | |
4517 | Fcons (unmodified, lispy_modifier_list (modifiers))); | |
4518 | ||
4519 | /* Since we know that SYMBOL is modifiers applied to unmodified, | |
4520 | it would be nice to put that in unmodified's cache. | |
4521 | But we can't, since we're not sure that parse_modifiers is | |
4522 | canonical. */ | |
4523 | ||
4524 | return elements; | |
4525 | } | |
4526 | } | |
4527 | ||
4528 | /* Apply the modifiers MODIFIERS to the symbol BASE. | |
4529 | BASE must be unmodified. | |
4530 | ||
4531 | This is like apply_modifiers_uncached, but uses BASE's | |
4532 | Qmodifier_cache property, if present. It also builds | |
cd21b839 JB |
4533 | Qevent_symbol_elements properties, since it has that info anyway. |
4534 | ||
4535 | apply_modifiers copies the value of BASE's Qevent_kind property to | |
4536 | the modified symbol. */ | |
0a7f1fc0 JB |
4537 | static Lisp_Object |
4538 | apply_modifiers (modifiers, base) | |
4539 | int modifiers; | |
4540 | Lisp_Object base; | |
4541 | { | |
7b4aedb9 | 4542 | Lisp_Object cache, index, entry, new_symbol; |
0a7f1fc0 | 4543 | |
80645119 | 4544 | /* Mask out upper bits. We don't know where this value's been. */ |
ec0faad2 | 4545 | modifiers &= ((EMACS_INT)1 << VALBITS) - 1; |
80645119 | 4546 | |
0a7f1fc0 | 4547 | /* The click modifier never figures into cache indices. */ |
0a7f1fc0 | 4548 | cache = Fget (base, Qmodifier_cache); |
bb9e9bed | 4549 | XSETFASTINT (index, (modifiers & ~click_modifier)); |
697e4895 | 4550 | entry = assq_no_quit (index, cache); |
0a7f1fc0 JB |
4551 | |
4552 | if (CONSP (entry)) | |
7b4aedb9 JB |
4553 | new_symbol = XCONS (entry)->cdr; |
4554 | else | |
4555 | { | |
df0f2ba1 | 4556 | /* We have to create the symbol ourselves. */ |
7b4aedb9 JB |
4557 | new_symbol = apply_modifiers_uncached (modifiers, |
4558 | XSYMBOL (base)->name->data, | |
4559 | XSYMBOL (base)->name->size); | |
4560 | ||
4561 | /* Add the new symbol to the base's cache. */ | |
4562 | entry = Fcons (index, new_symbol); | |
4563 | Fput (base, Qmodifier_cache, Fcons (entry, cache)); | |
4564 | ||
4565 | /* We have the parsing info now for free, so add it to the caches. */ | |
bb9e9bed | 4566 | XSETFASTINT (index, modifiers); |
7b4aedb9 JB |
4567 | Fput (new_symbol, Qevent_symbol_element_mask, |
4568 | Fcons (base, Fcons (index, Qnil))); | |
4569 | Fput (new_symbol, Qevent_symbol_elements, | |
4570 | Fcons (base, lispy_modifier_list (modifiers))); | |
4571 | } | |
0a7f1fc0 | 4572 | |
df0f2ba1 | 4573 | /* Make sure this symbol is of the same kind as BASE. |
7b4aedb9 JB |
4574 | |
4575 | You'd think we could just set this once and for all when we | |
4576 | intern the symbol above, but reorder_modifiers may call us when | |
4577 | BASE's property isn't set right; we can't assume that just | |
80645119 JB |
4578 | because it has a Qmodifier_cache property it must have its |
4579 | Qevent_kind set right as well. */ | |
7b4aedb9 JB |
4580 | if (NILP (Fget (new_symbol, Qevent_kind))) |
4581 | { | |
9b8eb840 | 4582 | Lisp_Object kind; |
7b4aedb9 | 4583 | |
9b8eb840 | 4584 | kind = Fget (base, Qevent_kind); |
7b4aedb9 JB |
4585 | if (! NILP (kind)) |
4586 | Fput (new_symbol, Qevent_kind, kind); | |
4587 | } | |
4588 | ||
4589 | return new_symbol; | |
0a7f1fc0 JB |
4590 | } |
4591 | ||
4592 | ||
4593 | /* Given a symbol whose name begins with modifiers ("C-", "M-", etc), | |
4594 | return a symbol with the modifiers placed in the canonical order. | |
4595 | Canonical order is alphabetical, except for down and drag, which | |
4596 | always come last. The 'click' modifier is never written out. | |
4597 | ||
4598 | Fdefine_key calls this to make sure that (for example) C-M-foo | |
4599 | and M-C-foo end up being equivalent in the keymap. */ | |
4600 | ||
4601 | Lisp_Object | |
4602 | reorder_modifiers (symbol) | |
4603 | Lisp_Object symbol; | |
4604 | { | |
4605 | /* It's hopefully okay to write the code this way, since everything | |
4606 | will soon be in caches, and no consing will be done at all. */ | |
9b8eb840 | 4607 | Lisp_Object parsed; |
0a7f1fc0 | 4608 | |
9b8eb840 | 4609 | parsed = parse_modifiers (symbol); |
54593ed9 | 4610 | return apply_modifiers ((int) XINT (XCONS (XCONS (parsed)->cdr)->car), |
0a7f1fc0 JB |
4611 | XCONS (parsed)->car); |
4612 | } | |
4613 | ||
4614 | ||
284f4730 JB |
4615 | /* For handling events, we often want to produce a symbol whose name |
4616 | is a series of modifier key prefixes ("M-", "C-", etcetera) attached | |
4617 | to some base, like the name of a function key or mouse button. | |
4618 | modify_event_symbol produces symbols of this sort. | |
4619 | ||
4620 | NAME_TABLE should point to an array of strings, such that NAME_TABLE[i] | |
4621 | is the name of the i'th symbol. TABLE_SIZE is the number of elements | |
4622 | in the table. | |
4623 | ||
80e4aa30 RS |
4624 | Alternatively, NAME_ALIST is an alist mapping codes into symbol names. |
4625 | NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used. | |
4626 | ||
284f4730 JB |
4627 | SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will |
4628 | persist between calls to modify_event_symbol that it can use to | |
4629 | store a cache of the symbols it's generated for this NAME_TABLE | |
80e4aa30 | 4630 | before. The object stored there may be a vector or an alist. |
284f4730 JB |
4631 | |
4632 | SYMBOL_NUM is the number of the base name we want from NAME_TABLE. | |
df0f2ba1 | 4633 | |
284f4730 JB |
4634 | MODIFIERS is a set of modifier bits (as given in struct input_events) |
4635 | whose prefixes should be applied to the symbol name. | |
4636 | ||
4637 | SYMBOL_KIND is the value to be placed in the event_kind property of | |
df0f2ba1 | 4638 | the returned symbol. |
88cb0656 JB |
4639 | |
4640 | The symbols we create are supposed to have an | |
eb8c3be9 | 4641 | `event-symbol-elements' property, which lists the modifiers present |
88cb0656 JB |
4642 | in the symbol's name. */ |
4643 | ||
284f4730 | 4644 | static Lisp_Object |
80e4aa30 RS |
4645 | modify_event_symbol (symbol_num, modifiers, symbol_kind, name_alist, |
4646 | name_table, symbol_table, table_size) | |
284f4730 JB |
4647 | int symbol_num; |
4648 | unsigned modifiers; | |
4649 | Lisp_Object symbol_kind; | |
80e4aa30 | 4650 | Lisp_Object name_alist; |
284f4730 JB |
4651 | char **name_table; |
4652 | Lisp_Object *symbol_table; | |
2c834fb3 | 4653 | unsigned int table_size; |
284f4730 | 4654 | { |
80e4aa30 RS |
4655 | Lisp_Object value; |
4656 | Lisp_Object symbol_int; | |
4657 | ||
2c834fb3 KH |
4658 | /* Get rid of the "vendor-specific" bit here. */ |
4659 | XSETINT (symbol_int, symbol_num & 0xffffff); | |
284f4730 JB |
4660 | |
4661 | /* Is this a request for a valid symbol? */ | |
88cb0656 | 4662 | if (symbol_num < 0 || symbol_num >= table_size) |
0c2611c5 | 4663 | return Qnil; |
284f4730 | 4664 | |
80e4aa30 RS |
4665 | if (CONSP (*symbol_table)) |
4666 | value = Fcdr (assq_no_quit (symbol_int, *symbol_table)); | |
4667 | ||
0a7f1fc0 | 4668 | /* If *symbol_table doesn't seem to be initialized properly, fix that. |
88cb0656 | 4669 | *symbol_table should be a lisp vector TABLE_SIZE elements long, |
4bb994d1 JB |
4670 | where the Nth element is the symbol for NAME_TABLE[N], or nil if |
4671 | we've never used that symbol before. */ | |
80e4aa30 | 4672 | else |
88cb0656 | 4673 | { |
80e4aa30 RS |
4674 | if (! VECTORP (*symbol_table) |
4675 | || XVECTOR (*symbol_table)->size != table_size) | |
4676 | { | |
4677 | Lisp_Object size; | |
0a7f1fc0 | 4678 | |
bb9e9bed | 4679 | XSETFASTINT (size, table_size); |
80e4aa30 RS |
4680 | *symbol_table = Fmake_vector (size, Qnil); |
4681 | } | |
284f4730 | 4682 | |
80e4aa30 RS |
4683 | value = XVECTOR (*symbol_table)->contents[symbol_num]; |
4684 | } | |
284f4730 | 4685 | |
0a7f1fc0 | 4686 | /* Have we already used this symbol before? */ |
80e4aa30 | 4687 | if (NILP (value)) |
284f4730 | 4688 | { |
0a7f1fc0 | 4689 | /* No; let's create it. */ |
80e4aa30 | 4690 | if (!NILP (name_alist)) |
b64b4075 | 4691 | value = Fcdr_safe (Fassq (symbol_int, name_alist)); |
2ff6714d | 4692 | else if (name_table != 0 && name_table[symbol_num]) |
80e4aa30 | 4693 | value = intern (name_table[symbol_num]); |
b64b4075 | 4694 | |
e98a93eb | 4695 | #ifdef HAVE_WINDOW_SYSTEM |
2c834fb3 KH |
4696 | if (NILP (value)) |
4697 | { | |
4698 | char *name = x_get_keysym_name (symbol_num); | |
4699 | if (name) | |
4700 | value = intern (name); | |
4701 | } | |
4702 | #endif | |
4703 | ||
b64b4075 | 4704 | if (NILP (value)) |
d1f50460 RS |
4705 | { |
4706 | char buf[20]; | |
4707 | sprintf (buf, "key-%d", symbol_num); | |
80e4aa30 | 4708 | value = intern (buf); |
d1f50460 | 4709 | } |
0a7f1fc0 | 4710 | |
80e4aa30 | 4711 | if (CONSP (*symbol_table)) |
4205cb08 | 4712 | *symbol_table = Fcons (Fcons (symbol_int, value), *symbol_table); |
80e4aa30 RS |
4713 | else |
4714 | XVECTOR (*symbol_table)->contents[symbol_num] = value; | |
4715 | ||
df0f2ba1 | 4716 | /* Fill in the cache entries for this symbol; this also |
0a7f1fc0 JB |
4717 | builds the Qevent_symbol_elements property, which the user |
4718 | cares about. */ | |
80e4aa30 RS |
4719 | apply_modifiers (modifiers & click_modifier, value); |
4720 | Fput (value, Qevent_kind, symbol_kind); | |
284f4730 | 4721 | } |
88cb0656 | 4722 | |
0a7f1fc0 | 4723 | /* Apply modifiers to that symbol. */ |
80e4aa30 | 4724 | return apply_modifiers (modifiers, value); |
284f4730 | 4725 | } |
6da3dd3a RS |
4726 | \f |
4727 | /* Convert a list that represents an event type, | |
4728 | such as (ctrl meta backspace), into the usual representation of that | |
4729 | event type as a number or a symbol. */ | |
4730 | ||
a1706c30 | 4731 | DEFUN ("event-convert-list", Fevent_convert_list, Sevent_convert_list, 1, 1, 0, |
e57d8fd8 EN |
4732 | "Convert the event description list EVENT-DESC to an event type.\n\ |
4733 | EVENT-DESC should contain one base event type (a character or symbol)\n\ | |
a1706c30 | 4734 | and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\ |
377f24f5 | 4735 | drag, down, double or triple). The base must be last.\n\ |
a1706c30 KH |
4736 | The return value is an event type (a character or symbol) which\n\ |
4737 | has the same base event type and all the specified modifiers.") | |
e57d8fd8 EN |
4738 | (event_desc) |
4739 | Lisp_Object event_desc; | |
6da3dd3a RS |
4740 | { |
4741 | Lisp_Object base; | |
4742 | int modifiers = 0; | |
4743 | Lisp_Object rest; | |
4744 | ||
4745 | base = Qnil; | |
e57d8fd8 | 4746 | rest = event_desc; |
6da3dd3a RS |
4747 | while (CONSP (rest)) |
4748 | { | |
4749 | Lisp_Object elt; | |
4750 | int this = 0; | |
4751 | ||
4752 | elt = XCONS (rest)->car; | |
377f24f5 | 4753 | rest = XCONS (rest)->cdr; |
6da3dd3a | 4754 | |
3d31316f | 4755 | /* Given a symbol, see if it is a modifier name. */ |
377f24f5 | 4756 | if (SYMBOLP (elt) && CONSP (rest)) |
3d31316f | 4757 | this = parse_solitary_modifier (elt); |
6da3dd3a RS |
4758 | |
4759 | if (this != 0) | |
4760 | modifiers |= this; | |
4761 | else if (!NILP (base)) | |
4762 | error ("Two bases given in one event"); | |
4763 | else | |
4764 | base = elt; | |
4765 | ||
6da3dd3a RS |
4766 | } |
4767 | ||
3d31316f RS |
4768 | /* Let the symbol A refer to the character A. */ |
4769 | if (SYMBOLP (base) && XSYMBOL (base)->name->size == 1) | |
4770 | XSETINT (base, XSYMBOL (base)->name->data[0]); | |
4771 | ||
6da3dd3a RS |
4772 | if (INTEGERP (base)) |
4773 | { | |
3d31316f RS |
4774 | /* Turn (shift a) into A. */ |
4775 | if ((modifiers & shift_modifier) != 0 | |
4776 | && (XINT (base) >= 'a' && XINT (base) <= 'z')) | |
4777 | { | |
4778 | XSETINT (base, XINT (base) - ('a' - 'A')); | |
4779 | modifiers &= ~shift_modifier; | |
4780 | } | |
4781 | ||
4782 | /* Turn (control a) into C-a. */ | |
6da3dd3a | 4783 | if (modifiers & ctrl_modifier) |
3d31316f | 4784 | return make_number ((modifiers & ~ctrl_modifier) |
6da3dd3a RS |
4785 | | make_ctrl_char (XINT (base))); |
4786 | else | |
4787 | return make_number (modifiers | XINT (base)); | |
4788 | } | |
4789 | else if (SYMBOLP (base)) | |
4790 | return apply_modifiers (modifiers, base); | |
4791 | else | |
4792 | error ("Invalid base event"); | |
4793 | } | |
4794 | ||
3d31316f RS |
4795 | /* Try to recognize SYMBOL as a modifier name. |
4796 | Return the modifier flag bit, or 0 if not recognized. */ | |
4797 | ||
4798 | static int | |
4799 | parse_solitary_modifier (symbol) | |
4800 | Lisp_Object symbol; | |
4801 | { | |
4802 | struct Lisp_String *name = XSYMBOL (symbol)->name; | |
4803 | ||
4804 | switch (name->data[0]) | |
4805 | { | |
4806 | #define SINGLE_LETTER_MOD(BIT) \ | |
4807 | if (name->size == 1) \ | |
4808 | return BIT; | |
4809 | ||
4810 | #define MULTI_LETTER_MOD(BIT, NAME, LEN) \ | |
4811 | if (LEN == name->size \ | |
4812 | && ! strncmp (name->data, NAME, LEN)) \ | |
4813 | return BIT; | |
4814 | ||
4815 | case 'A': | |
4816 | SINGLE_LETTER_MOD (alt_modifier); | |
4817 | break; | |
4818 | ||
4819 | case 'a': | |
4820 | MULTI_LETTER_MOD (alt_modifier, "alt", 3); | |
4821 | break; | |
4822 | ||
4823 | case 'C': | |
4824 | SINGLE_LETTER_MOD (ctrl_modifier); | |
4825 | break; | |
4826 | ||
4827 | case 'c': | |
4828 | MULTI_LETTER_MOD (ctrl_modifier, "ctrl", 4); | |
4829 | MULTI_LETTER_MOD (ctrl_modifier, "control", 7); | |
4830 | break; | |
4831 | ||
4832 | case 'H': | |
4833 | SINGLE_LETTER_MOD (hyper_modifier); | |
4834 | break; | |
4835 | ||
4836 | case 'h': | |
4837 | MULTI_LETTER_MOD (hyper_modifier, "hyper", 5); | |
4838 | break; | |
4839 | ||
4840 | case 'M': | |
4841 | SINGLE_LETTER_MOD (meta_modifier); | |
4842 | break; | |
4843 | ||
4844 | case 'm': | |
4845 | MULTI_LETTER_MOD (meta_modifier, "meta", 4); | |
4846 | break; | |
4847 | ||
4848 | case 'S': | |
4849 | SINGLE_LETTER_MOD (shift_modifier); | |
4850 | break; | |
4851 | ||
4852 | case 's': | |
4853 | MULTI_LETTER_MOD (shift_modifier, "shift", 5); | |
4854 | MULTI_LETTER_MOD (super_modifier, "super", 5); | |
4855 | SINGLE_LETTER_MOD (super_modifier); | |
4856 | break; | |
4857 | ||
4858 | case 'd': | |
4859 | MULTI_LETTER_MOD (drag_modifier, "drag", 4); | |
4860 | MULTI_LETTER_MOD (down_modifier, "down", 4); | |
4861 | MULTI_LETTER_MOD (double_modifier, "double", 6); | |
4862 | break; | |
4863 | ||
4864 | case 't': | |
4865 | MULTI_LETTER_MOD (triple_modifier, "triple", 6); | |
4866 | break; | |
4867 | ||
4868 | #undef SINGLE_LETTER_MOD | |
4869 | #undef MULTI_LETTER_MOD | |
4870 | } | |
4871 | ||
4872 | return 0; | |
4873 | } | |
4874 | ||
6da3dd3a RS |
4875 | /* Return 1 if EVENT is a list whose elements are all integers or symbols. |
4876 | Such a list is not valid as an event, | |
4877 | but it can be a Lucid-style event type list. */ | |
4878 | ||
4879 | int | |
4880 | lucid_event_type_list_p (object) | |
4881 | Lisp_Object object; | |
4882 | { | |
4883 | Lisp_Object tail; | |
4884 | ||
4885 | if (! CONSP (object)) | |
4886 | return 0; | |
4887 | ||
4888 | for (tail = object; CONSP (tail); tail = XCONS (tail)->cdr) | |
4889 | { | |
4890 | Lisp_Object elt; | |
4891 | elt = XCONS (tail)->car; | |
4892 | if (! (INTEGERP (elt) || SYMBOLP (elt))) | |
4893 | return 0; | |
4894 | } | |
4895 | ||
4896 | return NILP (tail); | |
4897 | } | |
284f4730 | 4898 | \f |
284f4730 JB |
4899 | /* Store into *addr a value nonzero if terminal input chars are available. |
4900 | Serves the purpose of ioctl (0, FIONREAD, addr) | |
4901 | but works even if FIONREAD does not exist. | |
d9d4c147 KH |
4902 | (In fact, this may actually read some input.) |
4903 | ||
4904 | If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */ | |
284f4730 JB |
4905 | |
4906 | static void | |
d9d4c147 | 4907 | get_input_pending (addr, do_timers_now) |
284f4730 | 4908 | int *addr; |
d9d4c147 | 4909 | int do_timers_now; |
284f4730 JB |
4910 | { |
4911 | /* First of all, have we already counted some input? */ | |
d9d4c147 | 4912 | *addr = !NILP (Vquit_flag) || readable_events (do_timers_now); |
284f4730 JB |
4913 | |
4914 | /* If input is being read as it arrives, and we have none, there is none. */ | |
4915 | if (*addr > 0 || (interrupt_input && ! interrupts_deferred)) | |
4916 | return; | |
4917 | ||
4918 | /* Try to read some input and see how much we get. */ | |
4919 | gobble_input (0); | |
d9d4c147 | 4920 | *addr = !NILP (Vquit_flag) || readable_events (do_timers_now); |
284f4730 JB |
4921 | } |
4922 | ||
81931ba1 | 4923 | /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */ |
284f4730 | 4924 | |
07a59269 | 4925 | void |
284f4730 JB |
4926 | gobble_input (expected) |
4927 | int expected; | |
4928 | { | |
4929 | #ifndef VMS | |
4930 | #ifdef SIGIO | |
4931 | if (interrupt_input) | |
4932 | { | |
32676c08 | 4933 | SIGMASKTYPE mask; |
4f8aaa74 | 4934 | mask = sigblock (sigmask (SIGIO)); |
284f4730 | 4935 | read_avail_input (expected); |
e065a56e | 4936 | sigsetmask (mask); |
284f4730 JB |
4937 | } |
4938 | else | |
81931ba1 RS |
4939 | #ifdef POLL_FOR_INPUT |
4940 | if (read_socket_hook && !interrupt_input && poll_suppress_count == 0) | |
4941 | { | |
4942 | SIGMASKTYPE mask; | |
4f8aaa74 | 4943 | mask = sigblock (sigmask (SIGALRM)); |
81931ba1 RS |
4944 | read_avail_input (expected); |
4945 | sigsetmask (mask); | |
4946 | } | |
4947 | else | |
87485d6f | 4948 | #endif |
284f4730 JB |
4949 | #endif |
4950 | read_avail_input (expected); | |
4951 | #endif | |
4952 | } | |
a8015ab5 | 4953 | |
241ceaf7 RS |
4954 | /* Put a buffer_switch_event in the buffer |
4955 | so that read_key_sequence will notice the new current buffer. */ | |
4956 | ||
07a59269 | 4957 | void |
a8015ab5 KH |
4958 | record_asynch_buffer_change () |
4959 | { | |
4960 | struct input_event event; | |
a30f0615 RS |
4961 | Lisp_Object tem; |
4962 | ||
a8015ab5 KH |
4963 | event.kind = buffer_switch_event; |
4964 | event.frame_or_window = Qnil; | |
241ceaf7 | 4965 | |
f65e6f7d | 4966 | #ifdef subprocesses |
a30f0615 RS |
4967 | /* We don't need a buffer-switch event unless Emacs is waiting for input. |
4968 | The purpose of the event is to make read_key_sequence look up the | |
4969 | keymaps again. If we aren't in read_key_sequence, we don't need one, | |
4970 | and the event could cause trouble by messing up (input-pending-p). */ | |
4971 | tem = Fwaiting_for_user_input_p (); | |
4972 | if (NILP (tem)) | |
4973 | return; | |
f65e6f7d RS |
4974 | #else |
4975 | /* We never need these events if we have no asynchronous subprocesses. */ | |
4976 | return; | |
4977 | #endif | |
a30f0615 | 4978 | |
241ceaf7 RS |
4979 | /* Make sure no interrupt happens while storing the event. */ |
4980 | #ifdef SIGIO | |
4981 | if (interrupt_input) | |
4982 | { | |
4983 | SIGMASKTYPE mask; | |
4f8aaa74 | 4984 | mask = sigblock (sigmask (SIGIO)); |
241ceaf7 RS |
4985 | kbd_buffer_store_event (&event); |
4986 | sigsetmask (mask); | |
4987 | } | |
4988 | else | |
4989 | #endif | |
4990 | { | |
4991 | stop_polling (); | |
4992 | kbd_buffer_store_event (&event); | |
4993 | start_polling (); | |
4994 | } | |
a8015ab5 | 4995 | } |
284f4730 JB |
4996 | \f |
4997 | #ifndef VMS | |
4998 | ||
4999 | /* Read any terminal input already buffered up by the system | |
5000 | into the kbd_buffer, but do not wait. | |
5001 | ||
5002 | EXPECTED should be nonzero if the caller knows there is some input. | |
5003 | ||
5004 | Except on VMS, all input is read by this function. | |
5005 | If interrupt_input is nonzero, this function MUST be called | |
5006 | only when SIGIO is blocked. | |
5007 | ||
5008 | Returns the number of keyboard chars read, or -1 meaning | |
5009 | this is a bad time to try to read input. */ | |
5010 | ||
5011 | static int | |
5012 | read_avail_input (expected) | |
5013 | int expected; | |
5014 | { | |
5015 | struct input_event buf[KBD_BUFFER_SIZE]; | |
5016 | register int i; | |
5017 | int nread; | |
5018 | ||
5019 | if (read_socket_hook) | |
5020 | /* No need for FIONREAD or fcntl; just say don't wait. */ | |
33e19c6e | 5021 | nread = (*read_socket_hook) (input_fd, buf, KBD_BUFFER_SIZE, expected); |
284f4730 JB |
5022 | else |
5023 | { | |
17270835 RS |
5024 | /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than |
5025 | the kbd_buffer can really hold. That may prevent loss | |
5026 | of characters on some systems when input is stuffed at us. */ | |
5027 | unsigned char cbuf[KBD_BUFFER_SIZE - 1]; | |
58788063 | 5028 | int n_to_read; |
284f4730 | 5029 | |
58788063 | 5030 | /* Determine how many characters we should *try* to read. */ |
bc536d84 RS |
5031 | #ifdef WINDOWSNT |
5032 | return 0; | |
5033 | #else /* not WINDOWSNT */ | |
80e4aa30 | 5034 | #ifdef MSDOS |
58788063 RS |
5035 | n_to_read = dos_keysns (); |
5036 | if (n_to_read == 0) | |
5037 | return 0; | |
c3a2738c | 5038 | #else /* not MSDOS */ |
284f4730 JB |
5039 | #ifdef FIONREAD |
5040 | /* Find out how much input is available. */ | |
437f6112 | 5041 | if (ioctl (input_fd, FIONREAD, &n_to_read) < 0) |
284f4730 JB |
5042 | /* Formerly simply reported no input, but that sometimes led to |
5043 | a failure of Emacs to terminate. | |
5044 | SIGHUP seems appropriate if we can't reach the terminal. */ | |
e4535288 RS |
5045 | /* ??? Is it really right to send the signal just to this process |
5046 | rather than to the whole process group? | |
5047 | Perhaps on systems with FIONREAD Emacs is alone in its group. */ | |
284f4730 | 5048 | kill (getpid (), SIGHUP); |
58788063 | 5049 | if (n_to_read == 0) |
284f4730 | 5050 | return 0; |
58788063 RS |
5051 | if (n_to_read > sizeof cbuf) |
5052 | n_to_read = sizeof cbuf; | |
284f4730 | 5053 | #else /* no FIONREAD */ |
0c04a67e | 5054 | #if defined (USG) || defined (DGUX) |
284f4730 | 5055 | /* Read some input if available, but don't wait. */ |
58788063 | 5056 | n_to_read = sizeof cbuf; |
437f6112 | 5057 | fcntl (input_fd, F_SETFL, O_NDELAY); |
284f4730 JB |
5058 | #else |
5059 | you lose; | |
5060 | #endif | |
5061 | #endif | |
80e4aa30 | 5062 | #endif /* not MSDOS */ |
bc536d84 | 5063 | #endif /* not WINDOWSNT */ |
284f4730 | 5064 | |
58788063 RS |
5065 | /* Now read; for one reason or another, this will not block. |
5066 | NREAD is set to the number of chars read. */ | |
9134775b | 5067 | do |
284f4730 | 5068 | { |
80e4aa30 | 5069 | #ifdef MSDOS |
0c04a67e | 5070 | cbuf[0] = dos_keyread (); |
80e4aa30 RS |
5071 | nread = 1; |
5072 | #else | |
437f6112 | 5073 | nread = read (input_fd, cbuf, n_to_read); |
80e4aa30 | 5074 | #endif |
49854566 RS |
5075 | /* POSIX infers that processes which are not in the session leader's |
5076 | process group won't get SIGHUP's at logout time. BSDI adheres to | |
5077 | this part standard and returns -1 from read(0) with errno==EIO | |
5078 | when the control tty is taken away. | |
5079 | Jeffrey Honig <jch@bsdi.com> says this is generally safe. */ | |
5080 | if (nread == -1 && errno == EIO) | |
5081 | kill (0, SIGHUP); | |
762f2b92 | 5082 | #if defined (AIX) && (! defined (aix386) && defined (_BSD)) |
284f4730 JB |
5083 | /* The kernel sometimes fails to deliver SIGHUP for ptys. |
5084 | This looks incorrect, but it isn't, because _BSD causes | |
5085 | O_NDELAY to be defined in fcntl.h as O_NONBLOCK, | |
5086 | and that causes a value other than 0 when there is no input. */ | |
854f3a54 | 5087 | if (nread == 0) |
80e4aa30 | 5088 | kill (0, SIGHUP); |
284f4730 | 5089 | #endif |
9134775b | 5090 | } |
791587ee KH |
5091 | while ( |
5092 | /* We used to retry the read if it was interrupted. | |
5093 | But this does the wrong thing when O_NDELAY causes | |
5094 | an EAGAIN error. Does anybody know of a situation | |
5095 | where a retry is actually needed? */ | |
5096 | #if 0 | |
5097 | nread < 0 && (errno == EAGAIN | |
6aec06f5 | 5098 | #ifdef EFAULT |
9134775b | 5099 | || errno == EFAULT |
80e4aa30 | 5100 | #endif |
284f4730 | 5101 | #ifdef EBADSLT |
9134775b | 5102 | || errno == EBADSLT |
284f4730 | 5103 | #endif |
791587ee KH |
5104 | ) |
5105 | #else | |
5106 | 0 | |
5107 | #endif | |
5108 | ); | |
284f4730 JB |
5109 | |
5110 | #ifndef FIONREAD | |
02c2c53f | 5111 | #if defined (USG) || defined (DGUX) |
437f6112 | 5112 | fcntl (input_fd, F_SETFL, 0); |
02c2c53f | 5113 | #endif /* USG or DGUX */ |
284f4730 JB |
5114 | #endif /* no FIONREAD */ |
5115 | for (i = 0; i < nread; i++) | |
5116 | { | |
5117 | buf[i].kind = ascii_keystroke; | |
86e5706b | 5118 | buf[i].modifiers = 0; |
b04904fb | 5119 | if (meta_key == 1 && (cbuf[i] & 0x80)) |
86e5706b | 5120 | buf[i].modifiers = meta_modifier; |
b04904fb RS |
5121 | if (meta_key != 2) |
5122 | cbuf[i] &= ~0x80; | |
f3e59d5e KH |
5123 | |
5124 | buf[i].code = cbuf[i]; | |
18cd2eeb | 5125 | XSETFRAME (buf[i].frame_or_window, selected_frame); |
284f4730 JB |
5126 | } |
5127 | } | |
5128 | ||
5129 | /* Scan the chars for C-g and store them in kbd_buffer. */ | |
5130 | for (i = 0; i < nread; i++) | |
5131 | { | |
5132 | kbd_buffer_store_event (&buf[i]); | |
5133 | /* Don't look at input that follows a C-g too closely. | |
5134 | This reduces lossage due to autorepeat on C-g. */ | |
5135 | if (buf[i].kind == ascii_keystroke | |
9343ab07 | 5136 | && buf[i].code == quit_char) |
284f4730 JB |
5137 | break; |
5138 | } | |
5139 | ||
5140 | return nread; | |
5141 | } | |
5142 | #endif /* not VMS */ | |
5143 | \f | |
5144 | #ifdef SIGIO /* for entire page */ | |
5145 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
5146 | ||
2ce30ea2 | 5147 | SIGTYPE |
284f4730 JB |
5148 | input_available_signal (signo) |
5149 | int signo; | |
5150 | { | |
5151 | /* Must preserve main program's value of errno. */ | |
5152 | int old_errno = errno; | |
5153 | #ifdef BSD4_1 | |
5154 | extern int select_alarmed; | |
5155 | #endif | |
5156 | ||
5970a8cb | 5157 | #if defined (USG) && !defined (POSIX_SIGNALS) |
284f4730 JB |
5158 | /* USG systems forget handlers when they are used; |
5159 | must reestablish each time */ | |
5160 | signal (signo, input_available_signal); | |
5161 | #endif /* USG */ | |
5162 | ||
5163 | #ifdef BSD4_1 | |
5164 | sigisheld (SIGIO); | |
5165 | #endif | |
5166 | ||
ffd56f97 JB |
5167 | if (input_available_clear_time) |
5168 | EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); | |
284f4730 JB |
5169 | |
5170 | while (1) | |
5171 | { | |
5172 | int nread; | |
5173 | nread = read_avail_input (1); | |
5174 | /* -1 means it's not ok to read the input now. | |
5175 | UNBLOCK_INPUT will read it later; now, avoid infinite loop. | |
5176 | 0 means there was no keyboard input available. */ | |
5177 | if (nread <= 0) | |
5178 | break; | |
5179 | ||
5180 | #ifdef BSD4_1 | |
5181 | select_alarmed = 1; /* Force the select emulator back to life */ | |
5182 | #endif | |
5183 | } | |
5184 | ||
5185 | #ifdef BSD4_1 | |
5186 | sigfree (); | |
5187 | #endif | |
5188 | errno = old_errno; | |
5189 | } | |
5190 | #endif /* SIGIO */ | |
ad163903 JB |
5191 | |
5192 | /* Send ourselves a SIGIO. | |
5193 | ||
5194 | This function exists so that the UNBLOCK_INPUT macro in | |
5195 | blockinput.h can have some way to take care of input we put off | |
5196 | dealing with, without assuming that every file which uses | |
5197 | UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */ | |
5198 | void | |
5199 | reinvoke_input_signal () | |
5200 | { | |
df0f2ba1 | 5201 | #ifdef SIGIO |
87dd9b9b | 5202 | kill (getpid (), SIGIO); |
ad163903 JB |
5203 | #endif |
5204 | } | |
5205 | ||
5206 | ||
284f4730 JB |
5207 | \f |
5208 | /* Return the prompt-string of a sparse keymap. | |
5209 | This is the first element which is a string. | |
5210 | Return nil if there is none. */ | |
5211 | ||
5212 | Lisp_Object | |
5213 | map_prompt (map) | |
5214 | Lisp_Object map; | |
5215 | { | |
5216 | while (CONSP (map)) | |
5217 | { | |
5218 | register Lisp_Object tem; | |
5219 | tem = Fcar (map); | |
8c18cbfb | 5220 | if (STRINGP (tem)) |
284f4730 JB |
5221 | return tem; |
5222 | map = Fcdr (map); | |
5223 | } | |
5224 | return Qnil; | |
5225 | } | |
5226 | ||
b7c49376 RS |
5227 | static void menu_bar_item (); |
5228 | static void menu_bar_one_keymap (); | |
5229 | ||
5230 | /* These variables hold the vector under construction within | |
5231 | menu_bar_items and its subroutines, and the current index | |
5232 | for storing into that vector. */ | |
5233 | static Lisp_Object menu_bar_items_vector; | |
9343ab07 | 5234 | static int menu_bar_items_index; |
5ec75a55 | 5235 | |
b7c49376 RS |
5236 | /* Return a vector of menu items for a menu bar, appropriate |
5237 | to the current buffer. Each item has three elements in the vector: | |
f5e09c8b | 5238 | KEY STRING MAPLIST. |
b7c49376 RS |
5239 | |
5240 | OLD is an old vector we can optionally reuse, or nil. */ | |
5ec75a55 RS |
5241 | |
5242 | Lisp_Object | |
b7c49376 RS |
5243 | menu_bar_items (old) |
5244 | Lisp_Object old; | |
5ec75a55 RS |
5245 | { |
5246 | /* The number of keymaps we're scanning right now, and the number of | |
5247 | keymaps we have allocated space for. */ | |
5248 | int nmaps; | |
5249 | ||
5250 | /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] | |
5251 | in the current keymaps, or nil where it is not a prefix. */ | |
5252 | Lisp_Object *maps; | |
5253 | ||
9f9c0e27 | 5254 | Lisp_Object def, tem, tail; |
5ec75a55 RS |
5255 | |
5256 | Lisp_Object result; | |
5257 | ||
5258 | int mapno; | |
47d319aa | 5259 | Lisp_Object oquit; |
5ec75a55 | 5260 | |
b7c49376 RS |
5261 | int i; |
5262 | ||
5263 | struct gcpro gcpro1; | |
5264 | ||
db60d856 JB |
5265 | /* In order to build the menus, we need to call the keymap |
5266 | accessors. They all call QUIT. But this function is called | |
5267 | during redisplay, during which a quit is fatal. So inhibit | |
47d319aa RS |
5268 | quitting while building the menus. |
5269 | We do this instead of specbind because (1) errors will clear it anyway | |
5270 | and (2) this avoids risk of specpdl overflow. */ | |
5271 | oquit = Vinhibit_quit; | |
df0f2ba1 | 5272 | Vinhibit_quit = Qt; |
db60d856 | 5273 | |
b7c49376 RS |
5274 | if (!NILP (old)) |
5275 | menu_bar_items_vector = old; | |
5276 | else | |
5277 | menu_bar_items_vector = Fmake_vector (make_number (24), Qnil); | |
5278 | menu_bar_items_index = 0; | |
5279 | ||
5280 | GCPRO1 (menu_bar_items_vector); | |
5281 | ||
5ec75a55 RS |
5282 | /* Build our list of keymaps. |
5283 | If we recognize a function key and replace its escape sequence in | |
5284 | keybuf with its symbol, or if the sequence starts with a mouse | |
5285 | click and we need to switch buffers, we jump back here to rebuild | |
5286 | the initial keymaps from the current buffer. */ | |
df0f2ba1 | 5287 | { |
5ec75a55 RS |
5288 | Lisp_Object *tmaps; |
5289 | ||
217258d5 | 5290 | /* Should overriding-terminal-local-map and overriding-local-map apply? */ |
d0a49716 | 5291 | if (!NILP (Voverriding_local_map_menu_flag)) |
9dd3131c | 5292 | { |
217258d5 KH |
5293 | /* Yes, use them (if non-nil) as well as the global map. */ |
5294 | maps = (Lisp_Object *) alloca (3 * sizeof (maps[0])); | |
5295 | nmaps = 0; | |
5296 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
5297 | maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
5298 | if (!NILP (Voverriding_local_map)) | |
5299 | maps[nmaps++] = Voverriding_local_map; | |
9dd3131c RS |
5300 | } |
5301 | else | |
5302 | { | |
d0a49716 | 5303 | /* No, so use major and minor mode keymaps. */ |
217258d5 KH |
5304 | nmaps = current_minor_maps (NULL, &tmaps); |
5305 | maps = (Lisp_Object *) alloca ((nmaps + 2) * sizeof (maps[0])); | |
5306 | bcopy (tmaps, maps, nmaps * sizeof (maps[0])); | |
5ec75a55 | 5307 | #ifdef USE_TEXT_PROPERTIES |
217258d5 | 5308 | maps[nmaps++] = get_local_map (PT, current_buffer); |
5ec75a55 | 5309 | #else |
217258d5 | 5310 | maps[nmaps++] = current_buffer->keymap; |
5ec75a55 | 5311 | #endif |
9dd3131c | 5312 | } |
217258d5 | 5313 | maps[nmaps++] = current_global_map; |
5ec75a55 RS |
5314 | } |
5315 | ||
5316 | /* Look up in each map the dummy prefix key `menu-bar'. */ | |
5317 | ||
5318 | result = Qnil; | |
5319 | ||
e58aa385 | 5320 | for (mapno = nmaps - 1; mapno >= 0; mapno--) |
5ec75a55 RS |
5321 | { |
5322 | if (! NILP (maps[mapno])) | |
c6a67acd | 5323 | def = get_keyelt (access_keymap (maps[mapno], Qmenu_bar, 1, 0), 0); |
5ec75a55 RS |
5324 | else |
5325 | def = Qnil; | |
5326 | ||
5327 | tem = Fkeymapp (def); | |
5328 | if (!NILP (tem)) | |
b7c49376 | 5329 | menu_bar_one_keymap (def); |
5ec75a55 RS |
5330 | } |
5331 | ||
b7c49376 RS |
5332 | /* Move to the end those items that should be at the end. */ |
5333 | ||
9f9c0e27 RS |
5334 | for (tail = Vmenu_bar_final_items; CONSP (tail); tail = XCONS (tail)->cdr) |
5335 | { | |
b7c49376 RS |
5336 | int i; |
5337 | int end = menu_bar_items_index; | |
5338 | ||
35b3402f | 5339 | for (i = 0; i < end; i += 4) |
b7c49376 RS |
5340 | if (EQ (XCONS (tail)->car, XVECTOR (menu_bar_items_vector)->contents[i])) |
5341 | { | |
35b3402f | 5342 | Lisp_Object tem0, tem1, tem2, tem3; |
0301268e RS |
5343 | /* Move the item at index I to the end, |
5344 | shifting all the others forward. */ | |
5345 | tem0 = XVECTOR (menu_bar_items_vector)->contents[i + 0]; | |
5346 | tem1 = XVECTOR (menu_bar_items_vector)->contents[i + 1]; | |
5347 | tem2 = XVECTOR (menu_bar_items_vector)->contents[i + 2]; | |
35b3402f RS |
5348 | tem3 = XVECTOR (menu_bar_items_vector)->contents[i + 3]; |
5349 | if (end > i + 4) | |
5350 | bcopy (&XVECTOR (menu_bar_items_vector)->contents[i + 4], | |
0301268e | 5351 | &XVECTOR (menu_bar_items_vector)->contents[i], |
35b3402f RS |
5352 | (end - i - 4) * sizeof (Lisp_Object)); |
5353 | XVECTOR (menu_bar_items_vector)->contents[end - 4] = tem0; | |
5354 | XVECTOR (menu_bar_items_vector)->contents[end - 3] = tem1; | |
5355 | XVECTOR (menu_bar_items_vector)->contents[end - 2] = tem2; | |
5356 | XVECTOR (menu_bar_items_vector)->contents[end - 1] = tem3; | |
0301268e | 5357 | break; |
b7c49376 RS |
5358 | } |
5359 | } | |
9f9c0e27 | 5360 | |
0c9071cd | 5361 | /* Add nil, nil, nil, nil at the end. */ |
b7c49376 | 5362 | i = menu_bar_items_index; |
35b3402f | 5363 | if (i + 4 > XVECTOR (menu_bar_items_vector)->size) |
b7c49376 RS |
5364 | { |
5365 | Lisp_Object tem; | |
5366 | int newsize = 2 * i; | |
5367 | tem = Fmake_vector (make_number (2 * i), Qnil); | |
5368 | bcopy (XVECTOR (menu_bar_items_vector)->contents, | |
5369 | XVECTOR (tem)->contents, i * sizeof (Lisp_Object)); | |
5370 | menu_bar_items_vector = tem; | |
9f9c0e27 | 5371 | } |
b7c49376 RS |
5372 | /* Add this item. */ |
5373 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
5374 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
5375 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
35b3402f | 5376 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; |
b7c49376 | 5377 | menu_bar_items_index = i; |
a73c5e29 | 5378 | |
47d319aa | 5379 | Vinhibit_quit = oquit; |
b7c49376 RS |
5380 | UNGCPRO; |
5381 | return menu_bar_items_vector; | |
5ec75a55 RS |
5382 | } |
5383 | \f | |
5384 | /* Scan one map KEYMAP, accumulating any menu items it defines | |
f5e09c8b | 5385 | in menu_bar_items_vector. */ |
5ec75a55 | 5386 | |
b7c49376 RS |
5387 | static void |
5388 | menu_bar_one_keymap (keymap) | |
5389 | Lisp_Object keymap; | |
5ec75a55 RS |
5390 | { |
5391 | Lisp_Object tail, item, key, binding, item_string, table; | |
5392 | ||
5393 | /* Loop over all keymap entries that have menu strings. */ | |
8c18cbfb | 5394 | for (tail = keymap; CONSP (tail); tail = XCONS (tail)->cdr) |
5ec75a55 RS |
5395 | { |
5396 | item = XCONS (tail)->car; | |
8c18cbfb | 5397 | if (CONSP (item)) |
5ec75a55 RS |
5398 | { |
5399 | key = XCONS (item)->car; | |
5400 | binding = XCONS (item)->cdr; | |
8c18cbfb | 5401 | if (CONSP (binding)) |
5ec75a55 RS |
5402 | { |
5403 | item_string = XCONS (binding)->car; | |
8c18cbfb | 5404 | if (STRINGP (item_string)) |
b7c49376 | 5405 | menu_bar_item (key, item_string, Fcdr (binding)); |
5ec75a55 | 5406 | } |
e58aa385 | 5407 | else if (EQ (binding, Qundefined)) |
8aa034e1 | 5408 | menu_bar_item (key, Qnil, binding); |
5ec75a55 | 5409 | } |
8c18cbfb | 5410 | else if (VECTORP (item)) |
5ec75a55 RS |
5411 | { |
5412 | /* Loop over the char values represented in the vector. */ | |
5413 | int len = XVECTOR (item)->size; | |
5414 | int c; | |
5415 | for (c = 0; c < len; c++) | |
5416 | { | |
5417 | Lisp_Object character; | |
bb9e9bed | 5418 | XSETFASTINT (character, c); |
5ec75a55 | 5419 | binding = XVECTOR (item)->contents[c]; |
8c18cbfb | 5420 | if (CONSP (binding)) |
5ec75a55 RS |
5421 | { |
5422 | item_string = XCONS (binding)->car; | |
8c18cbfb | 5423 | if (STRINGP (item_string)) |
b7c49376 | 5424 | menu_bar_item (key, item_string, Fcdr (binding)); |
5ec75a55 | 5425 | } |
e58aa385 | 5426 | else if (EQ (binding, Qundefined)) |
8aa034e1 | 5427 | menu_bar_item (key, Qnil, binding); |
5ec75a55 RS |
5428 | } |
5429 | } | |
5430 | } | |
5ec75a55 RS |
5431 | } |
5432 | ||
047a8ea7 RS |
5433 | /* This is used as the handler when calling internal_condition_case_1. */ |
5434 | ||
5435 | static Lisp_Object | |
5436 | menu_bar_item_1 (arg) | |
5437 | Lisp_Object arg; | |
5438 | { | |
5439 | return Qnil; | |
5440 | } | |
5441 | ||
f5e09c8b RS |
5442 | /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF. |
5443 | If there's already an item for KEY, add this DEF to it. */ | |
5444 | ||
b7c49376 RS |
5445 | static void |
5446 | menu_bar_item (key, item_string, def) | |
5447 | Lisp_Object key, item_string, def; | |
5ec75a55 | 5448 | { |
e58aa385 | 5449 | Lisp_Object tem; |
5ec75a55 | 5450 | Lisp_Object enabled; |
b7c49376 | 5451 | int i; |
5ec75a55 | 5452 | |
210df3bf KH |
5453 | /* Skip menu-bar equiv keys data. */ |
5454 | if (CONSP (def) && CONSP (XCONS (def)->car)) | |
5455 | def = XCONS (def)->cdr; | |
5456 | ||
e58aa385 RS |
5457 | if (EQ (def, Qundefined)) |
5458 | { | |
f5e09c8b | 5459 | /* If a map has an explicit `undefined' as definition, |
e58aa385 | 5460 | discard any previously made menu bar item. */ |
b7c49376 | 5461 | |
35b3402f | 5462 | for (i = 0; i < menu_bar_items_index; i += 4) |
b7c49376 RS |
5463 | if (EQ (key, XVECTOR (menu_bar_items_vector)->contents[i])) |
5464 | { | |
35b3402f RS |
5465 | if (menu_bar_items_index > i + 4) |
5466 | bcopy (&XVECTOR (menu_bar_items_vector)->contents[i + 4], | |
b7c49376 | 5467 | &XVECTOR (menu_bar_items_vector)->contents[i], |
35b3402f RS |
5468 | (menu_bar_items_index - i - 4) * sizeof (Lisp_Object)); |
5469 | menu_bar_items_index -= 4; | |
b7c49376 RS |
5470 | return; |
5471 | } | |
8aa034e1 RS |
5472 | |
5473 | /* If there's no definition for this key yet, | |
5474 | just ignore `undefined'. */ | |
5475 | return; | |
e58aa385 RS |
5476 | } |
5477 | ||
5ec75a55 RS |
5478 | /* See if this entry is enabled. */ |
5479 | enabled = Qt; | |
5480 | ||
8c18cbfb | 5481 | if (SYMBOLP (def)) |
5ec75a55 RS |
5482 | { |
5483 | /* No property, or nil, means enable. | |
5484 | Otherwise, enable if value is not nil. */ | |
5485 | tem = Fget (def, Qmenu_enable); | |
5486 | if (!NILP (tem)) | |
047a8ea7 RS |
5487 | /* (condition-case nil (eval tem) |
5488 | (error nil)) */ | |
5489 | enabled = internal_condition_case_1 (Feval, tem, Qerror, | |
5490 | menu_bar_item_1); | |
5ec75a55 RS |
5491 | } |
5492 | ||
b7c49376 RS |
5493 | /* Ignore this item if it's not enabled. */ |
5494 | if (NILP (enabled)) | |
5495 | return; | |
5ec75a55 | 5496 | |
f5e09c8b | 5497 | /* Find any existing item for this KEY. */ |
35b3402f | 5498 | for (i = 0; i < menu_bar_items_index; i += 4) |
b7c49376 RS |
5499 | if (EQ (key, XVECTOR (menu_bar_items_vector)->contents[i])) |
5500 | break; | |
5501 | ||
f5e09c8b | 5502 | /* If we did not find this KEY, add it at the end. */ |
b7c49376 RS |
5503 | if (i == menu_bar_items_index) |
5504 | { | |
5505 | /* If vector is too small, get a bigger one. */ | |
35b3402f | 5506 | if (i + 4 > XVECTOR (menu_bar_items_vector)->size) |
b7c49376 RS |
5507 | { |
5508 | Lisp_Object tem; | |
5509 | int newsize = 2 * i; | |
5510 | tem = Fmake_vector (make_number (2 * i), Qnil); | |
5511 | bcopy (XVECTOR (menu_bar_items_vector)->contents, | |
5512 | XVECTOR (tem)->contents, i * sizeof (Lisp_Object)); | |
5513 | menu_bar_items_vector = tem; | |
5514 | } | |
5515 | /* Add this item. */ | |
5516 | XVECTOR (menu_bar_items_vector)->contents[i++] = key; | |
5517 | XVECTOR (menu_bar_items_vector)->contents[i++] = item_string; | |
f5e09c8b | 5518 | XVECTOR (menu_bar_items_vector)->contents[i++] = Fcons (def, Qnil); |
35b3402f | 5519 | XVECTOR (menu_bar_items_vector)->contents[i++] = make_number (0); |
b7c49376 RS |
5520 | menu_bar_items_index = i; |
5521 | } | |
f5e09c8b RS |
5522 | /* We did find an item for this KEY. Add DEF to its list of maps. */ |
5523 | else | |
5524 | { | |
5525 | Lisp_Object old; | |
5526 | old = XVECTOR (menu_bar_items_vector)->contents[i + 2]; | |
5527 | XVECTOR (menu_bar_items_vector)->contents[i + 2] = Fcons (def, old); | |
5528 | } | |
5ec75a55 RS |
5529 | } |
5530 | \f | |
dcc408a0 RS |
5531 | /* Read a character using menus based on maps in the array MAPS. |
5532 | NMAPS is the length of MAPS. Return nil if there are no menus in the maps. | |
5533 | Return t if we displayed a menu but the user rejected it. | |
7d6de002 RS |
5534 | |
5535 | PREV_EVENT is the previous input event, or nil if we are reading | |
5536 | the first event of a key sequence. | |
5537 | ||
83d68044 | 5538 | If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1 |
6569cc8d | 5539 | if we used a mouse menu to read the input, or zero otherwise. If |
83d68044 | 5540 | USED_MOUSE_MENU is null, we don't dereference it. |
284f4730 JB |
5541 | |
5542 | The prompting is done based on the prompt-string of the map | |
df0f2ba1 | 5543 | and the strings associated with various map elements. |
8150596a RS |
5544 | |
5545 | This can be done with X menus or with menus put in the minibuf. | |
5546 | These are done in different ways, depending on how the input will be read. | |
5547 | Menus using X are done after auto-saving in read-char, getting the input | |
5548 | event from Fx_popup_menu; menus using the minibuf use read_char recursively | |
5549 | and do auto-saving in the inner call of read_char. */ | |
284f4730 | 5550 | |
7617111f | 5551 | static Lisp_Object |
8150596a | 5552 | read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu) |
7d6de002 RS |
5553 | int nmaps; |
5554 | Lisp_Object *maps; | |
5555 | Lisp_Object prev_event; | |
5556 | int *used_mouse_menu; | |
284f4730 | 5557 | { |
7d6de002 RS |
5558 | int mapno; |
5559 | register Lisp_Object name; | |
7d6de002 RS |
5560 | Lisp_Object rest, vector; |
5561 | ||
6569cc8d JB |
5562 | if (used_mouse_menu) |
5563 | *used_mouse_menu = 0; | |
284f4730 JB |
5564 | |
5565 | /* Use local over global Menu maps */ | |
5566 | ||
7d6de002 RS |
5567 | if (! menu_prompting) |
5568 | return Qnil; | |
5569 | ||
03361bcc RS |
5570 | /* Optionally disregard all but the global map. */ |
5571 | if (inhibit_local_menu_bar_menus) | |
5572 | { | |
5573 | maps += (nmaps - 1); | |
5574 | nmaps = 1; | |
5575 | } | |
5576 | ||
7d6de002 RS |
5577 | /* Get the menu name from the first map that has one (a prompt string). */ |
5578 | for (mapno = 0; mapno < nmaps; mapno++) | |
5579 | { | |
5580 | name = map_prompt (maps[mapno]); | |
5581 | if (!NILP (name)) | |
5582 | break; | |
5583 | } | |
284f4730 | 5584 | |
7d6de002 | 5585 | /* If we don't have any menus, just read a character normally. */ |
dbc4e1c1 | 5586 | if (mapno >= nmaps) |
7d6de002 RS |
5587 | return Qnil; |
5588 | ||
1f5b1641 | 5589 | #ifdef HAVE_MENUS |
7d6de002 RS |
5590 | /* If we got to this point via a mouse click, |
5591 | use a real menu for mouse selection. */ | |
5a8d99e0 KH |
5592 | if (EVENT_HAS_PARAMETERS (prev_event) |
5593 | && !EQ (XCONS (prev_event)->car, Qmenu_bar)) | |
7d6de002 RS |
5594 | { |
5595 | /* Display the menu and get the selection. */ | |
5596 | Lisp_Object *realmaps | |
5597 | = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); | |
5598 | Lisp_Object value; | |
5599 | int nmaps1 = 0; | |
5600 | ||
5601 | /* Use the maps that are not nil. */ | |
5602 | for (mapno = 0; mapno < nmaps; mapno++) | |
5603 | if (!NILP (maps[mapno])) | |
5604 | realmaps[nmaps1++] = maps[mapno]; | |
5605 | ||
5606 | value = Fx_popup_menu (prev_event, Flist (nmaps1, realmaps)); | |
663258f2 JB |
5607 | if (CONSP (value)) |
5608 | { | |
68f297c5 RS |
5609 | Lisp_Object tem; |
5610 | ||
8eb4d8ef RS |
5611 | record_menu_key (XCONS (value)->car); |
5612 | ||
68f297c5 RS |
5613 | /* If we got multiple events, unread all but |
5614 | the first. | |
5615 | There is no way to prevent those unread events | |
5616 | from showing up later in last_nonmenu_event. | |
5617 | So turn symbol and integer events into lists, | |
5618 | to indicate that they came from a mouse menu, | |
5619 | so that when present in last_nonmenu_event | |
5620 | they won't confuse things. */ | |
5621 | for (tem = XCONS (value)->cdr; !NILP (tem); | |
5622 | tem = XCONS (tem)->cdr) | |
8eb4d8ef RS |
5623 | { |
5624 | record_menu_key (XCONS (tem)->car); | |
5625 | if (SYMBOLP (XCONS (tem)->car) | |
5626 | || INTEGERP (XCONS (tem)->car)) | |
5627 | XCONS (tem)->car | |
5628 | = Fcons (XCONS (tem)->car, Qnil); | |
5629 | } | |
68f297c5 | 5630 | |
663258f2 JB |
5631 | /* If we got more than one event, put all but the first |
5632 | onto this list to be read later. | |
5633 | Return just the first event now. */ | |
24597608 RS |
5634 | Vunread_command_events |
5635 | = nconc2 (XCONS (value)->cdr, Vunread_command_events); | |
663258f2 JB |
5636 | value = XCONS (value)->car; |
5637 | } | |
1c90c381 | 5638 | else if (NILP (value)) |
dcc408a0 | 5639 | value = Qt; |
6569cc8d JB |
5640 | if (used_mouse_menu) |
5641 | *used_mouse_menu = 1; | |
7d6de002 RS |
5642 | return value; |
5643 | } | |
1f5b1641 | 5644 | #endif /* HAVE_MENUS */ |
8150596a RS |
5645 | return Qnil ; |
5646 | } | |
5647 | ||
68e0de82 RS |
5648 | /* Buffer in use so far for the minibuf prompts for menu keymaps. |
5649 | We make this bigger when necessary, and never free it. */ | |
5650 | static char *read_char_minibuf_menu_text; | |
5651 | /* Size of that buffer. */ | |
5652 | static int read_char_minibuf_menu_width; | |
5653 | ||
8150596a | 5654 | static Lisp_Object |
24597608 | 5655 | read_char_minibuf_menu_prompt (commandflag, nmaps, maps) |
8150596a RS |
5656 | int commandflag ; |
5657 | int nmaps; | |
5658 | Lisp_Object *maps; | |
5659 | { | |
5660 | int mapno; | |
5661 | register Lisp_Object name; | |
5662 | int nlength; | |
5663 | int width = FRAME_WIDTH (selected_frame) - 4; | |
8150596a | 5664 | int idx = -1; |
9fdbfdf8 | 5665 | int nobindings = 1; |
8150596a | 5666 | Lisp_Object rest, vector; |
68e0de82 | 5667 | char *menu; |
8150596a RS |
5668 | |
5669 | if (! menu_prompting) | |
5670 | return Qnil; | |
5671 | ||
68e0de82 RS |
5672 | /* Make sure we have a big enough buffer for the menu text. */ |
5673 | if (read_char_minibuf_menu_text == 0) | |
5674 | { | |
5675 | read_char_minibuf_menu_width = width + 4; | |
5676 | read_char_minibuf_menu_text = (char *) xmalloc (width + 4); | |
5677 | } | |
5678 | else if (width + 4 > read_char_minibuf_menu_width) | |
5679 | { | |
5680 | read_char_minibuf_menu_width = width + 4; | |
5681 | read_char_minibuf_menu_text | |
5682 | = (char *) xrealloc (read_char_minibuf_menu_text, width + 4); | |
5683 | } | |
5684 | menu = read_char_minibuf_menu_text; | |
5685 | ||
8150596a RS |
5686 | /* Get the menu name from the first map that has one (a prompt string). */ |
5687 | for (mapno = 0; mapno < nmaps; mapno++) | |
5688 | { | |
5689 | name = map_prompt (maps[mapno]); | |
5690 | if (!NILP (name)) | |
5691 | break; | |
5692 | } | |
5693 | ||
5694 | /* If we don't have any menus, just read a character normally. */ | |
5695 | if (mapno >= nmaps) | |
5696 | return Qnil; | |
284f4730 JB |
5697 | |
5698 | /* Prompt string always starts with map's prompt, and a space. */ | |
5699 | strcpy (menu, XSTRING (name)->data); | |
5700 | nlength = XSTRING (name)->size; | |
7d6de002 | 5701 | menu[nlength++] = ':'; |
284f4730 JB |
5702 | menu[nlength++] = ' '; |
5703 | menu[nlength] = 0; | |
5704 | ||
7d6de002 RS |
5705 | /* Start prompting at start of first map. */ |
5706 | mapno = 0; | |
5707 | rest = maps[mapno]; | |
284f4730 JB |
5708 | |
5709 | /* Present the documented bindings, a line at a time. */ | |
5710 | while (1) | |
5711 | { | |
5712 | int notfirst = 0; | |
5713 | int i = nlength; | |
5714 | Lisp_Object obj; | |
5715 | int ch; | |
8066f1a1 | 5716 | Lisp_Object orig_defn_macro; |
284f4730 | 5717 | |
284f4730 | 5718 | /* Loop over elements of map. */ |
7d6de002 | 5719 | while (i < width) |
284f4730 | 5720 | { |
7d6de002 | 5721 | Lisp_Object s, elt; |
284f4730 | 5722 | |
7d6de002 RS |
5723 | /* If reached end of map, start at beginning of next map. */ |
5724 | if (NILP (rest)) | |
5725 | { | |
5726 | mapno++; | |
5727 | /* At end of last map, wrap around to first map if just starting, | |
5728 | or end this line if already have something on it. */ | |
5729 | if (mapno == nmaps) | |
284f4730 | 5730 | { |
8150596a | 5731 | mapno = 0; |
40932d1a | 5732 | if (notfirst || nobindings) break; |
284f4730 | 5733 | } |
7d6de002 | 5734 | rest = maps[mapno]; |
284f4730 | 5735 | } |
7d6de002 RS |
5736 | |
5737 | /* Look at the next element of the map. */ | |
5738 | if (idx >= 0) | |
5739 | elt = XVECTOR (vector)->contents[idx]; | |
284f4730 | 5740 | else |
7d6de002 RS |
5741 | elt = Fcar_safe (rest); |
5742 | ||
8c18cbfb | 5743 | if (idx < 0 && VECTORP (elt)) |
284f4730 | 5744 | { |
7d6de002 RS |
5745 | /* If we found a dense table in the keymap, |
5746 | advanced past it, but start scanning its contents. */ | |
5747 | rest = Fcdr_safe (rest); | |
5748 | vector = elt; | |
5749 | idx = 0; | |
284f4730 | 5750 | } |
7d6de002 RS |
5751 | else |
5752 | { | |
5753 | /* An ordinary element. */ | |
0a2ea221 KH |
5754 | Lisp_Object event; |
5755 | ||
5756 | if (idx < 0) | |
5757 | { | |
5758 | s = Fcar_safe (Fcdr_safe (elt)); /* alist */ | |
5759 | event = Fcar_safe (elt); | |
5760 | } | |
8150596a | 5761 | else |
7d6de002 | 5762 | { |
0a2ea221 KH |
5763 | s = Fcar_safe (elt); /* vector */ |
5764 | XSETINT (event, idx); | |
5765 | } | |
5766 | ||
5767 | /* Ignore the element if it has no prompt string. */ | |
5768 | if (STRINGP (s) && INTEGERP (event)) | |
5769 | { | |
5770 | /* 1 if the char to type matches the string. */ | |
5771 | int char_matches; | |
5772 | Lisp_Object upcased_event, downcased_event; | |
5773 | Lisp_Object desc; | |
5774 | ||
5775 | upcased_event = Fupcase (event); | |
5776 | downcased_event = Fdowncase (event); | |
5777 | char_matches = (XINT (upcased_event) == XSTRING (s)->data[0] | |
5778 | || XINT (downcased_event) == XSTRING (s)->data[0]); | |
5779 | if (! char_matches) | |
5780 | desc = Fsingle_key_description (event); | |
5781 | ||
5782 | /* If we have room for the prompt string, add it to this line. | |
5783 | If this is the first on the line, always add it. */ | |
5784 | if ((XSTRING (s)->size + i + 2 | |
5785 | + (char_matches ? 0 : XSTRING (desc)->size + 3)) | |
5786 | < width | |
5787 | || !notfirst) | |
5788 | { | |
5789 | int thiswidth; | |
5790 | ||
5791 | /* Punctuate between strings. */ | |
5792 | if (notfirst) | |
5793 | { | |
5794 | strcpy (menu + i, ", "); | |
5795 | i += 2; | |
5796 | } | |
5797 | notfirst = 1; | |
5798 | nobindings = 0 ; | |
284f4730 | 5799 | |
0a2ea221 KH |
5800 | /* If the char to type doesn't match the string's |
5801 | first char, explicitly show what char to type. */ | |
5802 | if (! char_matches) | |
5803 | { | |
5804 | /* Add as much of string as fits. */ | |
5805 | thiswidth = XSTRING (desc)->size; | |
5806 | if (thiswidth + i > width) | |
5807 | thiswidth = width - i; | |
5808 | bcopy (XSTRING (desc)->data, menu + i, thiswidth); | |
5809 | i += thiswidth; | |
5810 | strcpy (menu + i, " = "); | |
5811 | i += 3; | |
5812 | } | |
5813 | ||
5814 | /* Add as much of string as fits. */ | |
5815 | thiswidth = XSTRING (s)->size; | |
5816 | if (thiswidth + i > width) | |
5817 | thiswidth = width - i; | |
5818 | bcopy (XSTRING (s)->data, menu + i, thiswidth); | |
5819 | i += thiswidth; | |
5820 | menu[i] = 0; | |
5821 | } | |
5822 | else | |
7d6de002 | 5823 | { |
0a2ea221 KH |
5824 | /* If this element does not fit, end the line now, |
5825 | and save the element for the next line. */ | |
5826 | strcpy (menu + i, "..."); | |
5827 | break; | |
7d6de002 | 5828 | } |
7d6de002 RS |
5829 | } |
5830 | ||
5831 | /* Move past this element. */ | |
8150596a | 5832 | if (idx >= 0 && idx + 1 >= XVECTOR (vector)->size) |
7d6de002 RS |
5833 | /* Handle reaching end of dense table. */ |
5834 | idx = -1; | |
5835 | if (idx >= 0) | |
5836 | idx++; | |
5837 | else | |
5838 | rest = Fcdr_safe (rest); | |
5839 | } | |
284f4730 JB |
5840 | } |
5841 | ||
5842 | /* Prompt with that and read response. */ | |
5843 | message1 (menu); | |
8150596a | 5844 | |
df0f2ba1 | 5845 | /* Make believe its not a keyboard macro in case the help char |
8150596a RS |
5846 | is pressed. Help characters are not recorded because menu prompting |
5847 | is not used on replay. | |
5848 | */ | |
c5fdd383 KH |
5849 | orig_defn_macro = current_kboard->defining_kbd_macro; |
5850 | current_kboard->defining_kbd_macro = Qnil; | |
3cb81011 KH |
5851 | do |
5852 | obj = read_char (commandflag, 0, 0, Qnil, 0); | |
8c18cbfb | 5853 | while (BUFFERP (obj)); |
c5fdd383 | 5854 | current_kboard->defining_kbd_macro = orig_defn_macro; |
284f4730 | 5855 | |
8c18cbfb | 5856 | if (!INTEGERP (obj)) |
284f4730 JB |
5857 | return obj; |
5858 | else | |
5859 | ch = XINT (obj); | |
5860 | ||
f4255cd1 | 5861 | if (! EQ (obj, menu_prompt_more_char) |
8c18cbfb | 5862 | && (!INTEGERP (menu_prompt_more_char) |
f4255cd1 | 5863 | || ! EQ (obj, make_number (Ctl (XINT (menu_prompt_more_char)))))) |
8150596a | 5864 | { |
c5fdd383 | 5865 | if (!NILP (current_kboard->defining_kbd_macro)) |
8066f1a1 | 5866 | store_kbd_macro_char (obj); |
8150596a RS |
5867 | return obj; |
5868 | } | |
5869 | /* Help char - go round again */ | |
284f4730 JB |
5870 | } |
5871 | } | |
284f4730 JB |
5872 | \f |
5873 | /* Reading key sequences. */ | |
5874 | ||
5875 | /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings | |
5876 | in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a | |
5877 | keymap, or nil otherwise. Return the index of the first keymap in | |
5878 | which KEY has any binding, or NMAPS if no map has a binding. | |
5879 | ||
5880 | If KEY is a meta ASCII character, treat it like meta-prefix-char | |
5881 | followed by the corresponding non-meta character. Keymaps in | |
5882 | CURRENT with non-prefix bindings for meta-prefix-char become nil in | |
5883 | NEXT. | |
5884 | ||
88cb0656 JB |
5885 | If KEY has no bindings in any of the CURRENT maps, NEXT is left |
5886 | unmodified. | |
5887 | ||
569871d2 | 5888 | NEXT may be the same array as CURRENT. */ |
284f4730 JB |
5889 | |
5890 | static int | |
4e50f26a | 5891 | follow_key (key, nmaps, current, defs, next) |
284f4730 JB |
5892 | Lisp_Object key; |
5893 | Lisp_Object *current, *defs, *next; | |
5894 | int nmaps; | |
5895 | { | |
5896 | int i, first_binding; | |
569871d2 | 5897 | int did_meta = 0; |
284f4730 JB |
5898 | |
5899 | /* If KEY is a meta ASCII character, treat it like meta-prefix-char | |
569871d2 RS |
5900 | followed by the corresponding non-meta character. |
5901 | Put the results into DEFS, since we are going to alter that anyway. | |
5902 | Do not alter CURRENT or NEXT. */ | |
8c18cbfb | 5903 | if (INTEGERP (key) && (XINT (key) & CHAR_META)) |
284f4730 JB |
5904 | { |
5905 | for (i = 0; i < nmaps; i++) | |
5906 | if (! NILP (current[i])) | |
5907 | { | |
569871d2 RS |
5908 | Lisp_Object def; |
5909 | def = get_keyelt (access_keymap (current[i], | |
c6a67acd | 5910 | meta_prefix_char, 1, 0), 0); |
284f4730 JB |
5911 | |
5912 | /* Note that since we pass the resulting bindings through | |
5913 | get_keymap_1, non-prefix bindings for meta-prefix-char | |
5914 | disappear. */ | |
569871d2 | 5915 | defs[i] = get_keymap_1 (def, 0, 1); |
284f4730 JB |
5916 | } |
5917 | else | |
569871d2 | 5918 | defs[i] = Qnil; |
284f4730 | 5919 | |
569871d2 | 5920 | did_meta = 1; |
18cd2eeb | 5921 | XSETINT (key, XFASTINT (key) & ~CHAR_META); |
284f4730 JB |
5922 | } |
5923 | ||
5924 | first_binding = nmaps; | |
5925 | for (i = nmaps - 1; i >= 0; i--) | |
5926 | { | |
5927 | if (! NILP (current[i])) | |
5928 | { | |
569871d2 RS |
5929 | Lisp_Object map; |
5930 | if (did_meta) | |
5931 | map = defs[i]; | |
5932 | else | |
5933 | map = current[i]; | |
5934 | ||
c6a67acd | 5935 | defs[i] = get_keyelt (access_keymap (map, key, 1, 0), 0); |
284f4730 JB |
5936 | if (! NILP (defs[i])) |
5937 | first_binding = i; | |
5938 | } | |
5939 | else | |
5940 | defs[i] = Qnil; | |
5941 | } | |
5942 | ||
284f4730 | 5943 | /* Given the set of bindings we've found, produce the next set of maps. */ |
0a7f1fc0 JB |
5944 | if (first_binding < nmaps) |
5945 | for (i = 0; i < nmaps; i++) | |
f4255cd1 | 5946 | next[i] = NILP (defs[i]) ? Qnil : get_keymap_1 (defs[i], 0, 1); |
284f4730 JB |
5947 | |
5948 | return first_binding; | |
5949 | } | |
5950 | ||
df0f2ba1 | 5951 | /* Read a sequence of keys that ends with a non prefix character, |
f4255cd1 JB |
5952 | storing it in KEYBUF, a buffer of size BUFSIZE. |
5953 | Prompt with PROMPT. | |
284f4730 | 5954 | Return the length of the key sequence stored. |
dcc408a0 | 5955 | Return -1 if the user rejected a command menu. |
284f4730 | 5956 | |
f4255cd1 JB |
5957 | Echo starting immediately unless `prompt' is 0. |
5958 | ||
5959 | Where a key sequence ends depends on the currently active keymaps. | |
5960 | These include any minor mode keymaps active in the current buffer, | |
5961 | the current buffer's local map, and the global map. | |
5962 | ||
5963 | If a key sequence has no other bindings, we check Vfunction_key_map | |
5964 | to see if some trailing subsequence might be the beginning of a | |
5965 | function key's sequence. If so, we try to read the whole function | |
5966 | key, and substitute its symbolic name into the key sequence. | |
5967 | ||
fbcd35bd JB |
5968 | We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and |
5969 | `double-' events into similar click events, if that would make them | |
5970 | bound. We try to turn `triple-' events first into `double-' events, | |
5971 | then into clicks. | |
f4255cd1 JB |
5972 | |
5973 | If we get a mouse click in a mode line, vertical divider, or other | |
5974 | non-text area, we treat the click as if it were prefixed by the | |
5975 | symbol denoting that area - `mode-line', `vertical-line', or | |
5976 | whatever. | |
5977 | ||
5978 | If the sequence starts with a mouse click, we read the key sequence | |
5979 | with respect to the buffer clicked on, not the current buffer. | |
284f4730 | 5980 | |
f4255cd1 JB |
5981 | If the user switches frames in the midst of a key sequence, we put |
5982 | off the switch-frame event until later; the next call to | |
f571ae0d RS |
5983 | read_char will return it. |
5984 | ||
5985 | If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer | |
5986 | from the selected window's buffer. */ | |
48e416d4 | 5987 | |
284f4730 | 5988 | static int |
ce98e608 | 5989 | read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last, |
f571ae0d | 5990 | can_return_switch_frame, fix_current_buffer) |
284f4730 JB |
5991 | Lisp_Object *keybuf; |
5992 | int bufsize; | |
84d91fda | 5993 | Lisp_Object prompt; |
309b0fc8 | 5994 | int dont_downcase_last; |
ce98e608 | 5995 | int can_return_switch_frame; |
f571ae0d | 5996 | int fix_current_buffer; |
284f4730 | 5997 | { |
f4255cd1 JB |
5998 | int count = specpdl_ptr - specpdl; |
5999 | ||
284f4730 JB |
6000 | /* How many keys there are in the current key sequence. */ |
6001 | int t; | |
6002 | ||
284f4730 JB |
6003 | /* The length of the echo buffer when we started reading, and |
6004 | the length of this_command_keys when we started reading. */ | |
6005 | int echo_start; | |
f4255cd1 | 6006 | int keys_start; |
284f4730 JB |
6007 | |
6008 | /* The number of keymaps we're scanning right now, and the number of | |
6009 | keymaps we have allocated space for. */ | |
6010 | int nmaps; | |
6011 | int nmaps_allocated = 0; | |
6012 | ||
284f4730 JB |
6013 | /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in |
6014 | the current keymaps. */ | |
6015 | Lisp_Object *defs; | |
6016 | ||
f4255cd1 JB |
6017 | /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] |
6018 | in the current keymaps, or nil where it is not a prefix. */ | |
6019 | Lisp_Object *submaps; | |
6020 | ||
e0dff5f6 RS |
6021 | /* The local map to start out with at start of key sequence. */ |
6022 | Lisp_Object orig_local_map; | |
6023 | ||
6024 | /* 1 if we have already considered switching to the local-map property | |
6025 | of the place where a mouse click occurred. */ | |
6026 | int localized_local_map = 0; | |
6027 | ||
f4255cd1 JB |
6028 | /* The index in defs[] of the first keymap that has a binding for |
6029 | this key sequence. In other words, the lowest i such that | |
6030 | defs[i] is non-nil. */ | |
284f4730 JB |
6031 | int first_binding; |
6032 | ||
f4255cd1 | 6033 | /* If t < mock_input, then KEYBUF[t] should be read as the next |
253598e4 JB |
6034 | input key. |
6035 | ||
6036 | We use this to recover after recognizing a function key. Once we | |
6037 | realize that a suffix of the current key sequence is actually a | |
6038 | function key's escape sequence, we replace the suffix with the | |
6039 | function key's binding from Vfunction_key_map. Now keybuf | |
f4255cd1 JB |
6040 | contains a new and different key sequence, so the echo area, |
6041 | this_command_keys, and the submaps and defs arrays are wrong. In | |
6042 | this situation, we set mock_input to t, set t to 0, and jump to | |
6043 | restart_sequence; the loop will read keys from keybuf up until | |
6044 | mock_input, thus rebuilding the state; and then it will resume | |
6045 | reading characters from the keyboard. */ | |
284f4730 JB |
6046 | int mock_input = 0; |
6047 | ||
253598e4 | 6048 | /* If the sequence is unbound in submaps[], then |
f4255cd1 JB |
6049 | keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map, |
6050 | and fkey_map is its binding. | |
253598e4 | 6051 | |
f4255cd1 JB |
6052 | These might be > t, indicating that all function key scanning |
6053 | should hold off until t reaches them. We do this when we've just | |
6054 | recognized a function key, to avoid searching for the function | |
6055 | key's again in Vfunction_key_map. */ | |
284f4730 | 6056 | int fkey_start = 0, fkey_end = 0; |
4efda7dd | 6057 | Lisp_Object fkey_map; |
284f4730 | 6058 | |
a612e298 RS |
6059 | /* Likewise, for key_translation_map. */ |
6060 | int keytran_start = 0, keytran_end = 0; | |
6061 | Lisp_Object keytran_map; | |
6062 | ||
cd21b839 JB |
6063 | /* If we receive a ``switch-frame'' event in the middle of a key sequence, |
6064 | we put it off for later. While we're reading, we keep the event here. */ | |
4efda7dd | 6065 | Lisp_Object delayed_switch_frame; |
cd21b839 | 6066 | |
51763820 BF |
6067 | /* See the comment below... */ |
6068 | #if defined (GOBBLE_FIRST_EVENT) | |
4efda7dd | 6069 | Lisp_Object first_event; |
51763820 | 6070 | #endif |
4efda7dd | 6071 | |
309b0fc8 RS |
6072 | Lisp_Object original_uppercase; |
6073 | int original_uppercase_position = -1; | |
6074 | ||
bc536d84 | 6075 | /* Gets around Microsoft compiler limitations. */ |
309b0fc8 | 6076 | int dummyflag = 0; |
bc536d84 | 6077 | |
3b9189f8 RS |
6078 | struct buffer *starting_buffer; |
6079 | ||
e9bf89a0 RS |
6080 | /* Nonzero if we seem to have got the beginning of a binding |
6081 | in function_key_map. */ | |
6082 | int function_key_possible = 0; | |
00a78037 | 6083 | int key_translation_possible = 0; |
e9bf89a0 | 6084 | |
3fe8e9a2 RS |
6085 | /* Save the status of key translation before each step, |
6086 | so that we can restore this after downcasing. */ | |
6087 | Lisp_Object prev_fkey_map; | |
3fdfceb3 RS |
6088 | int prev_fkey_start; |
6089 | int prev_fkey_end; | |
3fe8e9a2 RS |
6090 | |
6091 | Lisp_Object prev_keytran_map; | |
3fdfceb3 RS |
6092 | int prev_keytran_start; |
6093 | int prev_keytran_end; | |
3fe8e9a2 | 6094 | |
4efda7dd RS |
6095 | int junk; |
6096 | ||
6097 | last_nonmenu_event = Qnil; | |
6098 | ||
6099 | delayed_switch_frame = Qnil; | |
6100 | fkey_map = Vfunction_key_map; | |
a612e298 | 6101 | keytran_map = Vkey_translation_map; |
f4255cd1 | 6102 | |
a612e298 | 6103 | /* If there is no function-key-map, turn off function key scanning. */ |
f4255cd1 JB |
6104 | if (NILP (Fkeymapp (Vfunction_key_map))) |
6105 | fkey_start = fkey_end = bufsize + 1; | |
6106 | ||
a612e298 RS |
6107 | /* If there is no key-translation-map, turn off scanning. */ |
6108 | if (NILP (Fkeymapp (Vkey_translation_map))) | |
6109 | keytran_start = keytran_end = bufsize + 1; | |
6110 | ||
284f4730 JB |
6111 | if (INTERACTIVE) |
6112 | { | |
84d91fda RS |
6113 | if (!NILP (prompt)) |
6114 | echo_prompt (XSTRING (prompt)->data); | |
a98ea3f9 | 6115 | else if (cursor_in_echo_area && echo_keystrokes) |
284f4730 JB |
6116 | /* This doesn't put in a dash if the echo buffer is empty, so |
6117 | you don't always see a dash hanging out in the minibuffer. */ | |
6118 | echo_dash (); | |
284f4730 JB |
6119 | } |
6120 | ||
f4255cd1 JB |
6121 | /* Record the initial state of the echo area and this_command_keys; |
6122 | we will need to restore them if we replay a key sequence. */ | |
0a7f1fc0 | 6123 | if (INTERACTIVE) |
df0f2ba1 | 6124 | echo_start = echo_length (); |
f4255cd1 | 6125 | keys_start = this_command_key_count; |
6321824f | 6126 | this_single_command_key_start = keys_start; |
0a7f1fc0 | 6127 | |
51763820 BF |
6128 | #if defined (GOBBLE_FIRST_EVENT) |
6129 | /* This doesn't quite work, because some of the things that read_char | |
6130 | does cannot safely be bypassed. It seems too risky to try to make | |
df0f2ba1 | 6131 | this work right. */ |
51763820 | 6132 | |
4efda7dd RS |
6133 | /* Read the first char of the sequence specially, before setting |
6134 | up any keymaps, in case a filter runs and switches buffers on us. */ | |
84d91fda | 6135 | first_event = read_char (NILP (prompt), 0, submaps, last_nonmenu_event, |
4efda7dd | 6136 | &junk); |
51763820 | 6137 | #endif /* GOBBLE_FIRST_EVENT */ |
4efda7dd | 6138 | |
e0dff5f6 RS |
6139 | orig_local_map = get_local_map (PT, current_buffer); |
6140 | ||
7b4aedb9 JB |
6141 | /* We jump here when the key sequence has been thoroughly changed, and |
6142 | we need to rescan it starting from the beginning. When we jump here, | |
6143 | keybuf[0..mock_input] holds the sequence we should reread. */ | |
07d2b8de | 6144 | replay_sequence: |
7b4aedb9 | 6145 | |
3b9189f8 | 6146 | starting_buffer = current_buffer; |
e9bf89a0 | 6147 | function_key_possible = 0; |
00a78037 | 6148 | key_translation_possible = 0; |
3b9189f8 | 6149 | |
f4255cd1 | 6150 | /* Build our list of keymaps. |
07d2b8de JB |
6151 | If we recognize a function key and replace its escape sequence in |
6152 | keybuf with its symbol, or if the sequence starts with a mouse | |
6153 | click and we need to switch buffers, we jump back here to rebuild | |
6154 | the initial keymaps from the current buffer. */ | |
df0f2ba1 | 6155 | { |
284f4730 JB |
6156 | Lisp_Object *maps; |
6157 | ||
217258d5 KH |
6158 | if (!NILP (current_kboard->Voverriding_terminal_local_map) |
6159 | || !NILP (Voverriding_local_map)) | |
284f4730 | 6160 | { |
217258d5 | 6161 | if (3 > nmaps_allocated) |
9dd3131c | 6162 | { |
217258d5 KH |
6163 | submaps = (Lisp_Object *) alloca (3 * sizeof (submaps[0])); |
6164 | defs = (Lisp_Object *) alloca (3 * sizeof (defs[0])); | |
6165 | nmaps_allocated = 3; | |
9dd3131c | 6166 | } |
217258d5 KH |
6167 | nmaps = 0; |
6168 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
6169 | submaps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
6170 | if (!NILP (Voverriding_local_map)) | |
6171 | submaps[nmaps++] = Voverriding_local_map; | |
284f4730 | 6172 | } |
9dd3131c RS |
6173 | else |
6174 | { | |
217258d5 KH |
6175 | nmaps = current_minor_maps (0, &maps); |
6176 | if (nmaps + 2 > nmaps_allocated) | |
9dd3131c | 6177 | { |
217258d5 KH |
6178 | submaps = (Lisp_Object *) alloca ((nmaps+2) * sizeof (submaps[0])); |
6179 | defs = (Lisp_Object *) alloca ((nmaps+2) * sizeof (defs[0])); | |
6180 | nmaps_allocated = nmaps + 2; | |
9dd3131c | 6181 | } |
217258d5 | 6182 | bcopy (maps, submaps, nmaps * sizeof (submaps[0])); |
497ba7a1 | 6183 | #ifdef USE_TEXT_PROPERTIES |
217258d5 | 6184 | submaps[nmaps++] = orig_local_map; |
497ba7a1 | 6185 | #else |
217258d5 | 6186 | submaps[nmaps++] = current_buffer->keymap; |
497ba7a1 | 6187 | #endif |
9dd3131c | 6188 | } |
217258d5 | 6189 | submaps[nmaps++] = current_global_map; |
284f4730 JB |
6190 | } |
6191 | ||
6192 | /* Find an accurate initial value for first_binding. */ | |
6193 | for (first_binding = 0; first_binding < nmaps; first_binding++) | |
253598e4 | 6194 | if (! NILP (submaps[first_binding])) |
284f4730 JB |
6195 | break; |
6196 | ||
3b9189f8 | 6197 | /* Start from the beginning in keybuf. */ |
f4255cd1 JB |
6198 | t = 0; |
6199 | ||
6200 | /* These are no-ops the first time through, but if we restart, they | |
6201 | revert the echo area and this_command_keys to their original state. */ | |
6202 | this_command_key_count = keys_start; | |
df0f2ba1 | 6203 | if (INTERACTIVE && t < mock_input) |
f4255cd1 JB |
6204 | echo_truncate (echo_start); |
6205 | ||
cca310da JB |
6206 | /* If the best binding for the current key sequence is a keymap, or |
6207 | we may be looking at a function key's escape sequence, keep on | |
6208 | reading. */ | |
253598e4 | 6209 | while ((first_binding < nmaps && ! NILP (submaps[first_binding])) |
cca310da JB |
6210 | || (first_binding >= nmaps |
6211 | && fkey_start < t | |
6212 | /* mock input is never part of a function key's sequence. */ | |
a612e298 | 6213 | && mock_input <= fkey_start) |
0d882d52 KH |
6214 | || (first_binding >= nmaps |
6215 | && keytran_start < t && key_translation_possible) | |
e9bf89a0 RS |
6216 | /* Don't return in the middle of a possible function key sequence, |
6217 | if the only bindings we found were via case conversion. | |
6218 | Thus, if ESC O a has a function-key-map translation | |
6219 | and ESC o has a binding, don't return after ESC O, | |
6220 | so that we can translate ESC O plus the next character. */ | |
4e50f26a | 6221 | ) |
284f4730 JB |
6222 | { |
6223 | Lisp_Object key; | |
7d6de002 | 6224 | int used_mouse_menu = 0; |
284f4730 | 6225 | |
7b4aedb9 JB |
6226 | /* Where the last real key started. If we need to throw away a |
6227 | key that has expanded into more than one element of keybuf | |
6228 | (say, a mouse click on the mode line which is being treated | |
6229 | as [mode-line (mouse-...)], then we backtrack to this point | |
6230 | of keybuf. */ | |
6231 | int last_real_key_start; | |
6232 | ||
0a7f1fc0 JB |
6233 | /* These variables are analogous to echo_start and keys_start; |
6234 | while those allow us to restart the entire key sequence, | |
6235 | echo_local_start and keys_local_start allow us to throw away | |
6236 | just one key. */ | |
f4255cd1 JB |
6237 | int echo_local_start, keys_local_start, local_first_binding; |
6238 | ||
284f4730 | 6239 | if (t >= bufsize) |
3fe8e9a2 | 6240 | error ("Key sequence too long"); |
284f4730 | 6241 | |
f4255cd1 JB |
6242 | if (INTERACTIVE) |
6243 | echo_local_start = echo_length (); | |
6244 | keys_local_start = this_command_key_count; | |
6245 | local_first_binding = first_binding; | |
df0f2ba1 | 6246 | |
f4255cd1 | 6247 | replay_key: |
0a7f1fc0 | 6248 | /* These are no-ops, unless we throw away a keystroke below and |
f4255cd1 JB |
6249 | jumped back up to replay_key; in that case, these restore the |
6250 | variables to their original state, allowing us to replay the | |
0a7f1fc0 | 6251 | loop. */ |
40932d1a | 6252 | if (INTERACTIVE && t < mock_input) |
f4255cd1 | 6253 | echo_truncate (echo_local_start); |
0a7f1fc0 JB |
6254 | this_command_key_count = keys_local_start; |
6255 | first_binding = local_first_binding; | |
6256 | ||
7e85b935 RS |
6257 | /* By default, assume each event is "real". */ |
6258 | last_real_key_start = t; | |
6259 | ||
f4255cd1 | 6260 | /* Does mock_input indicate that we are re-reading a key sequence? */ |
284f4730 JB |
6261 | if (t < mock_input) |
6262 | { | |
6263 | key = keybuf[t]; | |
6264 | add_command_key (key); | |
a98ea3f9 RS |
6265 | if (echo_keystrokes) |
6266 | echo_char (key); | |
284f4730 | 6267 | } |
253598e4 JB |
6268 | |
6269 | /* If not, we should actually read a character. */ | |
284f4730 JB |
6270 | else |
6271 | { | |
a6d53864 RS |
6272 | struct buffer *buf = current_buffer; |
6273 | ||
beecf6a1 | 6274 | { |
c5fdd383 KH |
6275 | #ifdef MULTI_KBOARD |
6276 | KBOARD *interrupted_kboard = current_kboard; | |
df0f2ba1 | 6277 | struct frame *interrupted_frame = selected_frame; |
c5fdd383 | 6278 | if (setjmp (wrong_kboard_jmpbuf)) |
beecf6a1 | 6279 | { |
5798cf15 KH |
6280 | if (!NILP (delayed_switch_frame)) |
6281 | { | |
c5fdd383 | 6282 | interrupted_kboard->kbd_queue |
5798cf15 | 6283 | = Fcons (delayed_switch_frame, |
c5fdd383 | 6284 | interrupted_kboard->kbd_queue); |
5798cf15 KH |
6285 | delayed_switch_frame = Qnil; |
6286 | } | |
beecf6a1 | 6287 | while (t > 0) |
c5fdd383 KH |
6288 | interrupted_kboard->kbd_queue |
6289 | = Fcons (keybuf[--t], interrupted_kboard->kbd_queue); | |
5798cf15 KH |
6290 | |
6291 | /* If the side queue is non-empty, ensure it begins with a | |
6292 | switch-frame, so we'll replay it in the right context. */ | |
c5fdd383 KH |
6293 | if (CONSP (interrupted_kboard->kbd_queue) |
6294 | && (key = XCONS (interrupted_kboard->kbd_queue)->car, | |
5798cf15 KH |
6295 | !(EVENT_HAS_PARAMETERS (key) |
6296 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key)), | |
6297 | Qswitch_frame)))) | |
df0f2ba1 KH |
6298 | { |
6299 | Lisp_Object frame; | |
6300 | XSETFRAME (frame, interrupted_frame); | |
c5fdd383 | 6301 | interrupted_kboard->kbd_queue |
df0f2ba1 | 6302 | = Fcons (make_lispy_switch_frame (frame), |
c5fdd383 | 6303 | interrupted_kboard->kbd_queue); |
df0f2ba1 | 6304 | } |
beecf6a1 | 6305 | mock_input = 0; |
a6e0153c | 6306 | orig_local_map = get_local_map (PT, current_buffer); |
beecf6a1 KH |
6307 | goto replay_sequence; |
6308 | } | |
bded54dd | 6309 | #endif |
beecf6a1 KH |
6310 | key = read_char (NILP (prompt), nmaps, submaps, last_nonmenu_event, |
6311 | &used_mouse_menu); | |
6312 | } | |
284f4730 | 6313 | |
dcc408a0 RS |
6314 | /* read_char returns t when it shows a menu and the user rejects it. |
6315 | Just return -1. */ | |
6316 | if (EQ (key, Qt)) | |
6317 | return -1; | |
6318 | ||
f4255cd1 | 6319 | /* read_char returns -1 at the end of a macro. |
284f4730 JB |
6320 | Emacs 18 handles this by returning immediately with a |
6321 | zero, so that's what we'll do. */ | |
8c18cbfb | 6322 | if (INTEGERP (key) && XINT (key) == -1) |
cd21b839 | 6323 | { |
f4255cd1 | 6324 | t = 0; |
bc536d84 RS |
6325 | /* The Microsoft C compiler can't handle the goto that |
6326 | would go here. */ | |
309b0fc8 | 6327 | dummyflag = 1; |
bc536d84 | 6328 | break; |
cd21b839 | 6329 | } |
df0f2ba1 | 6330 | |
3cb81011 KH |
6331 | /* If the current buffer has been changed from under us, the |
6332 | keymap may have changed, so replay the sequence. */ | |
8c18cbfb | 6333 | if (BUFFERP (key)) |
3cb81011 KH |
6334 | { |
6335 | mock_input = t; | |
f571ae0d RS |
6336 | /* Reset the current buffer from the selected window |
6337 | in case something changed the former and not the latter. | |
6338 | This is to be more consistent with the behavior | |
6339 | of the command_loop_1. */ | |
6340 | if (fix_current_buffer) | |
6341 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
6342 | Fset_buffer (XWINDOW (selected_window)->buffer); | |
6343 | ||
a6e0153c | 6344 | orig_local_map = get_local_map (PT, current_buffer); |
3cb81011 KH |
6345 | goto replay_sequence; |
6346 | } | |
6347 | ||
3b9189f8 RS |
6348 | /* If we have a quit that was typed in another frame, and |
6349 | quit_throw_to_read_char switched buffers, | |
6350 | replay to get the right keymap. */ | |
9343ab07 | 6351 | if (XINT (key) == quit_char && current_buffer != starting_buffer) |
3b9189f8 RS |
6352 | { |
6353 | keybuf[t++] = key; | |
6354 | mock_input = t; | |
6355 | Vquit_flag = Qnil; | |
a6e0153c | 6356 | orig_local_map = get_local_map (PT, current_buffer); |
3b9189f8 RS |
6357 | goto replay_sequence; |
6358 | } | |
3cb81011 | 6359 | |
284f4730 | 6360 | Vquit_flag = Qnil; |
7e85b935 | 6361 | } |
284f4730 | 6362 | |
df0f2ba1 | 6363 | /* Clicks in non-text areas get prefixed by the symbol |
7e85b935 RS |
6364 | in their CHAR-ADDRESS field. For example, a click on |
6365 | the mode line is prefixed by the symbol `mode-line'. | |
6366 | ||
6367 | Furthermore, key sequences beginning with mouse clicks | |
6368 | are read using the keymaps of the buffer clicked on, not | |
6369 | the current buffer. So we may have to switch the buffer | |
6370 | here. | |
6371 | ||
6372 | When we turn one event into two events, we must make sure | |
6373 | that neither of the two looks like the original--so that, | |
6374 | if we replay the events, they won't be expanded again. | |
6375 | If not for this, such reexpansion could happen either here | |
6376 | or when user programs play with this-command-keys. */ | |
6377 | if (EVENT_HAS_PARAMETERS (key)) | |
6378 | { | |
9b8eb840 | 6379 | Lisp_Object kind; |
cca310da | 6380 | |
9b8eb840 | 6381 | kind = EVENT_HEAD_KIND (EVENT_HEAD (key)); |
7e85b935 | 6382 | if (EQ (kind, Qmouse_click)) |
0a7f1fc0 | 6383 | { |
9b8eb840 | 6384 | Lisp_Object window, posn; |
f4255cd1 | 6385 | |
9b8eb840 KH |
6386 | window = POSN_WINDOW (EVENT_START (key)); |
6387 | posn = POSN_BUFFER_POSN (EVENT_START (key)); | |
8c18cbfb | 6388 | if (CONSP (posn)) |
0a7f1fc0 | 6389 | { |
7e85b935 RS |
6390 | /* We're looking at the second event of a |
6391 | sequence which we expanded before. Set | |
6392 | last_real_key_start appropriately. */ | |
6393 | if (t > 0) | |
6394 | last_real_key_start = t - 1; | |
cd21b839 | 6395 | } |
7e85b935 RS |
6396 | |
6397 | /* Key sequences beginning with mouse clicks are | |
6398 | read using the keymaps in the buffer clicked on, | |
6399 | not the current buffer. If we're at the | |
6400 | beginning of a key sequence, switch buffers. */ | |
6401 | if (last_real_key_start == 0 | |
8c18cbfb KH |
6402 | && WINDOWP (window) |
6403 | && BUFFERP (XWINDOW (window)->buffer) | |
7e85b935 | 6404 | && XBUFFER (XWINDOW (window)->buffer) != current_buffer) |
cd21b839 | 6405 | { |
7e85b935 RS |
6406 | keybuf[t] = key; |
6407 | mock_input = t + 1; | |
6408 | ||
6409 | /* Arrange to go back to the original buffer once we're | |
6410 | done reading the key sequence. Note that we can't | |
6411 | use save_excursion_{save,restore} here, because they | |
6412 | save point as well as the current buffer; we don't | |
6413 | want to save point, because redisplay may change it, | |
6414 | to accommodate a Fset_window_start or something. We | |
6415 | don't want to do this at the top of the function, | |
6416 | because we may get input from a subprocess which | |
6417 | wants to change the selected window and stuff (say, | |
6418 | emacsclient). */ | |
6419 | record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
6420 | ||
6421 | set_buffer_internal (XBUFFER (XWINDOW (window)->buffer)); | |
e0dff5f6 | 6422 | orig_local_map = get_local_map (PT, current_buffer); |
7e85b935 | 6423 | goto replay_sequence; |
0a7f1fc0 | 6424 | } |
e0dff5f6 RS |
6425 | /* For a mouse click, get the local text-property keymap |
6426 | of the place clicked on, rather than point. */ | |
6427 | if (last_real_key_start == 0 && CONSP (XCONS (key)->cdr) | |
6428 | && ! localized_local_map) | |
5ec75a55 | 6429 | { |
e0dff5f6 RS |
6430 | Lisp_Object map_here, start, pos; |
6431 | ||
6432 | localized_local_map = 1; | |
6433 | start = EVENT_START (key); | |
6434 | if (CONSP (start) && CONSP (XCONS (start)->cdr)) | |
6435 | { | |
6436 | pos = POSN_BUFFER_POSN (start); | |
b78ce8fb RS |
6437 | if (INTEGERP (pos) |
6438 | && XINT (pos) >= BEG && XINT (pos) <= Z) | |
e0dff5f6 RS |
6439 | { |
6440 | map_here = get_local_map (XINT (pos), current_buffer); | |
6441 | if (!EQ (map_here, orig_local_map)) | |
6442 | { | |
6443 | orig_local_map = map_here; | |
6444 | keybuf[t] = key; | |
6445 | mock_input = t + 1; | |
5ec75a55 | 6446 | |
e0dff5f6 RS |
6447 | goto replay_sequence; |
6448 | } | |
6449 | } | |
6450 | } | |
6451 | } | |
6452 | ||
6453 | /* Expand mode-line and scroll-bar events into two events: | |
6454 | use posn as a fake prefix key. */ | |
6455 | if (SYMBOLP (posn)) | |
6456 | { | |
7e85b935 | 6457 | if (t + 1 >= bufsize) |
3fe8e9a2 | 6458 | error ("Key sequence too long"); |
7e85b935 RS |
6459 | keybuf[t] = posn; |
6460 | keybuf[t+1] = key; | |
6461 | mock_input = t + 2; | |
6462 | ||
6463 | /* Zap the position in key, so we know that we've | |
6464 | expanded it, and don't try to do so again. */ | |
6465 | POSN_BUFFER_POSN (EVENT_START (key)) | |
6466 | = Fcons (posn, Qnil); | |
6467 | goto replay_key; | |
5ec75a55 | 6468 | } |
0a7f1fc0 | 6469 | } |
7e85b935 | 6470 | else if (EQ (kind, Qswitch_frame)) |
a6d53864 | 6471 | { |
ce98e608 KH |
6472 | /* If we're at the beginning of a key sequence, and the caller |
6473 | says it's okay, go ahead and return this event. If we're | |
6474 | in the midst of a key sequence, delay it until the end. */ | |
6475 | if (t > 0 || !can_return_switch_frame) | |
7e85b935 RS |
6476 | { |
6477 | delayed_switch_frame = key; | |
6478 | goto replay_key; | |
6479 | } | |
6480 | } | |
7a80a6f6 RS |
6481 | else if (CONSP (XCONS (key)->cdr) |
6482 | && CONSP (EVENT_START (key)) | |
6483 | && CONSP (XCONS (EVENT_START (key))->cdr)) | |
7e85b935 | 6484 | { |
9b8eb840 | 6485 | Lisp_Object posn; |
7e85b935 | 6486 | |
9b8eb840 | 6487 | posn = POSN_BUFFER_POSN (EVENT_START (key)); |
7e85b935 RS |
6488 | /* Handle menu-bar events: |
6489 | insert the dummy prefix event `menu-bar'. */ | |
6490 | if (EQ (posn, Qmenu_bar)) | |
6491 | { | |
6492 | if (t + 1 >= bufsize) | |
3fe8e9a2 | 6493 | error ("Key sequence too long"); |
7e85b935 RS |
6494 | keybuf[t] = posn; |
6495 | keybuf[t+1] = key; | |
6496 | ||
6497 | /* Zap the position in key, so we know that we've | |
6498 | expanded it, and don't try to do so again. */ | |
6499 | POSN_BUFFER_POSN (EVENT_START (key)) | |
6500 | = Fcons (posn, Qnil); | |
6501 | ||
6502 | mock_input = t + 2; | |
6503 | goto replay_sequence; | |
6504 | } | |
8c18cbfb | 6505 | else if (CONSP (posn)) |
7e85b935 RS |
6506 | { |
6507 | /* We're looking at the second event of a | |
6508 | sequence which we expanded before. Set | |
6509 | last_real_key_start appropriately. */ | |
6510 | if (last_real_key_start == t && t > 0) | |
6511 | last_real_key_start = t - 1; | |
6512 | } | |
a6d53864 | 6513 | } |
284f4730 | 6514 | } |
f4255cd1 JB |
6515 | |
6516 | /* We have finally decided that KEY is something we might want | |
6517 | to look up. */ | |
284f4730 JB |
6518 | first_binding = (follow_key (key, |
6519 | nmaps - first_binding, | |
253598e4 | 6520 | submaps + first_binding, |
284f4730 | 6521 | defs + first_binding, |
4e50f26a | 6522 | submaps + first_binding) |
284f4730 | 6523 | + first_binding); |
0a7f1fc0 | 6524 | |
f4255cd1 | 6525 | /* If KEY wasn't bound, we'll try some fallbacks. */ |
0a7f1fc0 JB |
6526 | if (first_binding >= nmaps) |
6527 | { | |
9b8eb840 | 6528 | Lisp_Object head; |
0a7f1fc0 | 6529 | |
9b8eb840 | 6530 | head = EVENT_HEAD (key); |
24736fbc | 6531 | if (help_char_p (head) && t > 0) |
7e85b935 RS |
6532 | { |
6533 | read_key_sequence_cmd = Vprefix_help_command; | |
6534 | keybuf[t++] = key; | |
6535 | last_nonmenu_event = key; | |
bc536d84 RS |
6536 | /* The Microsoft C compiler can't handle the goto that |
6537 | would go here. */ | |
309b0fc8 | 6538 | dummyflag = 1; |
0d882d52 | 6539 | break; |
7e85b935 RS |
6540 | } |
6541 | ||
8c18cbfb | 6542 | if (SYMBOLP (head)) |
0a7f1fc0 | 6543 | { |
9b8eb840 KH |
6544 | Lisp_Object breakdown; |
6545 | int modifiers; | |
0a7f1fc0 | 6546 | |
9b8eb840 KH |
6547 | breakdown = parse_modifiers (head); |
6548 | modifiers = XINT (XCONS (XCONS (breakdown)->cdr)->car); | |
559f9d04 RS |
6549 | /* Attempt to reduce an unbound mouse event to a simpler |
6550 | event that is bound: | |
6551 | Drags reduce to clicks. | |
6552 | Double-clicks reduce to clicks. | |
6553 | Triple-clicks reduce to double-clicks, then to clicks. | |
6554 | Down-clicks are eliminated. | |
6555 | Double-downs reduce to downs, then are eliminated. | |
6556 | Triple-downs reduce to double-downs, then to downs, | |
6557 | then are eliminated. */ | |
6558 | if (modifiers & (down_modifier | drag_modifier | |
6559 | | double_modifier | triple_modifier)) | |
0a7f1fc0 | 6560 | { |
559f9d04 RS |
6561 | while (modifiers & (down_modifier | drag_modifier |
6562 | | double_modifier | triple_modifier)) | |
fbcd35bd JB |
6563 | { |
6564 | Lisp_Object new_head, new_click; | |
6565 | if (modifiers & triple_modifier) | |
6566 | modifiers ^= (double_modifier | triple_modifier); | |
bc536d84 RS |
6567 | else if (modifiers & double_modifier) |
6568 | modifiers &= ~double_modifier; | |
6569 | else if (modifiers & drag_modifier) | |
6570 | modifiers &= ~drag_modifier; | |
559f9d04 RS |
6571 | else |
6572 | { | |
6573 | /* Dispose of this `down' event by simply jumping | |
6574 | back to replay_key, to get another event. | |
6575 | ||
6576 | Note that if this event came from mock input, | |
6577 | then just jumping back to replay_key will just | |
6578 | hand it to us again. So we have to wipe out any | |
6579 | mock input. | |
6580 | ||
6581 | We could delete keybuf[t] and shift everything | |
6582 | after that to the left by one spot, but we'd also | |
6583 | have to fix up any variable that points into | |
6584 | keybuf, and shifting isn't really necessary | |
6585 | anyway. | |
6586 | ||
6587 | Adding prefixes for non-textual mouse clicks | |
6588 | creates two characters of mock input, and both | |
6589 | must be thrown away. If we're only looking at | |
6590 | the prefix now, we can just jump back to | |
6591 | replay_key. On the other hand, if we've already | |
6592 | processed the prefix, and now the actual click | |
6593 | itself is giving us trouble, then we've lost the | |
6594 | state of the keymaps we want to backtrack to, and | |
6595 | we need to replay the whole sequence to rebuild | |
6596 | it. | |
6597 | ||
6598 | Beyond that, only function key expansion could | |
6599 | create more than two keys, but that should never | |
6600 | generate mouse events, so it's okay to zero | |
6601 | mock_input in that case too. | |
6602 | ||
6603 | Isn't this just the most wonderful code ever? */ | |
6604 | if (t == last_real_key_start) | |
6605 | { | |
6606 | mock_input = 0; | |
6607 | goto replay_key; | |
6608 | } | |
6609 | else | |
6610 | { | |
6611 | mock_input = last_real_key_start; | |
6612 | goto replay_sequence; | |
6613 | } | |
6614 | } | |
6615 | ||
27203ead RS |
6616 | new_head |
6617 | = apply_modifiers (modifiers, XCONS (breakdown)->car); | |
6618 | new_click | |
6619 | = Fcons (new_head, Fcons (EVENT_START (key), Qnil)); | |
fbcd35bd JB |
6620 | |
6621 | /* Look for a binding for this new key. follow_key | |
6622 | promises that it didn't munge submaps the | |
6623 | last time we called it, since key was unbound. */ | |
27203ead RS |
6624 | first_binding |
6625 | = (follow_key (new_click, | |
6626 | nmaps - local_first_binding, | |
6627 | submaps + local_first_binding, | |
6628 | defs + local_first_binding, | |
4e50f26a | 6629 | submaps + local_first_binding) |
27203ead | 6630 | + local_first_binding); |
fbcd35bd JB |
6631 | |
6632 | /* If that click is bound, go for it. */ | |
6633 | if (first_binding < nmaps) | |
6634 | { | |
6635 | key = new_click; | |
6636 | break; | |
6637 | } | |
6638 | /* Otherwise, we'll leave key set to the drag event. */ | |
6639 | } | |
0a7f1fc0 JB |
6640 | } |
6641 | } | |
6642 | } | |
6643 | ||
284f4730 | 6644 | keybuf[t++] = key; |
7d6de002 RS |
6645 | /* Normally, last_nonmenu_event gets the previous key we read. |
6646 | But when a mouse popup menu is being used, | |
6647 | we don't update last_nonmenu_event; it continues to hold the mouse | |
6648 | event that preceded the first level of menu. */ | |
6649 | if (!used_mouse_menu) | |
6650 | last_nonmenu_event = key; | |
284f4730 | 6651 | |
6321824f RS |
6652 | /* Record what part of this_command_keys is the current key sequence. */ |
6653 | this_single_command_key_start = this_command_key_count - t; | |
6654 | ||
3fe8e9a2 RS |
6655 | prev_fkey_map = fkey_map; |
6656 | prev_fkey_start = fkey_start; | |
6657 | prev_fkey_end = fkey_end; | |
6658 | ||
6659 | prev_keytran_map = keytran_map; | |
6660 | prev_keytran_start = keytran_start; | |
6661 | prev_keytran_end = keytran_end; | |
6662 | ||
284f4730 | 6663 | /* If the sequence is unbound, see if we can hang a function key |
253598e4 JB |
6664 | off the end of it. We only want to scan real keyboard input |
6665 | for function key sequences, so if mock_input says that we're | |
f4255cd1 | 6666 | re-reading old events, don't examine it. */ |
4e50f26a | 6667 | if (first_binding >= nmaps |
253598e4 | 6668 | && t >= mock_input) |
284f4730 JB |
6669 | { |
6670 | Lisp_Object fkey_next; | |
6671 | ||
e9bf89a0 RS |
6672 | /* Continue scan from fkey_end until we find a bound suffix. |
6673 | If we fail, increment fkey_start | |
6674 | and start fkey_end from there. */ | |
284f4730 JB |
6675 | while (fkey_end < t) |
6676 | { | |
f4255cd1 JB |
6677 | Lisp_Object key; |
6678 | ||
6679 | key = keybuf[fkey_end++]; | |
067ffa38 JB |
6680 | /* Look up meta-characters by prefixing them |
6681 | with meta_prefix_char. I hate this. */ | |
8c18cbfb | 6682 | if (INTEGERP (key) && XINT (key) & meta_modifier) |
f4255cd1 | 6683 | { |
e74fbc70 RS |
6684 | fkey_next |
6685 | = get_keymap_1 | |
f4255cd1 | 6686 | (get_keyelt |
c6a67acd | 6687 | (access_keymap (fkey_map, meta_prefix_char, 1, 0), 0), |
f4255cd1 | 6688 | 0, 1); |
bb9e9bed | 6689 | XSETFASTINT (key, XFASTINT (key) & ~meta_modifier); |
f4255cd1 | 6690 | } |
067ffa38 JB |
6691 | else |
6692 | fkey_next = fkey_map; | |
6693 | ||
e74fbc70 | 6694 | fkey_next |
c6a67acd | 6695 | = get_keyelt (access_keymap (fkey_next, key, 1, 0), 0); |
067ffa38 | 6696 | |
7a80a6f6 RS |
6697 | #if 0 /* I didn't turn this on, because it might cause trouble |
6698 | for the mapping of return into C-m and tab into C-i. */ | |
6699 | /* Optionally don't map function keys into other things. | |
6700 | This enables the user to redefine kp- keys easily. */ | |
6701 | if (SYMBOLP (key) && !NILP (Vinhibit_function_key_mapping)) | |
6702 | fkey_next = Qnil; | |
6703 | #endif | |
6704 | ||
1abe6abe RS |
6705 | /* If the function key map gives a function, not an |
6706 | array, then call the function with no args and use | |
6707 | its value instead. */ | |
6708 | if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) | |
6709 | && fkey_end == t) | |
6710 | { | |
6711 | struct gcpro gcpro1, gcpro2, gcpro3; | |
6712 | Lisp_Object tem; | |
6713 | tem = fkey_next; | |
6714 | ||
6715 | GCPRO3 (fkey_map, keytran_map, delayed_switch_frame); | |
84d91fda | 6716 | fkey_next = call1 (fkey_next, prompt); |
1abe6abe RS |
6717 | UNGCPRO; |
6718 | /* If the function returned something invalid, | |
6719 | barf--don't ignore it. | |
df0f2ba1 | 6720 | (To ignore it safely, we would need to gcpro a bunch of |
1abe6abe RS |
6721 | other variables.) */ |
6722 | if (! (VECTORP (fkey_next) || STRINGP (fkey_next))) | |
6321824f | 6723 | error ("Function in key-translation-map returns invalid key sequence"); |
1abe6abe RS |
6724 | } |
6725 | ||
e9bf89a0 RS |
6726 | function_key_possible = ! NILP (fkey_next); |
6727 | ||
85bc5181 | 6728 | /* If keybuf[fkey_start..fkey_end] is bound in the |
a764a753 | 6729 | function key map and it's a suffix of the current |
85bc5181 | 6730 | sequence (i.e. fkey_end == t), replace it with |
a764a753 | 6731 | the binding and restart with fkey_start at the end. */ |
f5ea6163 | 6732 | if ((VECTORP (fkey_next) || STRINGP (fkey_next)) |
284f4730 JB |
6733 | && fkey_end == t) |
6734 | { | |
2e864a76 | 6735 | int len = XFASTINT (Flength (fkey_next)); |
f5ea6163 JB |
6736 | |
6737 | t = fkey_start + len; | |
284f4730 | 6738 | if (t >= bufsize) |
3fe8e9a2 | 6739 | error ("Key sequence too long"); |
284f4730 | 6740 | |
f5ea6163 JB |
6741 | if (VECTORP (fkey_next)) |
6742 | bcopy (XVECTOR (fkey_next)->contents, | |
6743 | keybuf + fkey_start, | |
6744 | (t - fkey_start) * sizeof (keybuf[0])); | |
6745 | else if (STRINGP (fkey_next)) | |
6746 | { | |
6747 | int i; | |
6748 | ||
6749 | for (i = 0; i < len; i++) | |
bb9e9bed KH |
6750 | XSETFASTINT (keybuf[fkey_start + i], |
6751 | XSTRING (fkey_next)->data[i]); | |
f5ea6163 | 6752 | } |
df0f2ba1 | 6753 | |
284f4730 JB |
6754 | mock_input = t; |
6755 | fkey_start = fkey_end = t; | |
32e6d806 | 6756 | fkey_map = Vfunction_key_map; |
284f4730 | 6757 | |
00a78037 RS |
6758 | /* Do pass the results through key-translation-map. */ |
6759 | keytran_start = keytran_end = 0; | |
6760 | keytran_map = Vkey_translation_map; | |
6761 | ||
f4255cd1 | 6762 | goto replay_sequence; |
284f4730 | 6763 | } |
df0f2ba1 | 6764 | |
f4255cd1 | 6765 | fkey_map = get_keymap_1 (fkey_next, 0, 1); |
284f4730 | 6766 | |
df0f2ba1 | 6767 | /* If we no longer have a bound suffix, try a new positions for |
a764a753 | 6768 | fkey_start. */ |
284f4730 JB |
6769 | if (NILP (fkey_map)) |
6770 | { | |
6771 | fkey_end = ++fkey_start; | |
6772 | fkey_map = Vfunction_key_map; | |
e9bf89a0 | 6773 | function_key_possible = 0; |
284f4730 JB |
6774 | } |
6775 | } | |
6776 | } | |
a612e298 RS |
6777 | |
6778 | /* Look for this sequence in key-translation-map. */ | |
6779 | { | |
6780 | Lisp_Object keytran_next; | |
6781 | ||
6782 | /* Scan from keytran_end until we find a bound suffix. */ | |
6783 | while (keytran_end < t) | |
6784 | { | |
6785 | Lisp_Object key; | |
6786 | ||
6787 | key = keybuf[keytran_end++]; | |
6788 | /* Look up meta-characters by prefixing them | |
6789 | with meta_prefix_char. I hate this. */ | |
8c18cbfb | 6790 | if (INTEGERP (key) && XINT (key) & meta_modifier) |
a612e298 RS |
6791 | { |
6792 | keytran_next | |
6793 | = get_keymap_1 | |
6794 | (get_keyelt | |
c6a67acd | 6795 | (access_keymap (keytran_map, meta_prefix_char, 1, 0), 0), |
a612e298 | 6796 | 0, 1); |
bb9e9bed | 6797 | XSETFASTINT (key, XFASTINT (key) & ~meta_modifier); |
a612e298 RS |
6798 | } |
6799 | else | |
6800 | keytran_next = keytran_map; | |
6801 | ||
6802 | keytran_next | |
c6a67acd | 6803 | = get_keyelt (access_keymap (keytran_next, key, 1, 0), 0); |
a612e298 | 6804 | |
1abe6abe RS |
6805 | /* If the key translation map gives a function, not an |
6806 | array, then call the function with no args and use | |
6807 | its value instead. */ | |
6808 | if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) | |
6809 | && keytran_end == t) | |
6810 | { | |
6811 | struct gcpro gcpro1, gcpro2, gcpro3; | |
6812 | Lisp_Object tem; | |
6813 | tem = keytran_next; | |
6814 | ||
40932d1a | 6815 | GCPRO3 (fkey_map, keytran_map, delayed_switch_frame); |
84d91fda | 6816 | keytran_next = call1 (keytran_next, prompt); |
1abe6abe RS |
6817 | UNGCPRO; |
6818 | /* If the function returned something invalid, | |
6819 | barf--don't ignore it. | |
df0f2ba1 | 6820 | (To ignore it safely, we would need to gcpro a bunch of |
1abe6abe RS |
6821 | other variables.) */ |
6822 | if (! (VECTORP (keytran_next) || STRINGP (keytran_next))) | |
40932d1a | 6823 | error ("Function in key-translation-map returns invalid key sequence"); |
1abe6abe RS |
6824 | } |
6825 | ||
00a78037 RS |
6826 | key_translation_possible = ! NILP (keytran_next); |
6827 | ||
a612e298 | 6828 | /* If keybuf[keytran_start..keytran_end] is bound in the |
1abe6abe | 6829 | key translation map and it's a suffix of the current |
a612e298 RS |
6830 | sequence (i.e. keytran_end == t), replace it with |
6831 | the binding and restart with keytran_start at the end. */ | |
6832 | if ((VECTORP (keytran_next) || STRINGP (keytran_next)) | |
6833 | && keytran_end == t) | |
6834 | { | |
2e864a76 | 6835 | int len = XFASTINT (Flength (keytran_next)); |
a612e298 RS |
6836 | |
6837 | t = keytran_start + len; | |
6838 | if (t >= bufsize) | |
3fe8e9a2 | 6839 | error ("Key sequence too long"); |
a612e298 RS |
6840 | |
6841 | if (VECTORP (keytran_next)) | |
6842 | bcopy (XVECTOR (keytran_next)->contents, | |
6843 | keybuf + keytran_start, | |
6844 | (t - keytran_start) * sizeof (keybuf[0])); | |
6845 | else if (STRINGP (keytran_next)) | |
6846 | { | |
6847 | int i; | |
6848 | ||
6849 | for (i = 0; i < len; i++) | |
bb9e9bed KH |
6850 | XSETFASTINT (keybuf[keytran_start + i], |
6851 | XSTRING (keytran_next)->data[i]); | |
a612e298 RS |
6852 | } |
6853 | ||
6854 | mock_input = t; | |
6855 | keytran_start = keytran_end = t; | |
6856 | keytran_map = Vkey_translation_map; | |
6857 | ||
00a78037 RS |
6858 | /* Don't pass the results of key-translation-map |
6859 | through function-key-map. */ | |
6860 | fkey_start = fkey_end = t; | |
6861 | fkey_map = Vkey_translation_map; | |
6862 | ||
a612e298 RS |
6863 | goto replay_sequence; |
6864 | } | |
6865 | ||
6866 | keytran_map = get_keymap_1 (keytran_next, 0, 1); | |
6867 | ||
df0f2ba1 | 6868 | /* If we no longer have a bound suffix, try a new positions for |
a612e298 RS |
6869 | keytran_start. */ |
6870 | if (NILP (keytran_map)) | |
6871 | { | |
6872 | keytran_end = ++keytran_start; | |
6873 | keytran_map = Vkey_translation_map; | |
00a78037 | 6874 | key_translation_possible = 0; |
a612e298 RS |
6875 | } |
6876 | } | |
6877 | } | |
4e50f26a RS |
6878 | |
6879 | /* If KEY is not defined in any of the keymaps, | |
6880 | and cannot be part of a function key or translation, | |
6881 | and is an upper case letter | |
6882 | use the corresponding lower-case letter instead. */ | |
6883 | if (first_binding == nmaps && ! function_key_possible | |
00a78037 | 6884 | && ! key_translation_possible |
8c18cbfb | 6885 | && INTEGERP (key) |
4e50f26a RS |
6886 | && ((((XINT (key) & 0x3ffff) |
6887 | < XSTRING (current_buffer->downcase_table)->size) | |
6888 | && UPPERCASEP (XINT (key) & 0x3ffff)) | |
6889 | || (XINT (key) & shift_modifier))) | |
6890 | { | |
569871d2 | 6891 | Lisp_Object new_key; |
569871d2 | 6892 | |
309b0fc8 RS |
6893 | original_uppercase = key; |
6894 | original_uppercase_position = t - 1; | |
6895 | ||
831f35a2 | 6896 | if (XINT (key) & shift_modifier) |
569871d2 | 6897 | XSETINT (new_key, XINT (key) & ~shift_modifier); |
4e50f26a | 6898 | else |
569871d2 RS |
6899 | XSETINT (new_key, (DOWNCASE (XINT (key) & 0x3ffff) |
6900 | | (XINT (key) & ~0x3ffff))); | |
6901 | ||
3fe8e9a2 RS |
6902 | /* We have to do this unconditionally, regardless of whether |
6903 | the lower-case char is defined in the keymaps, because they | |
6904 | might get translated through function-key-map. */ | |
6905 | keybuf[t - 1] = new_key; | |
6906 | mock_input = t; | |
6907 | ||
6908 | fkey_map = prev_fkey_map; | |
6909 | fkey_start = prev_fkey_start; | |
6910 | fkey_end = prev_fkey_end; | |
6911 | ||
6912 | keytran_map = prev_keytran_map; | |
6913 | keytran_start = prev_keytran_start; | |
6914 | keytran_end = prev_keytran_end; | |
6915 | ||
6916 | goto replay_sequence; | |
4e50f26a | 6917 | } |
ef8fd672 RS |
6918 | /* If KEY is not defined in any of the keymaps, |
6919 | and cannot be part of a function key or translation, | |
6920 | and is a shifted function key, | |
6921 | use the corresponding unshifted function key instead. */ | |
6922 | if (first_binding == nmaps && ! function_key_possible | |
6923 | && ! key_translation_possible | |
6924 | && SYMBOLP (key)) | |
6925 | { | |
6926 | Lisp_Object breakdown; | |
6927 | int modifiers; | |
6928 | ||
6929 | breakdown = parse_modifiers (key); | |
6930 | modifiers = XINT (XCONS (XCONS (breakdown)->cdr)->car); | |
6931 | if (modifiers & shift_modifier) | |
6932 | { | |
569871d2 | 6933 | Lisp_Object new_key; |
3fe8e9a2 RS |
6934 | |
6935 | original_uppercase = key; | |
6936 | original_uppercase_position = t - 1; | |
ef8fd672 | 6937 | |
569871d2 RS |
6938 | modifiers &= ~shift_modifier; |
6939 | new_key = apply_modifiers (modifiers, | |
6940 | XCONS (breakdown)->car); | |
6941 | ||
3fe8e9a2 RS |
6942 | keybuf[t - 1] = new_key; |
6943 | mock_input = t; | |
6944 | ||
6945 | fkey_map = prev_fkey_map; | |
6946 | fkey_start = prev_fkey_start; | |
6947 | fkey_end = prev_fkey_end; | |
6948 | ||
6949 | keytran_map = prev_keytran_map; | |
6950 | keytran_start = prev_keytran_start; | |
6951 | keytran_end = prev_keytran_end; | |
6952 | ||
6953 | goto replay_sequence; | |
ef8fd672 RS |
6954 | } |
6955 | } | |
284f4730 JB |
6956 | } |
6957 | ||
309b0fc8 | 6958 | if (!dummyflag) |
bc536d84 RS |
6959 | read_key_sequence_cmd = (first_binding < nmaps |
6960 | ? defs[first_binding] | |
6961 | : Qnil); | |
284f4730 | 6962 | |
cd21b839 | 6963 | unread_switch_frame = delayed_switch_frame; |
f4255cd1 | 6964 | unbind_to (count, Qnil); |
07f76a14 | 6965 | |
3fe8e9a2 RS |
6966 | /* Don't downcase the last character if the caller says don't. |
6967 | Don't downcase it if the result is undefined, either. */ | |
6968 | if ((dont_downcase_last || first_binding >= nmaps) | |
6969 | && t - 1 == original_uppercase_position) | |
309b0fc8 RS |
6970 | keybuf[t - 1] = original_uppercase; |
6971 | ||
07f76a14 JB |
6972 | /* Occasionally we fabricate events, perhaps by expanding something |
6973 | according to function-key-map, or by adding a prefix symbol to a | |
6974 | mouse click in the scroll bar or modeline. In this cases, return | |
6975 | the entire generated key sequence, even if we hit an unbound | |
6976 | prefix or a definition before the end. This means that you will | |
6977 | be able to push back the event properly, and also means that | |
6978 | read-key-sequence will always return a logical unit. | |
6979 | ||
6980 | Better ideas? */ | |
cca310da JB |
6981 | for (; t < mock_input; t++) |
6982 | { | |
a98ea3f9 RS |
6983 | if (echo_keystrokes) |
6984 | echo_char (keybuf[t]); | |
cca310da JB |
6985 | add_command_key (keybuf[t]); |
6986 | } | |
07f76a14 | 6987 | |
284f4730 JB |
6988 | return t; |
6989 | } | |
6990 | ||
a612e298 RS |
6991 | #if 0 /* This doc string is too long for some compilers. |
6992 | This commented-out definition serves for DOC. */ | |
ce98e608 | 6993 | DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 4, 0, |
284f4730 JB |
6994 | "Read a sequence of keystrokes and return as a string or vector.\n\ |
6995 | The sequence is sufficient to specify a non-prefix command in the\n\ | |
6996 | current local and global maps.\n\ | |
6997 | \n\ | |
c0a58692 RS |
6998 | First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\ |
6999 | Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\ | |
7000 | as a continuation of the previous key.\n\ | |
284f4730 | 7001 | \n\ |
309b0fc8 RS |
7002 | The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\ |
7003 | convert the last event to lower case. (Normally any upper case event\n\ | |
7004 | is converted to lower case if the original event is undefined and the lower\n\ | |
7005 | case equivalent is defined.) A non-nil value is appropriate for reading\n\ | |
7006 | a key sequence to be defined.\n\ | |
7007 | \n\ | |
cb5df6ae JB |
7008 | A C-g typed while in this function is treated like any other character,\n\ |
7009 | and `quit-flag' is not set.\n\ | |
7010 | \n\ | |
7011 | If the key sequence starts with a mouse click, then the sequence is read\n\ | |
7012 | using the keymaps of the buffer of the window clicked in, not the buffer\n\ | |
7013 | of the selected window as normal.\n\ | |
ede41463 | 7014 | ""\n\ |
cb5df6ae JB |
7015 | `read-key-sequence' drops unbound button-down events, since you normally\n\ |
7016 | only care about the click or drag events which follow them. If a drag\n\ | |
fbcd35bd JB |
7017 | or multi-click event is unbound, but the corresponding click event would\n\ |
7018 | be bound, `read-key-sequence' turns the event into a click event at the\n\ | |
cb5df6ae | 7019 | drag's starting position. This means that you don't have to distinguish\n\ |
fbcd35bd | 7020 | between click and drag, double, or triple events unless you want to.\n\ |
cb5df6ae JB |
7021 | \n\ |
7022 | `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\ | |
3c370943 JB |
7023 | lines separating windows, and scroll bars with imaginary keys\n\ |
7024 | `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\ | |
cb5df6ae | 7025 | \n\ |
ce98e608 KH |
7026 | Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\ |
7027 | function will process a switch-frame event if the user switches frames\n\ | |
7028 | before typing anything. If the user switches frames in the middle of a\n\ | |
7029 | key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\ | |
7030 | is nil, then the event will be put off until after the current key sequence.\n\ | |
cb5df6ae JB |
7031 | \n\ |
7032 | `read-key-sequence' checks `function-key-map' for function key\n\ | |
7033 | sequences, where they wouldn't conflict with ordinary bindings. See\n\ | |
4bb994d1 | 7034 | `function-key-map' for more details.") |
11e08aab | 7035 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame) |
a612e298 RS |
7036 | #endif |
7037 | ||
ce98e608 | 7038 | DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 4, 0, |
a612e298 | 7039 | 0) |
ce98e608 | 7040 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame) |
309b0fc8 | 7041 | Lisp_Object prompt, continue_echo, dont_downcase_last; |
ce98e608 | 7042 | Lisp_Object can_return_switch_frame; |
284f4730 JB |
7043 | { |
7044 | Lisp_Object keybuf[30]; | |
7045 | register int i; | |
7046 | struct gcpro gcpro1, gcpro2; | |
7047 | ||
7048 | if (!NILP (prompt)) | |
7049 | CHECK_STRING (prompt, 0); | |
7050 | QUIT; | |
7051 | ||
7052 | bzero (keybuf, sizeof keybuf); | |
7053 | GCPRO1 (keybuf[0]); | |
7054 | gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); | |
7055 | ||
daa37602 | 7056 | if (NILP (continue_echo)) |
6321824f RS |
7057 | { |
7058 | this_command_key_count = 0; | |
7059 | this_single_command_key_start = 0; | |
7060 | } | |
c0a58692 | 7061 | |
309b0fc8 | 7062 | i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), |
ce98e608 | 7063 | prompt, ! NILP (dont_downcase_last), |
f571ae0d | 7064 | ! NILP (can_return_switch_frame), 0); |
284f4730 | 7065 | |
dcc408a0 RS |
7066 | if (i == -1) |
7067 | { | |
7068 | Vquit_flag = Qt; | |
7069 | QUIT; | |
7070 | } | |
284f4730 | 7071 | UNGCPRO; |
86e5706b | 7072 | return make_event_array (i, keybuf); |
284f4730 JB |
7073 | } |
7074 | \f | |
158f7532 | 7075 | DEFUN ("command-execute", Fcommand_execute, Scommand_execute, 1, 4, 0, |
284f4730 JB |
7076 | "Execute CMD as an editor command.\n\ |
7077 | CMD must be a symbol that satisfies the `commandp' predicate.\n\ | |
7078 | Optional second arg RECORD-FLAG non-nil\n\ | |
7079 | means unconditionally put this command in `command-history'.\n\ | |
aaf2ead7 RS |
7080 | Otherwise, that is done only if an arg is read using the minibuffer.\n\ |
7081 | The argument KEYS specifies the value to use instead of (this-command-keys)\n\ | |
6321824f | 7082 | when reading the arguments; if it is nil, (this-command-keys) is used.\n\ |
158f7532 RS |
7083 | The argument SPECIAL, if non-nil, means that this command is executing\n\ |
7084 | a special event, so ignore the prefix argument and don't clear it.") | |
7085 | (cmd, record_flag, keys, special) | |
7086 | Lisp_Object cmd, record_flag, keys, special; | |
284f4730 JB |
7087 | { |
7088 | register Lisp_Object final; | |
7089 | register Lisp_Object tem; | |
7090 | Lisp_Object prefixarg; | |
7091 | struct backtrace backtrace; | |
7092 | extern int debug_on_next_call; | |
7093 | ||
284f4730 JB |
7094 | debug_on_next_call = 0; |
7095 | ||
158f7532 RS |
7096 | if (NILP (special)) |
7097 | { | |
7098 | prefixarg = current_kboard->Vprefix_arg; | |
7099 | Vcurrent_prefix_arg = prefixarg; | |
7100 | current_kboard->Vprefix_arg = Qnil; | |
7101 | } | |
7102 | else | |
7103 | prefixarg = Qnil; | |
7104 | ||
8c18cbfb | 7105 | if (SYMBOLP (cmd)) |
284f4730 JB |
7106 | { |
7107 | tem = Fget (cmd, Qdisabled); | |
88ce066e | 7108 | if (!NILP (tem) && !NILP (Vrun_hooks)) |
b78ce8fb RS |
7109 | { |
7110 | tem = Fsymbol_value (Qdisabled_command_hook); | |
7111 | if (!NILP (tem)) | |
7112 | return call1 (Vrun_hooks, Qdisabled_command_hook); | |
7113 | } | |
284f4730 JB |
7114 | } |
7115 | ||
01e26217 | 7116 | while (1) |
284f4730 | 7117 | { |
ffd56f97 | 7118 | final = Findirect_function (cmd); |
284f4730 JB |
7119 | |
7120 | if (CONSP (final) && (tem = Fcar (final), EQ (tem, Qautoload))) | |
b516a185 RS |
7121 | { |
7122 | struct gcpro gcpro1, gcpro2; | |
7123 | ||
7124 | GCPRO2 (cmd, prefixarg); | |
7125 | do_autoload (final, cmd); | |
7126 | UNGCPRO; | |
7127 | } | |
284f4730 JB |
7128 | else |
7129 | break; | |
7130 | } | |
7131 | ||
8c18cbfb | 7132 | if (STRINGP (final) || VECTORP (final)) |
284f4730 JB |
7133 | { |
7134 | /* If requested, place the macro in the command history. For | |
7135 | other sorts of commands, call-interactively takes care of | |
7136 | this. */ | |
e57d8fd8 | 7137 | if (!NILP (record_flag)) |
284f4730 JB |
7138 | Vcommand_history |
7139 | = Fcons (Fcons (Qexecute_kbd_macro, | |
7140 | Fcons (final, Fcons (prefixarg, Qnil))), | |
7141 | Vcommand_history); | |
7142 | ||
7143 | return Fexecute_kbd_macro (final, prefixarg); | |
7144 | } | |
8c18cbfb | 7145 | if (CONSP (final) || SUBRP (final) || COMPILEDP (final)) |
284f4730 JB |
7146 | { |
7147 | backtrace.next = backtrace_list; | |
7148 | backtrace_list = &backtrace; | |
7149 | backtrace.function = &Qcall_interactively; | |
7150 | backtrace.args = &cmd; | |
7151 | backtrace.nargs = 1; | |
7152 | backtrace.evalargs = 0; | |
7153 | ||
e57d8fd8 | 7154 | tem = Fcall_interactively (cmd, record_flag, keys); |
284f4730 JB |
7155 | |
7156 | backtrace_list = backtrace.next; | |
7157 | return tem; | |
7158 | } | |
7159 | return Qnil; | |
7160 | } | |
7161 | \f | |
284f4730 JB |
7162 | DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_command, |
7163 | 1, 1, "P", | |
7164 | "Read function name, then read its arguments and call it.") | |
7165 | (prefixarg) | |
7166 | Lisp_Object prefixarg; | |
7167 | { | |
7168 | Lisp_Object function; | |
7169 | char buf[40]; | |
7170 | Lisp_Object saved_keys; | |
5434fce6 | 7171 | Lisp_Object bindings, value; |
214360e9 | 7172 | struct gcpro gcpro1, gcpro2; |
284f4730 | 7173 | |
b0f2a7bf KH |
7174 | saved_keys = Fvector (this_command_key_count, |
7175 | XVECTOR (this_command_keys)->contents); | |
284f4730 | 7176 | buf[0] = 0; |
fde7aff8 | 7177 | GCPRO2 (saved_keys, prefixarg); |
284f4730 JB |
7178 | |
7179 | if (EQ (prefixarg, Qminus)) | |
7180 | strcpy (buf, "- "); | |
7181 | else if (CONSP (prefixarg) && XINT (XCONS (prefixarg)->car) == 4) | |
7182 | strcpy (buf, "C-u "); | |
8c18cbfb | 7183 | else if (CONSP (prefixarg) && INTEGERP (XCONS (prefixarg)->car)) |
5d5b907f RS |
7184 | { |
7185 | if (sizeof (int) == sizeof (EMACS_INT)) | |
7186 | sprintf (buf, "%d ", XINT (XCONS (prefixarg)->car)); | |
7187 | else if (sizeof (long) == sizeof (EMACS_INT)) | |
7188 | sprintf (buf, "%ld ", XINT (XCONS (prefixarg)->car)); | |
7189 | else | |
7190 | abort (); | |
7191 | } | |
8c18cbfb | 7192 | else if (INTEGERP (prefixarg)) |
5d5b907f RS |
7193 | { |
7194 | if (sizeof (int) == sizeof (EMACS_INT)) | |
7195 | sprintf (buf, "%d ", XINT (prefixarg)); | |
7196 | else if (sizeof (long) == sizeof (EMACS_INT)) | |
7197 | sprintf (buf, "%ld ", XINT (prefixarg)); | |
7198 | else | |
7199 | abort (); | |
7200 | } | |
284f4730 JB |
7201 | |
7202 | /* This isn't strictly correct if execute-extended-command | |
7203 | is bound to anything else. Perhaps it should use | |
7204 | this_command_keys? */ | |
7205 | strcat (buf, "M-x "); | |
7206 | ||
7207 | /* Prompt with buf, and then read a string, completing from and | |
7208 | restricting to the set of all defined commands. Don't provide | |
51763820 | 7209 | any initial input. Save the command read on the extended-command |
03b4122a | 7210 | history list. */ |
284f4730 JB |
7211 | function = Fcompleting_read (build_string (buf), |
7212 | Vobarray, Qcommandp, | |
4328577a KH |
7213 | Qt, Qnil, Qextended_command_history, Qnil, |
7214 | Qnil); | |
284f4730 | 7215 | |
1f5b1641 RS |
7216 | if (STRINGP (function) && XSTRING (function)->size == 0) |
7217 | error ("No command name given"); | |
7218 | ||
1113d9db JB |
7219 | /* Set this_command_keys to the concatenation of saved_keys and |
7220 | function, followed by a RET. */ | |
284f4730 | 7221 | { |
1113d9db | 7222 | struct Lisp_String *str; |
b0f2a7bf | 7223 | Lisp_Object *keys; |
284f4730 JB |
7224 | int i; |
7225 | Lisp_Object tem; | |
7226 | ||
1113d9db | 7227 | this_command_key_count = 0; |
6321824f | 7228 | this_single_command_key_start = 0; |
1113d9db | 7229 | |
b0f2a7bf KH |
7230 | keys = XVECTOR (saved_keys)->contents; |
7231 | for (i = 0; i < XVECTOR (saved_keys)->size; i++) | |
7232 | add_command_key (keys[i]); | |
1113d9db JB |
7233 | |
7234 | str = XSTRING (function); | |
7235 | for (i = 0; i < str->size; i++) | |
7236 | { | |
bb9e9bed | 7237 | XSETFASTINT (tem, str->data[i]); |
1113d9db JB |
7238 | add_command_key (tem); |
7239 | } | |
7240 | ||
bb9e9bed | 7241 | XSETFASTINT (tem, '\015'); |
1113d9db | 7242 | add_command_key (tem); |
284f4730 JB |
7243 | } |
7244 | ||
7245 | UNGCPRO; | |
7246 | ||
0a7f1fc0 | 7247 | function = Fintern (function, Qnil); |
d8bcf58e | 7248 | current_kboard->Vprefix_arg = prefixarg; |
284f4730 JB |
7249 | this_command = function; |
7250 | ||
6526ab49 RS |
7251 | /* If enabled, show which key runs this command. */ |
7252 | if (!NILP (Vsuggest_key_bindings) | |
71012575 | 7253 | && NILP (Vexecuting_macro) |
6526ab49 | 7254 | && SYMBOLP (function)) |
5434fce6 RS |
7255 | bindings = Fwhere_is_internal (function, Voverriding_local_map, |
7256 | Qt, Qnil); | |
7257 | else | |
7258 | bindings = Qnil; | |
6526ab49 | 7259 | |
5434fce6 RS |
7260 | value = Qnil; |
7261 | GCPRO2 (bindings, value); | |
7262 | value = Fcommand_execute (function, Qt, Qnil, Qnil); | |
6526ab49 | 7263 | |
5434fce6 | 7264 | /* If the command has a key binding, print it now. */ |
3ababa60 | 7265 | if (!NILP (bindings) |
ee112567 KH |
7266 | && ! (VECTORP (bindings) && EQ (Faref (bindings, make_number (0)), |
7267 | Qmouse_movement))) | |
5434fce6 RS |
7268 | { |
7269 | /* But first wait, and skip the message if there is input. */ | |
7270 | if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings) | |
7271 | ? Vsuggest_key_bindings : make_number (2)), | |
303b5b3f RS |
7272 | Qnil, Qnil)) |
7273 | && ! CONSP (Vunread_command_events)) | |
6526ab49 | 7274 | { |
5434fce6 RS |
7275 | Lisp_Object binding; |
7276 | char *newmessage; | |
7277 | char *oldmessage = echo_area_glyphs; | |
7278 | int oldmessage_len = echo_area_glyphs_length; | |
30c6e062 | 7279 | int oldmultibyte = message_enable_multibyte; |
5434fce6 RS |
7280 | |
7281 | binding = Fkey_description (bindings); | |
7282 | ||
7283 | newmessage | |
7284 | = (char *) alloca (XSYMBOL (function)->name->size | |
7285 | + XSTRING (binding)->size | |
7286 | + 100); | |
3ababa60 | 7287 | sprintf (newmessage, "You can run the command `%s' with %s", |
6526ab49 | 7288 | XSYMBOL (function)->name->data, |
5434fce6 RS |
7289 | XSTRING (binding)->data); |
7290 | message1_nolog (newmessage); | |
7291 | if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings) | |
7292 | ? Vsuggest_key_bindings : make_number (2)), | |
7293 | Qnil, Qnil))) | |
a59b172a | 7294 | message2_nolog (oldmessage, oldmessage_len, oldmultibyte); |
6526ab49 RS |
7295 | } |
7296 | } | |
7297 | ||
5434fce6 | 7298 | RETURN_UNGCPRO (value); |
284f4730 | 7299 | } |
6526ab49 RS |
7300 | |
7301 | /* Find the set of keymaps now active. | |
7302 | Store into *MAPS_P a vector holding the various maps | |
7303 | and return the number of them. The vector was malloc'd | |
7304 | and the caller should free it. */ | |
7305 | ||
7306 | int | |
7307 | current_active_maps (maps_p) | |
7308 | Lisp_Object **maps_p; | |
7309 | { | |
7310 | Lisp_Object *tmaps, *maps; | |
7311 | int nmaps; | |
7312 | ||
7313 | /* Should overriding-terminal-local-map and overriding-local-map apply? */ | |
7314 | if (!NILP (Voverriding_local_map_menu_flag)) | |
7315 | { | |
7316 | /* Yes, use them (if non-nil) as well as the global map. */ | |
7317 | maps = (Lisp_Object *) xmalloc (3 * sizeof (maps[0])); | |
7318 | nmaps = 0; | |
7319 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
7320 | maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
7321 | if (!NILP (Voverriding_local_map)) | |
7322 | maps[nmaps++] = Voverriding_local_map; | |
7323 | } | |
7324 | else | |
7325 | { | |
7326 | /* No, so use major and minor mode keymaps. */ | |
7327 | nmaps = current_minor_maps (NULL, &tmaps); | |
7328 | maps = (Lisp_Object *) xmalloc ((nmaps + 2) * sizeof (maps[0])); | |
7329 | bcopy (tmaps, maps, nmaps * sizeof (maps[0])); | |
7330 | #ifdef USE_TEXT_PROPERTIES | |
7331 | maps[nmaps++] = get_local_map (PT, current_buffer); | |
7332 | #else | |
7333 | maps[nmaps++] = current_buffer->keymap; | |
7334 | #endif | |
7335 | } | |
7336 | maps[nmaps++] = current_global_map; | |
7337 | ||
7338 | *maps_p = maps; | |
7339 | return nmaps; | |
7340 | } | |
284f4730 | 7341 | \f |
d9d4c147 | 7342 | /* Return nonzero if input events are pending. */ |
284f4730 JB |
7343 | |
7344 | detect_input_pending () | |
7345 | { | |
7346 | if (!input_pending) | |
d9d4c147 KH |
7347 | get_input_pending (&input_pending, 0); |
7348 | ||
7349 | return input_pending; | |
7350 | } | |
7351 | ||
b1878f45 | 7352 | /* Return nonzero if input events are pending, and run any pending timers. */ |
d9d4c147 | 7353 | |
87dd9b9b RS |
7354 | detect_input_pending_run_timers (do_display) |
7355 | int do_display; | |
d9d4c147 | 7356 | { |
87dd9b9b RS |
7357 | int old_timers_run = timers_run; |
7358 | ||
d9d4c147 KH |
7359 | if (!input_pending) |
7360 | get_input_pending (&input_pending, 1); | |
284f4730 | 7361 | |
87dd9b9b RS |
7362 | if (old_timers_run != timers_run && do_display) |
7363 | redisplay_preserve_echo_area (); | |
7364 | ||
284f4730 JB |
7365 | return input_pending; |
7366 | } | |
7367 | ||
ffd56f97 JB |
7368 | /* This is called in some cases before a possible quit. |
7369 | It cases the next call to detect_input_pending to recompute input_pending. | |
7370 | So calling this function unnecessarily can't do any harm. */ | |
07a59269 KH |
7371 | |
7372 | void | |
ffd56f97 JB |
7373 | clear_input_pending () |
7374 | { | |
7375 | input_pending = 0; | |
7376 | } | |
7377 | ||
b1878f45 RS |
7378 | /* Return nonzero if there are pending requeued events. |
7379 | This isn't used yet. The hope is to make wait_reading_process_input | |
7380 | call it, and return return if it runs Lisp code that unreads something. | |
7381 | The problem is, kbd_buffer_get_event needs to be fixed to know what | |
7382 | to do in that case. It isn't trivial. */ | |
7383 | ||
7384 | requeued_events_pending_p () | |
7385 | { | |
7386 | return (!NILP (Vunread_command_events) || unread_command_char != -1); | |
7387 | } | |
7388 | ||
7389 | ||
284f4730 JB |
7390 | DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0, |
7391 | "T if command input is currently available with no waiting.\n\ | |
7392 | Actually, the value is nil only if we can be sure that no input is available.") | |
7393 | () | |
7394 | { | |
24597608 | 7395 | if (!NILP (Vunread_command_events) || unread_command_char != -1) |
284f4730 JB |
7396 | return (Qt); |
7397 | ||
d9d4c147 KH |
7398 | get_input_pending (&input_pending, 1); |
7399 | return input_pending > 0 ? Qt : Qnil; | |
284f4730 JB |
7400 | } |
7401 | ||
7402 | DEFUN ("recent-keys", Frecent_keys, Srecent_keys, 0, 0, 0, | |
22d7cb89 | 7403 | "Return vector of last 100 events, not counting those from keyboard macros.") |
284f4730 JB |
7404 | () |
7405 | { | |
5160df46 | 7406 | Lisp_Object *keys = XVECTOR (recent_keys)->contents; |
284f4730 JB |
7407 | Lisp_Object val; |
7408 | ||
7409 | if (total_keys < NUM_RECENT_KEYS) | |
5160df46 | 7410 | return Fvector (total_keys, keys); |
284f4730 JB |
7411 | else |
7412 | { | |
5160df46 JB |
7413 | val = Fvector (NUM_RECENT_KEYS, keys); |
7414 | bcopy (keys + recent_keys_index, | |
284f4730 JB |
7415 | XVECTOR (val)->contents, |
7416 | (NUM_RECENT_KEYS - recent_keys_index) * sizeof (Lisp_Object)); | |
5160df46 | 7417 | bcopy (keys, |
284f4730 JB |
7418 | XVECTOR (val)->contents + NUM_RECENT_KEYS - recent_keys_index, |
7419 | recent_keys_index * sizeof (Lisp_Object)); | |
7420 | return val; | |
7421 | } | |
7422 | } | |
7423 | ||
7424 | DEFUN ("this-command-keys", Fthis_command_keys, Sthis_command_keys, 0, 0, 0, | |
e5f920d7 RS |
7425 | "Return the key sequence that invoked this command.\n\ |
7426 | The value is a string or a vector.") | |
284f4730 JB |
7427 | () |
7428 | { | |
86e5706b RS |
7429 | return make_event_array (this_command_key_count, |
7430 | XVECTOR (this_command_keys)->contents); | |
284f4730 JB |
7431 | } |
7432 | ||
6321824f RS |
7433 | DEFUN ("this-single-command-keys", Fthis_single_command_keys, |
7434 | Sthis_single_command_keys, 0, 0, 0, | |
7435 | "Return the key sequence that invoked this command.\n\ | |
7436 | Unlike `this-command-keys', this function's value\n\ | |
7437 | does not include prefix arguments.\n\ | |
7438 | The value is a string or a vector.") | |
7439 | () | |
7440 | { | |
7441 | return make_event_array (this_command_key_count | |
7442 | - this_single_command_key_start, | |
7443 | (XVECTOR (this_command_keys)->contents | |
7444 | + this_single_command_key_start)); | |
7445 | } | |
7446 | ||
71918b75 RS |
7447 | DEFUN ("reset-this-command-lengths", Freset_this_command_lengths, |
7448 | Sreset_this_command_lengths, 0, 0, 0, | |
7449 | "Used for complicated reasons in `universal-argument-other-key'.\n\ | |
7450 | \n\ | |
7451 | `universal-argument-other-key' rereads the event just typed.\n\ | |
7452 | It then gets translated through `function-key-map'.\n\ | |
7453 | The translated event gets included in the echo area and in\n\ | |
7454 | the value of `this-command-keys' in addition to the raw original event.\n\ | |
7455 | That is not right.\n\ | |
7456 | \n\ | |
7457 | Calling this function directs the translated event to replace\n\ | |
7458 | the original event, so that only one version of the event actually\n\ | |
7459 | appears in the echo area and in the value of `this-command-keys.'.") | |
7460 | () | |
7461 | { | |
7462 | before_command_restore_flag = 1; | |
7463 | before_command_key_count_1 = before_command_key_count; | |
7464 | before_command_echo_length_1 = before_command_echo_length; | |
7465 | } | |
7466 | ||
284f4730 JB |
7467 | DEFUN ("recursion-depth", Frecursion_depth, Srecursion_depth, 0, 0, 0, |
7468 | "Return the current depth in recursive edits.") | |
7469 | () | |
7470 | { | |
7471 | Lisp_Object temp; | |
bb9e9bed | 7472 | XSETFASTINT (temp, command_loop_level + minibuf_level); |
284f4730 JB |
7473 | return temp; |
7474 | } | |
7475 | ||
7476 | DEFUN ("open-dribble-file", Fopen_dribble_file, Sopen_dribble_file, 1, 1, | |
7477 | "FOpen dribble file: ", | |
9b2471df RS |
7478 | "Start writing all keyboard characters to a dribble file called FILE.\n\ |
7479 | If FILE is nil, close any open dribble file.") | |
284f4730 JB |
7480 | (file) |
7481 | Lisp_Object file; | |
7482 | { | |
6cb52def | 7483 | if (dribble) |
284f4730 | 7484 | { |
6cb52def KH |
7485 | fclose (dribble); |
7486 | dribble = 0; | |
284f4730 | 7487 | } |
6cb52def | 7488 | if (!NILP (file)) |
284f4730 JB |
7489 | { |
7490 | file = Fexpand_file_name (file, Qnil); | |
7491 | dribble = fopen (XSTRING (file)->data, "w"); | |
ab6ca1de KH |
7492 | if (dribble == 0) |
7493 | report_file_error ("Opening dribble", Fcons (file, Qnil)); | |
284f4730 JB |
7494 | } |
7495 | return Qnil; | |
7496 | } | |
7497 | ||
7498 | DEFUN ("discard-input", Fdiscard_input, Sdiscard_input, 0, 0, 0, | |
7499 | "Discard the contents of the terminal input buffer.\n\ | |
7500 | Also cancel any kbd macro being defined.") | |
7501 | () | |
7502 | { | |
c5fdd383 | 7503 | current_kboard->defining_kbd_macro = Qnil; |
284f4730 JB |
7504 | update_mode_lines++; |
7505 | ||
24597608 | 7506 | Vunread_command_events = Qnil; |
86e5706b | 7507 | unread_command_char = -1; |
284f4730 JB |
7508 | |
7509 | discard_tty_input (); | |
7510 | ||
ff0b5f4c JB |
7511 | /* Without the cast, GCC complains that this assignment loses the |
7512 | volatile qualifier of kbd_store_ptr. Is there anything wrong | |
7513 | with that? */ | |
beecf6a1 KH |
7514 | kbd_fetch_ptr = (struct input_event *) kbd_store_ptr; |
7515 | Ffillarray (kbd_buffer_frame_or_window, Qnil); | |
284f4730 JB |
7516 | input_pending = 0; |
7517 | ||
7518 | return Qnil; | |
7519 | } | |
7520 | \f | |
7521 | DEFUN ("suspend-emacs", Fsuspend_emacs, Ssuspend_emacs, 0, 1, "", | |
7522 | "Stop Emacs and return to superior process. You can resume later.\n\ | |
8026024c KH |
7523 | If `cannot-suspend' is non-nil, or if the system doesn't support job\n\ |
7524 | control, run a subshell instead.\n\n\ | |
284f4730 | 7525 | If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\ |
b7d2ebbf RS |
7526 | to be read as terminal input by Emacs's parent, after suspension.\n\ |
7527 | \n\ | |
bbdc2092 RS |
7528 | Before suspending, run the normal hook `suspend-hook'.\n\ |
7529 | After resumption run the normal hook `suspend-resume-hook'.\n\ | |
284f4730 JB |
7530 | \n\ |
7531 | Some operating systems cannot stop the Emacs process and resume it later.\n\ | |
b7d2ebbf | 7532 | On such systems, Emacs starts a subshell instead of suspending.") |
284f4730 JB |
7533 | (stuffstring) |
7534 | Lisp_Object stuffstring; | |
7535 | { | |
3a69360c | 7536 | Lisp_Object tem; |
284f4730 JB |
7537 | int count = specpdl_ptr - specpdl; |
7538 | int old_height, old_width; | |
7539 | int width, height; | |
b7d2ebbf | 7540 | struct gcpro gcpro1, gcpro2; |
284f4730 JB |
7541 | |
7542 | if (!NILP (stuffstring)) | |
7543 | CHECK_STRING (stuffstring, 0); | |
284f4730 | 7544 | |
1e95ed28 JB |
7545 | /* Run the functions in suspend-hook. */ |
7546 | if (!NILP (Vrun_hooks)) | |
7547 | call1 (Vrun_hooks, intern ("suspend-hook")); | |
284f4730 | 7548 | |
b7d2ebbf | 7549 | GCPRO1 (stuffstring); |
ff11dfa1 | 7550 | get_frame_size (&old_width, &old_height); |
284f4730 JB |
7551 | reset_sys_modes (); |
7552 | /* sys_suspend can get an error if it tries to fork a subshell | |
7553 | and the system resources aren't available for that. */ | |
91a0da02 AS |
7554 | record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes, |
7555 | 0); | |
284f4730 | 7556 | stuff_buffered_input (stuffstring); |
8026024c KH |
7557 | if (cannot_suspend) |
7558 | sys_subshell (); | |
7559 | else | |
7560 | sys_suspend (); | |
284f4730 JB |
7561 | unbind_to (count, Qnil); |
7562 | ||
7563 | /* Check if terminal/window size has changed. | |
7564 | Note that this is not useful when we are running directly | |
7565 | with a window system; but suspend should be disabled in that case. */ | |
ff11dfa1 | 7566 | get_frame_size (&width, &height); |
284f4730 | 7567 | if (width != old_width || height != old_height) |
f5ea6163 | 7568 | change_frame_size (selected_frame, height, width, 0, 0); |
284f4730 | 7569 | |
1e95ed28 | 7570 | /* Run suspend-resume-hook. */ |
284f4730 JB |
7571 | if (!NILP (Vrun_hooks)) |
7572 | call1 (Vrun_hooks, intern ("suspend-resume-hook")); | |
df0f2ba1 | 7573 | |
284f4730 JB |
7574 | UNGCPRO; |
7575 | return Qnil; | |
7576 | } | |
7577 | ||
7578 | /* If STUFFSTRING is a string, stuff its contents as pending terminal input. | |
eb8c3be9 | 7579 | Then in any case stuff anything Emacs has read ahead and not used. */ |
284f4730 | 7580 | |
07a59269 | 7581 | void |
284f4730 JB |
7582 | stuff_buffered_input (stuffstring) |
7583 | Lisp_Object stuffstring; | |
7584 | { | |
284f4730 | 7585 | /* stuff_char works only in BSD, versions 4.2 and up. */ |
6df54671 | 7586 | #ifdef BSD_SYSTEM |
284f4730 | 7587 | #ifndef BSD4_1 |
612b78ef | 7588 | register unsigned char *p; |
612b78ef | 7589 | |
8c18cbfb | 7590 | if (STRINGP (stuffstring)) |
284f4730 JB |
7591 | { |
7592 | register int count; | |
7593 | ||
7594 | p = XSTRING (stuffstring)->data; | |
7595 | count = XSTRING (stuffstring)->size; | |
7596 | while (count-- > 0) | |
7597 | stuff_char (*p++); | |
7598 | stuff_char ('\n'); | |
7599 | } | |
7600 | /* Anything we have read ahead, put back for the shell to read. */ | |
beecf6a1 | 7601 | /* ?? What should this do when we have multiple keyboards?? |
c5fdd383 | 7602 | Should we ignore anything that was typed in at the "wrong" kboard? */ |
beecf6a1 | 7603 | for (; kbd_fetch_ptr != kbd_store_ptr; kbd_fetch_ptr++) |
284f4730 | 7604 | { |
beecf6a1 KH |
7605 | if (kbd_fetch_ptr == kbd_buffer + KBD_BUFFER_SIZE) |
7606 | kbd_fetch_ptr = kbd_buffer; | |
7607 | if (kbd_fetch_ptr->kind == ascii_keystroke) | |
7608 | stuff_char (kbd_fetch_ptr->code); | |
7609 | kbd_fetch_ptr->kind = no_event; | |
7610 | (XVECTOR (kbd_buffer_frame_or_window)->contents[kbd_fetch_ptr | |
7611 | - kbd_buffer] | |
7b4aedb9 | 7612 | = Qnil); |
284f4730 JB |
7613 | } |
7614 | input_pending = 0; | |
7615 | #endif | |
6df54671 | 7616 | #endif /* BSD_SYSTEM and not BSD4_1 */ |
284f4730 JB |
7617 | } |
7618 | \f | |
ffd56f97 JB |
7619 | set_waiting_for_input (time_to_clear) |
7620 | EMACS_TIME *time_to_clear; | |
284f4730 | 7621 | { |
ffd56f97 | 7622 | input_available_clear_time = time_to_clear; |
284f4730 JB |
7623 | |
7624 | /* Tell interrupt_signal to throw back to read_char, */ | |
7625 | waiting_for_input = 1; | |
7626 | ||
7627 | /* If interrupt_signal was called before and buffered a C-g, | |
7628 | make it run again now, to avoid timing error. */ | |
7629 | if (!NILP (Vquit_flag)) | |
7630 | quit_throw_to_read_char (); | |
284f4730 JB |
7631 | } |
7632 | ||
07a59269 | 7633 | void |
284f4730 JB |
7634 | clear_waiting_for_input () |
7635 | { | |
7636 | /* Tell interrupt_signal not to throw back to read_char, */ | |
7637 | waiting_for_input = 0; | |
ffd56f97 | 7638 | input_available_clear_time = 0; |
284f4730 JB |
7639 | } |
7640 | ||
7641 | /* This routine is called at interrupt level in response to C-G. | |
7642 | If interrupt_input, this is the handler for SIGINT. | |
7643 | Otherwise, it is called from kbd_buffer_store_event, | |
7644 | in handling SIGIO or SIGTINT. | |
7645 | ||
7646 | If `waiting_for_input' is non zero, then unless `echoing' is nonzero, | |
7647 | immediately throw back to read_char. | |
7648 | ||
7649 | Otherwise it sets the Lisp variable quit-flag not-nil. | |
7650 | This causes eval to throw, when it gets a chance. | |
7651 | If quit-flag is already non-nil, it stops the job right away. */ | |
7652 | ||
7653 | SIGTYPE | |
91c049d4 RS |
7654 | interrupt_signal (signalnum) /* If we don't have an argument, */ |
7655 | int signalnum; /* some compilers complain in signal calls. */ | |
284f4730 JB |
7656 | { |
7657 | char c; | |
7658 | /* Must preserve main program's value of errno. */ | |
7659 | int old_errno = errno; | |
284f4730 | 7660 | |
5970a8cb | 7661 | #if defined (USG) && !defined (POSIX_SIGNALS) |
7a80a6f6 RS |
7662 | if (!read_socket_hook && NILP (Vwindow_system)) |
7663 | { | |
7664 | /* USG systems forget handlers when they are used; | |
7665 | must reestablish each time */ | |
7666 | signal (SIGINT, interrupt_signal); | |
7667 | signal (SIGQUIT, interrupt_signal); | |
7668 | } | |
284f4730 JB |
7669 | #endif /* USG */ |
7670 | ||
7671 | cancel_echoing (); | |
7672 | ||
31e4e97b EZ |
7673 | if (!NILP (Vquit_flag) |
7674 | && (FRAME_TERMCAP_P (selected_frame) || FRAME_MSDOS_P (selected_frame))) | |
284f4730 | 7675 | { |
31e4e97b EZ |
7676 | /* If SIGINT isn't blocked, don't let us be interrupted by |
7677 | another SIGINT, it might be harmful due to non-reentrancy | |
7678 | in I/O functions. */ | |
7679 | sigblock (sigmask (SIGINT)); | |
7680 | ||
284f4730 JB |
7681 | fflush (stdout); |
7682 | reset_sys_modes (); | |
31e4e97b | 7683 | |
284f4730 JB |
7684 | #ifdef SIGTSTP /* Support possible in later USG versions */ |
7685 | /* | |
7686 | * On systems which can suspend the current process and return to the original | |
7687 | * shell, this command causes the user to end up back at the shell. | |
7688 | * The "Auto-save" and "Abort" questions are not asked until | |
7689 | * the user elects to return to emacs, at which point he can save the current | |
7690 | * job and either dump core or continue. | |
7691 | */ | |
7692 | sys_suspend (); | |
7693 | #else | |
7694 | #ifdef VMS | |
7695 | if (sys_suspend () == -1) | |
7696 | { | |
7697 | printf ("Not running as a subprocess;\n"); | |
7698 | printf ("you can continue or abort.\n"); | |
7699 | } | |
7700 | #else /* not VMS */ | |
7701 | /* Perhaps should really fork an inferior shell? | |
7702 | But that would not provide any way to get back | |
7703 | to the original shell, ever. */ | |
7704 | printf ("No support for stopping a process on this operating system;\n"); | |
7705 | printf ("you can continue or abort.\n"); | |
7706 | #endif /* not VMS */ | |
7707 | #endif /* not SIGTSTP */ | |
80e4aa30 RS |
7708 | #ifdef MSDOS |
7709 | /* We must remain inside the screen area when the internal terminal | |
7710 | is used. Note that [Enter] is not echoed by dos. */ | |
7711 | cursor_to (0, 0); | |
7712 | #endif | |
118d6ca9 RS |
7713 | /* It doesn't work to autosave while GC is in progress; |
7714 | the code used for auto-saving doesn't cope with the mark bit. */ | |
7715 | if (!gc_in_progress) | |
9fd7d808 | 7716 | { |
118d6ca9 RS |
7717 | printf ("Auto-save? (y or n) "); |
7718 | fflush (stdout); | |
7719 | if (((c = getchar ()) & ~040) == 'Y') | |
7720 | { | |
7721 | Fdo_auto_save (Qt, Qnil); | |
80e4aa30 | 7722 | #ifdef MSDOS |
118d6ca9 | 7723 | printf ("\r\nAuto-save done"); |
80e4aa30 | 7724 | #else /* not MSDOS */ |
118d6ca9 | 7725 | printf ("Auto-save done\n"); |
80e4aa30 | 7726 | #endif /* not MSDOS */ |
118d6ca9 RS |
7727 | } |
7728 | while (c != '\n') c = getchar (); | |
9fd7d808 | 7729 | } |
118d6ca9 RS |
7730 | else |
7731 | { | |
7732 | /* During GC, it must be safe to reenable quitting again. */ | |
7733 | Vinhibit_quit = Qnil; | |
7734 | #ifdef MSDOS | |
7735 | printf ("\r\n"); | |
7736 | #endif /* not MSDOS */ | |
7737 | printf ("Garbage collection in progress; cannot auto-save now\r\n"); | |
7738 | printf ("but will instead do a real quit after garbage collection ends\r\n"); | |
7739 | fflush (stdout); | |
7740 | } | |
7741 | ||
80e4aa30 RS |
7742 | #ifdef MSDOS |
7743 | printf ("\r\nAbort? (y or n) "); | |
7744 | #else /* not MSDOS */ | |
284f4730 JB |
7745 | #ifdef VMS |
7746 | printf ("Abort (and enter debugger)? (y or n) "); | |
7747 | #else /* not VMS */ | |
7748 | printf ("Abort (and dump core)? (y or n) "); | |
7749 | #endif /* not VMS */ | |
80e4aa30 | 7750 | #endif /* not MSDOS */ |
284f4730 JB |
7751 | fflush (stdout); |
7752 | if (((c = getchar ()) & ~040) == 'Y') | |
7753 | abort (); | |
7754 | while (c != '\n') c = getchar (); | |
80e4aa30 RS |
7755 | #ifdef MSDOS |
7756 | printf ("\r\nContinuing...\r\n"); | |
7757 | #else /* not MSDOS */ | |
284f4730 | 7758 | printf ("Continuing...\n"); |
80e4aa30 | 7759 | #endif /* not MSDOS */ |
284f4730 JB |
7760 | fflush (stdout); |
7761 | init_sys_modes (); | |
31e4e97b | 7762 | sigfree (); |
284f4730 JB |
7763 | } |
7764 | else | |
7765 | { | |
7766 | /* If executing a function that wants to be interrupted out of | |
7767 | and the user has not deferred quitting by binding `inhibit-quit' | |
7768 | then quit right away. */ | |
7769 | if (immediate_quit && NILP (Vinhibit_quit)) | |
7770 | { | |
7771 | immediate_quit = 0; | |
7772 | sigfree (); | |
7773 | Fsignal (Qquit, Qnil); | |
7774 | } | |
7775 | else | |
7776 | /* Else request quit when it's safe */ | |
7777 | Vquit_flag = Qt; | |
7778 | } | |
7779 | ||
7780 | if (waiting_for_input && !echoing) | |
7781 | quit_throw_to_read_char (); | |
7782 | ||
7783 | errno = old_errno; | |
7784 | } | |
7785 | ||
7786 | /* Handle a C-g by making read_char return C-g. */ | |
7787 | ||
07a59269 | 7788 | void |
284f4730 JB |
7789 | quit_throw_to_read_char () |
7790 | { | |
7791 | quit_error_check (); | |
7792 | sigfree (); | |
7793 | /* Prevent another signal from doing this before we finish. */ | |
f76475ad | 7794 | clear_waiting_for_input (); |
284f4730 JB |
7795 | input_pending = 0; |
7796 | ||
24597608 | 7797 | Vunread_command_events = Qnil; |
86e5706b | 7798 | unread_command_char = -1; |
284f4730 | 7799 | |
087feab3 RS |
7800 | #if 0 /* Currently, sit_for is called from read_char without turning |
7801 | off polling. And that can call set_waiting_for_input. | |
7802 | It seems to be harmless. */ | |
e6b01c14 JB |
7803 | #ifdef POLL_FOR_INPUT |
7804 | /* May be > 1 if in recursive minibuffer. */ | |
7805 | if (poll_suppress_count == 0) | |
7806 | abort (); | |
7807 | #endif | |
087feab3 | 7808 | #endif |
4c52b668 KH |
7809 | if (FRAMEP (internal_last_event_frame) |
7810 | && XFRAME (internal_last_event_frame) != selected_frame) | |
719191cf RS |
7811 | do_switch_frame (make_lispy_switch_frame (internal_last_event_frame), |
7812 | Qnil, 0); | |
e6b01c14 | 7813 | |
284f4730 JB |
7814 | _longjmp (getcjmp, 1); |
7815 | } | |
7816 | \f | |
7817 | DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, | |
7818 | "Set mode of reading keyboard input.\n\ | |
464f8898 RS |
7819 | First arg INTERRUPT non-nil means use input interrupts;\n\ |
7820 | nil means use CBREAK mode.\n\ | |
7821 | Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\ | |
284f4730 | 7822 | (no effect except in CBREAK mode).\n\ |
b04904fb RS |
7823 | Third arg META t means accept 8-bit input (for a Meta key).\n\ |
7824 | META nil means ignore the top bit, on the assumption it is parity.\n\ | |
7825 | Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\ | |
a8ee7ef9 RS |
7826 | Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\ |
7827 | See also `current-input-mode'.") | |
284f4730 JB |
7828 | (interrupt, flow, meta, quit) |
7829 | Lisp_Object interrupt, flow, meta, quit; | |
7830 | { | |
7831 | if (!NILP (quit) | |
8c18cbfb | 7832 | && (!INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400)) |
34f04431 RS |
7833 | error ("set-input-mode: QUIT must be an ASCII character"); |
7834 | ||
7835 | #ifdef POLL_FOR_INPUT | |
7836 | stop_polling (); | |
7837 | #endif | |
284f4730 | 7838 | |
07de30b9 | 7839 | #ifndef DOS_NT |
2ee250ec | 7840 | /* this causes startup screen to be restored and messes with the mouse */ |
284f4730 | 7841 | reset_sys_modes (); |
2ee250ec RS |
7842 | #endif |
7843 | ||
284f4730 JB |
7844 | #ifdef SIGIO |
7845 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
284f4730 | 7846 | if (read_socket_hook) |
9a0f60bb KH |
7847 | { |
7848 | /* When using X, don't give the user a real choice, | |
7849 | because we haven't implemented the mechanisms to support it. */ | |
7850 | #ifdef NO_SOCK_SIGIO | |
7851 | interrupt_input = 0; | |
7852 | #else /* not NO_SOCK_SIGIO */ | |
7853 | interrupt_input = 1; | |
284f4730 | 7854 | #endif /* NO_SOCK_SIGIO */ |
9a0f60bb KH |
7855 | } |
7856 | else | |
284f4730 JB |
7857 | interrupt_input = !NILP (interrupt); |
7858 | #else /* not SIGIO */ | |
7859 | interrupt_input = 0; | |
7860 | #endif /* not SIGIO */ | |
9a0f60bb | 7861 | |
284f4730 JB |
7862 | /* Our VMS input only works by interrupts, as of now. */ |
7863 | #ifdef VMS | |
7864 | interrupt_input = 1; | |
7865 | #endif | |
9a0f60bb | 7866 | |
284f4730 | 7867 | flow_control = !NILP (flow); |
b04904fb RS |
7868 | if (NILP (meta)) |
7869 | meta_key = 0; | |
7870 | else if (EQ (meta, Qt)) | |
7871 | meta_key = 1; | |
7872 | else | |
7873 | meta_key = 2; | |
284f4730 JB |
7874 | if (!NILP (quit)) |
7875 | /* Don't let this value be out of range. */ | |
7876 | quit_char = XINT (quit) & (meta_key ? 0377 : 0177); | |
7877 | ||
07de30b9 | 7878 | #ifndef DOS_NT |
284f4730 | 7879 | init_sys_modes (); |
2ee250ec | 7880 | #endif |
34f04431 RS |
7881 | |
7882 | #ifdef POLL_FOR_INPUT | |
7883 | poll_suppress_count = 1; | |
7884 | start_polling (); | |
7885 | #endif | |
284f4730 JB |
7886 | return Qnil; |
7887 | } | |
80645119 JB |
7888 | |
7889 | DEFUN ("current-input-mode", Fcurrent_input_mode, Scurrent_input_mode, 0, 0, 0, | |
7890 | "Return information about the way Emacs currently reads keyboard input.\n\ | |
7891 | The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\ | |
7892 | INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\ | |
7893 | nil, Emacs is using CBREAK mode.\n\ | |
7894 | FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\ | |
7895 | terminal; this does not apply if Emacs uses interrupt-driven input.\n\ | |
a8ee7ef9 RS |
7896 | META is t if accepting 8-bit input with 8th bit as Meta flag.\n\ |
7897 | META nil means ignoring the top bit, on the assumption it is parity.\n\ | |
7898 | META is neither t nor nil if accepting 8-bit input and using\n\ | |
7899 | all 8 bits as the character code.\n\ | |
80645119 JB |
7900 | QUIT is the character Emacs currently uses to quit.\n\ |
7901 | The elements of this list correspond to the arguments of\n\ | |
a8ee7ef9 | 7902 | `set-input-mode'.") |
80645119 JB |
7903 | () |
7904 | { | |
7905 | Lisp_Object val[4]; | |
7906 | ||
7907 | val[0] = interrupt_input ? Qt : Qnil; | |
7908 | val[1] = flow_control ? Qt : Qnil; | |
a8ee7ef9 | 7909 | val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil; |
bb9e9bed | 7910 | XSETFASTINT (val[3], quit_char); |
80645119 | 7911 | |
bf673a7a | 7912 | return Flist (sizeof (val) / sizeof (val[0]), val); |
80645119 JB |
7913 | } |
7914 | ||
284f4730 | 7915 | \f |
6c6083a9 | 7916 | /* |
c5fdd383 | 7917 | * Set up a new kboard object with reasonable initial values. |
6c6083a9 KH |
7918 | */ |
7919 | void | |
c5fdd383 KH |
7920 | init_kboard (kb) |
7921 | KBOARD *kb; | |
6c6083a9 | 7922 | { |
217258d5 | 7923 | kb->Voverriding_terminal_local_map = Qnil; |
6c7178b9 | 7924 | kb->Vlast_command = Qnil; |
d8bcf58e | 7925 | kb->Vprefix_arg = Qnil; |
c5fdd383 KH |
7926 | kb->kbd_queue = Qnil; |
7927 | kb->kbd_queue_has_data = 0; | |
7928 | kb->immediate_echo = 0; | |
7929 | kb->echoptr = kb->echobuf; | |
7930 | kb->echo_after_prompt = -1; | |
7931 | kb->kbd_macro_buffer = 0; | |
7932 | kb->kbd_macro_bufsize = 0; | |
7933 | kb->defining_kbd_macro = Qnil; | |
7934 | kb->Vlast_kbd_macro = Qnil; | |
7935 | kb->reference_count = 0; | |
7c97ffdc | 7936 | kb->Vsystem_key_alist = Qnil; |
142e6c73 | 7937 | kb->system_key_syms = Qnil; |
9ba47203 | 7938 | kb->Vdefault_minibuffer_frame = Qnil; |
6c6083a9 KH |
7939 | } |
7940 | ||
7941 | /* | |
c5fdd383 | 7942 | * Destroy the contents of a kboard object, but not the object itself. |
8e6208c5 | 7943 | * We use this just before deleting it, or if we're going to initialize |
6c6083a9 KH |
7944 | * it a second time. |
7945 | */ | |
e50b8090 | 7946 | static void |
c5fdd383 KH |
7947 | wipe_kboard (kb) |
7948 | KBOARD *kb; | |
6c6083a9 | 7949 | { |
c5fdd383 KH |
7950 | if (kb->kbd_macro_buffer) |
7951 | xfree (kb->kbd_macro_buffer); | |
6c6083a9 KH |
7952 | } |
7953 | ||
e50b8090 KH |
7954 | #ifdef MULTI_KBOARD |
7955 | void | |
7956 | delete_kboard (kb) | |
7957 | KBOARD *kb; | |
7958 | { | |
7959 | KBOARD **kbp; | |
7960 | for (kbp = &all_kboards; *kbp != kb; kbp = &(*kbp)->next_kboard) | |
7961 | if (*kbp == NULL) | |
7962 | abort (); | |
7963 | *kbp = kb->next_kboard; | |
7964 | wipe_kboard (kb); | |
7965 | xfree (kb); | |
7966 | } | |
7967 | #endif | |
7968 | ||
284f4730 JB |
7969 | init_keyboard () |
7970 | { | |
284f4730 JB |
7971 | /* This is correct before outermost invocation of the editor loop */ |
7972 | command_loop_level = -1; | |
7973 | immediate_quit = 0; | |
7974 | quit_char = Ctl ('g'); | |
24597608 | 7975 | Vunread_command_events = Qnil; |
86e5706b | 7976 | unread_command_char = -1; |
87dd9b9b | 7977 | EMACS_SET_SECS_USECS (timer_idleness_start_time, -1, -1); |
284f4730 | 7978 | total_keys = 0; |
9deb415a | 7979 | recent_keys_index = 0; |
beecf6a1 KH |
7980 | kbd_fetch_ptr = kbd_buffer; |
7981 | kbd_store_ptr = kbd_buffer; | |
7982 | kbd_buffer_frame_or_window | |
7983 | = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil); | |
2eb6bfbe | 7984 | #ifdef HAVE_MOUSE |
a9d77f1f | 7985 | do_mouse_tracking = Qnil; |
2eb6bfbe | 7986 | #endif |
284f4730 JB |
7987 | input_pending = 0; |
7988 | ||
4c52b668 KH |
7989 | /* This means that command_loop_1 won't try to select anything the first |
7990 | time through. */ | |
7991 | internal_last_event_frame = Qnil; | |
7992 | Vlast_event_frame = internal_last_event_frame; | |
4c52b668 | 7993 | |
c5fdd383 | 7994 | #ifdef MULTI_KBOARD |
aaca43a1 | 7995 | current_kboard = initial_kboard; |
6c6083a9 | 7996 | #endif |
aaca43a1 | 7997 | wipe_kboard (current_kboard); |
c5fdd383 | 7998 | init_kboard (current_kboard); |
07d2b8de | 7999 | |
beecf6a1 KH |
8000 | if (initialized) |
8001 | Ffillarray (kbd_buffer_frame_or_window, Qnil); | |
8002 | ||
8003 | kbd_buffer_frame_or_window | |
8004 | = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil); | |
7a80a6f6 | 8005 | if (!noninteractive && !read_socket_hook && NILP (Vwindow_system)) |
284f4730 JB |
8006 | { |
8007 | signal (SIGINT, interrupt_signal); | |
cb5df6ae | 8008 | #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) |
284f4730 JB |
8009 | /* For systems with SysV TERMIO, C-g is set up for both SIGINT and |
8010 | SIGQUIT and we can't tell which one it will give us. */ | |
8011 | signal (SIGQUIT, interrupt_signal); | |
8012 | #endif /* HAVE_TERMIO */ | |
7a80a6f6 | 8013 | } |
284f4730 JB |
8014 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ |
8015 | #ifdef SIGIO | |
7a80a6f6 RS |
8016 | if (!noninteractive) |
8017 | signal (SIGIO, input_available_signal); | |
8ea0a720 | 8018 | #endif /* SIGIO */ |
284f4730 JB |
8019 | |
8020 | /* Use interrupt input by default, if it works and noninterrupt input | |
8021 | has deficiencies. */ | |
8022 | ||
8023 | #ifdef INTERRUPT_INPUT | |
8024 | interrupt_input = 1; | |
8025 | #else | |
8026 | interrupt_input = 0; | |
8027 | #endif | |
8028 | ||
8029 | /* Our VMS input only works by interrupts, as of now. */ | |
8030 | #ifdef VMS | |
8031 | interrupt_input = 1; | |
8032 | #endif | |
8033 | ||
8034 | sigfree (); | |
8035 | dribble = 0; | |
8036 | ||
8037 | if (keyboard_init_hook) | |
8038 | (*keyboard_init_hook) (); | |
8039 | ||
8040 | #ifdef POLL_FOR_INPUT | |
8041 | poll_suppress_count = 1; | |
8042 | start_polling (); | |
8043 | #endif | |
8044 | } | |
8045 | ||
df0f2ba1 | 8046 | /* This type's only use is in syms_of_keyboard, to initialize the |
284f4730 JB |
8047 | event header symbols and put properties on them. */ |
8048 | struct event_head { | |
8049 | Lisp_Object *var; | |
8050 | char *name; | |
8051 | Lisp_Object *kind; | |
8052 | }; | |
8053 | ||
8054 | struct event_head head_table[] = { | |
7b4aedb9 | 8055 | &Qmouse_movement, "mouse-movement", &Qmouse_movement, |
3c370943 | 8056 | &Qscroll_bar_movement, "scroll-bar-movement", &Qmouse_movement, |
7b4aedb9 | 8057 | &Qswitch_frame, "switch-frame", &Qswitch_frame, |
bbdc2092 | 8058 | &Qdelete_frame, "delete-frame", &Qdelete_frame, |
af17bd2b KH |
8059 | &Qiconify_frame, "iconify-frame", &Qiconify_frame, |
8060 | &Qmake_frame_visible, "make-frame-visible", &Qmake_frame_visible, | |
284f4730 JB |
8061 | }; |
8062 | ||
8063 | syms_of_keyboard () | |
8064 | { | |
d925fb39 RS |
8065 | Qtimer_event_handler = intern ("timer-event-handler"); |
8066 | staticpro (&Qtimer_event_handler); | |
8067 | ||
2e894dab RS |
8068 | Qdisabled_command_hook = intern ("disabled-command-hook"); |
8069 | staticpro (&Qdisabled_command_hook); | |
8070 | ||
284f4730 JB |
8071 | Qself_insert_command = intern ("self-insert-command"); |
8072 | staticpro (&Qself_insert_command); | |
8073 | ||
8074 | Qforward_char = intern ("forward-char"); | |
8075 | staticpro (&Qforward_char); | |
8076 | ||
8077 | Qbackward_char = intern ("backward-char"); | |
8078 | staticpro (&Qbackward_char); | |
8079 | ||
8080 | Qdisabled = intern ("disabled"); | |
8081 | staticpro (&Qdisabled); | |
8082 | ||
e58aa385 RS |
8083 | Qundefined = intern ("undefined"); |
8084 | staticpro (&Qundefined); | |
8085 | ||
86e5706b RS |
8086 | Qpre_command_hook = intern ("pre-command-hook"); |
8087 | staticpro (&Qpre_command_hook); | |
8088 | ||
8089 | Qpost_command_hook = intern ("post-command-hook"); | |
8090 | staticpro (&Qpost_command_hook); | |
8091 | ||
59aadc81 RS |
8092 | Qpost_command_idle_hook = intern ("post-command-idle-hook"); |
8093 | staticpro (&Qpost_command_idle_hook); | |
8094 | ||
3ef14e46 RS |
8095 | Qdeferred_action_function = intern ("deferred-action-function"); |
8096 | staticpro (&Qdeferred_action_function); | |
8097 | ||
40932d1a RS |
8098 | Qcommand_hook_internal = intern ("command-hook-internal"); |
8099 | staticpro (&Qcommand_hook_internal); | |
8100 | ||
284f4730 JB |
8101 | Qfunction_key = intern ("function-key"); |
8102 | staticpro (&Qfunction_key); | |
13b5e56c | 8103 | Qmouse_click = intern ("mouse-click"); |
284f4730 | 8104 | staticpro (&Qmouse_click); |
07de30b9 GV |
8105 | #ifdef WINDOWSNT |
8106 | Qmouse_wheel = intern ("mouse-wheel"); | |
8107 | staticpro (&Qmouse_wheel); | |
8108 | #endif | |
284f4730 | 8109 | |
598a9fa7 JB |
8110 | Qmenu_enable = intern ("menu-enable"); |
8111 | staticpro (&Qmenu_enable); | |
8112 | ||
284f4730 JB |
8113 | Qmode_line = intern ("mode-line"); |
8114 | staticpro (&Qmode_line); | |
e5d77022 JB |
8115 | Qvertical_line = intern ("vertical-line"); |
8116 | staticpro (&Qvertical_line); | |
3c370943 JB |
8117 | Qvertical_scroll_bar = intern ("vertical-scroll-bar"); |
8118 | staticpro (&Qvertical_scroll_bar); | |
5ec75a55 RS |
8119 | Qmenu_bar = intern ("menu-bar"); |
8120 | staticpro (&Qmenu_bar); | |
4bb994d1 JB |
8121 | |
8122 | Qabove_handle = intern ("above-handle"); | |
8123 | staticpro (&Qabove_handle); | |
8124 | Qhandle = intern ("handle"); | |
8125 | staticpro (&Qhandle); | |
8126 | Qbelow_handle = intern ("below-handle"); | |
8127 | staticpro (&Qbelow_handle); | |
db08707d RS |
8128 | Qup = intern ("up"); |
8129 | staticpro (&Qup); | |
8130 | Qdown = intern ("down"); | |
8131 | staticpro (&Qdown); | |
284f4730 | 8132 | |
cd21b839 | 8133 | Qevent_kind = intern ("event-kind"); |
284f4730 | 8134 | staticpro (&Qevent_kind); |
88cb0656 JB |
8135 | Qevent_symbol_elements = intern ("event-symbol-elements"); |
8136 | staticpro (&Qevent_symbol_elements); | |
0a7f1fc0 JB |
8137 | Qevent_symbol_element_mask = intern ("event-symbol-element-mask"); |
8138 | staticpro (&Qevent_symbol_element_mask); | |
8139 | Qmodifier_cache = intern ("modifier-cache"); | |
8140 | staticpro (&Qmodifier_cache); | |
284f4730 | 8141 | |
48e416d4 RS |
8142 | Qrecompute_lucid_menubar = intern ("recompute-lucid-menubar"); |
8143 | staticpro (&Qrecompute_lucid_menubar); | |
8144 | Qactivate_menubar_hook = intern ("activate-menubar-hook"); | |
8145 | staticpro (&Qactivate_menubar_hook); | |
8146 | ||
f4eef8b4 RS |
8147 | Qpolling_period = intern ("polling-period"); |
8148 | staticpro (&Qpolling_period); | |
8149 | ||
284f4730 JB |
8150 | { |
8151 | struct event_head *p; | |
8152 | ||
8153 | for (p = head_table; | |
8154 | p < head_table + (sizeof (head_table) / sizeof (head_table[0])); | |
8155 | p++) | |
8156 | { | |
8157 | *p->var = intern (p->name); | |
8158 | staticpro (p->var); | |
8159 | Fput (*p->var, Qevent_kind, *p->kind); | |
88cb0656 | 8160 | Fput (*p->var, Qevent_symbol_elements, Fcons (*p->var, Qnil)); |
284f4730 JB |
8161 | } |
8162 | } | |
8163 | ||
7b4aedb9 JB |
8164 | button_down_location = Fmake_vector (make_number (NUM_MOUSE_BUTTONS), Qnil); |
8165 | staticpro (&button_down_location); | |
88cb0656 JB |
8166 | |
8167 | { | |
8168 | int i; | |
8169 | int len = sizeof (modifier_names) / sizeof (modifier_names[0]); | |
8170 | ||
8171 | modifier_symbols = Fmake_vector (make_number (len), Qnil); | |
8172 | for (i = 0; i < len; i++) | |
86e5706b RS |
8173 | if (modifier_names[i]) |
8174 | XVECTOR (modifier_symbols)->contents[i] = intern (modifier_names[i]); | |
88cb0656 JB |
8175 | staticpro (&modifier_symbols); |
8176 | } | |
8177 | ||
9deb415a JB |
8178 | recent_keys = Fmake_vector (make_number (NUM_RECENT_KEYS), Qnil); |
8179 | staticpro (&recent_keys); | |
8180 | ||
6569cc8d | 8181 | this_command_keys = Fmake_vector (make_number (40), Qnil); |
715d9345 | 8182 | staticpro (&this_command_keys); |
6569cc8d | 8183 | |
03b4122a BF |
8184 | Qextended_command_history = intern ("extended-command-history"); |
8185 | Fset (Qextended_command_history, Qnil); | |
8186 | staticpro (&Qextended_command_history); | |
8187 | ||
beecf6a1 KH |
8188 | kbd_buffer_frame_or_window |
8189 | = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil); | |
8190 | staticpro (&kbd_buffer_frame_or_window); | |
8191 | ||
24597608 RS |
8192 | accent_key_syms = Qnil; |
8193 | staticpro (&accent_key_syms); | |
8194 | ||
284f4730 JB |
8195 | func_key_syms = Qnil; |
8196 | staticpro (&func_key_syms); | |
8197 | ||
8198 | mouse_syms = Qnil; | |
8199 | staticpro (&mouse_syms); | |
8200 | ||
07de30b9 GV |
8201 | #ifdef WINDOWSNT |
8202 | mouse_wheel_syms = Qnil; | |
8203 | staticpro (&mouse_wheel_syms); | |
8204 | #endif | |
8205 | ||
cd21b839 JB |
8206 | unread_switch_frame = Qnil; |
8207 | staticpro (&unread_switch_frame); | |
8208 | ||
fe412364 EN |
8209 | internal_last_event_frame = Qnil; |
8210 | staticpro (&internal_last_event_frame); | |
8211 | ||
8212 | read_key_sequence_cmd = Qnil; | |
8213 | staticpro (&read_key_sequence_cmd); | |
8214 | ||
a1706c30 | 8215 | defsubr (&Sevent_convert_list); |
284f4730 JB |
8216 | defsubr (&Sread_key_sequence); |
8217 | defsubr (&Srecursive_edit); | |
2eb6bfbe | 8218 | #ifdef HAVE_MOUSE |
284f4730 | 8219 | defsubr (&Strack_mouse); |
2eb6bfbe | 8220 | #endif |
284f4730 JB |
8221 | defsubr (&Sinput_pending_p); |
8222 | defsubr (&Scommand_execute); | |
8223 | defsubr (&Srecent_keys); | |
8224 | defsubr (&Sthis_command_keys); | |
6321824f | 8225 | defsubr (&Sthis_single_command_keys); |
71918b75 | 8226 | defsubr (&Sreset_this_command_lengths); |
284f4730 JB |
8227 | defsubr (&Ssuspend_emacs); |
8228 | defsubr (&Sabort_recursive_edit); | |
8229 | defsubr (&Sexit_recursive_edit); | |
8230 | defsubr (&Srecursion_depth); | |
8231 | defsubr (&Stop_level); | |
8232 | defsubr (&Sdiscard_input); | |
8233 | defsubr (&Sopen_dribble_file); | |
8234 | defsubr (&Sset_input_mode); | |
80645119 | 8235 | defsubr (&Scurrent_input_mode); |
284f4730 JB |
8236 | defsubr (&Sexecute_extended_command); |
8237 | ||
284f4730 | 8238 | DEFVAR_LISP ("last-command-char", &last_command_char, |
86e5706b RS |
8239 | "Last input event that was part of a command."); |
8240 | ||
186cf719 | 8241 | DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char, |
86e5706b | 8242 | "Last input event that was part of a command."); |
284f4730 | 8243 | |
7d6de002 | 8244 | DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event, |
86e5706b | 8245 | "Last input event in a command, except for mouse menu events.\n\ |
7d6de002 RS |
8246 | Mouse menus give back keys that don't look like mouse events;\n\ |
8247 | this variable holds the actual mouse event that led to the menu,\n\ | |
8248 | so that you can determine whether the command was run by mouse or not."); | |
8249 | ||
284f4730 | 8250 | DEFVAR_LISP ("last-input-char", &last_input_char, |
86e5706b RS |
8251 | "Last input event."); |
8252 | ||
186cf719 | 8253 | DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char, |
86e5706b | 8254 | "Last input event."); |
284f4730 | 8255 | |
24597608 | 8256 | DEFVAR_LISP ("unread-command-events", &Vunread_command_events, |
1c07d0a6 | 8257 | "List of objects to be read as next command input events."); |
284f4730 | 8258 | |
86e5706b RS |
8259 | DEFVAR_INT ("unread-command-char", &unread_command_char, |
8260 | "If not -1, an object to be read as next command input event."); | |
8261 | ||
284f4730 JB |
8262 | DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char, |
8263 | "Meta-prefix character code. Meta-foo as command input\n\ | |
8264 | turns into this character followed by foo."); | |
18cd2eeb | 8265 | XSETINT (meta_prefix_char, 033); |
284f4730 | 8266 | |
6c7178b9 | 8267 | DEFVAR_KBOARD ("last-command", Vlast_command, |
284f4730 JB |
8268 | "The last command executed. Normally a symbol with a function definition,\n\ |
8269 | but can be whatever was found in the keymap, or whatever the variable\n\ | |
18f29056 RS |
8270 | `this-command' was set to by that command.\n\ |
8271 | \n\ | |
8272 | The value `mode-exit' is special; it means that the previous command\n\ | |
8273 | read an event that told it to exit, and it did so and unread that event.\n\ | |
8274 | In other words, the present command is the event that made the previous\n\ | |
8275 | command exit.\n\ | |
8276 | \n\ | |
8277 | The value `kill-region' is special; it means that the previous command\n\ | |
8278 | was a kill command."); | |
284f4730 JB |
8279 | |
8280 | DEFVAR_LISP ("this-command", &this_command, | |
8281 | "The command now being executed.\n\ | |
8282 | The command can set this variable; whatever is put here\n\ | |
8283 | will be in `last-command' during the following command."); | |
8284 | this_command = Qnil; | |
8285 | ||
8286 | DEFVAR_INT ("auto-save-interval", &auto_save_interval, | |
8287 | "*Number of keyboard input characters between auto-saves.\n\ | |
8288 | Zero means disable autosaving due to number of characters typed."); | |
8289 | auto_save_interval = 300; | |
8290 | ||
8291 | DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout, | |
8292 | "*Number of seconds idle time before auto-save.\n\ | |
06ef7355 RS |
8293 | Zero or nil means disable auto-saving due to idleness.\n\ |
8294 | After auto-saving due to this many seconds of idle time,\n\ | |
84447c71 | 8295 | Emacs also does a garbage collection if that seems to be warranted."); |
bb9e9bed | 8296 | XSETFASTINT (Vauto_save_timeout, 30); |
284f4730 JB |
8297 | |
8298 | DEFVAR_INT ("echo-keystrokes", &echo_keystrokes, | |
8299 | "*Nonzero means echo unfinished commands after this many seconds of pause."); | |
8300 | echo_keystrokes = 1; | |
8301 | ||
8302 | DEFVAR_INT ("polling-period", &polling_period, | |
8303 | "*Interval between polling for input during Lisp execution.\n\ | |
8304 | The reason for polling is to make C-g work to stop a running program.\n\ | |
8305 | Polling is needed only when using X windows and SIGIO does not work.\n\ | |
8306 | Polling is automatically disabled in all other cases."); | |
8307 | polling_period = 2; | |
df0f2ba1 | 8308 | |
564dc952 | 8309 | DEFVAR_LISP ("double-click-time", &Vdouble_click_time, |
fbcd35bd | 8310 | "*Maximum time between mouse clicks to make a double-click.\n\ |
564dc952 JB |
8311 | Measured in milliseconds. nil means disable double-click recognition;\n\ |
8312 | t means double-clicks have no time limit and are detected\n\ | |
fbcd35bd | 8313 | by position only."); |
aab06933 | 8314 | Vdouble_click_time = make_number (500); |
fbcd35bd | 8315 | |
03361bcc RS |
8316 | DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus, |
8317 | "*Non-nil means inhibit local map menu bar menus."); | |
8318 | inhibit_local_menu_bar_menus = 0; | |
8319 | ||
284f4730 | 8320 | DEFVAR_INT ("num-input-keys", &num_input_keys, |
c43b1734 | 8321 | "Number of complete key sequences read as input so far.\n\ |
58ce35fb KH |
8322 | This includes key sequences read from keyboard macros.\n\ |
8323 | The number is effectively the number of interactive command invocations."); | |
284f4730 JB |
8324 | num_input_keys = 0; |
8325 | ||
c43b1734 RS |
8326 | DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events, |
8327 | "Number of input events read from the keyboard so far.\n\ | |
8328 | This does not include events generated by keyboard macros."); | |
8329 | num_nonmacro_input_events = 0; | |
fa90970d | 8330 | |
4c52b668 KH |
8331 | DEFVAR_LISP ("last-event-frame", &Vlast_event_frame, |
8332 | "The frame in which the most recently read event occurred.\n\ | |
8333 | If the last event came from a keyboard macro, this is set to `macro'."); | |
8334 | Vlast_event_frame = Qnil; | |
8335 | ||
fa90970d RS |
8336 | /* This variable is set up in sysdep.c. */ |
8337 | DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char, | |
8338 | "The ERASE character as set by the user with stty."); | |
8339 | ||
7e85b935 | 8340 | DEFVAR_LISP ("help-char", &Vhelp_char, |
284f4730 JB |
8341 | "Character to recognize as meaning Help.\n\ |
8342 | When it is read, do `(eval help-form)', and display result if it's a string.\n\ | |
8343 | If the value of `help-form' is nil, this char can be read normally."); | |
18cd2eeb | 8344 | XSETINT (Vhelp_char, Ctl ('H')); |
284f4730 | 8345 | |
ecb7cb34 KH |
8346 | DEFVAR_LISP ("help-event-list", &Vhelp_event_list, |
8347 | "List of input events to recognize as meaning Help.\n\ | |
8348 | These work just like the value of `help-char' (see that)."); | |
8349 | Vhelp_event_list = Qnil; | |
8350 | ||
284f4730 | 8351 | DEFVAR_LISP ("help-form", &Vhelp_form, |
7e85b935 | 8352 | "Form to execute when character `help-char' is read.\n\ |
284f4730 JB |
8353 | If the form returns a string, that string is displayed.\n\ |
8354 | If `help-form' is nil, the help char is not recognized."); | |
8355 | Vhelp_form = Qnil; | |
8356 | ||
7e85b935 RS |
8357 | DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command, |
8358 | "Command to run when `help-char' character follows a prefix key.\n\ | |
8359 | This command is used only when there is no actual binding\n\ | |
8360 | for that character after that prefix key."); | |
8361 | Vprefix_help_command = Qnil; | |
8362 | ||
284f4730 JB |
8363 | DEFVAR_LISP ("top-level", &Vtop_level, |
8364 | "Form to evaluate when Emacs starts up.\n\ | |
8365 | Useful to set before you dump a modified Emacs."); | |
8366 | Vtop_level = Qnil; | |
8367 | ||
8368 | DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table, | |
f9414d62 | 8369 | "Translate table for keyboard input, or nil.\n\ |
284f4730 | 8370 | Each character is looked up in this string and the contents used instead.\n\ |
f9414d62 RS |
8371 | The value may be a string, a vector, or a char-table.\n\ |
8372 | If it is a string or vector of length N,\n\ | |
8373 | character codes N and up are untranslated.\n\ | |
8374 | In a vector or a char-table, an element which is nil means \"no translation\"."); | |
284f4730 JB |
8375 | Vkeyboard_translate_table = Qnil; |
8376 | ||
8026024c KH |
8377 | DEFVAR_BOOL ("cannot-suspend", &cannot_suspend, |
8378 | "Non-nil means to always spawn a subshell instead of suspending,\n\ | |
8379 | even if the operating system has support for stopping a process."); | |
8380 | cannot_suspend = 0; | |
8381 | ||
284f4730 | 8382 | DEFVAR_BOOL ("menu-prompting", &menu_prompting, |
7d6de002 | 8383 | "Non-nil means prompt with menus when appropriate.\n\ |
284f4730 | 8384 | This is done when reading from a keymap that has a prompt string,\n\ |
7d6de002 RS |
8385 | for elements that have prompt strings.\n\ |
8386 | The menu is displayed on the screen\n\ | |
8387 | if X menus were enabled at configuration\n\ | |
8388 | time and the previous event was a mouse click prefix key.\n\ | |
8389 | Otherwise, menu prompting uses the echo area."); | |
284f4730 JB |
8390 | menu_prompting = 1; |
8391 | ||
8392 | DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char, | |
8393 | "Character to see next line of menu prompt.\n\ | |
8394 | Type this character while in a menu prompt to rotate around the lines of it."); | |
18cd2eeb | 8395 | XSETINT (menu_prompt_more_char, ' '); |
9fa4395d RS |
8396 | |
8397 | DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers, | |
8398 | "A mask of additional modifier keys to use with every keyboard character.\n\ | |
ad163903 JB |
8399 | Emacs applies the modifiers of the character stored here to each keyboard\n\ |
8400 | character it reads. For example, after evaluating the expression\n\ | |
9d9f56dd | 8401 | (setq extra-keyboard-modifiers ?\\C-x)\n\ |
80645119 JB |
8402 | all input characters will have the control modifier applied to them.\n\ |
8403 | \n\ | |
9d9f56dd | 8404 | Note that the character ?\\C-@, equivalent to the integer zero, does\n\ |
80645119 | 8405 | not count as a control character; rather, it counts as a character\n\ |
27203ead | 8406 | with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\ |
80645119 | 8407 | cancels any modification."); |
9fa4395d | 8408 | extra_keyboard_modifiers = 0; |
86e5706b RS |
8409 | |
8410 | DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark, | |
8411 | "If an editing command sets this to t, deactivate the mark afterward.\n\ | |
8412 | The command loop sets this to nil before each command,\n\ | |
8413 | and tests the value when the command returns.\n\ | |
8414 | Buffer modification stores t in this variable."); | |
8415 | Vdeactivate_mark = Qnil; | |
8416 | ||
b0f2a7bf KH |
8417 | DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal, |
8418 | "Temporary storage of pre-command-hook or post-command-hook."); | |
8419 | Vcommand_hook_internal = Qnil; | |
8420 | ||
86e5706b | 8421 | DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook, |
a1fd42c0 | 8422 | "Normal hook run before each command is executed.\n\ |
59aadc81 | 8423 | Errors running the hook are caught and ignored."); |
86e5706b RS |
8424 | Vpre_command_hook = Qnil; |
8425 | ||
8426 | DEFVAR_LISP ("post-command-hook", &Vpost_command_hook, | |
a1fd42c0 | 8427 | "Normal hook run after each command is executed.\n\ |
59aadc81 | 8428 | Errors running the hook are caught and ignored."); |
86e5706b | 8429 | Vpost_command_hook = Qnil; |
48e416d4 | 8430 | |
59aadc81 RS |
8431 | DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook, |
8432 | "Normal hook run after each command is executed, if idle.\n\ | |
d4d62e8d RS |
8433 | Errors running the hook are caught and ignored.\n\ |
8434 | This feature is obsolete; use idle timers instead. See `etc/NEWS'."); | |
59aadc81 RS |
8435 | Vpost_command_idle_hook = Qnil; |
8436 | ||
8437 | DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay, | |
7051b69b | 8438 | "Delay time before running `post-command-idle-hook'.\n\ |
59aadc81 RS |
8439 | This is measured in microseconds."); |
8440 | post_command_idle_delay = 100000; | |
8441 | ||
cdb9d665 RS |
8442 | #if 0 |
8443 | DEFVAR_LISP ("echo-area-clear-hook", ..., | |
8444 | "Normal hook run when clearing the echo area."); | |
8445 | #endif | |
8446 | Qecho_area_clear_hook = intern ("echo-area-clear-hook"); | |
8447 | XSYMBOL (Qecho_area_clear_hook)->value = Qnil; | |
8448 | ||
48e416d4 RS |
8449 | DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag, |
8450 | "t means menu bar, specified Lucid style, needs to be recomputed."); | |
8451 | Vlucid_menu_bar_dirty_flag = Qnil; | |
a73c5e29 | 8452 | |
9f9c0e27 RS |
8453 | DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items, |
8454 | "List of menu bar items to move to the end of the menu bar.\n\ | |
a612e298 | 8455 | The elements of the list are event types that may have menu bar bindings."); |
9f9c0e27 | 8456 | Vmenu_bar_final_items = Qnil; |
e9bf89a0 | 8457 | |
217258d5 KH |
8458 | DEFVAR_KBOARD ("overriding-terminal-local-map", |
8459 | Voverriding_terminal_local_map, | |
779b34df | 8460 | "Per-terminal keymap that overrides all other local keymaps.\n\ |
217258d5 | 8461 | If this variable is non-nil, it is used as a keymap instead of the\n\ |
779b34df RS |
8462 | buffer's local map, and the minor mode keymaps and text property keymaps.\n\ |
8463 | This variable is intended to let commands such as `universal-argumemnt'\n\ | |
8464 | set up a different keymap for reading the next command."); | |
217258d5 | 8465 | |
9dd3131c RS |
8466 | DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map, |
8467 | "Keymap that overrides all other local keymaps.\n\ | |
8468 | If this variable is non-nil, it is used as a keymap instead of the\n\ | |
8469 | buffer's local map, and the minor mode keymaps and text property keymaps."); | |
8470 | Voverriding_local_map = Qnil; | |
8471 | ||
d0a49716 RS |
8472 | DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag, |
8473 | "Non-nil means `overriding-local-map' applies to the menu bar.\n\ | |
8474 | Otherwise, the menu bar continues to reflect the buffer's local map\n\ | |
8475 | and the minor mode maps regardless of `overriding-local-map'."); | |
8476 | Voverriding_local_map_menu_flag = Qnil; | |
8477 | ||
7f07d5ca RS |
8478 | DEFVAR_LISP ("special-event-map", &Vspecial_event_map, |
8479 | "Keymap defining bindings for special events to execute at low level."); | |
8480 | Vspecial_event_map = Fcons (intern ("keymap"), Qnil); | |
8481 | ||
71edead1 | 8482 | DEFVAR_LISP ("track-mouse", &do_mouse_tracking, |
a53c7666 | 8483 | "*Non-nil means generate motion events for mouse motion."); |
80e4aa30 | 8484 | |
7c97ffdc | 8485 | DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist, |
270a208f | 8486 | "Alist of system-specific X windows key symbols.\n\ |
80e4aa30 | 8487 | Each element should have the form (N . SYMBOL) where N is the\n\ |
270a208f | 8488 | numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\ |
80e4aa30 | 8489 | and SYMBOL is its name."); |
8a792f3a RS |
8490 | |
8491 | DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list, | |
8492 | "List of deferred actions to be performed at a later time.\n\ | |
8493 | The precise format isn't relevant here; we just check whether it is nil."); | |
8494 | Vdeferred_action_list = Qnil; | |
8495 | ||
8496 | DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function, | |
8497 | "Function to call to handle deferred actions, after each command.\n\ | |
8498 | This function is called with no arguments after each command\n\ | |
8499 | whenever `deferred-action-list' is non-nil."); | |
8500 | Vdeferred_action_function = Qnil; | |
6526ab49 RS |
8501 | |
8502 | DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings, | |
8503 | "Non-nil means show the equivalent key-binding when M-x command has one.\n\ | |
8504 | The value can be a length of time to show the message for.\n\ | |
8505 | If the value is non-nil and not a number, we wait 2 seconds."); | |
8506 | Vsuggest_key_bindings = Qt; | |
8bb1c042 | 8507 | |
c04cbc3b | 8508 | DEFVAR_LISP ("timer-list", &Vtimer_list, |
d9d4c147 | 8509 | "List of active absolute time timers in order of increasing time"); |
c04cbc3b | 8510 | Vtimer_list = Qnil; |
d9d4c147 KH |
8511 | |
8512 | DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list, | |
8513 | "List of active idle-time timers in order of increasing time"); | |
8514 | Vtimer_idle_list = Qnil; | |
284f4730 JB |
8515 | } |
8516 | ||
8517 | keys_of_keyboard () | |
8518 | { | |
8519 | initial_define_key (global_map, Ctl ('Z'), "suspend-emacs"); | |
8520 | initial_define_key (control_x_map, Ctl ('Z'), "suspend-emacs"); | |
8521 | initial_define_key (meta_map, Ctl ('C'), "exit-recursive-edit"); | |
8522 | initial_define_key (global_map, Ctl (']'), "abort-recursive-edit"); | |
8523 | initial_define_key (meta_map, 'x', "execute-extended-command"); | |
7f07d5ca RS |
8524 | |
8525 | initial_define_lispy_key (Vspecial_event_map, "delete-frame", | |
8526 | "handle-delete-frame"); | |
8527 | initial_define_lispy_key (Vspecial_event_map, "iconify-frame", | |
8528 | "ignore-event"); | |
8529 | initial_define_lispy_key (Vspecial_event_map, "make-frame-visible", | |
8530 | "ignore-event"); | |
284f4730 | 8531 | } |