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" |
e39da3d7 | 39 | #include "syntax.h" |
497ba7a1 | 40 | #include "intervals.h" |
9ac0d9e0 | 41 | #include "blockinput.h" |
e8886a1d | 42 | #include "puresize.h" |
284f4730 JB |
43 | #include <setjmp.h> |
44 | #include <errno.h> | |
45 | ||
80e4aa30 RS |
46 | #ifdef MSDOS |
47 | #include "msdos.h" | |
48 | #include <time.h> | |
49 | #else /* not MSDOS */ | |
284f4730 JB |
50 | #ifndef VMS |
51 | #include <sys/ioctl.h> | |
284f4730 | 52 | #endif |
80e4aa30 | 53 | #endif /* not MSDOS */ |
284f4730 | 54 | |
52baf19e | 55 | #include "syssignal.h" |
6ef5b54f | 56 | #include "systty.h" |
52baf19e | 57 | |
c5e3b6c5 RS |
58 | /* This is to get the definitions of the XK_ symbols. */ |
59 | #ifdef HAVE_X_WINDOWS | |
60 | #include "xterm.h" | |
61 | #endif | |
62 | ||
e98a93eb GV |
63 | #ifdef HAVE_NTGUI |
64 | #include "w32term.h" | |
65 | #endif /* HAVE_NTGUI */ | |
66 | ||
0c2611c5 RS |
67 | /* Include systime.h after xterm.h to avoid double inclusion of time.h. */ |
68 | #include "systime.h" | |
69 | ||
52baf19e JB |
70 | extern int errno; |
71 | ||
9ac0d9e0 JB |
72 | /* Variables for blockinput.h: */ |
73 | ||
74 | /* Non-zero if interrupt input is blocked right now. */ | |
63927c41 | 75 | int interrupt_input_blocked; |
9ac0d9e0 JB |
76 | |
77 | /* Nonzero means an input interrupt has arrived | |
78 | during the current critical section. */ | |
63927c41 | 79 | int interrupt_input_pending; |
9ac0d9e0 JB |
80 | |
81 | ||
437f6112 RS |
82 | /* File descriptor to use for input. */ |
83 | extern int input_fd; | |
284f4730 | 84 | |
e98a93eb | 85 | #ifdef HAVE_WINDOW_SYSTEM |
284f4730 | 86 | /* Make all keyboard buffers much bigger when using X windows. */ |
f019cded RS |
87 | #ifdef macintosh |
88 | /* But not too big (local data > 32K error) if on macintosh */ | |
89 | #define KBD_BUFFER_SIZE 512 | |
90 | #else | |
284f4730 | 91 | #define KBD_BUFFER_SIZE 4096 |
f019cded | 92 | #endif |
284f4730 JB |
93 | #else /* No X-windows, character input */ |
94 | #define KBD_BUFFER_SIZE 256 | |
95 | #endif /* No X-windows */ | |
96 | ||
97 | /* Following definition copied from eval.c */ | |
98 | ||
99 | struct backtrace | |
100 | { | |
101 | struct backtrace *next; | |
102 | Lisp_Object *function; | |
103 | Lisp_Object *args; /* Points to vector of args. */ | |
104 | int nargs; /* length of vector. If nargs is UNEVALLED, | |
105 | args points to slot holding list of | |
106 | unevalled args */ | |
107 | char evalargs; | |
108 | }; | |
109 | ||
c5fdd383 KH |
110 | #ifdef MULTI_KBOARD |
111 | KBOARD *initial_kboard; | |
112 | KBOARD *current_kboard; | |
113 | KBOARD *all_kboards; | |
1e8bd3da | 114 | int single_kboard; |
6c6083a9 | 115 | #else |
c5fdd383 | 116 | KBOARD the_only_kboard; |
6c6083a9 | 117 | #endif |
612b78ef | 118 | |
284f4730 JB |
119 | /* Non-nil disable property on a command means |
120 | do not execute it; call disabled-command-hook's value instead. */ | |
2e894dab | 121 | Lisp_Object Qdisabled, Qdisabled_command_hook; |
284f4730 JB |
122 | |
123 | #define NUM_RECENT_KEYS (100) | |
124 | int recent_keys_index; /* Index for storing next element into recent_keys */ | |
125 | int total_keys; /* Total number of elements stored into recent_keys */ | |
5160df46 | 126 | Lisp_Object recent_keys; /* A vector, holding the last 100 keystrokes */ |
284f4730 | 127 | |
6569cc8d JB |
128 | /* Vector holding the key sequence that invoked the current command. |
129 | It is reused for each command, and it may be longer than the current | |
130 | sequence; this_command_key_count indicates how many elements | |
131 | actually mean something. | |
132 | It's easier to staticpro a single Lisp_Object than an array. */ | |
133 | Lisp_Object this_command_keys; | |
134 | int this_command_key_count; | |
284f4730 | 135 | |
7d18f9ae RS |
136 | /* This vector is used as a buffer to record the events that were actually read |
137 | by read_key_sequence. */ | |
138 | Lisp_Object raw_keybuf; | |
139 | int raw_keybuf_count; | |
140 | ||
141 | #define GROW_RAW_KEYBUF \ | |
142 | if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \ | |
143 | { \ | |
144 | int newsize = 2 * XVECTOR (raw_keybuf)->size; \ | |
145 | Lisp_Object new; \ | |
146 | new = Fmake_vector (make_number (newsize), Qnil); \ | |
147 | bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \ | |
148 | raw_keybuf_count * sizeof (Lisp_Object)); \ | |
149 | raw_keybuf = new; \ | |
150 | } | |
151 | ||
6321824f RS |
152 | /* Number of elements of this_command_keys |
153 | that precede this key sequence. */ | |
154 | int this_single_command_key_start; | |
155 | ||
71918b75 RS |
156 | /* Record values of this_command_key_count and echo_length () |
157 | before this command was read. */ | |
158 | static int before_command_key_count; | |
159 | static int before_command_echo_length; | |
160 | /* Values of before_command_key_count and before_command_echo_length | |
161 | saved by reset-this-command-lengths. */ | |
162 | static int before_command_key_count_1; | |
163 | static int before_command_echo_length_1; | |
164 | /* Flag set by reset-this-command-lengths, | |
165 | saying to reset the lengths when add_command_key is called. */ | |
166 | static int before_command_restore_flag; | |
167 | ||
284f4730 JB |
168 | extern int minbuf_level; |
169 | ||
a59b172a RS |
170 | extern int message_enable_multibyte; |
171 | ||
284f4730 JB |
172 | extern struct backtrace *backtrace_list; |
173 | ||
7ee32cda GM |
174 | /* If non-nil, the function that implements the display of help. |
175 | It's called with one argument, the help string to display. */ | |
176 | ||
177 | Lisp_Object Vshow_help_function; | |
178 | ||
284f4730 JB |
179 | /* Nonzero means do menu prompting. */ |
180 | static int menu_prompting; | |
181 | ||
182 | /* Character to see next line of menu prompt. */ | |
183 | static Lisp_Object menu_prompt_more_char; | |
184 | ||
185 | /* For longjmp to where kbd input is being done. */ | |
186 | static jmp_buf getcjmp; | |
187 | ||
188 | /* True while doing kbd input. */ | |
189 | int waiting_for_input; | |
190 | ||
191 | /* True while displaying for echoing. Delays C-g throwing. */ | |
985f9f66 | 192 | |
284f4730 JB |
193 | static int echoing; |
194 | ||
985f9f66 GM |
195 | /* Non-null means we can start echoing at the next input pause even |
196 | though there is something in the echo area. */ | |
197 | ||
198 | static struct kboard *ok_to_echo_at_next_pause; | |
199 | ||
200 | /* The kboard currently echoing, or null for none. Set in echo_now to | |
201 | the kboard echoing. Reset to 0 in cancel_echoing. If non-null, | |
202 | and a current echo area message exists, we know that it comes from | |
203 | echoing. */ | |
204 | ||
205 | static struct kboard *echo_kboard; | |
1fc93d49 | 206 | |
03361bcc RS |
207 | /* Nonzero means disregard local maps for the menu bar. */ |
208 | static int inhibit_local_menu_bar_menus; | |
209 | ||
80e4aa30 | 210 | /* Nonzero means C-g should cause immediate error-signal. */ |
284f4730 JB |
211 | int immediate_quit; |
212 | ||
fa90970d RS |
213 | /* The user's ERASE setting. */ |
214 | Lisp_Object Vtty_erase_char; | |
215 | ||
284f4730 | 216 | /* Character to recognize as the help char. */ |
7e85b935 | 217 | Lisp_Object Vhelp_char; |
284f4730 | 218 | |
ecb7cb34 KH |
219 | /* List of other event types to recognize as meaning "help". */ |
220 | Lisp_Object Vhelp_event_list; | |
221 | ||
284f4730 JB |
222 | /* Form to execute when help char is typed. */ |
223 | Lisp_Object Vhelp_form; | |
224 | ||
7e85b935 RS |
225 | /* Command to run when the help character follows a prefix key. */ |
226 | Lisp_Object Vprefix_help_command; | |
227 | ||
9f9c0e27 RS |
228 | /* List of items that should move to the end of the menu bar. */ |
229 | Lisp_Object Vmenu_bar_final_items; | |
a73c5e29 | 230 | |
6526ab49 RS |
231 | /* Non-nil means show the equivalent key-binding for |
232 | any M-x command that has one. | |
233 | The value can be a length of time to show the message for. | |
234 | If the value is non-nil and not a number, we wait 2 seconds. */ | |
235 | Lisp_Object Vsuggest_key_bindings; | |
236 | ||
284f4730 JB |
237 | /* Character that causes a quit. Normally C-g. |
238 | ||
239 | If we are running on an ordinary terminal, this must be an ordinary | |
240 | ASCII char, since we want to make it our interrupt character. | |
241 | ||
242 | If we are not running on an ordinary terminal, it still needs to be | |
243 | an ordinary ASCII char. This character needs to be recognized in | |
244 | the input interrupt handler. At this point, the keystroke is | |
245 | represented as a struct input_event, while the desired quit | |
246 | character is specified as a lispy event. The mapping from struct | |
247 | input_events to lispy events cannot run in an interrupt handler, | |
248 | and the reverse mapping is difficult for anything but ASCII | |
249 | keystrokes. | |
250 | ||
251 | FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an | |
252 | ASCII character. */ | |
253 | int quit_char; | |
254 | ||
255 | extern Lisp_Object current_global_map; | |
256 | extern int minibuf_level; | |
257 | ||
9dd3131c RS |
258 | /* If non-nil, this is a map that overrides all other local maps. */ |
259 | Lisp_Object Voverriding_local_map; | |
260 | ||
d0a49716 RS |
261 | /* If non-nil, Voverriding_local_map applies to the menu bar. */ |
262 | Lisp_Object Voverriding_local_map_menu_flag; | |
263 | ||
7f07d5ca RS |
264 | /* Keymap that defines special misc events that should |
265 | be processed immediately at a low level. */ | |
266 | Lisp_Object Vspecial_event_map; | |
267 | ||
284f4730 JB |
268 | /* Current depth in recursive edits. */ |
269 | int command_loop_level; | |
270 | ||
271 | /* Total number of times command_loop has read a key sequence. */ | |
272 | int num_input_keys; | |
273 | ||
274 | /* Last input character read as a command. */ | |
275 | Lisp_Object last_command_char; | |
276 | ||
7d6de002 RS |
277 | /* Last input character read as a command, not counting menus |
278 | reached by the mouse. */ | |
279 | Lisp_Object last_nonmenu_event; | |
280 | ||
284f4730 JB |
281 | /* Last input character read for any purpose. */ |
282 | Lisp_Object last_input_char; | |
283 | ||
dbc4e1c1 | 284 | /* If not Qnil, a list of objects to be read as subsequent command input. */ |
24597608 | 285 | Lisp_Object Vunread_command_events; |
284f4730 | 286 | |
7d18f9ae RS |
287 | /* If not Qnil, a list of objects to be read as subsequent command input |
288 | including input method processing. */ | |
289 | Lisp_Object Vunread_input_method_events; | |
290 | ||
291 | /* If not Qnil, a list of objects to be read as subsequent command input | |
292 | but NOT including input method processing. */ | |
293 | Lisp_Object Vunread_post_input_method_events; | |
294 | ||
86e5706b RS |
295 | /* If not -1, an event to be read as subsequent command input. */ |
296 | int unread_command_char; | |
297 | ||
cd21b839 JB |
298 | /* If not Qnil, this is a switch-frame event which we decided to put |
299 | off until the end of a key sequence. This should be read as the | |
dbc4e1c1 | 300 | next command input, after any unread_command_events. |
8f805655 JB |
301 | |
302 | read_key_sequence uses this to delay switch-frame events until the | |
303 | end of the key sequence; Fread_char uses it to put off switch-frame | |
304 | events until a non-ASCII event is acceptable as input. */ | |
305 | Lisp_Object unread_switch_frame; | |
cd21b839 | 306 | |
9fa4395d RS |
307 | /* A mask of extra modifier bits to put into every keyboard char. */ |
308 | int extra_keyboard_modifiers; | |
309 | ||
284f4730 JB |
310 | /* Char to use as prefix when a meta character is typed in. |
311 | This is bound on entry to minibuffer in case ESC is changed there. */ | |
312 | ||
313 | Lisp_Object meta_prefix_char; | |
314 | ||
315 | /* Last size recorded for a current buffer which is not a minibuffer. */ | |
316 | static int last_non_minibuf_size; | |
317 | ||
06ef7355 | 318 | /* Number of idle seconds before an auto-save and garbage collection. */ |
284f4730 JB |
319 | static Lisp_Object Vauto_save_timeout; |
320 | ||
321 | /* Total number of times read_char has returned. */ | |
4abfba1f | 322 | int num_input_events; |
284f4730 | 323 | |
51172b6d | 324 | /* Total number of times read_char has returned, outside of macros. */ |
c43b1734 | 325 | int num_nonmacro_input_events; |
51172b6d | 326 | |
284f4730 JB |
327 | /* Auto-save automatically when this many characters have been typed |
328 | since the last time. */ | |
329 | ||
330 | static int auto_save_interval; | |
331 | ||
c43b1734 | 332 | /* Value of num_nonmacro_input_events as of last auto save. */ |
284f4730 JB |
333 | |
334 | int last_auto_save; | |
335 | ||
284f4730 | 336 | /* The command being executed by the command loop. |
6c7178b9 KH |
337 | Commands may set this, and the value set will be copied into |
338 | current_kboard->Vlast_command instead of the actual command. */ | |
d5eecefb RS |
339 | Lisp_Object Vthis_command; |
340 | ||
341 | /* This is like Vthis_command, except that commands never set it. */ | |
342 | Lisp_Object real_this_command; | |
284f4730 | 343 | |
b453f72e KH |
344 | /* The value of point when the last command was executed. */ |
345 | int last_point_position; | |
346 | ||
047688cb RS |
347 | /* The buffer that was current when the last command was started. */ |
348 | Lisp_Object last_point_position_buffer; | |
349 | ||
4c52b668 KH |
350 | /* The frame in which the last input event occurred, or Qmacro if the |
351 | last event came from a macro. We use this to determine when to | |
352 | generate switch-frame events. This may be cleared by functions | |
353 | like Fselect_frame, to make sure that a switch-frame event is | |
354 | generated by the next character. */ | |
355 | Lisp_Object internal_last_event_frame; | |
4c52b668 KH |
356 | |
357 | /* A user-visible version of the above, intended to allow users to | |
358 | figure out where the last event came from, if the event doesn't | |
359 | carry that information itself (i.e. if it was a character). */ | |
360 | Lisp_Object Vlast_event_frame; | |
361 | ||
1113d9db JB |
362 | /* The timestamp of the last input event we received from the X server. |
363 | X Windows wants this for selection ownership. */ | |
284f4730 JB |
364 | unsigned long last_event_timestamp; |
365 | ||
366 | Lisp_Object Qself_insert_command; | |
367 | Lisp_Object Qforward_char; | |
368 | Lisp_Object Qbackward_char; | |
e58aa385 | 369 | Lisp_Object Qundefined; |
d925fb39 | 370 | Lisp_Object Qtimer_event_handler; |
284f4730 JB |
371 | |
372 | /* read_key_sequence stores here the command definition of the | |
373 | key sequence that it reads. */ | |
374 | Lisp_Object read_key_sequence_cmd; | |
375 | ||
376 | /* Form to evaluate (if non-nil) when Emacs is started. */ | |
377 | Lisp_Object Vtop_level; | |
378 | ||
379 | /* User-supplied string to translate input characters through. */ | |
380 | Lisp_Object Vkeyboard_translate_table; | |
381 | ||
382 | /* Keymap mapping ASCII function key sequences onto their preferred forms. */ | |
383 | extern Lisp_Object Vfunction_key_map; | |
384 | ||
e0301c07 RS |
385 | /* Another keymap that maps key sequences into key sequences. |
386 | This one takes precedence over ordinary definitions. */ | |
387 | extern Lisp_Object Vkey_translation_map; | |
a612e298 | 388 | |
7d18f9ae RS |
389 | /* If non-nil, this implements the current input method. */ |
390 | Lisp_Object Vinput_method_function; | |
391 | Lisp_Object Qinput_method_function; | |
392 | ||
d5eecefb RS |
393 | /* When we call Vinput_method_function, |
394 | this holds the echo area message that was just erased. */ | |
395 | Lisp_Object Vinput_method_previous_message; | |
396 | ||
86e5706b RS |
397 | /* Non-nil means deactivate the mark at end of this command. */ |
398 | Lisp_Object Vdeactivate_mark; | |
399 | ||
48e416d4 RS |
400 | /* Menu bar specified in Lucid Emacs fashion. */ |
401 | ||
402 | Lisp_Object Vlucid_menu_bar_dirty_flag; | |
403 | Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook; | |
404 | ||
cdb9d665 RS |
405 | Lisp_Object Qecho_area_clear_hook; |
406 | ||
86e5706b | 407 | /* Hooks to run before and after each command. */ |
59aadc81 RS |
408 | Lisp_Object Qpre_command_hook, Vpre_command_hook; |
409 | Lisp_Object Qpost_command_hook, Vpost_command_hook; | |
40932d1a | 410 | Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal; |
59aadc81 RS |
411 | /* Hook run after a command if there's no more input soon. */ |
412 | Lisp_Object Qpost_command_idle_hook, Vpost_command_idle_hook; | |
413 | ||
414 | /* Delay time in microseconds before running post-command-idle-hook. */ | |
415 | int post_command_idle_delay; | |
86e5706b | 416 | |
8a792f3a RS |
417 | /* List of deferred actions to be performed at a later time. |
418 | The precise format isn't relevant here; we just check whether it is nil. */ | |
419 | Lisp_Object Vdeferred_action_list; | |
420 | ||
421 | /* Function to call to handle deferred actions, when there are any. */ | |
422 | Lisp_Object Vdeferred_action_function; | |
3ef14e46 | 423 | Lisp_Object Qdeferred_action_function; |
8a792f3a | 424 | |
d5eecefb RS |
425 | Lisp_Object Qinput_method_exit_on_first_char; |
426 | Lisp_Object Qinput_method_use_echo_area; | |
427 | ||
284f4730 JB |
428 | /* File in which we write all commands we read. */ |
429 | FILE *dribble; | |
430 | ||
431 | /* Nonzero if input is available. */ | |
432 | int input_pending; | |
433 | ||
b04904fb RS |
434 | /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should |
435 | keep 0200 bit in input chars. 0 to ignore the 0200 bit. */ | |
436 | ||
284f4730 JB |
437 | int meta_key; |
438 | ||
439 | extern char *pending_malloc_warning; | |
440 | ||
beecf6a1 KH |
441 | /* Circular buffer for pre-read keyboard input. */ |
442 | static struct input_event kbd_buffer[KBD_BUFFER_SIZE]; | |
443 | ||
444 | /* Vector to GCPRO the frames and windows mentioned in kbd_buffer. | |
445 | ||
446 | The interrupt-level event handlers will never enqueue an event on a | |
447 | frame which is not in Vframe_list, and once an event is dequeued, | |
448 | internal_last_event_frame or the event itself points to the frame. | |
449 | So that's all fine. | |
450 | ||
451 | But while the event is sitting in the queue, it's completely | |
452 | unprotected. Suppose the user types one command which will run for | |
453 | a while and then delete a frame, and then types another event at | |
454 | the frame that will be deleted, before the command gets around to | |
455 | it. Suppose there are no references to this frame elsewhere in | |
456 | Emacs, and a GC occurs before the second event is dequeued. Now we | |
457 | have an event referring to a freed frame, which will crash Emacs | |
458 | when it is dequeued. | |
459 | ||
460 | Similar things happen when an event on a scroll bar is enqueued; the | |
461 | window may be deleted while the event is in the queue. | |
462 | ||
463 | So, we use this vector to protect the frame_or_window field in the | |
464 | event queue. That way, they'll be dequeued as dead frames or | |
465 | windows, but still valid lisp objects. | |
466 | ||
467 | If kbd_buffer[i].kind != no_event, then | |
468 | (XVECTOR (kbd_buffer_frame_or_window)->contents[i] | |
469 | == kbd_buffer[i].frame_or_window. */ | |
470 | static Lisp_Object kbd_buffer_frame_or_window; | |
471 | ||
472 | /* Pointer to next available character in kbd_buffer. | |
473 | If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty. | |
474 | This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the | |
475 | next available char is in kbd_buffer[0]. */ | |
476 | static struct input_event *kbd_fetch_ptr; | |
477 | ||
478 | /* Pointer to next place to store character in kbd_buffer. This | |
479 | may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next | |
480 | character should go in kbd_buffer[0]. */ | |
7ee32cda | 481 | static struct input_event * volatile kbd_store_ptr; |
beecf6a1 KH |
482 | |
483 | /* The above pair of variables forms a "queue empty" flag. When we | |
484 | enqueue a non-hook event, we increment kbd_store_ptr. When we | |
485 | dequeue a non-hook event, we increment kbd_fetch_ptr. We say that | |
486 | there is input available iff the two pointers are not equal. | |
487 | ||
488 | Why not just have a flag set and cleared by the enqueuing and | |
489 | dequeuing functions? Such a flag could be screwed up by interrupts | |
490 | at inopportune times. */ | |
491 | ||
f3253854 | 492 | /* If this flag is non-nil, we check mouse_moved to see when the |
a9d77f1f RS |
493 | mouse moves, and motion events will appear in the input stream. |
494 | Otherwise, mouse motion is ignored. */ | |
495 | static Lisp_Object do_mouse_tracking; | |
284f4730 | 496 | |
284f4730 JB |
497 | /* Symbols to head events. */ |
498 | Lisp_Object Qmouse_movement; | |
3c370943 | 499 | Lisp_Object Qscroll_bar_movement; |
cd21b839 | 500 | Lisp_Object Qswitch_frame; |
bbdc2092 | 501 | Lisp_Object Qdelete_frame; |
af17bd2b KH |
502 | Lisp_Object Qiconify_frame; |
503 | Lisp_Object Qmake_frame_visible; | |
7ee32cda | 504 | Lisp_Object Qhelp_echo; |
cd21b839 | 505 | |
284f4730 JB |
506 | /* Symbols to denote kinds of events. */ |
507 | Lisp_Object Qfunction_key; | |
508 | Lisp_Object Qmouse_click; | |
07de30b9 GV |
509 | #ifdef WINDOWSNT |
510 | Lisp_Object Qmouse_wheel; | |
1161d367 | 511 | Lisp_Object Qlanguage_change; |
07de30b9 | 512 | #endif |
a24dc617 | 513 | Lisp_Object Qdrag_n_drop; |
284f4730 | 514 | /* Lisp_Object Qmouse_movement; - also an event header */ |
284f4730 JB |
515 | |
516 | /* Properties of event headers. */ | |
517 | Lisp_Object Qevent_kind; | |
88cb0656 | 518 | Lisp_Object Qevent_symbol_elements; |
284f4730 | 519 | |
e8886a1d RS |
520 | /* menu item parts */ |
521 | Lisp_Object Qmenu_alias; | |
598a9fa7 | 522 | Lisp_Object Qmenu_enable; |
74c1de23 RS |
523 | Lisp_Object QCenable, QCvisible, QChelp, QCfilter, QCkeys, QCkey_sequence; |
524 | Lisp_Object QCbutton, QCtoggle, QCradio; | |
e8886a1d RS |
525 | extern Lisp_Object Vdefine_key_rebound_commands; |
526 | extern Lisp_Object Qmenu_item; | |
598a9fa7 | 527 | |
0a7f1fc0 JB |
528 | /* An event header symbol HEAD may have a property named |
529 | Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS); | |
530 | BASE is the base, unmodified version of HEAD, and MODIFIERS is the | |
531 | mask of modifiers applied to it. If present, this is used to help | |
532 | speed up parse_modifiers. */ | |
533 | Lisp_Object Qevent_symbol_element_mask; | |
534 | ||
535 | /* An unmodified event header BASE may have a property named | |
536 | Qmodifier_cache, which is an alist mapping modifier masks onto | |
537 | modified versions of BASE. If present, this helps speed up | |
538 | apply_modifiers. */ | |
539 | Lisp_Object Qmodifier_cache; | |
540 | ||
5ec75a55 | 541 | /* Symbols to use for parts of windows. */ |
284f4730 | 542 | Lisp_Object Qmode_line; |
e5d77022 | 543 | Lisp_Object Qvertical_line; |
3c370943 | 544 | Lisp_Object Qvertical_scroll_bar; |
5ec75a55 RS |
545 | Lisp_Object Qmenu_bar; |
546 | ||
f4255cd1 JB |
547 | Lisp_Object recursive_edit_unwind (), command_loop (); |
548 | Lisp_Object Fthis_command_keys (); | |
03b4122a | 549 | Lisp_Object Qextended_command_history; |
c04cbc3b | 550 | EMACS_TIME timer_check (); |
284f4730 | 551 | |
f4385381 RS |
552 | extern Lisp_Object Vhistory_length; |
553 | ||
2c834fb3 KH |
554 | extern char *x_get_keysym_name (); |
555 | ||
8eb4d8ef RS |
556 | static void record_menu_key (); |
557 | ||
f4eef8b4 RS |
558 | Lisp_Object Qpolling_period; |
559 | ||
d9d4c147 | 560 | /* List of absolute timers. Appears in order of next scheduled event. */ |
c04cbc3b RS |
561 | Lisp_Object Vtimer_list; |
562 | ||
d9d4c147 KH |
563 | /* List of idle time timers. Appears in order of next scheduled event. */ |
564 | Lisp_Object Vtimer_idle_list; | |
565 | ||
87dd9b9b RS |
566 | /* Incremented whenever a timer is run. */ |
567 | int timers_run; | |
568 | ||
a9f16aa9 KH |
569 | extern Lisp_Object Vprint_level, Vprint_length; |
570 | ||
ffd56f97 JB |
571 | /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt |
572 | happens. */ | |
573 | EMACS_TIME *input_available_clear_time; | |
284f4730 JB |
574 | |
575 | /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode. | |
576 | Default is 1 if INTERRUPT_INPUT is defined. */ | |
577 | int interrupt_input; | |
578 | ||
579 | /* Nonzero while interrupts are temporarily deferred during redisplay. */ | |
580 | int interrupts_deferred; | |
581 | ||
87dd9b9b | 582 | /* Nonzero means use ^S/^Q for flow control. */ |
284f4730 JB |
583 | int flow_control; |
584 | ||
284f4730 JB |
585 | /* Allow m- file to inhibit use of FIONREAD. */ |
586 | #ifdef BROKEN_FIONREAD | |
587 | #undef FIONREAD | |
588 | #endif | |
589 | ||
590 | /* We are unable to use interrupts if FIONREAD is not available, | |
591 | so flush SIGIO so we won't try. */ | |
592 | #ifndef FIONREAD | |
593 | #ifdef SIGIO | |
594 | #undef SIGIO | |
595 | #endif | |
596 | #endif | |
597 | ||
e98a93eb | 598 | /* If we support a window system, turn on the code to poll periodically |
34f04431 | 599 | to detect C-g. It isn't actually used when doing interrupt input. */ |
e98a93eb | 600 | #ifdef HAVE_WINDOW_SYSTEM |
284f4730 JB |
601 | #define POLL_FOR_INPUT |
602 | #endif | |
284f4730 JB |
603 | \f |
604 | /* Global variable declarations. */ | |
605 | ||
606 | /* Function for init_keyboard to call with no args (if nonzero). */ | |
607 | void (*keyboard_init_hook) (); | |
608 | ||
609 | static int read_avail_input (); | |
610 | static void get_input_pending (); | |
9fd7d808 | 611 | static int readable_events (); |
8150596a RS |
612 | static Lisp_Object read_char_x_menu_prompt (); |
613 | static Lisp_Object read_char_minibuf_menu_prompt (); | |
a612e298 | 614 | static Lisp_Object make_lispy_event (); |
514354e9 | 615 | #ifdef HAVE_MOUSE |
a612e298 | 616 | static Lisp_Object make_lispy_movement (); |
514354e9 | 617 | #endif |
a612e298 RS |
618 | static Lisp_Object modify_event_symbol (); |
619 | static Lisp_Object make_lispy_switch_frame (); | |
3d31316f | 620 | static int parse_solitary_modifier (); |
dfcf069d AS |
621 | static void save_getcjmp (); |
622 | static void restore_getcjmp (); | |
7ee32cda | 623 | static Lisp_Object apply_modifiers P_ ((int, Lisp_Object)); |
284f4730 JB |
624 | |
625 | /* > 0 if we are to echo keystrokes. */ | |
626 | static int echo_keystrokes; | |
627 | ||
8026024c KH |
628 | /* Nonzero means don't try to suspend even if the operating system seems |
629 | to support it. */ | |
630 | static int cannot_suspend; | |
631 | ||
284f4730 JB |
632 | #define min(a,b) ((a)<(b)?(a):(b)) |
633 | #define max(a,b) ((a)>(b)?(a):(b)) | |
634 | ||
635 | /* Install the string STR as the beginning of the string of echoing, | |
636 | so that it serves as a prompt for the next character. | |
637 | Also start echoing. */ | |
638 | ||
dfcf069d | 639 | void |
284f4730 JB |
640 | echo_prompt (str) |
641 | char *str; | |
642 | { | |
643 | int len = strlen (str); | |
7a80a6f6 | 644 | |
ba72822c KH |
645 | if (len > ECHOBUFSIZE - 4) |
646 | len = ECHOBUFSIZE - 4; | |
c5fdd383 KH |
647 | bcopy (str, current_kboard->echobuf, len); |
648 | current_kboard->echoptr = current_kboard->echobuf + len; | |
649 | *current_kboard->echoptr = '\0'; | |
284f4730 | 650 | |
c5fdd383 | 651 | current_kboard->echo_after_prompt = len; |
7a80a6f6 | 652 | |
3dbd9ee4 | 653 | echo_now (); |
284f4730 JB |
654 | } |
655 | ||
df0f2ba1 | 656 | /* Add C to the echo string, if echoing is going on. |
284f4730 JB |
657 | C can be a character, which is printed prettily ("M-C-x" and all that |
658 | jazz), or a symbol, whose name is printed. */ | |
659 | ||
dfcf069d | 660 | void |
284f4730 JB |
661 | echo_char (c) |
662 | Lisp_Object c; | |
663 | { | |
664 | extern char *push_key_description (); | |
665 | ||
c5fdd383 | 666 | if (current_kboard->immediate_echo) |
284f4730 | 667 | { |
c5fdd383 | 668 | char *ptr = current_kboard->echoptr; |
df0f2ba1 | 669 | |
c5fdd383 | 670 | if (ptr != current_kboard->echobuf) |
284f4730 JB |
671 | *ptr++ = ' '; |
672 | ||
673 | /* If someone has passed us a composite event, use its head symbol. */ | |
88cb0656 | 674 | c = EVENT_HEAD (c); |
284f4730 | 675 | |
8c18cbfb | 676 | if (INTEGERP (c)) |
284f4730 | 677 | { |
c5fdd383 | 678 | if (ptr - current_kboard->echobuf > ECHOBUFSIZE - 6) |
284f4730 JB |
679 | return; |
680 | ||
cb5df6ae | 681 | ptr = push_key_description (XINT (c), ptr); |
284f4730 | 682 | } |
8c18cbfb | 683 | else if (SYMBOLP (c)) |
284f4730 JB |
684 | { |
685 | struct Lisp_String *name = XSYMBOL (c)->name; | |
fc932ac6 | 686 | if ((ptr - current_kboard->echobuf) + STRING_BYTES (name) + 4 |
301738ed | 687 | > ECHOBUFSIZE) |
284f4730 | 688 | return; |
fc932ac6 RS |
689 | bcopy (name->data, ptr, STRING_BYTES (name)); |
690 | ptr += STRING_BYTES (name); | |
284f4730 JB |
691 | } |
692 | ||
c5fdd383 | 693 | if (current_kboard->echoptr == current_kboard->echobuf |
ecb7cb34 | 694 | && help_char_p (c)) |
284f4730 JB |
695 | { |
696 | strcpy (ptr, " (Type ? for further options)"); | |
697 | ptr += strlen (ptr); | |
698 | } | |
699 | ||
700 | *ptr = 0; | |
c5fdd383 | 701 | current_kboard->echoptr = ptr; |
284f4730 | 702 | |
3dbd9ee4 | 703 | echo_now (); |
284f4730 JB |
704 | } |
705 | } | |
706 | ||
707 | /* Temporarily add a dash to the end of the echo string if it's not | |
708 | empty, so that it serves as a mini-prompt for the very next character. */ | |
709 | ||
dfcf069d | 710 | void |
284f4730 JB |
711 | echo_dash () |
712 | { | |
c5fdd383 KH |
713 | if (!current_kboard->immediate_echo |
714 | && current_kboard->echoptr == current_kboard->echobuf) | |
284f4730 | 715 | return; |
7a80a6f6 | 716 | /* Do nothing if we just printed a prompt. */ |
c5fdd383 KH |
717 | if (current_kboard->echo_after_prompt |
718 | == current_kboard->echoptr - current_kboard->echobuf) | |
7a80a6f6 | 719 | return; |
4bafa972 | 720 | /* Do nothing if not echoing at all. */ |
c5fdd383 | 721 | if (current_kboard->echoptr == 0) |
4bafa972 | 722 | return; |
284f4730 JB |
723 | |
724 | /* Put a dash at the end of the buffer temporarily, | |
725 | but make it go away when the next character is added. */ | |
c5fdd383 KH |
726 | current_kboard->echoptr[0] = '-'; |
727 | current_kboard->echoptr[1] = 0; | |
284f4730 | 728 | |
3dbd9ee4 | 729 | echo_now (); |
284f4730 JB |
730 | } |
731 | ||
732 | /* Display the current echo string, and begin echoing if not already | |
733 | doing so. */ | |
734 | ||
07a59269 | 735 | void |
3dbd9ee4 | 736 | echo_now () |
284f4730 | 737 | { |
c5fdd383 | 738 | if (!current_kboard->immediate_echo) |
284f4730 JB |
739 | { |
740 | int i; | |
c5fdd383 | 741 | current_kboard->immediate_echo = 1; |
284f4730 JB |
742 | |
743 | for (i = 0; i < this_command_key_count; i++) | |
d0a57728 RS |
744 | { |
745 | Lisp_Object c; | |
746 | c = XVECTOR (this_command_keys)->contents[i]; | |
747 | if (! (EVENT_HAS_PARAMETERS (c) | |
748 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_movement))) | |
749 | echo_char (c); | |
750 | } | |
284f4730 JB |
751 | echo_dash (); |
752 | } | |
753 | ||
754 | echoing = 1; | |
985f9f66 | 755 | echo_kboard = current_kboard; |
301738ed RS |
756 | message2_nolog (current_kboard->echobuf, strlen (current_kboard->echobuf), |
757 | ! NILP (current_buffer->enable_multibyte_characters)); | |
284f4730 JB |
758 | echoing = 0; |
759 | ||
760 | if (waiting_for_input && !NILP (Vquit_flag)) | |
761 | quit_throw_to_read_char (); | |
762 | } | |
763 | ||
764 | /* Turn off echoing, for the start of a new command. */ | |
765 | ||
dfcf069d | 766 | void |
284f4730 JB |
767 | cancel_echoing () |
768 | { | |
c5fdd383 KH |
769 | current_kboard->immediate_echo = 0; |
770 | current_kboard->echoptr = current_kboard->echobuf; | |
771 | current_kboard->echo_after_prompt = -1; | |
1fc93d49 | 772 | ok_to_echo_at_next_pause = 0; |
985f9f66 | 773 | echo_kboard = 0; |
284f4730 JB |
774 | } |
775 | ||
776 | /* Return the length of the current echo string. */ | |
777 | ||
778 | static int | |
779 | echo_length () | |
780 | { | |
c5fdd383 | 781 | return current_kboard->echoptr - current_kboard->echobuf; |
284f4730 JB |
782 | } |
783 | ||
784 | /* Truncate the current echo message to its first LEN chars. | |
785 | This and echo_char get used by read_key_sequence when the user | |
ff11dfa1 | 786 | switches frames while entering a key sequence. */ |
284f4730 JB |
787 | |
788 | static void | |
789 | echo_truncate (len) | |
790 | int len; | |
791 | { | |
c5fdd383 KH |
792 | current_kboard->echobuf[len] = '\0'; |
793 | current_kboard->echoptr = current_kboard->echobuf + len; | |
40932d1a | 794 | truncate_echo_area (len); |
284f4730 JB |
795 | } |
796 | ||
797 | \f | |
798 | /* Functions for manipulating this_command_keys. */ | |
799 | static void | |
800 | add_command_key (key) | |
801 | Lisp_Object key; | |
802 | { | |
6569cc8d JB |
803 | int size = XVECTOR (this_command_keys)->size; |
804 | ||
71918b75 RS |
805 | /* If reset-this-command-length was called recently, obey it now. |
806 | See the doc string of that function for an explanation of why. */ | |
807 | if (before_command_restore_flag) | |
808 | { | |
809 | this_command_key_count = before_command_key_count_1; | |
6321824f RS |
810 | if (this_command_key_count < this_single_command_key_start) |
811 | this_single_command_key_start = this_command_key_count; | |
71918b75 RS |
812 | echo_truncate (before_command_echo_length_1); |
813 | before_command_restore_flag = 0; | |
814 | } | |
815 | ||
6569cc8d | 816 | if (this_command_key_count >= size) |
284f4730 | 817 | { |
9b8eb840 | 818 | Lisp_Object new_keys; |
6569cc8d | 819 | |
9b8eb840 | 820 | new_keys = Fmake_vector (make_number (size * 2), Qnil); |
6569cc8d JB |
821 | bcopy (XVECTOR (this_command_keys)->contents, |
822 | XVECTOR (new_keys)->contents, | |
8f805655 | 823 | size * sizeof (Lisp_Object)); |
6569cc8d JB |
824 | |
825 | this_command_keys = new_keys; | |
284f4730 | 826 | } |
6569cc8d JB |
827 | |
828 | XVECTOR (this_command_keys)->contents[this_command_key_count++] = key; | |
284f4730 JB |
829 | } |
830 | \f | |
831 | Lisp_Object | |
832 | recursive_edit_1 () | |
833 | { | |
834 | int count = specpdl_ptr - specpdl; | |
835 | Lisp_Object val; | |
836 | ||
837 | if (command_loop_level > 0) | |
838 | { | |
839 | specbind (Qstandard_output, Qt); | |
840 | specbind (Qstandard_input, Qt); | |
841 | } | |
842 | ||
843 | val = command_loop (); | |
844 | if (EQ (val, Qt)) | |
845 | Fsignal (Qquit, Qnil); | |
cb252880 RS |
846 | /* Handle throw from read_minibuf when using minibuffer |
847 | while it's active but we're in another window. */ | |
848 | if (STRINGP (val)) | |
849 | Fsignal (Qerror, Fcons (val, Qnil)); | |
284f4730 | 850 | |
cb5df6ae | 851 | return unbind_to (count, Qnil); |
284f4730 JB |
852 | } |
853 | ||
854 | /* When an auto-save happens, record the "time", and don't do again soon. */ | |
5846638c | 855 | |
07a59269 | 856 | void |
284f4730 JB |
857 | record_auto_save () |
858 | { | |
c43b1734 | 859 | last_auto_save = num_nonmacro_input_events; |
284f4730 | 860 | } |
5846638c RS |
861 | |
862 | /* Make an auto save happen as soon as possible at command level. */ | |
863 | ||
dfcf069d | 864 | void |
5846638c RS |
865 | force_auto_save_soon () |
866 | { | |
867 | last_auto_save = - auto_save_interval - 1; | |
241ceaf7 RS |
868 | |
869 | record_asynch_buffer_change (); | |
5846638c | 870 | } |
284f4730 | 871 | \f |
284f4730 JB |
872 | DEFUN ("recursive-edit", Frecursive_edit, Srecursive_edit, 0, 0, "", |
873 | "Invoke the editor command loop recursively.\n\ | |
874 | To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\ | |
875 | that tells this function to return.\n\ | |
876 | Alternately, `(throw 'exit t)' makes this function signal an error.\n\ | |
877 | This function is called by the editor initialization to begin editing.") | |
878 | () | |
879 | { | |
880 | int count = specpdl_ptr - specpdl; | |
881 | Lisp_Object val; | |
882 | ||
883 | command_loop_level++; | |
884 | update_mode_lines = 1; | |
885 | ||
886 | record_unwind_protect (recursive_edit_unwind, | |
887 | (command_loop_level | |
888 | && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer)) | |
889 | ? Fcurrent_buffer () | |
890 | : Qnil); | |
891 | recursive_edit_1 (); | |
892 | return unbind_to (count, Qnil); | |
893 | } | |
894 | ||
895 | Lisp_Object | |
896 | recursive_edit_unwind (buffer) | |
897 | Lisp_Object buffer; | |
898 | { | |
899 | if (!NILP (buffer)) | |
900 | Fset_buffer (buffer); | |
901 | ||
902 | command_loop_level--; | |
903 | update_mode_lines = 1; | |
904 | return Qnil; | |
905 | } | |
906 | \f | |
604ccd1d | 907 | static void |
1e8bd3da | 908 | any_kboard_state () |
604ccd1d | 909 | { |
1e8bd3da RS |
910 | #ifdef MULTI_KBOARD |
911 | #if 0 /* Theory: if there's anything in Vunread_command_events, | |
912 | it will right away be read by read_key_sequence, | |
913 | and then if we do switch KBOARDS, it will go into the side | |
914 | queue then. So we don't need to do anything special here -- rms. */ | |
604ccd1d | 915 | if (CONSP (Vunread_command_events)) |
4524b161 | 916 | { |
c5fdd383 KH |
917 | current_kboard->kbd_queue |
918 | = nconc2 (Vunread_command_events, current_kboard->kbd_queue); | |
919 | current_kboard->kbd_queue_has_data = 1; | |
4524b161 | 920 | } |
604ccd1d | 921 | Vunread_command_events = Qnil; |
1e8bd3da RS |
922 | #endif |
923 | single_kboard = 0; | |
924 | #endif | |
604ccd1d | 925 | } |
1e8bd3da RS |
926 | |
927 | /* Switch to the single-kboard state, making current_kboard | |
928 | the only KBOARD from which further input is accepted. */ | |
929 | ||
930 | void | |
931 | single_kboard_state () | |
932 | { | |
933 | #ifdef MULTI_KBOARD | |
934 | single_kboard = 1; | |
604ccd1d | 935 | #endif |
1e8bd3da RS |
936 | } |
937 | ||
938 | /* Maintain a stack of kboards, so other parts of Emacs | |
939 | can switch temporarily to the kboard of a given frame | |
940 | and then revert to the previous status. */ | |
941 | ||
942 | struct kboard_stack | |
943 | { | |
944 | KBOARD *kboard; | |
945 | struct kboard_stack *next; | |
946 | }; | |
947 | ||
948 | static struct kboard_stack *kboard_stack; | |
949 | ||
950 | void | |
951 | push_frame_kboard (f) | |
952 | FRAME_PTR f; | |
953 | { | |
ab48365b | 954 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
955 | struct kboard_stack *p |
956 | = (struct kboard_stack *) xmalloc (sizeof (struct kboard_stack)); | |
957 | ||
958 | p->next = kboard_stack; | |
959 | p->kboard = current_kboard; | |
960 | kboard_stack = p; | |
961 | ||
962 | current_kboard = FRAME_KBOARD (f); | |
ab48365b | 963 | #endif |
1e8bd3da RS |
964 | } |
965 | ||
966 | void | |
967 | pop_frame_kboard () | |
968 | { | |
ab48365b | 969 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
970 | struct kboard_stack *p = kboard_stack; |
971 | current_kboard = p->kboard; | |
972 | kboard_stack = p->next; | |
973 | xfree (p); | |
ab48365b | 974 | #endif |
1e8bd3da RS |
975 | } |
976 | \f | |
977 | /* Handle errors that are not handled at inner levels | |
978 | by printing an error message and returning to the editor command loop. */ | |
604ccd1d | 979 | |
284f4730 JB |
980 | Lisp_Object |
981 | cmd_error (data) | |
982 | Lisp_Object data; | |
a1341f75 | 983 | { |
a9f16aa9 | 984 | Lisp_Object old_level, old_length; |
e881d8b2 RS |
985 | char macroerror[50]; |
986 | ||
987 | if (!NILP (executing_macro)) | |
988 | { | |
989 | if (executing_macro_iterations == 1) | |
990 | sprintf (macroerror, "After 1 kbd macro iteration: "); | |
991 | else | |
992 | sprintf (macroerror, "After %d kbd macro iterations: ", | |
993 | executing_macro_iterations); | |
994 | } | |
995 | else | |
996 | *macroerror = 0; | |
a9f16aa9 | 997 | |
a1341f75 RS |
998 | Vstandard_output = Qt; |
999 | Vstandard_input = Qt; | |
1000 | Vexecuting_macro = Qnil; | |
9f58e89e | 1001 | executing_macro = Qnil; |
d8bcf58e | 1002 | current_kboard->Vprefix_arg = Qnil; |
75045dcb | 1003 | current_kboard->Vlast_prefix_arg = Qnil; |
df0f2ba1 | 1004 | cancel_echoing (); |
a9f16aa9 KH |
1005 | |
1006 | /* Avoid unquittable loop if data contains a circular list. */ | |
1007 | old_level = Vprint_level; | |
1008 | old_length = Vprint_length; | |
0c04a67e RS |
1009 | XSETFASTINT (Vprint_level, 10); |
1010 | XSETFASTINT (Vprint_length, 10); | |
e881d8b2 | 1011 | cmd_error_internal (data, macroerror); |
a9f16aa9 KH |
1012 | Vprint_level = old_level; |
1013 | Vprint_length = old_length; | |
a1341f75 RS |
1014 | |
1015 | Vquit_flag = Qnil; | |
1016 | ||
1017 | Vinhibit_quit = Qnil; | |
c5fdd383 | 1018 | #ifdef MULTI_KBOARD |
1e8bd3da | 1019 | any_kboard_state (); |
ff4b06d3 | 1020 | #endif |
a1341f75 RS |
1021 | |
1022 | return make_number (0); | |
1023 | } | |
1024 | ||
301738ed RS |
1025 | /* Take actions on handling an error. DATA is the data that describes |
1026 | the error. | |
1027 | ||
1028 | CONTEXT is a C-string containing ASCII characters only which | |
1029 | describes the context in which the error happened. If we need to | |
1030 | generalize CONTEXT to allow multibyte characters, make it a Lisp | |
1031 | string. */ | |
1032 | ||
07a59269 | 1033 | void |
a1341f75 RS |
1034 | cmd_error_internal (data, context) |
1035 | Lisp_Object data; | |
1036 | char *context; | |
284f4730 | 1037 | { |
284f4730 | 1038 | Lisp_Object stream; |
7ee32cda | 1039 | int kill_emacs_p = 0; |
284f4730 JB |
1040 | |
1041 | Vquit_flag = Qnil; | |
1042 | Vinhibit_quit = Qt; | |
985f9f66 | 1043 | clear_message (1, 0); |
284f4730 | 1044 | |
ff11dfa1 | 1045 | /* If the window system or terminal frame hasn't been initialized |
284f4730 JB |
1046 | yet, or we're not interactive, it's best to dump this message out |
1047 | to stderr and exit. */ | |
7ee32cda GM |
1048 | if (!selected_frame->glyphs_initialized_p |
1049 | /* This is the case of the frame dumped with Emacs, when we're | |
1050 | running under a window system. */ | |
1051 | || (!NILP (Vwindow_system) | |
1052 | && !inhibit_window_system | |
e6a77d6c | 1053 | && FRAME_TERMCAP_P (selected_frame)) |
284f4730 | 1054 | || noninteractive) |
7ee32cda GM |
1055 | { |
1056 | stream = Qexternal_debugging_output; | |
1057 | kill_emacs_p = 1; | |
1058 | } | |
284f4730 JB |
1059 | else |
1060 | { | |
1061 | Fdiscard_input (); | |
1062 | bitch_at_user (); | |
1063 | stream = Qt; | |
1064 | } | |
1065 | ||
a1341f75 RS |
1066 | if (context != 0) |
1067 | write_string_1 (context, -1, stream); | |
1068 | ||
22a51344 | 1069 | print_error_message (data, stream); |
284f4730 | 1070 | |
ff11dfa1 | 1071 | /* If the window system or terminal frame hasn't been initialized |
284f4730 | 1072 | yet, or we're in -batch mode, this error should cause Emacs to exit. */ |
7ee32cda | 1073 | if (kill_emacs_p) |
284f4730 JB |
1074 | { |
1075 | Fterpri (stream); | |
1076 | Fkill_emacs (make_number (-1)); | |
1077 | } | |
284f4730 JB |
1078 | } |
1079 | \f | |
1080 | Lisp_Object command_loop_1 (); | |
1081 | Lisp_Object command_loop_2 (); | |
1082 | Lisp_Object top_level_1 (); | |
1083 | ||
1084 | /* Entry to editor-command-loop. | |
1085 | This level has the catches for exiting/returning to editor command loop. | |
1086 | It returns nil to exit recursive edit, t to abort it. */ | |
1087 | ||
1088 | Lisp_Object | |
1089 | command_loop () | |
1090 | { | |
1091 | if (command_loop_level > 0 || minibuf_level > 0) | |
1092 | { | |
07ba902e RS |
1093 | Lisp_Object val; |
1094 | val = internal_catch (Qexit, command_loop_2, Qnil); | |
68c46464 RS |
1095 | executing_macro = Qnil; |
1096 | return val; | |
284f4730 JB |
1097 | } |
1098 | else | |
1099 | while (1) | |
1100 | { | |
1101 | internal_catch (Qtop_level, top_level_1, Qnil); | |
1102 | internal_catch (Qtop_level, command_loop_2, Qnil); | |
68c46464 | 1103 | executing_macro = Qnil; |
df0f2ba1 | 1104 | |
284f4730 JB |
1105 | /* End of file in -batch run causes exit here. */ |
1106 | if (noninteractive) | |
1107 | Fkill_emacs (Qt); | |
1108 | } | |
1109 | } | |
1110 | ||
1111 | /* Here we catch errors in execution of commands within the | |
1112 | editing loop, and reenter the editing loop. | |
1113 | When there is an error, cmd_error runs and returns a non-nil | |
1114 | value to us. A value of nil means that cmd_loop_1 itself | |
1115 | returned due to end of file (or end of kbd macro). */ | |
1116 | ||
1117 | Lisp_Object | |
1118 | command_loop_2 () | |
1119 | { | |
1120 | register Lisp_Object val; | |
1121 | ||
1122 | do | |
1123 | val = internal_condition_case (command_loop_1, Qerror, cmd_error); | |
1124 | while (!NILP (val)); | |
1125 | ||
1126 | return Qnil; | |
1127 | } | |
1128 | ||
1129 | Lisp_Object | |
1130 | top_level_2 () | |
1131 | { | |
1132 | return Feval (Vtop_level); | |
1133 | } | |
1134 | ||
1135 | Lisp_Object | |
1136 | top_level_1 () | |
1137 | { | |
1138 | /* On entry to the outer level, run the startup file */ | |
1139 | if (!NILP (Vtop_level)) | |
1140 | internal_condition_case (top_level_2, Qerror, cmd_error); | |
1141 | else if (!NILP (Vpurify_flag)) | |
1142 | message ("Bare impure Emacs (standard Lisp code not loaded)"); | |
1143 | else | |
1144 | message ("Bare Emacs (standard Lisp code not loaded)"); | |
1145 | return Qnil; | |
1146 | } | |
1147 | ||
1148 | DEFUN ("top-level", Ftop_level, Stop_level, 0, 0, "", | |
1149 | "Exit all recursive editing levels.") | |
1150 | () | |
1151 | { | |
1152 | Fthrow (Qtop_level, Qnil); | |
1153 | } | |
1154 | ||
1155 | DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, "", | |
1156 | "Exit from the innermost recursive edit or minibuffer.") | |
1157 | () | |
1158 | { | |
1159 | if (command_loop_level > 0 || minibuf_level > 0) | |
1160 | Fthrow (Qexit, Qnil); | |
1161 | ||
1162 | error ("No recursive edit is in progress"); | |
1163 | } | |
1164 | ||
1165 | DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0, 0, "", | |
1166 | "Abort the command that requested this recursive edit or minibuffer input.") | |
1167 | () | |
1168 | { | |
1169 | if (command_loop_level > 0 || minibuf_level > 0) | |
1170 | Fthrow (Qexit, Qt); | |
1171 | ||
1172 | error ("No recursive edit is in progress"); | |
1173 | } | |
1174 | \f | |
1175 | /* This is the actual command reading loop, | |
1176 | sans error-handling encapsulation. */ | |
1177 | ||
1178 | Lisp_Object Fcommand_execute (); | |
1179 | static int read_key_sequence (); | |
68f297c5 | 1180 | void safe_run_hooks (); |
284f4730 JB |
1181 | |
1182 | Lisp_Object | |
1183 | command_loop_1 () | |
1184 | { | |
48e416d4 | 1185 | Lisp_Object cmd, tem; |
37cd9f30 | 1186 | int lose, lose2; |
284f4730 JB |
1187 | int nonundocount; |
1188 | Lisp_Object keybuf[30]; | |
1189 | int i; | |
1190 | int no_redisplay; | |
1191 | int no_direct; | |
86e5706b RS |
1192 | int prev_modiff; |
1193 | struct buffer *prev_buffer; | |
c5fdd383 | 1194 | #ifdef MULTI_KBOARD |
1e8bd3da | 1195 | int was_locked = single_kboard; |
bded54dd | 1196 | #endif |
284f4730 | 1197 | |
d9b641bb | 1198 | current_kboard->Vprefix_arg = Qnil; |
75045dcb | 1199 | current_kboard->Vlast_prefix_arg = Qnil; |
86e5706b | 1200 | Vdeactivate_mark = Qnil; |
284f4730 | 1201 | waiting_for_input = 0; |
df0f2ba1 | 1202 | cancel_echoing (); |
284f4730 | 1203 | |
284f4730 JB |
1204 | nonundocount = 0; |
1205 | no_redisplay = 0; | |
1206 | this_command_key_count = 0; | |
6321824f | 1207 | this_single_command_key_start = 0; |
284f4730 | 1208 | |
a612e298 RS |
1209 | /* Make sure this hook runs after commands that get errors and |
1210 | throw to top level. */ | |
a98ea3f9 RS |
1211 | /* Note that the value cell will never directly contain nil |
1212 | if the symbol is a local variable. */ | |
e98a93eb | 1213 | if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) |
a98ea3f9 | 1214 | safe_run_hooks (Qpost_command_hook); |
a612e298 | 1215 | |
8a792f3a RS |
1216 | if (!NILP (Vdeferred_action_list)) |
1217 | call0 (Vdeferred_action_function); | |
1218 | ||
e98a93eb | 1219 | if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks)) |
59aadc81 RS |
1220 | { |
1221 | if (NILP (Vunread_command_events) | |
7d18f9ae RS |
1222 | && NILP (Vunread_input_method_events) |
1223 | && NILP (Vunread_post_input_method_events) | |
59aadc81 | 1224 | && NILP (Vexecuting_macro) |
41365083 | 1225 | && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1))) |
59aadc81 RS |
1226 | safe_run_hooks (Qpost_command_idle_hook); |
1227 | } | |
1228 | ||
51d5a2c9 | 1229 | /* Do this after running Vpost_command_hook, for consistency. */ |
d5eecefb RS |
1230 | current_kboard->Vlast_command = Vthis_command; |
1231 | current_kboard->Vreal_last_command = real_this_command; | |
51d5a2c9 | 1232 | |
284f4730 JB |
1233 | while (1) |
1234 | { | |
a94a4335 KH |
1235 | if (! FRAME_LIVE_P (selected_frame)) |
1236 | Fkill_emacs (Qnil); | |
1237 | ||
284f4730 JB |
1238 | /* Make sure the current window's buffer is selected. */ |
1239 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
1240 | set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer)); | |
1241 | ||
1242 | /* Display any malloc warning that just came out. Use while because | |
1243 | displaying one warning can cause another. */ | |
1244 | ||
1245 | while (pending_malloc_warning) | |
1246 | display_malloc_warning (); | |
1247 | ||
1248 | no_direct = 0; | |
1249 | ||
86e5706b RS |
1250 | Vdeactivate_mark = Qnil; |
1251 | ||
284f4730 | 1252 | /* If minibuffer on and echo area in use, |
eb8c3be9 | 1253 | wait 2 sec and redraw minibuffer. */ |
284f4730 | 1254 | |
7ee32cda | 1255 | if (minibuf_level |
985f9f66 | 1256 | && !NILP (echo_area_buffer[0]) |
93127526 | 1257 | && EQ (minibuf_window, echo_area_window)) |
284f4730 | 1258 | { |
f1bed6d8 RS |
1259 | /* Bind inhibit-quit to t so that C-g gets read in |
1260 | rather than quitting back to the minibuffer. */ | |
1261 | int count = specpdl_ptr - specpdl; | |
1262 | specbind (Qinhibit_quit, Qt); | |
f1bed6d8 | 1263 | |
db08707d | 1264 | Fsit_for (make_number (2), Qnil, Qnil); |
e6aa7813 | 1265 | /* Clear the echo area. */ |
301738ed | 1266 | message2 (0, 0, 0); |
cdb9d665 | 1267 | safe_run_hooks (Qecho_area_clear_hook); |
e6aa7813 | 1268 | |
db08707d RS |
1269 | unbind_to (count, Qnil); |
1270 | ||
e6aa7813 | 1271 | /* If a C-g came in before, treat it as input now. */ |
284f4730 JB |
1272 | if (!NILP (Vquit_flag)) |
1273 | { | |
1274 | Vquit_flag = Qnil; | |
24597608 | 1275 | Vunread_command_events = Fcons (make_number (quit_char), Qnil); |
284f4730 JB |
1276 | } |
1277 | } | |
1278 | ||
1279 | #ifdef C_ALLOCA | |
ff4b06d3 | 1280 | alloca (0); /* Cause a garbage collection now */ |
284f4730 JB |
1281 | /* Since we can free the most stuff here. */ |
1282 | #endif /* C_ALLOCA */ | |
1283 | ||
8f805655 | 1284 | #if 0 |
8f805655 JB |
1285 | /* Select the frame that the last event came from. Usually, |
1286 | switch-frame events will take care of this, but if some lisp | |
1287 | code swallows a switch-frame event, we'll fix things up here. | |
1288 | Is this a good idea? */ | |
8c18cbfb | 1289 | if (FRAMEP (internal_last_event_frame) |
3c370943 JB |
1290 | && XFRAME (internal_last_event_frame) != selected_frame) |
1291 | Fselect_frame (internal_last_event_frame, Qnil); | |
284f4730 | 1292 | #endif |
48e416d4 RS |
1293 | /* If it has changed current-menubar from previous value, |
1294 | really recompute the menubar from the value. */ | |
a646e520 RS |
1295 | if (! NILP (Vlucid_menu_bar_dirty_flag) |
1296 | && !NILP (Ffboundp (Qrecompute_lucid_menubar))) | |
48e416d4 RS |
1297 | call0 (Qrecompute_lucid_menubar); |
1298 | ||
71918b75 RS |
1299 | before_command_key_count = this_command_key_count; |
1300 | before_command_echo_length = echo_length (); | |
1301 | ||
d5eecefb RS |
1302 | Vthis_command = Qnil; |
1303 | real_this_command = Qnil; | |
d7437ef6 | 1304 | |
8f805655 | 1305 | /* Read next key sequence; i gets its length. */ |
ce98e608 | 1306 | i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0], |
f571ae0d | 1307 | Qnil, 0, 1, 1); |
8f805655 | 1308 | |
6fac1409 | 1309 | /* A filter may have run while we were reading the input. */ |
a94a4335 KH |
1310 | if (! FRAME_LIVE_P (selected_frame)) |
1311 | Fkill_emacs (Qnil); | |
6fac1409 RS |
1312 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) |
1313 | set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer)); | |
1314 | ||
8f805655 JB |
1315 | ++num_input_keys; |
1316 | ||
284f4730 JB |
1317 | /* Now we have read a key sequence of length I, |
1318 | or else I is 0 and we found end of file. */ | |
1319 | ||
1320 | if (i == 0) /* End of file -- happens only in */ | |
1321 | return Qnil; /* a kbd macro, at the end. */ | |
dcc408a0 RS |
1322 | /* -1 means read_key_sequence got a menu that was rejected. |
1323 | Just loop around and read another command. */ | |
1324 | if (i == -1) | |
1325 | { | |
1326 | cancel_echoing (); | |
1327 | this_command_key_count = 0; | |
6321824f | 1328 | this_single_command_key_start = 0; |
ff4b06d3 | 1329 | goto finalize; |
dcc408a0 | 1330 | } |
284f4730 | 1331 | |
284f4730 JB |
1332 | last_command_char = keybuf[i - 1]; |
1333 | ||
75c0b143 RS |
1334 | /* If the previous command tried to force a specific window-start, |
1335 | forget about that, in case this command moves point far away | |
c422836d KH |
1336 | from that position. But also throw away beg_unchanged and |
1337 | end_unchanged information in that case, so that redisplay will | |
1338 | update the whole window properly. */ | |
1339 | if (!NILP (XWINDOW (selected_window)->force_start)) | |
1340 | { | |
9351ebd0 | 1341 | struct buffer *b; |
c422836d | 1342 | XWINDOW (selected_window)->force_start = Qnil; |
9351ebd0 GM |
1343 | b = XBUFFER (XWINDOW (selected_window)->buffer); |
1344 | BUF_BEG_UNCHANGED (b) = BUF_END_UNCHANGED (b) = 0; | |
c422836d | 1345 | } |
75c0b143 | 1346 | |
284f4730 JB |
1347 | cmd = read_key_sequence_cmd; |
1348 | if (!NILP (Vexecuting_macro)) | |
1349 | { | |
1350 | if (!NILP (Vquit_flag)) | |
1351 | { | |
1352 | Vexecuting_macro = Qt; | |
1353 | QUIT; /* Make some noise. */ | |
1354 | /* Will return since macro now empty. */ | |
1355 | } | |
1356 | } | |
1357 | ||
1358 | /* Do redisplay processing after this command except in special | |
40932d1a RS |
1359 | cases identified below that set no_redisplay to 1. |
1360 | (actually, there's currently no way to prevent the redisplay, | |
1361 | and no_redisplay is ignored. | |
beecf6a1 | 1362 | Perhaps someday we will really implement it.) */ |
284f4730 JB |
1363 | no_redisplay = 0; |
1364 | ||
86e5706b RS |
1365 | prev_buffer = current_buffer; |
1366 | prev_modiff = MODIFF; | |
8746da95 | 1367 | last_point_position = PT; |
18cd2eeb | 1368 | XSETBUFFER (last_point_position_buffer, prev_buffer); |
86e5706b | 1369 | |
284f4730 JB |
1370 | /* Execute the command. */ |
1371 | ||
d5eecefb RS |
1372 | Vthis_command = cmd; |
1373 | real_this_command = cmd; | |
a98ea3f9 RS |
1374 | /* Note that the value cell will never directly contain nil |
1375 | if the symbol is a local variable. */ | |
e98a93eb | 1376 | if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks)) |
a98ea3f9 | 1377 | safe_run_hooks (Qpre_command_hook); |
75045dcb | 1378 | |
d5eecefb | 1379 | if (NILP (Vthis_command)) |
284f4730 JB |
1380 | { |
1381 | /* nil means key is undefined. */ | |
1382 | bitch_at_user (); | |
c5fdd383 | 1383 | current_kboard->defining_kbd_macro = Qnil; |
284f4730 | 1384 | update_mode_lines = 1; |
d8bcf58e | 1385 | current_kboard->Vprefix_arg = Qnil; |
284f4730 JB |
1386 | } |
1387 | else | |
1388 | { | |
d8bcf58e | 1389 | if (NILP (current_kboard->Vprefix_arg) && ! no_direct) |
284f4730 | 1390 | { |
75045dcb RS |
1391 | /* In case we jump to directly_done. */ |
1392 | Vcurrent_prefix_arg = current_kboard->Vprefix_arg; | |
1393 | ||
284f4730 JB |
1394 | /* Recognize some common commands in common situations and |
1395 | do them directly. */ | |
d5eecefb | 1396 | if (EQ (Vthis_command, Qforward_char) && PT < ZV) |
284f4730 | 1397 | { |
51ad8a68 | 1398 | struct Lisp_Char_Table *dp |
284f4730 | 1399 | = window_display_table (XWINDOW (selected_window)); |
aaf35234 | 1400 | lose = FETCH_CHAR (PT_BYTE); |
8458ede6 | 1401 | SET_PT (PT + 1); |
0f7a8fee | 1402 | if ((dp |
82ba47d7 | 1403 | ? (VECTORP (DISP_CHAR_VECTOR (dp, lose)) |
9a5540db RS |
1404 | ? XVECTOR (DISP_CHAR_VECTOR (dp, lose))->size == 1 |
1405 | : (NILP (DISP_CHAR_VECTOR (dp, lose)) | |
1406 | && (lose >= 0x20 && lose < 0x7f))) | |
0f7a8fee | 1407 | : (lose >= 0x20 && lose < 0x7f)) |
37cd9f30 KH |
1408 | /* To extract the case of continuation on |
1409 | wide-column characters. */ | |
8458ede6 | 1410 | && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE)) == 1) |
284f4730 JB |
1411 | && (XFASTINT (XWINDOW (selected_window)->last_modified) |
1412 | >= MODIFF) | |
598ba4c7 RS |
1413 | && (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1414 | >= OVERLAY_MODIFF) | |
284f4730 | 1415 | && (XFASTINT (XWINDOW (selected_window)->last_point) |
8001d352 | 1416 | == PT - 1) |
284f4730 JB |
1417 | && !windows_or_buffers_changed |
1418 | && EQ (current_buffer->selective_display, Qnil) | |
1419 | && !detect_input_pending () | |
962ae636 | 1420 | && NILP (XWINDOW (selected_window)->column_number_displayed) |
284f4730 JB |
1421 | && NILP (Vexecuting_macro)) |
1422 | no_redisplay = direct_output_forward_char (1); | |
1423 | goto directly_done; | |
1424 | } | |
d5eecefb | 1425 | else if (EQ (Vthis_command, Qbackward_char) && PT > BEGV) |
284f4730 | 1426 | { |
51ad8a68 | 1427 | struct Lisp_Char_Table *dp |
284f4730 | 1428 | = window_display_table (XWINDOW (selected_window)); |
8458ede6 | 1429 | SET_PT (PT - 1); |
aaf35234 | 1430 | lose = FETCH_CHAR (PT_BYTE); |
0f7a8fee | 1431 | if ((dp |
ca873d73 | 1432 | ? (VECTORP (DISP_CHAR_VECTOR (dp, lose)) |
9a5540db RS |
1433 | ? XVECTOR (DISP_CHAR_VECTOR (dp, lose))->size == 1 |
1434 | : (NILP (DISP_CHAR_VECTOR (dp, lose)) | |
1435 | && (lose >= 0x20 && lose < 0x7f))) | |
0f7a8fee | 1436 | : (lose >= 0x20 && lose < 0x7f)) |
284f4730 JB |
1437 | && (XFASTINT (XWINDOW (selected_window)->last_modified) |
1438 | >= MODIFF) | |
598ba4c7 RS |
1439 | && (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1440 | >= OVERLAY_MODIFF) | |
284f4730 | 1441 | && (XFASTINT (XWINDOW (selected_window)->last_point) |
8001d352 | 1442 | == PT + 1) |
284f4730 JB |
1443 | && !windows_or_buffers_changed |
1444 | && EQ (current_buffer->selective_display, Qnil) | |
1445 | && !detect_input_pending () | |
962ae636 | 1446 | && NILP (XWINDOW (selected_window)->column_number_displayed) |
284f4730 JB |
1447 | && NILP (Vexecuting_macro)) |
1448 | no_redisplay = direct_output_forward_char (-1); | |
1449 | goto directly_done; | |
1450 | } | |
d5eecefb | 1451 | else if (EQ (Vthis_command, Qself_insert_command) |
284f4730 | 1452 | /* Try this optimization only on ascii keystrokes. */ |
8c18cbfb | 1453 | && INTEGERP (last_command_char)) |
284f4730 | 1454 | { |
89599794 | 1455 | unsigned int c = XINT (last_command_char); |
fc9cce4e | 1456 | int value; |
fc9cce4e RS |
1457 | if (NILP (Vexecuting_macro) |
1458 | && !EQ (minibuf_window, selected_window)) | |
284f4730 JB |
1459 | { |
1460 | if (!nonundocount || nonundocount >= 20) | |
1461 | { | |
1462 | Fundo_boundary (); | |
1463 | nonundocount = 0; | |
1464 | } | |
1465 | nonundocount++; | |
1466 | } | |
7ee32cda | 1467 | |
fc9cce4e RS |
1468 | lose = ((XFASTINT (XWINDOW (selected_window)->last_modified) |
1469 | < MODIFF) | |
598ba4c7 RS |
1470 | || (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1471 | < OVERLAY_MODIFF) | |
fc9cce4e RS |
1472 | || (XFASTINT (XWINDOW (selected_window)->last_point) |
1473 | != PT) | |
4c61f38e | 1474 | || MODIFF <= SAVE_MODIFF |
fc9cce4e RS |
1475 | || windows_or_buffers_changed |
1476 | || !EQ (current_buffer->selective_display, Qnil) | |
1477 | || detect_input_pending () | |
962ae636 | 1478 | || !NILP (XWINDOW (selected_window)->column_number_displayed) |
fc9cce4e | 1479 | || !NILP (Vexecuting_macro)); |
7ee32cda | 1480 | |
fc9cce4e | 1481 | value = internal_self_insert (c, 0); |
7ee32cda | 1482 | |
fc9cce4e RS |
1483 | if (value == 2) |
1484 | nonundocount = 0; | |
1485 | ||
7ee32cda GM |
1486 | /* VALUE == 1 when AFTER-CHANGE functions are |
1487 | installed which is the case most of the time | |
1488 | because FONT-LOCK installs one. */ | |
1489 | if (!lose && !value) | |
1490 | no_redisplay = direct_output_for_insert (c); | |
284f4730 JB |
1491 | goto directly_done; |
1492 | } | |
1493 | } | |
1494 | ||
1495 | /* Here for a command that isn't executed directly */ | |
1496 | ||
7ee32cda GM |
1497 | #ifdef HAVE_X_WINDOWS |
1498 | if (display_busy_cursor_p) | |
1499 | { | |
1500 | if (inhibit_busy_cursor != 2) | |
1501 | inhibit_busy_cursor = 0; | |
1502 | if (!inhibit_busy_cursor) | |
1503 | Fx_show_busy_cursor (); | |
1504 | } | |
1505 | #endif | |
1506 | ||
284f4730 | 1507 | nonundocount = 0; |
d8bcf58e | 1508 | if (NILP (current_kboard->Vprefix_arg)) |
284f4730 | 1509 | Fundo_boundary (); |
d5eecefb | 1510 | Fcommand_execute (Vthis_command, Qnil, Qnil, Qnil); |
284f4730 | 1511 | } |
a764a753 | 1512 | directly_done: ; |
75045dcb | 1513 | current_kboard->Vlast_prefix_arg = Vcurrent_prefix_arg; |
284f4730 | 1514 | |
84ee6048 RS |
1515 | /* Note that the value cell will never directly contain nil |
1516 | if the symbol is a local variable. */ | |
1517 | if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) | |
1518 | safe_run_hooks (Qpost_command_hook); | |
1519 | ||
1520 | if (!NILP (Vdeferred_action_list)) | |
1521 | safe_run_hooks (Qdeferred_action_function); | |
1522 | ||
1523 | if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks)) | |
1524 | { | |
1525 | if (NILP (Vunread_command_events) | |
7d18f9ae RS |
1526 | && NILP (Vunread_input_method_events) |
1527 | && NILP (Vunread_post_input_method_events) | |
84ee6048 RS |
1528 | && NILP (Vexecuting_macro) |
1529 | && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1))) | |
1530 | safe_run_hooks (Qpost_command_idle_hook); | |
1531 | } | |
1532 | ||
284f4730 | 1533 | /* If there is a prefix argument, |
6c7178b9 KH |
1534 | 1) We don't want Vlast_command to be ``universal-argument'' |
1535 | (that would be dumb), so don't set Vlast_command, | |
284f4730 JB |
1536 | 2) we want to leave echoing on so that the prefix will be |
1537 | echoed as part of this key sequence, so don't call | |
1538 | cancel_echoing, and | |
1539 | 3) we want to leave this_command_key_count non-zero, so that | |
1540 | read_char will realize that it is re-reading a character, and | |
217258d5 KH |
1541 | not echo it a second time. |
1542 | ||
1543 | If the command didn't actually create a prefix arg, | |
1544 | but is merely a frame event that is transparent to prefix args, | |
1545 | then the above doesn't apply. */ | |
1546 | if (NILP (current_kboard->Vprefix_arg) || CONSP (last_command_char)) | |
284f4730 | 1547 | { |
d5eecefb RS |
1548 | current_kboard->Vlast_command = Vthis_command; |
1549 | current_kboard->Vreal_last_command = real_this_command; | |
284f4730 JB |
1550 | cancel_echoing (); |
1551 | this_command_key_count = 0; | |
6321824f | 1552 | this_single_command_key_start = 0; |
284f4730 | 1553 | } |
86e5706b | 1554 | |
88ce066e | 1555 | if (!NILP (current_buffer->mark_active) && !NILP (Vrun_hooks)) |
86e5706b RS |
1556 | { |
1557 | if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode)) | |
1558 | { | |
1559 | current_buffer->mark_active = Qnil; | |
1560 | call1 (Vrun_hooks, intern ("deactivate-mark-hook")); | |
1561 | } | |
1562 | else if (current_buffer != prev_buffer || MODIFF != prev_modiff) | |
1563 | call1 (Vrun_hooks, intern ("activate-mark-hook")); | |
1564 | } | |
ff4b06d3 KH |
1565 | |
1566 | finalize: | |
1567 | /* Install chars successfully executed in kbd macro. */ | |
1568 | ||
d8bcf58e KH |
1569 | if (!NILP (current_kboard->defining_kbd_macro) |
1570 | && NILP (current_kboard->Vprefix_arg)) | |
ff4b06d3 KH |
1571 | finalize_kbd_macro_chars (); |
1572 | ||
c5fdd383 | 1573 | #ifdef MULTI_KBOARD |
604ccd1d | 1574 | if (!was_locked) |
1e8bd3da | 1575 | any_kboard_state (); |
ff4b06d3 | 1576 | #endif |
284f4730 JB |
1577 | } |
1578 | } | |
1c9784c9 | 1579 | |
0bc3db2b RS |
1580 | /* Subroutine for safe_run_hooks: run the hook HOOK. */ |
1581 | ||
1582 | static Lisp_Object | |
1583 | safe_run_hooks_1 (hook) | |
1584 | Lisp_Object hook; | |
1585 | { | |
1586 | return call1 (Vrun_hooks, Vinhibit_quit); | |
1587 | } | |
1588 | ||
1589 | /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */ | |
1590 | ||
1591 | static Lisp_Object | |
1592 | safe_run_hooks_error (data) | |
1593 | Lisp_Object data; | |
1594 | { | |
1595 | Fset (Vinhibit_quit, Qnil); | |
1596 | } | |
1597 | ||
1c9784c9 KH |
1598 | /* If we get an error while running the hook, cause the hook variable |
1599 | to be nil. Also inhibit quits, so that C-g won't cause the hook | |
1600 | to mysteriously evaporate. */ | |
0bc3db2b | 1601 | |
68f297c5 | 1602 | void |
1c9784c9 | 1603 | safe_run_hooks (hook) |
a98ea3f9 | 1604 | Lisp_Object hook; |
1c9784c9 | 1605 | { |
68553292 | 1606 | Lisp_Object value; |
1c9784c9 | 1607 | int count = specpdl_ptr - specpdl; |
0bc3db2b RS |
1608 | specbind (Qinhibit_quit, hook); |
1609 | ||
e702932d | 1610 | internal_condition_case (safe_run_hooks_1, Qt, safe_run_hooks_error); |
1c9784c9 KH |
1611 | |
1612 | unbind_to (count, Qnil); | |
1613 | } | |
284f4730 JB |
1614 | \f |
1615 | /* Number of seconds between polling for input. */ | |
1616 | int polling_period; | |
1617 | ||
eb8c3be9 | 1618 | /* Nonzero means polling for input is temporarily suppressed. */ |
284f4730 JB |
1619 | int poll_suppress_count; |
1620 | ||
36922b18 | 1621 | /* Nonzero if polling_for_input is actually being used. */ |
284f4730 JB |
1622 | int polling_for_input; |
1623 | ||
36922b18 RS |
1624 | #ifdef POLL_FOR_INPUT |
1625 | ||
284f4730 JB |
1626 | /* Handle an alarm once each second and read pending input |
1627 | so as to handle a C-g if it comces in. */ | |
1628 | ||
1629 | SIGTYPE | |
91c049d4 RS |
1630 | input_poll_signal (signalnum) /* If we don't have an argument, */ |
1631 | int signalnum; /* some compilers complain in signal calls. */ | |
284f4730 | 1632 | { |
87dd9b9b RS |
1633 | /* This causes the call to start_polling at the end |
1634 | to do its job. It also arranges for a quit or error | |
1635 | from within read_avail_input to resume polling. */ | |
1636 | poll_suppress_count++; | |
9ac0d9e0 JB |
1637 | if (interrupt_input_blocked == 0 |
1638 | && !waiting_for_input) | |
1639 | read_avail_input (0); | |
87dd9b9b RS |
1640 | /* Turn on the SIGALRM handler and request another alarm. */ |
1641 | start_polling (); | |
284f4730 JB |
1642 | } |
1643 | ||
1644 | #endif | |
1645 | ||
1646 | /* Begin signals to poll for input, if they are appropriate. | |
1647 | This function is called unconditionally from various places. */ | |
1648 | ||
07a59269 | 1649 | void |
284f4730 JB |
1650 | start_polling () |
1651 | { | |
1652 | #ifdef POLL_FOR_INPUT | |
34f04431 | 1653 | if (read_socket_hook && !interrupt_input) |
284f4730 JB |
1654 | { |
1655 | poll_suppress_count--; | |
1656 | if (poll_suppress_count == 0) | |
1657 | { | |
1658 | signal (SIGALRM, input_poll_signal); | |
1659 | polling_for_input = 1; | |
1660 | alarm (polling_period); | |
1661 | } | |
1662 | } | |
1663 | #endif | |
1664 | } | |
1665 | ||
1d3195db RS |
1666 | /* Nonzero if we are using polling to handle input asynchronously. */ |
1667 | ||
1668 | int | |
1669 | input_polling_used () | |
1670 | { | |
1671 | #ifdef POLL_FOR_INPUT | |
1672 | return read_socket_hook && !interrupt_input; | |
1673 | #else | |
1674 | return 0; | |
1675 | #endif | |
1676 | } | |
1677 | ||
284f4730 JB |
1678 | /* Turn off polling. */ |
1679 | ||
07a59269 | 1680 | void |
284f4730 JB |
1681 | stop_polling () |
1682 | { | |
1683 | #ifdef POLL_FOR_INPUT | |
34f04431 | 1684 | if (read_socket_hook && !interrupt_input) |
284f4730 JB |
1685 | { |
1686 | if (poll_suppress_count == 0) | |
1687 | { | |
1688 | polling_for_input = 0; | |
1689 | alarm (0); | |
1690 | } | |
1691 | poll_suppress_count++; | |
1692 | } | |
1693 | #endif | |
1694 | } | |
fe8aeef3 RS |
1695 | |
1696 | /* Set the value of poll_suppress_count to COUNT | |
1697 | and start or stop polling accordingly. */ | |
1698 | ||
1699 | void | |
1700 | set_poll_suppress_count (count) | |
1701 | int count; | |
1702 | { | |
1703 | #ifdef POLL_FOR_INPUT | |
1704 | if (count == 0 && poll_suppress_count != 0) | |
1705 | { | |
1706 | poll_suppress_count = 1; | |
1707 | start_polling (); | |
1708 | } | |
1709 | else if (count != 0 && poll_suppress_count == 0) | |
1710 | { | |
1711 | stop_polling (); | |
1712 | } | |
1713 | poll_suppress_count = count; | |
1714 | #endif | |
1715 | } | |
f4eef8b4 | 1716 | |
d0a57728 RS |
1717 | /* Bind polling_period to a value at least N. |
1718 | But don't decrease it. */ | |
1719 | ||
07a59269 | 1720 | void |
f4eef8b4 RS |
1721 | bind_polling_period (n) |
1722 | int n; | |
1723 | { | |
1724 | #ifdef POLL_FOR_INPUT | |
d0a57728 RS |
1725 | int new = polling_period; |
1726 | ||
1727 | if (n > new) | |
1728 | new = n; | |
1729 | ||
f4eef8b4 | 1730 | stop_polling (); |
d0a57728 RS |
1731 | specbind (Qpolling_period, make_number (new)); |
1732 | /* Start a new alarm with the new period. */ | |
f4eef8b4 RS |
1733 | start_polling (); |
1734 | #endif | |
1735 | } | |
284f4730 | 1736 | \f |
6da3dd3a RS |
1737 | /* Apply the control modifier to CHARACTER. */ |
1738 | ||
faf5e407 JB |
1739 | int |
1740 | make_ctrl_char (c) | |
1741 | int c; | |
1742 | { | |
d205953b JB |
1743 | /* Save the upper bits here. */ |
1744 | int upper = c & ~0177; | |
1745 | ||
1746 | c &= 0177; | |
1747 | ||
1748 | /* Everything in the columns containing the upper-case letters | |
1749 | denotes a control character. */ | |
1750 | if (c >= 0100 && c < 0140) | |
1751 | { | |
1752 | int oc = c; | |
1753 | c &= ~0140; | |
1754 | /* Set the shift modifier for a control char | |
1755 | made from a shifted letter. But only for letters! */ | |
1756 | if (oc >= 'A' && oc <= 'Z') | |
1757 | c |= shift_modifier; | |
1758 | } | |
1759 | ||
1760 | /* The lower-case letters denote control characters too. */ | |
1761 | else if (c >= 'a' && c <= 'z') | |
1762 | c &= ~0140; | |
1763 | ||
1764 | /* Include the bits for control and shift | |
1765 | only if the basic ASCII code can't indicate them. */ | |
1766 | else if (c >= ' ') | |
1767 | c |= ctrl_modifier; | |
1768 | ||
1769 | /* Replace the high bits. */ | |
1770 | c |= (upper & ~ctrl_modifier); | |
faf5e407 JB |
1771 | |
1772 | return c; | |
1773 | } | |
1774 | ||
1775 | ||
1776 | \f | |
284f4730 JB |
1777 | /* Input of single characters from keyboard */ |
1778 | ||
1779 | Lisp_Object print_help (); | |
1780 | static Lisp_Object kbd_buffer_get_event (); | |
e4fe371d | 1781 | static void record_char (); |
284f4730 | 1782 | |
c5fdd383 KH |
1783 | #ifdef MULTI_KBOARD |
1784 | static jmp_buf wrong_kboard_jmpbuf; | |
bded54dd | 1785 | #endif |
beecf6a1 | 1786 | |
284f4730 JB |
1787 | /* read a character from the keyboard; call the redisplay if needed */ |
1788 | /* commandflag 0 means do not do auto-saving, but do do redisplay. | |
1789 | -1 means do not do redisplay, but do do autosaving. | |
1790 | 1 means do both. */ | |
1791 | ||
7d6de002 RS |
1792 | /* The arguments MAPS and NMAPS are for menu prompting. |
1793 | MAPS is an array of keymaps; NMAPS is the length of MAPS. | |
1794 | ||
1795 | PREV_EVENT is the previous input event, or nil if we are reading | |
b638f328 RS |
1796 | the first event of a key sequence (or not reading a key sequence). |
1797 | If PREV_EVENT is t, that is a "magic" value that says | |
1798 | not to run input methods, but in other respects to act as if | |
1799 | not reading a key sequence. | |
7d6de002 | 1800 | |
83d68044 | 1801 | If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1 |
6569cc8d | 1802 | if we used a mouse menu to read the input, or zero otherwise. If |
83d68044 | 1803 | USED_MOUSE_MENU is null, we don't dereference it. |
dcc408a0 RS |
1804 | |
1805 | Value is t if we showed a menu and the user rejected it. */ | |
7d6de002 | 1806 | |
284f4730 | 1807 | Lisp_Object |
7d6de002 | 1808 | read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu) |
284f4730 | 1809 | int commandflag; |
7d6de002 RS |
1810 | int nmaps; |
1811 | Lisp_Object *maps; | |
1812 | Lisp_Object prev_event; | |
1813 | int *used_mouse_menu; | |
284f4730 | 1814 | { |
7c3bc944 | 1815 | Lisp_Object c; |
284f4730 | 1816 | int count; |
410d4de9 | 1817 | jmp_buf local_getcjmp; |
284f4730 | 1818 | jmp_buf save_jump; |
a1341f75 | 1819 | int key_already_recorded = 0; |
017c7cb6 | 1820 | Lisp_Object tem, save; |
7ee32cda | 1821 | Lisp_Object previous_echo_area_message; |
e4fe371d | 1822 | Lisp_Object also_record; |
7d18f9ae | 1823 | int reread; |
d5eecefb | 1824 | struct gcpro gcpro1, gcpro2; |
7c3bc944 | 1825 | |
e4fe371d | 1826 | also_record = Qnil; |
284f4730 | 1827 | |
71918b75 RS |
1828 | before_command_key_count = this_command_key_count; |
1829 | before_command_echo_length = echo_length (); | |
ef6661f7 | 1830 | c = Qnil; |
7ee32cda | 1831 | previous_echo_area_message = Qnil; |
71918b75 | 1832 | |
7ee32cda | 1833 | GCPRO2 (c, previous_echo_area_message); |
7c3bc944 | 1834 | |
7f07d5ca RS |
1835 | retry: |
1836 | ||
7d18f9ae RS |
1837 | reread = 0; |
1838 | if (CONSP (Vunread_post_input_method_events)) | |
284f4730 | 1839 | { |
7d18f9ae RS |
1840 | c = XCONS (Vunread_post_input_method_events)->car; |
1841 | Vunread_post_input_method_events | |
1842 | = XCONS (Vunread_post_input_method_events)->cdr; | |
284f4730 | 1843 | |
2479e91e RS |
1844 | /* Undo what read_char_x_menu_prompt did when it unread |
1845 | additional keys returned by Fx_popup_menu. */ | |
1846 | if (CONSP (c) | |
1847 | && (SYMBOLP (XCONS (c)->car) || INTEGERP (XCONS (c)->car)) | |
1848 | && NILP (XCONS (c)->cdr)) | |
1849 | c = XCONS (c)->car; | |
1850 | ||
7d18f9ae RS |
1851 | reread = 1; |
1852 | goto reread_first; | |
284f4730 JB |
1853 | } |
1854 | ||
86e5706b RS |
1855 | if (unread_command_char != -1) |
1856 | { | |
18cd2eeb | 1857 | XSETINT (c, unread_command_char); |
86e5706b RS |
1858 | unread_command_char = -1; |
1859 | ||
7d18f9ae RS |
1860 | reread = 1; |
1861 | goto reread_first; | |
1862 | } | |
1863 | ||
1864 | if (CONSP (Vunread_command_events)) | |
1865 | { | |
1866 | c = XCONS (Vunread_command_events)->car; | |
1867 | Vunread_command_events = XCONS (Vunread_command_events)->cdr; | |
1868 | ||
1869 | /* Undo what read_char_x_menu_prompt did when it unread | |
1870 | additional keys returned by Fx_popup_menu. */ | |
1871 | if (CONSP (c) | |
1872 | && (SYMBOLP (XCONS (c)->car) || INTEGERP (XCONS (c)->car)) | |
1873 | && NILP (XCONS (c)->cdr)) | |
1874 | c = XCONS (c)->car; | |
1875 | ||
1876 | reread = 1; | |
1877 | goto reread_for_input_method; | |
1878 | } | |
1879 | ||
1880 | if (CONSP (Vunread_input_method_events)) | |
1881 | { | |
1882 | c = XCONS (Vunread_input_method_events)->car; | |
1883 | Vunread_input_method_events = XCONS (Vunread_input_method_events)->cdr; | |
1884 | ||
1885 | /* Undo what read_char_x_menu_prompt did when it unread | |
1886 | additional keys returned by Fx_popup_menu. */ | |
1887 | if (CONSP (c) | |
1888 | && (SYMBOLP (XCONS (c)->car) || INTEGERP (XCONS (c)->car)) | |
1889 | && NILP (XCONS (c)->cdr)) | |
1890 | c = XCONS (c)->car; | |
1891 | reread = 1; | |
1892 | goto reread_for_input_method; | |
86e5706b RS |
1893 | } |
1894 | ||
71918b75 RS |
1895 | /* If there is no function key translated before |
1896 | reset-this-command-lengths takes effect, forget about it. */ | |
1897 | before_command_restore_flag = 0; | |
1898 | ||
284f4730 JB |
1899 | if (!NILP (Vexecuting_macro)) |
1900 | { | |
fce33686 JB |
1901 | /* We set this to Qmacro; since that's not a frame, nobody will |
1902 | try to switch frames on us, and the selected window will | |
1903 | remain unchanged. | |
1904 | ||
1905 | Since this event came from a macro, it would be misleading to | |
eb8c3be9 | 1906 | leave internal_last_event_frame set to wherever the last |
3c370943 JB |
1907 | real event came from. Normally, a switch-frame event selects |
1908 | internal_last_event_frame after each command is read, but | |
1909 | events read from a macro should never cause a new frame to be | |
1910 | selected. */ | |
4c52b668 | 1911 | Vlast_event_frame = internal_last_event_frame = Qmacro; |
fce33686 | 1912 | |
663258f2 JB |
1913 | /* Exit the macro if we are at the end. |
1914 | Also, some things replace the macro with t | |
1915 | to force an early exit. */ | |
1916 | if (EQ (Vexecuting_macro, Qt) | |
1917 | || executing_macro_index >= XFASTINT (Flength (Vexecuting_macro))) | |
284f4730 | 1918 | { |
18cd2eeb | 1919 | XSETINT (c, -1); |
7c3bc944 | 1920 | RETURN_UNGCPRO (c); |
284f4730 | 1921 | } |
df0f2ba1 | 1922 | |
284f4730 | 1923 | c = Faref (Vexecuting_macro, make_number (executing_macro_index)); |
8c18cbfb | 1924 | if (STRINGP (Vexecuting_macro) |
86e5706b | 1925 | && (XINT (c) & 0x80)) |
bb9e9bed | 1926 | XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80)); |
86e5706b | 1927 | |
284f4730 JB |
1928 | executing_macro_index++; |
1929 | ||
1930 | goto from_macro; | |
1931 | } | |
1932 | ||
cd21b839 JB |
1933 | if (!NILP (unread_switch_frame)) |
1934 | { | |
1935 | c = unread_switch_frame; | |
1936 | unread_switch_frame = Qnil; | |
1937 | ||
1938 | /* This event should make it into this_command_keys, and get echoed | |
7d18f9ae | 1939 | again, so we do not set `reread'. */ |
f4255cd1 | 1940 | goto reread_first; |
cd21b839 JB |
1941 | } |
1942 | ||
adc1d5c8 | 1943 | /* if redisplay was requested */ |
6e4e64a8 RS |
1944 | if (commandflag >= 0) |
1945 | { | |
adc1d5c8 RS |
1946 | /* If there is pending input, process any events which are not |
1947 | user-visible, such as X selection_request events. */ | |
6e4e64a8 RS |
1948 | if (input_pending |
1949 | || detect_input_pending_run_timers (0)) | |
adc1d5c8 | 1950 | swallow_events (0); /* may clear input_pending */ |
6e4e64a8 | 1951 | |
adc1d5c8 RS |
1952 | /* Redisplay if no pending input. */ |
1953 | while (!input_pending) | |
1954 | { | |
1955 | redisplay (); | |
1956 | ||
1957 | if (!input_pending) | |
1958 | /* Normal case: no input arrived during redisplay. */ | |
1959 | break; | |
1960 | ||
1961 | /* Input arrived and pre-empted redisplay. | |
1962 | Process any events which are not user-visible. */ | |
1963 | swallow_events (0); | |
1964 | /* If that cleared input_pending, try again to redisplay. */ | |
1965 | } | |
6e4e64a8 | 1966 | } |
e9bf89a0 | 1967 | |
410d4de9 | 1968 | /* Message turns off echoing unless more keystrokes turn it on again. */ |
985f9f66 GM |
1969 | if (/* There is a current message. */ |
1970 | !NILP (echo_area_buffer[0]) | |
1971 | /* And we're not echoing from this kboard. */ | |
1972 | && echo_kboard != current_kboard | |
1973 | /* And it's either not ok to echo (ok_to_echo == NULL), or the | |
1974 | last char echoed was from a different kboard. */ | |
1975 | && ok_to_echo_at_next_pause != echo_kboard) | |
7ee32cda | 1976 | cancel_echoing (); |
410d4de9 RS |
1977 | else |
1978 | /* If already echoing, continue. */ | |
1979 | echo_dash (); | |
284f4730 | 1980 | |
410d4de9 RS |
1981 | /* Try reading a character via menu prompting in the minibuf. |
1982 | Try this before the sit-for, because the sit-for | |
1983 | would do the wrong thing if we are supposed to do | |
1984 | menu prompting. If EVENT_HAS_PARAMETERS then we are reading | |
1985 | after a mouse event so don't try a minibuf menu. */ | |
1986 | c = Qnil; | |
1987 | if (nmaps > 0 && INTERACTIVE | |
1988 | && !NILP (prev_event) && ! EVENT_HAS_PARAMETERS (prev_event) | |
1989 | /* Don't bring up a menu if we already have another event. */ | |
1990 | && NILP (Vunread_command_events) | |
1991 | && unread_command_char < 0 | |
4ec4ed6a | 1992 | && !detect_input_pending_run_timers (0)) |
410d4de9 RS |
1993 | { |
1994 | c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps); | |
1995 | if (! NILP (c)) | |
1996 | { | |
1997 | key_already_recorded = 1; | |
1998 | goto non_reread_1; | |
1999 | } | |
2000 | } | |
284f4730 | 2001 | |
410d4de9 RS |
2002 | /* Make a longjmp point for quits to use, but don't alter getcjmp just yet. |
2003 | We will do that below, temporarily for short sections of code, | |
2004 | when appropriate. local_getcjmp must be in effect | |
2005 | around any call to sit_for or kbd_buffer_get_event; | |
2006 | it *must not* be in effect when we call redisplay. */ | |
284f4730 | 2007 | |
410d4de9 | 2008 | if (_setjmp (local_getcjmp)) |
284f4730 | 2009 | { |
18cd2eeb | 2010 | XSETINT (c, quit_char); |
4c52b668 KH |
2011 | XSETFRAME (internal_last_event_frame, selected_frame); |
2012 | Vlast_event_frame = internal_last_event_frame; | |
04904c29 RS |
2013 | /* If we report the quit char as an event, |
2014 | don't do so more than once. */ | |
2015 | if (!NILP (Vinhibit_quit)) | |
2016 | Vquit_flag = Qnil; | |
284f4730 | 2017 | |
c5fdd383 | 2018 | #ifdef MULTI_KBOARD |
df0f2ba1 | 2019 | { |
c5fdd383 KH |
2020 | KBOARD *kb = FRAME_KBOARD (selected_frame); |
2021 | if (kb != current_kboard) | |
df0f2ba1 | 2022 | { |
c5fdd383 | 2023 | Lisp_Object *tailp = &kb->kbd_queue; |
1e8bd3da RS |
2024 | /* We shouldn't get here if we were in single-kboard mode! */ |
2025 | if (single_kboard) | |
df0f2ba1 KH |
2026 | abort (); |
2027 | while (CONSP (*tailp)) | |
2028 | tailp = &XCONS (*tailp)->cdr; | |
2029 | if (!NILP (*tailp)) | |
2030 | abort (); | |
2031 | *tailp = Fcons (c, Qnil); | |
c5fdd383 KH |
2032 | kb->kbd_queue_has_data = 1; |
2033 | current_kboard = kb; | |
ef6661f7 RS |
2034 | /* This is going to exit from read_char |
2035 | so we had better get rid of this frame's stuff. */ | |
2036 | UNGCPRO; | |
c5fdd383 | 2037 | longjmp (wrong_kboard_jmpbuf, 1); |
df0f2ba1 KH |
2038 | } |
2039 | } | |
2040 | #endif | |
284f4730 JB |
2041 | goto non_reread; |
2042 | } | |
2043 | ||
d9d4c147 KH |
2044 | timer_start_idle (); |
2045 | ||
284f4730 JB |
2046 | /* If in middle of key sequence and minibuffer not active, |
2047 | start echoing if enough time elapses. */ | |
410d4de9 | 2048 | |
7ee32cda GM |
2049 | if (minibuf_level == 0 |
2050 | && !current_kboard->immediate_echo | |
6c6083a9 | 2051 | && this_command_key_count > 0 |
27203ead | 2052 | && ! noninteractive |
284f4730 | 2053 | && echo_keystrokes > 0 |
985f9f66 GM |
2054 | && (/* No message. */ |
2055 | NILP (echo_area_buffer[0]) | |
2056 | /* Or empty message. */ | |
2057 | || (BUF_BEG (XBUFFER (echo_area_buffer[0])) | |
2058 | == BUF_Z (XBUFFER (echo_area_buffer[0]))) | |
2059 | /* Or already echoing from same kboard. */ | |
2060 | || (echo_kboard && ok_to_echo_at_next_pause == echo_kboard) | |
2061 | /* Or not echoing before and echoing allowed. */ | |
2062 | || (!echo_kboard && ok_to_echo_at_next_pause))) | |
284f4730 JB |
2063 | { |
2064 | Lisp_Object tem0; | |
985f9f66 | 2065 | |
7d6de002 RS |
2066 | /* After a mouse event, start echoing right away. |
2067 | This is because we are probably about to display a menu, | |
2068 | and we don't want to delay before doing so. */ | |
dbc4e1c1 | 2069 | if (EVENT_HAS_PARAMETERS (prev_event)) |
3dbd9ee4 | 2070 | echo_now (); |
7d6de002 RS |
2071 | else |
2072 | { | |
410d4de9 RS |
2073 | save_getcjmp (save_jump); |
2074 | restore_getcjmp (local_getcjmp); | |
41365083 | 2075 | tem0 = sit_for (echo_keystrokes, 0, 1, 1, 0); |
410d4de9 | 2076 | restore_getcjmp (save_jump); |
303b5b3f RS |
2077 | if (EQ (tem0, Qt) |
2078 | && ! CONSP (Vunread_command_events)) | |
3dbd9ee4 | 2079 | echo_now (); |
7d6de002 | 2080 | } |
284f4730 JB |
2081 | } |
2082 | ||
410d4de9 | 2083 | /* Maybe auto save due to number of keystrokes. */ |
284f4730 JB |
2084 | |
2085 | if (commandflag != 0 | |
2086 | && auto_save_interval > 0 | |
c43b1734 | 2087 | && num_nonmacro_input_events - last_auto_save > max (auto_save_interval, 20) |
4ec4ed6a | 2088 | && !detect_input_pending_run_timers (0)) |
284f4730 | 2089 | { |
284f4730 | 2090 | Fdo_auto_save (Qnil, Qnil); |
ef8fd672 RS |
2091 | /* Hooks can actually change some buffers in auto save. */ |
2092 | redisplay (); | |
284f4730 JB |
2093 | } |
2094 | ||
8150596a | 2095 | /* Try reading using an X menu. |
24597608 RS |
2096 | This is never confused with reading using the minibuf |
2097 | because the recursive call of read_char in read_char_minibuf_menu_prompt | |
2098 | does not pass on any keymaps. */ | |
410d4de9 | 2099 | |
24597608 | 2100 | if (nmaps > 0 && INTERACTIVE |
5a8d99e0 KH |
2101 | && !NILP (prev_event) |
2102 | && EVENT_HAS_PARAMETERS (prev_event) | |
2103 | && !EQ (XCONS (prev_event)->car, Qmenu_bar) | |
9ea173e8 | 2104 | && !EQ (XCONS (prev_event)->car, Qtool_bar) |
24597608 RS |
2105 | /* Don't bring up a menu if we already have another event. */ |
2106 | && NILP (Vunread_command_events) | |
b8556aee | 2107 | && unread_command_char < 0) |
8eb4d8ef RS |
2108 | { |
2109 | c = read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu); | |
2110 | ||
2111 | /* Now that we have read an event, Emacs is not idle. */ | |
2112 | timer_stop_idle (); | |
2113 | ||
7c3bc944 | 2114 | RETURN_UNGCPRO (c); |
8eb4d8ef | 2115 | } |
7d6de002 | 2116 | |
410d4de9 RS |
2117 | /* Maybe autosave and/or garbage collect due to idleness. */ |
2118 | ||
26c1639e | 2119 | if (INTERACTIVE && NILP (c)) |
7d6de002 RS |
2120 | { |
2121 | int delay_level, buffer_size; | |
2122 | ||
410d4de9 RS |
2123 | /* Slow down auto saves logarithmically in size of current buffer, |
2124 | and garbage collect while we're at it. */ | |
7d6de002 RS |
2125 | if (! MINI_WINDOW_P (XWINDOW (selected_window))) |
2126 | last_non_minibuf_size = Z - BEG; | |
2127 | buffer_size = (last_non_minibuf_size >> 8) + 1; | |
2128 | delay_level = 0; | |
2129 | while (buffer_size > 64) | |
2130 | delay_level++, buffer_size -= buffer_size >> 2; | |
2131 | if (delay_level < 4) delay_level = 4; | |
2132 | /* delay_level is 4 for files under around 50k, 7 at 100k, | |
2133 | 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */ | |
2134 | ||
2135 | /* Auto save if enough time goes by without input. */ | |
2136 | if (commandflag != 0 | |
c43b1734 | 2137 | && num_nonmacro_input_events > last_auto_save |
8c18cbfb | 2138 | && INTEGERP (Vauto_save_timeout) |
7d6de002 RS |
2139 | && XINT (Vauto_save_timeout) > 0) |
2140 | { | |
2141 | Lisp_Object tem0; | |
410d4de9 RS |
2142 | |
2143 | save_getcjmp (save_jump); | |
2144 | restore_getcjmp (local_getcjmp); | |
d9d4c147 | 2145 | tem0 = sit_for (delay_level * XFASTINT (Vauto_save_timeout) / 4, |
41365083 | 2146 | 0, 1, 1, 0); |
410d4de9 RS |
2147 | restore_getcjmp (save_jump); |
2148 | ||
303b5b3f RS |
2149 | if (EQ (tem0, Qt) |
2150 | && ! CONSP (Vunread_command_events)) | |
7d6de002 | 2151 | { |
7d6de002 | 2152 | Fdo_auto_save (Qnil, Qnil); |
7d6de002 RS |
2153 | |
2154 | /* If we have auto-saved and there is still no input | |
2155 | available, garbage collect if there has been enough | |
2156 | consing going on to make it worthwhile. */ | |
4ec4ed6a | 2157 | if (!detect_input_pending_run_timers (0) |
7d6de002 | 2158 | && consing_since_gc > gc_cons_threshold / 2) |
ef8fd672 | 2159 | Fgarbage_collect (); |
410d4de9 | 2160 | |
ef8fd672 | 2161 | redisplay (); |
7d6de002 RS |
2162 | } |
2163 | } | |
2164 | } | |
284f4730 | 2165 | |
303b5b3f RS |
2166 | /* If this has become non-nil here, it has been set by a timer |
2167 | or sentinel or filter. */ | |
2168 | if (CONSP (Vunread_command_events)) | |
2169 | { | |
2170 | c = XCONS (Vunread_command_events)->car; | |
2171 | Vunread_command_events = XCONS (Vunread_command_events)->cdr; | |
2172 | } | |
2173 | ||
410d4de9 RS |
2174 | /* Read something from current KBOARD's side queue, if possible. */ |
2175 | ||
beecf6a1 | 2176 | if (NILP (c)) |
1e12dd87 | 2177 | { |
c5fdd383 | 2178 | if (current_kboard->kbd_queue_has_data) |
beecf6a1 | 2179 | { |
c5fdd383 | 2180 | if (!CONSP (current_kboard->kbd_queue)) |
4524b161 | 2181 | abort (); |
c5fdd383 KH |
2182 | c = XCONS (current_kboard->kbd_queue)->car; |
2183 | current_kboard->kbd_queue | |
2184 | = XCONS (current_kboard->kbd_queue)->cdr; | |
2185 | if (NILP (current_kboard->kbd_queue)) | |
2186 | current_kboard->kbd_queue_has_data = 0; | |
d9d4c147 | 2187 | input_pending = readable_events (0); |
4c52b668 KH |
2188 | if (EVENT_HAS_PARAMETERS (c) |
2189 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qswitch_frame)) | |
2190 | internal_last_event_frame = XCONS (XCONS (c)->cdr)->car; | |
2191 | Vlast_event_frame = internal_last_event_frame; | |
beecf6a1 | 2192 | } |
1e8bd3da RS |
2193 | } |
2194 | ||
c5fdd383 | 2195 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
2196 | /* If current_kboard's side queue is empty check the other kboards. |
2197 | If one of them has data that we have not yet seen here, | |
2198 | switch to it and process the data waiting for it. | |
2199 | ||
2200 | Note: if the events queued up for another kboard | |
2201 | have already been seen here, and therefore are not a complete command, | |
2202 | the kbd_queue_has_data field is 0, so we skip that kboard here. | |
2203 | That's to avoid an infinite loop switching between kboards here. */ | |
2204 | if (NILP (c) && !single_kboard) | |
2205 | { | |
2206 | KBOARD *kb; | |
2207 | for (kb = all_kboards; kb; kb = kb->next_kboard) | |
2208 | if (kb->kbd_queue_has_data) | |
2209 | { | |
2210 | current_kboard = kb; | |
ef6661f7 RS |
2211 | /* This is going to exit from read_char |
2212 | so we had better get rid of this frame's stuff. */ | |
2213 | UNGCPRO; | |
1e8bd3da RS |
2214 | longjmp (wrong_kboard_jmpbuf, 1); |
2215 | } | |
2216 | } | |
df0f2ba1 KH |
2217 | #endif |
2218 | ||
410d4de9 RS |
2219 | wrong_kboard: |
2220 | ||
2221 | stop_polling (); | |
2222 | ||
1e8bd3da RS |
2223 | /* Finally, we read from the main queue, |
2224 | and if that gives us something we can't use yet, we put it on the | |
2225 | appropriate side queue and try again. */ | |
410d4de9 | 2226 | |
1e8bd3da RS |
2227 | if (NILP (c)) |
2228 | { | |
2229 | KBOARD *kb; | |
2230 | ||
1e8bd3da | 2231 | /* Actually read a character, waiting if necessary. */ |
410d4de9 RS |
2232 | save_getcjmp (save_jump); |
2233 | restore_getcjmp (local_getcjmp); | |
83d68044 | 2234 | c = kbd_buffer_get_event (&kb, used_mouse_menu); |
410d4de9 RS |
2235 | restore_getcjmp (save_jump); |
2236 | ||
c5fdd383 | 2237 | #ifdef MULTI_KBOARD |
410d4de9 | 2238 | if (! NILP (c) && (kb != current_kboard)) |
1e8bd3da RS |
2239 | { |
2240 | Lisp_Object *tailp = &kb->kbd_queue; | |
2241 | while (CONSP (*tailp)) | |
2242 | tailp = &XCONS (*tailp)->cdr; | |
2243 | if (!NILP (*tailp)) | |
2244 | abort (); | |
2245 | *tailp = Fcons (c, Qnil); | |
2246 | kb->kbd_queue_has_data = 1; | |
46b84797 | 2247 | c = Qnil; |
1e8bd3da RS |
2248 | if (single_kboard) |
2249 | goto wrong_kboard; | |
2250 | current_kboard = kb; | |
ef6661f7 RS |
2251 | /* This is going to exit from read_char |
2252 | so we had better get rid of this frame's stuff. */ | |
2253 | UNGCPRO; | |
1e8bd3da | 2254 | longjmp (wrong_kboard_jmpbuf, 1); |
df0f2ba1 | 2255 | } |
1e8bd3da | 2256 | #endif |
beecf6a1 | 2257 | } |
1e8bd3da | 2258 | |
284f4730 | 2259 | /* Terminate Emacs in batch mode if at eof. */ |
8c18cbfb | 2260 | if (noninteractive && INTEGERP (c) && XINT (c) < 0) |
284f4730 JB |
2261 | Fkill_emacs (make_number (1)); |
2262 | ||
8c18cbfb | 2263 | if (INTEGERP (c)) |
80645119 JB |
2264 | { |
2265 | /* Add in any extra modifiers, where appropriate. */ | |
2266 | if ((extra_keyboard_modifiers & CHAR_CTL) | |
2267 | || ((extra_keyboard_modifiers & 0177) < ' ' | |
2268 | && (extra_keyboard_modifiers & 0177) != 0)) | |
faf5e407 | 2269 | XSETINT (c, make_ctrl_char (XINT (c))); |
80645119 JB |
2270 | |
2271 | /* Transfer any other modifier bits directly from | |
2272 | extra_keyboard_modifiers to c. Ignore the actual character code | |
2273 | in the low 16 bits of extra_keyboard_modifiers. */ | |
b8d9050d | 2274 | XSETINT (c, XINT (c) | (extra_keyboard_modifiers & ~0xff7f & ~CHAR_CTL)); |
80645119 | 2275 | } |
9fa4395d | 2276 | |
284f4730 JB |
2277 | non_reread: |
2278 | ||
2fb9049e | 2279 | timer_stop_idle (); |
d9d4c147 | 2280 | |
284f4730 JB |
2281 | start_polling (); |
2282 | ||
410d4de9 RS |
2283 | if (NILP (c)) |
2284 | { | |
2285 | if (commandflag >= 0 | |
4ec4ed6a | 2286 | && !input_pending && !detect_input_pending_run_timers (0)) |
410d4de9 RS |
2287 | redisplay (); |
2288 | ||
2289 | goto wrong_kboard; | |
2290 | } | |
2291 | ||
2292 | non_reread_1: | |
2293 | ||
dfd11da7 | 2294 | /* Buffer switch events are only for internal wakeups |
7c3bc944 RS |
2295 | so don't show them to the user. |
2296 | Also, don't record a key if we already did. */ | |
2297 | if (BUFFERP (c) || key_already_recorded) | |
2298 | RETURN_UNGCPRO (c); | |
a1341f75 | 2299 | |
7f07d5ca RS |
2300 | /* Process special events within read_char |
2301 | and loop around to read another event. */ | |
017c7cb6 RS |
2302 | save = Vquit_flag; |
2303 | Vquit_flag = Qnil; | |
7f07d5ca RS |
2304 | tem = get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map, 0, 0), |
2305 | c, 0, 0), 1); | |
017c7cb6 | 2306 | Vquit_flag = save; |
7f07d5ca RS |
2307 | |
2308 | if (!NILP (tem)) | |
2309 | { | |
ba8dfba8 RS |
2310 | int was_locked = single_kboard; |
2311 | ||
7f07d5ca | 2312 | last_input_char = c; |
158f7532 | 2313 | Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt); |
ba8dfba8 RS |
2314 | |
2315 | /* Resume allowing input from any kboard, if that was true before. */ | |
2316 | if (!was_locked) | |
2317 | any_kboard_state (); | |
2318 | ||
7f07d5ca RS |
2319 | goto retry; |
2320 | } | |
2321 | ||
284f4730 | 2322 | /* Handle things that only apply to characters. */ |
8c18cbfb | 2323 | if (INTEGERP (c)) |
284f4730 JB |
2324 | { |
2325 | /* If kbd_buffer_get_event gave us an EOF, return that. */ | |
86e5706b | 2326 | if (XINT (c) == -1) |
7c3bc944 | 2327 | RETURN_UNGCPRO (c); |
284f4730 | 2328 | |
301738ed RS |
2329 | if ((STRINGP (Vkeyboard_translate_table) |
2330 | && XSTRING (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) | |
2331 | || (VECTORP (Vkeyboard_translate_table) | |
2332 | && XVECTOR (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) | |
2333 | || (CHAR_TABLE_P (Vkeyboard_translate_table) | |
2334 | && CHAR_TABLE_ORDINARY_SLOTS > (unsigned) XFASTINT (c))) | |
f9414d62 RS |
2335 | { |
2336 | Lisp_Object d; | |
2337 | d = Faref (Vkeyboard_translate_table, c); | |
2338 | /* nil in keyboard-translate-table means no translation. */ | |
2339 | if (!NILP (d)) | |
2340 | c = d; | |
2341 | } | |
284f4730 JB |
2342 | } |
2343 | ||
e4fe371d RS |
2344 | /* If this event is a mouse click in the menu bar, |
2345 | return just menu-bar for now. Modify the mouse click event | |
2346 | so we won't do this twice, then queue it up. */ | |
2347 | if (EVENT_HAS_PARAMETERS (c) | |
2348 | && CONSP (XCONS (c)->cdr) | |
2349 | && CONSP (EVENT_START (c)) | |
2350 | && CONSP (XCONS (EVENT_START (c))->cdr)) | |
284f4730 | 2351 | { |
e4fe371d | 2352 | Lisp_Object posn; |
284f4730 | 2353 | |
e4fe371d RS |
2354 | posn = POSN_BUFFER_POSN (EVENT_START (c)); |
2355 | /* Handle menu-bar events: | |
2356 | insert the dummy prefix event `menu-bar'. */ | |
9ea173e8 | 2357 | if (EQ (posn, Qmenu_bar) || EQ (posn, Qtool_bar)) |
e4fe371d RS |
2358 | { |
2359 | /* Change menu-bar to (menu-bar) as the event "position". */ | |
2360 | POSN_BUFFER_POSN (EVENT_START (c)) = Fcons (posn, Qnil); | |
284f4730 | 2361 | |
e4fe371d RS |
2362 | also_record = c; |
2363 | Vunread_command_events = Fcons (c, Vunread_command_events); | |
2364 | c = posn; | |
284f4730 | 2365 | } |
284f4730 JB |
2366 | } |
2367 | ||
7d18f9ae RS |
2368 | /* Store these characters into recent_keys, the dribble file if any, |
2369 | and the keyboard macro being defined, if any. */ | |
e4fe371d RS |
2370 | record_char (c); |
2371 | if (! NILP (also_record)) | |
2372 | record_char (also_record); | |
51172b6d | 2373 | |
d5eecefb RS |
2374 | /* Wipe the echo area. |
2375 | But first, if we are about to use an input method, | |
2376 | save the echo area contents for it to refer to. */ | |
2377 | if (INTEGERP (c) | |
2378 | && ! NILP (Vinput_method_function) | |
2379 | && (unsigned) XINT (c) >= ' ' | |
2380 | && (unsigned) XINT (c) < 127) | |
7ee32cda GM |
2381 | { |
2382 | previous_echo_area_message = Fcurrent_message (); | |
2383 | Vinput_method_previous_message = previous_echo_area_message; | |
2384 | } | |
d5eecefb RS |
2385 | |
2386 | /* Now wipe the echo area. */ | |
985f9f66 | 2387 | if (!NILP (echo_area_buffer[0])) |
d5eecefb | 2388 | safe_run_hooks (Qecho_area_clear_hook); |
985f9f66 | 2389 | clear_message (1, 0); |
d5eecefb | 2390 | |
7d18f9ae | 2391 | reread_for_input_method: |
284f4730 | 2392 | from_macro: |
7d18f9ae | 2393 | /* Pass this to the input method, if appropriate. */ |
d5eecefb RS |
2394 | if (INTEGERP (c) |
2395 | && ! NILP (Vinput_method_function) | |
b638f328 RS |
2396 | /* Don't run the input method within a key sequence, |
2397 | after the first event of the key sequence. */ | |
2398 | && NILP (prev_event) | |
d5eecefb RS |
2399 | && (unsigned) XINT (c) >= ' ' |
2400 | && (unsigned) XINT (c) < 127) | |
2401 | { | |
2402 | Lisp_Object keys; | |
6e5742a0 | 2403 | int key_count; |
d5eecefb | 2404 | struct gcpro gcpro1; |
b638f328 | 2405 | int count = specpdl_ptr - specpdl; |
d5eecefb | 2406 | |
6e5742a0 RS |
2407 | /* Save the echo status. */ |
2408 | int saved_immediate_echo = current_kboard->immediate_echo; | |
985f9f66 | 2409 | struct kboard *saved_ok_to_echo = ok_to_echo_at_next_pause; |
6e5742a0 RS |
2410 | int saved_echo_after_prompt = current_kboard->echo_after_prompt; |
2411 | ||
2412 | if (before_command_restore_flag) | |
2413 | { | |
2414 | this_command_key_count = before_command_key_count_1; | |
2415 | if (this_command_key_count < this_single_command_key_start) | |
2416 | this_single_command_key_start = this_command_key_count; | |
2417 | echo_truncate (before_command_echo_length_1); | |
2418 | before_command_restore_flag = 0; | |
2419 | } | |
2420 | ||
2421 | /* Save the this_command_keys status. */ | |
2422 | key_count = this_command_key_count; | |
2423 | ||
2424 | if (key_count > 0) | |
2425 | keys = Fcopy_sequence (this_command_keys); | |
2426 | else | |
2427 | keys = Qnil; | |
d5eecefb | 2428 | GCPRO1 (keys); |
6e5742a0 RS |
2429 | |
2430 | /* Clear out this_command_keys. */ | |
2431 | this_command_key_count = 0; | |
2432 | ||
2433 | /* Now wipe the echo area. */ | |
985f9f66 | 2434 | if (!NILP (echo_area_buffer[0])) |
6e5742a0 | 2435 | safe_run_hooks (Qecho_area_clear_hook); |
985f9f66 | 2436 | clear_message (1, 0); |
6e5742a0 RS |
2437 | echo_truncate (0); |
2438 | ||
b638f328 RS |
2439 | /* If we are not reading a key sequence, |
2440 | never use the echo area. */ | |
2441 | if (maps == 0) | |
2442 | { | |
b638f328 RS |
2443 | specbind (Qinput_method_use_echo_area, Qt); |
2444 | } | |
2445 | ||
6e5742a0 | 2446 | /* Call the input method. */ |
d5eecefb | 2447 | tem = call1 (Vinput_method_function, c); |
b638f328 RS |
2448 | |
2449 | tem = unbind_to (count, tem); | |
2450 | ||
6e5742a0 RS |
2451 | /* Restore the saved echoing state |
2452 | and this_command_keys state. */ | |
2453 | this_command_key_count = key_count; | |
2454 | if (key_count > 0) | |
2455 | this_command_keys = keys; | |
2456 | ||
2457 | cancel_echoing (); | |
2458 | ok_to_echo_at_next_pause = saved_ok_to_echo; | |
2459 | current_kboard->echo_after_prompt = saved_echo_after_prompt; | |
2460 | if (saved_immediate_echo) | |
2461 | echo_now (); | |
2462 | ||
d5eecefb | 2463 | UNGCPRO; |
6e5742a0 | 2464 | |
d5eecefb RS |
2465 | /* The input method can return no events. */ |
2466 | if (! CONSP (tem)) | |
7d18f9ae | 2467 | { |
d5eecefb | 2468 | /* Bring back the previous message, if any. */ |
7ee32cda GM |
2469 | if (! NILP (previous_echo_area_message)) |
2470 | message_with_string ("%s", previous_echo_area_message, 0); | |
d5eecefb | 2471 | goto retry; |
7d18f9ae | 2472 | } |
d5eecefb RS |
2473 | /* It returned one event or more. */ |
2474 | c = XCONS (tem)->car; | |
2475 | Vunread_post_input_method_events | |
2476 | = nconc2 (XCONS (tem)->cdr, Vunread_post_input_method_events); | |
7d18f9ae | 2477 | } |
7c3bc944 | 2478 | |
7d18f9ae | 2479 | reread_first: |
284f4730 | 2480 | |
7ee32cda GM |
2481 | /* Display help if not echoing. */ |
2482 | if (CONSP (c) | |
2483 | && EQ (XCAR (c), Qhelp_echo)) | |
2484 | { | |
2485 | Lisp_Object msg = XCDR (XCDR (c)); | |
2486 | ||
2487 | if (!NILP (Vshow_help_function)) | |
2488 | call1 (Vshow_help_function, msg); | |
2489 | else if (!echoing && !MINI_WINDOW_P (XWINDOW (selected_window))) | |
2490 | { | |
2491 | if (STRINGP (msg)) | |
2492 | message3_nolog (msg, XSTRING (msg)->size, STRING_MULTIBYTE (msg)); | |
2493 | else | |
2494 | message (0); | |
2495 | } | |
2496 | ||
2497 | goto retry; | |
2498 | } | |
2499 | ||
7d18f9ae | 2500 | if (this_command_key_count == 0 || ! reread) |
e4fe371d | 2501 | { |
7d18f9ae RS |
2502 | before_command_key_count = this_command_key_count; |
2503 | before_command_echo_length = echo_length (); | |
2504 | ||
2505 | /* Don't echo mouse motion events. */ | |
2506 | if (echo_keystrokes | |
2507 | && ! (EVENT_HAS_PARAMETERS (c) | |
2508 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_movement))) | |
2509 | { | |
2510 | echo_char (c); | |
2511 | if (! NILP (also_record)) | |
2512 | echo_char (also_record); | |
2513 | /* Once we reread a character, echoing can happen | |
2514 | the next time we pause to read a new one. */ | |
985f9f66 | 2515 | ok_to_echo_at_next_pause = current_kboard; |
7d18f9ae RS |
2516 | } |
2517 | ||
2518 | /* Record this character as part of the current key. */ | |
2519 | add_command_key (c); | |
e4fe371d | 2520 | if (! NILP (also_record)) |
7d18f9ae | 2521 | add_command_key (also_record); |
e4fe371d | 2522 | } |
b8556aee | 2523 | |
284f4730 | 2524 | last_input_char = c; |
c43b1734 | 2525 | num_input_events++; |
284f4730 JB |
2526 | |
2527 | /* Process the help character specially if enabled */ | |
ecb7cb34 | 2528 | if (!NILP (Vhelp_form) && help_char_p (c)) |
284f4730 JB |
2529 | { |
2530 | Lisp_Object tem0; | |
2531 | count = specpdl_ptr - specpdl; | |
2532 | ||
2533 | record_unwind_protect (Fset_window_configuration, | |
2534 | Fcurrent_window_configuration (Qnil)); | |
2535 | ||
2536 | tem0 = Feval (Vhelp_form); | |
8c18cbfb | 2537 | if (STRINGP (tem0)) |
284f4730 JB |
2538 | internal_with_output_to_temp_buffer ("*Help*", print_help, tem0); |
2539 | ||
2540 | cancel_echoing (); | |
3cb81011 KH |
2541 | do |
2542 | c = read_char (0, 0, 0, Qnil, 0); | |
8c18cbfb | 2543 | while (BUFFERP (c)); |
ff11dfa1 | 2544 | /* Remove the help from the frame */ |
284f4730 | 2545 | unbind_to (count, Qnil); |
410d4de9 | 2546 | |
284f4730 JB |
2547 | redisplay (); |
2548 | if (EQ (c, make_number (040))) | |
2549 | { | |
2550 | cancel_echoing (); | |
3cb81011 KH |
2551 | do |
2552 | c = read_char (0, 0, 0, Qnil, 0); | |
8c18cbfb | 2553 | while (BUFFERP (c)); |
284f4730 JB |
2554 | } |
2555 | } | |
2556 | ||
7c3bc944 | 2557 | RETURN_UNGCPRO (c); |
284f4730 JB |
2558 | } |
2559 | ||
8eb4d8ef RS |
2560 | /* Record a key that came from a mouse menu. |
2561 | Record it for echoing, for this-command-keys, and so on. */ | |
2562 | ||
2563 | static void | |
2564 | record_menu_key (c) | |
2565 | Lisp_Object c; | |
2566 | { | |
2567 | /* Wipe the echo area. */ | |
985f9f66 | 2568 | clear_message (1, 0); |
8eb4d8ef RS |
2569 | |
2570 | record_char (c); | |
2571 | ||
2572 | before_command_key_count = this_command_key_count; | |
2573 | before_command_echo_length = echo_length (); | |
2574 | ||
2575 | /* Don't echo mouse motion events. */ | |
2576 | if (echo_keystrokes) | |
2577 | { | |
2578 | echo_char (c); | |
2579 | ||
2580 | /* Once we reread a character, echoing can happen | |
2581 | the next time we pause to read a new one. */ | |
2582 | ok_to_echo_at_next_pause = 0; | |
2583 | } | |
2584 | ||
2585 | /* Record this character as part of the current key. */ | |
2586 | add_command_key (c); | |
2587 | ||
2588 | /* Re-reading in the middle of a command */ | |
2589 | last_input_char = c; | |
c43b1734 | 2590 | num_input_events++; |
8eb4d8ef RS |
2591 | } |
2592 | ||
ecb7cb34 KH |
2593 | /* Return 1 if should recognize C as "the help character". */ |
2594 | ||
2595 | int | |
2596 | help_char_p (c) | |
2597 | Lisp_Object c; | |
2598 | { | |
2599 | Lisp_Object tail; | |
2600 | ||
2601 | if (EQ (c, Vhelp_char)) | |
2602 | return 1; | |
2603 | for (tail = Vhelp_event_list; CONSP (tail); tail = XCONS (tail)->cdr) | |
2604 | if (EQ (c, XCONS (tail)->car)) | |
2605 | return 1; | |
2606 | return 0; | |
2607 | } | |
2608 | ||
e4fe371d RS |
2609 | /* Record the input event C in various ways. */ |
2610 | ||
2611 | static void | |
2612 | record_char (c) | |
2613 | Lisp_Object c; | |
2614 | { | |
2615 | total_keys++; | |
2616 | XVECTOR (recent_keys)->contents[recent_keys_index] = c; | |
2617 | if (++recent_keys_index >= NUM_RECENT_KEYS) | |
2618 | recent_keys_index = 0; | |
2619 | ||
2620 | /* Write c to the dribble file. If c is a lispy event, write | |
2621 | the event's symbol to the dribble file, in <brackets>. Bleaugh. | |
2622 | If you, dear reader, have a better idea, you've got the source. :-) */ | |
2623 | if (dribble) | |
2624 | { | |
2625 | if (INTEGERP (c)) | |
2626 | { | |
2627 | if (XUINT (c) < 0x100) | |
2628 | putc (XINT (c), dribble); | |
2629 | else | |
6de34814 | 2630 | fprintf (dribble, " 0x%x", (int) XUINT (c)); |
e4fe371d RS |
2631 | } |
2632 | else | |
2633 | { | |
2634 | Lisp_Object dribblee; | |
2635 | ||
2636 | /* If it's a structured event, take the event header. */ | |
2637 | dribblee = EVENT_HEAD (c); | |
2638 | ||
2639 | if (SYMBOLP (dribblee)) | |
2640 | { | |
2641 | putc ('<', dribble); | |
2642 | fwrite (XSYMBOL (dribblee)->name->data, sizeof (char), | |
fc932ac6 | 2643 | STRING_BYTES (XSYMBOL (dribblee)->name), |
e4fe371d RS |
2644 | dribble); |
2645 | putc ('>', dribble); | |
2646 | } | |
2647 | } | |
2648 | ||
2649 | fflush (dribble); | |
2650 | } | |
2651 | ||
2652 | store_kbd_macro_char (c); | |
2653 | ||
c43b1734 | 2654 | num_nonmacro_input_events++; |
e4fe371d RS |
2655 | } |
2656 | ||
284f4730 JB |
2657 | Lisp_Object |
2658 | print_help (object) | |
2659 | Lisp_Object object; | |
2660 | { | |
622de3e9 | 2661 | struct buffer *old = current_buffer; |
284f4730 | 2662 | Fprinc (object, Qnil); |
622de3e9 KH |
2663 | set_buffer_internal (XBUFFER (Vstandard_output)); |
2664 | call0 (intern ("help-mode")); | |
2665 | set_buffer_internal (old); | |
284f4730 JB |
2666 | return Qnil; |
2667 | } | |
2668 | ||
2669 | /* Copy out or in the info on where C-g should throw to. | |
2670 | This is used when running Lisp code from within get_char, | |
2671 | in case get_char is called recursively. | |
2672 | See read_process_output. */ | |
2673 | ||
dfcf069d | 2674 | static void |
284f4730 JB |
2675 | save_getcjmp (temp) |
2676 | jmp_buf temp; | |
2677 | { | |
2678 | bcopy (getcjmp, temp, sizeof getcjmp); | |
2679 | } | |
2680 | ||
dfcf069d | 2681 | static void |
284f4730 JB |
2682 | restore_getcjmp (temp) |
2683 | jmp_buf temp; | |
2684 | { | |
2685 | bcopy (temp, getcjmp, sizeof getcjmp); | |
2686 | } | |
284f4730 | 2687 | \f |
2eb6bfbe RM |
2688 | #ifdef HAVE_MOUSE |
2689 | ||
284f4730 JB |
2690 | /* Restore mouse tracking enablement. See Ftrack_mouse for the only use |
2691 | of this function. */ | |
a9d77f1f | 2692 | |
284f4730 JB |
2693 | static Lisp_Object |
2694 | tracking_off (old_value) | |
2695 | Lisp_Object old_value; | |
2696 | { | |
71edead1 RS |
2697 | do_mouse_tracking = old_value; |
2698 | if (NILP (old_value)) | |
284f4730 | 2699 | { |
284f4730 JB |
2700 | /* Redisplay may have been preempted because there was input |
2701 | available, and it assumes it will be called again after the | |
2702 | input has been processed. If the only input available was | |
2703 | the sort that we have just disabled, then we need to call | |
2704 | redisplay. */ | |
d9d4c147 | 2705 | if (!readable_events (1)) |
284f4730 JB |
2706 | { |
2707 | redisplay_preserve_echo_area (); | |
d9d4c147 | 2708 | get_input_pending (&input_pending, 1); |
284f4730 JB |
2709 | } |
2710 | } | |
2711 | } | |
2712 | ||
2713 | DEFUN ("track-mouse", Ftrack_mouse, Strack_mouse, 0, UNEVALLED, 0, | |
4bb994d1 JB |
2714 | "Evaluate BODY with mouse movement events enabled.\n\ |
2715 | Within a `track-mouse' form, mouse motion generates input events that\n\ | |
2716 | you can read with `read-event'.\n\ | |
2717 | Normally, mouse motion is ignored.") | |
284f4730 JB |
2718 | (args) |
2719 | Lisp_Object args; | |
2720 | { | |
2721 | int count = specpdl_ptr - specpdl; | |
2722 | Lisp_Object val; | |
2723 | ||
a9d77f1f | 2724 | record_unwind_protect (tracking_off, do_mouse_tracking); |
284f4730 | 2725 | |
f3253854 | 2726 | do_mouse_tracking = Qt; |
df0f2ba1 | 2727 | |
284f4730 JB |
2728 | val = Fprogn (args); |
2729 | return unbind_to (count, val); | |
2730 | } | |
2eb6bfbe | 2731 | |
f3253854 KH |
2732 | /* If mouse has moved on some frame, return one of those frames. |
2733 | Return 0 otherwise. */ | |
2734 | ||
2735 | static FRAME_PTR | |
2736 | some_mouse_moved () | |
2737 | { | |
2738 | Lisp_Object tail, frame; | |
2739 | ||
2740 | FOR_EACH_FRAME (tail, frame) | |
2741 | { | |
2742 | if (XFRAME (frame)->mouse_moved) | |
2743 | return XFRAME (frame); | |
2744 | } | |
2745 | ||
2746 | return 0; | |
2747 | } | |
2748 | ||
2eb6bfbe | 2749 | #endif /* HAVE_MOUSE */ |
a612e298 RS |
2750 | \f |
2751 | /* Low level keyboard/mouse input. | |
2752 | kbd_buffer_store_event places events in kbd_buffer, and | |
0646c0dd | 2753 | kbd_buffer_get_event retrieves them. */ |
a612e298 RS |
2754 | |
2755 | /* Return true iff there are any events in the queue that read-char | |
2756 | would return. If this returns false, a read-char would block. */ | |
2757 | static int | |
d9d4c147 KH |
2758 | readable_events (do_timers_now) |
2759 | int do_timers_now; | |
a612e298 | 2760 | { |
4ec4ed6a RS |
2761 | if (do_timers_now) |
2762 | timer_check (do_timers_now); | |
2763 | ||
beecf6a1 KH |
2764 | if (kbd_fetch_ptr != kbd_store_ptr) |
2765 | return 1; | |
2766 | #ifdef HAVE_MOUSE | |
f3253854 | 2767 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
beecf6a1 KH |
2768 | return 1; |
2769 | #endif | |
1e8bd3da | 2770 | if (single_kboard) |
4c52b668 | 2771 | { |
c5fdd383 | 2772 | if (current_kboard->kbd_queue_has_data) |
4c52b668 KH |
2773 | return 1; |
2774 | } | |
2775 | else | |
2776 | { | |
c5fdd383 KH |
2777 | KBOARD *kb; |
2778 | for (kb = all_kboards; kb; kb = kb->next_kboard) | |
2779 | if (kb->kbd_queue_has_data) | |
4c52b668 KH |
2780 | return 1; |
2781 | } | |
beecf6a1 | 2782 | return 0; |
a612e298 RS |
2783 | } |
2784 | ||
2785 | /* Set this for debugging, to have a way to get out */ | |
2786 | int stop_character; | |
284f4730 | 2787 | |
c5fdd383 KH |
2788 | #ifdef MULTI_KBOARD |
2789 | static KBOARD * | |
2790 | event_to_kboard (event) | |
5798cf15 KH |
2791 | struct input_event *event; |
2792 | { | |
2793 | Lisp_Object frame; | |
2794 | frame = event->frame_or_window; | |
2795 | if (CONSP (frame)) | |
2796 | frame = XCONS (frame)->car; | |
2797 | else if (WINDOWP (frame)) | |
2798 | frame = WINDOW_FRAME (XWINDOW (frame)); | |
2799 | ||
2800 | /* There are still some events that don't set this field. | |
f5b56972 KH |
2801 | For now, just ignore the problem. |
2802 | Also ignore dead frames here. */ | |
2803 | if (!FRAMEP (frame) || !FRAME_LIVE_P (XFRAME (frame))) | |
5798cf15 KH |
2804 | return 0; |
2805 | else | |
c5fdd383 | 2806 | return FRAME_KBOARD (XFRAME (frame)); |
5798cf15 KH |
2807 | } |
2808 | #endif | |
2809 | ||
284f4730 JB |
2810 | /* Store an event obtained at interrupt level into kbd_buffer, fifo */ |
2811 | ||
2812 | void | |
2813 | kbd_buffer_store_event (event) | |
2814 | register struct input_event *event; | |
2815 | { | |
2816 | if (event->kind == no_event) | |
2817 | abort (); | |
2818 | ||
2819 | if (event->kind == ascii_keystroke) | |
2820 | { | |
e9bf89a0 | 2821 | register int c = event->code & 0377; |
284f4730 | 2822 | |
faf5e407 JB |
2823 | if (event->modifiers & ctrl_modifier) |
2824 | c = make_ctrl_char (c); | |
2825 | ||
9fd7d808 RS |
2826 | c |= (event->modifiers |
2827 | & (meta_modifier | alt_modifier | |
2828 | | hyper_modifier | super_modifier)); | |
2829 | ||
86e5706b | 2830 | if (c == quit_char) |
284f4730 | 2831 | { |
3e51c7b7 | 2832 | extern SIGTYPE interrupt_signal (); |
c5fdd383 KH |
2833 | #ifdef MULTI_KBOARD |
2834 | KBOARD *kb; | |
5798cf15 KH |
2835 | struct input_event *sp; |
2836 | ||
1e8bd3da | 2837 | if (single_kboard |
c5fdd383 KH |
2838 | && (kb = FRAME_KBOARD (XFRAME (event->frame_or_window)), |
2839 | kb != current_kboard)) | |
5798cf15 | 2840 | { |
c5fdd383 | 2841 | kb->kbd_queue |
5798cf15 KH |
2842 | = Fcons (make_lispy_switch_frame (event->frame_or_window), |
2843 | Fcons (make_number (c), Qnil)); | |
c5fdd383 | 2844 | kb->kbd_queue_has_data = 1; |
5798cf15 KH |
2845 | for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++) |
2846 | { | |
2847 | if (sp == kbd_buffer + KBD_BUFFER_SIZE) | |
2848 | sp = kbd_buffer; | |
2849 | ||
c5fdd383 | 2850 | if (event_to_kboard (sp) == kb) |
5798cf15 KH |
2851 | { |
2852 | sp->kind = no_event; | |
2853 | sp->frame_or_window = Qnil; | |
2854 | } | |
2855 | } | |
2856 | return; | |
2857 | } | |
2858 | #endif | |
3e51c7b7 | 2859 | |
284f4730 | 2860 | /* If this results in a quit_char being returned to Emacs as |
3c370943 | 2861 | input, set Vlast_event_frame properly. If this doesn't |
284f4730 | 2862 | get returned to Emacs as an event, the next event read |
ff11dfa1 | 2863 | will set Vlast_event_frame again, so this is safe to do. */ |
4bb994d1 | 2864 | { |
9b8eb840 | 2865 | Lisp_Object focus; |
4bb994d1 | 2866 | |
9b8eb840 | 2867 | focus = FRAME_FOCUS_FRAME (XFRAME (event->frame_or_window)); |
4bb994d1 | 2868 | if (NILP (focus)) |
beecf6a1 | 2869 | focus = event->frame_or_window; |
4c52b668 KH |
2870 | internal_last_event_frame = focus; |
2871 | Vlast_event_frame = focus; | |
4bb994d1 | 2872 | } |
3e51c7b7 | 2873 | |
ffd56f97 | 2874 | last_event_timestamp = event->timestamp; |
284f4730 JB |
2875 | interrupt_signal (); |
2876 | return; | |
2877 | } | |
2878 | ||
2879 | if (c && c == stop_character) | |
2880 | { | |
2881 | sys_suspend (); | |
2882 | return; | |
2883 | } | |
284f4730 | 2884 | } |
3fe8e9a2 RS |
2885 | /* Don't insert two buffer_switch_event's in a row. |
2886 | Just ignore the second one. */ | |
2887 | else if (event->kind == buffer_switch_event | |
2888 | && kbd_fetch_ptr != kbd_store_ptr | |
2889 | && kbd_store_ptr->kind == buffer_switch_event) | |
2890 | return; | |
284f4730 | 2891 | |
beecf6a1 KH |
2892 | if (kbd_store_ptr - kbd_buffer == KBD_BUFFER_SIZE) |
2893 | kbd_store_ptr = kbd_buffer; | |
284f4730 JB |
2894 | |
2895 | /* Don't let the very last slot in the buffer become full, | |
2896 | since that would make the two pointers equal, | |
2897 | and that is indistinguishable from an empty buffer. | |
2898 | Discard the event if it would fill the last slot. */ | |
beecf6a1 | 2899 | if (kbd_fetch_ptr - 1 != kbd_store_ptr) |
284f4730 | 2900 | { |
7ee32cda | 2901 | struct input_event *sp = kbd_store_ptr; |
612b78ef | 2902 | sp->kind = event->kind; |
27203ead RS |
2903 | if (event->kind == selection_request_event) |
2904 | { | |
2905 | /* We must not use the ordinary copying code for this case, | |
2906 | since `part' is an enum and copying it might not copy enough | |
2907 | in this case. */ | |
612b78ef | 2908 | bcopy (event, (char *) sp, sizeof (*event)); |
27203ead RS |
2909 | } |
2910 | else | |
2911 | { | |
612b78ef KH |
2912 | sp->code = event->code; |
2913 | sp->part = event->part; | |
2914 | sp->frame_or_window = event->frame_or_window; | |
2915 | sp->modifiers = event->modifiers; | |
2916 | sp->x = event->x; | |
2917 | sp->y = event->y; | |
2918 | sp->timestamp = event->timestamp; | |
27203ead | 2919 | } |
beecf6a1 KH |
2920 | (XVECTOR (kbd_buffer_frame_or_window)->contents[kbd_store_ptr |
2921 | - kbd_buffer] | |
7b4aedb9 | 2922 | = event->frame_or_window); |
284f4730 | 2923 | |
beecf6a1 | 2924 | kbd_store_ptr++; |
284f4730 JB |
2925 | } |
2926 | } | |
a612e298 | 2927 | \f |
07de30b9 GV |
2928 | /* Discard any mouse events in the event buffer by setting them to |
2929 | no_event. */ | |
2930 | void | |
2931 | discard_mouse_events () | |
2932 | { | |
2933 | struct input_event *sp; | |
2934 | for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++) | |
2935 | { | |
2936 | if (sp == kbd_buffer + KBD_BUFFER_SIZE) | |
2937 | sp = kbd_buffer; | |
2938 | ||
2939 | if (sp->kind == mouse_click | |
2940 | #ifdef WINDOWSNT | |
2941 | || sp->kind == w32_scroll_bar_click | |
2942 | #endif | |
2943 | || sp->kind == scroll_bar_click) | |
2944 | { | |
2945 | sp->kind = no_event; | |
2946 | } | |
2947 | } | |
2948 | } | |
2949 | \f | |
a612e298 RS |
2950 | /* Read one event from the event buffer, waiting if necessary. |
2951 | The value is a Lisp object representing the event. | |
2952 | The value is nil for an event that should be ignored, | |
2953 | or that was handled here. | |
2954 | We always read and discard one event. */ | |
284f4730 JB |
2955 | |
2956 | static Lisp_Object | |
83d68044 | 2957 | kbd_buffer_get_event (kbp, used_mouse_menu) |
410d4de9 | 2958 | KBOARD **kbp; |
83d68044 | 2959 | int *used_mouse_menu; |
284f4730 JB |
2960 | { |
2961 | register int c; | |
2962 | Lisp_Object obj; | |
c04cbc3b | 2963 | EMACS_TIME next_timer_delay; |
284f4730 JB |
2964 | |
2965 | if (noninteractive) | |
2966 | { | |
2967 | c = getchar (); | |
18cd2eeb | 2968 | XSETINT (obj, c); |
f5b56972 | 2969 | *kbp = current_kboard; |
284f4730 JB |
2970 | return obj; |
2971 | } | |
2972 | ||
2973 | /* Wait until there is input available. */ | |
2974 | for (;;) | |
2975 | { | |
beecf6a1 KH |
2976 | if (kbd_fetch_ptr != kbd_store_ptr) |
2977 | break; | |
2978 | #ifdef HAVE_MOUSE | |
f3253854 | 2979 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
284f4730 | 2980 | break; |
beecf6a1 | 2981 | #endif |
284f4730 JB |
2982 | |
2983 | /* If the quit flag is set, then read_char will return | |
2984 | quit_char, so that counts as "available input." */ | |
2985 | if (!NILP (Vquit_flag)) | |
2986 | quit_throw_to_read_char (); | |
2987 | ||
2988 | /* One way or another, wait until input is available; then, if | |
2989 | interrupt handlers have not read it, read it now. */ | |
2990 | ||
2991 | #ifdef OLDVMS | |
2992 | wait_for_kbd_input (); | |
2993 | #else | |
2994 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
2995 | #ifdef SIGIO | |
2996 | gobble_input (0); | |
2997 | #endif /* SIGIO */ | |
beecf6a1 KH |
2998 | if (kbd_fetch_ptr != kbd_store_ptr) |
2999 | break; | |
3000 | #ifdef HAVE_MOUSE | |
f3253854 | 3001 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
beecf6a1 KH |
3002 | break; |
3003 | #endif | |
3004 | { | |
3005 | Lisp_Object minus_one; | |
f76475ad | 3006 | |
beecf6a1 | 3007 | XSETINT (minus_one, -1); |
d9d4c147 | 3008 | wait_reading_process_input (0, 0, minus_one, 1); |
284f4730 | 3009 | |
beecf6a1 KH |
3010 | if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr) |
3011 | /* Pass 1 for EXPECT since we just waited to have input. */ | |
3012 | read_avail_input (1); | |
3013 | } | |
284f4730 JB |
3014 | #endif /* not VMS */ |
3015 | } | |
3016 | ||
303b5b3f RS |
3017 | if (CONSP (Vunread_command_events)) |
3018 | { | |
3019 | Lisp_Object first; | |
3020 | first = XCONS (Vunread_command_events)->car; | |
3021 | Vunread_command_events = XCONS (Vunread_command_events)->cdr; | |
3022 | *kbp = current_kboard; | |
3023 | return first; | |
3024 | } | |
3025 | ||
284f4730 JB |
3026 | /* At this point, we know that there is a readable event available |
3027 | somewhere. If the event queue is empty, then there must be a | |
3028 | mouse movement enabled and available. */ | |
beecf6a1 | 3029 | if (kbd_fetch_ptr != kbd_store_ptr) |
284f4730 | 3030 | { |
cd21b839 | 3031 | struct input_event *event; |
3e51c7b7 | 3032 | |
beecf6a1 KH |
3033 | event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE) |
3034 | ? kbd_fetch_ptr | |
3035 | : kbd_buffer); | |
3e51c7b7 | 3036 | |
cd21b839 | 3037 | last_event_timestamp = event->timestamp; |
cd21b839 | 3038 | |
c5fdd383 KH |
3039 | #ifdef MULTI_KBOARD |
3040 | *kbp = event_to_kboard (event); | |
3041 | if (*kbp == 0) | |
3042 | *kbp = current_kboard; /* Better than returning null ptr? */ | |
5798cf15 | 3043 | #else |
c5fdd383 | 3044 | *kbp = &the_only_kboard; |
5798cf15 | 3045 | #endif |
beecf6a1 | 3046 | |
4bb994d1 JB |
3047 | obj = Qnil; |
3048 | ||
48e416d4 | 3049 | /* These two kinds of events get special handling |
a612e298 RS |
3050 | and don't actually appear to the command loop. |
3051 | We return nil for them. */ | |
48e416d4 RS |
3052 | if (event->kind == selection_request_event) |
3053 | { | |
598a9fa7 | 3054 | #ifdef HAVE_X11 |
1e8bd3da RS |
3055 | struct input_event copy; |
3056 | ||
4581e928 RS |
3057 | /* Remove it from the buffer before processing it, |
3058 | since otherwise swallow_events will see it | |
3059 | and process it again. */ | |
1e8bd3da | 3060 | copy = *event; |
beecf6a1 | 3061 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3062 | input_pending = readable_events (0); |
4581e928 | 3063 | x_handle_selection_request (©); |
598a9fa7 JB |
3064 | #else |
3065 | /* We're getting selection request events, but we don't have | |
3066 | a window system. */ | |
3067 | abort (); | |
3068 | #endif | |
48e416d4 RS |
3069 | } |
3070 | ||
1e12dd87 | 3071 | else if (event->kind == selection_clear_event) |
48e416d4 | 3072 | { |
598a9fa7 | 3073 | #ifdef HAVE_X11 |
e0301c07 RS |
3074 | struct input_event copy; |
3075 | ||
3076 | /* Remove it from the buffer before processing it. */ | |
3077 | copy = *event; | |
beecf6a1 | 3078 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3079 | input_pending = readable_events (0); |
90c2bb0c | 3080 | x_handle_selection_clear (©); |
598a9fa7 JB |
3081 | #else |
3082 | /* We're getting selection request events, but we don't have | |
3083 | a window system. */ | |
3084 | abort (); | |
3085 | #endif | |
48e416d4 | 3086 | } |
e98a93eb | 3087 | #if defined (HAVE_X11) || defined (HAVE_NTGUI) |
990acea3 RS |
3088 | else if (event->kind == delete_window_event) |
3089 | { | |
bbdc2092 RS |
3090 | /* Make an event (delete-frame (FRAME)). */ |
3091 | obj = Fcons (event->frame_or_window, Qnil); | |
af17bd2b | 3092 | obj = Fcons (Qdelete_frame, Fcons (obj, Qnil)); |
beecf6a1 | 3093 | kbd_fetch_ptr = event + 1; |
af17bd2b KH |
3094 | } |
3095 | else if (event->kind == iconify_event) | |
3096 | { | |
3097 | /* Make an event (iconify-frame (FRAME)). */ | |
3098 | obj = Fcons (event->frame_or_window, Qnil); | |
3099 | obj = Fcons (Qiconify_frame, Fcons (obj, Qnil)); | |
beecf6a1 | 3100 | kbd_fetch_ptr = event + 1; |
af17bd2b KH |
3101 | } |
3102 | else if (event->kind == deiconify_event) | |
3103 | { | |
3104 | /* Make an event (make-frame-visible (FRAME)). */ | |
3105 | obj = Fcons (event->frame_or_window, Qnil); | |
3106 | obj = Fcons (Qmake_frame_visible, Fcons (obj, Qnil)); | |
beecf6a1 | 3107 | kbd_fetch_ptr = event + 1; |
990acea3 RS |
3108 | } |
3109 | #endif | |
a8015ab5 KH |
3110 | else if (event->kind == buffer_switch_event) |
3111 | { | |
3112 | /* The value doesn't matter here; only the type is tested. */ | |
18cd2eeb | 3113 | XSETBUFFER (obj, current_buffer); |
beecf6a1 | 3114 | kbd_fetch_ptr = event + 1; |
a8015ab5 | 3115 | } |
07de30b9 | 3116 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
099787c1 RS |
3117 | else if (event->kind == menu_bar_activate_event) |
3118 | { | |
3119 | kbd_fetch_ptr = event + 1; | |
d9d4c147 | 3120 | input_pending = readable_events (0); |
e649d076 RS |
3121 | if (FRAME_LIVE_P (XFRAME (event->frame_or_window))) |
3122 | x_activate_menubar (XFRAME (event->frame_or_window)); | |
099787c1 | 3123 | } |
1161d367 GV |
3124 | #endif |
3125 | #ifdef WINDOWSNT | |
3126 | else if (event->kind == language_change_event) | |
3127 | { | |
3128 | /* Make an event (language-change (FRAME CHARSET LCID)). */ | |
3129 | obj = Fcons (event->modifiers, Qnil); | |
3130 | obj = Fcons (event->code, Qnil); | |
3131 | obj = Fcons (event->frame_or_window, obj); | |
3132 | obj = Fcons (Qlanguage_change, Fcons (obj, Qnil)); | |
3133 | kbd_fetch_ptr = event + 1; | |
3134 | } | |
099787c1 | 3135 | #endif |
a612e298 | 3136 | /* Just discard these, by returning nil. |
c5fdd383 | 3137 | With MULTI_KBOARD, these events are used as placeholders |
5798cf15 KH |
3138 | when we need to randomly delete events from the queue. |
3139 | (They shouldn't otherwise be found in the buffer, | |
3140 | but on some machines it appears they do show up | |
c5fdd383 | 3141 | even without MULTI_KBOARD.) */ |
07de30b9 GV |
3142 | /* On Windows NT/9X, no_event is used to delete extraneous |
3143 | mouse events during a popup-menu call. */ | |
a612e298 | 3144 | else if (event->kind == no_event) |
beecf6a1 | 3145 | kbd_fetch_ptr = event + 1; |
7ee32cda GM |
3146 | else if (event->kind == HELP_EVENT) |
3147 | { | |
3148 | /* The car of event->frame_or_window is a frame, | |
3149 | the cdr is the help to display. */ | |
3150 | obj = Fcons (Qhelp_echo, event->frame_or_window); | |
3151 | kbd_fetch_ptr = event + 1; | |
3152 | } | |
4bb994d1 JB |
3153 | /* If this event is on a different frame, return a switch-frame this |
3154 | time, and leave the event in the queue for next time. */ | |
1e12dd87 RS |
3155 | else |
3156 | { | |
9b8eb840 | 3157 | Lisp_Object frame; |
1e12dd87 | 3158 | Lisp_Object focus; |
7b4aedb9 | 3159 | |
9b8eb840 | 3160 | frame = event->frame_or_window; |
2470a66f KH |
3161 | if (CONSP (frame)) |
3162 | frame = XCONS (frame)->car; | |
3163 | else if (WINDOWP (frame)) | |
1e12dd87 | 3164 | frame = WINDOW_FRAME (XWINDOW (frame)); |
4bb994d1 | 3165 | |
1e12dd87 RS |
3166 | focus = FRAME_FOCUS_FRAME (XFRAME (frame)); |
3167 | if (! NILP (focus)) | |
3168 | frame = focus; | |
07d2b8de | 3169 | |
4c52b668 | 3170 | if (! EQ (frame, internal_last_event_frame) |
1e12dd87 RS |
3171 | && XFRAME (frame) != selected_frame) |
3172 | obj = make_lispy_switch_frame (frame); | |
4c52b668 | 3173 | internal_last_event_frame = frame; |
4bb994d1 | 3174 | |
1e12dd87 RS |
3175 | /* If we didn't decide to make a switch-frame event, go ahead |
3176 | and build a real event from the queue entry. */ | |
cd21b839 | 3177 | |
1e12dd87 RS |
3178 | if (NILP (obj)) |
3179 | { | |
3180 | obj = make_lispy_event (event); | |
e98a93eb | 3181 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
83d68044 KH |
3182 | /* If this was a menu selection, then set the flag to inhibit |
3183 | writing to last_nonmenu_event. Don't do this if the event | |
3184 | we're returning is (menu-bar), though; that indicates the | |
3185 | beginning of the menu sequence, and we might as well leave | |
3186 | that as the `event with parameters' for this selection. */ | |
7ee32cda | 3187 | if ((event->kind == menu_bar_event |
9ea173e8 | 3188 | || event->kind == TOOL_BAR_EVENT) |
83d68044 | 3189 | && !(CONSP (obj) && EQ (XCONS (obj)->car, Qmenu_bar)) |
9ea173e8 | 3190 | && !(CONSP (obj) && EQ (XCONS (obj)->car, Qtool_bar)) |
83d68044 KH |
3191 | && used_mouse_menu) |
3192 | *used_mouse_menu = 1; | |
3193 | #endif | |
1e12dd87 RS |
3194 | |
3195 | /* Wipe out this event, to catch bugs. */ | |
3196 | event->kind = no_event; | |
beecf6a1 | 3197 | XVECTOR (kbd_buffer_frame_or_window)->contents[event - kbd_buffer] = Qnil; |
1e12dd87 | 3198 | |
beecf6a1 | 3199 | kbd_fetch_ptr = event + 1; |
1e12dd87 | 3200 | } |
4bb994d1 | 3201 | } |
284f4730 | 3202 | } |
2eb6bfbe | 3203 | #ifdef HAVE_MOUSE |
a612e298 | 3204 | /* Try generating a mouse motion event. */ |
f3253854 | 3205 | else if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
284f4730 | 3206 | { |
f3253854 | 3207 | FRAME_PTR f = some_mouse_moved (); |
7b4aedb9 | 3208 | Lisp_Object bar_window; |
3c370943 | 3209 | enum scroll_bar_part part; |
e5d77022 JB |
3210 | Lisp_Object x, y; |
3211 | unsigned long time; | |
284f4730 | 3212 | |
c5fdd383 | 3213 | *kbp = current_kboard; |
e177ac3a RS |
3214 | /* Note that this uses F to determine which display to look at. |
3215 | If there is no valid info, it does not store anything | |
3216 | so x remains nil. */ | |
3217 | x = Qnil; | |
dd26ab75 | 3218 | (*mouse_position_hook) (&f, 0, &bar_window, &part, &x, &y, &time); |
4bb994d1 JB |
3219 | |
3220 | obj = Qnil; | |
284f4730 | 3221 | |
4bb994d1 JB |
3222 | /* Decide if we should generate a switch-frame event. Don't |
3223 | generate switch-frame events for motion outside of all Emacs | |
3224 | frames. */ | |
e177ac3a | 3225 | if (!NILP (x) && f) |
cd21b839 | 3226 | { |
9b8eb840 | 3227 | Lisp_Object frame; |
4bb994d1 | 3228 | |
9b8eb840 | 3229 | frame = FRAME_FOCUS_FRAME (f); |
4bb994d1 | 3230 | if (NILP (frame)) |
18cd2eeb | 3231 | XSETFRAME (frame, f); |
4bb994d1 | 3232 | |
4c52b668 | 3233 | if (! EQ (frame, internal_last_event_frame) |
80645119 | 3234 | && XFRAME (frame) != selected_frame) |
764cb3f9 | 3235 | obj = make_lispy_switch_frame (frame); |
4c52b668 | 3236 | internal_last_event_frame = frame; |
cd21b839 | 3237 | } |
4bb994d1 | 3238 | |
df0f2ba1 | 3239 | /* If we didn't decide to make a switch-frame event, go ahead and |
4bb994d1 | 3240 | return a mouse-motion event. */ |
e177ac3a | 3241 | if (!NILP (x) && NILP (obj)) |
7b4aedb9 | 3242 | obj = make_lispy_movement (f, bar_window, part, x, y, time); |
6cbff1cb | 3243 | } |
2eb6bfbe | 3244 | #endif /* HAVE_MOUSE */ |
284f4730 JB |
3245 | else |
3246 | /* We were promised by the above while loop that there was | |
3247 | something for us to read! */ | |
3248 | abort (); | |
3249 | ||
d9d4c147 | 3250 | input_pending = readable_events (0); |
284f4730 | 3251 | |
4c52b668 | 3252 | Vlast_event_frame = internal_last_event_frame; |
3c370943 | 3253 | |
284f4730 JB |
3254 | return (obj); |
3255 | } | |
a612e298 RS |
3256 | \f |
3257 | /* Process any events that are not user-visible, | |
3258 | then return, without reading any user-visible events. */ | |
3a3b9632 RS |
3259 | |
3260 | void | |
d9d4c147 KH |
3261 | swallow_events (do_display) |
3262 | int do_display; | |
3a3b9632 | 3263 | { |
87dd9b9b RS |
3264 | int old_timers_run; |
3265 | ||
beecf6a1 | 3266 | while (kbd_fetch_ptr != kbd_store_ptr) |
3a3b9632 RS |
3267 | { |
3268 | struct input_event *event; | |
3269 | ||
beecf6a1 KH |
3270 | event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE) |
3271 | ? kbd_fetch_ptr | |
3272 | : kbd_buffer); | |
3a3b9632 RS |
3273 | |
3274 | last_event_timestamp = event->timestamp; | |
3275 | ||
3276 | /* These two kinds of events get special handling | |
3277 | and don't actually appear to the command loop. */ | |
3278 | if (event->kind == selection_request_event) | |
3279 | { | |
3280 | #ifdef HAVE_X11 | |
4581e928 | 3281 | struct input_event copy; |
e0301c07 RS |
3282 | |
3283 | /* Remove it from the buffer before processing it, | |
3284 | since otherwise swallow_events called recursively could see it | |
3285 | and process it again. */ | |
4581e928 | 3286 | copy = *event; |
beecf6a1 | 3287 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3288 | input_pending = readable_events (0); |
4581e928 | 3289 | x_handle_selection_request (©); |
3a3b9632 RS |
3290 | #else |
3291 | /* We're getting selection request events, but we don't have | |
3292 | a window system. */ | |
3293 | abort (); | |
3294 | #endif | |
3295 | } | |
3296 | ||
3297 | else if (event->kind == selection_clear_event) | |
3298 | { | |
3299 | #ifdef HAVE_X11 | |
e0301c07 RS |
3300 | struct input_event copy; |
3301 | ||
3302 | /* Remove it from the buffer before processing it, */ | |
3303 | copy = *event; | |
3304 | ||
beecf6a1 | 3305 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3306 | input_pending = readable_events (0); |
90c2bb0c | 3307 | x_handle_selection_clear (©); |
3a3b9632 RS |
3308 | #else |
3309 | /* We're getting selection request events, but we don't have | |
3310 | a window system. */ | |
3311 | abort (); | |
3312 | #endif | |
3313 | } | |
3314 | else | |
3315 | break; | |
3316 | } | |
3317 | ||
87dd9b9b | 3318 | old_timers_run = timers_run; |
d9d4c147 | 3319 | get_input_pending (&input_pending, 1); |
87dd9b9b RS |
3320 | |
3321 | if (timers_run != old_timers_run && do_display) | |
3322 | redisplay_preserve_echo_area (); | |
3a3b9632 | 3323 | } |
a612e298 | 3324 | \f |
d9d4c147 KH |
3325 | static EMACS_TIME timer_idleness_start_time; |
3326 | ||
3327 | /* Record the start of when Emacs is idle, | |
3328 | for the sake of running idle-time timers. */ | |
3329 | ||
07a59269 | 3330 | void |
d9d4c147 KH |
3331 | timer_start_idle () |
3332 | { | |
3333 | Lisp_Object timers; | |
3334 | ||
3335 | /* If we are already in the idle state, do nothing. */ | |
3336 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3337 | return; | |
3338 | ||
3339 | EMACS_GET_TIME (timer_idleness_start_time); | |
3340 | ||
3341 | /* Mark all idle-time timers as once again candidates for running. */ | |
3342 | for (timers = Vtimer_idle_list; CONSP (timers); timers = XCONS (timers)->cdr) | |
3343 | { | |
3344 | Lisp_Object timer; | |
3345 | ||
3346 | timer = XCONS (timers)->car; | |
3347 | ||
3348 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) | |
3349 | continue; | |
3350 | XVECTOR (timer)->contents[0] = Qnil; | |
3351 | } | |
3352 | } | |
3353 | ||
3354 | /* Record that Emacs is no longer idle, so stop running idle-time timers. */ | |
3355 | ||
07a59269 | 3356 | void |
d9d4c147 KH |
3357 | timer_stop_idle () |
3358 | { | |
3359 | EMACS_SET_SECS_USECS (timer_idleness_start_time, -1, -1); | |
3360 | } | |
3361 | ||
e044e87c RS |
3362 | /* This is only for debugging. */ |
3363 | struct input_event last_timer_event; | |
3364 | ||
c04cbc3b RS |
3365 | /* Check whether a timer has fired. To prevent larger problems we simply |
3366 | disregard elements that are not proper timers. Do not make a circular | |
3367 | timer list for the time being. | |
3368 | ||
3369 | Returns the number of seconds to wait until the next timer fires. If a | |
3370 | timer is triggering now, return zero seconds. | |
3371 | If no timer is active, return -1 seconds. | |
3372 | ||
4ec4ed6a RS |
3373 | If a timer is ripe, we run it, with quitting turned off. |
3374 | ||
3375 | DO_IT_NOW is now ignored. It used to mean that we should | |
3376 | run the timer directly instead of queueing a timer-event. | |
3377 | Now we always run timers directly. */ | |
c04cbc3b RS |
3378 | |
3379 | EMACS_TIME | |
3380 | timer_check (do_it_now) | |
3381 | int do_it_now; | |
3382 | { | |
3383 | EMACS_TIME nexttime; | |
9291c072 RS |
3384 | EMACS_TIME now, idleness_now; |
3385 | Lisp_Object timers, idle_timers, chosen_timer; | |
9291c072 | 3386 | struct gcpro gcpro1, gcpro2, gcpro3; |
c04cbc3b | 3387 | |
c04cbc3b RS |
3388 | EMACS_SET_SECS (nexttime, -1); |
3389 | EMACS_SET_USECS (nexttime, -1); | |
3390 | ||
9291c072 | 3391 | /* Always consider the ordinary timers. */ |
7ea13e12 | 3392 | timers = Vtimer_list; |
9291c072 RS |
3393 | /* Consider the idle timers only if Emacs is idle. */ |
3394 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3395 | idle_timers = Vtimer_idle_list; | |
3396 | else | |
3397 | idle_timers = Qnil; | |
3398 | chosen_timer = Qnil; | |
3399 | GCPRO3 (timers, idle_timers, chosen_timer); | |
7ea13e12 | 3400 | |
9291c072 | 3401 | if (CONSP (timers) || CONSP (idle_timers)) |
c04cbc3b | 3402 | { |
9291c072 RS |
3403 | EMACS_GET_TIME (now); |
3404 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3405 | EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time); | |
3406 | } | |
c04cbc3b | 3407 | |
9291c072 RS |
3408 | while (CONSP (timers) || CONSP (idle_timers)) |
3409 | { | |
3410 | int triggertime = EMACS_SECS (now); | |
3411 | Lisp_Object *vector; | |
3412 | Lisp_Object timer, idle_timer; | |
3413 | EMACS_TIME timer_time, idle_timer_time; | |
3414 | EMACS_TIME difference, timer_difference, idle_timer_difference; | |
3415 | ||
3416 | /* Skip past invalid timers and timers already handled. */ | |
3417 | if (!NILP (timers)) | |
c04cbc3b | 3418 | { |
d9d4c147 | 3419 | timer = XCONS (timers)->car; |
9291c072 RS |
3420 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) |
3421 | { | |
3422 | timers = XCONS (timers)->cdr; | |
3423 | continue; | |
3424 | } | |
3425 | vector = XVECTOR (timer)->contents; | |
d9d4c147 | 3426 | |
9291c072 RS |
3427 | if (!INTEGERP (vector[1]) || !INTEGERP (vector[2]) |
3428 | || !INTEGERP (vector[3]) | |
3429 | || ! NILP (vector[0])) | |
3430 | { | |
3431 | timers = XCONS (timers)->cdr; | |
3432 | continue; | |
3433 | } | |
3434 | } | |
3435 | if (!NILP (idle_timers)) | |
3436 | { | |
3437 | timer = XCONS (idle_timers)->car; | |
d9d4c147 | 3438 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) |
9291c072 RS |
3439 | { |
3440 | idle_timers = XCONS (idle_timers)->cdr; | |
3441 | continue; | |
3442 | } | |
d9d4c147 KH |
3443 | vector = XVECTOR (timer)->contents; |
3444 | ||
3445 | if (!INTEGERP (vector[1]) || !INTEGERP (vector[2]) | |
9291c072 RS |
3446 | || !INTEGERP (vector[3]) |
3447 | || ! NILP (vector[0])) | |
3448 | { | |
3449 | idle_timers = XCONS (idle_timers)->cdr; | |
3450 | continue; | |
3451 | } | |
3452 | } | |
d9d4c147 | 3453 | |
9291c072 RS |
3454 | /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE |
3455 | based on the next ordinary timer. | |
3456 | TIMER_DIFFERENCE is the distance in time from NOW to when | |
3457 | this timer becomes ripe (negative if it's already ripe). */ | |
3458 | if (!NILP (timers)) | |
3459 | { | |
3460 | timer = XCONS (timers)->car; | |
3461 | vector = XVECTOR (timer)->contents; | |
d9d4c147 KH |
3462 | EMACS_SET_SECS (timer_time, |
3463 | (XINT (vector[1]) << 16) | (XINT (vector[2]))); | |
3464 | EMACS_SET_USECS (timer_time, XINT (vector[3])); | |
9291c072 RS |
3465 | EMACS_SUB_TIME (timer_difference, timer_time, now); |
3466 | } | |
ba8dfba8 | 3467 | |
9291c072 RS |
3468 | /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE |
3469 | based on the next idle timer. */ | |
3470 | if (!NILP (idle_timers)) | |
3471 | { | |
3472 | idle_timer = XCONS (idle_timers)->car; | |
3473 | vector = XVECTOR (idle_timer)->contents; | |
3474 | EMACS_SET_SECS (idle_timer_time, | |
3475 | (XINT (vector[1]) << 16) | (XINT (vector[2]))); | |
3476 | EMACS_SET_USECS (idle_timer_time, XINT (vector[3])); | |
3477 | EMACS_SUB_TIME (idle_timer_difference, idle_timer_time, idleness_now); | |
3478 | } | |
ba8dfba8 | 3479 | |
9291c072 RS |
3480 | /* Decide which timer is the next timer, |
3481 | and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly. | |
3482 | Also step down the list where we found that timer. */ | |
d9d4c147 | 3483 | |
9291c072 RS |
3484 | if (! NILP (timers) && ! NILP (idle_timers)) |
3485 | { | |
3486 | EMACS_TIME temp; | |
3487 | EMACS_SUB_TIME (temp, timer_difference, idle_timer_difference); | |
3488 | if (EMACS_TIME_NEG_P (temp)) | |
3489 | { | |
3490 | chosen_timer = timer; | |
3491 | timers = XCONS (timers)->cdr; | |
3492 | difference = timer_difference; | |
c04cbc3b | 3493 | } |
d9d4c147 | 3494 | else |
d9d4c147 | 3495 | { |
9291c072 RS |
3496 | chosen_timer = idle_timer; |
3497 | idle_timers = XCONS (idle_timers)->cdr; | |
3498 | difference = idle_timer_difference; | |
d9d4c147 | 3499 | } |
7ea13e12 | 3500 | } |
9291c072 RS |
3501 | else if (! NILP (timers)) |
3502 | { | |
3503 | chosen_timer = timer; | |
3504 | timers = XCONS (timers)->cdr; | |
3505 | difference = timer_difference; | |
3506 | } | |
3507 | else | |
3508 | { | |
3509 | chosen_timer = idle_timer; | |
3510 | idle_timers = XCONS (idle_timers)->cdr; | |
3511 | difference = idle_timer_difference; | |
3512 | } | |
3513 | vector = XVECTOR (chosen_timer)->contents; | |
3514 | ||
3515 | /* If timer is rupe, run it if it hasn't been run. */ | |
3516 | if (EMACS_TIME_NEG_P (difference) | |
3517 | || (EMACS_SECS (difference) == 0 | |
3518 | && EMACS_USECS (difference) == 0)) | |
3519 | { | |
3520 | if (NILP (vector[0])) | |
3521 | { | |
d925fb39 RS |
3522 | Lisp_Object tem; |
3523 | int was_locked = single_kboard; | |
3524 | int count = specpdl_ptr - specpdl; | |
7ee32cda GM |
3525 | #ifdef HAVE_WINDOW_SYSTEM |
3526 | int old_inhibit_busy_cursor = inhibit_busy_cursor; | |
3527 | #endif | |
d925fb39 | 3528 | |
9291c072 RS |
3529 | /* Mark the timer as triggered to prevent problems if the lisp |
3530 | code fails to reschedule it right. */ | |
3531 | vector[0] = Qt; | |
3532 | ||
d925fb39 | 3533 | specbind (Qinhibit_quit, Qt); |
9291c072 | 3534 | |
7ee32cda GM |
3535 | #ifdef HAVE_WINDOW_SYSTEM |
3536 | inhibit_busy_cursor = 2; | |
3537 | #endif | |
3538 | ||
d925fb39 RS |
3539 | call1 (Qtimer_event_handler, chosen_timer); |
3540 | timers_run++; | |
9291c072 | 3541 | |
7ee32cda GM |
3542 | #ifdef HAVE_WINDOW_SYSTEM |
3543 | inhibit_busy_cursor = old_inhibit_busy_cursor; | |
3544 | #endif | |
3545 | ||
d925fb39 | 3546 | unbind_to (count, Qnil); |
4ec4ed6a | 3547 | |
d925fb39 RS |
3548 | /* Resume allowing input from any kboard, if that was true before. */ |
3549 | if (!was_locked) | |
3550 | any_kboard_state (); | |
9291c072 | 3551 | |
d925fb39 RS |
3552 | /* Since we have handled the event, |
3553 | we don't need to tell the caller to wake up and do it. */ | |
9291c072 RS |
3554 | } |
3555 | } | |
3556 | else | |
3557 | /* When we encounter a timer that is still waiting, | |
3558 | return the amount of time to wait before it is ripe. */ | |
3559 | { | |
3560 | UNGCPRO; | |
9291c072 RS |
3561 | return difference; |
3562 | } | |
c04cbc3b | 3563 | } |
9291c072 | 3564 | |
7ea13e12 RS |
3565 | /* No timers are pending in the future. */ |
3566 | /* Return 0 if we generated an event, and -1 if not. */ | |
3567 | UNGCPRO; | |
c04cbc3b RS |
3568 | return nexttime; |
3569 | } | |
3570 | \f | |
284f4730 | 3571 | /* Caches for modify_event_symbol. */ |
e9bf89a0 | 3572 | static Lisp_Object accent_key_syms; |
284f4730 JB |
3573 | static Lisp_Object func_key_syms; |
3574 | static Lisp_Object mouse_syms; | |
07de30b9 GV |
3575 | #ifdef WINDOWSNT |
3576 | static Lisp_Object mouse_wheel_syms; | |
3577 | #endif | |
a24dc617 | 3578 | static Lisp_Object drag_n_drop_syms; |
284f4730 | 3579 | |
e9bf89a0 RS |
3580 | /* This is a list of keysym codes for special "accent" characters. |
3581 | It parallels lispy_accent_keys. */ | |
3582 | ||
3583 | static int lispy_accent_codes[] = | |
3584 | { | |
79a7046c | 3585 | #ifdef XK_dead_circumflex |
e9bf89a0 | 3586 | XK_dead_circumflex, |
79a7046c RS |
3587 | #else |
3588 | 0, | |
3589 | #endif | |
3590 | #ifdef XK_dead_grave | |
e9bf89a0 | 3591 | XK_dead_grave, |
79a7046c RS |
3592 | #else |
3593 | 0, | |
3594 | #endif | |
3595 | #ifdef XK_dead_tilde | |
e9bf89a0 | 3596 | XK_dead_tilde, |
79a7046c RS |
3597 | #else |
3598 | 0, | |
3599 | #endif | |
3600 | #ifdef XK_dead_diaeresis | |
e9bf89a0 | 3601 | XK_dead_diaeresis, |
79a7046c RS |
3602 | #else |
3603 | 0, | |
3604 | #endif | |
3605 | #ifdef XK_dead_macron | |
e9bf89a0 | 3606 | XK_dead_macron, |
79a7046c RS |
3607 | #else |
3608 | 0, | |
3609 | #endif | |
3610 | #ifdef XK_dead_degree | |
e9bf89a0 | 3611 | XK_dead_degree, |
79a7046c RS |
3612 | #else |
3613 | 0, | |
3614 | #endif | |
3615 | #ifdef XK_dead_acute | |
e9bf89a0 | 3616 | XK_dead_acute, |
79a7046c RS |
3617 | #else |
3618 | 0, | |
3619 | #endif | |
3620 | #ifdef XK_dead_cedilla | |
e9bf89a0 | 3621 | XK_dead_cedilla, |
79a7046c RS |
3622 | #else |
3623 | 0, | |
3624 | #endif | |
3625 | #ifdef XK_dead_breve | |
e9bf89a0 | 3626 | XK_dead_breve, |
79a7046c RS |
3627 | #else |
3628 | 0, | |
3629 | #endif | |
3630 | #ifdef XK_dead_ogonek | |
e9bf89a0 | 3631 | XK_dead_ogonek, |
79a7046c RS |
3632 | #else |
3633 | 0, | |
3634 | #endif | |
3635 | #ifdef XK_dead_caron | |
e9bf89a0 | 3636 | XK_dead_caron, |
79a7046c RS |
3637 | #else |
3638 | 0, | |
3639 | #endif | |
3640 | #ifdef XK_dead_doubleacute | |
e9bf89a0 | 3641 | XK_dead_doubleacute, |
79a7046c RS |
3642 | #else |
3643 | 0, | |
3644 | #endif | |
3645 | #ifdef XK_dead_abovedot | |
e9bf89a0 | 3646 | XK_dead_abovedot, |
79a7046c RS |
3647 | #else |
3648 | 0, | |
3649 | #endif | |
e9bf89a0 RS |
3650 | }; |
3651 | ||
3652 | /* This is a list of Lisp names for special "accent" characters. | |
3653 | It parallels lispy_accent_codes. */ | |
3654 | ||
3655 | static char *lispy_accent_keys[] = | |
3656 | { | |
3657 | "dead-circumflex", | |
3658 | "dead-grave", | |
3659 | "dead-tilde", | |
3660 | "dead-diaeresis", | |
3661 | "dead-macron", | |
3662 | "dead-degree", | |
3663 | "dead-acute", | |
3664 | "dead-cedilla", | |
3665 | "dead-breve", | |
3666 | "dead-ogonek", | |
3667 | "dead-caron", | |
3668 | "dead-doubleacute", | |
3669 | "dead-abovedot", | |
3670 | }; | |
3671 | ||
e98a93eb GV |
3672 | #ifdef HAVE_NTGUI |
3673 | #define FUNCTION_KEY_OFFSET 0x0 | |
3674 | ||
3675 | char *lispy_function_keys[] = | |
3676 | { | |
3677 | 0, /* 0 */ | |
3678 | ||
3679 | 0, /* VK_LBUTTON 0x01 */ | |
3680 | 0, /* VK_RBUTTON 0x02 */ | |
3681 | "cancel", /* VK_CANCEL 0x03 */ | |
3682 | 0, /* VK_MBUTTON 0x04 */ | |
3683 | ||
3684 | 0, 0, 0, /* 0x05 .. 0x07 */ | |
3685 | ||
3686 | "backspace", /* VK_BACK 0x08 */ | |
3687 | "tab", /* VK_TAB 0x09 */ | |
3688 | ||
3689 | 0, 0, /* 0x0A .. 0x0B */ | |
3690 | ||
3691 | "clear", /* VK_CLEAR 0x0C */ | |
3692 | "return", /* VK_RETURN 0x0D */ | |
3693 | ||
3694 | 0, 0, /* 0x0E .. 0x0F */ | |
3695 | ||
1161d367 GV |
3696 | 0, /* VK_SHIFT 0x10 */ |
3697 | 0, /* VK_CONTROL 0x11 */ | |
3698 | 0, /* VK_MENU 0x12 */ | |
e98a93eb | 3699 | "pause", /* VK_PAUSE 0x13 */ |
1161d367 | 3700 | "capslock", /* VK_CAPITAL 0x14 */ |
e98a93eb GV |
3701 | |
3702 | 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */ | |
3703 | ||
1161d367 | 3704 | "escape", /* VK_ESCAPE 0x1B */ |
e98a93eb GV |
3705 | |
3706 | 0, 0, 0, 0, /* 0x1C .. 0x1F */ | |
3707 | ||
3708 | 0, /* VK_SPACE 0x20 */ | |
3709 | "prior", /* VK_PRIOR 0x21 */ | |
3710 | "next", /* VK_NEXT 0x22 */ | |
3711 | "end", /* VK_END 0x23 */ | |
3712 | "home", /* VK_HOME 0x24 */ | |
3713 | "left", /* VK_LEFT 0x25 */ | |
3714 | "up", /* VK_UP 0x26 */ | |
3715 | "right", /* VK_RIGHT 0x27 */ | |
3716 | "down", /* VK_DOWN 0x28 */ | |
3717 | "select", /* VK_SELECT 0x29 */ | |
3718 | "print", /* VK_PRINT 0x2A */ | |
3719 | "execute", /* VK_EXECUTE 0x2B */ | |
3720 | "snapshot", /* VK_SNAPSHOT 0x2C */ | |
3721 | "insert", /* VK_INSERT 0x2D */ | |
3722 | "delete", /* VK_DELETE 0x2E */ | |
3723 | "help", /* VK_HELP 0x2F */ | |
3724 | ||
3725 | /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ | |
3726 | ||
3727 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3728 | ||
3729 | 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */ | |
3730 | ||
3731 | /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ | |
3732 | ||
3733 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3734 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3735 | 0, 0, 0, 0, 0, 0, 0, 0, | |
3736 | ||
e376f90d RS |
3737 | "lwindow", /* VK_LWIN 0x5B */ |
3738 | "rwindow", /* VK_RWIN 0x5C */ | |
3739 | "apps", /* VK_APPS 0x5D */ | |
e98a93eb GV |
3740 | |
3741 | 0, 0, /* 0x5E .. 0x5F */ | |
3742 | ||
3743 | "kp-0", /* VK_NUMPAD0 0x60 */ | |
3744 | "kp-1", /* VK_NUMPAD1 0x61 */ | |
3745 | "kp-2", /* VK_NUMPAD2 0x62 */ | |
3746 | "kp-3", /* VK_NUMPAD3 0x63 */ | |
3747 | "kp-4", /* VK_NUMPAD4 0x64 */ | |
3748 | "kp-5", /* VK_NUMPAD5 0x65 */ | |
3749 | "kp-6", /* VK_NUMPAD6 0x66 */ | |
3750 | "kp-7", /* VK_NUMPAD7 0x67 */ | |
3751 | "kp-8", /* VK_NUMPAD8 0x68 */ | |
3752 | "kp-9", /* VK_NUMPAD9 0x69 */ | |
3753 | "kp-multiply", /* VK_MULTIPLY 0x6A */ | |
3754 | "kp-add", /* VK_ADD 0x6B */ | |
3755 | "kp-separator", /* VK_SEPARATOR 0x6C */ | |
3756 | "kp-subtract", /* VK_SUBTRACT 0x6D */ | |
3757 | "kp-decimal", /* VK_DECIMAL 0x6E */ | |
3758 | "kp-divide", /* VK_DIVIDE 0x6F */ | |
3759 | "f1", /* VK_F1 0x70 */ | |
3760 | "f2", /* VK_F2 0x71 */ | |
3761 | "f3", /* VK_F3 0x72 */ | |
3762 | "f4", /* VK_F4 0x73 */ | |
3763 | "f5", /* VK_F5 0x74 */ | |
3764 | "f6", /* VK_F6 0x75 */ | |
3765 | "f7", /* VK_F7 0x76 */ | |
3766 | "f8", /* VK_F8 0x77 */ | |
3767 | "f9", /* VK_F9 0x78 */ | |
3768 | "f10", /* VK_F10 0x79 */ | |
3769 | "f11", /* VK_F11 0x7A */ | |
3770 | "f12", /* VK_F12 0x7B */ | |
3771 | "f13", /* VK_F13 0x7C */ | |
3772 | "f14", /* VK_F14 0x7D */ | |
3773 | "f15", /* VK_F15 0x7E */ | |
3774 | "f16", /* VK_F16 0x7F */ | |
3775 | "f17", /* VK_F17 0x80 */ | |
3776 | "f18", /* VK_F18 0x81 */ | |
3777 | "f19", /* VK_F19 0x82 */ | |
3778 | "f20", /* VK_F20 0x83 */ | |
3779 | "f21", /* VK_F21 0x84 */ | |
3780 | "f22", /* VK_F22 0x85 */ | |
3781 | "f23", /* VK_F23 0x86 */ | |
3782 | "f24", /* VK_F24 0x87 */ | |
3783 | ||
3784 | 0, 0, 0, 0, /* 0x88 .. 0x8B */ | |
3785 | 0, 0, 0, 0, /* 0x8C .. 0x8F */ | |
3786 | ||
3787 | "kp-numlock", /* VK_NUMLOCK 0x90 */ | |
3788 | "scroll", /* VK_SCROLL 0x91 */ | |
3789 | ||
e376f90d RS |
3790 | "kp-space", /* VK_NUMPAD_CLEAR 0x92 */ |
3791 | "kp-enter", /* VK_NUMPAD_ENTER 0x93 */ | |
3792 | "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */ | |
3793 | "kp-next", /* VK_NUMPAD_NEXT 0x95 */ | |
3794 | "kp-end", /* VK_NUMPAD_END 0x96 */ | |
3795 | "kp-home", /* VK_NUMPAD_HOME 0x97 */ | |
3796 | "kp-left", /* VK_NUMPAD_LEFT 0x98 */ | |
3797 | "kp-up", /* VK_NUMPAD_UP 0x99 */ | |
3798 | "kp-right", /* VK_NUMPAD_RIGHT 0x9A */ | |
3799 | "kp-down", /* VK_NUMPAD_DOWN 0x9B */ | |
3800 | "kp-insert", /* VK_NUMPAD_INSERT 0x9C */ | |
3801 | "kp-delete", /* VK_NUMPAD_DELETE 0x9D */ | |
3802 | ||
3803 | 0, 0, /* 0x9E .. 0x9F */ | |
3804 | ||
e98a93eb GV |
3805 | /* |
3806 | * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys. | |
e8886a1d | 3807 | * Used only as parameters to GetAsyncKeyState and GetKeyState. |
e98a93eb GV |
3808 | * No other API or message will distinguish left and right keys this way. |
3809 | */ | |
3810 | /* 0xA0 .. 0xEF */ | |
3811 | ||
3812 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3813 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3814 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3815 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3816 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3817 | ||
3818 | /* 0xF0 .. 0xF5 */ | |
3819 | ||
3820 | 0, 0, 0, 0, 0, 0, | |
3821 | ||
3822 | "attn", /* VK_ATTN 0xF6 */ | |
3823 | "crsel", /* VK_CRSEL 0xF7 */ | |
3824 | "exsel", /* VK_EXSEL 0xF8 */ | |
3825 | "ereof", /* VK_EREOF 0xF9 */ | |
3826 | "play", /* VK_PLAY 0xFA */ | |
3827 | "zoom", /* VK_ZOOM 0xFB */ | |
3828 | "noname", /* VK_NONAME 0xFC */ | |
3829 | "pa1", /* VK_PA1 0xFD */ | |
3830 | "oem_clear", /* VK_OEM_CLEAR 0xFE */ | |
1161d367 | 3831 | 0 /* 0xFF */ |
e98a93eb GV |
3832 | }; |
3833 | ||
04f215f0 | 3834 | #else /* not HAVE_NTGUI */ |
e98a93eb | 3835 | |
37cd9f30 KH |
3836 | #ifdef XK_kana_A |
3837 | static char *lispy_kana_keys[] = | |
3838 | { | |
3839 | /* X Keysym value */ | |
3840 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */ | |
3841 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */ | |
3842 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */ | |
3843 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */ | |
3844 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */ | |
3845 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */ | |
3846 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */ | |
3847 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0, | |
3848 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */ | |
3849 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */ | |
3850 | 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket", | |
3851 | "kana-comma", "kana-conjunctive", "kana-WO", "kana-a", | |
3852 | "kana-i", "kana-u", "kana-e", "kana-o", | |
3853 | "kana-ya", "kana-yu", "kana-yo", "kana-tsu", | |
3854 | "prolongedsound", "kana-A", "kana-I", "kana-U", | |
3855 | "kana-E", "kana-O", "kana-KA", "kana-KI", | |
3856 | "kana-KU", "kana-KE", "kana-KO", "kana-SA", | |
3857 | "kana-SHI", "kana-SU", "kana-SE", "kana-SO", | |
3858 | "kana-TA", "kana-CHI", "kana-TSU", "kana-TE", | |
3859 | "kana-TO", "kana-NA", "kana-NI", "kana-NU", | |
3860 | "kana-NE", "kana-NO", "kana-HA", "kana-HI", | |
3861 | "kana-FU", "kana-HE", "kana-HO", "kana-MA", | |
3862 | "kana-MI", "kana-MU", "kana-ME", "kana-MO", | |
3863 | "kana-YA", "kana-YU", "kana-YO", "kana-RA", | |
3864 | "kana-RI", "kana-RU", "kana-RE", "kana-RO", | |
3865 | "kana-WA", "kana-N", "voicedsound", "semivoicedsound", | |
3866 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */ | |
3867 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */ | |
3868 | }; | |
3869 | #endif /* XK_kana_A */ | |
3870 | ||
04f215f0 RS |
3871 | #define FUNCTION_KEY_OFFSET 0xff00 |
3872 | ||
284f4730 JB |
3873 | /* You'll notice that this table is arranged to be conveniently |
3874 | indexed by X Windows keysym values. */ | |
3875 | static char *lispy_function_keys[] = | |
3876 | { | |
3877 | /* X Keysym value */ | |
3878 | ||
75045dcb RS |
3879 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */ |
3880 | "backspace", "tab", "linefeed", "clear", | |
3881 | 0, "return", 0, 0, | |
3882 | 0, 0, 0, "pause", /* 0xff10...1f */ | |
3883 | 0, 0, 0, 0, 0, 0, 0, "escape", | |
86e5706b | 3884 | 0, 0, 0, 0, |
75045dcb RS |
3885 | 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */ |
3886 | "romaji", "hiragana", "katakana", "hiragana-katakana", | |
3887 | "zenkaku", "hankaku", "zenkaku-hankaku", "touroku", | |
3888 | "massyo", "kana-lock", "kana-shift", "eisu-shift", | |
3889 | "eisu-toggle", /* 0xff30...3f */ | |
3890 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
86e5706b RS |
3891 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */ |
3892 | ||
75045dcb RS |
3893 | "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */ |
3894 | "down", "prior", "next", "end", | |
3895 | "begin", 0, 0, 0, 0, 0, 0, 0, | |
284f4730 JB |
3896 | "select", /* 0xff60 */ /* IsMiscFunctionKey */ |
3897 | "print", | |
3898 | "execute", | |
3899 | "insert", | |
3900 | 0, /* 0xff64 */ | |
3901 | "undo", | |
3902 | "redo", | |
3903 | "menu", | |
3904 | "find", | |
3905 | "cancel", | |
3906 | "help", | |
3907 | "break", /* 0xff6b */ | |
3908 | ||
75045dcb RS |
3909 | 0, 0, 0, 0, |
3910 | 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */ | |
3911 | 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */ | |
284f4730 JB |
3912 | "kp-space", /* 0xff80 */ /* IsKeypadKey */ |
3913 | 0, 0, 0, 0, 0, 0, 0, 0, | |
3914 | "kp-tab", /* 0xff89 */ | |
3915 | 0, 0, 0, | |
3916 | "kp-enter", /* 0xff8d */ | |
3917 | 0, 0, 0, | |
3918 | "kp-f1", /* 0xff91 */ | |
3919 | "kp-f2", | |
3920 | "kp-f3", | |
3921 | "kp-f4", | |
872157e7 RS |
3922 | "kp-home", /* 0xff95 */ |
3923 | "kp-left", | |
3924 | "kp-up", | |
3925 | "kp-right", | |
3926 | "kp-down", | |
3927 | "kp-prior", /* kp-page-up */ | |
3928 | "kp-next", /* kp-page-down */ | |
3929 | "kp-end", | |
3930 | "kp-begin", | |
3931 | "kp-insert", | |
3932 | "kp-delete", | |
3933 | 0, /* 0xffa0 */ | |
3934 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
284f4730 JB |
3935 | "kp-multiply", /* 0xffaa */ |
3936 | "kp-add", | |
3937 | "kp-separator", | |
3938 | "kp-subtract", | |
3939 | "kp-decimal", | |
3940 | "kp-divide", /* 0xffaf */ | |
3941 | "kp-0", /* 0xffb0 */ | |
3942 | "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9", | |
3943 | 0, /* 0xffba */ | |
3944 | 0, 0, | |
3945 | "kp-equal", /* 0xffbd */ | |
3946 | "f1", /* 0xffbe */ /* IsFunctionKey */ | |
86e5706b RS |
3947 | "f2", |
3948 | "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */ | |
3949 | "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", | |
3950 | "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */ | |
3951 | "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34", | |
3952 | "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */ | |
3953 | 0, 0, 0, 0, 0, 0, 0, 0, | |
3954 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */ | |
3955 | 0, 0, 0, 0, 0, 0, 0, "delete" | |
04f215f0 | 3956 | }; |
284f4730 | 3957 | |
04f215f0 RS |
3958 | /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */ |
3959 | #define ISO_FUNCTION_KEY_OFFSET 0xfe00 | |
3960 | ||
3961 | static char *iso_lispy_function_keys[] = | |
3962 | { | |
3963 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */ | |
3964 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */ | |
3965 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */ | |
3966 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */ | |
3967 | "iso-lefttab", /* 0xfe20 */ | |
3968 | "iso-move-line-up", "iso-move-line-down", | |
3969 | "iso-partial-line-up", "iso-partial-line-down", | |
3970 | "iso-partial-space-left", "iso-partial-space-right", | |
3971 | "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */ | |
3972 | "iso-release-margin-left", "iso-release-margin-right", | |
3973 | "iso-release-both-margins", | |
3974 | "iso-fast-cursor-left", "iso-fast-cursor-right", | |
3975 | "iso-fast-cursor-up", "iso-fast-cursor-down", | |
3976 | "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */ | |
3977 | "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */ | |
3978 | }; | |
3979 | ||
3980 | #endif /* not HAVE_NTGUI */ | |
e98a93eb | 3981 | |
df0f2ba1 | 3982 | static char *lispy_mouse_names[] = |
284f4730 JB |
3983 | { |
3984 | "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5" | |
3985 | }; | |
3986 | ||
07de30b9 GV |
3987 | #ifdef WINDOWSNT |
3988 | /* mouse-wheel events are generated by the wheel on devices such as | |
3989 | the MS Intellimouse. The wheel sits in between the left and right | |
3990 | mouse buttons, and is typically used to scroll or zoom the window | |
3991 | underneath the pointer. mouse-wheel events specify the object on | |
3992 | which they operate, and a delta corresponding to the amount and | |
3993 | direction that the wheel is rotated. Clicking the mouse-wheel | |
3994 | generates a mouse-2 event. */ | |
3995 | static char *lispy_mouse_wheel_names[] = | |
3996 | { | |
3997 | "mouse-wheel" | |
3998 | }; | |
a24dc617 | 3999 | |
07de30b9 GV |
4000 | #endif /* WINDOWSNT */ |
4001 | ||
a24dc617 RS |
4002 | /* drag-n-drop events are generated when a set of selected files are |
4003 | dragged from another application and dropped onto an Emacs window. */ | |
4004 | static char *lispy_drag_n_drop_names[] = | |
4005 | { | |
4006 | "drag-n-drop" | |
4007 | }; | |
4008 | ||
3c370943 | 4009 | /* Scroll bar parts. */ |
4bb994d1 | 4010 | Lisp_Object Qabove_handle, Qhandle, Qbelow_handle; |
7ee32cda GM |
4011 | Lisp_Object Qup, Qdown, Qbottom, Qend_scroll; |
4012 | Lisp_Object Qtop; | |
4bb994d1 | 4013 | |
3c370943 JB |
4014 | /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */ |
4015 | Lisp_Object *scroll_bar_parts[] = { | |
db08707d | 4016 | &Qabove_handle, &Qhandle, &Qbelow_handle, |
7ee32cda | 4017 | &Qup, &Qdown, &Qtop, &Qbottom, &Qend_scroll |
4bb994d1 JB |
4018 | }; |
4019 | ||
5bf68f6e AS |
4020 | /* User signal events. */ |
4021 | Lisp_Object Qusr1_signal, Qusr2_signal; | |
4022 | ||
4023 | Lisp_Object *lispy_user_signals[] = | |
4024 | { | |
4025 | &Qusr1_signal, &Qusr2_signal | |
4026 | }; | |
4027 | ||
4bb994d1 | 4028 | |
7b4aedb9 | 4029 | /* A vector, indexed by button number, giving the down-going location |
3c370943 | 4030 | of currently depressed buttons, both scroll bar and non-scroll bar. |
7b4aedb9 JB |
4031 | |
4032 | The elements have the form | |
4033 | (BUTTON-NUMBER MODIFIER-MASK . REST) | |
4034 | where REST is the cdr of a position as it would be reported in the event. | |
4035 | ||
4036 | The make_lispy_event function stores positions here to tell the | |
4037 | difference between click and drag events, and to store the starting | |
4038 | location to be included in drag events. */ | |
4039 | ||
4040 | static Lisp_Object button_down_location; | |
88cb0656 | 4041 | |
fbcd35bd JB |
4042 | /* Information about the most recent up-going button event: Which |
4043 | button, what location, and what time. */ | |
4044 | ||
559f9d04 RS |
4045 | static int last_mouse_button; |
4046 | static int last_mouse_x; | |
4047 | static int last_mouse_y; | |
4048 | static unsigned long button_down_time; | |
fbcd35bd | 4049 | |
564dc952 JB |
4050 | /* The maximum time between clicks to make a double-click, |
4051 | or Qnil to disable double-click detection, | |
4052 | or Qt for no time limit. */ | |
4053 | Lisp_Object Vdouble_click_time; | |
fbcd35bd JB |
4054 | |
4055 | /* The number of clicks in this multiple-click. */ | |
4056 | ||
4057 | int double_click_count; | |
4058 | ||
284f4730 JB |
4059 | /* Given a struct input_event, build the lisp event which represents |
4060 | it. If EVENT is 0, build a mouse movement event from the mouse | |
88cb0656 JB |
4061 | movement buffer, which should have a movement event in it. |
4062 | ||
4063 | Note that events must be passed to this function in the order they | |
4064 | are received; this function stores the location of button presses | |
4065 | in order to build drag events when the button is released. */ | |
284f4730 JB |
4066 | |
4067 | static Lisp_Object | |
4068 | make_lispy_event (event) | |
4069 | struct input_event *event; | |
4070 | { | |
79a7046c RS |
4071 | int i; |
4072 | ||
0220c518 | 4073 | switch (SWITCH_ENUM_CAST (event->kind)) |
284f4730 | 4074 | { |
284f4730 JB |
4075 | /* A simple keystroke. */ |
4076 | case ascii_keystroke: | |
86e5706b | 4077 | { |
9343ab07 | 4078 | Lisp_Object lispy_c; |
e9bf89a0 | 4079 | int c = event->code & 0377; |
5a1c6df8 JB |
4080 | /* Turn ASCII characters into control characters |
4081 | when proper. */ | |
4082 | if (event->modifiers & ctrl_modifier) | |
d205953b JB |
4083 | c = make_ctrl_char (c); |
4084 | ||
4085 | /* Add in the other modifier bits. We took care of ctrl_modifier | |
4086 | just above, and the shift key was taken care of by the X code, | |
4087 | and applied to control characters by make_ctrl_char. */ | |
86e5706b RS |
4088 | c |= (event->modifiers |
4089 | & (meta_modifier | alt_modifier | |
4090 | | hyper_modifier | super_modifier)); | |
32454a9f RS |
4091 | /* Distinguish Shift-SPC from SPC. */ |
4092 | if ((event->code & 0377) == 040 | |
4093 | && event->modifiers & shift_modifier) | |
4094 | c |= shift_modifier; | |
559f9d04 | 4095 | button_down_time = 0; |
bb9e9bed | 4096 | XSETFASTINT (lispy_c, c); |
9343ab07 | 4097 | return lispy_c; |
86e5706b | 4098 | } |
284f4730 JB |
4099 | |
4100 | /* A function key. The symbol may need to have modifier prefixes | |
4101 | tacked onto it. */ | |
4102 | case non_ascii_keystroke: | |
559f9d04 | 4103 | button_down_time = 0; |
e9bf89a0 RS |
4104 | |
4105 | for (i = 0; i < sizeof (lispy_accent_codes) / sizeof (int); i++) | |
4106 | if (event->code == lispy_accent_codes[i]) | |
4107 | return modify_event_symbol (i, | |
4108 | event->modifiers, | |
80e4aa30 | 4109 | Qfunction_key, Qnil, |
e9bf89a0 RS |
4110 | lispy_accent_keys, &accent_key_syms, |
4111 | (sizeof (lispy_accent_keys) | |
4112 | / sizeof (lispy_accent_keys[0]))); | |
4113 | ||
270a208f | 4114 | /* Handle system-specific keysyms. */ |
80e4aa30 RS |
4115 | if (event->code & (1 << 28)) |
4116 | { | |
4117 | /* We need to use an alist rather than a vector as the cache | |
4118 | since we can't make a vector long enuf. */ | |
142e6c73 KH |
4119 | if (NILP (current_kboard->system_key_syms)) |
4120 | current_kboard->system_key_syms = Fcons (Qnil, Qnil); | |
2c834fb3 | 4121 | return modify_event_symbol (event->code, |
80e4aa30 | 4122 | event->modifiers, |
7c97ffdc KH |
4123 | Qfunction_key, |
4124 | current_kboard->Vsystem_key_alist, | |
142e6c73 KH |
4125 | 0, ¤t_kboard->system_key_syms, |
4126 | (unsigned)-1); | |
80e4aa30 RS |
4127 | } |
4128 | ||
37cd9f30 KH |
4129 | #ifdef XK_kana_A |
4130 | if (event->code >= 0x400 && event->code < 0x500) | |
4131 | return modify_event_symbol (event->code - 0x400, | |
4132 | event->modifiers & ~shift_modifier, | |
4133 | Qfunction_key, Qnil, | |
4134 | lispy_kana_keys, &func_key_syms, | |
4135 | (sizeof (lispy_kana_keys) | |
4136 | / sizeof (lispy_kana_keys[0]))); | |
4137 | #endif /* XK_kana_A */ | |
4138 | ||
111c4138 | 4139 | #ifdef ISO_FUNCTION_KEY_OFFSET |
04f215f0 RS |
4140 | if (event->code < FUNCTION_KEY_OFFSET |
4141 | && event->code >= ISO_FUNCTION_KEY_OFFSET) | |
4142 | return modify_event_symbol (event->code - ISO_FUNCTION_KEY_OFFSET, | |
4143 | event->modifiers, | |
4144 | Qfunction_key, Qnil, | |
4145 | iso_lispy_function_keys, &func_key_syms, | |
4146 | (sizeof (iso_lispy_function_keys) | |
4147 | / sizeof (iso_lispy_function_keys[0]))); | |
4148 | else | |
111c4138 | 4149 | #endif |
04f215f0 RS |
4150 | return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET, |
4151 | event->modifiers, | |
4152 | Qfunction_key, Qnil, | |
4153 | lispy_function_keys, &func_key_syms, | |
4154 | (sizeof (lispy_function_keys) | |
4155 | / sizeof (lispy_function_keys[0]))); | |
284f4730 | 4156 | |
514354e9 | 4157 | #ifdef HAVE_MOUSE |
df0f2ba1 | 4158 | /* A mouse click. Figure out where it is, decide whether it's |
88cb0656 | 4159 | a press, click or drag, and build the appropriate structure. */ |
284f4730 | 4160 | case mouse_click: |
7ee32cda | 4161 | #ifndef USE_TOOLKIT_SCROLL_BARS |
3c370943 | 4162 | case scroll_bar_click: |
7ee32cda | 4163 | #endif |
284f4730 | 4164 | { |
e9bf89a0 | 4165 | int button = event->code; |
559f9d04 | 4166 | int is_double; |
7b4aedb9 | 4167 | Lisp_Object position; |
dbc4e1c1 JB |
4168 | Lisp_Object *start_pos_ptr; |
4169 | Lisp_Object start_pos; | |
284f4730 | 4170 | |
7b4aedb9 | 4171 | if (button < 0 || button >= NUM_MOUSE_BUTTONS) |
88cb0656 JB |
4172 | abort (); |
4173 | ||
7b4aedb9 JB |
4174 | /* Build the position as appropriate for this mouse click. */ |
4175 | if (event->kind == mouse_click) | |
284f4730 | 4176 | { |
7b4aedb9 | 4177 | int part; |
598a9fa7 | 4178 | FRAME_PTR f = XFRAME (event->frame_or_window); |
0aafc975 | 4179 | Lisp_Object window; |
7b4aedb9 | 4180 | Lisp_Object posn; |
7ee32cda | 4181 | Lisp_Object string_info = Qnil; |
9e20143a RS |
4182 | int row, column; |
4183 | ||
5da3133a RS |
4184 | /* Ignore mouse events that were made on frame that |
4185 | have been deleted. */ | |
4186 | if (! FRAME_LIVE_P (f)) | |
4187 | return Qnil; | |
4188 | ||
7ee32cda GM |
4189 | /* EVENT->x and EVENT->y are frame-relative pixel |
4190 | coordinates at this place. Under old redisplay, COLUMN | |
4191 | and ROW are set to frame relative glyph coordinates | |
4192 | which are then used to determine whether this click is | |
4193 | in a menu (non-toolkit version). */ | |
4194 | pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), | |
4195 | &column, &row, NULL, 1); | |
7b4aedb9 | 4196 | |
eef045bf RS |
4197 | #ifndef USE_X_TOOLKIT |
4198 | /* In the non-toolkit version, clicks on the menu bar | |
4199 | are ordinary button events in the event buffer. | |
4200 | Distinguish them, and invoke the menu. | |
4201 | ||
4202 | (In the toolkit version, the toolkit handles the menu bar | |
4203 | and Emacs doesn't know about it until after the user | |
4204 | makes a selection.) */ | |
2ee250ec RS |
4205 | if (row >= 0 && row < FRAME_MENU_BAR_LINES (f) |
4206 | && (event->modifiers & down_modifier)) | |
bb936752 | 4207 | { |
b7c49376 | 4208 | Lisp_Object items, item; |
0a0e8fe6 RS |
4209 | int hpos; |
4210 | int i; | |
4211 | ||
2ee250ec | 4212 | #if 0 |
0a0e8fe6 RS |
4213 | /* Activate the menu bar on the down event. If the |
4214 | up event comes in before the menu code can deal with it, | |
4215 | just ignore it. */ | |
4216 | if (! (event->modifiers & down_modifier)) | |
4217 | return Qnil; | |
2ee250ec | 4218 | #endif |
0aafc975 | 4219 | |
7ee32cda | 4220 | /* Find the menu bar item under `column'. */ |
f2ae6b3f | 4221 | item = Qnil; |
5ec75a55 | 4222 | items = FRAME_MENU_BAR_ITEMS (f); |
35b3402f | 4223 | for (i = 0; i < XVECTOR (items)->size; i += 4) |
5ec75a55 RS |
4224 | { |
4225 | Lisp_Object pos, string; | |
b7c49376 | 4226 | string = XVECTOR (items)->contents[i + 1]; |
35b3402f | 4227 | pos = XVECTOR (items)->contents[i + 3]; |
b7c49376 RS |
4228 | if (NILP (string)) |
4229 | break; | |
9e20143a RS |
4230 | if (column >= XINT (pos) |
4231 | && column < XINT (pos) + XSTRING (string)->size) | |
b7c49376 RS |
4232 | { |
4233 | item = XVECTOR (items)->contents[i]; | |
4234 | break; | |
4235 | } | |
5ec75a55 | 4236 | } |
9e20143a | 4237 | |
7ee32cda GM |
4238 | /* ELisp manual 2.4b says (x y) are window relative but |
4239 | code says they are frame-relative. */ | |
5ec75a55 RS |
4240 | position |
4241 | = Fcons (event->frame_or_window, | |
4242 | Fcons (Qmenu_bar, | |
4243 | Fcons (Fcons (event->x, event->y), | |
4244 | Fcons (make_number (event->timestamp), | |
4245 | Qnil)))); | |
4246 | ||
b7c49376 | 4247 | return Fcons (item, Fcons (position, Qnil)); |
5ec75a55 | 4248 | } |
eef045bf | 4249 | #endif /* not USE_X_TOOLKIT */ |
0aafc975 | 4250 | |
7ee32cda GM |
4251 | /* Set `window' to the window under frame pixel coordinates |
4252 | event->x/event->y. */ | |
4253 | window = window_from_coordinates (f, XINT (event->x), | |
4254 | XINT (event->y), &part, 0); | |
0aafc975 | 4255 | |
8c18cbfb | 4256 | if (!WINDOWP (window)) |
78ced549 RS |
4257 | { |
4258 | window = event->frame_or_window; | |
4259 | posn = Qnil; | |
4260 | } | |
284f4730 | 4261 | else |
7b4aedb9 | 4262 | { |
7ee32cda GM |
4263 | /* It's a click in window window at frame coordinates |
4264 | event->x/ event->y. */ | |
4265 | struct window *w = XWINDOW (window); | |
4266 | ||
4267 | /* Get window relative coordinates. Original code | |
4268 | `rounded' this to glyph boundaries. */ | |
4269 | int wx = FRAME_TO_WINDOW_PIXEL_X (w, XINT (event->x)); | |
4270 | int wy = FRAME_TO_WINDOW_PIXEL_Y (w, XINT (event->y)); | |
4271 | ||
4272 | /* Set event coordinates to window-relative coordinates | |
4273 | for constructing the Lisp event below. */ | |
4274 | XSETINT (event->x, wx); | |
4275 | XSETINT (event->y, wy); | |
4276 | ||
4277 | if (part == 1 || part == 3) | |
4278 | { | |
4279 | /* Mode line or top line. Look for a string under | |
4280 | the mouse that may have a `local-map' property. */ | |
4281 | Lisp_Object string; | |
4282 | int charpos; | |
4283 | ||
045dee35 | 4284 | posn = part == 1 ? Qmode_line : Qheader_line; |
7ee32cda GM |
4285 | string = mode_line_string (w, wx, wy, part == 1, &charpos); |
4286 | if (STRINGP (string)) | |
4287 | string_info = Fcons (string, make_number (charpos)); | |
4288 | } | |
7b4aedb9 JB |
4289 | else if (part == 2) |
4290 | posn = Qvertical_line; | |
4291 | else | |
7ee32cda | 4292 | XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy)); |
7b4aedb9 JB |
4293 | } |
4294 | ||
5ec75a55 RS |
4295 | position |
4296 | = Fcons (window, | |
4297 | Fcons (posn, | |
4298 | Fcons (Fcons (event->x, event->y), | |
4299 | Fcons (make_number (event->timestamp), | |
7ee32cda GM |
4300 | (NILP (string_info) |
4301 | ? Qnil | |
4302 | : Fcons (string_info, Qnil)))))); | |
284f4730 | 4303 | } |
7ee32cda | 4304 | #ifndef USE_TOOLKIT_SCROLL_BARS |
7b4aedb9 | 4305 | else |
88cb0656 | 4306 | { |
7ee32cda | 4307 | /* It's a scrollbar click. */ |
9e20143a RS |
4308 | Lisp_Object window; |
4309 | Lisp_Object portion_whole; | |
4310 | Lisp_Object part; | |
4311 | ||
4312 | window = event->frame_or_window; | |
4313 | portion_whole = Fcons (event->x, event->y); | |
4314 | part = *scroll_bar_parts[(int) event->part]; | |
7b4aedb9 | 4315 | |
db08707d RS |
4316 | position |
4317 | = Fcons (window, | |
4318 | Fcons (Qvertical_scroll_bar, | |
4319 | Fcons (portion_whole, | |
4320 | Fcons (make_number (event->timestamp), | |
4321 | Fcons (part, Qnil))))); | |
88cb0656 | 4322 | } |
7ee32cda | 4323 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
88cb0656 | 4324 | |
dbc4e1c1 JB |
4325 | start_pos_ptr = &XVECTOR (button_down_location)->contents[button]; |
4326 | ||
4327 | start_pos = *start_pos_ptr; | |
4328 | *start_pos_ptr = Qnil; | |
7b4aedb9 | 4329 | |
559f9d04 RS |
4330 | is_double = (button == last_mouse_button |
4331 | && XINT (event->x) == last_mouse_x | |
4332 | && XINT (event->y) == last_mouse_y | |
4333 | && button_down_time != 0 | |
4334 | && (EQ (Vdouble_click_time, Qt) | |
4335 | || (INTEGERP (Vdouble_click_time) | |
4336 | && ((int)(event->timestamp - button_down_time) | |
4337 | < XINT (Vdouble_click_time))))); | |
4338 | last_mouse_button = button; | |
4339 | last_mouse_x = XINT (event->x); | |
4340 | last_mouse_y = XINT (event->y); | |
4341 | ||
7b4aedb9 JB |
4342 | /* If this is a button press, squirrel away the location, so |
4343 | we can decide later whether it was a click or a drag. */ | |
4344 | if (event->modifiers & down_modifier) | |
559f9d04 RS |
4345 | { |
4346 | if (is_double) | |
4347 | { | |
4348 | double_click_count++; | |
4349 | event->modifiers |= ((double_click_count > 2) | |
4350 | ? triple_modifier | |
4351 | : double_modifier); | |
4352 | } | |
4353 | else | |
4354 | double_click_count = 1; | |
4355 | button_down_time = event->timestamp; | |
4356 | *start_pos_ptr = Fcopy_alist (position); | |
4357 | } | |
7b4aedb9 | 4358 | |
88cb0656 | 4359 | /* Now we're releasing a button - check the co-ordinates to |
7b4aedb9 | 4360 | see if this was a click or a drag. */ |
88cb0656 JB |
4361 | else if (event->modifiers & up_modifier) |
4362 | { | |
48e416d4 RS |
4363 | /* If we did not see a down before this up, |
4364 | ignore the up. Probably this happened because | |
4365 | the down event chose a menu item. | |
4366 | It would be an annoyance to treat the release | |
4367 | of the button that chose the menu item | |
4368 | as a separate event. */ | |
4369 | ||
8c18cbfb | 4370 | if (!CONSP (start_pos)) |
48e416d4 RS |
4371 | return Qnil; |
4372 | ||
88cb0656 | 4373 | event->modifiers &= ~up_modifier; |
48e416d4 | 4374 | #if 0 /* Formerly we treated an up with no down as a click event. */ |
8c18cbfb | 4375 | if (!CONSP (start_pos)) |
dbc4e1c1 JB |
4376 | event->modifiers |= click_modifier; |
4377 | else | |
48e416d4 | 4378 | #endif |
dbc4e1c1 JB |
4379 | { |
4380 | /* The third element of every position should be the (x,y) | |
4381 | pair. */ | |
9b8eb840 | 4382 | Lisp_Object down; |
dbc4e1c1 | 4383 | |
9b8eb840 | 4384 | down = Fnth (make_number (2), start_pos); |
fbcd35bd JB |
4385 | if (EQ (event->x, XCONS (down)->car) |
4386 | && EQ (event->y, XCONS (down)->cdr)) | |
4387 | { | |
bc536d84 | 4388 | event->modifiers |= click_modifier; |
fbcd35bd JB |
4389 | } |
4390 | else | |
4391 | { | |
559f9d04 | 4392 | button_down_time = 0; |
fbcd35bd JB |
4393 | event->modifiers |= drag_modifier; |
4394 | } | |
bc536d84 RS |
4395 | /* Don't check is_double; treat this as multiple |
4396 | if the down-event was multiple. */ | |
4397 | if (double_click_count > 1) | |
4398 | event->modifiers |= ((double_click_count > 2) | |
4399 | ? triple_modifier | |
4400 | : double_modifier); | |
dbc4e1c1 | 4401 | } |
88cb0656 JB |
4402 | } |
4403 | else | |
4404 | /* Every mouse event should either have the down_modifier or | |
7b4aedb9 | 4405 | the up_modifier set. */ |
88cb0656 JB |
4406 | abort (); |
4407 | ||
88cb0656 | 4408 | { |
7b4aedb9 | 4409 | /* Get the symbol we should use for the mouse click. */ |
9b8eb840 KH |
4410 | Lisp_Object head; |
4411 | ||
4412 | head = modify_event_symbol (button, | |
4413 | event->modifiers, | |
4414 | Qmouse_click, Qnil, | |
4415 | lispy_mouse_names, &mouse_syms, | |
4416 | (sizeof (lispy_mouse_names) | |
4417 | / sizeof (lispy_mouse_names[0]))); | |
88cb0656 | 4418 | if (event->modifiers & drag_modifier) |
dbc4e1c1 JB |
4419 | return Fcons (head, |
4420 | Fcons (start_pos, | |
4421 | Fcons (position, | |
4422 | Qnil))); | |
fbcd35bd JB |
4423 | else if (event->modifiers & (double_modifier | triple_modifier)) |
4424 | return Fcons (head, | |
4425 | Fcons (position, | |
4426 | Fcons (make_number (double_click_count), | |
4427 | Qnil))); | |
88cb0656 JB |
4428 | else |
4429 | return Fcons (head, | |
7b4aedb9 | 4430 | Fcons (position, |
88cb0656 JB |
4431 | Qnil)); |
4432 | } | |
284f4730 | 4433 | } |
db08707d | 4434 | |
7ee32cda GM |
4435 | #if USE_TOOLKIT_SCROLL_BARS |
4436 | ||
4437 | /* We don't have down and up events if using toolkit scroll bars, | |
4438 | so make this always a click event. Store in the `part' of | |
4439 | the Lisp event a symbol which maps to the following actions: | |
4440 | ||
4441 | `above_handle' page up | |
4442 | `below_handle' page down | |
4443 | `up' line up | |
4444 | `down' line down | |
4445 | `top' top of buffer | |
4446 | `bottom' bottom of buffer | |
4447 | `handle' thumb has been dragged. | |
4448 | `end-scroll' end of interaction with scroll bar | |
4449 | ||
4450 | The incoming input_event contains in its `part' member an | |
4451 | index of type `enum scroll_bar_part' which we can use as an | |
4452 | index in scroll_bar_parts to get the appropriate symbol. */ | |
4453 | ||
4454 | case scroll_bar_click: | |
4455 | { | |
4456 | Lisp_Object position, head, window, portion_whole, part; | |
4457 | ||
4458 | window = event->frame_or_window; | |
4459 | portion_whole = Fcons (event->x, event->y); | |
4460 | part = *scroll_bar_parts[(int) event->part]; | |
4461 | ||
4462 | position | |
4463 | = Fcons (window, | |
4464 | Fcons (Qvertical_scroll_bar, | |
4465 | Fcons (portion_whole, | |
4466 | Fcons (make_number (event->timestamp), | |
4467 | Fcons (part, Qnil))))); | |
4468 | ||
4469 | /* Always treat scroll bar events as clicks. */ | |
4470 | event->modifiers |= click_modifier; | |
4471 | ||
4472 | /* Get the symbol we should use for the mouse click. */ | |
4473 | head = modify_event_symbol (event->code, | |
4474 | event->modifiers, | |
4475 | Qmouse_click, Qnil, | |
4476 | lispy_mouse_names, &mouse_syms, | |
4477 | (sizeof (lispy_mouse_names) | |
4478 | / sizeof (lispy_mouse_names[0]))); | |
4479 | return Fcons (head, Fcons (position, Qnil)); | |
4480 | } | |
4481 | ||
4482 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
4483 | ||
db08707d | 4484 | #ifdef WINDOWSNT |
fbd6baed | 4485 | case w32_scroll_bar_click: |
db08707d RS |
4486 | { |
4487 | int button = event->code; | |
4488 | int is_double; | |
4489 | Lisp_Object position; | |
4490 | Lisp_Object *start_pos_ptr; | |
4491 | Lisp_Object start_pos; | |
4492 | ||
4493 | if (button < 0 || button >= NUM_MOUSE_BUTTONS) | |
4494 | abort (); | |
4495 | ||
4496 | { | |
4497 | Lisp_Object window; | |
4498 | Lisp_Object portion_whole; | |
4499 | Lisp_Object part; | |
4500 | ||
4501 | window = event->frame_or_window; | |
4502 | portion_whole = Fcons (event->x, event->y); | |
4503 | part = *scroll_bar_parts[(int) event->part]; | |
4504 | ||
e8886a1d RS |
4505 | position |
4506 | = Fcons (window, | |
4507 | Fcons (Qvertical_scroll_bar, | |
4508 | Fcons (portion_whole, | |
4509 | Fcons (make_number (event->timestamp), | |
4510 | Fcons (part, Qnil))))); | |
db08707d RS |
4511 | } |
4512 | ||
fbd6baed | 4513 | /* Always treat W32 scroll bar events as clicks. */ |
db08707d RS |
4514 | event->modifiers |= click_modifier; |
4515 | ||
4516 | { | |
4517 | /* Get the symbol we should use for the mouse click. */ | |
4518 | Lisp_Object head; | |
4519 | ||
4520 | head = modify_event_symbol (button, | |
4521 | event->modifiers, | |
4522 | Qmouse_click, Qnil, | |
4523 | lispy_mouse_names, &mouse_syms, | |
4524 | (sizeof (lispy_mouse_names) | |
4525 | / sizeof (lispy_mouse_names[0]))); | |
4526 | return Fcons (head, | |
4527 | Fcons (position, | |
4528 | Qnil)); | |
4529 | } | |
4530 | } | |
07de30b9 GV |
4531 | case mouse_wheel: |
4532 | { | |
4533 | int part; | |
4534 | FRAME_PTR f = XFRAME (event->frame_or_window); | |
4535 | Lisp_Object window; | |
4536 | Lisp_Object posn; | |
4537 | Lisp_Object head, position; | |
4538 | int row, column; | |
4539 | ||
4540 | /* Ignore mouse events that were made on frame that | |
4541 | have been deleted. */ | |
4542 | if (! FRAME_LIVE_P (f)) | |
4543 | return Qnil; | |
4544 | pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), | |
4545 | &column, &row, NULL, 1); | |
7ee32cda | 4546 | window = window_from_coordinates (f, column, row, &part, 0); |
07de30b9 GV |
4547 | |
4548 | if (!WINDOWP (window)) | |
4549 | { | |
4550 | window = event->frame_or_window; | |
4551 | posn = Qnil; | |
4552 | } | |
4553 | else | |
4554 | { | |
4555 | int pixcolumn, pixrow; | |
4556 | column -= XINT (XWINDOW (window)->left); | |
4557 | row -= XINT (XWINDOW (window)->top); | |
4558 | glyph_to_pixel_coords (f, column, row, &pixcolumn, &pixrow); | |
4559 | XSETINT (event->x, pixcolumn); | |
4560 | XSETINT (event->y, pixrow); | |
4561 | ||
4562 | if (part == 1) | |
4563 | posn = Qmode_line; | |
4564 | else if (part == 2) | |
4565 | posn = Qvertical_line; | |
7ee32cda | 4566 | else if (part == 3) |
045dee35 | 4567 | posn = Qheader_line; |
07de30b9 GV |
4568 | else |
4569 | XSETINT (posn, | |
4570 | buffer_posn_from_coords (XWINDOW (window), | |
4571 | column, row)); | |
4572 | } | |
db08707d | 4573 | |
07de30b9 GV |
4574 | { |
4575 | Lisp_Object head, position; | |
4576 | ||
4577 | position | |
4578 | = Fcons (window, | |
4579 | Fcons (posn, | |
4580 | Fcons (Fcons (event->x, event->y), | |
4581 | Fcons (make_number (event->timestamp), | |
4582 | Qnil)))); | |
4583 | ||
4584 | head = modify_event_symbol (0, event->modifiers, | |
4585 | Qmouse_wheel, Qnil, | |
4586 | lispy_mouse_wheel_names, | |
4587 | &mouse_wheel_syms, 1); | |
4588 | return Fcons (head, | |
4589 | Fcons (position, | |
4590 | Fcons (make_number (event->code), | |
4591 | Qnil))); | |
4592 | } | |
4593 | } | |
4594 | #endif /* WINDOWSNT */ | |
a24dc617 RS |
4595 | |
4596 | case drag_n_drop: | |
4597 | { | |
4598 | int part; | |
4599 | FRAME_PTR f; | |
4600 | Lisp_Object window; | |
4601 | Lisp_Object posn; | |
4602 | Lisp_Object head, position; | |
4603 | Lisp_Object files; | |
4604 | int row, column; | |
4605 | ||
4606 | /* The frame_or_window field should be a cons of the frame in | |
4607 | which the event occurred and a list of the filenames | |
4608 | dropped. */ | |
4609 | if (! CONSP (event->frame_or_window)) | |
4610 | abort (); | |
4611 | ||
4612 | f = XFRAME (XCONS (event->frame_or_window)->car); | |
4613 | files = XCONS (event->frame_or_window)->cdr; | |
4614 | ||
4615 | /* Ignore mouse events that were made on frames that | |
4616 | have been deleted. */ | |
4617 | if (! FRAME_LIVE_P (f)) | |
4618 | return Qnil; | |
4619 | pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), | |
4620 | &column, &row, NULL, 1); | |
7ee32cda | 4621 | window = window_from_coordinates (f, column, row, &part, 0); |
a24dc617 RS |
4622 | |
4623 | if (!WINDOWP (window)) | |
4624 | { | |
4625 | window = XCONS (event->frame_or_window)->car; | |
4626 | posn = Qnil; | |
4627 | } | |
4628 | else | |
4629 | { | |
7ee32cda GM |
4630 | /* It's an event in window `window' at frame coordinates |
4631 | event->x/ event->y. */ | |
4632 | struct window *w = XWINDOW (window); | |
4633 | ||
4634 | /* Get window relative coordinates. */ | |
4635 | int wx = FRAME_TO_WINDOW_PIXEL_X (w, XINT (event->x)); | |
4636 | int wy = FRAME_TO_WINDOW_PIXEL_Y (w, XINT (event->y)); | |
4637 | ||
4638 | /* Set event coordinates to window-relative coordinates | |
4639 | for constructing the Lisp event below. */ | |
4640 | XSETINT (event->x, wx); | |
4641 | XSETINT (event->y, wy); | |
a24dc617 RS |
4642 | |
4643 | if (part == 1) | |
4644 | posn = Qmode_line; | |
4645 | else if (part == 2) | |
4646 | posn = Qvertical_line; | |
7ee32cda | 4647 | else if (part == 3) |
045dee35 | 4648 | posn = Qheader_line; |
a24dc617 | 4649 | else |
7ee32cda | 4650 | XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy)); |
a24dc617 RS |
4651 | } |
4652 | ||
4653 | { | |
4654 | Lisp_Object head, position; | |
4655 | ||
4656 | position | |
4657 | = Fcons (window, | |
4658 | Fcons (posn, | |
4659 | Fcons (Fcons (event->x, event->y), | |
4660 | Fcons (make_number (event->timestamp), | |
4661 | Qnil)))); | |
4662 | ||
4663 | head = modify_event_symbol (0, event->modifiers, | |
4664 | Qdrag_n_drop, Qnil, | |
4665 | lispy_drag_n_drop_names, | |
4666 | &drag_n_drop_syms, 1); | |
4667 | return Fcons (head, | |
4668 | Fcons (position, | |
4669 | Fcons (files, | |
4670 | Qnil))); | |
4671 | } | |
4672 | } | |
514354e9 | 4673 | #endif /* HAVE_MOUSE */ |
284f4730 | 4674 | |
e98a93eb | 4675 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
2470a66f KH |
4676 | case menu_bar_event: |
4677 | /* The event value is in the cdr of the frame_or_window slot. */ | |
4678 | if (!CONSP (event->frame_or_window)) | |
4679 | abort (); | |
4680 | return XCONS (event->frame_or_window)->cdr; | |
4681 | #endif | |
4682 | ||
9ea173e8 | 4683 | case TOOL_BAR_EVENT: |
7ee32cda GM |
4684 | { |
4685 | Lisp_Object key; | |
4686 | if (!CONSP (event->frame_or_window)) | |
4687 | abort (); | |
4688 | key = XCDR (event->frame_or_window); | |
4689 | if (SYMBOLP (key)) | |
4690 | key = apply_modifiers (event->modifiers, key); | |
4691 | return key; | |
4692 | } | |
4693 | ||
5bf68f6e AS |
4694 | case user_signal: |
4695 | /* A user signal. */ | |
4696 | return *lispy_user_signals[event->code]; | |
4697 | ||
284f4730 JB |
4698 | /* The 'kind' field of the event is something we don't recognize. */ |
4699 | default: | |
48e416d4 | 4700 | abort (); |
284f4730 JB |
4701 | } |
4702 | } | |
4703 | ||
514354e9 | 4704 | #ifdef HAVE_MOUSE |
6cbff1cb | 4705 | |
284f4730 | 4706 | static Lisp_Object |
7b4aedb9 | 4707 | make_lispy_movement (frame, bar_window, part, x, y, time) |
ff11dfa1 | 4708 | FRAME_PTR frame; |
7b4aedb9 | 4709 | Lisp_Object bar_window; |
3c370943 | 4710 | enum scroll_bar_part part; |
284f4730 | 4711 | Lisp_Object x, y; |
e5d77022 | 4712 | unsigned long time; |
284f4730 | 4713 | { |
3c370943 | 4714 | /* Is it a scroll bar movement? */ |
7b4aedb9 | 4715 | if (frame && ! NILP (bar_window)) |
4bb994d1 | 4716 | { |
9b8eb840 | 4717 | Lisp_Object part_sym; |
4bb994d1 | 4718 | |
9b8eb840 | 4719 | part_sym = *scroll_bar_parts[(int) part]; |
3c370943 | 4720 | return Fcons (Qscroll_bar_movement, |
7b4aedb9 | 4721 | (Fcons (Fcons (bar_window, |
3c370943 | 4722 | Fcons (Qvertical_scroll_bar, |
4bb994d1 JB |
4723 | Fcons (Fcons (x, y), |
4724 | Fcons (make_number (time), | |
cb5df6ae | 4725 | Fcons (part_sym, |
4bb994d1 JB |
4726 | Qnil))))), |
4727 | Qnil))); | |
4728 | } | |
4729 | ||
4730 | /* Or is it an ordinary mouse movement? */ | |
284f4730 JB |
4731 | else |
4732 | { | |
4bb994d1 | 4733 | int area; |
9e20143a | 4734 | Lisp_Object window; |
4bb994d1 | 4735 | Lisp_Object posn; |
9e20143a | 4736 | |
9e20143a | 4737 | if (frame) |
7ee32cda GM |
4738 | /* It's in a frame; which window on that frame? */ |
4739 | window = window_from_coordinates (frame, XINT (x), XINT (y), &area, 0); | |
9e20143a RS |
4740 | else |
4741 | window = Qnil; | |
4bb994d1 | 4742 | |
8c18cbfb | 4743 | if (WINDOWP (window)) |
4bb994d1 | 4744 | { |
7ee32cda GM |
4745 | struct window *w = XWINDOW (window); |
4746 | int hpos, vpos; | |
4747 | int wx, wy; | |
4748 | int pos; | |
4749 | ||
4750 | /* Get window relative coordinates. */ | |
4751 | wx = FRAME_TO_WINDOW_PIXEL_X (w, XINT (x)); | |
4752 | wy = FRAME_TO_WINDOW_PIXEL_Y (w, XINT (y)); | |
4753 | XSETINT (x, wx); | |
4754 | XSETINT (y, wy); | |
4755 | ||
4bb994d1 JB |
4756 | if (area == 1) |
4757 | posn = Qmode_line; | |
4758 | else if (area == 2) | |
4759 | posn = Qvertical_line; | |
7ee32cda | 4760 | else if (area == 3) |
045dee35 | 4761 | posn = Qheader_line; |
4bb994d1 | 4762 | else |
7ee32cda | 4763 | XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy)); |
4bb994d1 | 4764 | } |
e9bf89a0 RS |
4765 | else if (frame != 0) |
4766 | { | |
18cd2eeb | 4767 | XSETFRAME (window, frame); |
e9bf89a0 RS |
4768 | posn = Qnil; |
4769 | } | |
284f4730 | 4770 | else |
4bb994d1 JB |
4771 | { |
4772 | window = Qnil; | |
4773 | posn = Qnil; | |
bb9e9bed KH |
4774 | XSETFASTINT (x, 0); |
4775 | XSETFASTINT (y, 0); | |
4bb994d1 | 4776 | } |
284f4730 | 4777 | |
4bb994d1 JB |
4778 | return Fcons (Qmouse_movement, |
4779 | Fcons (Fcons (window, | |
4780 | Fcons (posn, | |
4781 | Fcons (Fcons (x, y), | |
4782 | Fcons (make_number (time), | |
4783 | Qnil)))), | |
4784 | Qnil)); | |
4785 | } | |
284f4730 JB |
4786 | } |
4787 | ||
514354e9 | 4788 | #endif /* HAVE_MOUSE */ |
6cbff1cb | 4789 | |
cd21b839 JB |
4790 | /* Construct a switch frame event. */ |
4791 | static Lisp_Object | |
4792 | make_lispy_switch_frame (frame) | |
4793 | Lisp_Object frame; | |
4794 | { | |
4795 | return Fcons (Qswitch_frame, Fcons (frame, Qnil)); | |
4796 | } | |
0a7f1fc0 JB |
4797 | \f |
4798 | /* Manipulating modifiers. */ | |
284f4730 | 4799 | |
0a7f1fc0 | 4800 | /* Parse the name of SYMBOL, and return the set of modifiers it contains. |
284f4730 | 4801 | |
0a7f1fc0 JB |
4802 | If MODIFIER_END is non-zero, set *MODIFIER_END to the position in |
4803 | SYMBOL's name of the end of the modifiers; the string from this | |
4804 | position is the unmodified symbol name. | |
284f4730 | 4805 | |
0a7f1fc0 | 4806 | This doesn't use any caches. */ |
6da3dd3a | 4807 | |
0a7f1fc0 JB |
4808 | static int |
4809 | parse_modifiers_uncached (symbol, modifier_end) | |
284f4730 | 4810 | Lisp_Object symbol; |
0a7f1fc0 | 4811 | int *modifier_end; |
284f4730 JB |
4812 | { |
4813 | struct Lisp_String *name; | |
4814 | int i; | |
4815 | int modifiers; | |
284f4730 JB |
4816 | |
4817 | CHECK_SYMBOL (symbol, 1); | |
df0f2ba1 | 4818 | |
284f4730 JB |
4819 | modifiers = 0; |
4820 | name = XSYMBOL (symbol)->name; | |
4821 | ||
fc932ac6 | 4822 | for (i = 0; i+2 <= STRING_BYTES (name); ) |
6da3dd3a RS |
4823 | { |
4824 | int this_mod_end = 0; | |
4825 | int this_mod = 0; | |
284f4730 | 4826 | |
6da3dd3a RS |
4827 | /* See if the name continues with a modifier word. |
4828 | Check that the word appears, but don't check what follows it. | |
4829 | Set this_mod and this_mod_end to record what we find. */ | |
fce33686 | 4830 | |
6da3dd3a RS |
4831 | switch (name->data[i]) |
4832 | { | |
4833 | #define SINGLE_LETTER_MOD(BIT) \ | |
4834 | (this_mod_end = i + 1, this_mod = BIT) | |
4835 | ||
6da3dd3a RS |
4836 | case 'A': |
4837 | SINGLE_LETTER_MOD (alt_modifier); | |
4838 | break; | |
284f4730 | 4839 | |
6da3dd3a RS |
4840 | case 'C': |
4841 | SINGLE_LETTER_MOD (ctrl_modifier); | |
4842 | break; | |
284f4730 | 4843 | |
6da3dd3a RS |
4844 | case 'H': |
4845 | SINGLE_LETTER_MOD (hyper_modifier); | |
4846 | break; | |
4847 | ||
6da3dd3a RS |
4848 | case 'M': |
4849 | SINGLE_LETTER_MOD (meta_modifier); | |
4850 | break; | |
4851 | ||
6da3dd3a RS |
4852 | case 'S': |
4853 | SINGLE_LETTER_MOD (shift_modifier); | |
4854 | break; | |
4855 | ||
4856 | case 's': | |
6da3dd3a RS |
4857 | SINGLE_LETTER_MOD (super_modifier); |
4858 | break; | |
4859 | ||
0a7f1fc0 | 4860 | #undef SINGLE_LETTER_MOD |
6da3dd3a RS |
4861 | } |
4862 | ||
4863 | /* If we found no modifier, stop looking for them. */ | |
4864 | if (this_mod_end == 0) | |
4865 | break; | |
4866 | ||
4867 | /* Check there is a dash after the modifier, so that it | |
4868 | really is a modifier. */ | |
fc932ac6 RS |
4869 | if (this_mod_end >= STRING_BYTES (name) |
4870 | || name->data[this_mod_end] != '-') | |
6da3dd3a RS |
4871 | break; |
4872 | ||
4873 | /* This modifier is real; look for another. */ | |
4874 | modifiers |= this_mod; | |
4875 | i = this_mod_end + 1; | |
4876 | } | |
284f4730 | 4877 | |
0a7f1fc0 | 4878 | /* Should we include the `click' modifier? */ |
fbcd35bd JB |
4879 | if (! (modifiers & (down_modifier | drag_modifier |
4880 | | double_modifier | triple_modifier)) | |
fc932ac6 | 4881 | && i + 7 == STRING_BYTES (name) |
4bb994d1 | 4882 | && strncmp (name->data + i, "mouse-", 6) == 0 |
6569cc8d | 4883 | && ('0' <= name->data[i + 6] && name->data[i + 6] <= '9')) |
0a7f1fc0 JB |
4884 | modifiers |= click_modifier; |
4885 | ||
4886 | if (modifier_end) | |
4887 | *modifier_end = i; | |
4888 | ||
4889 | return modifiers; | |
4890 | } | |
4891 | ||
0a7f1fc0 JB |
4892 | /* Return a symbol whose name is the modifier prefixes for MODIFIERS |
4893 | prepended to the string BASE[0..BASE_LEN-1]. | |
4894 | This doesn't use any caches. */ | |
4895 | static Lisp_Object | |
301738ed | 4896 | apply_modifiers_uncached (modifiers, base, base_len, base_len_byte) |
0a7f1fc0 JB |
4897 | int modifiers; |
4898 | char *base; | |
301738ed | 4899 | int base_len, base_len_byte; |
0a7f1fc0 JB |
4900 | { |
4901 | /* Since BASE could contain nulls, we can't use intern here; we have | |
4902 | to use Fintern, which expects a genuine Lisp_String, and keeps a | |
4903 | reference to it. */ | |
301738ed RS |
4904 | char *new_mods |
4905 | = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-")); | |
0a7f1fc0 | 4906 | int mod_len; |
284f4730 | 4907 | |
284f4730 | 4908 | { |
0a7f1fc0 JB |
4909 | char *p = new_mods; |
4910 | ||
4911 | /* Only the event queue may use the `up' modifier; it should always | |
4912 | be turned into a click or drag event before presented to lisp code. */ | |
4913 | if (modifiers & up_modifier) | |
4914 | abort (); | |
4915 | ||
4916 | if (modifiers & alt_modifier) { *p++ = 'A'; *p++ = '-'; } | |
4917 | if (modifiers & ctrl_modifier) { *p++ = 'C'; *p++ = '-'; } | |
4918 | if (modifiers & hyper_modifier) { *p++ = 'H'; *p++ = '-'; } | |
4919 | if (modifiers & meta_modifier) { *p++ = 'M'; *p++ = '-'; } | |
4920 | if (modifiers & shift_modifier) { *p++ = 'S'; *p++ = '-'; } | |
86e5706b | 4921 | if (modifiers & super_modifier) { *p++ = 's'; *p++ = '-'; } |
fbcd35bd JB |
4922 | if (modifiers & double_modifier) { strcpy (p, "double-"); p += 7; } |
4923 | if (modifiers & triple_modifier) { strcpy (p, "triple-"); p += 7; } | |
559f9d04 RS |
4924 | if (modifiers & down_modifier) { strcpy (p, "down-"); p += 5; } |
4925 | if (modifiers & drag_modifier) { strcpy (p, "drag-"); p += 5; } | |
0a7f1fc0 JB |
4926 | /* The click modifier is denoted by the absence of other modifiers. */ |
4927 | ||
4928 | *p = '\0'; | |
4929 | ||
4930 | mod_len = p - new_mods; | |
4931 | } | |
284f4730 | 4932 | |
0a7f1fc0 | 4933 | { |
9b8eb840 | 4934 | Lisp_Object new_name; |
df0f2ba1 | 4935 | |
301738ed RS |
4936 | new_name = make_uninit_multibyte_string (mod_len + base_len, |
4937 | mod_len + base_len_byte); | |
0a7f1fc0 | 4938 | bcopy (new_mods, XSTRING (new_name)->data, mod_len); |
301738ed | 4939 | bcopy (base, XSTRING (new_name)->data + mod_len, base_len_byte); |
284f4730 JB |
4940 | |
4941 | return Fintern (new_name, Qnil); | |
4942 | } | |
4943 | } | |
4944 | ||
4945 | ||
0a7f1fc0 JB |
4946 | static char *modifier_names[] = |
4947 | { | |
fbcd35bd | 4948 | "up", "down", "drag", "click", "double", "triple", 0, 0, |
f335fabe | 4949 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
86e5706b | 4950 | 0, 0, "alt", "super", "hyper", "shift", "control", "meta" |
0a7f1fc0 | 4951 | }; |
80645119 | 4952 | #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0])) |
0a7f1fc0 JB |
4953 | |
4954 | static Lisp_Object modifier_symbols; | |
4955 | ||
4956 | /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */ | |
4957 | static Lisp_Object | |
4958 | lispy_modifier_list (modifiers) | |
4959 | int modifiers; | |
4960 | { | |
4961 | Lisp_Object modifier_list; | |
4962 | int i; | |
4963 | ||
4964 | modifier_list = Qnil; | |
80645119 | 4965 | for (i = 0; (1<<i) <= modifiers && i < NUM_MOD_NAMES; i++) |
0a7f1fc0 | 4966 | if (modifiers & (1<<i)) |
80645119 JB |
4967 | modifier_list = Fcons (XVECTOR (modifier_symbols)->contents[i], |
4968 | modifier_list); | |
0a7f1fc0 JB |
4969 | |
4970 | return modifier_list; | |
4971 | } | |
4972 | ||
4973 | ||
4974 | /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK), | |
4975 | where UNMODIFIED is the unmodified form of SYMBOL, | |
4976 | MASK is the set of modifiers present in SYMBOL's name. | |
4977 | This is similar to parse_modifiers_uncached, but uses the cache in | |
4978 | SYMBOL's Qevent_symbol_element_mask property, and maintains the | |
4979 | Qevent_symbol_elements property. */ | |
3d31316f | 4980 | |
1161d367 | 4981 | Lisp_Object |
0a7f1fc0 JB |
4982 | parse_modifiers (symbol) |
4983 | Lisp_Object symbol; | |
4984 | { | |
9b8eb840 | 4985 | Lisp_Object elements; |
0a7f1fc0 | 4986 | |
9b8eb840 | 4987 | elements = Fget (symbol, Qevent_symbol_element_mask); |
0a7f1fc0 JB |
4988 | if (CONSP (elements)) |
4989 | return elements; | |
4990 | else | |
4991 | { | |
4992 | int end; | |
ec0faad2 | 4993 | int modifiers = parse_modifiers_uncached (symbol, &end); |
9b8eb840 | 4994 | Lisp_Object unmodified; |
0a7f1fc0 JB |
4995 | Lisp_Object mask; |
4996 | ||
9b8eb840 | 4997 | unmodified = Fintern (make_string (XSYMBOL (symbol)->name->data + end, |
fc932ac6 | 4998 | STRING_BYTES (XSYMBOL (symbol)->name) - end), |
9b8eb840 KH |
4999 | Qnil); |
5000 | ||
ec0faad2 | 5001 | if (modifiers & ~(((EMACS_INT)1 << VALBITS) - 1)) |
734fef94 | 5002 | abort (); |
bb9e9bed | 5003 | XSETFASTINT (mask, modifiers); |
0a7f1fc0 JB |
5004 | elements = Fcons (unmodified, Fcons (mask, Qnil)); |
5005 | ||
5006 | /* Cache the parsing results on SYMBOL. */ | |
5007 | Fput (symbol, Qevent_symbol_element_mask, | |
5008 | elements); | |
5009 | Fput (symbol, Qevent_symbol_elements, | |
5010 | Fcons (unmodified, lispy_modifier_list (modifiers))); | |
5011 | ||
5012 | /* Since we know that SYMBOL is modifiers applied to unmodified, | |
5013 | it would be nice to put that in unmodified's cache. | |
5014 | But we can't, since we're not sure that parse_modifiers is | |
5015 | canonical. */ | |
5016 | ||
5017 | return elements; | |
5018 | } | |
5019 | } | |
5020 | ||
5021 | /* Apply the modifiers MODIFIERS to the symbol BASE. | |
5022 | BASE must be unmodified. | |
5023 | ||
5024 | This is like apply_modifiers_uncached, but uses BASE's | |
5025 | Qmodifier_cache property, if present. It also builds | |
cd21b839 JB |
5026 | Qevent_symbol_elements properties, since it has that info anyway. |
5027 | ||
5028 | apply_modifiers copies the value of BASE's Qevent_kind property to | |
5029 | the modified symbol. */ | |
0a7f1fc0 JB |
5030 | static Lisp_Object |
5031 | apply_modifiers (modifiers, base) | |
5032 | int modifiers; | |
5033 | Lisp_Object base; | |
5034 | { | |
7b4aedb9 | 5035 | Lisp_Object cache, index, entry, new_symbol; |
0a7f1fc0 | 5036 | |
80645119 | 5037 | /* Mask out upper bits. We don't know where this value's been. */ |
ec0faad2 | 5038 | modifiers &= ((EMACS_INT)1 << VALBITS) - 1; |
80645119 | 5039 | |
0a7f1fc0 | 5040 | /* The click modifier never figures into cache indices. */ |
0a7f1fc0 | 5041 | cache = Fget (base, Qmodifier_cache); |
bb9e9bed | 5042 | XSETFASTINT (index, (modifiers & ~click_modifier)); |
697e4895 | 5043 | entry = assq_no_quit (index, cache); |
0a7f1fc0 JB |
5044 | |
5045 | if (CONSP (entry)) | |
7b4aedb9 JB |
5046 | new_symbol = XCONS (entry)->cdr; |
5047 | else | |
5048 | { | |
df0f2ba1 | 5049 | /* We have to create the symbol ourselves. */ |
7b4aedb9 JB |
5050 | new_symbol = apply_modifiers_uncached (modifiers, |
5051 | XSYMBOL (base)->name->data, | |
301738ed | 5052 | XSYMBOL (base)->name->size, |
fc932ac6 | 5053 | STRING_BYTES (XSYMBOL (base)->name)); |
7b4aedb9 JB |
5054 | |
5055 | /* Add the new symbol to the base's cache. */ | |
5056 | entry = Fcons (index, new_symbol); | |
5057 | Fput (base, Qmodifier_cache, Fcons (entry, cache)); | |
5058 | ||
5059 | /* We have the parsing info now for free, so add it to the caches. */ | |
bb9e9bed | 5060 | XSETFASTINT (index, modifiers); |
7b4aedb9 JB |
5061 | Fput (new_symbol, Qevent_symbol_element_mask, |
5062 | Fcons (base, Fcons (index, Qnil))); | |
5063 | Fput (new_symbol, Qevent_symbol_elements, | |
5064 | Fcons (base, lispy_modifier_list (modifiers))); | |
5065 | } | |
0a7f1fc0 | 5066 | |
df0f2ba1 | 5067 | /* Make sure this symbol is of the same kind as BASE. |
7b4aedb9 JB |
5068 | |
5069 | You'd think we could just set this once and for all when we | |
5070 | intern the symbol above, but reorder_modifiers may call us when | |
5071 | BASE's property isn't set right; we can't assume that just | |
80645119 JB |
5072 | because it has a Qmodifier_cache property it must have its |
5073 | Qevent_kind set right as well. */ | |
7b4aedb9 JB |
5074 | if (NILP (Fget (new_symbol, Qevent_kind))) |
5075 | { | |
9b8eb840 | 5076 | Lisp_Object kind; |
7b4aedb9 | 5077 | |
9b8eb840 | 5078 | kind = Fget (base, Qevent_kind); |
7b4aedb9 JB |
5079 | if (! NILP (kind)) |
5080 | Fput (new_symbol, Qevent_kind, kind); | |
5081 | } | |
5082 | ||
5083 | return new_symbol; | |
0a7f1fc0 JB |
5084 | } |
5085 | ||
5086 | ||
5087 | /* Given a symbol whose name begins with modifiers ("C-", "M-", etc), | |
5088 | return a symbol with the modifiers placed in the canonical order. | |
5089 | Canonical order is alphabetical, except for down and drag, which | |
5090 | always come last. The 'click' modifier is never written out. | |
5091 | ||
5092 | Fdefine_key calls this to make sure that (for example) C-M-foo | |
5093 | and M-C-foo end up being equivalent in the keymap. */ | |
5094 | ||
5095 | Lisp_Object | |
5096 | reorder_modifiers (symbol) | |
5097 | Lisp_Object symbol; | |
5098 | { | |
5099 | /* It's hopefully okay to write the code this way, since everything | |
5100 | will soon be in caches, and no consing will be done at all. */ | |
9b8eb840 | 5101 | Lisp_Object parsed; |
0a7f1fc0 | 5102 | |
9b8eb840 | 5103 | parsed = parse_modifiers (symbol); |
54593ed9 | 5104 | return apply_modifiers ((int) XINT (XCONS (XCONS (parsed)->cdr)->car), |
0a7f1fc0 JB |
5105 | XCONS (parsed)->car); |
5106 | } | |
5107 | ||
5108 | ||
284f4730 JB |
5109 | /* For handling events, we often want to produce a symbol whose name |
5110 | is a series of modifier key prefixes ("M-", "C-", etcetera) attached | |
5111 | to some base, like the name of a function key or mouse button. | |
5112 | modify_event_symbol produces symbols of this sort. | |
5113 | ||
5114 | NAME_TABLE should point to an array of strings, such that NAME_TABLE[i] | |
5115 | is the name of the i'th symbol. TABLE_SIZE is the number of elements | |
5116 | in the table. | |
5117 | ||
80e4aa30 RS |
5118 | Alternatively, NAME_ALIST is an alist mapping codes into symbol names. |
5119 | NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used. | |
5120 | ||
284f4730 JB |
5121 | SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will |
5122 | persist between calls to modify_event_symbol that it can use to | |
5123 | store a cache of the symbols it's generated for this NAME_TABLE | |
80e4aa30 | 5124 | before. The object stored there may be a vector or an alist. |
284f4730 JB |
5125 | |
5126 | SYMBOL_NUM is the number of the base name we want from NAME_TABLE. | |
df0f2ba1 | 5127 | |
284f4730 JB |
5128 | MODIFIERS is a set of modifier bits (as given in struct input_events) |
5129 | whose prefixes should be applied to the symbol name. | |
5130 | ||
5131 | SYMBOL_KIND is the value to be placed in the event_kind property of | |
df0f2ba1 | 5132 | the returned symbol. |
88cb0656 JB |
5133 | |
5134 | The symbols we create are supposed to have an | |
eb8c3be9 | 5135 | `event-symbol-elements' property, which lists the modifiers present |
88cb0656 JB |
5136 | in the symbol's name. */ |
5137 | ||
284f4730 | 5138 | static Lisp_Object |
80e4aa30 RS |
5139 | modify_event_symbol (symbol_num, modifiers, symbol_kind, name_alist, |
5140 | name_table, symbol_table, table_size) | |
284f4730 JB |
5141 | int symbol_num; |
5142 | unsigned modifiers; | |
5143 | Lisp_Object symbol_kind; | |
80e4aa30 | 5144 | Lisp_Object name_alist; |
284f4730 JB |
5145 | char **name_table; |
5146 | Lisp_Object *symbol_table; | |
2c834fb3 | 5147 | unsigned int table_size; |
284f4730 | 5148 | { |
80e4aa30 RS |
5149 | Lisp_Object value; |
5150 | Lisp_Object symbol_int; | |
5151 | ||
2c834fb3 KH |
5152 | /* Get rid of the "vendor-specific" bit here. */ |
5153 | XSETINT (symbol_int, symbol_num & 0xffffff); | |
284f4730 JB |
5154 | |
5155 | /* Is this a request for a valid symbol? */ | |
88cb0656 | 5156 | if (symbol_num < 0 || symbol_num >= table_size) |
0c2611c5 | 5157 | return Qnil; |
284f4730 | 5158 | |
80e4aa30 RS |
5159 | if (CONSP (*symbol_table)) |
5160 | value = Fcdr (assq_no_quit (symbol_int, *symbol_table)); | |
5161 | ||
0a7f1fc0 | 5162 | /* If *symbol_table doesn't seem to be initialized properly, fix that. |
88cb0656 | 5163 | *symbol_table should be a lisp vector TABLE_SIZE elements long, |
4bb994d1 JB |
5164 | where the Nth element is the symbol for NAME_TABLE[N], or nil if |
5165 | we've never used that symbol before. */ | |
80e4aa30 | 5166 | else |
88cb0656 | 5167 | { |
80e4aa30 RS |
5168 | if (! VECTORP (*symbol_table) |
5169 | || XVECTOR (*symbol_table)->size != table_size) | |
5170 | { | |
5171 | Lisp_Object size; | |
0a7f1fc0 | 5172 | |
bb9e9bed | 5173 | XSETFASTINT (size, table_size); |
80e4aa30 RS |
5174 | *symbol_table = Fmake_vector (size, Qnil); |
5175 | } | |
284f4730 | 5176 | |
80e4aa30 RS |
5177 | value = XVECTOR (*symbol_table)->contents[symbol_num]; |
5178 | } | |
284f4730 | 5179 | |
0a7f1fc0 | 5180 | /* Have we already used this symbol before? */ |
80e4aa30 | 5181 | if (NILP (value)) |
284f4730 | 5182 | { |
0a7f1fc0 | 5183 | /* No; let's create it. */ |
80e4aa30 | 5184 | if (!NILP (name_alist)) |
b64b4075 | 5185 | value = Fcdr_safe (Fassq (symbol_int, name_alist)); |
2ff6714d | 5186 | else if (name_table != 0 && name_table[symbol_num]) |
80e4aa30 | 5187 | value = intern (name_table[symbol_num]); |
b64b4075 | 5188 | |
e98a93eb | 5189 | #ifdef HAVE_WINDOW_SYSTEM |
2c834fb3 KH |
5190 | if (NILP (value)) |
5191 | { | |
5192 | char *name = x_get_keysym_name (symbol_num); | |
5193 | if (name) | |
5194 | value = intern (name); | |
5195 | } | |
5196 | #endif | |
5197 | ||
b64b4075 | 5198 | if (NILP (value)) |
d1f50460 RS |
5199 | { |
5200 | char buf[20]; | |
5201 | sprintf (buf, "key-%d", symbol_num); | |
80e4aa30 | 5202 | value = intern (buf); |
d1f50460 | 5203 | } |
0a7f1fc0 | 5204 | |
80e4aa30 | 5205 | if (CONSP (*symbol_table)) |
4205cb08 | 5206 | *symbol_table = Fcons (Fcons (symbol_int, value), *symbol_table); |
80e4aa30 RS |
5207 | else |
5208 | XVECTOR (*symbol_table)->contents[symbol_num] = value; | |
5209 | ||
df0f2ba1 | 5210 | /* Fill in the cache entries for this symbol; this also |
0a7f1fc0 JB |
5211 | builds the Qevent_symbol_elements property, which the user |
5212 | cares about. */ | |
80e4aa30 RS |
5213 | apply_modifiers (modifiers & click_modifier, value); |
5214 | Fput (value, Qevent_kind, symbol_kind); | |
284f4730 | 5215 | } |
88cb0656 | 5216 | |
0a7f1fc0 | 5217 | /* Apply modifiers to that symbol. */ |
80e4aa30 | 5218 | return apply_modifiers (modifiers, value); |
284f4730 | 5219 | } |
6da3dd3a RS |
5220 | \f |
5221 | /* Convert a list that represents an event type, | |
5222 | such as (ctrl meta backspace), into the usual representation of that | |
5223 | event type as a number or a symbol. */ | |
5224 | ||
a1706c30 | 5225 | DEFUN ("event-convert-list", Fevent_convert_list, Sevent_convert_list, 1, 1, 0, |
e57d8fd8 EN |
5226 | "Convert the event description list EVENT-DESC to an event type.\n\ |
5227 | EVENT-DESC should contain one base event type (a character or symbol)\n\ | |
a1706c30 | 5228 | and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\ |
377f24f5 | 5229 | drag, down, double or triple). The base must be last.\n\ |
a1706c30 KH |
5230 | The return value is an event type (a character or symbol) which\n\ |
5231 | has the same base event type and all the specified modifiers.") | |
e57d8fd8 EN |
5232 | (event_desc) |
5233 | Lisp_Object event_desc; | |
6da3dd3a RS |
5234 | { |
5235 | Lisp_Object base; | |
5236 | int modifiers = 0; | |
5237 | Lisp_Object rest; | |
5238 | ||
5239 | base = Qnil; | |
e57d8fd8 | 5240 | rest = event_desc; |
6da3dd3a RS |
5241 | while (CONSP (rest)) |
5242 | { | |
5243 | Lisp_Object elt; | |
5244 | int this = 0; | |
5245 | ||
5246 | elt = XCONS (rest)->car; | |
377f24f5 | 5247 | rest = XCONS (rest)->cdr; |
6da3dd3a | 5248 | |
3d31316f | 5249 | /* Given a symbol, see if it is a modifier name. */ |
377f24f5 | 5250 | if (SYMBOLP (elt) && CONSP (rest)) |
3d31316f | 5251 | this = parse_solitary_modifier (elt); |
6da3dd3a RS |
5252 | |
5253 | if (this != 0) | |
5254 | modifiers |= this; | |
5255 | else if (!NILP (base)) | |
5256 | error ("Two bases given in one event"); | |
5257 | else | |
5258 | base = elt; | |
5259 | ||
6da3dd3a RS |
5260 | } |
5261 | ||
3d31316f RS |
5262 | /* Let the symbol A refer to the character A. */ |
5263 | if (SYMBOLP (base) && XSYMBOL (base)->name->size == 1) | |
5264 | XSETINT (base, XSYMBOL (base)->name->data[0]); | |
5265 | ||
6da3dd3a RS |
5266 | if (INTEGERP (base)) |
5267 | { | |
3d31316f RS |
5268 | /* Turn (shift a) into A. */ |
5269 | if ((modifiers & shift_modifier) != 0 | |
5270 | && (XINT (base) >= 'a' && XINT (base) <= 'z')) | |
5271 | { | |
5272 | XSETINT (base, XINT (base) - ('a' - 'A')); | |
5273 | modifiers &= ~shift_modifier; | |
5274 | } | |
5275 | ||
5276 | /* Turn (control a) into C-a. */ | |
6da3dd3a | 5277 | if (modifiers & ctrl_modifier) |
3d31316f | 5278 | return make_number ((modifiers & ~ctrl_modifier) |
6da3dd3a RS |
5279 | | make_ctrl_char (XINT (base))); |
5280 | else | |
5281 | return make_number (modifiers | XINT (base)); | |
5282 | } | |
5283 | else if (SYMBOLP (base)) | |
5284 | return apply_modifiers (modifiers, base); | |
5285 | else | |
5286 | error ("Invalid base event"); | |
5287 | } | |
5288 | ||
3d31316f RS |
5289 | /* Try to recognize SYMBOL as a modifier name. |
5290 | Return the modifier flag bit, or 0 if not recognized. */ | |
5291 | ||
5292 | static int | |
5293 | parse_solitary_modifier (symbol) | |
5294 | Lisp_Object symbol; | |
5295 | { | |
5296 | struct Lisp_String *name = XSYMBOL (symbol)->name; | |
5297 | ||
5298 | switch (name->data[0]) | |
5299 | { | |
5300 | #define SINGLE_LETTER_MOD(BIT) \ | |
fc932ac6 | 5301 | if (STRING_BYTES (name) == 1) \ |
3d31316f RS |
5302 | return BIT; |
5303 | ||
5304 | #define MULTI_LETTER_MOD(BIT, NAME, LEN) \ | |
fc932ac6 | 5305 | if (LEN == STRING_BYTES (name) \ |
3d31316f RS |
5306 | && ! strncmp (name->data, NAME, LEN)) \ |
5307 | return BIT; | |
5308 | ||
5309 | case 'A': | |
5310 | SINGLE_LETTER_MOD (alt_modifier); | |
5311 | break; | |
5312 | ||
5313 | case 'a': | |
5314 | MULTI_LETTER_MOD (alt_modifier, "alt", 3); | |
5315 | break; | |
5316 | ||
5317 | case 'C': | |
5318 | SINGLE_LETTER_MOD (ctrl_modifier); | |
5319 | break; | |
5320 | ||
5321 | case 'c': | |
5322 | MULTI_LETTER_MOD (ctrl_modifier, "ctrl", 4); | |
5323 | MULTI_LETTER_MOD (ctrl_modifier, "control", 7); | |
5324 | break; | |
5325 | ||
5326 | case 'H': | |
5327 | SINGLE_LETTER_MOD (hyper_modifier); | |
5328 | break; | |
5329 | ||
5330 | case 'h': | |
5331 | MULTI_LETTER_MOD (hyper_modifier, "hyper", 5); | |
5332 | break; | |
5333 | ||
5334 | case 'M': | |
5335 | SINGLE_LETTER_MOD (meta_modifier); | |
5336 | break; | |
5337 | ||
5338 | case 'm': | |
5339 | MULTI_LETTER_MOD (meta_modifier, "meta", 4); | |
5340 | break; | |
5341 | ||
5342 | case 'S': | |
5343 | SINGLE_LETTER_MOD (shift_modifier); | |
5344 | break; | |
5345 | ||
5346 | case 's': | |
5347 | MULTI_LETTER_MOD (shift_modifier, "shift", 5); | |
5348 | MULTI_LETTER_MOD (super_modifier, "super", 5); | |
5349 | SINGLE_LETTER_MOD (super_modifier); | |
5350 | break; | |
5351 | ||
5352 | case 'd': | |
5353 | MULTI_LETTER_MOD (drag_modifier, "drag", 4); | |
5354 | MULTI_LETTER_MOD (down_modifier, "down", 4); | |
5355 | MULTI_LETTER_MOD (double_modifier, "double", 6); | |
5356 | break; | |
5357 | ||
5358 | case 't': | |
5359 | MULTI_LETTER_MOD (triple_modifier, "triple", 6); | |
5360 | break; | |
5361 | ||
5362 | #undef SINGLE_LETTER_MOD | |
5363 | #undef MULTI_LETTER_MOD | |
5364 | } | |
5365 | ||
5366 | return 0; | |
5367 | } | |
5368 | ||
6da3dd3a RS |
5369 | /* Return 1 if EVENT is a list whose elements are all integers or symbols. |
5370 | Such a list is not valid as an event, | |
5371 | but it can be a Lucid-style event type list. */ | |
5372 | ||
5373 | int | |
5374 | lucid_event_type_list_p (object) | |
5375 | Lisp_Object object; | |
5376 | { | |
5377 | Lisp_Object tail; | |
5378 | ||
5379 | if (! CONSP (object)) | |
5380 | return 0; | |
5381 | ||
5382 | for (tail = object; CONSP (tail); tail = XCONS (tail)->cdr) | |
5383 | { | |
5384 | Lisp_Object elt; | |
5385 | elt = XCONS (tail)->car; | |
5386 | if (! (INTEGERP (elt) || SYMBOLP (elt))) | |
5387 | return 0; | |
5388 | } | |
5389 | ||
5390 | return NILP (tail); | |
5391 | } | |
284f4730 | 5392 | \f |
284f4730 JB |
5393 | /* Store into *addr a value nonzero if terminal input chars are available. |
5394 | Serves the purpose of ioctl (0, FIONREAD, addr) | |
5395 | but works even if FIONREAD does not exist. | |
d9d4c147 KH |
5396 | (In fact, this may actually read some input.) |
5397 | ||
5398 | If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */ | |
284f4730 JB |
5399 | |
5400 | static void | |
d9d4c147 | 5401 | get_input_pending (addr, do_timers_now) |
284f4730 | 5402 | int *addr; |
d9d4c147 | 5403 | int do_timers_now; |
284f4730 JB |
5404 | { |
5405 | /* First of all, have we already counted some input? */ | |
d9d4c147 | 5406 | *addr = !NILP (Vquit_flag) || readable_events (do_timers_now); |
284f4730 JB |
5407 | |
5408 | /* If input is being read as it arrives, and we have none, there is none. */ | |
5409 | if (*addr > 0 || (interrupt_input && ! interrupts_deferred)) | |
5410 | return; | |
5411 | ||
5412 | /* Try to read some input and see how much we get. */ | |
5413 | gobble_input (0); | |
d9d4c147 | 5414 | *addr = !NILP (Vquit_flag) || readable_events (do_timers_now); |
284f4730 JB |
5415 | } |
5416 | ||
81931ba1 | 5417 | /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */ |
284f4730 | 5418 | |
07a59269 | 5419 | void |
284f4730 JB |
5420 | gobble_input (expected) |
5421 | int expected; | |
5422 | { | |
5423 | #ifndef VMS | |
5424 | #ifdef SIGIO | |
5425 | if (interrupt_input) | |
5426 | { | |
32676c08 | 5427 | SIGMASKTYPE mask; |
4f8aaa74 | 5428 | mask = sigblock (sigmask (SIGIO)); |
284f4730 | 5429 | read_avail_input (expected); |
e065a56e | 5430 | sigsetmask (mask); |
284f4730 JB |
5431 | } |
5432 | else | |
81931ba1 RS |
5433 | #ifdef POLL_FOR_INPUT |
5434 | if (read_socket_hook && !interrupt_input && poll_suppress_count == 0) | |
5435 | { | |
5436 | SIGMASKTYPE mask; | |
4f8aaa74 | 5437 | mask = sigblock (sigmask (SIGALRM)); |
81931ba1 RS |
5438 | read_avail_input (expected); |
5439 | sigsetmask (mask); | |
5440 | } | |
5441 | else | |
87485d6f | 5442 | #endif |
284f4730 JB |
5443 | #endif |
5444 | read_avail_input (expected); | |
5445 | #endif | |
5446 | } | |
a8015ab5 | 5447 | |
241ceaf7 RS |
5448 | /* Put a buffer_switch_event in the buffer |
5449 | so that read_key_sequence will notice the new current buffer. */ | |
5450 | ||
07a59269 | 5451 | void |
a8015ab5 KH |
5452 | record_asynch_buffer_change () |
5453 | { | |
5454 | struct input_event event; | |
a30f0615 RS |
5455 | Lisp_Object tem; |
5456 | ||
a8015ab5 KH |
5457 | event.kind = buffer_switch_event; |
5458 | event.frame_or_window = Qnil; | |
241ceaf7 | 5459 | |
f65e6f7d | 5460 | #ifdef subprocesses |
a30f0615 RS |
5461 | /* We don't need a buffer-switch event unless Emacs is waiting for input. |
5462 | The purpose of the event is to make read_key_sequence look up the | |
5463 | keymaps again. If we aren't in read_key_sequence, we don't need one, | |
5464 | and the event could cause trouble by messing up (input-pending-p). */ | |
5465 | tem = Fwaiting_for_user_input_p (); | |
5466 | if (NILP (tem)) | |
5467 | return; | |
f65e6f7d RS |
5468 | #else |
5469 | /* We never need these events if we have no asynchronous subprocesses. */ | |
5470 | return; | |
5471 | #endif | |
a30f0615 | 5472 | |
241ceaf7 RS |
5473 | /* Make sure no interrupt happens while storing the event. */ |
5474 | #ifdef SIGIO | |
5475 | if (interrupt_input) | |
5476 | { | |
5477 | SIGMASKTYPE mask; | |
4f8aaa74 | 5478 | mask = sigblock (sigmask (SIGIO)); |
241ceaf7 RS |
5479 | kbd_buffer_store_event (&event); |
5480 | sigsetmask (mask); | |
5481 | } | |
5482 | else | |
5483 | #endif | |
5484 | { | |
5485 | stop_polling (); | |
5486 | kbd_buffer_store_event (&event); | |
5487 | start_polling (); | |
5488 | } | |
a8015ab5 | 5489 | } |
284f4730 JB |
5490 | \f |
5491 | #ifndef VMS | |
5492 | ||
5493 | /* Read any terminal input already buffered up by the system | |
5494 | into the kbd_buffer, but do not wait. | |
5495 | ||
5496 | EXPECTED should be nonzero if the caller knows there is some input. | |
5497 | ||
5498 | Except on VMS, all input is read by this function. | |
5499 | If interrupt_input is nonzero, this function MUST be called | |
5500 | only when SIGIO is blocked. | |
5501 | ||
5502 | Returns the number of keyboard chars read, or -1 meaning | |
5503 | this is a bad time to try to read input. */ | |
5504 | ||
5505 | static int | |
5506 | read_avail_input (expected) | |
5507 | int expected; | |
5508 | { | |
5509 | struct input_event buf[KBD_BUFFER_SIZE]; | |
5510 | register int i; | |
5511 | int nread; | |
5512 | ||
5513 | if (read_socket_hook) | |
5514 | /* No need for FIONREAD or fcntl; just say don't wait. */ | |
33e19c6e | 5515 | nread = (*read_socket_hook) (input_fd, buf, KBD_BUFFER_SIZE, expected); |
284f4730 JB |
5516 | else |
5517 | { | |
17270835 RS |
5518 | /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than |
5519 | the kbd_buffer can really hold. That may prevent loss | |
5520 | of characters on some systems when input is stuffed at us. */ | |
5521 | unsigned char cbuf[KBD_BUFFER_SIZE - 1]; | |
58788063 | 5522 | int n_to_read; |
284f4730 | 5523 | |
58788063 | 5524 | /* Determine how many characters we should *try* to read. */ |
bc536d84 RS |
5525 | #ifdef WINDOWSNT |
5526 | return 0; | |
5527 | #else /* not WINDOWSNT */ | |
80e4aa30 | 5528 | #ifdef MSDOS |
58788063 RS |
5529 | n_to_read = dos_keysns (); |
5530 | if (n_to_read == 0) | |
5531 | return 0; | |
c3a2738c | 5532 | #else /* not MSDOS */ |
284f4730 JB |
5533 | #ifdef FIONREAD |
5534 | /* Find out how much input is available. */ | |
437f6112 | 5535 | if (ioctl (input_fd, FIONREAD, &n_to_read) < 0) |
284f4730 JB |
5536 | /* Formerly simply reported no input, but that sometimes led to |
5537 | a failure of Emacs to terminate. | |
5538 | SIGHUP seems appropriate if we can't reach the terminal. */ | |
e4535288 RS |
5539 | /* ??? Is it really right to send the signal just to this process |
5540 | rather than to the whole process group? | |
5541 | Perhaps on systems with FIONREAD Emacs is alone in its group. */ | |
284f4730 | 5542 | kill (getpid (), SIGHUP); |
58788063 | 5543 | if (n_to_read == 0) |
284f4730 | 5544 | return 0; |
58788063 RS |
5545 | if (n_to_read > sizeof cbuf) |
5546 | n_to_read = sizeof cbuf; | |
284f4730 | 5547 | #else /* no FIONREAD */ |
0c04a67e | 5548 | #if defined (USG) || defined (DGUX) |
284f4730 | 5549 | /* Read some input if available, but don't wait. */ |
58788063 | 5550 | n_to_read = sizeof cbuf; |
437f6112 | 5551 | fcntl (input_fd, F_SETFL, O_NDELAY); |
284f4730 JB |
5552 | #else |
5553 | you lose; | |
5554 | #endif | |
5555 | #endif | |
80e4aa30 | 5556 | #endif /* not MSDOS */ |
bc536d84 | 5557 | #endif /* not WINDOWSNT */ |
284f4730 | 5558 | |
58788063 RS |
5559 | /* Now read; for one reason or another, this will not block. |
5560 | NREAD is set to the number of chars read. */ | |
9134775b | 5561 | do |
284f4730 | 5562 | { |
80e4aa30 | 5563 | #ifdef MSDOS |
0c04a67e | 5564 | cbuf[0] = dos_keyread (); |
80e4aa30 RS |
5565 | nread = 1; |
5566 | #else | |
437f6112 | 5567 | nread = read (input_fd, cbuf, n_to_read); |
80e4aa30 | 5568 | #endif |
49854566 RS |
5569 | /* POSIX infers that processes which are not in the session leader's |
5570 | process group won't get SIGHUP's at logout time. BSDI adheres to | |
e8886a1d | 5571 | this part standard and returns -1 from read (0) with errno==EIO |
49854566 RS |
5572 | when the control tty is taken away. |
5573 | Jeffrey Honig <jch@bsdi.com> says this is generally safe. */ | |
5574 | if (nread == -1 && errno == EIO) | |
5575 | kill (0, SIGHUP); | |
762f2b92 | 5576 | #if defined (AIX) && (! defined (aix386) && defined (_BSD)) |
284f4730 JB |
5577 | /* The kernel sometimes fails to deliver SIGHUP for ptys. |
5578 | This looks incorrect, but it isn't, because _BSD causes | |
5579 | O_NDELAY to be defined in fcntl.h as O_NONBLOCK, | |
5580 | and that causes a value other than 0 when there is no input. */ | |
854f3a54 | 5581 | if (nread == 0) |
80e4aa30 | 5582 | kill (0, SIGHUP); |
284f4730 | 5583 | #endif |
9134775b | 5584 | } |
791587ee KH |
5585 | while ( |
5586 | /* We used to retry the read if it was interrupted. | |
5587 | But this does the wrong thing when O_NDELAY causes | |
5588 | an EAGAIN error. Does anybody know of a situation | |
5589 | where a retry is actually needed? */ | |
5590 | #if 0 | |
5591 | nread < 0 && (errno == EAGAIN | |
6aec06f5 | 5592 | #ifdef EFAULT |
9134775b | 5593 | || errno == EFAULT |
80e4aa30 | 5594 | #endif |
284f4730 | 5595 | #ifdef EBADSLT |
9134775b | 5596 | || errno == EBADSLT |
284f4730 | 5597 | #endif |
791587ee KH |
5598 | ) |
5599 | #else | |
5600 | 0 | |
5601 | #endif | |
5602 | ); | |
284f4730 JB |
5603 | |
5604 | #ifndef FIONREAD | |
02c2c53f | 5605 | #if defined (USG) || defined (DGUX) |
437f6112 | 5606 | fcntl (input_fd, F_SETFL, 0); |
02c2c53f | 5607 | #endif /* USG or DGUX */ |
284f4730 JB |
5608 | #endif /* no FIONREAD */ |
5609 | for (i = 0; i < nread; i++) | |
5610 | { | |
5611 | buf[i].kind = ascii_keystroke; | |
86e5706b | 5612 | buf[i].modifiers = 0; |
b04904fb | 5613 | if (meta_key == 1 && (cbuf[i] & 0x80)) |
86e5706b | 5614 | buf[i].modifiers = meta_modifier; |
b04904fb RS |
5615 | if (meta_key != 2) |
5616 | cbuf[i] &= ~0x80; | |
f3e59d5e KH |
5617 | |
5618 | buf[i].code = cbuf[i]; | |
18cd2eeb | 5619 | XSETFRAME (buf[i].frame_or_window, selected_frame); |
284f4730 JB |
5620 | } |
5621 | } | |
5622 | ||
5623 | /* Scan the chars for C-g and store them in kbd_buffer. */ | |
5624 | for (i = 0; i < nread; i++) | |
5625 | { | |
5626 | kbd_buffer_store_event (&buf[i]); | |
5627 | /* Don't look at input that follows a C-g too closely. | |
5628 | This reduces lossage due to autorepeat on C-g. */ | |
5629 | if (buf[i].kind == ascii_keystroke | |
9343ab07 | 5630 | && buf[i].code == quit_char) |
284f4730 JB |
5631 | break; |
5632 | } | |
5633 | ||
5634 | return nread; | |
5635 | } | |
5636 | #endif /* not VMS */ | |
5637 | \f | |
5638 | #ifdef SIGIO /* for entire page */ | |
5639 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
5640 | ||
2ce30ea2 | 5641 | SIGTYPE |
284f4730 JB |
5642 | input_available_signal (signo) |
5643 | int signo; | |
5644 | { | |
5645 | /* Must preserve main program's value of errno. */ | |
5646 | int old_errno = errno; | |
5647 | #ifdef BSD4_1 | |
5648 | extern int select_alarmed; | |
5649 | #endif | |
5650 | ||
5970a8cb | 5651 | #if defined (USG) && !defined (POSIX_SIGNALS) |
284f4730 JB |
5652 | /* USG systems forget handlers when they are used; |
5653 | must reestablish each time */ | |
5654 | signal (signo, input_available_signal); | |
5655 | #endif /* USG */ | |
5656 | ||
5657 | #ifdef BSD4_1 | |
5658 | sigisheld (SIGIO); | |
5659 | #endif | |
5660 | ||
ffd56f97 JB |
5661 | if (input_available_clear_time) |
5662 | EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); | |
284f4730 JB |
5663 | |
5664 | while (1) | |
5665 | { | |
5666 | int nread; | |
5667 | nread = read_avail_input (1); | |
5668 | /* -1 means it's not ok to read the input now. | |
5669 | UNBLOCK_INPUT will read it later; now, avoid infinite loop. | |
5670 | 0 means there was no keyboard input available. */ | |
5671 | if (nread <= 0) | |
5672 | break; | |
5673 | ||
5674 | #ifdef BSD4_1 | |
5675 | select_alarmed = 1; /* Force the select emulator back to life */ | |
5676 | #endif | |
5677 | } | |
5678 | ||
5679 | #ifdef BSD4_1 | |
5680 | sigfree (); | |
5681 | #endif | |
5682 | errno = old_errno; | |
5683 | } | |
5684 | #endif /* SIGIO */ | |
ad163903 JB |
5685 | |
5686 | /* Send ourselves a SIGIO. | |
5687 | ||
5688 | This function exists so that the UNBLOCK_INPUT macro in | |
5689 | blockinput.h can have some way to take care of input we put off | |
5690 | dealing with, without assuming that every file which uses | |
5691 | UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */ | |
5692 | void | |
5693 | reinvoke_input_signal () | |
5694 | { | |
df0f2ba1 | 5695 | #ifdef SIGIO |
87dd9b9b | 5696 | kill (getpid (), SIGIO); |
ad163903 JB |
5697 | #endif |
5698 | } | |
5699 | ||
5700 | ||
284f4730 JB |
5701 | \f |
5702 | /* Return the prompt-string of a sparse keymap. | |
5703 | This is the first element which is a string. | |
5704 | Return nil if there is none. */ | |
5705 | ||
5706 | Lisp_Object | |
5707 | map_prompt (map) | |
5708 | Lisp_Object map; | |
5709 | { | |
5710 | while (CONSP (map)) | |
5711 | { | |
5712 | register Lisp_Object tem; | |
5713 | tem = Fcar (map); | |
8c18cbfb | 5714 | if (STRINGP (tem)) |
284f4730 JB |
5715 | return tem; |
5716 | map = Fcdr (map); | |
5717 | } | |
5718 | return Qnil; | |
5719 | } | |
5720 | ||
b7c49376 RS |
5721 | static void menu_bar_item (); |
5722 | static void menu_bar_one_keymap (); | |
5723 | ||
5724 | /* These variables hold the vector under construction within | |
5725 | menu_bar_items and its subroutines, and the current index | |
5726 | for storing into that vector. */ | |
5727 | static Lisp_Object menu_bar_items_vector; | |
9343ab07 | 5728 | static int menu_bar_items_index; |
5ec75a55 | 5729 | |
b7c49376 RS |
5730 | /* Return a vector of menu items for a menu bar, appropriate |
5731 | to the current buffer. Each item has three elements in the vector: | |
f5e09c8b | 5732 | KEY STRING MAPLIST. |
b7c49376 RS |
5733 | |
5734 | OLD is an old vector we can optionally reuse, or nil. */ | |
5ec75a55 RS |
5735 | |
5736 | Lisp_Object | |
b7c49376 RS |
5737 | menu_bar_items (old) |
5738 | Lisp_Object old; | |
5ec75a55 RS |
5739 | { |
5740 | /* The number of keymaps we're scanning right now, and the number of | |
5741 | keymaps we have allocated space for. */ | |
5742 | int nmaps; | |
5743 | ||
5744 | /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] | |
5745 | in the current keymaps, or nil where it is not a prefix. */ | |
5746 | Lisp_Object *maps; | |
5747 | ||
9f9c0e27 | 5748 | Lisp_Object def, tem, tail; |
5ec75a55 RS |
5749 | |
5750 | Lisp_Object result; | |
5751 | ||
5752 | int mapno; | |
47d319aa | 5753 | Lisp_Object oquit; |
5ec75a55 | 5754 | |
b7c49376 RS |
5755 | int i; |
5756 | ||
5757 | struct gcpro gcpro1; | |
5758 | ||
db60d856 JB |
5759 | /* In order to build the menus, we need to call the keymap |
5760 | accessors. They all call QUIT. But this function is called | |
5761 | during redisplay, during which a quit is fatal. So inhibit | |
47d319aa RS |
5762 | quitting while building the menus. |
5763 | We do this instead of specbind because (1) errors will clear it anyway | |
5764 | and (2) this avoids risk of specpdl overflow. */ | |
5765 | oquit = Vinhibit_quit; | |
df0f2ba1 | 5766 | Vinhibit_quit = Qt; |
db60d856 | 5767 | |
b7c49376 RS |
5768 | if (!NILP (old)) |
5769 | menu_bar_items_vector = old; | |
5770 | else | |
5771 | menu_bar_items_vector = Fmake_vector (make_number (24), Qnil); | |
5772 | menu_bar_items_index = 0; | |
5773 | ||
5774 | GCPRO1 (menu_bar_items_vector); | |
5775 | ||
5ec75a55 RS |
5776 | /* Build our list of keymaps. |
5777 | If we recognize a function key and replace its escape sequence in | |
5778 | keybuf with its symbol, or if the sequence starts with a mouse | |
5779 | click and we need to switch buffers, we jump back here to rebuild | |
5780 | the initial keymaps from the current buffer. */ | |
df0f2ba1 | 5781 | { |
5ec75a55 RS |
5782 | Lisp_Object *tmaps; |
5783 | ||
217258d5 | 5784 | /* Should overriding-terminal-local-map and overriding-local-map apply? */ |
d0a49716 | 5785 | if (!NILP (Voverriding_local_map_menu_flag)) |
9dd3131c | 5786 | { |
217258d5 KH |
5787 | /* Yes, use them (if non-nil) as well as the global map. */ |
5788 | maps = (Lisp_Object *) alloca (3 * sizeof (maps[0])); | |
5789 | nmaps = 0; | |
5790 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
5791 | maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
5792 | if (!NILP (Voverriding_local_map)) | |
5793 | maps[nmaps++] = Voverriding_local_map; | |
9dd3131c RS |
5794 | } |
5795 | else | |
5796 | { | |
d0a49716 | 5797 | /* No, so use major and minor mode keymaps. */ |
217258d5 KH |
5798 | nmaps = current_minor_maps (NULL, &tmaps); |
5799 | maps = (Lisp_Object *) alloca ((nmaps + 2) * sizeof (maps[0])); | |
5800 | bcopy (tmaps, maps, nmaps * sizeof (maps[0])); | |
5ec75a55 | 5801 | #ifdef USE_TEXT_PROPERTIES |
217258d5 | 5802 | maps[nmaps++] = get_local_map (PT, current_buffer); |
5ec75a55 | 5803 | #else |
217258d5 | 5804 | maps[nmaps++] = current_buffer->keymap; |
5ec75a55 | 5805 | #endif |
9dd3131c | 5806 | } |
217258d5 | 5807 | maps[nmaps++] = current_global_map; |
5ec75a55 RS |
5808 | } |
5809 | ||
5810 | /* Look up in each map the dummy prefix key `menu-bar'. */ | |
5811 | ||
5812 | result = Qnil; | |
5813 | ||
e58aa385 | 5814 | for (mapno = nmaps - 1; mapno >= 0; mapno--) |
5ec75a55 RS |
5815 | { |
5816 | if (! NILP (maps[mapno])) | |
c6a67acd | 5817 | def = get_keyelt (access_keymap (maps[mapno], Qmenu_bar, 1, 0), 0); |
5ec75a55 RS |
5818 | else |
5819 | def = Qnil; | |
5820 | ||
5821 | tem = Fkeymapp (def); | |
5822 | if (!NILP (tem)) | |
b7c49376 | 5823 | menu_bar_one_keymap (def); |
5ec75a55 RS |
5824 | } |
5825 | ||
b7c49376 RS |
5826 | /* Move to the end those items that should be at the end. */ |
5827 | ||
9f9c0e27 RS |
5828 | for (tail = Vmenu_bar_final_items; CONSP (tail); tail = XCONS (tail)->cdr) |
5829 | { | |
b7c49376 RS |
5830 | int i; |
5831 | int end = menu_bar_items_index; | |
5832 | ||
35b3402f | 5833 | for (i = 0; i < end; i += 4) |
b7c49376 RS |
5834 | if (EQ (XCONS (tail)->car, XVECTOR (menu_bar_items_vector)->contents[i])) |
5835 | { | |
35b3402f | 5836 | Lisp_Object tem0, tem1, tem2, tem3; |
0301268e RS |
5837 | /* Move the item at index I to the end, |
5838 | shifting all the others forward. */ | |
5839 | tem0 = XVECTOR (menu_bar_items_vector)->contents[i + 0]; | |
5840 | tem1 = XVECTOR (menu_bar_items_vector)->contents[i + 1]; | |
5841 | tem2 = XVECTOR (menu_bar_items_vector)->contents[i + 2]; | |
35b3402f RS |
5842 | tem3 = XVECTOR (menu_bar_items_vector)->contents[i + 3]; |
5843 | if (end > i + 4) | |
5844 | bcopy (&XVECTOR (menu_bar_items_vector)->contents[i + 4], | |
0301268e | 5845 | &XVECTOR (menu_bar_items_vector)->contents[i], |
35b3402f RS |
5846 | (end - i - 4) * sizeof (Lisp_Object)); |
5847 | XVECTOR (menu_bar_items_vector)->contents[end - 4] = tem0; | |
5848 | XVECTOR (menu_bar_items_vector)->contents[end - 3] = tem1; | |
5849 | XVECTOR (menu_bar_items_vector)->contents[end - 2] = tem2; | |
5850 | XVECTOR (menu_bar_items_vector)->contents[end - 1] = tem3; | |
0301268e | 5851 | break; |
b7c49376 RS |
5852 | } |
5853 | } | |
9f9c0e27 | 5854 | |
0c9071cd | 5855 | /* Add nil, nil, nil, nil at the end. */ |
b7c49376 | 5856 | i = menu_bar_items_index; |
35b3402f | 5857 | if (i + 4 > XVECTOR (menu_bar_items_vector)->size) |
b7c49376 RS |
5858 | { |
5859 | Lisp_Object tem; | |
5860 | int newsize = 2 * i; | |
5861 | tem = Fmake_vector (make_number (2 * i), Qnil); | |
5862 | bcopy (XVECTOR (menu_bar_items_vector)->contents, | |
5863 | XVECTOR (tem)->contents, i * sizeof (Lisp_Object)); | |
5864 | menu_bar_items_vector = tem; | |
9f9c0e27 | 5865 | } |
b7c49376 RS |
5866 | /* Add this item. */ |
5867 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
5868 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
5869 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
35b3402f | 5870 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; |
b7c49376 | 5871 | menu_bar_items_index = i; |
a73c5e29 | 5872 | |
47d319aa | 5873 | Vinhibit_quit = oquit; |
b7c49376 RS |
5874 | UNGCPRO; |
5875 | return menu_bar_items_vector; | |
5ec75a55 RS |
5876 | } |
5877 | \f | |
5878 | /* Scan one map KEYMAP, accumulating any menu items it defines | |
f5e09c8b | 5879 | in menu_bar_items_vector. */ |
5ec75a55 | 5880 | |
759860a6 RS |
5881 | static Lisp_Object menu_bar_one_keymap_changed_items; |
5882 | ||
b7c49376 RS |
5883 | static void |
5884 | menu_bar_one_keymap (keymap) | |
5885 | Lisp_Object keymap; | |
5ec75a55 | 5886 | { |
e8886a1d | 5887 | Lisp_Object tail, item, table; |
5ec75a55 | 5888 | |
759860a6 RS |
5889 | menu_bar_one_keymap_changed_items = Qnil; |
5890 | ||
5ec75a55 | 5891 | /* Loop over all keymap entries that have menu strings. */ |
8c18cbfb | 5892 | for (tail = keymap; CONSP (tail); tail = XCONS (tail)->cdr) |
5ec75a55 RS |
5893 | { |
5894 | item = XCONS (tail)->car; | |
8c18cbfb | 5895 | if (CONSP (item)) |
e8886a1d | 5896 | menu_bar_item (XCONS (item)->car, XCONS (item)->cdr); |
8c18cbfb | 5897 | else if (VECTORP (item)) |
5ec75a55 RS |
5898 | { |
5899 | /* Loop over the char values represented in the vector. */ | |
5900 | int len = XVECTOR (item)->size; | |
5901 | int c; | |
5902 | for (c = 0; c < len; c++) | |
5903 | { | |
5904 | Lisp_Object character; | |
bb9e9bed | 5905 | XSETFASTINT (character, c); |
e8886a1d | 5906 | menu_bar_item (character, XVECTOR (item)->contents[c]); |
5ec75a55 RS |
5907 | } |
5908 | } | |
5909 | } | |
5ec75a55 RS |
5910 | } |
5911 | ||
f5e09c8b RS |
5912 | /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF. |
5913 | If there's already an item for KEY, add this DEF to it. */ | |
5914 | ||
e8886a1d RS |
5915 | Lisp_Object item_properties; |
5916 | ||
b7c49376 | 5917 | static void |
e8886a1d RS |
5918 | menu_bar_item (key, item) |
5919 | Lisp_Object key, item; | |
5ec75a55 | 5920 | { |
e8886a1d | 5921 | struct gcpro gcpro1; |
b7c49376 | 5922 | int i; |
759860a6 | 5923 | Lisp_Object tem; |
5ec75a55 | 5924 | |
e8886a1d | 5925 | if (EQ (item, Qundefined)) |
e58aa385 | 5926 | { |
f5e09c8b | 5927 | /* If a map has an explicit `undefined' as definition, |
e58aa385 | 5928 | discard any previously made menu bar item. */ |
b7c49376 | 5929 | |
35b3402f | 5930 | for (i = 0; i < menu_bar_items_index; i += 4) |
b7c49376 RS |
5931 | if (EQ (key, XVECTOR (menu_bar_items_vector)->contents[i])) |
5932 | { | |
35b3402f RS |
5933 | if (menu_bar_items_index > i + 4) |
5934 | bcopy (&XVECTOR (menu_bar_items_vector)->contents[i + 4], | |
b7c49376 | 5935 | &XVECTOR (menu_bar_items_vector)->contents[i], |
35b3402f RS |
5936 | (menu_bar_items_index - i - 4) * sizeof (Lisp_Object)); |
5937 | menu_bar_items_index -= 4; | |
b7c49376 RS |
5938 | return; |
5939 | } | |
8aa034e1 RS |
5940 | |
5941 | /* If there's no definition for this key yet, | |
5942 | just ignore `undefined'. */ | |
5943 | return; | |
e58aa385 RS |
5944 | } |
5945 | ||
e8886a1d RS |
5946 | GCPRO1 (key); /* Is this necessary? */ |
5947 | i = parse_menu_item (item, 0, 1); | |
5948 | UNGCPRO; | |
5949 | if (!i) | |
b7c49376 | 5950 | return; |
5ec75a55 | 5951 | |
759860a6 RS |
5952 | /* If this keymap has already contributed to this KEY, |
5953 | don't contribute to it a second time. */ | |
5954 | tem = Fmemq (key, menu_bar_one_keymap_changed_items); | |
5955 | if (!NILP (tem)) | |
5956 | return; | |
5957 | ||
5958 | menu_bar_one_keymap_changed_items | |
5959 | = Fcons (key, menu_bar_one_keymap_changed_items); | |
5960 | ||
e8886a1d RS |
5961 | item = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF]; |
5962 | ||
f5e09c8b | 5963 | /* Find any existing item for this KEY. */ |
35b3402f | 5964 | for (i = 0; i < menu_bar_items_index; i += 4) |
b7c49376 RS |
5965 | if (EQ (key, XVECTOR (menu_bar_items_vector)->contents[i])) |
5966 | break; | |
5967 | ||
f5e09c8b | 5968 | /* If we did not find this KEY, add it at the end. */ |
b7c49376 RS |
5969 | if (i == menu_bar_items_index) |
5970 | { | |
5971 | /* If vector is too small, get a bigger one. */ | |
35b3402f | 5972 | if (i + 4 > XVECTOR (menu_bar_items_vector)->size) |
b7c49376 RS |
5973 | { |
5974 | Lisp_Object tem; | |
5975 | int newsize = 2 * i; | |
5976 | tem = Fmake_vector (make_number (2 * i), Qnil); | |
5977 | bcopy (XVECTOR (menu_bar_items_vector)->contents, | |
5978 | XVECTOR (tem)->contents, i * sizeof (Lisp_Object)); | |
5979 | menu_bar_items_vector = tem; | |
5980 | } | |
e8886a1d | 5981 | |
b7c49376 RS |
5982 | /* Add this item. */ |
5983 | XVECTOR (menu_bar_items_vector)->contents[i++] = key; | |
e8886a1d RS |
5984 | XVECTOR (menu_bar_items_vector)->contents[i++] |
5985 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; | |
5986 | XVECTOR (menu_bar_items_vector)->contents[i++] = Fcons (item, Qnil); | |
35b3402f | 5987 | XVECTOR (menu_bar_items_vector)->contents[i++] = make_number (0); |
b7c49376 RS |
5988 | menu_bar_items_index = i; |
5989 | } | |
e8886a1d | 5990 | /* We did find an item for this KEY. Add ITEM to its list of maps. */ |
f5e09c8b RS |
5991 | else |
5992 | { | |
5993 | Lisp_Object old; | |
5994 | old = XVECTOR (menu_bar_items_vector)->contents[i + 2]; | |
e8886a1d | 5995 | XVECTOR (menu_bar_items_vector)->contents[i + 2] = Fcons (item, old); |
f5e09c8b | 5996 | } |
5ec75a55 RS |
5997 | } |
5998 | \f | |
e8886a1d RS |
5999 | /* This is used as the handler when calling menu_item_eval_property. */ |
6000 | static Lisp_Object | |
6001 | menu_item_eval_property_1 (arg) | |
6002 | Lisp_Object arg; | |
6003 | { | |
6004 | /* If we got a quit from within the menu computation, | |
6005 | quit all the way out of it. This takes care of C-] in the debugger. */ | |
6006 | if (CONSP (arg) && EQ (XCONS (arg)->car, Qquit)) | |
6007 | Fsignal (Qquit, Qnil); | |
6008 | ||
6009 | return Qnil; | |
6010 | } | |
6011 | ||
6012 | /* Evaluate an expression and return the result (or nil if something | |
6013 | went wrong). Used to evaluate dynamic parts of menu items. */ | |
7ee32cda | 6014 | Lisp_Object |
e8886a1d RS |
6015 | menu_item_eval_property (sexpr) |
6016 | Lisp_Object sexpr; | |
6017 | { | |
44e553a3 | 6018 | int count = specpdl_ptr - specpdl; |
e8886a1d | 6019 | Lisp_Object val; |
44e553a3 | 6020 | specbind (Qinhibit_redisplay, Qt); |
e8886a1d RS |
6021 | val = internal_condition_case_1 (Feval, sexpr, Qerror, |
6022 | menu_item_eval_property_1); | |
44e553a3 | 6023 | return unbind_to (count, val); |
e8886a1d RS |
6024 | } |
6025 | ||
6026 | /* This function parses a menu item and leaves the result in the | |
6027 | vector item_properties. | |
6028 | ITEM is a key binding, a possible menu item. | |
6029 | If NOTREAL is nonzero, only check for equivalent key bindings, don't | |
6030 | evaluate dynamic expressions in the menu item. | |
fd3613d7 | 6031 | INMENUBAR is > 0 when this is considered for an entry in a menu bar |
e8886a1d | 6032 | top level. |
fd3613d7 | 6033 | INMENUBAR is < 0 when this is considered for an entry in a keyboard menu. |
e8886a1d RS |
6034 | parse_menu_item returns true if the item is a menu item and false |
6035 | otherwise. */ | |
6036 | ||
6037 | int | |
6038 | parse_menu_item (item, notreal, inmenubar) | |
6039 | Lisp_Object item; | |
6040 | int notreal, inmenubar; | |
6041 | { | |
adc1d5c8 | 6042 | Lisp_Object def, tem, item_string, start; |
07ba902e RS |
6043 | Lisp_Object cachelist; |
6044 | Lisp_Object filter; | |
6045 | Lisp_Object keyhint; | |
e8886a1d | 6046 | int i; |
74c1de23 RS |
6047 | int newcache = 0; |
6048 | ||
07ba902e RS |
6049 | cachelist = Qnil; |
6050 | filter = Qnil; | |
6051 | keyhint = Qnil; | |
6052 | ||
e8886a1d RS |
6053 | if (!CONSP (item)) |
6054 | return 0; | |
6055 | ||
e8886a1d RS |
6056 | /* Create item_properties vector if necessary. */ |
6057 | if (NILP (item_properties)) | |
6058 | item_properties | |
6059 | = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE + 1), Qnil); | |
6060 | ||
6061 | /* Initialize optional entries. */ | |
6062 | for (i = ITEM_PROPERTY_DEF; i < ITEM_PROPERTY_ENABLE; i++) | |
6063 | XVECTOR (item_properties)->contents[i] = Qnil; | |
6064 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] = Qt; | |
6065 | ||
6066 | /* Save the item here to protect it from GC. */ | |
6067 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_ITEM] = item; | |
6068 | ||
6069 | item_string = XCONS (item)->car; | |
6070 | ||
6071 | start = item; | |
6072 | item = XCONS (item)->cdr; | |
6073 | if (STRINGP (item_string)) | |
6074 | { | |
6075 | /* Old format menu item. */ | |
6076 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME] = item_string; | |
6077 | ||
6078 | /* Maybe help string. */ | |
6079 | if (CONSP (item) && STRINGP (XCONS (item)->car)) | |
6080 | { | |
6081 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] | |
6082 | = XCONS (item)->car; | |
6083 | start = item; | |
6084 | item = XCONS (item)->cdr; | |
6085 | } | |
6086 | ||
6087 | /* Maybee key binding cache. */ | |
6088 | if (CONSP (item) && CONSP (XCONS (item)->car) | |
6089 | && (NILP (XCONS (XCONS (item)->car)->car) | |
6090 | || VECTORP (XCONS (XCONS (item)->car)->car))) | |
6091 | { | |
6092 | cachelist = XCONS (item)->car; | |
6093 | item = XCONS (item)->cdr; | |
6094 | } | |
6095 | ||
6096 | /* This is the real definition--the function to run. */ | |
6097 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] = item; | |
6098 | ||
6099 | /* Get enable property, if any. */ | |
6100 | if (SYMBOLP (item)) | |
6101 | { | |
6102 | tem = Fget (item, Qmenu_enable); | |
6103 | if (!NILP (tem)) | |
6104 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] = tem; | |
6105 | } | |
6106 | } | |
6107 | else if (EQ (item_string, Qmenu_item) && CONSP (item)) | |
6108 | { | |
6109 | /* New format menu item. */ | |
6110 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME] | |
6111 | = XCONS (item)->car; | |
6112 | start = XCONS (item)->cdr; | |
6113 | if (CONSP (start)) | |
6114 | { | |
6115 | /* We have a real binding. */ | |
6116 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] | |
6117 | = XCONS (start)->car; | |
6118 | ||
6119 | item = XCONS (start)->cdr; | |
6120 | /* Is there a cache list with key equivalences. */ | |
6121 | if (CONSP (item) && CONSP (XCONS (item)->car)) | |
6122 | { | |
6123 | cachelist = XCONS (item)->car; | |
6124 | item = XCONS (item)->cdr; | |
6125 | } | |
6126 | ||
6127 | /* Parse properties. */ | |
6128 | while (CONSP (item) && CONSP (XCONS (item)->cdr)) | |
6129 | { | |
6130 | tem = XCONS (item)->car; | |
6131 | item = XCONS (item)->cdr; | |
6132 | ||
6133 | if (EQ (tem, QCenable)) | |
6134 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] | |
6135 | = XCONS (item)->car; | |
6136 | else if (EQ (tem, QCvisible) && !notreal) | |
6137 | { | |
6138 | /* If got a visible property and that evaluates to nil | |
6139 | then ignore this item. */ | |
6140 | tem = menu_item_eval_property (XCONS (item)->car); | |
6141 | if (NILP (tem)) | |
adc1d5c8 | 6142 | return 0; |
e8886a1d RS |
6143 | } |
6144 | else if (EQ (tem, QChelp)) | |
6145 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] | |
6146 | = XCONS (item)->car; | |
6147 | else if (EQ (tem, QCfilter)) | |
74c1de23 RS |
6148 | filter = item; |
6149 | else if (EQ (tem, QCkey_sequence)) | |
6150 | { | |
6151 | tem = XCONS (item)->car; | |
6152 | if (NILP (cachelist) | |
6153 | && (SYMBOLP (tem) || STRINGP (tem) || VECTORP (tem))) | |
6154 | /* Be GC protected. Set keyhint to item instead of tem. */ | |
6155 | keyhint = item; | |
6156 | } | |
6157 | else if (EQ (tem, QCkeys)) | |
6158 | { | |
6159 | tem = XCONS (item)->car; | |
6160 | if (CONSP (tem) || STRINGP (tem) && NILP (cachelist)) | |
6161 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ] | |
6162 | = tem; | |
6163 | } | |
e8886a1d RS |
6164 | else if (EQ (tem, QCbutton) && CONSP (XCONS (item)->car)) |
6165 | { | |
74c1de23 | 6166 | Lisp_Object type; |
e8886a1d RS |
6167 | tem = XCONS (item)->car; |
6168 | type = XCONS (tem)->car; | |
6169 | if (EQ (type, QCtoggle) || EQ (type, QCradio)) | |
6170 | { | |
6171 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED] | |
6172 | = XCONS (tem)->cdr; | |
6173 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE] | |
6174 | = type; | |
6175 | } | |
6176 | } | |
6177 | item = XCONS (item)->cdr; | |
6178 | } | |
6179 | } | |
6180 | else if (inmenubar || !NILP (start)) | |
adc1d5c8 | 6181 | return 0; |
e8886a1d RS |
6182 | } |
6183 | else | |
adc1d5c8 | 6184 | return 0; /* not a menu item */ |
e8886a1d RS |
6185 | |
6186 | /* If item string is not a string, evaluate it to get string. | |
6187 | If we don't get a string, skip this item. */ | |
6188 | item_string = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; | |
6189 | if (!(STRINGP (item_string) || notreal)) | |
6190 | { | |
6191 | item_string = menu_item_eval_property (item_string); | |
6192 | if (!STRINGP (item_string)) | |
adc1d5c8 | 6193 | return 0; |
e8886a1d RS |
6194 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME] = item_string; |
6195 | } | |
6196 | ||
6197 | /* If got a filter apply it on definition. */ | |
6198 | def = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF]; | |
6199 | if (!NILP (filter)) | |
6200 | { | |
c5c5a6f8 RS |
6201 | def = menu_item_eval_property (list2 (XCONS (filter)->car, |
6202 | list2 (Qquote, def))); | |
6203 | ||
e8886a1d RS |
6204 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] = def; |
6205 | } | |
6206 | ||
6207 | /* If we got no definition, this item is just unselectable text which | |
74c1de23 | 6208 | is OK in a submenu but not in the menubar. */ |
e8886a1d | 6209 | if (NILP (def)) |
adc1d5c8 | 6210 | return (inmenubar ? 0 : 1); |
e8886a1d RS |
6211 | |
6212 | /* Enable or disable selection of item. */ | |
6213 | tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE]; | |
6214 | if (!EQ (tem, Qt)) | |
6215 | { | |
6216 | if (notreal) | |
6217 | tem = Qt; | |
6218 | else | |
6219 | tem = menu_item_eval_property (tem); | |
6220 | if (inmenubar && NILP (tem)) | |
adc1d5c8 | 6221 | return 0; /* Ignore disabled items in menu bar. */ |
e8886a1d RS |
6222 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] = tem; |
6223 | } | |
6224 | ||
6225 | /* See if this is a separate pane or a submenu. */ | |
74c1de23 | 6226 | def = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF]; |
e8886a1d | 6227 | tem = get_keymap_1 (def, 0, 1); |
9ac425d1 | 6228 | /* For a subkeymap, just record its details and exit. */ |
e8886a1d RS |
6229 | if (!NILP (tem)) |
6230 | { | |
6231 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_MAP] = tem; | |
6232 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] = tem; | |
e8886a1d RS |
6233 | return 1; |
6234 | } | |
9ac425d1 RS |
6235 | /* At the top level in the menu bar, do likewise for commands also. |
6236 | The menu bar does not display equivalent key bindings anyway. | |
6237 | ITEM_PROPERTY_DEF is already set up properly. */ | |
6238 | if (inmenubar > 0) | |
6239 | return 1; | |
e8886a1d RS |
6240 | |
6241 | /* This is a command. See if there is an equivalent key binding. */ | |
6242 | if (NILP (cachelist)) | |
6243 | { | |
74c1de23 | 6244 | /* We have to create a cachelist. */ |
e8886a1d RS |
6245 | CHECK_IMPURE (start); |
6246 | XCONS (start)->cdr = Fcons (Fcons (Qnil, Qnil), XCONS (start)->cdr); | |
6247 | cachelist = XCONS (XCONS (start)->cdr)->car; | |
74c1de23 RS |
6248 | newcache = 1; |
6249 | tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ]; | |
6250 | if (!NILP (keyhint)) | |
6251 | { | |
6252 | XCONS (cachelist)->car = XCONS (keyhint)->car; | |
6253 | newcache = 0; | |
6254 | } | |
6255 | else if (STRINGP (tem)) | |
6256 | { | |
6257 | XCONS (cachelist)->cdr = Fsubstitute_command_keys (tem); | |
6258 | XCONS (cachelist)->car = Qt; | |
6259 | } | |
6260 | } | |
6261 | tem = XCONS (cachelist)->car; | |
6262 | if (!EQ (tem, Qt)) | |
6263 | { | |
6264 | int chkcache = 0; | |
6265 | Lisp_Object prefix; | |
6266 | ||
6267 | if (!NILP (tem)) | |
6268 | tem = Fkey_binding (tem, Qnil); | |
6269 | ||
6270 | prefix = XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ]; | |
6271 | if (CONSP (prefix)) | |
6272 | { | |
6273 | def = XCONS (prefix)->car; | |
6274 | prefix = XCONS (prefix)->cdr; | |
6275 | } | |
e8886a1d | 6276 | else |
74c1de23 RS |
6277 | def = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF]; |
6278 | ||
6279 | if (NILP (XCONS (cachelist)->car)) /* Have no saved key. */ | |
6280 | { | |
6281 | if (newcache /* Always check first time. */ | |
6282 | /* Should we check everything when precomputing key | |
6283 | bindings? */ | |
6284 | /* || notreal */ | |
6285 | /* If something had no key binding before, don't recheck it | |
6286 | because that is too slow--except if we have a list of | |
6287 | rebound commands in Vdefine_key_rebound_commands, do | |
6288 | recheck any command that appears in that list. */ | |
6289 | || (CONSP (Vdefine_key_rebound_commands) | |
6290 | && !NILP (Fmemq (def, Vdefine_key_rebound_commands)))) | |
6291 | chkcache = 1; | |
6292 | } | |
6293 | /* We had a saved key. Is it still bound to the command? */ | |
6294 | else if (NILP (tem) | |
6295 | || !EQ (tem, def) | |
6296 | /* If the command is an alias for another | |
6297 | (such as lmenu.el set it up), check if the | |
6298 | original command matches the cached command. */ | |
6299 | && !(SYMBOLP (def) && EQ (tem, XSYMBOL (def)->function))) | |
6300 | chkcache = 1; /* Need to recompute key binding. */ | |
6301 | ||
6302 | if (chkcache) | |
6303 | { | |
6304 | /* Recompute equivalent key binding. If the command is an alias | |
6305 | for another (such as lmenu.el set it up), see if the original | |
6306 | command name has equivalent keys. Otherwise look up the | |
6307 | specified command itself. We don't try both, because that | |
6308 | makes lmenu menus slow. */ | |
6309 | if (SYMBOLP (def) && SYMBOLP (XSYMBOL (def)->function) | |
6310 | && ! NILP (Fget (def, Qmenu_alias))) | |
6311 | def = XSYMBOL (def)->function; | |
6312 | tem = Fwhere_is_internal (def, Qnil, Qt, Qnil); | |
6313 | XCONS (cachelist)->car = tem; | |
6314 | if (NILP (tem)) | |
6315 | { | |
6316 | XCONS (cachelist)->cdr = Qnil; | |
6317 | chkcache = 0; | |
6318 | } | |
6319 | } | |
6320 | else if (!NILP (keyhint) && !NILP (XCONS (cachelist)->car)) | |
6321 | { | |
6322 | tem = XCONS (cachelist)->car; | |
6323 | chkcache = 1; | |
6324 | } | |
6325 | ||
6326 | newcache = chkcache; | |
6327 | if (chkcache) | |
6328 | { | |
6329 | tem = Fkey_description (tem); | |
6330 | if (CONSP (prefix)) | |
6331 | { | |
6332 | if (STRINGP (XCONS (prefix)->car)) | |
6333 | tem = concat2 (XCONS (prefix)->car, tem); | |
6334 | if (STRINGP (XCONS (prefix)->cdr)) | |
6335 | tem = concat2 (tem, XCONS (prefix)->cdr); | |
6336 | } | |
6337 | XCONS (cachelist)->cdr = tem; | |
6338 | } | |
6339 | } | |
6340 | ||
6341 | tem = XCONS (cachelist)->cdr; | |
6342 | if (newcache && !NILP (tem)) | |
e8886a1d | 6343 | { |
74c1de23 RS |
6344 | tem = concat3 (build_string (" ("), tem, build_string (")")); |
6345 | XCONS (cachelist)->cdr = tem; | |
e8886a1d RS |
6346 | } |
6347 | ||
6348 | /* If we only want to precompute equivalent key bindings, stop here. */ | |
6349 | if (notreal) | |
adc1d5c8 | 6350 | return 1; |
e8886a1d RS |
6351 | |
6352 | /* If we have an equivalent key binding, use that. */ | |
adc1d5c8 RS |
6353 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ] = tem; |
6354 | ||
6355 | /* Include this when menu help is implemented. | |
6356 | tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP]; | |
6357 | if (!(NILP (tem) || STRINGP (tem))) | |
6358 | { | |
6359 | tem = menu_item_eval_property (tem); | |
6360 | if (!STRINGP (tem)) | |
6361 | tem = Qnil; | |
6362 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem; | |
6363 | } | |
e8886a1d RS |
6364 | */ |
6365 | ||
6366 | /* Handle radio buttons or toggle boxes. */ | |
6367 | tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]; | |
6368 | if (!NILP (tem)) | |
6369 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED] | |
6370 | = menu_item_eval_property (tem); | |
6371 | ||
e8886a1d RS |
6372 | return 1; |
6373 | } | |
7ee32cda GM |
6374 | |
6375 | ||
6376 | \f | |
6377 | /*********************************************************************** | |
6378 | Tool-bars | |
6379 | ***********************************************************************/ | |
6380 | ||
9ea173e8 GM |
6381 | /* A vector holding tool bar items while they are parsed in function |
6382 | tool_bar_items runs Each item occupies TOOL_BAR_ITEM_NSCLOTS elements | |
6383 | in the vector. */ | |
7ee32cda | 6384 | |
9ea173e8 | 6385 | static Lisp_Object tool_bar_items_vector; |
7ee32cda | 6386 | |
9ea173e8 GM |
6387 | /* A vector holding the result of parse_tool_bar_item. Layout is like |
6388 | the one for a single item in tool_bar_items_vector. */ | |
7ee32cda | 6389 | |
9ea173e8 | 6390 | static Lisp_Object tool_bar_item_properties; |
7ee32cda | 6391 | |
9ea173e8 | 6392 | /* Next free index in tool_bar_items_vector. */ |
7ee32cda | 6393 | |
9ea173e8 | 6394 | static int ntool_bar_items; |
7ee32cda | 6395 | |
9ea173e8 | 6396 | /* The symbols `tool-bar', and `:image'. */ |
7ee32cda | 6397 | |
9ea173e8 | 6398 | extern Lisp_Object Qtool_bar; |
7ee32cda GM |
6399 | Lisp_Object QCimage; |
6400 | ||
6401 | /* Function prototypes. */ | |
6402 | ||
9ea173e8 GM |
6403 | static void init_tool_bar_items P_ ((Lisp_Object)); |
6404 | static void process_tool_bar_item P_ ((Lisp_Object, Lisp_Object)); | |
6405 | static int parse_tool_bar_item P_ ((Lisp_Object, Lisp_Object)); | |
6406 | static void append_tool_bar_item P_ ((void)); | |
7ee32cda GM |
6407 | |
6408 | ||
9ea173e8 | 6409 | /* Return a vector of tool bar items for keymaps currently in effect. |
7ee32cda | 6410 | Reuse vector REUSE if non-nil. Return in *NITEMS the number of |
9ea173e8 | 6411 | tool bar items found. */ |
7ee32cda GM |
6412 | |
6413 | Lisp_Object | |
9ea173e8 | 6414 | tool_bar_items (reuse, nitems) |
7ee32cda GM |
6415 | Lisp_Object reuse; |
6416 | int *nitems; | |
6417 | { | |
6418 | Lisp_Object *maps; | |
6419 | int nmaps, i; | |
6420 | Lisp_Object oquit; | |
6421 | Lisp_Object *tmaps; | |
6422 | extern Lisp_Object Voverriding_local_map_menu_flag; | |
6423 | extern Lisp_Object Voverriding_local_map; | |
6424 | ||
6425 | *nitems = 0; | |
6426 | ||
6427 | /* In order to build the menus, we need to call the keymap | |
6428 | accessors. They all call QUIT. But this function is called | |
6429 | during redisplay, during which a quit is fatal. So inhibit | |
6430 | quitting while building the menus. We do this instead of | |
6431 | specbind because (1) errors will clear it anyway and (2) this | |
6432 | avoids risk of specpdl overflow. */ | |
6433 | oquit = Vinhibit_quit; | |
6434 | Vinhibit_quit = Qt; | |
6435 | ||
9ea173e8 GM |
6436 | /* Initialize tool_bar_items_vector and protect it from GC. */ |
6437 | init_tool_bar_items (reuse); | |
7ee32cda GM |
6438 | |
6439 | /* Build list of keymaps in maps. Set nmaps to the number of maps | |
6440 | to process. */ | |
6441 | ||
6442 | /* Should overriding-terminal-local-map and overriding-local-map apply? */ | |
6443 | if (!NILP (Voverriding_local_map_menu_flag)) | |
6444 | { | |
6445 | /* Yes, use them (if non-nil) as well as the global map. */ | |
6446 | maps = (Lisp_Object *) alloca (3 * sizeof (maps[0])); | |
6447 | nmaps = 0; | |
6448 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
6449 | maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
6450 | if (!NILP (Voverriding_local_map)) | |
6451 | maps[nmaps++] = Voverriding_local_map; | |
6452 | } | |
6453 | else | |
6454 | { | |
6455 | /* No, so use major and minor mode keymaps. */ | |
6456 | nmaps = current_minor_maps (NULL, &tmaps); | |
6457 | maps = (Lisp_Object *) alloca ((nmaps + 2) * sizeof (maps[0])); | |
6458 | bcopy (tmaps, maps, nmaps * sizeof (maps[0])); | |
6459 | #ifdef USE_TEXT_PROPERTIES | |
6460 | maps[nmaps++] = get_local_map (PT, current_buffer); | |
6461 | #else | |
6462 | maps[nmaps++] = current_buffer->keymap; | |
6463 | #endif | |
6464 | } | |
6465 | ||
6466 | /* Add global keymap at the end. */ | |
6467 | maps[nmaps++] = current_global_map; | |
6468 | ||
6469 | /* Process maps in reverse order and look up in each map the prefix | |
9ea173e8 | 6470 | key `tool-bar'. */ |
7ee32cda GM |
6471 | for (i = nmaps - 1; i >= 0; --i) |
6472 | if (!NILP (maps[i])) | |
6473 | { | |
6474 | Lisp_Object keymap; | |
6475 | ||
9ea173e8 | 6476 | keymap = get_keyelt (access_keymap (maps[i], Qtool_bar, 1, 1), 0); |
7ee32cda GM |
6477 | if (!NILP (Fkeymapp (keymap))) |
6478 | { | |
6479 | Lisp_Object tail; | |
6480 | ||
6481 | /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */ | |
6482 | for (tail = keymap; CONSP (tail); tail = XCONS (tail)->cdr) | |
6483 | { | |
6484 | Lisp_Object keydef = XCAR (tail); | |
6485 | if (CONSP (keydef)) | |
9ea173e8 | 6486 | process_tool_bar_item (XCAR (keydef), XCDR (keydef)); |
7ee32cda GM |
6487 | } |
6488 | } | |
6489 | } | |
6490 | ||
6491 | Vinhibit_quit = oquit; | |
9ea173e8 GM |
6492 | *nitems = ntool_bar_items / TOOL_BAR_ITEM_NSLOTS; |
6493 | return tool_bar_items_vector; | |
7ee32cda GM |
6494 | } |
6495 | ||
6496 | ||
6497 | /* Process the definition of KEY which is DEF. */ | |
6498 | ||
6499 | static void | |
9ea173e8 | 6500 | process_tool_bar_item (key, def) |
7ee32cda GM |
6501 | Lisp_Object key, def; |
6502 | { | |
6503 | int i; | |
6504 | extern Lisp_Object Qundefined; | |
6505 | struct gcpro gcpro1, gcpro2; | |
6506 | ||
9ea173e8 | 6507 | /* Protect KEY and DEF from GC because parse_tool_bar_item may call |
7ee32cda GM |
6508 | eval. */ |
6509 | GCPRO2 (key, def); | |
6510 | ||
6511 | if (EQ (def, Qundefined)) | |
6512 | { | |
6513 | /* If a map has an explicit `undefined' as definition, | |
6514 | discard any previously made item. */ | |
9ea173e8 | 6515 | for (i = 0; i < ntool_bar_items; i += TOOL_BAR_ITEM_NSLOTS) |
7ee32cda | 6516 | { |
9ea173e8 | 6517 | Lisp_Object *v = XVECTOR (tool_bar_items_vector)->contents + i; |
7ee32cda | 6518 | |
9ea173e8 | 6519 | if (EQ (key, v[TOOL_BAR_ITEM_KEY])) |
7ee32cda | 6520 | { |
9ea173e8 GM |
6521 | if (ntool_bar_items > i + TOOL_BAR_ITEM_NSLOTS) |
6522 | bcopy (v + TOOL_BAR_ITEM_NSLOTS, v, | |
6523 | ((ntool_bar_items - i - TOOL_BAR_ITEM_NSLOTS) | |
7ee32cda | 6524 | * sizeof (Lisp_Object))); |
9ea173e8 | 6525 | ntool_bar_items -= TOOL_BAR_ITEM_NSLOTS; |
7ee32cda GM |
6526 | break; |
6527 | } | |
6528 | } | |
6529 | } | |
9ea173e8 GM |
6530 | else if (parse_tool_bar_item (key, def)) |
6531 | /* Append a new tool bar item to tool_bar_items_vector. Accept | |
7ee32cda | 6532 | more than one definition for the same key. */ |
9ea173e8 | 6533 | append_tool_bar_item (); |
7ee32cda GM |
6534 | |
6535 | UNGCPRO; | |
6536 | } | |
6537 | ||
6538 | ||
9ea173e8 GM |
6539 | /* Parse a tool bar item specification ITEM for key KEY and return the |
6540 | result in tool_bar_item_properties. Value is zero if ITEM is | |
7ee32cda GM |
6541 | invalid. |
6542 | ||
6543 | ITEM is a list `(menu-item CAPTION BINDING PROPS...)'. | |
6544 | ||
6545 | CAPTION is the caption of the item, If it's not a string, it is | |
6546 | evaluated to get a string. | |
6547 | ||
9ea173e8 | 6548 | BINDING is the tool bar item's binding. Tool-bar items with keymaps |
7ee32cda GM |
6549 | as binding are currently ignored. |
6550 | ||
6551 | The following properties are recognized: | |
6552 | ||
6553 | - `:enable FORM'. | |
6554 | ||
9ea173e8 GM |
6555 | FORM is evaluated and specifies whether the tool bar item is |
6556 | enabled or disabled. | |
7ee32cda GM |
6557 | |
6558 | - `:visible FORM' | |
6559 | ||
9ea173e8 | 6560 | FORM is evaluated and specifies whether the tool bar item is visible. |
7ee32cda GM |
6561 | |
6562 | - `:filter FUNCTION' | |
6563 | ||
6564 | FUNCTION is invoked with one parameter `(quote BINDING)'. Its | |
6565 | result is stored as the new binding. | |
6566 | ||
6567 | - `:button (TYPE SELECTED)' | |
6568 | ||
6569 | TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated | |
6570 | and specifies whether the button is selected (pressed) or not. | |
6571 | ||
6572 | - `:image IMAGES' | |
6573 | ||
6574 | IMAGES is either a single image specification or a vector of four | |
9ea173e8 | 6575 | image specifications. See enum tool_bar_item_images. |
7ee32cda GM |
6576 | |
6577 | - `:help HELP-STRING'. | |
6578 | ||
9ea173e8 | 6579 | Gives a help string to display for the tool bar item. */ |
7ee32cda GM |
6580 | |
6581 | static int | |
9ea173e8 | 6582 | parse_tool_bar_item (key, item) |
7ee32cda GM |
6583 | Lisp_Object key, item; |
6584 | { | |
9ea173e8 GM |
6585 | /* Access slot with index IDX of vector tool_bar_item_properties. */ |
6586 | #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX] | |
7ee32cda GM |
6587 | |
6588 | Lisp_Object filter = Qnil; | |
6589 | Lisp_Object caption; | |
6590 | extern Lisp_Object QCenable, QCvisible, QChelp, QCfilter; | |
6591 | extern Lisp_Object QCbutton, QCtoggle, QCradio; | |
6592 | int i; | |
6593 | struct gcpro gcpro1; | |
6594 | ||
9ea173e8 | 6595 | /* Defininition looks like `(tool-bar-item CAPTION BINDING |
7ee32cda | 6596 | PROPS...)'. Rule out items that aren't lists, don't start with |
9ea173e8 | 6597 | `tool-bar-item' or whose rest following `tool-bar-item' is not a |
7ee32cda GM |
6598 | list. */ |
6599 | if (!CONSP (item) | |
6600 | || !EQ (XCAR (item), Qmenu_item) | |
6601 | || (item = XCDR (item), | |
6602 | !CONSP (item))) | |
6603 | return 0; | |
6604 | ||
9ea173e8 | 6605 | /* Create tool_bar_item_properties vector if necessary. Reset it to |
7ee32cda | 6606 | defaults. */ |
9ea173e8 | 6607 | if (VECTORP (tool_bar_item_properties)) |
7ee32cda | 6608 | { |
9ea173e8 | 6609 | for (i = 0; i < TOOL_BAR_ITEM_NSLOTS; ++i) |
7ee32cda GM |
6610 | PROP (i) = Qnil; |
6611 | } | |
6612 | else | |
9ea173e8 GM |
6613 | tool_bar_item_properties |
6614 | = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS), Qnil); | |
7ee32cda GM |
6615 | |
6616 | /* Set defaults. */ | |
9ea173e8 GM |
6617 | PROP (TOOL_BAR_ITEM_KEY) = key; |
6618 | PROP (TOOL_BAR_ITEM_ENABLED_P) = Qt; | |
7ee32cda GM |
6619 | |
6620 | /* Get the caption of the item. If the caption is not a string, | |
6621 | evaluate it to get a string. If we don't get a string, skip this | |
6622 | item. */ | |
6623 | caption = XCAR (item); | |
6624 | if (!STRINGP (caption)) | |
6625 | { | |
6626 | caption = menu_item_eval_property (caption); | |
6627 | if (!STRINGP (caption)) | |
6628 | return 0; | |
6629 | } | |
9ea173e8 | 6630 | PROP (TOOL_BAR_ITEM_CAPTION) = caption; |
7ee32cda GM |
6631 | |
6632 | /* Give up if rest following the caption is not a list. */ | |
6633 | item = XCDR (item); | |
6634 | if (!CONSP (item)) | |
6635 | return 0; | |
6636 | ||
6637 | /* Store the binding. */ | |
9ea173e8 | 6638 | PROP (TOOL_BAR_ITEM_BINDING) = XCAR (item); |
7ee32cda GM |
6639 | item = XCDR (item); |
6640 | ||
6641 | /* Process the rest of the properties. */ | |
6642 | for (; CONSP (item) && CONSP (XCDR (item)); item = XCDR (XCDR (item))) | |
6643 | { | |
6644 | Lisp_Object key, value; | |
6645 | ||
6646 | key = XCAR (item); | |
6647 | value = XCAR (XCDR (item)); | |
6648 | ||
6649 | if (EQ (key, QCenable)) | |
6650 | /* `:enable FORM'. */ | |
9ea173e8 | 6651 | PROP (TOOL_BAR_ITEM_ENABLED_P) = value; |
7ee32cda GM |
6652 | else if (EQ (key, QCvisible)) |
6653 | { | |
6654 | /* `:visible FORM'. If got a visible property and that | |
6655 | evaluates to nil then ignore this item. */ | |
6656 | if (NILP (menu_item_eval_property (value))) | |
6657 | return 0; | |
6658 | } | |
6659 | else if (EQ (key, QChelp)) | |
6660 | /* `:help HELP-STRING'. */ | |
9ea173e8 | 6661 | PROP (TOOL_BAR_ITEM_HELP) = value; |
7ee32cda GM |
6662 | else if (EQ (key, QCfilter)) |
6663 | /* ':filter FORM'. */ | |
6664 | filter = value; | |
6665 | else if (EQ (key, QCbutton) && CONSP (value)) | |
6666 | { | |
6667 | /* `:button (TYPE . SELECTED)'. */ | |
6668 | Lisp_Object type, selected; | |
6669 | ||
6670 | type = XCAR (value); | |
6671 | selected = XCDR (value); | |
6672 | if (EQ (type, QCtoggle) || EQ (type, QCradio)) | |
6673 | { | |
9ea173e8 GM |
6674 | PROP (TOOL_BAR_ITEM_SELECTED_P) = selected; |
6675 | PROP (TOOL_BAR_ITEM_TYPE) = type; | |
7ee32cda GM |
6676 | } |
6677 | } | |
6678 | else if (EQ (key, QCimage) | |
6679 | && (CONSP (value) | |
6680 | || (VECTORP (value) && XVECTOR (value)->size == 4))) | |
6681 | /* Value is either a single image specification or a vector | |
6682 | of 4 such specifications for the different buttion states. */ | |
9ea173e8 | 6683 | PROP (TOOL_BAR_ITEM_IMAGES) = value; |
7ee32cda GM |
6684 | } |
6685 | ||
6686 | /* If got a filter apply it on binding. */ | |
6687 | if (!NILP (filter)) | |
9ea173e8 | 6688 | PROP (TOOL_BAR_ITEM_BINDING) |
7ee32cda GM |
6689 | = menu_item_eval_property (list2 (filter, |
6690 | list2 (Qquote, | |
9ea173e8 | 6691 | PROP (TOOL_BAR_ITEM_BINDING)))); |
7ee32cda GM |
6692 | |
6693 | /* See if the binding is a keymap. Give up if it is. */ | |
9ea173e8 | 6694 | if (!NILP (get_keymap_1 (PROP (TOOL_BAR_ITEM_BINDING), 0, 1))) |
7ee32cda GM |
6695 | return 0; |
6696 | ||
6697 | /* Enable or disable selection of item. */ | |
9ea173e8 GM |
6698 | if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P), Qt)) |
6699 | PROP (TOOL_BAR_ITEM_ENABLED_P) | |
6700 | = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P)); | |
7ee32cda GM |
6701 | |
6702 | /* Handle radio buttons or toggle boxes. */ | |
9ea173e8 GM |
6703 | if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P))) |
6704 | PROP (TOOL_BAR_ITEM_SELECTED_P) | |
6705 | = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P)); | |
7ee32cda GM |
6706 | |
6707 | return 1; | |
6708 | ||
6709 | #undef PROP | |
6710 | } | |
6711 | ||
6712 | ||
9ea173e8 GM |
6713 | /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector |
6714 | that can be reused. */ | |
7ee32cda GM |
6715 | |
6716 | static void | |
9ea173e8 | 6717 | init_tool_bar_items (reuse) |
7ee32cda GM |
6718 | Lisp_Object reuse; |
6719 | { | |
6720 | if (VECTORP (reuse)) | |
9ea173e8 | 6721 | tool_bar_items_vector = reuse; |
7ee32cda | 6722 | else |
9ea173e8 GM |
6723 | tool_bar_items_vector = Fmake_vector (make_number (64), Qnil); |
6724 | ntool_bar_items = 0; | |
7ee32cda GM |
6725 | } |
6726 | ||
6727 | ||
9ea173e8 GM |
6728 | /* Append parsed tool bar item properties from |
6729 | tool_bar_item_properties */ | |
7ee32cda GM |
6730 | |
6731 | static void | |
9ea173e8 | 6732 | append_tool_bar_item () |
7ee32cda GM |
6733 | { |
6734 | Lisp_Object *to, *from; | |
6735 | ||
9ea173e8 GM |
6736 | /* Enlarge tool_bar_items_vector if necessary. */ |
6737 | if (ntool_bar_items + TOOL_BAR_ITEM_NSLOTS | |
6738 | >= XVECTOR (tool_bar_items_vector)->size) | |
7ee32cda GM |
6739 | { |
6740 | Lisp_Object new_vector; | |
9ea173e8 | 6741 | int old_size = XVECTOR (tool_bar_items_vector)->size; |
7ee32cda GM |
6742 | |
6743 | new_vector = Fmake_vector (make_number (2 * old_size), Qnil); | |
9ea173e8 | 6744 | bcopy (XVECTOR (tool_bar_items_vector)->contents, |
7ee32cda GM |
6745 | XVECTOR (new_vector)->contents, |
6746 | old_size * sizeof (Lisp_Object)); | |
9ea173e8 | 6747 | tool_bar_items_vector = new_vector; |
7ee32cda GM |
6748 | } |
6749 | ||
9ea173e8 GM |
6750 | /* Append entries from tool_bar_item_properties to the end of |
6751 | tool_bar_items_vector. */ | |
6752 | to = XVECTOR (tool_bar_items_vector)->contents + ntool_bar_items; | |
6753 | from = XVECTOR (tool_bar_item_properties)->contents; | |
6754 | bcopy (from, to, TOOL_BAR_ITEM_NSLOTS * sizeof *to); | |
6755 | ntool_bar_items += TOOL_BAR_ITEM_NSLOTS; | |
7ee32cda GM |
6756 | } |
6757 | ||
6758 | ||
6759 | ||
6760 | ||
e8886a1d | 6761 | \f |
dcc408a0 RS |
6762 | /* Read a character using menus based on maps in the array MAPS. |
6763 | NMAPS is the length of MAPS. Return nil if there are no menus in the maps. | |
6764 | Return t if we displayed a menu but the user rejected it. | |
7d6de002 RS |
6765 | |
6766 | PREV_EVENT is the previous input event, or nil if we are reading | |
6767 | the first event of a key sequence. | |
6768 | ||
83d68044 | 6769 | If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1 |
6569cc8d | 6770 | if we used a mouse menu to read the input, or zero otherwise. If |
83d68044 | 6771 | USED_MOUSE_MENU is null, we don't dereference it. |
284f4730 JB |
6772 | |
6773 | The prompting is done based on the prompt-string of the map | |
df0f2ba1 | 6774 | and the strings associated with various map elements. |
8150596a RS |
6775 | |
6776 | This can be done with X menus or with menus put in the minibuf. | |
6777 | These are done in different ways, depending on how the input will be read. | |
6778 | Menus using X are done after auto-saving in read-char, getting the input | |
6779 | event from Fx_popup_menu; menus using the minibuf use read_char recursively | |
6780 | and do auto-saving in the inner call of read_char. */ | |
284f4730 | 6781 | |
7617111f | 6782 | static Lisp_Object |
8150596a | 6783 | read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu) |
7d6de002 RS |
6784 | int nmaps; |
6785 | Lisp_Object *maps; | |
6786 | Lisp_Object prev_event; | |
6787 | int *used_mouse_menu; | |
284f4730 | 6788 | { |
7d6de002 RS |
6789 | int mapno; |
6790 | register Lisp_Object name; | |
7d6de002 RS |
6791 | Lisp_Object rest, vector; |
6792 | ||
6569cc8d JB |
6793 | if (used_mouse_menu) |
6794 | *used_mouse_menu = 0; | |
284f4730 JB |
6795 | |
6796 | /* Use local over global Menu maps */ | |
6797 | ||
7d6de002 RS |
6798 | if (! menu_prompting) |
6799 | return Qnil; | |
6800 | ||
03361bcc RS |
6801 | /* Optionally disregard all but the global map. */ |
6802 | if (inhibit_local_menu_bar_menus) | |
6803 | { | |
6804 | maps += (nmaps - 1); | |
6805 | nmaps = 1; | |
6806 | } | |
6807 | ||
7d6de002 RS |
6808 | /* Get the menu name from the first map that has one (a prompt string). */ |
6809 | for (mapno = 0; mapno < nmaps; mapno++) | |
6810 | { | |
6811 | name = map_prompt (maps[mapno]); | |
6812 | if (!NILP (name)) | |
6813 | break; | |
6814 | } | |
284f4730 | 6815 | |
7d6de002 | 6816 | /* If we don't have any menus, just read a character normally. */ |
dbc4e1c1 | 6817 | if (mapno >= nmaps) |
7d6de002 RS |
6818 | return Qnil; |
6819 | ||
1f5b1641 | 6820 | #ifdef HAVE_MENUS |
7d6de002 RS |
6821 | /* If we got to this point via a mouse click, |
6822 | use a real menu for mouse selection. */ | |
5a8d99e0 | 6823 | if (EVENT_HAS_PARAMETERS (prev_event) |
7ee32cda | 6824 | && !EQ (XCONS (prev_event)->car, Qmenu_bar) |
9ea173e8 | 6825 | && !EQ (XCONS (prev_event)->car, Qtool_bar)) |
7d6de002 RS |
6826 | { |
6827 | /* Display the menu and get the selection. */ | |
6828 | Lisp_Object *realmaps | |
6829 | = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); | |
6830 | Lisp_Object value; | |
6831 | int nmaps1 = 0; | |
6832 | ||
6833 | /* Use the maps that are not nil. */ | |
6834 | for (mapno = 0; mapno < nmaps; mapno++) | |
6835 | if (!NILP (maps[mapno])) | |
6836 | realmaps[nmaps1++] = maps[mapno]; | |
6837 | ||
6838 | value = Fx_popup_menu (prev_event, Flist (nmaps1, realmaps)); | |
663258f2 JB |
6839 | if (CONSP (value)) |
6840 | { | |
68f297c5 RS |
6841 | Lisp_Object tem; |
6842 | ||
8eb4d8ef RS |
6843 | record_menu_key (XCONS (value)->car); |
6844 | ||
68f297c5 RS |
6845 | /* If we got multiple events, unread all but |
6846 | the first. | |
6847 | There is no way to prevent those unread events | |
6848 | from showing up later in last_nonmenu_event. | |
6849 | So turn symbol and integer events into lists, | |
6850 | to indicate that they came from a mouse menu, | |
6851 | so that when present in last_nonmenu_event | |
6852 | they won't confuse things. */ | |
6853 | for (tem = XCONS (value)->cdr; !NILP (tem); | |
6854 | tem = XCONS (tem)->cdr) | |
8eb4d8ef RS |
6855 | { |
6856 | record_menu_key (XCONS (tem)->car); | |
6857 | if (SYMBOLP (XCONS (tem)->car) | |
6858 | || INTEGERP (XCONS (tem)->car)) | |
6859 | XCONS (tem)->car | |
6860 | = Fcons (XCONS (tem)->car, Qnil); | |
6861 | } | |
68f297c5 | 6862 | |
663258f2 JB |
6863 | /* If we got more than one event, put all but the first |
6864 | onto this list to be read later. | |
6865 | Return just the first event now. */ | |
24597608 RS |
6866 | Vunread_command_events |
6867 | = nconc2 (XCONS (value)->cdr, Vunread_command_events); | |
663258f2 JB |
6868 | value = XCONS (value)->car; |
6869 | } | |
1c90c381 | 6870 | else if (NILP (value)) |
dcc408a0 | 6871 | value = Qt; |
6569cc8d JB |
6872 | if (used_mouse_menu) |
6873 | *used_mouse_menu = 1; | |
7d6de002 RS |
6874 | return value; |
6875 | } | |
1f5b1641 | 6876 | #endif /* HAVE_MENUS */ |
8150596a RS |
6877 | return Qnil ; |
6878 | } | |
6879 | ||
68e0de82 RS |
6880 | /* Buffer in use so far for the minibuf prompts for menu keymaps. |
6881 | We make this bigger when necessary, and never free it. */ | |
6882 | static char *read_char_minibuf_menu_text; | |
6883 | /* Size of that buffer. */ | |
6884 | static int read_char_minibuf_menu_width; | |
6885 | ||
8150596a | 6886 | static Lisp_Object |
24597608 | 6887 | read_char_minibuf_menu_prompt (commandflag, nmaps, maps) |
8150596a RS |
6888 | int commandflag ; |
6889 | int nmaps; | |
6890 | Lisp_Object *maps; | |
6891 | { | |
6892 | int mapno; | |
6893 | register Lisp_Object name; | |
6894 | int nlength; | |
6895 | int width = FRAME_WIDTH (selected_frame) - 4; | |
8150596a | 6896 | int idx = -1; |
9fdbfdf8 | 6897 | int nobindings = 1; |
8150596a | 6898 | Lisp_Object rest, vector; |
68e0de82 | 6899 | char *menu; |
8150596a RS |
6900 | |
6901 | if (! menu_prompting) | |
6902 | return Qnil; | |
6903 | ||
68e0de82 RS |
6904 | /* Make sure we have a big enough buffer for the menu text. */ |
6905 | if (read_char_minibuf_menu_text == 0) | |
6906 | { | |
6907 | read_char_minibuf_menu_width = width + 4; | |
6908 | read_char_minibuf_menu_text = (char *) xmalloc (width + 4); | |
6909 | } | |
6910 | else if (width + 4 > read_char_minibuf_menu_width) | |
6911 | { | |
6912 | read_char_minibuf_menu_width = width + 4; | |
6913 | read_char_minibuf_menu_text | |
6914 | = (char *) xrealloc (read_char_minibuf_menu_text, width + 4); | |
6915 | } | |
6916 | menu = read_char_minibuf_menu_text; | |
6917 | ||
8150596a RS |
6918 | /* Get the menu name from the first map that has one (a prompt string). */ |
6919 | for (mapno = 0; mapno < nmaps; mapno++) | |
6920 | { | |
6921 | name = map_prompt (maps[mapno]); | |
6922 | if (!NILP (name)) | |
6923 | break; | |
6924 | } | |
6925 | ||
6926 | /* If we don't have any menus, just read a character normally. */ | |
6927 | if (mapno >= nmaps) | |
6928 | return Qnil; | |
284f4730 JB |
6929 | |
6930 | /* Prompt string always starts with map's prompt, and a space. */ | |
6931 | strcpy (menu, XSTRING (name)->data); | |
fc932ac6 | 6932 | nlength = STRING_BYTES (XSTRING (name)); |
7d6de002 | 6933 | menu[nlength++] = ':'; |
284f4730 JB |
6934 | menu[nlength++] = ' '; |
6935 | menu[nlength] = 0; | |
6936 | ||
7d6de002 RS |
6937 | /* Start prompting at start of first map. */ |
6938 | mapno = 0; | |
6939 | rest = maps[mapno]; | |
284f4730 JB |
6940 | |
6941 | /* Present the documented bindings, a line at a time. */ | |
6942 | while (1) | |
6943 | { | |
6944 | int notfirst = 0; | |
6945 | int i = nlength; | |
6946 | Lisp_Object obj; | |
6947 | int ch; | |
8066f1a1 | 6948 | Lisp_Object orig_defn_macro; |
284f4730 | 6949 | |
284f4730 | 6950 | /* Loop over elements of map. */ |
7d6de002 | 6951 | while (i < width) |
284f4730 | 6952 | { |
fd3613d7 | 6953 | Lisp_Object elt; |
284f4730 | 6954 | |
7d6de002 RS |
6955 | /* If reached end of map, start at beginning of next map. */ |
6956 | if (NILP (rest)) | |
6957 | { | |
6958 | mapno++; | |
6959 | /* At end of last map, wrap around to first map if just starting, | |
6960 | or end this line if already have something on it. */ | |
6961 | if (mapno == nmaps) | |
284f4730 | 6962 | { |
8150596a | 6963 | mapno = 0; |
40932d1a | 6964 | if (notfirst || nobindings) break; |
284f4730 | 6965 | } |
7d6de002 | 6966 | rest = maps[mapno]; |
284f4730 | 6967 | } |
7d6de002 RS |
6968 | |
6969 | /* Look at the next element of the map. */ | |
6970 | if (idx >= 0) | |
6971 | elt = XVECTOR (vector)->contents[idx]; | |
284f4730 | 6972 | else |
7d6de002 RS |
6973 | elt = Fcar_safe (rest); |
6974 | ||
8c18cbfb | 6975 | if (idx < 0 && VECTORP (elt)) |
284f4730 | 6976 | { |
7d6de002 RS |
6977 | /* If we found a dense table in the keymap, |
6978 | advanced past it, but start scanning its contents. */ | |
6979 | rest = Fcdr_safe (rest); | |
6980 | vector = elt; | |
6981 | idx = 0; | |
284f4730 | 6982 | } |
7d6de002 RS |
6983 | else |
6984 | { | |
6985 | /* An ordinary element. */ | |
fd3613d7 | 6986 | Lisp_Object event, tem; |
0a2ea221 KH |
6987 | |
6988 | if (idx < 0) | |
6989 | { | |
fd3613d7 RS |
6990 | event = Fcar_safe (elt); /* alist */ |
6991 | elt = Fcdr_safe (elt); | |
0a2ea221 | 6992 | } |
8150596a | 6993 | else |
7d6de002 | 6994 | { |
fd3613d7 | 6995 | XSETINT (event, idx); /* vector */ |
0a2ea221 KH |
6996 | } |
6997 | ||
6998 | /* Ignore the element if it has no prompt string. */ | |
fd3613d7 | 6999 | if (INTEGERP (event) && parse_menu_item (elt, 0, -1)) |
0a2ea221 KH |
7000 | { |
7001 | /* 1 if the char to type matches the string. */ | |
7002 | int char_matches; | |
7003 | Lisp_Object upcased_event, downcased_event; | |
7004 | Lisp_Object desc; | |
fd3613d7 RS |
7005 | Lisp_Object s |
7006 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; | |
0a2ea221 KH |
7007 | |
7008 | upcased_event = Fupcase (event); | |
7009 | downcased_event = Fdowncase (event); | |
7010 | char_matches = (XINT (upcased_event) == XSTRING (s)->data[0] | |
7011 | || XINT (downcased_event) == XSTRING (s)->data[0]); | |
7012 | if (! char_matches) | |
7013 | desc = Fsingle_key_description (event); | |
7014 | ||
fd3613d7 RS |
7015 | tem |
7016 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ]; | |
7017 | if (!NILP (tem)) | |
7018 | /* Insert equivalent keybinding. */ | |
7019 | s = concat2 (s, tem); | |
7020 | ||
7021 | tem | |
7022 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE]; | |
7023 | if (EQ (tem, QCradio) || EQ (tem, QCtoggle)) | |
7024 | { | |
7025 | /* Insert button prefix. */ | |
7026 | Lisp_Object selected | |
7027 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]; | |
7028 | if (EQ (tem, QCradio)) | |
7029 | tem = build_string (NILP (selected) ? "(*) " : "( ) "); | |
7030 | else | |
7031 | tem = build_string (NILP (selected) ? "[X] " : "[ ] "); | |
7032 | s = concat2 (tem, s); | |
7033 | } | |
7034 | ||
7035 | ||
0a2ea221 KH |
7036 | /* If we have room for the prompt string, add it to this line. |
7037 | If this is the first on the line, always add it. */ | |
7038 | if ((XSTRING (s)->size + i + 2 | |
7039 | + (char_matches ? 0 : XSTRING (desc)->size + 3)) | |
7040 | < width | |
7041 | || !notfirst) | |
7042 | { | |
7043 | int thiswidth; | |
7044 | ||
7045 | /* Punctuate between strings. */ | |
7046 | if (notfirst) | |
7047 | { | |
7048 | strcpy (menu + i, ", "); | |
7049 | i += 2; | |
7050 | } | |
7051 | notfirst = 1; | |
7052 | nobindings = 0 ; | |
284f4730 | 7053 | |
0a2ea221 KH |
7054 | /* If the char to type doesn't match the string's |
7055 | first char, explicitly show what char to type. */ | |
7056 | if (! char_matches) | |
7057 | { | |
7058 | /* Add as much of string as fits. */ | |
7059 | thiswidth = XSTRING (desc)->size; | |
7060 | if (thiswidth + i > width) | |
7061 | thiswidth = width - i; | |
7062 | bcopy (XSTRING (desc)->data, menu + i, thiswidth); | |
7063 | i += thiswidth; | |
7064 | strcpy (menu + i, " = "); | |
7065 | i += 3; | |
7066 | } | |
7067 | ||
7068 | /* Add as much of string as fits. */ | |
7069 | thiswidth = XSTRING (s)->size; | |
7070 | if (thiswidth + i > width) | |
7071 | thiswidth = width - i; | |
7072 | bcopy (XSTRING (s)->data, menu + i, thiswidth); | |
7073 | i += thiswidth; | |
7074 | menu[i] = 0; | |
7075 | } | |
7076 | else | |
7d6de002 | 7077 | { |
0a2ea221 KH |
7078 | /* If this element does not fit, end the line now, |
7079 | and save the element for the next line. */ | |
7080 | strcpy (menu + i, "..."); | |
7081 | break; | |
7d6de002 | 7082 | } |
7d6de002 RS |
7083 | } |
7084 | ||
7085 | /* Move past this element. */ | |
8150596a | 7086 | if (idx >= 0 && idx + 1 >= XVECTOR (vector)->size) |
7d6de002 RS |
7087 | /* Handle reaching end of dense table. */ |
7088 | idx = -1; | |
7089 | if (idx >= 0) | |
7090 | idx++; | |
7091 | else | |
7092 | rest = Fcdr_safe (rest); | |
7093 | } | |
284f4730 JB |
7094 | } |
7095 | ||
7096 | /* Prompt with that and read response. */ | |
301738ed RS |
7097 | message2_nolog (menu, strlen (menu), |
7098 | ! NILP (current_buffer->enable_multibyte_characters)); | |
8150596a | 7099 | |
df0f2ba1 | 7100 | /* Make believe its not a keyboard macro in case the help char |
8150596a RS |
7101 | is pressed. Help characters are not recorded because menu prompting |
7102 | is not used on replay. | |
7103 | */ | |
c5fdd383 KH |
7104 | orig_defn_macro = current_kboard->defining_kbd_macro; |
7105 | current_kboard->defining_kbd_macro = Qnil; | |
3cb81011 KH |
7106 | do |
7107 | obj = read_char (commandflag, 0, 0, Qnil, 0); | |
8c18cbfb | 7108 | while (BUFFERP (obj)); |
c5fdd383 | 7109 | current_kboard->defining_kbd_macro = orig_defn_macro; |
284f4730 | 7110 | |
8c18cbfb | 7111 | if (!INTEGERP (obj)) |
284f4730 JB |
7112 | return obj; |
7113 | else | |
7114 | ch = XINT (obj); | |
7115 | ||
f4255cd1 | 7116 | if (! EQ (obj, menu_prompt_more_char) |
8c18cbfb | 7117 | && (!INTEGERP (menu_prompt_more_char) |
f4255cd1 | 7118 | || ! EQ (obj, make_number (Ctl (XINT (menu_prompt_more_char)))))) |
8150596a | 7119 | { |
c5fdd383 | 7120 | if (!NILP (current_kboard->defining_kbd_macro)) |
8066f1a1 | 7121 | store_kbd_macro_char (obj); |
8150596a RS |
7122 | return obj; |
7123 | } | |
7124 | /* Help char - go round again */ | |
284f4730 JB |
7125 | } |
7126 | } | |
284f4730 JB |
7127 | \f |
7128 | /* Reading key sequences. */ | |
7129 | ||
7130 | /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings | |
7131 | in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a | |
7132 | keymap, or nil otherwise. Return the index of the first keymap in | |
7133 | which KEY has any binding, or NMAPS if no map has a binding. | |
7134 | ||
7135 | If KEY is a meta ASCII character, treat it like meta-prefix-char | |
7136 | followed by the corresponding non-meta character. Keymaps in | |
7137 | CURRENT with non-prefix bindings for meta-prefix-char become nil in | |
7138 | NEXT. | |
7139 | ||
88cb0656 JB |
7140 | If KEY has no bindings in any of the CURRENT maps, NEXT is left |
7141 | unmodified. | |
7142 | ||
569871d2 | 7143 | NEXT may be the same array as CURRENT. */ |
284f4730 JB |
7144 | |
7145 | static int | |
4e50f26a | 7146 | follow_key (key, nmaps, current, defs, next) |
284f4730 JB |
7147 | Lisp_Object key; |
7148 | Lisp_Object *current, *defs, *next; | |
7149 | int nmaps; | |
7150 | { | |
7151 | int i, first_binding; | |
569871d2 | 7152 | int did_meta = 0; |
284f4730 JB |
7153 | |
7154 | /* If KEY is a meta ASCII character, treat it like meta-prefix-char | |
569871d2 RS |
7155 | followed by the corresponding non-meta character. |
7156 | Put the results into DEFS, since we are going to alter that anyway. | |
7157 | Do not alter CURRENT or NEXT. */ | |
8c18cbfb | 7158 | if (INTEGERP (key) && (XINT (key) & CHAR_META)) |
284f4730 JB |
7159 | { |
7160 | for (i = 0; i < nmaps; i++) | |
7161 | if (! NILP (current[i])) | |
7162 | { | |
569871d2 RS |
7163 | Lisp_Object def; |
7164 | def = get_keyelt (access_keymap (current[i], | |
c6a67acd | 7165 | meta_prefix_char, 1, 0), 0); |
284f4730 JB |
7166 | |
7167 | /* Note that since we pass the resulting bindings through | |
7168 | get_keymap_1, non-prefix bindings for meta-prefix-char | |
7169 | disappear. */ | |
569871d2 | 7170 | defs[i] = get_keymap_1 (def, 0, 1); |
284f4730 JB |
7171 | } |
7172 | else | |
569871d2 | 7173 | defs[i] = Qnil; |
284f4730 | 7174 | |
569871d2 | 7175 | did_meta = 1; |
18cd2eeb | 7176 | XSETINT (key, XFASTINT (key) & ~CHAR_META); |
284f4730 JB |
7177 | } |
7178 | ||
7179 | first_binding = nmaps; | |
7180 | for (i = nmaps - 1; i >= 0; i--) | |
7181 | { | |
7182 | if (! NILP (current[i])) | |
7183 | { | |
569871d2 RS |
7184 | Lisp_Object map; |
7185 | if (did_meta) | |
7186 | map = defs[i]; | |
7187 | else | |
7188 | map = current[i]; | |
7189 | ||
c6a67acd | 7190 | defs[i] = get_keyelt (access_keymap (map, key, 1, 0), 0); |
284f4730 JB |
7191 | if (! NILP (defs[i])) |
7192 | first_binding = i; | |
7193 | } | |
7194 | else | |
7195 | defs[i] = Qnil; | |
7196 | } | |
7197 | ||
284f4730 | 7198 | /* Given the set of bindings we've found, produce the next set of maps. */ |
0a7f1fc0 JB |
7199 | if (first_binding < nmaps) |
7200 | for (i = 0; i < nmaps; i++) | |
f4255cd1 | 7201 | next[i] = NILP (defs[i]) ? Qnil : get_keymap_1 (defs[i], 0, 1); |
284f4730 JB |
7202 | |
7203 | return first_binding; | |
7204 | } | |
7205 | ||
df0f2ba1 | 7206 | /* Read a sequence of keys that ends with a non prefix character, |
f4255cd1 JB |
7207 | storing it in KEYBUF, a buffer of size BUFSIZE. |
7208 | Prompt with PROMPT. | |
284f4730 | 7209 | Return the length of the key sequence stored. |
dcc408a0 | 7210 | Return -1 if the user rejected a command menu. |
284f4730 | 7211 | |
f4255cd1 JB |
7212 | Echo starting immediately unless `prompt' is 0. |
7213 | ||
7214 | Where a key sequence ends depends on the currently active keymaps. | |
7215 | These include any minor mode keymaps active in the current buffer, | |
7216 | the current buffer's local map, and the global map. | |
7217 | ||
7218 | If a key sequence has no other bindings, we check Vfunction_key_map | |
7219 | to see if some trailing subsequence might be the beginning of a | |
7220 | function key's sequence. If so, we try to read the whole function | |
7221 | key, and substitute its symbolic name into the key sequence. | |
7222 | ||
fbcd35bd JB |
7223 | We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and |
7224 | `double-' events into similar click events, if that would make them | |
7225 | bound. We try to turn `triple-' events first into `double-' events, | |
7226 | then into clicks. | |
f4255cd1 JB |
7227 | |
7228 | If we get a mouse click in a mode line, vertical divider, or other | |
7229 | non-text area, we treat the click as if it were prefixed by the | |
7230 | symbol denoting that area - `mode-line', `vertical-line', or | |
7231 | whatever. | |
7232 | ||
7233 | If the sequence starts with a mouse click, we read the key sequence | |
7234 | with respect to the buffer clicked on, not the current buffer. | |
284f4730 | 7235 | |
f4255cd1 JB |
7236 | If the user switches frames in the midst of a key sequence, we put |
7237 | off the switch-frame event until later; the next call to | |
f571ae0d RS |
7238 | read_char will return it. |
7239 | ||
7240 | If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer | |
7241 | from the selected window's buffer. */ | |
48e416d4 | 7242 | |
284f4730 | 7243 | static int |
ce98e608 | 7244 | read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last, |
f571ae0d | 7245 | can_return_switch_frame, fix_current_buffer) |
284f4730 JB |
7246 | Lisp_Object *keybuf; |
7247 | int bufsize; | |
84d91fda | 7248 | Lisp_Object prompt; |
309b0fc8 | 7249 | int dont_downcase_last; |
ce98e608 | 7250 | int can_return_switch_frame; |
f571ae0d | 7251 | int fix_current_buffer; |
284f4730 | 7252 | { |
f4255cd1 JB |
7253 | int count = specpdl_ptr - specpdl; |
7254 | ||
284f4730 JB |
7255 | /* How many keys there are in the current key sequence. */ |
7256 | int t; | |
7257 | ||
284f4730 JB |
7258 | /* The length of the echo buffer when we started reading, and |
7259 | the length of this_command_keys when we started reading. */ | |
7260 | int echo_start; | |
f4255cd1 | 7261 | int keys_start; |
284f4730 JB |
7262 | |
7263 | /* The number of keymaps we're scanning right now, and the number of | |
7264 | keymaps we have allocated space for. */ | |
7265 | int nmaps; | |
7266 | int nmaps_allocated = 0; | |
7267 | ||
284f4730 JB |
7268 | /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in |
7269 | the current keymaps. */ | |
7270 | Lisp_Object *defs; | |
7271 | ||
f4255cd1 JB |
7272 | /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] |
7273 | in the current keymaps, or nil where it is not a prefix. */ | |
7274 | Lisp_Object *submaps; | |
7275 | ||
e0dff5f6 RS |
7276 | /* The local map to start out with at start of key sequence. */ |
7277 | Lisp_Object orig_local_map; | |
7278 | ||
7279 | /* 1 if we have already considered switching to the local-map property | |
7280 | of the place where a mouse click occurred. */ | |
7281 | int localized_local_map = 0; | |
7282 | ||
f4255cd1 JB |
7283 | /* The index in defs[] of the first keymap that has a binding for |
7284 | this key sequence. In other words, the lowest i such that | |
7285 | defs[i] is non-nil. */ | |
284f4730 JB |
7286 | int first_binding; |
7287 | ||
f4255cd1 | 7288 | /* If t < mock_input, then KEYBUF[t] should be read as the next |
253598e4 JB |
7289 | input key. |
7290 | ||
7291 | We use this to recover after recognizing a function key. Once we | |
7292 | realize that a suffix of the current key sequence is actually a | |
7293 | function key's escape sequence, we replace the suffix with the | |
7294 | function key's binding from Vfunction_key_map. Now keybuf | |
f4255cd1 JB |
7295 | contains a new and different key sequence, so the echo area, |
7296 | this_command_keys, and the submaps and defs arrays are wrong. In | |
7297 | this situation, we set mock_input to t, set t to 0, and jump to | |
7298 | restart_sequence; the loop will read keys from keybuf up until | |
7299 | mock_input, thus rebuilding the state; and then it will resume | |
7300 | reading characters from the keyboard. */ | |
284f4730 JB |
7301 | int mock_input = 0; |
7302 | ||
253598e4 | 7303 | /* If the sequence is unbound in submaps[], then |
f4255cd1 JB |
7304 | keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map, |
7305 | and fkey_map is its binding. | |
253598e4 | 7306 | |
f4255cd1 JB |
7307 | These might be > t, indicating that all function key scanning |
7308 | should hold off until t reaches them. We do this when we've just | |
7309 | recognized a function key, to avoid searching for the function | |
7310 | key's again in Vfunction_key_map. */ | |
284f4730 | 7311 | int fkey_start = 0, fkey_end = 0; |
4efda7dd | 7312 | Lisp_Object fkey_map; |
284f4730 | 7313 | |
a612e298 RS |
7314 | /* Likewise, for key_translation_map. */ |
7315 | int keytran_start = 0, keytran_end = 0; | |
7316 | Lisp_Object keytran_map; | |
7317 | ||
cd21b839 JB |
7318 | /* If we receive a ``switch-frame'' event in the middle of a key sequence, |
7319 | we put it off for later. While we're reading, we keep the event here. */ | |
4efda7dd | 7320 | Lisp_Object delayed_switch_frame; |
cd21b839 | 7321 | |
51763820 BF |
7322 | /* See the comment below... */ |
7323 | #if defined (GOBBLE_FIRST_EVENT) | |
4efda7dd | 7324 | Lisp_Object first_event; |
51763820 | 7325 | #endif |
4efda7dd | 7326 | |
309b0fc8 RS |
7327 | Lisp_Object original_uppercase; |
7328 | int original_uppercase_position = -1; | |
7329 | ||
bc536d84 | 7330 | /* Gets around Microsoft compiler limitations. */ |
309b0fc8 | 7331 | int dummyflag = 0; |
bc536d84 | 7332 | |
3b9189f8 RS |
7333 | struct buffer *starting_buffer; |
7334 | ||
e9bf89a0 RS |
7335 | /* Nonzero if we seem to have got the beginning of a binding |
7336 | in function_key_map. */ | |
7337 | int function_key_possible = 0; | |
00a78037 | 7338 | int key_translation_possible = 0; |
e9bf89a0 | 7339 | |
3fe8e9a2 RS |
7340 | /* Save the status of key translation before each step, |
7341 | so that we can restore this after downcasing. */ | |
7342 | Lisp_Object prev_fkey_map; | |
3fdfceb3 RS |
7343 | int prev_fkey_start; |
7344 | int prev_fkey_end; | |
3fe8e9a2 RS |
7345 | |
7346 | Lisp_Object prev_keytran_map; | |
3fdfceb3 RS |
7347 | int prev_keytran_start; |
7348 | int prev_keytran_end; | |
3fe8e9a2 | 7349 | |
4efda7dd RS |
7350 | int junk; |
7351 | ||
7d18f9ae RS |
7352 | raw_keybuf_count = 0; |
7353 | ||
4efda7dd RS |
7354 | last_nonmenu_event = Qnil; |
7355 | ||
7356 | delayed_switch_frame = Qnil; | |
7357 | fkey_map = Vfunction_key_map; | |
a612e298 | 7358 | keytran_map = Vkey_translation_map; |
f4255cd1 | 7359 | |
a612e298 | 7360 | /* If there is no function-key-map, turn off function key scanning. */ |
f4255cd1 JB |
7361 | if (NILP (Fkeymapp (Vfunction_key_map))) |
7362 | fkey_start = fkey_end = bufsize + 1; | |
7363 | ||
a612e298 RS |
7364 | /* If there is no key-translation-map, turn off scanning. */ |
7365 | if (NILP (Fkeymapp (Vkey_translation_map))) | |
7366 | keytran_start = keytran_end = bufsize + 1; | |
7367 | ||
284f4730 JB |
7368 | if (INTERACTIVE) |
7369 | { | |
84d91fda RS |
7370 | if (!NILP (prompt)) |
7371 | echo_prompt (XSTRING (prompt)->data); | |
a98ea3f9 | 7372 | else if (cursor_in_echo_area && echo_keystrokes) |
284f4730 JB |
7373 | /* This doesn't put in a dash if the echo buffer is empty, so |
7374 | you don't always see a dash hanging out in the minibuffer. */ | |
7375 | echo_dash (); | |
284f4730 JB |
7376 | } |
7377 | ||
f4255cd1 JB |
7378 | /* Record the initial state of the echo area and this_command_keys; |
7379 | we will need to restore them if we replay a key sequence. */ | |
0a7f1fc0 | 7380 | if (INTERACTIVE) |
df0f2ba1 | 7381 | echo_start = echo_length (); |
f4255cd1 | 7382 | keys_start = this_command_key_count; |
6321824f | 7383 | this_single_command_key_start = keys_start; |
0a7f1fc0 | 7384 | |
51763820 BF |
7385 | #if defined (GOBBLE_FIRST_EVENT) |
7386 | /* This doesn't quite work, because some of the things that read_char | |
7387 | does cannot safely be bypassed. It seems too risky to try to make | |
df0f2ba1 | 7388 | this work right. */ |
51763820 | 7389 | |
4efda7dd RS |
7390 | /* Read the first char of the sequence specially, before setting |
7391 | up any keymaps, in case a filter runs and switches buffers on us. */ | |
84d91fda | 7392 | first_event = read_char (NILP (prompt), 0, submaps, last_nonmenu_event, |
4efda7dd | 7393 | &junk); |
51763820 | 7394 | #endif /* GOBBLE_FIRST_EVENT */ |
4efda7dd | 7395 | |
e0dff5f6 RS |
7396 | orig_local_map = get_local_map (PT, current_buffer); |
7397 | ||
7b4aedb9 JB |
7398 | /* We jump here when the key sequence has been thoroughly changed, and |
7399 | we need to rescan it starting from the beginning. When we jump here, | |
7400 | keybuf[0..mock_input] holds the sequence we should reread. */ | |
07d2b8de | 7401 | replay_sequence: |
7b4aedb9 | 7402 | |
3b9189f8 | 7403 | starting_buffer = current_buffer; |
e9bf89a0 | 7404 | function_key_possible = 0; |
00a78037 | 7405 | key_translation_possible = 0; |
3b9189f8 | 7406 | |
f4255cd1 | 7407 | /* Build our list of keymaps. |
07d2b8de JB |
7408 | If we recognize a function key and replace its escape sequence in |
7409 | keybuf with its symbol, or if the sequence starts with a mouse | |
7410 | click and we need to switch buffers, we jump back here to rebuild | |
7411 | the initial keymaps from the current buffer. */ | |
df0f2ba1 | 7412 | { |
284f4730 JB |
7413 | Lisp_Object *maps; |
7414 | ||
217258d5 KH |
7415 | if (!NILP (current_kboard->Voverriding_terminal_local_map) |
7416 | || !NILP (Voverriding_local_map)) | |
284f4730 | 7417 | { |
217258d5 | 7418 | if (3 > nmaps_allocated) |
9dd3131c | 7419 | { |
217258d5 KH |
7420 | submaps = (Lisp_Object *) alloca (3 * sizeof (submaps[0])); |
7421 | defs = (Lisp_Object *) alloca (3 * sizeof (defs[0])); | |
7422 | nmaps_allocated = 3; | |
9dd3131c | 7423 | } |
217258d5 KH |
7424 | nmaps = 0; |
7425 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
7426 | submaps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
7427 | if (!NILP (Voverriding_local_map)) | |
7428 | submaps[nmaps++] = Voverriding_local_map; | |
284f4730 | 7429 | } |
9dd3131c RS |
7430 | else |
7431 | { | |
217258d5 KH |
7432 | nmaps = current_minor_maps (0, &maps); |
7433 | if (nmaps + 2 > nmaps_allocated) | |
9dd3131c | 7434 | { |
217258d5 KH |
7435 | submaps = (Lisp_Object *) alloca ((nmaps+2) * sizeof (submaps[0])); |
7436 | defs = (Lisp_Object *) alloca ((nmaps+2) * sizeof (defs[0])); | |
7437 | nmaps_allocated = nmaps + 2; | |
9dd3131c | 7438 | } |
217258d5 | 7439 | bcopy (maps, submaps, nmaps * sizeof (submaps[0])); |
497ba7a1 | 7440 | #ifdef USE_TEXT_PROPERTIES |
217258d5 | 7441 | submaps[nmaps++] = orig_local_map; |
497ba7a1 | 7442 | #else |
217258d5 | 7443 | submaps[nmaps++] = current_buffer->keymap; |
497ba7a1 | 7444 | #endif |
9dd3131c | 7445 | } |
217258d5 | 7446 | submaps[nmaps++] = current_global_map; |
284f4730 JB |
7447 | } |
7448 | ||
7449 | /* Find an accurate initial value for first_binding. */ | |
7450 | for (first_binding = 0; first_binding < nmaps; first_binding++) | |
253598e4 | 7451 | if (! NILP (submaps[first_binding])) |
284f4730 JB |
7452 | break; |
7453 | ||
3b9189f8 | 7454 | /* Start from the beginning in keybuf. */ |
f4255cd1 JB |
7455 | t = 0; |
7456 | ||
7457 | /* These are no-ops the first time through, but if we restart, they | |
7458 | revert the echo area and this_command_keys to their original state. */ | |
7459 | this_command_key_count = keys_start; | |
df0f2ba1 | 7460 | if (INTERACTIVE && t < mock_input) |
f4255cd1 JB |
7461 | echo_truncate (echo_start); |
7462 | ||
cca310da JB |
7463 | /* If the best binding for the current key sequence is a keymap, or |
7464 | we may be looking at a function key's escape sequence, keep on | |
7465 | reading. */ | |
253598e4 | 7466 | while ((first_binding < nmaps && ! NILP (submaps[first_binding])) |
cca310da JB |
7467 | || (first_binding >= nmaps |
7468 | && fkey_start < t | |
7469 | /* mock input is never part of a function key's sequence. */ | |
a612e298 | 7470 | && mock_input <= fkey_start) |
0d882d52 KH |
7471 | || (first_binding >= nmaps |
7472 | && keytran_start < t && key_translation_possible) | |
e9bf89a0 RS |
7473 | /* Don't return in the middle of a possible function key sequence, |
7474 | if the only bindings we found were via case conversion. | |
7475 | Thus, if ESC O a has a function-key-map translation | |
7476 | and ESC o has a binding, don't return after ESC O, | |
7477 | so that we can translate ESC O plus the next character. */ | |
4e50f26a | 7478 | ) |
284f4730 JB |
7479 | { |
7480 | Lisp_Object key; | |
7d6de002 | 7481 | int used_mouse_menu = 0; |
284f4730 | 7482 | |
7b4aedb9 JB |
7483 | /* Where the last real key started. If we need to throw away a |
7484 | key that has expanded into more than one element of keybuf | |
7485 | (say, a mouse click on the mode line which is being treated | |
7486 | as [mode-line (mouse-...)], then we backtrack to this point | |
7487 | of keybuf. */ | |
7488 | int last_real_key_start; | |
7489 | ||
0a7f1fc0 JB |
7490 | /* These variables are analogous to echo_start and keys_start; |
7491 | while those allow us to restart the entire key sequence, | |
7492 | echo_local_start and keys_local_start allow us to throw away | |
7493 | just one key. */ | |
f4255cd1 JB |
7494 | int echo_local_start, keys_local_start, local_first_binding; |
7495 | ||
284f4730 | 7496 | if (t >= bufsize) |
3fe8e9a2 | 7497 | error ("Key sequence too long"); |
284f4730 | 7498 | |
f4255cd1 JB |
7499 | if (INTERACTIVE) |
7500 | echo_local_start = echo_length (); | |
7501 | keys_local_start = this_command_key_count; | |
7502 | local_first_binding = first_binding; | |
df0f2ba1 | 7503 | |
f4255cd1 | 7504 | replay_key: |
0a7f1fc0 | 7505 | /* These are no-ops, unless we throw away a keystroke below and |
f4255cd1 JB |
7506 | jumped back up to replay_key; in that case, these restore the |
7507 | variables to their original state, allowing us to replay the | |
0a7f1fc0 | 7508 | loop. */ |
40932d1a | 7509 | if (INTERACTIVE && t < mock_input) |
f4255cd1 | 7510 | echo_truncate (echo_local_start); |
0a7f1fc0 JB |
7511 | this_command_key_count = keys_local_start; |
7512 | first_binding = local_first_binding; | |
7513 | ||
7e85b935 RS |
7514 | /* By default, assume each event is "real". */ |
7515 | last_real_key_start = t; | |
7516 | ||
f4255cd1 | 7517 | /* Does mock_input indicate that we are re-reading a key sequence? */ |
284f4730 JB |
7518 | if (t < mock_input) |
7519 | { | |
7520 | key = keybuf[t]; | |
7521 | add_command_key (key); | |
a98ea3f9 RS |
7522 | if (echo_keystrokes) |
7523 | echo_char (key); | |
284f4730 | 7524 | } |
253598e4 JB |
7525 | |
7526 | /* If not, we should actually read a character. */ | |
284f4730 JB |
7527 | else |
7528 | { | |
a6d53864 RS |
7529 | struct buffer *buf = current_buffer; |
7530 | ||
beecf6a1 | 7531 | { |
c5fdd383 KH |
7532 | #ifdef MULTI_KBOARD |
7533 | KBOARD *interrupted_kboard = current_kboard; | |
df0f2ba1 | 7534 | struct frame *interrupted_frame = selected_frame; |
c5fdd383 | 7535 | if (setjmp (wrong_kboard_jmpbuf)) |
beecf6a1 | 7536 | { |
5798cf15 KH |
7537 | if (!NILP (delayed_switch_frame)) |
7538 | { | |
c5fdd383 | 7539 | interrupted_kboard->kbd_queue |
5798cf15 | 7540 | = Fcons (delayed_switch_frame, |
c5fdd383 | 7541 | interrupted_kboard->kbd_queue); |
5798cf15 KH |
7542 | delayed_switch_frame = Qnil; |
7543 | } | |
beecf6a1 | 7544 | while (t > 0) |
c5fdd383 KH |
7545 | interrupted_kboard->kbd_queue |
7546 | = Fcons (keybuf[--t], interrupted_kboard->kbd_queue); | |
5798cf15 KH |
7547 | |
7548 | /* If the side queue is non-empty, ensure it begins with a | |
7549 | switch-frame, so we'll replay it in the right context. */ | |
c5fdd383 KH |
7550 | if (CONSP (interrupted_kboard->kbd_queue) |
7551 | && (key = XCONS (interrupted_kboard->kbd_queue)->car, | |
5798cf15 KH |
7552 | !(EVENT_HAS_PARAMETERS (key) |
7553 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key)), | |
7554 | Qswitch_frame)))) | |
df0f2ba1 KH |
7555 | { |
7556 | Lisp_Object frame; | |
7557 | XSETFRAME (frame, interrupted_frame); | |
c5fdd383 | 7558 | interrupted_kboard->kbd_queue |
df0f2ba1 | 7559 | = Fcons (make_lispy_switch_frame (frame), |
c5fdd383 | 7560 | interrupted_kboard->kbd_queue); |
df0f2ba1 | 7561 | } |
beecf6a1 | 7562 | mock_input = 0; |
a6e0153c | 7563 | orig_local_map = get_local_map (PT, current_buffer); |
beecf6a1 KH |
7564 | goto replay_sequence; |
7565 | } | |
bded54dd | 7566 | #endif |
beecf6a1 KH |
7567 | key = read_char (NILP (prompt), nmaps, submaps, last_nonmenu_event, |
7568 | &used_mouse_menu); | |
7569 | } | |
284f4730 | 7570 | |
dcc408a0 RS |
7571 | /* read_char returns t when it shows a menu and the user rejects it. |
7572 | Just return -1. */ | |
7573 | if (EQ (key, Qt)) | |
7d18f9ae RS |
7574 | { |
7575 | unbind_to (count, Qnil); | |
7576 | return -1; | |
7577 | } | |
dcc408a0 | 7578 | |
f4255cd1 | 7579 | /* read_char returns -1 at the end of a macro. |
284f4730 JB |
7580 | Emacs 18 handles this by returning immediately with a |
7581 | zero, so that's what we'll do. */ | |
8c18cbfb | 7582 | if (INTEGERP (key) && XINT (key) == -1) |
cd21b839 | 7583 | { |
f4255cd1 | 7584 | t = 0; |
bc536d84 RS |
7585 | /* The Microsoft C compiler can't handle the goto that |
7586 | would go here. */ | |
309b0fc8 | 7587 | dummyflag = 1; |
bc536d84 | 7588 | break; |
cd21b839 | 7589 | } |
df0f2ba1 | 7590 | |
3cb81011 KH |
7591 | /* If the current buffer has been changed from under us, the |
7592 | keymap may have changed, so replay the sequence. */ | |
8c18cbfb | 7593 | if (BUFFERP (key)) |
3cb81011 KH |
7594 | { |
7595 | mock_input = t; | |
f571ae0d RS |
7596 | /* Reset the current buffer from the selected window |
7597 | in case something changed the former and not the latter. | |
7598 | This is to be more consistent with the behavior | |
7599 | of the command_loop_1. */ | |
7600 | if (fix_current_buffer) | |
a94a4335 KH |
7601 | { |
7602 | if (! FRAME_LIVE_P (selected_frame)) | |
7603 | Fkill_emacs (Qnil); | |
7604 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
7605 | Fset_buffer (XWINDOW (selected_window)->buffer); | |
7606 | } | |
f571ae0d | 7607 | |
a6e0153c | 7608 | orig_local_map = get_local_map (PT, current_buffer); |
3cb81011 KH |
7609 | goto replay_sequence; |
7610 | } | |
7611 | ||
3b9189f8 RS |
7612 | /* If we have a quit that was typed in another frame, and |
7613 | quit_throw_to_read_char switched buffers, | |
7614 | replay to get the right keymap. */ | |
9343ab07 | 7615 | if (XINT (key) == quit_char && current_buffer != starting_buffer) |
3b9189f8 | 7616 | { |
7d18f9ae RS |
7617 | GROW_RAW_KEYBUF; |
7618 | XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key; | |
3b9189f8 RS |
7619 | keybuf[t++] = key; |
7620 | mock_input = t; | |
7621 | Vquit_flag = Qnil; | |
a6e0153c | 7622 | orig_local_map = get_local_map (PT, current_buffer); |
3b9189f8 RS |
7623 | goto replay_sequence; |
7624 | } | |
3cb81011 | 7625 | |
284f4730 | 7626 | Vquit_flag = Qnil; |
7d18f9ae RS |
7627 | |
7628 | if (EVENT_HAS_PARAMETERS (key) | |
7629 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key)), Qswitch_frame)) | |
7630 | { | |
7631 | /* If we're at the beginning of a key sequence, and the caller | |
7632 | says it's okay, go ahead and return this event. If we're | |
7633 | in the midst of a key sequence, delay it until the end. */ | |
7634 | if (t > 0 || !can_return_switch_frame) | |
7635 | { | |
7636 | delayed_switch_frame = key; | |
7637 | goto replay_key; | |
7638 | } | |
7639 | } | |
7640 | ||
7641 | GROW_RAW_KEYBUF; | |
7642 | XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key; | |
7e85b935 | 7643 | } |
284f4730 | 7644 | |
df0f2ba1 | 7645 | /* Clicks in non-text areas get prefixed by the symbol |
7e85b935 RS |
7646 | in their CHAR-ADDRESS field. For example, a click on |
7647 | the mode line is prefixed by the symbol `mode-line'. | |
7648 | ||
7649 | Furthermore, key sequences beginning with mouse clicks | |
7650 | are read using the keymaps of the buffer clicked on, not | |
7651 | the current buffer. So we may have to switch the buffer | |
7652 | here. | |
7653 | ||
7654 | When we turn one event into two events, we must make sure | |
7655 | that neither of the two looks like the original--so that, | |
7656 | if we replay the events, they won't be expanded again. | |
7657 | If not for this, such reexpansion could happen either here | |
7658 | or when user programs play with this-command-keys. */ | |
7659 | if (EVENT_HAS_PARAMETERS (key)) | |
7660 | { | |
9b8eb840 | 7661 | Lisp_Object kind; |
cca310da | 7662 | |
9b8eb840 | 7663 | kind = EVENT_HEAD_KIND (EVENT_HEAD (key)); |
7e85b935 | 7664 | if (EQ (kind, Qmouse_click)) |
0a7f1fc0 | 7665 | { |
9b8eb840 | 7666 | Lisp_Object window, posn; |
f4255cd1 | 7667 | |
9b8eb840 KH |
7668 | window = POSN_WINDOW (EVENT_START (key)); |
7669 | posn = POSN_BUFFER_POSN (EVENT_START (key)); | |
7ee32cda | 7670 | |
8c18cbfb | 7671 | if (CONSP (posn)) |
0a7f1fc0 | 7672 | { |
7e85b935 RS |
7673 | /* We're looking at the second event of a |
7674 | sequence which we expanded before. Set | |
7675 | last_real_key_start appropriately. */ | |
7676 | if (t > 0) | |
7677 | last_real_key_start = t - 1; | |
cd21b839 | 7678 | } |
7e85b935 RS |
7679 | |
7680 | /* Key sequences beginning with mouse clicks are | |
7681 | read using the keymaps in the buffer clicked on, | |
7682 | not the current buffer. If we're at the | |
7683 | beginning of a key sequence, switch buffers. */ | |
7684 | if (last_real_key_start == 0 | |
8c18cbfb KH |
7685 | && WINDOWP (window) |
7686 | && BUFFERP (XWINDOW (window)->buffer) | |
7e85b935 | 7687 | && XBUFFER (XWINDOW (window)->buffer) != current_buffer) |
cd21b839 | 7688 | { |
7d18f9ae | 7689 | XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key; |
7e85b935 RS |
7690 | keybuf[t] = key; |
7691 | mock_input = t + 1; | |
7692 | ||
7693 | /* Arrange to go back to the original buffer once we're | |
7694 | done reading the key sequence. Note that we can't | |
7695 | use save_excursion_{save,restore} here, because they | |
7696 | save point as well as the current buffer; we don't | |
7697 | want to save point, because redisplay may change it, | |
7698 | to accommodate a Fset_window_start or something. We | |
7699 | don't want to do this at the top of the function, | |
7700 | because we may get input from a subprocess which | |
7701 | wants to change the selected window and stuff (say, | |
7702 | emacsclient). */ | |
7703 | record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
7704 | ||
a94a4335 KH |
7705 | if (! FRAME_LIVE_P (selected_frame)) |
7706 | Fkill_emacs (Qnil); | |
7e85b935 | 7707 | set_buffer_internal (XBUFFER (XWINDOW (window)->buffer)); |
e0dff5f6 | 7708 | orig_local_map = get_local_map (PT, current_buffer); |
7e85b935 | 7709 | goto replay_sequence; |
0a7f1fc0 | 7710 | } |
7ee32cda | 7711 | |
e0dff5f6 RS |
7712 | /* For a mouse click, get the local text-property keymap |
7713 | of the place clicked on, rather than point. */ | |
7ee32cda GM |
7714 | if (last_real_key_start == 0 |
7715 | && CONSP (XCONS (key)->cdr) | |
e0dff5f6 | 7716 | && ! localized_local_map) |
5ec75a55 | 7717 | { |
e0dff5f6 RS |
7718 | Lisp_Object map_here, start, pos; |
7719 | ||
7720 | localized_local_map = 1; | |
7721 | start = EVENT_START (key); | |
7ee32cda | 7722 | |
e0dff5f6 RS |
7723 | if (CONSP (start) && CONSP (XCONS (start)->cdr)) |
7724 | { | |
7725 | pos = POSN_BUFFER_POSN (start); | |
b78ce8fb RS |
7726 | if (INTEGERP (pos) |
7727 | && XINT (pos) >= BEG && XINT (pos) <= Z) | |
e0dff5f6 RS |
7728 | { |
7729 | map_here = get_local_map (XINT (pos), current_buffer); | |
7730 | if (!EQ (map_here, orig_local_map)) | |
7731 | { | |
7732 | orig_local_map = map_here; | |
7733 | keybuf[t] = key; | |
7734 | mock_input = t + 1; | |
5ec75a55 | 7735 | |
e0dff5f6 RS |
7736 | goto replay_sequence; |
7737 | } | |
7738 | } | |
7739 | } | |
7740 | } | |
7741 | ||
7742 | /* Expand mode-line and scroll-bar events into two events: | |
7743 | use posn as a fake prefix key. */ | |
7744 | if (SYMBOLP (posn)) | |
7745 | { | |
7e85b935 | 7746 | if (t + 1 >= bufsize) |
3fe8e9a2 | 7747 | error ("Key sequence too long"); |
7e85b935 RS |
7748 | keybuf[t] = posn; |
7749 | keybuf[t+1] = key; | |
7750 | mock_input = t + 2; | |
7ee32cda | 7751 | |
7e85b935 RS |
7752 | /* Zap the position in key, so we know that we've |
7753 | expanded it, and don't try to do so again. */ | |
7754 | POSN_BUFFER_POSN (EVENT_START (key)) | |
7755 | = Fcons (posn, Qnil); | |
7ee32cda GM |
7756 | |
7757 | /* If on a mode line string with a local keymap, | |
7758 | reconsider the key sequence with that keymap. */ | |
7759 | if (CONSP (POSN_STRING (EVENT_START (key)))) | |
7760 | { | |
7761 | Lisp_Object string, pos, map; | |
7762 | ||
7763 | string = POSN_STRING (EVENT_START (key)); | |
7764 | pos = XCDR (string); | |
7765 | string = XCAR (string); | |
7766 | ||
7767 | if (pos >= 0 | |
7768 | && pos < XSTRING (string)->size | |
7769 | && (map = Fget_text_property (pos, Qlocal_map, | |
7770 | string), | |
7771 | !NILP (map))) | |
7772 | { | |
7773 | orig_local_map = map; | |
7774 | goto replay_sequence; | |
7775 | } | |
7776 | } | |
7777 | ||
7e85b935 | 7778 | goto replay_key; |
5ec75a55 | 7779 | } |
0a7f1fc0 | 7780 | } |
7a80a6f6 RS |
7781 | else if (CONSP (XCONS (key)->cdr) |
7782 | && CONSP (EVENT_START (key)) | |
7783 | && CONSP (XCONS (EVENT_START (key))->cdr)) | |
7e85b935 | 7784 | { |
9b8eb840 | 7785 | Lisp_Object posn; |
7e85b935 | 7786 | |
9b8eb840 | 7787 | posn = POSN_BUFFER_POSN (EVENT_START (key)); |
7e85b935 RS |
7788 | /* Handle menu-bar events: |
7789 | insert the dummy prefix event `menu-bar'. */ | |
9ea173e8 | 7790 | if (EQ (posn, Qmenu_bar) || EQ (posn, Qtool_bar)) |
7e85b935 RS |
7791 | { |
7792 | if (t + 1 >= bufsize) | |
3fe8e9a2 | 7793 | error ("Key sequence too long"); |
7e85b935 RS |
7794 | keybuf[t] = posn; |
7795 | keybuf[t+1] = key; | |
7796 | ||
7797 | /* Zap the position in key, so we know that we've | |
7798 | expanded it, and don't try to do so again. */ | |
7799 | POSN_BUFFER_POSN (EVENT_START (key)) | |
7800 | = Fcons (posn, Qnil); | |
7801 | ||
7802 | mock_input = t + 2; | |
7803 | goto replay_sequence; | |
7804 | } | |
8c18cbfb | 7805 | else if (CONSP (posn)) |
7e85b935 RS |
7806 | { |
7807 | /* We're looking at the second event of a | |
7808 | sequence which we expanded before. Set | |
7809 | last_real_key_start appropriately. */ | |
7810 | if (last_real_key_start == t && t > 0) | |
7811 | last_real_key_start = t - 1; | |
7812 | } | |
a6d53864 | 7813 | } |
284f4730 | 7814 | } |
f4255cd1 JB |
7815 | |
7816 | /* We have finally decided that KEY is something we might want | |
7817 | to look up. */ | |
284f4730 JB |
7818 | first_binding = (follow_key (key, |
7819 | nmaps - first_binding, | |
253598e4 | 7820 | submaps + first_binding, |
284f4730 | 7821 | defs + first_binding, |
4e50f26a | 7822 | submaps + first_binding) |
284f4730 | 7823 | + first_binding); |
0a7f1fc0 | 7824 | |
f4255cd1 | 7825 | /* If KEY wasn't bound, we'll try some fallbacks. */ |
0a7f1fc0 JB |
7826 | if (first_binding >= nmaps) |
7827 | { | |
9b8eb840 | 7828 | Lisp_Object head; |
0a7f1fc0 | 7829 | |
9b8eb840 | 7830 | head = EVENT_HEAD (key); |
24736fbc | 7831 | if (help_char_p (head) && t > 0) |
7e85b935 RS |
7832 | { |
7833 | read_key_sequence_cmd = Vprefix_help_command; | |
7834 | keybuf[t++] = key; | |
7835 | last_nonmenu_event = key; | |
bc536d84 RS |
7836 | /* The Microsoft C compiler can't handle the goto that |
7837 | would go here. */ | |
309b0fc8 | 7838 | dummyflag = 1; |
0d882d52 | 7839 | break; |
7e85b935 RS |
7840 | } |
7841 | ||
8c18cbfb | 7842 | if (SYMBOLP (head)) |
0a7f1fc0 | 7843 | { |
9b8eb840 KH |
7844 | Lisp_Object breakdown; |
7845 | int modifiers; | |
0a7f1fc0 | 7846 | |
9b8eb840 KH |
7847 | breakdown = parse_modifiers (head); |
7848 | modifiers = XINT (XCONS (XCONS (breakdown)->cdr)->car); | |
559f9d04 RS |
7849 | /* Attempt to reduce an unbound mouse event to a simpler |
7850 | event that is bound: | |
7851 | Drags reduce to clicks. | |
7852 | Double-clicks reduce to clicks. | |
7853 | Triple-clicks reduce to double-clicks, then to clicks. | |
7854 | Down-clicks are eliminated. | |
7855 | Double-downs reduce to downs, then are eliminated. | |
7856 | Triple-downs reduce to double-downs, then to downs, | |
7857 | then are eliminated. */ | |
7858 | if (modifiers & (down_modifier | drag_modifier | |
7859 | | double_modifier | triple_modifier)) | |
0a7f1fc0 | 7860 | { |
559f9d04 RS |
7861 | while (modifiers & (down_modifier | drag_modifier |
7862 | | double_modifier | triple_modifier)) | |
fbcd35bd JB |
7863 | { |
7864 | Lisp_Object new_head, new_click; | |
7865 | if (modifiers & triple_modifier) | |
7866 | modifiers ^= (double_modifier | triple_modifier); | |
bc536d84 RS |
7867 | else if (modifiers & double_modifier) |
7868 | modifiers &= ~double_modifier; | |
7869 | else if (modifiers & drag_modifier) | |
7870 | modifiers &= ~drag_modifier; | |
559f9d04 RS |
7871 | else |
7872 | { | |
7873 | /* Dispose of this `down' event by simply jumping | |
7874 | back to replay_key, to get another event. | |
7875 | ||
7876 | Note that if this event came from mock input, | |
7877 | then just jumping back to replay_key will just | |
7878 | hand it to us again. So we have to wipe out any | |
7879 | mock input. | |
7880 | ||
7881 | We could delete keybuf[t] and shift everything | |
7882 | after that to the left by one spot, but we'd also | |
7883 | have to fix up any variable that points into | |
7884 | keybuf, and shifting isn't really necessary | |
7885 | anyway. | |
7886 | ||
7887 | Adding prefixes for non-textual mouse clicks | |
7888 | creates two characters of mock input, and both | |
7889 | must be thrown away. If we're only looking at | |
7890 | the prefix now, we can just jump back to | |
7891 | replay_key. On the other hand, if we've already | |
7892 | processed the prefix, and now the actual click | |
7893 | itself is giving us trouble, then we've lost the | |
7894 | state of the keymaps we want to backtrack to, and | |
7895 | we need to replay the whole sequence to rebuild | |
7896 | it. | |
7897 | ||
7898 | Beyond that, only function key expansion could | |
7899 | create more than two keys, but that should never | |
7900 | generate mouse events, so it's okay to zero | |
7901 | mock_input in that case too. | |
7902 | ||
7903 | Isn't this just the most wonderful code ever? */ | |
7904 | if (t == last_real_key_start) | |
7905 | { | |
7906 | mock_input = 0; | |
7907 | goto replay_key; | |
7908 | } | |
7909 | else | |
7910 | { | |
7911 | mock_input = last_real_key_start; | |
7912 | goto replay_sequence; | |
7913 | } | |
7914 | } | |
7915 | ||
27203ead RS |
7916 | new_head |
7917 | = apply_modifiers (modifiers, XCONS (breakdown)->car); | |
7918 | new_click | |
7919 | = Fcons (new_head, Fcons (EVENT_START (key), Qnil)); | |
fbcd35bd JB |
7920 | |
7921 | /* Look for a binding for this new key. follow_key | |
7922 | promises that it didn't munge submaps the | |
7923 | last time we called it, since key was unbound. */ | |
27203ead RS |
7924 | first_binding |
7925 | = (follow_key (new_click, | |
7926 | nmaps - local_first_binding, | |
7927 | submaps + local_first_binding, | |
7928 | defs + local_first_binding, | |
4e50f26a | 7929 | submaps + local_first_binding) |
27203ead | 7930 | + local_first_binding); |
fbcd35bd JB |
7931 | |
7932 | /* If that click is bound, go for it. */ | |
7933 | if (first_binding < nmaps) | |
7934 | { | |
7935 | key = new_click; | |
7936 | break; | |
7937 | } | |
7938 | /* Otherwise, we'll leave key set to the drag event. */ | |
7939 | } | |
0a7f1fc0 JB |
7940 | } |
7941 | } | |
7942 | } | |
7943 | ||
284f4730 | 7944 | keybuf[t++] = key; |
7d6de002 RS |
7945 | /* Normally, last_nonmenu_event gets the previous key we read. |
7946 | But when a mouse popup menu is being used, | |
7947 | we don't update last_nonmenu_event; it continues to hold the mouse | |
7948 | event that preceded the first level of menu. */ | |
7949 | if (!used_mouse_menu) | |
7950 | last_nonmenu_event = key; | |
284f4730 | 7951 | |
6321824f RS |
7952 | /* Record what part of this_command_keys is the current key sequence. */ |
7953 | this_single_command_key_start = this_command_key_count - t; | |
7954 | ||
3fe8e9a2 RS |
7955 | prev_fkey_map = fkey_map; |
7956 | prev_fkey_start = fkey_start; | |
7957 | prev_fkey_end = fkey_end; | |
7958 | ||
7959 | prev_keytran_map = keytran_map; | |
7960 | prev_keytran_start = keytran_start; | |
7961 | prev_keytran_end = keytran_end; | |
7962 | ||
284f4730 | 7963 | /* If the sequence is unbound, see if we can hang a function key |
253598e4 JB |
7964 | off the end of it. We only want to scan real keyboard input |
7965 | for function key sequences, so if mock_input says that we're | |
f4255cd1 | 7966 | re-reading old events, don't examine it. */ |
4e50f26a | 7967 | if (first_binding >= nmaps |
253598e4 | 7968 | && t >= mock_input) |
284f4730 JB |
7969 | { |
7970 | Lisp_Object fkey_next; | |
7971 | ||
e9bf89a0 RS |
7972 | /* Continue scan from fkey_end until we find a bound suffix. |
7973 | If we fail, increment fkey_start | |
7974 | and start fkey_end from there. */ | |
284f4730 JB |
7975 | while (fkey_end < t) |
7976 | { | |
f4255cd1 JB |
7977 | Lisp_Object key; |
7978 | ||
7979 | key = keybuf[fkey_end++]; | |
067ffa38 JB |
7980 | /* Look up meta-characters by prefixing them |
7981 | with meta_prefix_char. I hate this. */ | |
8c18cbfb | 7982 | if (INTEGERP (key) && XINT (key) & meta_modifier) |
f4255cd1 | 7983 | { |
e74fbc70 RS |
7984 | fkey_next |
7985 | = get_keymap_1 | |
f4255cd1 | 7986 | (get_keyelt |
c6a67acd | 7987 | (access_keymap (fkey_map, meta_prefix_char, 1, 0), 0), |
f4255cd1 | 7988 | 0, 1); |
bb9e9bed | 7989 | XSETFASTINT (key, XFASTINT (key) & ~meta_modifier); |
f4255cd1 | 7990 | } |
067ffa38 JB |
7991 | else |
7992 | fkey_next = fkey_map; | |
7993 | ||
e74fbc70 | 7994 | fkey_next |
c700c260 RS |
7995 | = get_keyelt (access_keymap (fkey_next, key, 1, 0), 1); |
7996 | ||
7997 | /* Handle symbol with autoload definition. */ | |
0afc861b RS |
7998 | if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) |
7999 | && CONSP (XSYMBOL (fkey_next)->function) | |
8000 | && EQ (XCONS (XSYMBOL (fkey_next)->function)->car, Qautoload)) | |
8001 | do_autoload (XSYMBOL (fkey_next)->function, | |
8002 | fkey_next); | |
c700c260 RS |
8003 | |
8004 | /* Handle a symbol whose function definition is a keymap | |
8005 | or an array. */ | |
0afc861b RS |
8006 | if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) |
8007 | && (!NILP (Farrayp (XSYMBOL (fkey_next)->function)) | |
8008 | || !NILP (Fkeymapp (XSYMBOL (fkey_next)->function)))) | |
8009 | fkey_next = XSYMBOL (fkey_next)->function; | |
067ffa38 | 8010 | |
7a80a6f6 RS |
8011 | #if 0 /* I didn't turn this on, because it might cause trouble |
8012 | for the mapping of return into C-m and tab into C-i. */ | |
8013 | /* Optionally don't map function keys into other things. | |
8014 | This enables the user to redefine kp- keys easily. */ | |
8015 | if (SYMBOLP (key) && !NILP (Vinhibit_function_key_mapping)) | |
8016 | fkey_next = Qnil; | |
8017 | #endif | |
8018 | ||
1abe6abe RS |
8019 | /* If the function key map gives a function, not an |
8020 | array, then call the function with no args and use | |
8021 | its value instead. */ | |
8022 | if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) | |
8023 | && fkey_end == t) | |
8024 | { | |
8025 | struct gcpro gcpro1, gcpro2, gcpro3; | |
8026 | Lisp_Object tem; | |
8027 | tem = fkey_next; | |
8028 | ||
8029 | GCPRO3 (fkey_map, keytran_map, delayed_switch_frame); | |
84d91fda | 8030 | fkey_next = call1 (fkey_next, prompt); |
1abe6abe RS |
8031 | UNGCPRO; |
8032 | /* If the function returned something invalid, | |
8033 | barf--don't ignore it. | |
df0f2ba1 | 8034 | (To ignore it safely, we would need to gcpro a bunch of |
1abe6abe RS |
8035 | other variables.) */ |
8036 | if (! (VECTORP (fkey_next) || STRINGP (fkey_next))) | |
6321824f | 8037 | error ("Function in key-translation-map returns invalid key sequence"); |
1abe6abe RS |
8038 | } |
8039 | ||
e9bf89a0 RS |
8040 | function_key_possible = ! NILP (fkey_next); |
8041 | ||
85bc5181 | 8042 | /* If keybuf[fkey_start..fkey_end] is bound in the |
a764a753 | 8043 | function key map and it's a suffix of the current |
85bc5181 | 8044 | sequence (i.e. fkey_end == t), replace it with |
a764a753 | 8045 | the binding and restart with fkey_start at the end. */ |
f5ea6163 | 8046 | if ((VECTORP (fkey_next) || STRINGP (fkey_next)) |
284f4730 JB |
8047 | && fkey_end == t) |
8048 | { | |
2e864a76 | 8049 | int len = XFASTINT (Flength (fkey_next)); |
f5ea6163 JB |
8050 | |
8051 | t = fkey_start + len; | |
284f4730 | 8052 | if (t >= bufsize) |
3fe8e9a2 | 8053 | error ("Key sequence too long"); |
284f4730 | 8054 | |
f5ea6163 JB |
8055 | if (VECTORP (fkey_next)) |
8056 | bcopy (XVECTOR (fkey_next)->contents, | |
8057 | keybuf + fkey_start, | |
8058 | (t - fkey_start) * sizeof (keybuf[0])); | |
8059 | else if (STRINGP (fkey_next)) | |
8060 | { | |
8061 | int i; | |
8062 | ||
8063 | for (i = 0; i < len; i++) | |
bb9e9bed KH |
8064 | XSETFASTINT (keybuf[fkey_start + i], |
8065 | XSTRING (fkey_next)->data[i]); | |
f5ea6163 | 8066 | } |
df0f2ba1 | 8067 | |
284f4730 JB |
8068 | mock_input = t; |
8069 | fkey_start = fkey_end = t; | |
32e6d806 | 8070 | fkey_map = Vfunction_key_map; |
284f4730 | 8071 | |
3bd0dffb KH |
8072 | /* Do pass the results through key-translation-map. |
8073 | But don't retranslate what key-translation-map | |
8074 | has already translated. */ | |
8075 | keytran_end = keytran_start; | |
00a78037 RS |
8076 | keytran_map = Vkey_translation_map; |
8077 | ||
f4255cd1 | 8078 | goto replay_sequence; |
284f4730 | 8079 | } |
df0f2ba1 | 8080 | |
f4255cd1 | 8081 | fkey_map = get_keymap_1 (fkey_next, 0, 1); |
284f4730 | 8082 | |
df0f2ba1 | 8083 | /* If we no longer have a bound suffix, try a new positions for |
a764a753 | 8084 | fkey_start. */ |
284f4730 JB |
8085 | if (NILP (fkey_map)) |
8086 | { | |
8087 | fkey_end = ++fkey_start; | |
8088 | fkey_map = Vfunction_key_map; | |
e9bf89a0 | 8089 | function_key_possible = 0; |
284f4730 JB |
8090 | } |
8091 | } | |
8092 | } | |
a612e298 RS |
8093 | |
8094 | /* Look for this sequence in key-translation-map. */ | |
8095 | { | |
8096 | Lisp_Object keytran_next; | |
8097 | ||
8098 | /* Scan from keytran_end until we find a bound suffix. */ | |
8099 | while (keytran_end < t) | |
8100 | { | |
8101 | Lisp_Object key; | |
8102 | ||
8103 | key = keybuf[keytran_end++]; | |
8104 | /* Look up meta-characters by prefixing them | |
8105 | with meta_prefix_char. I hate this. */ | |
8c18cbfb | 8106 | if (INTEGERP (key) && XINT (key) & meta_modifier) |
a612e298 RS |
8107 | { |
8108 | keytran_next | |
8109 | = get_keymap_1 | |
8110 | (get_keyelt | |
c6a67acd | 8111 | (access_keymap (keytran_map, meta_prefix_char, 1, 0), 0), |
a612e298 | 8112 | 0, 1); |
bb9e9bed | 8113 | XSETFASTINT (key, XFASTINT (key) & ~meta_modifier); |
a612e298 RS |
8114 | } |
8115 | else | |
8116 | keytran_next = keytran_map; | |
8117 | ||
8118 | keytran_next | |
e83f6bb0 | 8119 | = get_keyelt (access_keymap (keytran_next, key, 1, 0), 1); |
a612e298 | 8120 | |
c700c260 | 8121 | /* Handle symbol with autoload definition. */ |
e83f6bb0 RS |
8122 | if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) |
8123 | && CONSP (XSYMBOL (keytran_next)->function) | |
8124 | && EQ (XCONS (XSYMBOL (keytran_next)->function)->car, Qautoload)) | |
8125 | do_autoload (XSYMBOL (keytran_next)->function, | |
8126 | keytran_next); | |
8127 | ||
c700c260 RS |
8128 | /* Handle a symbol whose function definition is a keymap |
8129 | or an array. */ | |
e83f6bb0 | 8130 | if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) |
c700c260 RS |
8131 | && (!NILP (Farrayp (XSYMBOL (keytran_next)->function)) |
8132 | || !NILP (Fkeymapp (XSYMBOL (keytran_next)->function)))) | |
e83f6bb0 RS |
8133 | keytran_next = XSYMBOL (keytran_next)->function; |
8134 | ||
1abe6abe | 8135 | /* If the key translation map gives a function, not an |
e83f6bb0 | 8136 | array, then call the function with one arg and use |
1abe6abe RS |
8137 | its value instead. */ |
8138 | if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) | |
8139 | && keytran_end == t) | |
8140 | { | |
8141 | struct gcpro gcpro1, gcpro2, gcpro3; | |
8142 | Lisp_Object tem; | |
8143 | tem = keytran_next; | |
8144 | ||
40932d1a | 8145 | GCPRO3 (fkey_map, keytran_map, delayed_switch_frame); |
84d91fda | 8146 | keytran_next = call1 (keytran_next, prompt); |
1abe6abe RS |
8147 | UNGCPRO; |
8148 | /* If the function returned something invalid, | |
8149 | barf--don't ignore it. | |
df0f2ba1 | 8150 | (To ignore it safely, we would need to gcpro a bunch of |
1abe6abe RS |
8151 | other variables.) */ |
8152 | if (! (VECTORP (keytran_next) || STRINGP (keytran_next))) | |
40932d1a | 8153 | error ("Function in key-translation-map returns invalid key sequence"); |
1abe6abe RS |
8154 | } |
8155 | ||
00a78037 RS |
8156 | key_translation_possible = ! NILP (keytran_next); |
8157 | ||
a612e298 | 8158 | /* If keybuf[keytran_start..keytran_end] is bound in the |
1abe6abe | 8159 | key translation map and it's a suffix of the current |
a612e298 RS |
8160 | sequence (i.e. keytran_end == t), replace it with |
8161 | the binding and restart with keytran_start at the end. */ | |
8162 | if ((VECTORP (keytran_next) || STRINGP (keytran_next)) | |
8163 | && keytran_end == t) | |
8164 | { | |
2e864a76 | 8165 | int len = XFASTINT (Flength (keytran_next)); |
a612e298 RS |
8166 | |
8167 | t = keytran_start + len; | |
8168 | if (t >= bufsize) | |
3fe8e9a2 | 8169 | error ("Key sequence too long"); |
a612e298 RS |
8170 | |
8171 | if (VECTORP (keytran_next)) | |
8172 | bcopy (XVECTOR (keytran_next)->contents, | |
8173 | keybuf + keytran_start, | |
8174 | (t - keytran_start) * sizeof (keybuf[0])); | |
8175 | else if (STRINGP (keytran_next)) | |
8176 | { | |
8177 | int i; | |
8178 | ||
8179 | for (i = 0; i < len; i++) | |
bb9e9bed KH |
8180 | XSETFASTINT (keybuf[keytran_start + i], |
8181 | XSTRING (keytran_next)->data[i]); | |
a612e298 RS |
8182 | } |
8183 | ||
8184 | mock_input = t; | |
8185 | keytran_start = keytran_end = t; | |
8186 | keytran_map = Vkey_translation_map; | |
8187 | ||
00a78037 RS |
8188 | /* Don't pass the results of key-translation-map |
8189 | through function-key-map. */ | |
8190 | fkey_start = fkey_end = t; | |
3bd0dffb | 8191 | fkey_map = Vfunction_key_map; |
00a78037 | 8192 | |
a612e298 RS |
8193 | goto replay_sequence; |
8194 | } | |
8195 | ||
8196 | keytran_map = get_keymap_1 (keytran_next, 0, 1); | |
8197 | ||
df0f2ba1 | 8198 | /* If we no longer have a bound suffix, try a new positions for |
a612e298 RS |
8199 | keytran_start. */ |
8200 | if (NILP (keytran_map)) | |
8201 | { | |
8202 | keytran_end = ++keytran_start; | |
8203 | keytran_map = Vkey_translation_map; | |
00a78037 | 8204 | key_translation_possible = 0; |
a612e298 RS |
8205 | } |
8206 | } | |
8207 | } | |
4e50f26a RS |
8208 | |
8209 | /* If KEY is not defined in any of the keymaps, | |
8210 | and cannot be part of a function key or translation, | |
8211 | and is an upper case letter | |
8212 | use the corresponding lower-case letter instead. */ | |
8213 | if (first_binding == nmaps && ! function_key_possible | |
00a78037 | 8214 | && ! key_translation_possible |
8c18cbfb | 8215 | && INTEGERP (key) |
4e50f26a | 8216 | && ((((XINT (key) & 0x3ffff) |
301738ed | 8217 | < XCHAR_TABLE (current_buffer->downcase_table)->size) |
4e50f26a RS |
8218 | && UPPERCASEP (XINT (key) & 0x3ffff)) |
8219 | || (XINT (key) & shift_modifier))) | |
8220 | { | |
569871d2 | 8221 | Lisp_Object new_key; |
569871d2 | 8222 | |
309b0fc8 RS |
8223 | original_uppercase = key; |
8224 | original_uppercase_position = t - 1; | |
8225 | ||
831f35a2 | 8226 | if (XINT (key) & shift_modifier) |
569871d2 | 8227 | XSETINT (new_key, XINT (key) & ~shift_modifier); |
4e50f26a | 8228 | else |
569871d2 RS |
8229 | XSETINT (new_key, (DOWNCASE (XINT (key) & 0x3ffff) |
8230 | | (XINT (key) & ~0x3ffff))); | |
8231 | ||
3fe8e9a2 RS |
8232 | /* We have to do this unconditionally, regardless of whether |
8233 | the lower-case char is defined in the keymaps, because they | |
8234 | might get translated through function-key-map. */ | |
8235 | keybuf[t - 1] = new_key; | |
8236 | mock_input = t; | |
8237 | ||
8238 | fkey_map = prev_fkey_map; | |
8239 | fkey_start = prev_fkey_start; | |
8240 | fkey_end = prev_fkey_end; | |
8241 | ||
8242 | keytran_map = prev_keytran_map; | |
8243 | keytran_start = prev_keytran_start; | |
8244 | keytran_end = prev_keytran_end; | |
8245 | ||
8246 | goto replay_sequence; | |
4e50f26a | 8247 | } |
ef8fd672 RS |
8248 | /* If KEY is not defined in any of the keymaps, |
8249 | and cannot be part of a function key or translation, | |
8250 | and is a shifted function key, | |
8251 | use the corresponding unshifted function key instead. */ | |
8252 | if (first_binding == nmaps && ! function_key_possible | |
8253 | && ! key_translation_possible | |
8254 | && SYMBOLP (key)) | |
8255 | { | |
8256 | Lisp_Object breakdown; | |
8257 | int modifiers; | |
8258 | ||
8259 | breakdown = parse_modifiers (key); | |
8260 | modifiers = XINT (XCONS (XCONS (breakdown)->cdr)->car); | |
8261 | if (modifiers & shift_modifier) | |
8262 | { | |
569871d2 | 8263 | Lisp_Object new_key; |
3fe8e9a2 RS |
8264 | |
8265 | original_uppercase = key; | |
8266 | original_uppercase_position = t - 1; | |
ef8fd672 | 8267 | |
569871d2 RS |
8268 | modifiers &= ~shift_modifier; |
8269 | new_key = apply_modifiers (modifiers, | |
8270 | XCONS (breakdown)->car); | |
8271 | ||
3fe8e9a2 RS |
8272 | keybuf[t - 1] = new_key; |
8273 | mock_input = t; | |
8274 | ||
8275 | fkey_map = prev_fkey_map; | |
8276 | fkey_start = prev_fkey_start; | |
8277 | fkey_end = prev_fkey_end; | |
8278 | ||
8279 | keytran_map = prev_keytran_map; | |
8280 | keytran_start = prev_keytran_start; | |
8281 | keytran_end = prev_keytran_end; | |
8282 | ||
8283 | goto replay_sequence; | |
ef8fd672 RS |
8284 | } |
8285 | } | |
284f4730 JB |
8286 | } |
8287 | ||
309b0fc8 | 8288 | if (!dummyflag) |
bc536d84 RS |
8289 | read_key_sequence_cmd = (first_binding < nmaps |
8290 | ? defs[first_binding] | |
8291 | : Qnil); | |
284f4730 | 8292 | |
cd21b839 | 8293 | unread_switch_frame = delayed_switch_frame; |
f4255cd1 | 8294 | unbind_to (count, Qnil); |
07f76a14 | 8295 | |
3fe8e9a2 RS |
8296 | /* Don't downcase the last character if the caller says don't. |
8297 | Don't downcase it if the result is undefined, either. */ | |
8298 | if ((dont_downcase_last || first_binding >= nmaps) | |
8299 | && t - 1 == original_uppercase_position) | |
309b0fc8 RS |
8300 | keybuf[t - 1] = original_uppercase; |
8301 | ||
07f76a14 JB |
8302 | /* Occasionally we fabricate events, perhaps by expanding something |
8303 | according to function-key-map, or by adding a prefix symbol to a | |
8304 | mouse click in the scroll bar or modeline. In this cases, return | |
8305 | the entire generated key sequence, even if we hit an unbound | |
8306 | prefix or a definition before the end. This means that you will | |
8307 | be able to push back the event properly, and also means that | |
8308 | read-key-sequence will always return a logical unit. | |
8309 | ||
8310 | Better ideas? */ | |
cca310da JB |
8311 | for (; t < mock_input; t++) |
8312 | { | |
a98ea3f9 RS |
8313 | if (echo_keystrokes) |
8314 | echo_char (keybuf[t]); | |
cca310da JB |
8315 | add_command_key (keybuf[t]); |
8316 | } | |
07f76a14 | 8317 | |
7d18f9ae RS |
8318 | |
8319 | ||
284f4730 JB |
8320 | return t; |
8321 | } | |
8322 | ||
a612e298 RS |
8323 | #if 0 /* This doc string is too long for some compilers. |
8324 | This commented-out definition serves for DOC. */ | |
ce98e608 | 8325 | DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 4, 0, |
284f4730 JB |
8326 | "Read a sequence of keystrokes and return as a string or vector.\n\ |
8327 | The sequence is sufficient to specify a non-prefix command in the\n\ | |
8328 | current local and global maps.\n\ | |
8329 | \n\ | |
c0a58692 RS |
8330 | First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\ |
8331 | Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\ | |
8332 | as a continuation of the previous key.\n\ | |
284f4730 | 8333 | \n\ |
309b0fc8 RS |
8334 | The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\ |
8335 | convert the last event to lower case. (Normally any upper case event\n\ | |
8336 | is converted to lower case if the original event is undefined and the lower\n\ | |
8337 | case equivalent is defined.) A non-nil value is appropriate for reading\n\ | |
8338 | a key sequence to be defined.\n\ | |
8339 | \n\ | |
cb5df6ae JB |
8340 | A C-g typed while in this function is treated like any other character,\n\ |
8341 | and `quit-flag' is not set.\n\ | |
8342 | \n\ | |
8343 | If the key sequence starts with a mouse click, then the sequence is read\n\ | |
8344 | using the keymaps of the buffer of the window clicked in, not the buffer\n\ | |
8345 | of the selected window as normal.\n\ | |
ede41463 | 8346 | ""\n\ |
cb5df6ae JB |
8347 | `read-key-sequence' drops unbound button-down events, since you normally\n\ |
8348 | only care about the click or drag events which follow them. If a drag\n\ | |
fbcd35bd JB |
8349 | or multi-click event is unbound, but the corresponding click event would\n\ |
8350 | be bound, `read-key-sequence' turns the event into a click event at the\n\ | |
cb5df6ae | 8351 | drag's starting position. This means that you don't have to distinguish\n\ |
fbcd35bd | 8352 | between click and drag, double, or triple events unless you want to.\n\ |
cb5df6ae JB |
8353 | \n\ |
8354 | `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\ | |
3c370943 JB |
8355 | lines separating windows, and scroll bars with imaginary keys\n\ |
8356 | `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\ | |
cb5df6ae | 8357 | \n\ |
ce98e608 KH |
8358 | Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\ |
8359 | function will process a switch-frame event if the user switches frames\n\ | |
8360 | before typing anything. If the user switches frames in the middle of a\n\ | |
8361 | key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\ | |
8362 | is nil, then the event will be put off until after the current key sequence.\n\ | |
cb5df6ae JB |
8363 | \n\ |
8364 | `read-key-sequence' checks `function-key-map' for function key\n\ | |
8365 | sequences, where they wouldn't conflict with ordinary bindings. See\n\ | |
d5eecefb RS |
8366 | `function-key-map' for more details.\n\ |
8367 | \n\ | |
8368 | The optional fifth argument COMMAND-LOOP, if non-nil, means\n\ | |
8369 | that this key sequence is being read by something that will\n\ | |
8370 | read commands one after another. It should be nil if the caller\n\ | |
8371 | will read just one key sequence.") | |
b638f328 | 8372 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame, command-loop) |
a612e298 RS |
8373 | #endif |
8374 | ||
d5eecefb | 8375 | DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0, |
a612e298 | 8376 | 0) |
d5eecefb RS |
8377 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame, |
8378 | command_loop) | |
309b0fc8 | 8379 | Lisp_Object prompt, continue_echo, dont_downcase_last; |
d5eecefb | 8380 | Lisp_Object can_return_switch_frame, command_loop; |
284f4730 JB |
8381 | { |
8382 | Lisp_Object keybuf[30]; | |
8383 | register int i; | |
8384 | struct gcpro gcpro1, gcpro2; | |
d5eecefb | 8385 | int count = specpdl_ptr - specpdl; |
284f4730 JB |
8386 | |
8387 | if (!NILP (prompt)) | |
8388 | CHECK_STRING (prompt, 0); | |
8389 | QUIT; | |
8390 | ||
d5eecefb RS |
8391 | specbind (Qinput_method_exit_on_first_char, |
8392 | (NILP (command_loop) ? Qt : Qnil)); | |
8393 | specbind (Qinput_method_use_echo_area, | |
8394 | (NILP (command_loop) ? Qt : Qnil)); | |
8395 | ||
284f4730 JB |
8396 | bzero (keybuf, sizeof keybuf); |
8397 | GCPRO1 (keybuf[0]); | |
8398 | gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); | |
8399 | ||
daa37602 | 8400 | if (NILP (continue_echo)) |
6321824f RS |
8401 | { |
8402 | this_command_key_count = 0; | |
8403 | this_single_command_key_start = 0; | |
8404 | } | |
c0a58692 | 8405 | |
309b0fc8 | 8406 | i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), |
ce98e608 | 8407 | prompt, ! NILP (dont_downcase_last), |
f571ae0d | 8408 | ! NILP (can_return_switch_frame), 0); |
284f4730 | 8409 | |
dcc408a0 RS |
8410 | if (i == -1) |
8411 | { | |
8412 | Vquit_flag = Qt; | |
8413 | QUIT; | |
8414 | } | |
284f4730 | 8415 | UNGCPRO; |
d5eecefb | 8416 | return unbind_to (count, make_event_array (i, keybuf)); |
284f4730 | 8417 | } |
e39da3d7 RS |
8418 | |
8419 | DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector, | |
d5eecefb | 8420 | Sread_key_sequence_vector, 1, 5, 0, |
e39da3d7 | 8421 | "Like `read-key-sequence' but always return a vector.") |
d5eecefb RS |
8422 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame, |
8423 | command_loop) | |
e39da3d7 | 8424 | Lisp_Object prompt, continue_echo, dont_downcase_last; |
d5eecefb | 8425 | Lisp_Object can_return_switch_frame, command_loop; |
e39da3d7 RS |
8426 | { |
8427 | Lisp_Object keybuf[30]; | |
8428 | register int i; | |
8429 | struct gcpro gcpro1, gcpro2; | |
d5eecefb | 8430 | int count = specpdl_ptr - specpdl; |
e39da3d7 RS |
8431 | |
8432 | if (!NILP (prompt)) | |
8433 | CHECK_STRING (prompt, 0); | |
8434 | QUIT; | |
8435 | ||
d5eecefb RS |
8436 | specbind (Qinput_method_exit_on_first_char, |
8437 | (NILP (command_loop) ? Qt : Qnil)); | |
8438 | specbind (Qinput_method_use_echo_area, | |
8439 | (NILP (command_loop) ? Qt : Qnil)); | |
8440 | ||
e39da3d7 RS |
8441 | bzero (keybuf, sizeof keybuf); |
8442 | GCPRO1 (keybuf[0]); | |
8443 | gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); | |
8444 | ||
8445 | if (NILP (continue_echo)) | |
8446 | { | |
8447 | this_command_key_count = 0; | |
8448 | this_single_command_key_start = 0; | |
8449 | } | |
8450 | ||
8451 | i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), | |
8452 | prompt, ! NILP (dont_downcase_last), | |
8453 | ! NILP (can_return_switch_frame), 0); | |
8454 | ||
8455 | if (i == -1) | |
8456 | { | |
8457 | Vquit_flag = Qt; | |
8458 | QUIT; | |
8459 | } | |
8460 | UNGCPRO; | |
d5eecefb | 8461 | return unbind_to (count, Fvector (i, keybuf)); |
e39da3d7 | 8462 | } |
284f4730 | 8463 | \f |
158f7532 | 8464 | DEFUN ("command-execute", Fcommand_execute, Scommand_execute, 1, 4, 0, |
284f4730 JB |
8465 | "Execute CMD as an editor command.\n\ |
8466 | CMD must be a symbol that satisfies the `commandp' predicate.\n\ | |
8467 | Optional second arg RECORD-FLAG non-nil\n\ | |
8468 | means unconditionally put this command in `command-history'.\n\ | |
aaf2ead7 RS |
8469 | Otherwise, that is done only if an arg is read using the minibuffer.\n\ |
8470 | The argument KEYS specifies the value to use instead of (this-command-keys)\n\ | |
6321824f | 8471 | when reading the arguments; if it is nil, (this-command-keys) is used.\n\ |
158f7532 RS |
8472 | The argument SPECIAL, if non-nil, means that this command is executing\n\ |
8473 | a special event, so ignore the prefix argument and don't clear it.") | |
8474 | (cmd, record_flag, keys, special) | |
8475 | Lisp_Object cmd, record_flag, keys, special; | |
284f4730 JB |
8476 | { |
8477 | register Lisp_Object final; | |
8478 | register Lisp_Object tem; | |
8479 | Lisp_Object prefixarg; | |
8480 | struct backtrace backtrace; | |
8481 | extern int debug_on_next_call; | |
8482 | ||
284f4730 JB |
8483 | debug_on_next_call = 0; |
8484 | ||
158f7532 RS |
8485 | if (NILP (special)) |
8486 | { | |
8487 | prefixarg = current_kboard->Vprefix_arg; | |
8488 | Vcurrent_prefix_arg = prefixarg; | |
8489 | current_kboard->Vprefix_arg = Qnil; | |
8490 | } | |
8491 | else | |
8492 | prefixarg = Qnil; | |
8493 | ||
8c18cbfb | 8494 | if (SYMBOLP (cmd)) |
284f4730 JB |
8495 | { |
8496 | tem = Fget (cmd, Qdisabled); | |
88ce066e | 8497 | if (!NILP (tem) && !NILP (Vrun_hooks)) |
b78ce8fb RS |
8498 | { |
8499 | tem = Fsymbol_value (Qdisabled_command_hook); | |
8500 | if (!NILP (tem)) | |
8501 | return call1 (Vrun_hooks, Qdisabled_command_hook); | |
8502 | } | |
284f4730 JB |
8503 | } |
8504 | ||
01e26217 | 8505 | while (1) |
284f4730 | 8506 | { |
ffd56f97 | 8507 | final = Findirect_function (cmd); |
284f4730 JB |
8508 | |
8509 | if (CONSP (final) && (tem = Fcar (final), EQ (tem, Qautoload))) | |
b516a185 RS |
8510 | { |
8511 | struct gcpro gcpro1, gcpro2; | |
8512 | ||
8513 | GCPRO2 (cmd, prefixarg); | |
8514 | do_autoload (final, cmd); | |
8515 | UNGCPRO; | |
8516 | } | |
284f4730 JB |
8517 | else |
8518 | break; | |
8519 | } | |
8520 | ||
8c18cbfb | 8521 | if (STRINGP (final) || VECTORP (final)) |
284f4730 JB |
8522 | { |
8523 | /* If requested, place the macro in the command history. For | |
8524 | other sorts of commands, call-interactively takes care of | |
8525 | this. */ | |
e57d8fd8 | 8526 | if (!NILP (record_flag)) |
f4385381 RS |
8527 | { |
8528 | Vcommand_history | |
8529 | = Fcons (Fcons (Qexecute_kbd_macro, | |
8530 | Fcons (final, Fcons (prefixarg, Qnil))), | |
8531 | Vcommand_history); | |
8532 | ||
8533 | /* Don't keep command history around forever. */ | |
8534 | if (NUMBERP (Vhistory_length) && XINT (Vhistory_length) > 0) | |
8535 | { | |
8536 | tem = Fnthcdr (Vhistory_length, Vcommand_history); | |
8537 | if (CONSP (tem)) | |
8538 | XCONS (tem)->cdr = Qnil; | |
8539 | } | |
8540 | } | |
284f4730 JB |
8541 | |
8542 | return Fexecute_kbd_macro (final, prefixarg); | |
8543 | } | |
f4385381 | 8544 | |
8c18cbfb | 8545 | if (CONSP (final) || SUBRP (final) || COMPILEDP (final)) |
284f4730 JB |
8546 | { |
8547 | backtrace.next = backtrace_list; | |
8548 | backtrace_list = &backtrace; | |
8549 | backtrace.function = &Qcall_interactively; | |
8550 | backtrace.args = &cmd; | |
8551 | backtrace.nargs = 1; | |
8552 | backtrace.evalargs = 0; | |
8553 | ||
e57d8fd8 | 8554 | tem = Fcall_interactively (cmd, record_flag, keys); |
284f4730 JB |
8555 | |
8556 | backtrace_list = backtrace.next; | |
8557 | return tem; | |
8558 | } | |
8559 | return Qnil; | |
8560 | } | |
8561 | \f | |
284f4730 JB |
8562 | DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_command, |
8563 | 1, 1, "P", | |
8564 | "Read function name, then read its arguments and call it.") | |
8565 | (prefixarg) | |
8566 | Lisp_Object prefixarg; | |
8567 | { | |
8568 | Lisp_Object function; | |
8569 | char buf[40]; | |
8570 | Lisp_Object saved_keys; | |
5434fce6 | 8571 | Lisp_Object bindings, value; |
214360e9 | 8572 | struct gcpro gcpro1, gcpro2; |
284f4730 | 8573 | |
b0f2a7bf KH |
8574 | saved_keys = Fvector (this_command_key_count, |
8575 | XVECTOR (this_command_keys)->contents); | |
284f4730 | 8576 | buf[0] = 0; |
fde7aff8 | 8577 | GCPRO2 (saved_keys, prefixarg); |
284f4730 JB |
8578 | |
8579 | if (EQ (prefixarg, Qminus)) | |
8580 | strcpy (buf, "- "); | |
8581 | else if (CONSP (prefixarg) && XINT (XCONS (prefixarg)->car) == 4) | |
8582 | strcpy (buf, "C-u "); | |
8c18cbfb | 8583 | else if (CONSP (prefixarg) && INTEGERP (XCONS (prefixarg)->car)) |
5d5b907f RS |
8584 | { |
8585 | if (sizeof (int) == sizeof (EMACS_INT)) | |
8586 | sprintf (buf, "%d ", XINT (XCONS (prefixarg)->car)); | |
8587 | else if (sizeof (long) == sizeof (EMACS_INT)) | |
8588 | sprintf (buf, "%ld ", XINT (XCONS (prefixarg)->car)); | |
8589 | else | |
8590 | abort (); | |
8591 | } | |
8c18cbfb | 8592 | else if (INTEGERP (prefixarg)) |
5d5b907f RS |
8593 | { |
8594 | if (sizeof (int) == sizeof (EMACS_INT)) | |
8595 | sprintf (buf, "%d ", XINT (prefixarg)); | |
8596 | else if (sizeof (long) == sizeof (EMACS_INT)) | |
8597 | sprintf (buf, "%ld ", XINT (prefixarg)); | |
8598 | else | |
8599 | abort (); | |
8600 | } | |
284f4730 JB |
8601 | |
8602 | /* This isn't strictly correct if execute-extended-command | |
8603 | is bound to anything else. Perhaps it should use | |
8604 | this_command_keys? */ | |
8605 | strcat (buf, "M-x "); | |
8606 | ||
8607 | /* Prompt with buf, and then read a string, completing from and | |
8608 | restricting to the set of all defined commands. Don't provide | |
51763820 | 8609 | any initial input. Save the command read on the extended-command |
03b4122a | 8610 | history list. */ |
284f4730 JB |
8611 | function = Fcompleting_read (build_string (buf), |
8612 | Vobarray, Qcommandp, | |
4328577a KH |
8613 | Qt, Qnil, Qextended_command_history, Qnil, |
8614 | Qnil); | |
284f4730 | 8615 | |
1f5b1641 RS |
8616 | if (STRINGP (function) && XSTRING (function)->size == 0) |
8617 | error ("No command name given"); | |
8618 | ||
1113d9db JB |
8619 | /* Set this_command_keys to the concatenation of saved_keys and |
8620 | function, followed by a RET. */ | |
284f4730 | 8621 | { |
1113d9db | 8622 | struct Lisp_String *str; |
b0f2a7bf | 8623 | Lisp_Object *keys; |
284f4730 | 8624 | int i; |
284f4730 | 8625 | |
1113d9db | 8626 | this_command_key_count = 0; |
6321824f | 8627 | this_single_command_key_start = 0; |
1113d9db | 8628 | |
b0f2a7bf KH |
8629 | keys = XVECTOR (saved_keys)->contents; |
8630 | for (i = 0; i < XVECTOR (saved_keys)->size; i++) | |
8631 | add_command_key (keys[i]); | |
1113d9db JB |
8632 | |
8633 | str = XSTRING (function); | |
8634 | for (i = 0; i < str->size; i++) | |
301738ed | 8635 | add_command_key (Faref (function, make_number (i))); |
1113d9db | 8636 | |
301738ed | 8637 | add_command_key (make_number ('\015')); |
284f4730 JB |
8638 | } |
8639 | ||
8640 | UNGCPRO; | |
8641 | ||
0a7f1fc0 | 8642 | function = Fintern (function, Qnil); |
d8bcf58e | 8643 | current_kboard->Vprefix_arg = prefixarg; |
d5eecefb RS |
8644 | Vthis_command = function; |
8645 | real_this_command = function; | |
284f4730 | 8646 | |
6526ab49 RS |
8647 | /* If enabled, show which key runs this command. */ |
8648 | if (!NILP (Vsuggest_key_bindings) | |
71012575 | 8649 | && NILP (Vexecuting_macro) |
6526ab49 | 8650 | && SYMBOLP (function)) |
5434fce6 RS |
8651 | bindings = Fwhere_is_internal (function, Voverriding_local_map, |
8652 | Qt, Qnil); | |
8653 | else | |
8654 | bindings = Qnil; | |
6526ab49 | 8655 | |
5434fce6 RS |
8656 | value = Qnil; |
8657 | GCPRO2 (bindings, value); | |
8658 | value = Fcommand_execute (function, Qt, Qnil, Qnil); | |
6526ab49 | 8659 | |
5434fce6 | 8660 | /* If the command has a key binding, print it now. */ |
3ababa60 | 8661 | if (!NILP (bindings) |
ee112567 KH |
8662 | && ! (VECTORP (bindings) && EQ (Faref (bindings, make_number (0)), |
8663 | Qmouse_movement))) | |
5434fce6 RS |
8664 | { |
8665 | /* But first wait, and skip the message if there is input. */ | |
426939cc | 8666 | int delay_time; |
985f9f66 | 8667 | if (!NILP (echo_area_buffer[0])) |
426939cc RS |
8668 | /* This command displayed something in the echo area; |
8669 | so wait a few seconds, then display our suggestion message. */ | |
8670 | delay_time = (NUMBERP (Vsuggest_key_bindings) | |
8671 | ? XINT (Vsuggest_key_bindings) : 2); | |
8672 | else | |
8673 | /* This command left the echo area empty, | |
8674 | so display our message immediately. */ | |
8675 | delay_time = 0; | |
8676 | ||
8677 | if (!NILP (Fsit_for (make_number (delay_time), Qnil, Qnil)) | |
303b5b3f | 8678 | && ! CONSP (Vunread_command_events)) |
6526ab49 | 8679 | { |
5434fce6 RS |
8680 | Lisp_Object binding; |
8681 | char *newmessage; | |
985f9f66 | 8682 | int message_p = push_message (); |
5434fce6 RS |
8683 | |
8684 | binding = Fkey_description (bindings); | |
8685 | ||
8686 | newmessage | |
8687 | = (char *) alloca (XSYMBOL (function)->name->size | |
fc932ac6 | 8688 | + STRING_BYTES (XSTRING (binding)) |
5434fce6 | 8689 | + 100); |
3ababa60 | 8690 | sprintf (newmessage, "You can run the command `%s' with %s", |
6526ab49 | 8691 | XSYMBOL (function)->name->data, |
5434fce6 | 8692 | XSTRING (binding)->data); |
301738ed RS |
8693 | message2_nolog (newmessage, |
8694 | strlen (newmessage), | |
8695 | STRING_MULTIBYTE (binding)); | |
5434fce6 RS |
8696 | if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings) |
8697 | ? Vsuggest_key_bindings : make_number (2)), | |
985f9f66 GM |
8698 | Qnil, Qnil)) |
8699 | && message_p) | |
8700 | restore_message (); | |
8701 | ||
8702 | pop_message (); | |
6526ab49 RS |
8703 | } |
8704 | } | |
8705 | ||
5434fce6 | 8706 | RETURN_UNGCPRO (value); |
284f4730 | 8707 | } |
6526ab49 RS |
8708 | |
8709 | /* Find the set of keymaps now active. | |
8710 | Store into *MAPS_P a vector holding the various maps | |
8711 | and return the number of them. The vector was malloc'd | |
8712 | and the caller should free it. */ | |
8713 | ||
8714 | int | |
8715 | current_active_maps (maps_p) | |
8716 | Lisp_Object **maps_p; | |
8717 | { | |
8718 | Lisp_Object *tmaps, *maps; | |
8719 | int nmaps; | |
8720 | ||
8721 | /* Should overriding-terminal-local-map and overriding-local-map apply? */ | |
8722 | if (!NILP (Voverriding_local_map_menu_flag)) | |
8723 | { | |
8724 | /* Yes, use them (if non-nil) as well as the global map. */ | |
8725 | maps = (Lisp_Object *) xmalloc (3 * sizeof (maps[0])); | |
8726 | nmaps = 0; | |
8727 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
8728 | maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
8729 | if (!NILP (Voverriding_local_map)) | |
8730 | maps[nmaps++] = Voverriding_local_map; | |
8731 | } | |
8732 | else | |
8733 | { | |
8734 | /* No, so use major and minor mode keymaps. */ | |
8735 | nmaps = current_minor_maps (NULL, &tmaps); | |
8736 | maps = (Lisp_Object *) xmalloc ((nmaps + 2) * sizeof (maps[0])); | |
8737 | bcopy (tmaps, maps, nmaps * sizeof (maps[0])); | |
8738 | #ifdef USE_TEXT_PROPERTIES | |
8739 | maps[nmaps++] = get_local_map (PT, current_buffer); | |
8740 | #else | |
8741 | maps[nmaps++] = current_buffer->keymap; | |
8742 | #endif | |
8743 | } | |
8744 | maps[nmaps++] = current_global_map; | |
8745 | ||
8746 | *maps_p = maps; | |
8747 | return nmaps; | |
8748 | } | |
284f4730 | 8749 | \f |
d9d4c147 | 8750 | /* Return nonzero if input events are pending. */ |
284f4730 | 8751 | |
dfcf069d | 8752 | int |
284f4730 JB |
8753 | detect_input_pending () |
8754 | { | |
8755 | if (!input_pending) | |
d9d4c147 KH |
8756 | get_input_pending (&input_pending, 0); |
8757 | ||
8758 | return input_pending; | |
8759 | } | |
8760 | ||
b1878f45 | 8761 | /* Return nonzero if input events are pending, and run any pending timers. */ |
d9d4c147 | 8762 | |
dfcf069d | 8763 | int |
87dd9b9b RS |
8764 | detect_input_pending_run_timers (do_display) |
8765 | int do_display; | |
d9d4c147 | 8766 | { |
87dd9b9b RS |
8767 | int old_timers_run = timers_run; |
8768 | ||
d9d4c147 KH |
8769 | if (!input_pending) |
8770 | get_input_pending (&input_pending, 1); | |
284f4730 | 8771 | |
87dd9b9b | 8772 | if (old_timers_run != timers_run && do_display) |
7ee32cda GM |
8773 | { |
8774 | redisplay_preserve_echo_area (); | |
8775 | /* The following fixes a bug when using lazy-lock with | |
8776 | lazy-lock-defer-on-the-fly set to t, i.e. when fontifying | |
8777 | from an idle timer function. The symptom of the bug is that | |
8778 | the cursor sometimes doesn't become visible until the next X | |
8779 | event is processed. --gerd. */ | |
8780 | if (rif) | |
8781 | rif->flush_display (NULL); | |
8782 | } | |
87dd9b9b | 8783 | |
284f4730 JB |
8784 | return input_pending; |
8785 | } | |
8786 | ||
ffd56f97 JB |
8787 | /* This is called in some cases before a possible quit. |
8788 | It cases the next call to detect_input_pending to recompute input_pending. | |
8789 | So calling this function unnecessarily can't do any harm. */ | |
07a59269 KH |
8790 | |
8791 | void | |
ffd56f97 JB |
8792 | clear_input_pending () |
8793 | { | |
8794 | input_pending = 0; | |
8795 | } | |
8796 | ||
b1878f45 RS |
8797 | /* Return nonzero if there are pending requeued events. |
8798 | This isn't used yet. The hope is to make wait_reading_process_input | |
8799 | call it, and return return if it runs Lisp code that unreads something. | |
8800 | The problem is, kbd_buffer_get_event needs to be fixed to know what | |
8801 | to do in that case. It isn't trivial. */ | |
8802 | ||
dfcf069d | 8803 | int |
b1878f45 RS |
8804 | requeued_events_pending_p () |
8805 | { | |
8806 | return (!NILP (Vunread_command_events) || unread_command_char != -1); | |
8807 | } | |
8808 | ||
8809 | ||
284f4730 JB |
8810 | DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0, |
8811 | "T if command input is currently available with no waiting.\n\ | |
8812 | Actually, the value is nil only if we can be sure that no input is available.") | |
8813 | () | |
8814 | { | |
24597608 | 8815 | if (!NILP (Vunread_command_events) || unread_command_char != -1) |
284f4730 JB |
8816 | return (Qt); |
8817 | ||
d9d4c147 KH |
8818 | get_input_pending (&input_pending, 1); |
8819 | return input_pending > 0 ? Qt : Qnil; | |
284f4730 JB |
8820 | } |
8821 | ||
8822 | DEFUN ("recent-keys", Frecent_keys, Srecent_keys, 0, 0, 0, | |
22d7cb89 | 8823 | "Return vector of last 100 events, not counting those from keyboard macros.") |
284f4730 JB |
8824 | () |
8825 | { | |
5160df46 | 8826 | Lisp_Object *keys = XVECTOR (recent_keys)->contents; |
284f4730 JB |
8827 | Lisp_Object val; |
8828 | ||
8829 | if (total_keys < NUM_RECENT_KEYS) | |
5160df46 | 8830 | return Fvector (total_keys, keys); |
284f4730 JB |
8831 | else |
8832 | { | |
5160df46 JB |
8833 | val = Fvector (NUM_RECENT_KEYS, keys); |
8834 | bcopy (keys + recent_keys_index, | |
284f4730 JB |
8835 | XVECTOR (val)->contents, |
8836 | (NUM_RECENT_KEYS - recent_keys_index) * sizeof (Lisp_Object)); | |
5160df46 | 8837 | bcopy (keys, |
284f4730 JB |
8838 | XVECTOR (val)->contents + NUM_RECENT_KEYS - recent_keys_index, |
8839 | recent_keys_index * sizeof (Lisp_Object)); | |
8840 | return val; | |
8841 | } | |
8842 | } | |
8843 | ||
8844 | DEFUN ("this-command-keys", Fthis_command_keys, Sthis_command_keys, 0, 0, 0, | |
e5f920d7 RS |
8845 | "Return the key sequence that invoked this command.\n\ |
8846 | The value is a string or a vector.") | |
284f4730 JB |
8847 | () |
8848 | { | |
86e5706b RS |
8849 | return make_event_array (this_command_key_count, |
8850 | XVECTOR (this_command_keys)->contents); | |
284f4730 JB |
8851 | } |
8852 | ||
e39da3d7 RS |
8853 | DEFUN ("this-command-keys-vector", Fthis_command_keys_vector, Sthis_command_keys_vector, 0, 0, 0, |
8854 | "Return the key sequence that invoked this command, as a vector.") | |
8855 | () | |
8856 | { | |
8857 | return Fvector (this_command_key_count, | |
8858 | XVECTOR (this_command_keys)->contents); | |
8859 | } | |
8860 | ||
6321824f RS |
8861 | DEFUN ("this-single-command-keys", Fthis_single_command_keys, |
8862 | Sthis_single_command_keys, 0, 0, 0, | |
8863 | "Return the key sequence that invoked this command.\n\ | |
8864 | Unlike `this-command-keys', this function's value\n\ | |
8865 | does not include prefix arguments.\n\ | |
e39da3d7 | 8866 | The value is always a vector.") |
6321824f RS |
8867 | () |
8868 | { | |
e39da3d7 RS |
8869 | return Fvector (this_command_key_count |
8870 | - this_single_command_key_start, | |
8871 | (XVECTOR (this_command_keys)->contents | |
8872 | + this_single_command_key_start)); | |
6321824f RS |
8873 | } |
8874 | ||
7d18f9ae RS |
8875 | DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys, |
8876 | Sthis_single_command_raw_keys, 0, 0, 0, | |
8877 | "Return the raw events that were read for this command.\n\ | |
8878 | Unlike `this-single-command-keys', this function's value\n\ | |
8879 | shows the events before all translations (except for input methods).\n\ | |
8880 | The value is always a vector.") | |
8881 | () | |
8882 | { | |
8883 | return Fvector (raw_keybuf_count, | |
8884 | (XVECTOR (raw_keybuf)->contents)); | |
8885 | } | |
8886 | ||
71918b75 RS |
8887 | DEFUN ("reset-this-command-lengths", Freset_this_command_lengths, |
8888 | Sreset_this_command_lengths, 0, 0, 0, | |
8889 | "Used for complicated reasons in `universal-argument-other-key'.\n\ | |
8890 | \n\ | |
8891 | `universal-argument-other-key' rereads the event just typed.\n\ | |
8892 | It then gets translated through `function-key-map'.\n\ | |
8893 | The translated event gets included in the echo area and in\n\ | |
8894 | the value of `this-command-keys' in addition to the raw original event.\n\ | |
8895 | That is not right.\n\ | |
8896 | \n\ | |
8897 | Calling this function directs the translated event to replace\n\ | |
8898 | the original event, so that only one version of the event actually\n\ | |
8899 | appears in the echo area and in the value of `this-command-keys.'.") | |
8900 | () | |
8901 | { | |
8902 | before_command_restore_flag = 1; | |
8903 | before_command_key_count_1 = before_command_key_count; | |
8904 | before_command_echo_length_1 = before_command_echo_length; | |
6e5742a0 | 8905 | return Qnil; |
71918b75 RS |
8906 | } |
8907 | ||
82e6e5af RS |
8908 | DEFUN ("clear-this-command-keys", Fclear_this_command_keys, |
8909 | Sclear_this_command_keys, 0, 0, 0, | |
8910 | "Clear out the vector that `this-command-keys' returns.") | |
8911 | () | |
8912 | { | |
8913 | this_command_key_count = 0; | |
8914 | return Qnil; | |
8915 | } | |
8916 | ||
284f4730 JB |
8917 | DEFUN ("recursion-depth", Frecursion_depth, Srecursion_depth, 0, 0, 0, |
8918 | "Return the current depth in recursive edits.") | |
8919 | () | |
8920 | { | |
8921 | Lisp_Object temp; | |
bb9e9bed | 8922 | XSETFASTINT (temp, command_loop_level + minibuf_level); |
284f4730 JB |
8923 | return temp; |
8924 | } | |
8925 | ||
8926 | DEFUN ("open-dribble-file", Fopen_dribble_file, Sopen_dribble_file, 1, 1, | |
8927 | "FOpen dribble file: ", | |
9b2471df RS |
8928 | "Start writing all keyboard characters to a dribble file called FILE.\n\ |
8929 | If FILE is nil, close any open dribble file.") | |
284f4730 JB |
8930 | (file) |
8931 | Lisp_Object file; | |
8932 | { | |
6cb52def | 8933 | if (dribble) |
284f4730 | 8934 | { |
6cb52def KH |
8935 | fclose (dribble); |
8936 | dribble = 0; | |
284f4730 | 8937 | } |
6cb52def | 8938 | if (!NILP (file)) |
284f4730 JB |
8939 | { |
8940 | file = Fexpand_file_name (file, Qnil); | |
8941 | dribble = fopen (XSTRING (file)->data, "w"); | |
ab6ca1de KH |
8942 | if (dribble == 0) |
8943 | report_file_error ("Opening dribble", Fcons (file, Qnil)); | |
284f4730 JB |
8944 | } |
8945 | return Qnil; | |
8946 | } | |
8947 | ||
8948 | DEFUN ("discard-input", Fdiscard_input, Sdiscard_input, 0, 0, 0, | |
8949 | "Discard the contents of the terminal input buffer.\n\ | |
8950 | Also cancel any kbd macro being defined.") | |
8951 | () | |
8952 | { | |
c5fdd383 | 8953 | current_kboard->defining_kbd_macro = Qnil; |
284f4730 JB |
8954 | update_mode_lines++; |
8955 | ||
24597608 | 8956 | Vunread_command_events = Qnil; |
86e5706b | 8957 | unread_command_char = -1; |
284f4730 JB |
8958 | |
8959 | discard_tty_input (); | |
8960 | ||
7ee32cda | 8961 | kbd_fetch_ptr = kbd_store_ptr; |
beecf6a1 | 8962 | Ffillarray (kbd_buffer_frame_or_window, Qnil); |
284f4730 JB |
8963 | input_pending = 0; |
8964 | ||
8965 | return Qnil; | |
8966 | } | |
8967 | \f | |
8968 | DEFUN ("suspend-emacs", Fsuspend_emacs, Ssuspend_emacs, 0, 1, "", | |
8969 | "Stop Emacs and return to superior process. You can resume later.\n\ | |
8026024c KH |
8970 | If `cannot-suspend' is non-nil, or if the system doesn't support job\n\ |
8971 | control, run a subshell instead.\n\n\ | |
284f4730 | 8972 | If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\ |
b7d2ebbf RS |
8973 | to be read as terminal input by Emacs's parent, after suspension.\n\ |
8974 | \n\ | |
bbdc2092 RS |
8975 | Before suspending, run the normal hook `suspend-hook'.\n\ |
8976 | After resumption run the normal hook `suspend-resume-hook'.\n\ | |
284f4730 JB |
8977 | \n\ |
8978 | Some operating systems cannot stop the Emacs process and resume it later.\n\ | |
b7d2ebbf | 8979 | On such systems, Emacs starts a subshell instead of suspending.") |
284f4730 JB |
8980 | (stuffstring) |
8981 | Lisp_Object stuffstring; | |
8982 | { | |
3a69360c | 8983 | Lisp_Object tem; |
284f4730 JB |
8984 | int count = specpdl_ptr - specpdl; |
8985 | int old_height, old_width; | |
8986 | int width, height; | |
b7d2ebbf | 8987 | struct gcpro gcpro1, gcpro2; |
284f4730 JB |
8988 | |
8989 | if (!NILP (stuffstring)) | |
8990 | CHECK_STRING (stuffstring, 0); | |
284f4730 | 8991 | |
1e95ed28 JB |
8992 | /* Run the functions in suspend-hook. */ |
8993 | if (!NILP (Vrun_hooks)) | |
8994 | call1 (Vrun_hooks, intern ("suspend-hook")); | |
284f4730 | 8995 | |
b7d2ebbf | 8996 | GCPRO1 (stuffstring); |
ff11dfa1 | 8997 | get_frame_size (&old_width, &old_height); |
284f4730 JB |
8998 | reset_sys_modes (); |
8999 | /* sys_suspend can get an error if it tries to fork a subshell | |
9000 | and the system resources aren't available for that. */ | |
91a0da02 | 9001 | record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes, |
d52a7a92 | 9002 | Qnil); |
284f4730 | 9003 | stuff_buffered_input (stuffstring); |
8026024c KH |
9004 | if (cannot_suspend) |
9005 | sys_subshell (); | |
9006 | else | |
9007 | sys_suspend (); | |
284f4730 JB |
9008 | unbind_to (count, Qnil); |
9009 | ||
9010 | /* Check if terminal/window size has changed. | |
9011 | Note that this is not useful when we are running directly | |
9012 | with a window system; but suspend should be disabled in that case. */ | |
ff11dfa1 | 9013 | get_frame_size (&width, &height); |
284f4730 | 9014 | if (width != old_width || height != old_height) |
985f9f66 | 9015 | change_frame_size (selected_frame, height, width, 0, 0, 0); |
284f4730 | 9016 | |
1e95ed28 | 9017 | /* Run suspend-resume-hook. */ |
284f4730 JB |
9018 | if (!NILP (Vrun_hooks)) |
9019 | call1 (Vrun_hooks, intern ("suspend-resume-hook")); | |
df0f2ba1 | 9020 | |
284f4730 JB |
9021 | UNGCPRO; |
9022 | return Qnil; | |
9023 | } | |
9024 | ||
9025 | /* If STUFFSTRING is a string, stuff its contents as pending terminal input. | |
eb8c3be9 | 9026 | Then in any case stuff anything Emacs has read ahead and not used. */ |
284f4730 | 9027 | |
07a59269 | 9028 | void |
284f4730 JB |
9029 | stuff_buffered_input (stuffstring) |
9030 | Lisp_Object stuffstring; | |
9031 | { | |
284f4730 | 9032 | /* stuff_char works only in BSD, versions 4.2 and up. */ |
6df54671 | 9033 | #ifdef BSD_SYSTEM |
284f4730 | 9034 | #ifndef BSD4_1 |
612b78ef | 9035 | register unsigned char *p; |
612b78ef | 9036 | |
8c18cbfb | 9037 | if (STRINGP (stuffstring)) |
284f4730 JB |
9038 | { |
9039 | register int count; | |
9040 | ||
9041 | p = XSTRING (stuffstring)->data; | |
fc932ac6 | 9042 | count = STRING_BYTES (XSTRING (stuffstring)); |
284f4730 JB |
9043 | while (count-- > 0) |
9044 | stuff_char (*p++); | |
9045 | stuff_char ('\n'); | |
9046 | } | |
9047 | /* Anything we have read ahead, put back for the shell to read. */ | |
beecf6a1 | 9048 | /* ?? What should this do when we have multiple keyboards?? |
c5fdd383 | 9049 | Should we ignore anything that was typed in at the "wrong" kboard? */ |
beecf6a1 | 9050 | for (; kbd_fetch_ptr != kbd_store_ptr; kbd_fetch_ptr++) |
284f4730 | 9051 | { |
beecf6a1 KH |
9052 | if (kbd_fetch_ptr == kbd_buffer + KBD_BUFFER_SIZE) |
9053 | kbd_fetch_ptr = kbd_buffer; | |
9054 | if (kbd_fetch_ptr->kind == ascii_keystroke) | |
9055 | stuff_char (kbd_fetch_ptr->code); | |
9056 | kbd_fetch_ptr->kind = no_event; | |
9057 | (XVECTOR (kbd_buffer_frame_or_window)->contents[kbd_fetch_ptr | |
9058 | - kbd_buffer] | |
7b4aedb9 | 9059 | = Qnil); |
284f4730 JB |
9060 | } |
9061 | input_pending = 0; | |
9062 | #endif | |
6df54671 | 9063 | #endif /* BSD_SYSTEM and not BSD4_1 */ |
284f4730 JB |
9064 | } |
9065 | \f | |
dfcf069d | 9066 | void |
ffd56f97 JB |
9067 | set_waiting_for_input (time_to_clear) |
9068 | EMACS_TIME *time_to_clear; | |
284f4730 | 9069 | { |
ffd56f97 | 9070 | input_available_clear_time = time_to_clear; |
284f4730 JB |
9071 | |
9072 | /* Tell interrupt_signal to throw back to read_char, */ | |
9073 | waiting_for_input = 1; | |
9074 | ||
9075 | /* If interrupt_signal was called before and buffered a C-g, | |
9076 | make it run again now, to avoid timing error. */ | |
9077 | if (!NILP (Vquit_flag)) | |
9078 | quit_throw_to_read_char (); | |
284f4730 JB |
9079 | } |
9080 | ||
07a59269 | 9081 | void |
284f4730 JB |
9082 | clear_waiting_for_input () |
9083 | { | |
9084 | /* Tell interrupt_signal not to throw back to read_char, */ | |
9085 | waiting_for_input = 0; | |
ffd56f97 | 9086 | input_available_clear_time = 0; |
284f4730 JB |
9087 | } |
9088 | ||
9089 | /* This routine is called at interrupt level in response to C-G. | |
9090 | If interrupt_input, this is the handler for SIGINT. | |
9091 | Otherwise, it is called from kbd_buffer_store_event, | |
9092 | in handling SIGIO or SIGTINT. | |
9093 | ||
9094 | If `waiting_for_input' is non zero, then unless `echoing' is nonzero, | |
9095 | immediately throw back to read_char. | |
9096 | ||
9097 | Otherwise it sets the Lisp variable quit-flag not-nil. | |
9098 | This causes eval to throw, when it gets a chance. | |
9099 | If quit-flag is already non-nil, it stops the job right away. */ | |
9100 | ||
9101 | SIGTYPE | |
91c049d4 RS |
9102 | interrupt_signal (signalnum) /* If we don't have an argument, */ |
9103 | int signalnum; /* some compilers complain in signal calls. */ | |
284f4730 JB |
9104 | { |
9105 | char c; | |
9106 | /* Must preserve main program's value of errno. */ | |
9107 | int old_errno = errno; | |
284f4730 | 9108 | |
5970a8cb | 9109 | #if defined (USG) && !defined (POSIX_SIGNALS) |
7a80a6f6 RS |
9110 | if (!read_socket_hook && NILP (Vwindow_system)) |
9111 | { | |
9112 | /* USG systems forget handlers when they are used; | |
9113 | must reestablish each time */ | |
9114 | signal (SIGINT, interrupt_signal); | |
9115 | signal (SIGQUIT, interrupt_signal); | |
9116 | } | |
284f4730 JB |
9117 | #endif /* USG */ |
9118 | ||
9119 | cancel_echoing (); | |
9120 | ||
31e4e97b EZ |
9121 | if (!NILP (Vquit_flag) |
9122 | && (FRAME_TERMCAP_P (selected_frame) || FRAME_MSDOS_P (selected_frame))) | |
284f4730 | 9123 | { |
31e4e97b EZ |
9124 | /* If SIGINT isn't blocked, don't let us be interrupted by |
9125 | another SIGINT, it might be harmful due to non-reentrancy | |
9126 | in I/O functions. */ | |
9127 | sigblock (sigmask (SIGINT)); | |
9128 | ||
284f4730 JB |
9129 | fflush (stdout); |
9130 | reset_sys_modes (); | |
31e4e97b | 9131 | |
284f4730 JB |
9132 | #ifdef SIGTSTP /* Support possible in later USG versions */ |
9133 | /* | |
9134 | * On systems which can suspend the current process and return to the original | |
9135 | * shell, this command causes the user to end up back at the shell. | |
9136 | * The "Auto-save" and "Abort" questions are not asked until | |
9137 | * the user elects to return to emacs, at which point he can save the current | |
9138 | * job and either dump core or continue. | |
9139 | */ | |
9140 | sys_suspend (); | |
9141 | #else | |
9142 | #ifdef VMS | |
9143 | if (sys_suspend () == -1) | |
9144 | { | |
9145 | printf ("Not running as a subprocess;\n"); | |
9146 | printf ("you can continue or abort.\n"); | |
9147 | } | |
9148 | #else /* not VMS */ | |
9149 | /* Perhaps should really fork an inferior shell? | |
9150 | But that would not provide any way to get back | |
9151 | to the original shell, ever. */ | |
9152 | printf ("No support for stopping a process on this operating system;\n"); | |
9153 | printf ("you can continue or abort.\n"); | |
9154 | #endif /* not VMS */ | |
9155 | #endif /* not SIGTSTP */ | |
80e4aa30 RS |
9156 | #ifdef MSDOS |
9157 | /* We must remain inside the screen area when the internal terminal | |
9158 | is used. Note that [Enter] is not echoed by dos. */ | |
9159 | cursor_to (0, 0); | |
9160 | #endif | |
118d6ca9 RS |
9161 | /* It doesn't work to autosave while GC is in progress; |
9162 | the code used for auto-saving doesn't cope with the mark bit. */ | |
9163 | if (!gc_in_progress) | |
9fd7d808 | 9164 | { |
118d6ca9 RS |
9165 | printf ("Auto-save? (y or n) "); |
9166 | fflush (stdout); | |
9167 | if (((c = getchar ()) & ~040) == 'Y') | |
9168 | { | |
9169 | Fdo_auto_save (Qt, Qnil); | |
80e4aa30 | 9170 | #ifdef MSDOS |
118d6ca9 | 9171 | printf ("\r\nAuto-save done"); |
80e4aa30 | 9172 | #else /* not MSDOS */ |
118d6ca9 | 9173 | printf ("Auto-save done\n"); |
80e4aa30 | 9174 | #endif /* not MSDOS */ |
118d6ca9 RS |
9175 | } |
9176 | while (c != '\n') c = getchar (); | |
9fd7d808 | 9177 | } |
118d6ca9 RS |
9178 | else |
9179 | { | |
9180 | /* During GC, it must be safe to reenable quitting again. */ | |
9181 | Vinhibit_quit = Qnil; | |
9182 | #ifdef MSDOS | |
9183 | printf ("\r\n"); | |
9184 | #endif /* not MSDOS */ | |
9185 | printf ("Garbage collection in progress; cannot auto-save now\r\n"); | |
9186 | printf ("but will instead do a real quit after garbage collection ends\r\n"); | |
9187 | fflush (stdout); | |
9188 | } | |
9189 | ||
80e4aa30 RS |
9190 | #ifdef MSDOS |
9191 | printf ("\r\nAbort? (y or n) "); | |
9192 | #else /* not MSDOS */ | |
284f4730 JB |
9193 | #ifdef VMS |
9194 | printf ("Abort (and enter debugger)? (y or n) "); | |
9195 | #else /* not VMS */ | |
9196 | printf ("Abort (and dump core)? (y or n) "); | |
9197 | #endif /* not VMS */ | |
80e4aa30 | 9198 | #endif /* not MSDOS */ |
284f4730 JB |
9199 | fflush (stdout); |
9200 | if (((c = getchar ()) & ~040) == 'Y') | |
9201 | abort (); | |
9202 | while (c != '\n') c = getchar (); | |
80e4aa30 RS |
9203 | #ifdef MSDOS |
9204 | printf ("\r\nContinuing...\r\n"); | |
9205 | #else /* not MSDOS */ | |
284f4730 | 9206 | printf ("Continuing...\n"); |
80e4aa30 | 9207 | #endif /* not MSDOS */ |
284f4730 JB |
9208 | fflush (stdout); |
9209 | init_sys_modes (); | |
31e4e97b | 9210 | sigfree (); |
284f4730 JB |
9211 | } |
9212 | else | |
9213 | { | |
9214 | /* If executing a function that wants to be interrupted out of | |
9215 | and the user has not deferred quitting by binding `inhibit-quit' | |
9216 | then quit right away. */ | |
9217 | if (immediate_quit && NILP (Vinhibit_quit)) | |
9218 | { | |
e39da3d7 RS |
9219 | struct gl_state_s saved; |
9220 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
9221 | ||
284f4730 JB |
9222 | immediate_quit = 0; |
9223 | sigfree (); | |
e39da3d7 RS |
9224 | saved = gl_state; |
9225 | GCPRO4 (saved.object, saved.global_code, | |
9226 | saved.current_syntax_table, saved.old_prop); | |
284f4730 | 9227 | Fsignal (Qquit, Qnil); |
e39da3d7 RS |
9228 | gl_state = saved; |
9229 | UNGCPRO; | |
284f4730 JB |
9230 | } |
9231 | else | |
9232 | /* Else request quit when it's safe */ | |
9233 | Vquit_flag = Qt; | |
9234 | } | |
9235 | ||
9236 | if (waiting_for_input && !echoing) | |
9237 | quit_throw_to_read_char (); | |
9238 | ||
9239 | errno = old_errno; | |
9240 | } | |
9241 | ||
9242 | /* Handle a C-g by making read_char return C-g. */ | |
9243 | ||
07a59269 | 9244 | void |
284f4730 JB |
9245 | quit_throw_to_read_char () |
9246 | { | |
284f4730 JB |
9247 | sigfree (); |
9248 | /* Prevent another signal from doing this before we finish. */ | |
f76475ad | 9249 | clear_waiting_for_input (); |
284f4730 JB |
9250 | input_pending = 0; |
9251 | ||
24597608 | 9252 | Vunread_command_events = Qnil; |
86e5706b | 9253 | unread_command_char = -1; |
284f4730 | 9254 | |
087feab3 RS |
9255 | #if 0 /* Currently, sit_for is called from read_char without turning |
9256 | off polling. And that can call set_waiting_for_input. | |
9257 | It seems to be harmless. */ | |
e6b01c14 JB |
9258 | #ifdef POLL_FOR_INPUT |
9259 | /* May be > 1 if in recursive minibuffer. */ | |
9260 | if (poll_suppress_count == 0) | |
9261 | abort (); | |
9262 | #endif | |
087feab3 | 9263 | #endif |
4c52b668 KH |
9264 | if (FRAMEP (internal_last_event_frame) |
9265 | && XFRAME (internal_last_event_frame) != selected_frame) | |
719191cf RS |
9266 | do_switch_frame (make_lispy_switch_frame (internal_last_event_frame), |
9267 | Qnil, 0); | |
e6b01c14 | 9268 | |
284f4730 JB |
9269 | _longjmp (getcjmp, 1); |
9270 | } | |
9271 | \f | |
9272 | DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, | |
9273 | "Set mode of reading keyboard input.\n\ | |
464f8898 RS |
9274 | First arg INTERRUPT non-nil means use input interrupts;\n\ |
9275 | nil means use CBREAK mode.\n\ | |
9276 | Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\ | |
284f4730 | 9277 | (no effect except in CBREAK mode).\n\ |
b04904fb RS |
9278 | Third arg META t means accept 8-bit input (for a Meta key).\n\ |
9279 | META nil means ignore the top bit, on the assumption it is parity.\n\ | |
9280 | Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\ | |
a8ee7ef9 RS |
9281 | Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\ |
9282 | See also `current-input-mode'.") | |
284f4730 JB |
9283 | (interrupt, flow, meta, quit) |
9284 | Lisp_Object interrupt, flow, meta, quit; | |
9285 | { | |
9286 | if (!NILP (quit) | |
8c18cbfb | 9287 | && (!INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400)) |
34f04431 RS |
9288 | error ("set-input-mode: QUIT must be an ASCII character"); |
9289 | ||
9290 | #ifdef POLL_FOR_INPUT | |
9291 | stop_polling (); | |
9292 | #endif | |
284f4730 | 9293 | |
07de30b9 | 9294 | #ifndef DOS_NT |
2ee250ec | 9295 | /* this causes startup screen to be restored and messes with the mouse */ |
284f4730 | 9296 | reset_sys_modes (); |
2ee250ec RS |
9297 | #endif |
9298 | ||
284f4730 JB |
9299 | #ifdef SIGIO |
9300 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
284f4730 | 9301 | if (read_socket_hook) |
9a0f60bb KH |
9302 | { |
9303 | /* When using X, don't give the user a real choice, | |
9304 | because we haven't implemented the mechanisms to support it. */ | |
9305 | #ifdef NO_SOCK_SIGIO | |
9306 | interrupt_input = 0; | |
9307 | #else /* not NO_SOCK_SIGIO */ | |
9308 | interrupt_input = 1; | |
284f4730 | 9309 | #endif /* NO_SOCK_SIGIO */ |
9a0f60bb KH |
9310 | } |
9311 | else | |
284f4730 JB |
9312 | interrupt_input = !NILP (interrupt); |
9313 | #else /* not SIGIO */ | |
9314 | interrupt_input = 0; | |
9315 | #endif /* not SIGIO */ | |
9a0f60bb | 9316 | |
284f4730 JB |
9317 | /* Our VMS input only works by interrupts, as of now. */ |
9318 | #ifdef VMS | |
9319 | interrupt_input = 1; | |
9320 | #endif | |
9a0f60bb | 9321 | |
284f4730 | 9322 | flow_control = !NILP (flow); |
b04904fb RS |
9323 | if (NILP (meta)) |
9324 | meta_key = 0; | |
9325 | else if (EQ (meta, Qt)) | |
9326 | meta_key = 1; | |
9327 | else | |
9328 | meta_key = 2; | |
284f4730 JB |
9329 | if (!NILP (quit)) |
9330 | /* Don't let this value be out of range. */ | |
9331 | quit_char = XINT (quit) & (meta_key ? 0377 : 0177); | |
9332 | ||
07de30b9 | 9333 | #ifndef DOS_NT |
284f4730 | 9334 | init_sys_modes (); |
2ee250ec | 9335 | #endif |
34f04431 RS |
9336 | |
9337 | #ifdef POLL_FOR_INPUT | |
9338 | poll_suppress_count = 1; | |
9339 | start_polling (); | |
9340 | #endif | |
284f4730 JB |
9341 | return Qnil; |
9342 | } | |
80645119 JB |
9343 | |
9344 | DEFUN ("current-input-mode", Fcurrent_input_mode, Scurrent_input_mode, 0, 0, 0, | |
9345 | "Return information about the way Emacs currently reads keyboard input.\n\ | |
9346 | The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\ | |
9347 | INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\ | |
9348 | nil, Emacs is using CBREAK mode.\n\ | |
9349 | FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\ | |
9350 | terminal; this does not apply if Emacs uses interrupt-driven input.\n\ | |
a8ee7ef9 RS |
9351 | META is t if accepting 8-bit input with 8th bit as Meta flag.\n\ |
9352 | META nil means ignoring the top bit, on the assumption it is parity.\n\ | |
9353 | META is neither t nor nil if accepting 8-bit input and using\n\ | |
9354 | all 8 bits as the character code.\n\ | |
80645119 JB |
9355 | QUIT is the character Emacs currently uses to quit.\n\ |
9356 | The elements of this list correspond to the arguments of\n\ | |
a8ee7ef9 | 9357 | `set-input-mode'.") |
80645119 JB |
9358 | () |
9359 | { | |
9360 | Lisp_Object val[4]; | |
9361 | ||
9362 | val[0] = interrupt_input ? Qt : Qnil; | |
9363 | val[1] = flow_control ? Qt : Qnil; | |
a8ee7ef9 | 9364 | val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil; |
bb9e9bed | 9365 | XSETFASTINT (val[3], quit_char); |
80645119 | 9366 | |
bf673a7a | 9367 | return Flist (sizeof (val) / sizeof (val[0]), val); |
80645119 JB |
9368 | } |
9369 | ||
284f4730 | 9370 | \f |
6c6083a9 | 9371 | /* |
c5fdd383 | 9372 | * Set up a new kboard object with reasonable initial values. |
6c6083a9 KH |
9373 | */ |
9374 | void | |
c5fdd383 KH |
9375 | init_kboard (kb) |
9376 | KBOARD *kb; | |
6c6083a9 | 9377 | { |
217258d5 | 9378 | kb->Voverriding_terminal_local_map = Qnil; |
6c7178b9 | 9379 | kb->Vlast_command = Qnil; |
75045dcb | 9380 | kb->Vreal_last_command = Qnil; |
d8bcf58e | 9381 | kb->Vprefix_arg = Qnil; |
75045dcb | 9382 | kb->Vlast_prefix_arg = Qnil; |
c5fdd383 KH |
9383 | kb->kbd_queue = Qnil; |
9384 | kb->kbd_queue_has_data = 0; | |
9385 | kb->immediate_echo = 0; | |
9386 | kb->echoptr = kb->echobuf; | |
9387 | kb->echo_after_prompt = -1; | |
9388 | kb->kbd_macro_buffer = 0; | |
9389 | kb->kbd_macro_bufsize = 0; | |
9390 | kb->defining_kbd_macro = Qnil; | |
9391 | kb->Vlast_kbd_macro = Qnil; | |
9392 | kb->reference_count = 0; | |
7c97ffdc | 9393 | kb->Vsystem_key_alist = Qnil; |
142e6c73 | 9394 | kb->system_key_syms = Qnil; |
9ba47203 | 9395 | kb->Vdefault_minibuffer_frame = Qnil; |
6c6083a9 KH |
9396 | } |
9397 | ||
9398 | /* | |
c5fdd383 | 9399 | * Destroy the contents of a kboard object, but not the object itself. |
8e6208c5 | 9400 | * We use this just before deleting it, or if we're going to initialize |
6c6083a9 KH |
9401 | * it a second time. |
9402 | */ | |
e50b8090 | 9403 | static void |
c5fdd383 KH |
9404 | wipe_kboard (kb) |
9405 | KBOARD *kb; | |
6c6083a9 | 9406 | { |
c5fdd383 KH |
9407 | if (kb->kbd_macro_buffer) |
9408 | xfree (kb->kbd_macro_buffer); | |
6c6083a9 KH |
9409 | } |
9410 | ||
e50b8090 KH |
9411 | #ifdef MULTI_KBOARD |
9412 | void | |
9413 | delete_kboard (kb) | |
9414 | KBOARD *kb; | |
9415 | { | |
9416 | KBOARD **kbp; | |
9417 | for (kbp = &all_kboards; *kbp != kb; kbp = &(*kbp)->next_kboard) | |
9418 | if (*kbp == NULL) | |
9419 | abort (); | |
9420 | *kbp = kb->next_kboard; | |
9421 | wipe_kboard (kb); | |
9422 | xfree (kb); | |
9423 | } | |
9424 | #endif | |
9425 | ||
dfcf069d | 9426 | void |
284f4730 JB |
9427 | init_keyboard () |
9428 | { | |
284f4730 JB |
9429 | /* This is correct before outermost invocation of the editor loop */ |
9430 | command_loop_level = -1; | |
9431 | immediate_quit = 0; | |
9432 | quit_char = Ctl ('g'); | |
24597608 | 9433 | Vunread_command_events = Qnil; |
86e5706b | 9434 | unread_command_char = -1; |
87dd9b9b | 9435 | EMACS_SET_SECS_USECS (timer_idleness_start_time, -1, -1); |
284f4730 | 9436 | total_keys = 0; |
9deb415a | 9437 | recent_keys_index = 0; |
beecf6a1 KH |
9438 | kbd_fetch_ptr = kbd_buffer; |
9439 | kbd_store_ptr = kbd_buffer; | |
9440 | kbd_buffer_frame_or_window | |
9441 | = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil); | |
2eb6bfbe | 9442 | #ifdef HAVE_MOUSE |
a9d77f1f | 9443 | do_mouse_tracking = Qnil; |
2eb6bfbe | 9444 | #endif |
284f4730 JB |
9445 | input_pending = 0; |
9446 | ||
4c52b668 KH |
9447 | /* This means that command_loop_1 won't try to select anything the first |
9448 | time through. */ | |
9449 | internal_last_event_frame = Qnil; | |
9450 | Vlast_event_frame = internal_last_event_frame; | |
4c52b668 | 9451 | |
c5fdd383 | 9452 | #ifdef MULTI_KBOARD |
aaca43a1 | 9453 | current_kboard = initial_kboard; |
6c6083a9 | 9454 | #endif |
aaca43a1 | 9455 | wipe_kboard (current_kboard); |
c5fdd383 | 9456 | init_kboard (current_kboard); |
07d2b8de | 9457 | |
beecf6a1 KH |
9458 | if (initialized) |
9459 | Ffillarray (kbd_buffer_frame_or_window, Qnil); | |
9460 | ||
9461 | kbd_buffer_frame_or_window | |
9462 | = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil); | |
7a80a6f6 | 9463 | if (!noninteractive && !read_socket_hook && NILP (Vwindow_system)) |
284f4730 JB |
9464 | { |
9465 | signal (SIGINT, interrupt_signal); | |
cb5df6ae | 9466 | #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) |
284f4730 JB |
9467 | /* For systems with SysV TERMIO, C-g is set up for both SIGINT and |
9468 | SIGQUIT and we can't tell which one it will give us. */ | |
9469 | signal (SIGQUIT, interrupt_signal); | |
9470 | #endif /* HAVE_TERMIO */ | |
7a80a6f6 | 9471 | } |
284f4730 JB |
9472 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ |
9473 | #ifdef SIGIO | |
7a80a6f6 RS |
9474 | if (!noninteractive) |
9475 | signal (SIGIO, input_available_signal); | |
8ea0a720 | 9476 | #endif /* SIGIO */ |
284f4730 JB |
9477 | |
9478 | /* Use interrupt input by default, if it works and noninterrupt input | |
9479 | has deficiencies. */ | |
9480 | ||
9481 | #ifdef INTERRUPT_INPUT | |
9482 | interrupt_input = 1; | |
9483 | #else | |
9484 | interrupt_input = 0; | |
9485 | #endif | |
9486 | ||
9487 | /* Our VMS input only works by interrupts, as of now. */ | |
9488 | #ifdef VMS | |
9489 | interrupt_input = 1; | |
9490 | #endif | |
9491 | ||
9492 | sigfree (); | |
9493 | dribble = 0; | |
9494 | ||
9495 | if (keyboard_init_hook) | |
9496 | (*keyboard_init_hook) (); | |
9497 | ||
9498 | #ifdef POLL_FOR_INPUT | |
9499 | poll_suppress_count = 1; | |
9500 | start_polling (); | |
9501 | #endif | |
9502 | } | |
9503 | ||
df0f2ba1 | 9504 | /* This type's only use is in syms_of_keyboard, to initialize the |
284f4730 JB |
9505 | event header symbols and put properties on them. */ |
9506 | struct event_head { | |
9507 | Lisp_Object *var; | |
9508 | char *name; | |
9509 | Lisp_Object *kind; | |
9510 | }; | |
9511 | ||
9512 | struct event_head head_table[] = { | |
7b4aedb9 | 9513 | &Qmouse_movement, "mouse-movement", &Qmouse_movement, |
3c370943 | 9514 | &Qscroll_bar_movement, "scroll-bar-movement", &Qmouse_movement, |
7b4aedb9 | 9515 | &Qswitch_frame, "switch-frame", &Qswitch_frame, |
bbdc2092 | 9516 | &Qdelete_frame, "delete-frame", &Qdelete_frame, |
af17bd2b KH |
9517 | &Qiconify_frame, "iconify-frame", &Qiconify_frame, |
9518 | &Qmake_frame_visible, "make-frame-visible", &Qmake_frame_visible, | |
284f4730 JB |
9519 | }; |
9520 | ||
dfcf069d | 9521 | void |
284f4730 JB |
9522 | syms_of_keyboard () |
9523 | { | |
9ea173e8 | 9524 | /* Tool-bars. */ |
7ee32cda GM |
9525 | QCimage = intern (":image"); |
9526 | staticpro (&QCimage); | |
9527 | ||
9528 | staticpro (&Qhelp_echo); | |
9529 | Qhelp_echo = intern ("help-echo"); | |
9530 | ||
e8886a1d RS |
9531 | staticpro (&item_properties); |
9532 | item_properties = Qnil; | |
9533 | ||
9ea173e8 GM |
9534 | staticpro (&tool_bar_item_properties); |
9535 | tool_bar_item_properties = Qnil; | |
9536 | staticpro (&tool_bar_items_vector); | |
9537 | tool_bar_items_vector = Qnil; | |
7ee32cda | 9538 | |
d5eecefb RS |
9539 | staticpro (&real_this_command); |
9540 | real_this_command = Qnil; | |
9541 | ||
d925fb39 RS |
9542 | Qtimer_event_handler = intern ("timer-event-handler"); |
9543 | staticpro (&Qtimer_event_handler); | |
9544 | ||
2e894dab RS |
9545 | Qdisabled_command_hook = intern ("disabled-command-hook"); |
9546 | staticpro (&Qdisabled_command_hook); | |
9547 | ||
284f4730 JB |
9548 | Qself_insert_command = intern ("self-insert-command"); |
9549 | staticpro (&Qself_insert_command); | |
9550 | ||
9551 | Qforward_char = intern ("forward-char"); | |
9552 | staticpro (&Qforward_char); | |
9553 | ||
9554 | Qbackward_char = intern ("backward-char"); | |
9555 | staticpro (&Qbackward_char); | |
9556 | ||
9557 | Qdisabled = intern ("disabled"); | |
9558 | staticpro (&Qdisabled); | |
9559 | ||
e58aa385 RS |
9560 | Qundefined = intern ("undefined"); |
9561 | staticpro (&Qundefined); | |
9562 | ||
86e5706b RS |
9563 | Qpre_command_hook = intern ("pre-command-hook"); |
9564 | staticpro (&Qpre_command_hook); | |
9565 | ||
9566 | Qpost_command_hook = intern ("post-command-hook"); | |
9567 | staticpro (&Qpost_command_hook); | |
9568 | ||
59aadc81 RS |
9569 | Qpost_command_idle_hook = intern ("post-command-idle-hook"); |
9570 | staticpro (&Qpost_command_idle_hook); | |
9571 | ||
3ef14e46 RS |
9572 | Qdeferred_action_function = intern ("deferred-action-function"); |
9573 | staticpro (&Qdeferred_action_function); | |
9574 | ||
40932d1a RS |
9575 | Qcommand_hook_internal = intern ("command-hook-internal"); |
9576 | staticpro (&Qcommand_hook_internal); | |
9577 | ||
284f4730 JB |
9578 | Qfunction_key = intern ("function-key"); |
9579 | staticpro (&Qfunction_key); | |
13b5e56c | 9580 | Qmouse_click = intern ("mouse-click"); |
284f4730 | 9581 | staticpro (&Qmouse_click); |
07de30b9 GV |
9582 | #ifdef WINDOWSNT |
9583 | Qmouse_wheel = intern ("mouse-wheel"); | |
9584 | staticpro (&Qmouse_wheel); | |
1161d367 GV |
9585 | Qlanguage_change = intern ("language-change"); |
9586 | staticpro (&Qlanguage_change); | |
07de30b9 | 9587 | #endif |
a24dc617 RS |
9588 | Qdrag_n_drop = intern ("drag-n-drop"); |
9589 | staticpro (&Qdrag_n_drop); | |
284f4730 | 9590 | |
5bf68f6e AS |
9591 | Qusr1_signal = intern ("usr1-signal"); |
9592 | staticpro (&Qusr1_signal); | |
9593 | Qusr2_signal = intern ("usr2-signal"); | |
9594 | staticpro (&Qusr2_signal); | |
9595 | ||
598a9fa7 JB |
9596 | Qmenu_enable = intern ("menu-enable"); |
9597 | staticpro (&Qmenu_enable); | |
e8886a1d RS |
9598 | Qmenu_alias = intern ("menu-alias"); |
9599 | staticpro (&Qmenu_alias); | |
9600 | QCenable = intern (":enable"); | |
9601 | staticpro (&QCenable); | |
9602 | QCvisible = intern (":visible"); | |
9603 | staticpro (&QCvisible); | |
7ee32cda GM |
9604 | QChelp = intern (":help"); |
9605 | staticpro (&QChelp); | |
e8886a1d RS |
9606 | QCfilter = intern (":filter"); |
9607 | staticpro (&QCfilter); | |
9608 | QCbutton = intern (":button"); | |
9609 | staticpro (&QCbutton); | |
74c1de23 RS |
9610 | QCkeys = intern (":keys"); |
9611 | staticpro (&QCkeys); | |
9612 | QCkey_sequence = intern (":key-sequence"); | |
9613 | staticpro (&QCkey_sequence); | |
e8886a1d RS |
9614 | QCtoggle = intern (":toggle"); |
9615 | staticpro (&QCtoggle); | |
9616 | QCradio = intern (":radio"); | |
9617 | staticpro (&QCradio); | |
598a9fa7 | 9618 | |
284f4730 JB |
9619 | Qmode_line = intern ("mode-line"); |
9620 | staticpro (&Qmode_line); | |
e5d77022 JB |
9621 | Qvertical_line = intern ("vertical-line"); |
9622 | staticpro (&Qvertical_line); | |
3c370943 JB |
9623 | Qvertical_scroll_bar = intern ("vertical-scroll-bar"); |
9624 | staticpro (&Qvertical_scroll_bar); | |
5ec75a55 RS |
9625 | Qmenu_bar = intern ("menu-bar"); |
9626 | staticpro (&Qmenu_bar); | |
4bb994d1 JB |
9627 | |
9628 | Qabove_handle = intern ("above-handle"); | |
9629 | staticpro (&Qabove_handle); | |
9630 | Qhandle = intern ("handle"); | |
9631 | staticpro (&Qhandle); | |
9632 | Qbelow_handle = intern ("below-handle"); | |
9633 | staticpro (&Qbelow_handle); | |
db08707d RS |
9634 | Qup = intern ("up"); |
9635 | staticpro (&Qup); | |
9636 | Qdown = intern ("down"); | |
9637 | staticpro (&Qdown); | |
7ee32cda GM |
9638 | Qtop = intern ("top"); |
9639 | staticpro (&Qtop); | |
9640 | Qbottom = intern ("bottom"); | |
9641 | staticpro (&Qbottom); | |
9642 | Qend_scroll = intern ("end-scroll"); | |
9643 | staticpro (&Qend_scroll); | |
284f4730 | 9644 | |
cd21b839 | 9645 | Qevent_kind = intern ("event-kind"); |
284f4730 | 9646 | staticpro (&Qevent_kind); |
88cb0656 JB |
9647 | Qevent_symbol_elements = intern ("event-symbol-elements"); |
9648 | staticpro (&Qevent_symbol_elements); | |
0a7f1fc0 JB |
9649 | Qevent_symbol_element_mask = intern ("event-symbol-element-mask"); |
9650 | staticpro (&Qevent_symbol_element_mask); | |
9651 | Qmodifier_cache = intern ("modifier-cache"); | |
9652 | staticpro (&Qmodifier_cache); | |
284f4730 | 9653 | |
48e416d4 RS |
9654 | Qrecompute_lucid_menubar = intern ("recompute-lucid-menubar"); |
9655 | staticpro (&Qrecompute_lucid_menubar); | |
9656 | Qactivate_menubar_hook = intern ("activate-menubar-hook"); | |
9657 | staticpro (&Qactivate_menubar_hook); | |
9658 | ||
f4eef8b4 RS |
9659 | Qpolling_period = intern ("polling-period"); |
9660 | staticpro (&Qpolling_period); | |
9661 | ||
7d18f9ae RS |
9662 | Qinput_method_function = intern ("input-method-function"); |
9663 | staticpro (&Qinput_method_function); | |
9664 | ||
d5eecefb RS |
9665 | Qinput_method_exit_on_first_char = intern ("input-method-exit-on-first-char"); |
9666 | staticpro (&Qinput_method_exit_on_first_char); | |
9667 | Qinput_method_use_echo_area = intern ("input-method-use-echo-area"); | |
9668 | staticpro (&Qinput_method_use_echo_area); | |
9669 | ||
9670 | Fset (Qinput_method_exit_on_first_char, Qnil); | |
9671 | Fset (Qinput_method_use_echo_area, Qnil); | |
9672 | ||
284f4730 JB |
9673 | { |
9674 | struct event_head *p; | |
9675 | ||
9676 | for (p = head_table; | |
9677 | p < head_table + (sizeof (head_table) / sizeof (head_table[0])); | |
9678 | p++) | |
9679 | { | |
9680 | *p->var = intern (p->name); | |
9681 | staticpro (p->var); | |
9682 | Fput (*p->var, Qevent_kind, *p->kind); | |
88cb0656 | 9683 | Fput (*p->var, Qevent_symbol_elements, Fcons (*p->var, Qnil)); |
284f4730 JB |
9684 | } |
9685 | } | |
9686 | ||
7b4aedb9 JB |
9687 | button_down_location = Fmake_vector (make_number (NUM_MOUSE_BUTTONS), Qnil); |
9688 | staticpro (&button_down_location); | |
88cb0656 JB |
9689 | |
9690 | { | |
9691 | int i; | |
9692 | int len = sizeof (modifier_names) / sizeof (modifier_names[0]); | |
9693 | ||
9694 | modifier_symbols = Fmake_vector (make_number (len), Qnil); | |
9695 | for (i = 0; i < len; i++) | |
86e5706b RS |
9696 | if (modifier_names[i]) |
9697 | XVECTOR (modifier_symbols)->contents[i] = intern (modifier_names[i]); | |
88cb0656 JB |
9698 | staticpro (&modifier_symbols); |
9699 | } | |
9700 | ||
9deb415a JB |
9701 | recent_keys = Fmake_vector (make_number (NUM_RECENT_KEYS), Qnil); |
9702 | staticpro (&recent_keys); | |
9703 | ||
6569cc8d | 9704 | this_command_keys = Fmake_vector (make_number (40), Qnil); |
715d9345 | 9705 | staticpro (&this_command_keys); |
6569cc8d | 9706 | |
7d18f9ae RS |
9707 | raw_keybuf = Fmake_vector (make_number (30), Qnil); |
9708 | staticpro (&raw_keybuf); | |
9709 | ||
03b4122a BF |
9710 | Qextended_command_history = intern ("extended-command-history"); |
9711 | Fset (Qextended_command_history, Qnil); | |
9712 | staticpro (&Qextended_command_history); | |
9713 | ||
beecf6a1 KH |
9714 | kbd_buffer_frame_or_window |
9715 | = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil); | |
9716 | staticpro (&kbd_buffer_frame_or_window); | |
9717 | ||
24597608 RS |
9718 | accent_key_syms = Qnil; |
9719 | staticpro (&accent_key_syms); | |
9720 | ||
284f4730 JB |
9721 | func_key_syms = Qnil; |
9722 | staticpro (&func_key_syms); | |
9723 | ||
9724 | mouse_syms = Qnil; | |
9725 | staticpro (&mouse_syms); | |
9726 | ||
07de30b9 GV |
9727 | #ifdef WINDOWSNT |
9728 | mouse_wheel_syms = Qnil; | |
9729 | staticpro (&mouse_wheel_syms); | |
a24dc617 RS |
9730 | |
9731 | drag_n_drop_syms = Qnil; | |
9732 | staticpro (&drag_n_drop_syms); | |
07de30b9 GV |
9733 | #endif |
9734 | ||
cd21b839 JB |
9735 | unread_switch_frame = Qnil; |
9736 | staticpro (&unread_switch_frame); | |
9737 | ||
fe412364 EN |
9738 | internal_last_event_frame = Qnil; |
9739 | staticpro (&internal_last_event_frame); | |
9740 | ||
9741 | read_key_sequence_cmd = Qnil; | |
9742 | staticpro (&read_key_sequence_cmd); | |
9743 | ||
759860a6 RS |
9744 | menu_bar_one_keymap_changed_items = Qnil; |
9745 | staticpro (&menu_bar_one_keymap_changed_items); | |
9746 | ||
a1706c30 | 9747 | defsubr (&Sevent_convert_list); |
284f4730 | 9748 | defsubr (&Sread_key_sequence); |
e39da3d7 | 9749 | defsubr (&Sread_key_sequence_vector); |
284f4730 | 9750 | defsubr (&Srecursive_edit); |
2eb6bfbe | 9751 | #ifdef HAVE_MOUSE |
284f4730 | 9752 | defsubr (&Strack_mouse); |
2eb6bfbe | 9753 | #endif |
284f4730 JB |
9754 | defsubr (&Sinput_pending_p); |
9755 | defsubr (&Scommand_execute); | |
9756 | defsubr (&Srecent_keys); | |
9757 | defsubr (&Sthis_command_keys); | |
e39da3d7 | 9758 | defsubr (&Sthis_command_keys_vector); |
6321824f | 9759 | defsubr (&Sthis_single_command_keys); |
7d18f9ae | 9760 | defsubr (&Sthis_single_command_raw_keys); |
71918b75 | 9761 | defsubr (&Sreset_this_command_lengths); |
82e6e5af | 9762 | defsubr (&Sclear_this_command_keys); |
284f4730 JB |
9763 | defsubr (&Ssuspend_emacs); |
9764 | defsubr (&Sabort_recursive_edit); | |
9765 | defsubr (&Sexit_recursive_edit); | |
9766 | defsubr (&Srecursion_depth); | |
9767 | defsubr (&Stop_level); | |
9768 | defsubr (&Sdiscard_input); | |
9769 | defsubr (&Sopen_dribble_file); | |
9770 | defsubr (&Sset_input_mode); | |
80645119 | 9771 | defsubr (&Scurrent_input_mode); |
284f4730 JB |
9772 | defsubr (&Sexecute_extended_command); |
9773 | ||
284f4730 | 9774 | DEFVAR_LISP ("last-command-char", &last_command_char, |
86e5706b RS |
9775 | "Last input event that was part of a command."); |
9776 | ||
186cf719 | 9777 | DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char, |
86e5706b | 9778 | "Last input event that was part of a command."); |
284f4730 | 9779 | |
7d6de002 | 9780 | DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event, |
86e5706b | 9781 | "Last input event in a command, except for mouse menu events.\n\ |
7d6de002 RS |
9782 | Mouse menus give back keys that don't look like mouse events;\n\ |
9783 | this variable holds the actual mouse event that led to the menu,\n\ | |
9784 | so that you can determine whether the command was run by mouse or not."); | |
9785 | ||
284f4730 | 9786 | DEFVAR_LISP ("last-input-char", &last_input_char, |
86e5706b RS |
9787 | "Last input event."); |
9788 | ||
186cf719 | 9789 | DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char, |
86e5706b | 9790 | "Last input event."); |
284f4730 | 9791 | |
24597608 | 9792 | DEFVAR_LISP ("unread-command-events", &Vunread_command_events, |
7d18f9ae RS |
9793 | "List of events to be read as the command input.\n\ |
9794 | These events are processed first, before actual keyboard input."); | |
9795 | Vunread_command_events = Qnil; | |
284f4730 | 9796 | |
86e5706b RS |
9797 | DEFVAR_INT ("unread-command-char", &unread_command_char, |
9798 | "If not -1, an object to be read as next command input event."); | |
9799 | ||
7d18f9ae RS |
9800 | DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events, |
9801 | "List of events to be processed as input by input methods.\n\ | |
9802 | These events are processed after `unread-command-events', but\n\ | |
9803 | before actual keyboard input."); | |
9804 | Vunread_post_input_method_events = Qnil; | |
9805 | ||
9806 | DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events, | |
9807 | "List of events to be processed as input by input methods.\n\ | |
9808 | These events are processed after `unread-command-events', but\n\ | |
9809 | before actual keyboard input."); | |
9810 | Vunread_input_method_events = Qnil; | |
9811 | ||
284f4730 | 9812 | DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char, |
b283f79e KH |
9813 | "Meta-prefix character code.\n\ |
9814 | Meta-foo as command input turns into this character followed by foo."); | |
18cd2eeb | 9815 | XSETINT (meta_prefix_char, 033); |
284f4730 | 9816 | |
6c7178b9 | 9817 | DEFVAR_KBOARD ("last-command", Vlast_command, |
b283f79e KH |
9818 | "The last command executed.\n\ |
9819 | Normally a symbol with a function definition, but can be whatever was found\n\ | |
9820 | in the keymap, or whatever the variable `this-command' was set to by that\n\ | |
9821 | command.\n\ | |
18f29056 RS |
9822 | \n\ |
9823 | The value `mode-exit' is special; it means that the previous command\n\ | |
9824 | read an event that told it to exit, and it did so and unread that event.\n\ | |
9825 | In other words, the present command is the event that made the previous\n\ | |
9826 | command exit.\n\ | |
9827 | \n\ | |
9828 | The value `kill-region' is special; it means that the previous command\n\ | |
9829 | was a kill command."); | |
284f4730 | 9830 | |
75045dcb RS |
9831 | DEFVAR_KBOARD ("real-last-command", Vreal_last_command, |
9832 | "Same as `last-command', but never altered by Lisp code."); | |
9833 | ||
d5eecefb | 9834 | DEFVAR_LISP ("this-command", &Vthis_command, |
284f4730 JB |
9835 | "The command now being executed.\n\ |
9836 | The command can set this variable; whatever is put here\n\ | |
9837 | will be in `last-command' during the following command."); | |
d5eecefb | 9838 | Vthis_command = Qnil; |
284f4730 JB |
9839 | |
9840 | DEFVAR_INT ("auto-save-interval", &auto_save_interval, | |
9841 | "*Number of keyboard input characters between auto-saves.\n\ | |
9842 | Zero means disable autosaving due to number of characters typed."); | |
9843 | auto_save_interval = 300; | |
9844 | ||
9845 | DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout, | |
9846 | "*Number of seconds idle time before auto-save.\n\ | |
06ef7355 RS |
9847 | Zero or nil means disable auto-saving due to idleness.\n\ |
9848 | After auto-saving due to this many seconds of idle time,\n\ | |
84447c71 | 9849 | Emacs also does a garbage collection if that seems to be warranted."); |
bb9e9bed | 9850 | XSETFASTINT (Vauto_save_timeout, 30); |
284f4730 JB |
9851 | |
9852 | DEFVAR_INT ("echo-keystrokes", &echo_keystrokes, | |
9853 | "*Nonzero means echo unfinished commands after this many seconds of pause."); | |
9854 | echo_keystrokes = 1; | |
9855 | ||
9856 | DEFVAR_INT ("polling-period", &polling_period, | |
9857 | "*Interval between polling for input during Lisp execution.\n\ | |
9858 | The reason for polling is to make C-g work to stop a running program.\n\ | |
9859 | Polling is needed only when using X windows and SIGIO does not work.\n\ | |
9860 | Polling is automatically disabled in all other cases."); | |
9861 | polling_period = 2; | |
df0f2ba1 | 9862 | |
564dc952 | 9863 | DEFVAR_LISP ("double-click-time", &Vdouble_click_time, |
fbcd35bd | 9864 | "*Maximum time between mouse clicks to make a double-click.\n\ |
564dc952 JB |
9865 | Measured in milliseconds. nil means disable double-click recognition;\n\ |
9866 | t means double-clicks have no time limit and are detected\n\ | |
fbcd35bd | 9867 | by position only."); |
aab06933 | 9868 | Vdouble_click_time = make_number (500); |
fbcd35bd | 9869 | |
03361bcc RS |
9870 | DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus, |
9871 | "*Non-nil means inhibit local map menu bar menus."); | |
9872 | inhibit_local_menu_bar_menus = 0; | |
9873 | ||
284f4730 | 9874 | DEFVAR_INT ("num-input-keys", &num_input_keys, |
c43b1734 | 9875 | "Number of complete key sequences read as input so far.\n\ |
58ce35fb KH |
9876 | This includes key sequences read from keyboard macros.\n\ |
9877 | The number is effectively the number of interactive command invocations."); | |
284f4730 JB |
9878 | num_input_keys = 0; |
9879 | ||
c43b1734 RS |
9880 | DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events, |
9881 | "Number of input events read from the keyboard so far.\n\ | |
9882 | This does not include events generated by keyboard macros."); | |
9883 | num_nonmacro_input_events = 0; | |
fa90970d | 9884 | |
4c52b668 KH |
9885 | DEFVAR_LISP ("last-event-frame", &Vlast_event_frame, |
9886 | "The frame in which the most recently read event occurred.\n\ | |
9887 | If the last event came from a keyboard macro, this is set to `macro'."); | |
9888 | Vlast_event_frame = Qnil; | |
9889 | ||
fa90970d RS |
9890 | /* This variable is set up in sysdep.c. */ |
9891 | DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char, | |
9892 | "The ERASE character as set by the user with stty."); | |
9893 | ||
7e85b935 | 9894 | DEFVAR_LISP ("help-char", &Vhelp_char, |
284f4730 JB |
9895 | "Character to recognize as meaning Help.\n\ |
9896 | When it is read, do `(eval help-form)', and display result if it's a string.\n\ | |
9897 | If the value of `help-form' is nil, this char can be read normally."); | |
18cd2eeb | 9898 | XSETINT (Vhelp_char, Ctl ('H')); |
284f4730 | 9899 | |
ecb7cb34 KH |
9900 | DEFVAR_LISP ("help-event-list", &Vhelp_event_list, |
9901 | "List of input events to recognize as meaning Help.\n\ | |
9902 | These work just like the value of `help-char' (see that)."); | |
9903 | Vhelp_event_list = Qnil; | |
9904 | ||
284f4730 | 9905 | DEFVAR_LISP ("help-form", &Vhelp_form, |
7e85b935 | 9906 | "Form to execute when character `help-char' is read.\n\ |
284f4730 JB |
9907 | If the form returns a string, that string is displayed.\n\ |
9908 | If `help-form' is nil, the help char is not recognized."); | |
9909 | Vhelp_form = Qnil; | |
9910 | ||
7e85b935 RS |
9911 | DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command, |
9912 | "Command to run when `help-char' character follows a prefix key.\n\ | |
9913 | This command is used only when there is no actual binding\n\ | |
9914 | for that character after that prefix key."); | |
9915 | Vprefix_help_command = Qnil; | |
9916 | ||
284f4730 JB |
9917 | DEFVAR_LISP ("top-level", &Vtop_level, |
9918 | "Form to evaluate when Emacs starts up.\n\ | |
9919 | Useful to set before you dump a modified Emacs."); | |
9920 | Vtop_level = Qnil; | |
9921 | ||
9922 | DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table, | |
f9414d62 | 9923 | "Translate table for keyboard input, or nil.\n\ |
284f4730 | 9924 | Each character is looked up in this string and the contents used instead.\n\ |
f9414d62 RS |
9925 | The value may be a string, a vector, or a char-table.\n\ |
9926 | If it is a string or vector of length N,\n\ | |
9927 | character codes N and up are untranslated.\n\ | |
9928 | In a vector or a char-table, an element which is nil means \"no translation\"."); | |
284f4730 JB |
9929 | Vkeyboard_translate_table = Qnil; |
9930 | ||
8026024c | 9931 | DEFVAR_BOOL ("cannot-suspend", &cannot_suspend, |
b283f79e KH |
9932 | "Non-nil means to always spawn a subshell instead of suspending.\n\ |
9933 | \(Even if the operating system has support for stopping a process.\)"); | |
8026024c KH |
9934 | cannot_suspend = 0; |
9935 | ||
284f4730 | 9936 | DEFVAR_BOOL ("menu-prompting", &menu_prompting, |
7d6de002 | 9937 | "Non-nil means prompt with menus when appropriate.\n\ |
284f4730 | 9938 | This is done when reading from a keymap that has a prompt string,\n\ |
7d6de002 RS |
9939 | for elements that have prompt strings.\n\ |
9940 | The menu is displayed on the screen\n\ | |
9941 | if X menus were enabled at configuration\n\ | |
9942 | time and the previous event was a mouse click prefix key.\n\ | |
9943 | Otherwise, menu prompting uses the echo area."); | |
284f4730 JB |
9944 | menu_prompting = 1; |
9945 | ||
9946 | DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char, | |
9947 | "Character to see next line of menu prompt.\n\ | |
9948 | Type this character while in a menu prompt to rotate around the lines of it."); | |
18cd2eeb | 9949 | XSETINT (menu_prompt_more_char, ' '); |
9fa4395d RS |
9950 | |
9951 | DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers, | |
9952 | "A mask of additional modifier keys to use with every keyboard character.\n\ | |
ad163903 JB |
9953 | Emacs applies the modifiers of the character stored here to each keyboard\n\ |
9954 | character it reads. For example, after evaluating the expression\n\ | |
9d9f56dd | 9955 | (setq extra-keyboard-modifiers ?\\C-x)\n\ |
80645119 JB |
9956 | all input characters will have the control modifier applied to them.\n\ |
9957 | \n\ | |
9d9f56dd | 9958 | Note that the character ?\\C-@, equivalent to the integer zero, does\n\ |
80645119 | 9959 | not count as a control character; rather, it counts as a character\n\ |
27203ead | 9960 | with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\ |
80645119 | 9961 | cancels any modification."); |
9fa4395d | 9962 | extra_keyboard_modifiers = 0; |
86e5706b RS |
9963 | |
9964 | DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark, | |
9965 | "If an editing command sets this to t, deactivate the mark afterward.\n\ | |
9966 | The command loop sets this to nil before each command,\n\ | |
9967 | and tests the value when the command returns.\n\ | |
9968 | Buffer modification stores t in this variable."); | |
9969 | Vdeactivate_mark = Qnil; | |
9970 | ||
b0f2a7bf KH |
9971 | DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal, |
9972 | "Temporary storage of pre-command-hook or post-command-hook."); | |
9973 | Vcommand_hook_internal = Qnil; | |
9974 | ||
86e5706b | 9975 | DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook, |
a1fd42c0 | 9976 | "Normal hook run before each command is executed.\n\ |
307958d6 RS |
9977 | If an unhandled error happens in running this hook,\n\ |
9978 | the hook value is set to nil, since otherwise the error\n\ | |
9979 | might happen repeatedly and make Emacs nonfunctional."); | |
86e5706b RS |
9980 | Vpre_command_hook = Qnil; |
9981 | ||
9982 | DEFVAR_LISP ("post-command-hook", &Vpost_command_hook, | |
a1fd42c0 | 9983 | "Normal hook run after each command is executed.\n\ |
307958d6 RS |
9984 | If an unhandled error happens in running this hook,\n\ |
9985 | the hook value is set to nil, since otherwise the error\n\ | |
9986 | might happen repeatedly and make Emacs nonfunctional."); | |
86e5706b | 9987 | Vpost_command_hook = Qnil; |
48e416d4 | 9988 | |
59aadc81 RS |
9989 | DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook, |
9990 | "Normal hook run after each command is executed, if idle.\n\ | |
d4d62e8d RS |
9991 | Errors running the hook are caught and ignored.\n\ |
9992 | This feature is obsolete; use idle timers instead. See `etc/NEWS'."); | |
59aadc81 RS |
9993 | Vpost_command_idle_hook = Qnil; |
9994 | ||
9995 | DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay, | |
7051b69b | 9996 | "Delay time before running `post-command-idle-hook'.\n\ |
59aadc81 RS |
9997 | This is measured in microseconds."); |
9998 | post_command_idle_delay = 100000; | |
9999 | ||
cdb9d665 RS |
10000 | #if 0 |
10001 | DEFVAR_LISP ("echo-area-clear-hook", ..., | |
10002 | "Normal hook run when clearing the echo area."); | |
10003 | #endif | |
10004 | Qecho_area_clear_hook = intern ("echo-area-clear-hook"); | |
10005 | XSYMBOL (Qecho_area_clear_hook)->value = Qnil; | |
10006 | ||
48e416d4 RS |
10007 | DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag, |
10008 | "t means menu bar, specified Lucid style, needs to be recomputed."); | |
10009 | Vlucid_menu_bar_dirty_flag = Qnil; | |
a73c5e29 | 10010 | |
9f9c0e27 RS |
10011 | DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items, |
10012 | "List of menu bar items to move to the end of the menu bar.\n\ | |
a612e298 | 10013 | The elements of the list are event types that may have menu bar bindings."); |
9f9c0e27 | 10014 | Vmenu_bar_final_items = Qnil; |
e9bf89a0 | 10015 | |
217258d5 KH |
10016 | DEFVAR_KBOARD ("overriding-terminal-local-map", |
10017 | Voverriding_terminal_local_map, | |
779b34df | 10018 | "Per-terminal keymap that overrides all other local keymaps.\n\ |
217258d5 | 10019 | If this variable is non-nil, it is used as a keymap instead of the\n\ |
779b34df RS |
10020 | buffer's local map, and the minor mode keymaps and text property keymaps.\n\ |
10021 | This variable is intended to let commands such as `universal-argumemnt'\n\ | |
10022 | set up a different keymap for reading the next command."); | |
217258d5 | 10023 | |
9dd3131c RS |
10024 | DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map, |
10025 | "Keymap that overrides all other local keymaps.\n\ | |
10026 | If this variable is non-nil, it is used as a keymap instead of the\n\ | |
10027 | buffer's local map, and the minor mode keymaps and text property keymaps."); | |
10028 | Voverriding_local_map = Qnil; | |
10029 | ||
d0a49716 RS |
10030 | DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag, |
10031 | "Non-nil means `overriding-local-map' applies to the menu bar.\n\ | |
10032 | Otherwise, the menu bar continues to reflect the buffer's local map\n\ | |
10033 | and the minor mode maps regardless of `overriding-local-map'."); | |
10034 | Voverriding_local_map_menu_flag = Qnil; | |
10035 | ||
7f07d5ca RS |
10036 | DEFVAR_LISP ("special-event-map", &Vspecial_event_map, |
10037 | "Keymap defining bindings for special events to execute at low level."); | |
10038 | Vspecial_event_map = Fcons (intern ("keymap"), Qnil); | |
10039 | ||
71edead1 | 10040 | DEFVAR_LISP ("track-mouse", &do_mouse_tracking, |
a53c7666 | 10041 | "*Non-nil means generate motion events for mouse motion."); |
80e4aa30 | 10042 | |
7c97ffdc | 10043 | DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist, |
270a208f | 10044 | "Alist of system-specific X windows key symbols.\n\ |
80e4aa30 | 10045 | Each element should have the form (N . SYMBOL) where N is the\n\ |
270a208f | 10046 | numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\ |
80e4aa30 | 10047 | and SYMBOL is its name."); |
8a792f3a RS |
10048 | |
10049 | DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list, | |
10050 | "List of deferred actions to be performed at a later time.\n\ | |
10051 | The precise format isn't relevant here; we just check whether it is nil."); | |
10052 | Vdeferred_action_list = Qnil; | |
10053 | ||
10054 | DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function, | |
10055 | "Function to call to handle deferred actions, after each command.\n\ | |
10056 | This function is called with no arguments after each command\n\ | |
10057 | whenever `deferred-action-list' is non-nil."); | |
10058 | Vdeferred_action_function = Qnil; | |
6526ab49 RS |
10059 | |
10060 | DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings, | |
ac52ebd5 | 10061 | "*Non-nil means show the equivalent key-binding when M-x command has one.\n\ |
6526ab49 RS |
10062 | The value can be a length of time to show the message for.\n\ |
10063 | If the value is non-nil and not a number, we wait 2 seconds."); | |
10064 | Vsuggest_key_bindings = Qt; | |
8bb1c042 | 10065 | |
c04cbc3b | 10066 | DEFVAR_LISP ("timer-list", &Vtimer_list, |
d9d4c147 | 10067 | "List of active absolute time timers in order of increasing time"); |
c04cbc3b | 10068 | Vtimer_list = Qnil; |
d9d4c147 KH |
10069 | |
10070 | DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list, | |
10071 | "List of active idle-time timers in order of increasing time"); | |
10072 | Vtimer_idle_list = Qnil; | |
7d18f9ae RS |
10073 | |
10074 | DEFVAR_LISP ("input-method-function", &Vinput_method_function, | |
10075 | "If non-nil, the function that implements the current input method.\n\ | |
10076 | It's called with one argument, a printing character that was just read.\n\ | |
10077 | \(That means a character with code 040...0176.)\n\ | |
10078 | Typically this function uses `read-event' to read additional events.\n\ | |
10079 | When it does so, it should first bind `input-method-function' to nil\n\ | |
10080 | so it will not be called recursively.\n\ | |
10081 | \n\ | |
10082 | The function should return a list of zero or more events\n\ | |
10083 | to be used as input. If it wants to put back some events\n\ | |
10084 | to be reconsidered, separately, by the input method,\n\ | |
d5eecefb RS |
10085 | it can add them to the beginning of `unread-command-events'.\n\ |
10086 | \n\ | |
10087 | The input method function can find in `input-method-previous-method'\n\ | |
10088 | the previous echo area message.\n\ | |
10089 | \n\ | |
10090 | The input method function should refer to the variables\n\ | |
10091 | `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\ | |
10092 | for guidance on what to do."); | |
7d18f9ae | 10093 | Vinput_method_function = Qnil; |
d5eecefb RS |
10094 | |
10095 | DEFVAR_LISP ("input-method-previous-message", | |
10096 | &Vinput_method_previous_message, | |
a8b13665 | 10097 | "When `input-method-function' is called, hold the previous echo area message.\n\ |
d5eecefb RS |
10098 | This variable exists because `read-event' clears the echo area\n\ |
10099 | before running the input method. It is nil if there was no message."); | |
10100 | Vinput_method_previous_message = Qnil; | |
7ee32cda GM |
10101 | |
10102 | DEFVAR_LISP ("show-help-function", &Vshow_help_function, | |
10103 | "If non-nil, the function that implements the display of help.\n\ | |
10104 | It's called with one argument, the help string to display."); | |
10105 | Vshow_help_function = Qnil; | |
284f4730 JB |
10106 | } |
10107 | ||
dfcf069d | 10108 | void |
284f4730 JB |
10109 | keys_of_keyboard () |
10110 | { | |
10111 | initial_define_key (global_map, Ctl ('Z'), "suspend-emacs"); | |
10112 | initial_define_key (control_x_map, Ctl ('Z'), "suspend-emacs"); | |
10113 | initial_define_key (meta_map, Ctl ('C'), "exit-recursive-edit"); | |
10114 | initial_define_key (global_map, Ctl (']'), "abort-recursive-edit"); | |
10115 | initial_define_key (meta_map, 'x', "execute-extended-command"); | |
7f07d5ca RS |
10116 | |
10117 | initial_define_lispy_key (Vspecial_event_map, "delete-frame", | |
10118 | "handle-delete-frame"); | |
10119 | initial_define_lispy_key (Vspecial_event_map, "iconify-frame", | |
10120 | "ignore-event"); | |
10121 | initial_define_lispy_key (Vspecial_event_map, "make-frame-visible", | |
10122 | "ignore-event"); | |
284f4730 | 10123 | } |