Commit | Line | Data |
---|---|---|
284f4730 | 1 | /* Keyboard and mouse input; editor command loop. |
39aab679 DL |
2 | Copyright (C) 1985,86,87,88,89,93,94,95,96,97,99, 2000 |
3 | Free Software Foundation, Inc. | |
284f4730 JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
7 | GNU Emacs is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
7b4aedb9 | 9 | the Free Software Foundation; either version 2, or (at your option) |
284f4730 JB |
10 | any later version. |
11 | ||
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU Emacs; see the file COPYING. If not, write to | |
3b7ad313 EN |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
284f4730 | 21 | |
18160b98 | 22 | #include <config.h> |
68c45bf0 | 23 | #include <signal.h> |
284f4730 | 24 | #include <stdio.h> |
284f4730 JB |
25 | #include "termchar.h" |
26 | #include "termopts.h" | |
27 | #include "lisp.h" | |
28 | #include "termhooks.h" | |
29 | #include "macros.h" | |
02639609 | 30 | #include "keyboard.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" |
e39da3d7 | 38 | #include "syntax.h" |
497ba7a1 | 39 | #include "intervals.h" |
9ac0d9e0 | 40 | #include "blockinput.h" |
e8886a1d | 41 | #include "puresize.h" |
8a9f5d3c GM |
42 | #include "systime.h" |
43 | #include "atimer.h" | |
284f4730 JB |
44 | #include <setjmp.h> |
45 | #include <errno.h> | |
46 | ||
80e4aa30 RS |
47 | #ifdef MSDOS |
48 | #include "msdos.h" | |
49 | #include <time.h> | |
50 | #else /* not MSDOS */ | |
284f4730 JB |
51 | #ifndef VMS |
52 | #include <sys/ioctl.h> | |
284f4730 | 53 | #endif |
80e4aa30 | 54 | #endif /* not MSDOS */ |
284f4730 | 55 | |
52baf19e | 56 | #include "syssignal.h" |
6ef5b54f | 57 | #include "systty.h" |
52baf19e | 58 | |
03cee6ae GM |
59 | #include <sys/types.h> |
60 | #ifdef HAVE_UNISTD_H | |
61 | #include <unistd.h> | |
62 | #endif | |
63 | ||
c5e3b6c5 RS |
64 | /* This is to get the definitions of the XK_ symbols. */ |
65 | #ifdef HAVE_X_WINDOWS | |
66 | #include "xterm.h" | |
67 | #endif | |
68 | ||
e98a93eb GV |
69 | #ifdef HAVE_NTGUI |
70 | #include "w32term.h" | |
71 | #endif /* HAVE_NTGUI */ | |
72 | ||
1a578e9b AC |
73 | #ifdef macintosh |
74 | #include "macterm.h" | |
75 | #endif | |
76 | ||
0c2611c5 RS |
77 | /* Include systime.h after xterm.h to avoid double inclusion of time.h. */ |
78 | #include "systime.h" | |
79 | ||
02639609 | 80 | #ifndef USE_CRT_DLL |
52baf19e | 81 | extern int errno; |
02639609 | 82 | #endif |
52baf19e | 83 | |
9ac0d9e0 JB |
84 | /* Variables for blockinput.h: */ |
85 | ||
86 | /* Non-zero if interrupt input is blocked right now. */ | |
63927c41 | 87 | int interrupt_input_blocked; |
9ac0d9e0 JB |
88 | |
89 | /* Nonzero means an input interrupt has arrived | |
90 | during the current critical section. */ | |
63927c41 | 91 | int interrupt_input_pending; |
9ac0d9e0 JB |
92 | |
93 | ||
437f6112 RS |
94 | /* File descriptor to use for input. */ |
95 | extern int input_fd; | |
284f4730 | 96 | |
e98a93eb | 97 | #ifdef HAVE_WINDOW_SYSTEM |
284f4730 | 98 | /* Make all keyboard buffers much bigger when using X windows. */ |
f019cded | 99 | #ifdef macintosh |
1a578e9b | 100 | /* But not too big (local data > 32K error) if on macintosh. */ |
f019cded RS |
101 | #define KBD_BUFFER_SIZE 512 |
102 | #else | |
284f4730 | 103 | #define KBD_BUFFER_SIZE 4096 |
f019cded | 104 | #endif |
284f4730 JB |
105 | #else /* No X-windows, character input */ |
106 | #define KBD_BUFFER_SIZE 256 | |
107 | #endif /* No X-windows */ | |
108 | ||
109 | /* Following definition copied from eval.c */ | |
110 | ||
111 | struct backtrace | |
112 | { | |
113 | struct backtrace *next; | |
114 | Lisp_Object *function; | |
115 | Lisp_Object *args; /* Points to vector of args. */ | |
116 | int nargs; /* length of vector. If nargs is UNEVALLED, | |
117 | args points to slot holding list of | |
118 | unevalled args */ | |
119 | char evalargs; | |
120 | }; | |
121 | ||
c5fdd383 KH |
122 | #ifdef MULTI_KBOARD |
123 | KBOARD *initial_kboard; | |
124 | KBOARD *current_kboard; | |
125 | KBOARD *all_kboards; | |
1e8bd3da | 126 | int single_kboard; |
6c6083a9 | 127 | #else |
c5fdd383 | 128 | KBOARD the_only_kboard; |
6c6083a9 | 129 | #endif |
612b78ef | 130 | |
284f4730 JB |
131 | /* Non-nil disable property on a command means |
132 | do not execute it; call disabled-command-hook's value instead. */ | |
2e894dab | 133 | Lisp_Object Qdisabled, Qdisabled_command_hook; |
284f4730 JB |
134 | |
135 | #define NUM_RECENT_KEYS (100) | |
136 | int recent_keys_index; /* Index for storing next element into recent_keys */ | |
137 | int total_keys; /* Total number of elements stored into recent_keys */ | |
5160df46 | 138 | Lisp_Object recent_keys; /* A vector, holding the last 100 keystrokes */ |
284f4730 | 139 | |
6569cc8d JB |
140 | /* Vector holding the key sequence that invoked the current command. |
141 | It is reused for each command, and it may be longer than the current | |
142 | sequence; this_command_key_count indicates how many elements | |
143 | actually mean something. | |
144 | It's easier to staticpro a single Lisp_Object than an array. */ | |
145 | Lisp_Object this_command_keys; | |
146 | int this_command_key_count; | |
284f4730 | 147 | |
7d18f9ae RS |
148 | /* This vector is used as a buffer to record the events that were actually read |
149 | by read_key_sequence. */ | |
150 | Lisp_Object raw_keybuf; | |
151 | int raw_keybuf_count; | |
152 | ||
153 | #define GROW_RAW_KEYBUF \ | |
154 | if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \ | |
155 | { \ | |
156 | int newsize = 2 * XVECTOR (raw_keybuf)->size; \ | |
157 | Lisp_Object new; \ | |
158 | new = Fmake_vector (make_number (newsize), Qnil); \ | |
159 | bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \ | |
160 | raw_keybuf_count * sizeof (Lisp_Object)); \ | |
161 | raw_keybuf = new; \ | |
162 | } | |
163 | ||
6321824f RS |
164 | /* Number of elements of this_command_keys |
165 | that precede this key sequence. */ | |
166 | int this_single_command_key_start; | |
167 | ||
71918b75 RS |
168 | /* Record values of this_command_key_count and echo_length () |
169 | before this command was read. */ | |
170 | static int before_command_key_count; | |
171 | static int before_command_echo_length; | |
172 | /* Values of before_command_key_count and before_command_echo_length | |
173 | saved by reset-this-command-lengths. */ | |
174 | static int before_command_key_count_1; | |
175 | static int before_command_echo_length_1; | |
176 | /* Flag set by reset-this-command-lengths, | |
177 | saying to reset the lengths when add_command_key is called. */ | |
178 | static int before_command_restore_flag; | |
179 | ||
284f4730 JB |
180 | extern int minbuf_level; |
181 | ||
a59b172a RS |
182 | extern int message_enable_multibyte; |
183 | ||
284f4730 JB |
184 | extern struct backtrace *backtrace_list; |
185 | ||
7ee32cda GM |
186 | /* If non-nil, the function that implements the display of help. |
187 | It's called with one argument, the help string to display. */ | |
188 | ||
189 | Lisp_Object Vshow_help_function; | |
190 | ||
284f4730 JB |
191 | /* Nonzero means do menu prompting. */ |
192 | static int menu_prompting; | |
193 | ||
194 | /* Character to see next line of menu prompt. */ | |
195 | static Lisp_Object menu_prompt_more_char; | |
196 | ||
197 | /* For longjmp to where kbd input is being done. */ | |
198 | static jmp_buf getcjmp; | |
199 | ||
200 | /* True while doing kbd input. */ | |
201 | int waiting_for_input; | |
202 | ||
203 | /* True while displaying for echoing. Delays C-g throwing. */ | |
985f9f66 | 204 | |
284f4730 JB |
205 | static int echoing; |
206 | ||
985f9f66 GM |
207 | /* Non-null means we can start echoing at the next input pause even |
208 | though there is something in the echo area. */ | |
209 | ||
210 | static struct kboard *ok_to_echo_at_next_pause; | |
211 | ||
59a84f8e GM |
212 | /* The kboard last echoing, or null for none. Reset to 0 in |
213 | cancel_echoing. If non-null, and a current echo area message | |
214 | exists, and echo_message_buffer is eq to the current message | |
215 | buffer, we know that the message comes from echo_kboard. */ | |
985f9f66 GM |
216 | |
217 | static struct kboard *echo_kboard; | |
1fc93d49 | 218 | |
59a84f8e GM |
219 | /* The buffer used for echoing. Set in echo_now, reset in |
220 | cancel_echoing. */ | |
221 | ||
222 | static Lisp_Object echo_message_buffer; | |
223 | ||
03361bcc RS |
224 | /* Nonzero means disregard local maps for the menu bar. */ |
225 | static int inhibit_local_menu_bar_menus; | |
226 | ||
80e4aa30 | 227 | /* Nonzero means C-g should cause immediate error-signal. */ |
284f4730 JB |
228 | int immediate_quit; |
229 | ||
fa90970d RS |
230 | /* The user's ERASE setting. */ |
231 | Lisp_Object Vtty_erase_char; | |
232 | ||
284f4730 | 233 | /* Character to recognize as the help char. */ |
7e85b935 | 234 | Lisp_Object Vhelp_char; |
284f4730 | 235 | |
ecb7cb34 KH |
236 | /* List of other event types to recognize as meaning "help". */ |
237 | Lisp_Object Vhelp_event_list; | |
238 | ||
284f4730 JB |
239 | /* Form to execute when help char is typed. */ |
240 | Lisp_Object Vhelp_form; | |
241 | ||
7e85b935 RS |
242 | /* Command to run when the help character follows a prefix key. */ |
243 | Lisp_Object Vprefix_help_command; | |
244 | ||
9f9c0e27 RS |
245 | /* List of items that should move to the end of the menu bar. */ |
246 | Lisp_Object Vmenu_bar_final_items; | |
a73c5e29 | 247 | |
6526ab49 RS |
248 | /* Non-nil means show the equivalent key-binding for |
249 | any M-x command that has one. | |
250 | The value can be a length of time to show the message for. | |
251 | If the value is non-nil and not a number, we wait 2 seconds. */ | |
252 | Lisp_Object Vsuggest_key_bindings; | |
253 | ||
00392ce6 MB |
254 | /* How long to display an echo-area message when the minibuffer is active. |
255 | If the value is not a number, such messages don't time out. */ | |
256 | Lisp_Object Vminibuffer_message_timeout; | |
257 | ||
284f4730 JB |
258 | /* Character that causes a quit. Normally C-g. |
259 | ||
260 | If we are running on an ordinary terminal, this must be an ordinary | |
261 | ASCII char, since we want to make it our interrupt character. | |
262 | ||
263 | If we are not running on an ordinary terminal, it still needs to be | |
264 | an ordinary ASCII char. This character needs to be recognized in | |
265 | the input interrupt handler. At this point, the keystroke is | |
266 | represented as a struct input_event, while the desired quit | |
267 | character is specified as a lispy event. The mapping from struct | |
268 | input_events to lispy events cannot run in an interrupt handler, | |
269 | and the reverse mapping is difficult for anything but ASCII | |
270 | keystrokes. | |
271 | ||
272 | FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an | |
273 | ASCII character. */ | |
274 | int quit_char; | |
275 | ||
276 | extern Lisp_Object current_global_map; | |
277 | extern int minibuf_level; | |
278 | ||
9dd3131c RS |
279 | /* If non-nil, this is a map that overrides all other local maps. */ |
280 | Lisp_Object Voverriding_local_map; | |
281 | ||
d0a49716 RS |
282 | /* If non-nil, Voverriding_local_map applies to the menu bar. */ |
283 | Lisp_Object Voverriding_local_map_menu_flag; | |
284 | ||
7f07d5ca RS |
285 | /* Keymap that defines special misc events that should |
286 | be processed immediately at a low level. */ | |
287 | Lisp_Object Vspecial_event_map; | |
288 | ||
284f4730 JB |
289 | /* Current depth in recursive edits. */ |
290 | int command_loop_level; | |
291 | ||
292 | /* Total number of times command_loop has read a key sequence. */ | |
293 | int num_input_keys; | |
294 | ||
295 | /* Last input character read as a command. */ | |
296 | Lisp_Object last_command_char; | |
297 | ||
7d6de002 RS |
298 | /* Last input character read as a command, not counting menus |
299 | reached by the mouse. */ | |
300 | Lisp_Object last_nonmenu_event; | |
301 | ||
284f4730 JB |
302 | /* Last input character read for any purpose. */ |
303 | Lisp_Object last_input_char; | |
304 | ||
dbc4e1c1 | 305 | /* If not Qnil, a list of objects to be read as subsequent command input. */ |
24597608 | 306 | Lisp_Object Vunread_command_events; |
284f4730 | 307 | |
7d18f9ae RS |
308 | /* If not Qnil, a list of objects to be read as subsequent command input |
309 | including input method processing. */ | |
310 | Lisp_Object Vunread_input_method_events; | |
311 | ||
312 | /* If not Qnil, a list of objects to be read as subsequent command input | |
313 | but NOT including input method processing. */ | |
314 | Lisp_Object Vunread_post_input_method_events; | |
315 | ||
86e5706b RS |
316 | /* If not -1, an event to be read as subsequent command input. */ |
317 | int unread_command_char; | |
318 | ||
cd21b839 JB |
319 | /* If not Qnil, this is a switch-frame event which we decided to put |
320 | off until the end of a key sequence. This should be read as the | |
dbc4e1c1 | 321 | next command input, after any unread_command_events. |
8f805655 JB |
322 | |
323 | read_key_sequence uses this to delay switch-frame events until the | |
324 | end of the key sequence; Fread_char uses it to put off switch-frame | |
325 | events until a non-ASCII event is acceptable as input. */ | |
326 | Lisp_Object unread_switch_frame; | |
cd21b839 | 327 | |
9fa4395d RS |
328 | /* A mask of extra modifier bits to put into every keyboard char. */ |
329 | int extra_keyboard_modifiers; | |
330 | ||
284f4730 JB |
331 | /* Char to use as prefix when a meta character is typed in. |
332 | This is bound on entry to minibuffer in case ESC is changed there. */ | |
333 | ||
334 | Lisp_Object meta_prefix_char; | |
335 | ||
336 | /* Last size recorded for a current buffer which is not a minibuffer. */ | |
337 | static int last_non_minibuf_size; | |
338 | ||
06ef7355 | 339 | /* Number of idle seconds before an auto-save and garbage collection. */ |
284f4730 JB |
340 | static Lisp_Object Vauto_save_timeout; |
341 | ||
342 | /* Total number of times read_char has returned. */ | |
4abfba1f | 343 | int num_input_events; |
284f4730 | 344 | |
51172b6d | 345 | /* Total number of times read_char has returned, outside of macros. */ |
c43b1734 | 346 | int num_nonmacro_input_events; |
51172b6d | 347 | |
284f4730 JB |
348 | /* Auto-save automatically when this many characters have been typed |
349 | since the last time. */ | |
350 | ||
351 | static int auto_save_interval; | |
352 | ||
c43b1734 | 353 | /* Value of num_nonmacro_input_events as of last auto save. */ |
284f4730 JB |
354 | |
355 | int last_auto_save; | |
356 | ||
284f4730 | 357 | /* The command being executed by the command loop. |
6c7178b9 KH |
358 | Commands may set this, and the value set will be copied into |
359 | current_kboard->Vlast_command instead of the actual command. */ | |
d5eecefb RS |
360 | Lisp_Object Vthis_command; |
361 | ||
362 | /* This is like Vthis_command, except that commands never set it. */ | |
363 | Lisp_Object real_this_command; | |
284f4730 | 364 | |
b453f72e KH |
365 | /* The value of point when the last command was executed. */ |
366 | int last_point_position; | |
367 | ||
047688cb RS |
368 | /* The buffer that was current when the last command was started. */ |
369 | Lisp_Object last_point_position_buffer; | |
370 | ||
4c52b668 KH |
371 | /* The frame in which the last input event occurred, or Qmacro if the |
372 | last event came from a macro. We use this to determine when to | |
373 | generate switch-frame events. This may be cleared by functions | |
374 | like Fselect_frame, to make sure that a switch-frame event is | |
375 | generated by the next character. */ | |
376 | Lisp_Object internal_last_event_frame; | |
4c52b668 KH |
377 | |
378 | /* A user-visible version of the above, intended to allow users to | |
379 | figure out where the last event came from, if the event doesn't | |
380 | carry that information itself (i.e. if it was a character). */ | |
381 | Lisp_Object Vlast_event_frame; | |
382 | ||
1113d9db JB |
383 | /* The timestamp of the last input event we received from the X server. |
384 | X Windows wants this for selection ownership. */ | |
284f4730 JB |
385 | unsigned long last_event_timestamp; |
386 | ||
387 | Lisp_Object Qself_insert_command; | |
388 | Lisp_Object Qforward_char; | |
389 | Lisp_Object Qbackward_char; | |
e58aa385 | 390 | Lisp_Object Qundefined; |
d925fb39 | 391 | Lisp_Object Qtimer_event_handler; |
284f4730 JB |
392 | |
393 | /* read_key_sequence stores here the command definition of the | |
394 | key sequence that it reads. */ | |
395 | Lisp_Object read_key_sequence_cmd; | |
396 | ||
39aab679 DL |
397 | /* Echo unfinished commands after this many seconds of pause. */ |
398 | Lisp_Object Vecho_keystrokes; | |
399 | ||
284f4730 JB |
400 | /* Form to evaluate (if non-nil) when Emacs is started. */ |
401 | Lisp_Object Vtop_level; | |
402 | ||
403 | /* User-supplied string to translate input characters through. */ | |
404 | Lisp_Object Vkeyboard_translate_table; | |
405 | ||
406 | /* Keymap mapping ASCII function key sequences onto their preferred forms. */ | |
407 | extern Lisp_Object Vfunction_key_map; | |
408 | ||
e0301c07 RS |
409 | /* Another keymap that maps key sequences into key sequences. |
410 | This one takes precedence over ordinary definitions. */ | |
411 | extern Lisp_Object Vkey_translation_map; | |
a612e298 | 412 | |
7d18f9ae RS |
413 | /* If non-nil, this implements the current input method. */ |
414 | Lisp_Object Vinput_method_function; | |
415 | Lisp_Object Qinput_method_function; | |
416 | ||
d5eecefb RS |
417 | /* When we call Vinput_method_function, |
418 | this holds the echo area message that was just erased. */ | |
419 | Lisp_Object Vinput_method_previous_message; | |
420 | ||
86e5706b RS |
421 | /* Non-nil means deactivate the mark at end of this command. */ |
422 | Lisp_Object Vdeactivate_mark; | |
423 | ||
48e416d4 RS |
424 | /* Menu bar specified in Lucid Emacs fashion. */ |
425 | ||
426 | Lisp_Object Vlucid_menu_bar_dirty_flag; | |
427 | Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook; | |
428 | ||
cdb9d665 RS |
429 | Lisp_Object Qecho_area_clear_hook; |
430 | ||
86e5706b | 431 | /* Hooks to run before and after each command. */ |
59aadc81 RS |
432 | Lisp_Object Qpre_command_hook, Vpre_command_hook; |
433 | Lisp_Object Qpost_command_hook, Vpost_command_hook; | |
40932d1a | 434 | Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal; |
59aadc81 RS |
435 | /* Hook run after a command if there's no more input soon. */ |
436 | Lisp_Object Qpost_command_idle_hook, Vpost_command_idle_hook; | |
437 | ||
438 | /* Delay time in microseconds before running post-command-idle-hook. */ | |
439 | int post_command_idle_delay; | |
86e5706b | 440 | |
8a792f3a RS |
441 | /* List of deferred actions to be performed at a later time. |
442 | The precise format isn't relevant here; we just check whether it is nil. */ | |
443 | Lisp_Object Vdeferred_action_list; | |
444 | ||
445 | /* Function to call to handle deferred actions, when there are any. */ | |
446 | Lisp_Object Vdeferred_action_function; | |
3ef14e46 | 447 | Lisp_Object Qdeferred_action_function; |
8a792f3a | 448 | |
d5eecefb RS |
449 | Lisp_Object Qinput_method_exit_on_first_char; |
450 | Lisp_Object Qinput_method_use_echo_area; | |
451 | ||
284f4730 JB |
452 | /* File in which we write all commands we read. */ |
453 | FILE *dribble; | |
454 | ||
455 | /* Nonzero if input is available. */ | |
456 | int input_pending; | |
457 | ||
b04904fb RS |
458 | /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should |
459 | keep 0200 bit in input chars. 0 to ignore the 0200 bit. */ | |
460 | ||
284f4730 JB |
461 | int meta_key; |
462 | ||
3626fb1a GM |
463 | /* Non-zero means force key bindings update in parse_menu_item. */ |
464 | ||
465 | int update_menu_bindings; | |
466 | ||
284f4730 JB |
467 | extern char *pending_malloc_warning; |
468 | ||
beecf6a1 | 469 | /* Circular buffer for pre-read keyboard input. */ |
da8f7368 | 470 | |
beecf6a1 KH |
471 | static struct input_event kbd_buffer[KBD_BUFFER_SIZE]; |
472 | ||
da8f7368 | 473 | /* Vector to GCPRO the Lisp objects referenced from kbd_buffer. |
beecf6a1 KH |
474 | |
475 | The interrupt-level event handlers will never enqueue an event on a | |
476 | frame which is not in Vframe_list, and once an event is dequeued, | |
477 | internal_last_event_frame or the event itself points to the frame. | |
478 | So that's all fine. | |
479 | ||
480 | But while the event is sitting in the queue, it's completely | |
481 | unprotected. Suppose the user types one command which will run for | |
482 | a while and then delete a frame, and then types another event at | |
483 | the frame that will be deleted, before the command gets around to | |
484 | it. Suppose there are no references to this frame elsewhere in | |
485 | Emacs, and a GC occurs before the second event is dequeued. Now we | |
486 | have an event referring to a freed frame, which will crash Emacs | |
487 | when it is dequeued. | |
488 | ||
489 | Similar things happen when an event on a scroll bar is enqueued; the | |
490 | window may be deleted while the event is in the queue. | |
491 | ||
da8f7368 GM |
492 | So, we use this vector to protect the Lisp_Objects in the event |
493 | queue. That way, they'll be dequeued as dead frames or windows, | |
494 | but still valid Lisp objects. | |
beecf6a1 KH |
495 | |
496 | If kbd_buffer[i].kind != no_event, then | |
da8f7368 GM |
497 | |
498 | AREF (kbd_buffer_gcpro, 2 * i) == kbd_buffer[i].frame_or_window. | |
499 | AREF (kbd_buffer_gcpro, 2 * i + 1) == kbd_buffer[i].arg. */ | |
500 | ||
501 | static Lisp_Object kbd_buffer_gcpro; | |
beecf6a1 KH |
502 | |
503 | /* Pointer to next available character in kbd_buffer. | |
504 | If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty. | |
505 | This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the | |
506 | next available char is in kbd_buffer[0]. */ | |
507 | static struct input_event *kbd_fetch_ptr; | |
508 | ||
509 | /* Pointer to next place to store character in kbd_buffer. This | |
510 | may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next | |
511 | character should go in kbd_buffer[0]. */ | |
7ee32cda | 512 | static struct input_event * volatile kbd_store_ptr; |
beecf6a1 KH |
513 | |
514 | /* The above pair of variables forms a "queue empty" flag. When we | |
515 | enqueue a non-hook event, we increment kbd_store_ptr. When we | |
516 | dequeue a non-hook event, we increment kbd_fetch_ptr. We say that | |
517 | there is input available iff the two pointers are not equal. | |
518 | ||
519 | Why not just have a flag set and cleared by the enqueuing and | |
520 | dequeuing functions? Such a flag could be screwed up by interrupts | |
521 | at inopportune times. */ | |
522 | ||
f3253854 | 523 | /* If this flag is non-nil, we check mouse_moved to see when the |
a9d77f1f RS |
524 | mouse moves, and motion events will appear in the input stream. |
525 | Otherwise, mouse motion is ignored. */ | |
526 | static Lisp_Object do_mouse_tracking; | |
284f4730 | 527 | |
284f4730 JB |
528 | /* Symbols to head events. */ |
529 | Lisp_Object Qmouse_movement; | |
3c370943 | 530 | Lisp_Object Qscroll_bar_movement; |
cd21b839 | 531 | Lisp_Object Qswitch_frame; |
bbdc2092 | 532 | Lisp_Object Qdelete_frame; |
af17bd2b KH |
533 | Lisp_Object Qiconify_frame; |
534 | Lisp_Object Qmake_frame_visible; | |
7ee32cda | 535 | Lisp_Object Qhelp_echo; |
cd21b839 | 536 | |
284f4730 JB |
537 | /* Symbols to denote kinds of events. */ |
538 | Lisp_Object Qfunction_key; | |
539 | Lisp_Object Qmouse_click; | |
07de30b9 GV |
540 | #ifdef WINDOWSNT |
541 | Lisp_Object Qmouse_wheel; | |
1161d367 | 542 | Lisp_Object Qlanguage_change; |
07de30b9 | 543 | #endif |
a24dc617 | 544 | Lisp_Object Qdrag_n_drop; |
284f4730 | 545 | /* Lisp_Object Qmouse_movement; - also an event header */ |
284f4730 JB |
546 | |
547 | /* Properties of event headers. */ | |
548 | Lisp_Object Qevent_kind; | |
88cb0656 | 549 | Lisp_Object Qevent_symbol_elements; |
284f4730 | 550 | |
e8886a1d RS |
551 | /* menu item parts */ |
552 | Lisp_Object Qmenu_alias; | |
598a9fa7 | 553 | Lisp_Object Qmenu_enable; |
74c1de23 RS |
554 | Lisp_Object QCenable, QCvisible, QChelp, QCfilter, QCkeys, QCkey_sequence; |
555 | Lisp_Object QCbutton, QCtoggle, QCradio; | |
e8886a1d RS |
556 | extern Lisp_Object Vdefine_key_rebound_commands; |
557 | extern Lisp_Object Qmenu_item; | |
598a9fa7 | 558 | |
0a7f1fc0 JB |
559 | /* An event header symbol HEAD may have a property named |
560 | Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS); | |
561 | BASE is the base, unmodified version of HEAD, and MODIFIERS is the | |
562 | mask of modifiers applied to it. If present, this is used to help | |
563 | speed up parse_modifiers. */ | |
564 | Lisp_Object Qevent_symbol_element_mask; | |
565 | ||
566 | /* An unmodified event header BASE may have a property named | |
567 | Qmodifier_cache, which is an alist mapping modifier masks onto | |
568 | modified versions of BASE. If present, this helps speed up | |
569 | apply_modifiers. */ | |
570 | Lisp_Object Qmodifier_cache; | |
571 | ||
5ec75a55 | 572 | /* Symbols to use for parts of windows. */ |
284f4730 | 573 | Lisp_Object Qmode_line; |
e5d77022 | 574 | Lisp_Object Qvertical_line; |
3c370943 | 575 | Lisp_Object Qvertical_scroll_bar; |
5ec75a55 RS |
576 | Lisp_Object Qmenu_bar; |
577 | ||
f4255cd1 JB |
578 | Lisp_Object recursive_edit_unwind (), command_loop (); |
579 | Lisp_Object Fthis_command_keys (); | |
03b4122a | 580 | Lisp_Object Qextended_command_history; |
c04cbc3b | 581 | EMACS_TIME timer_check (); |
284f4730 | 582 | |
f4385381 RS |
583 | extern Lisp_Object Vhistory_length; |
584 | ||
2c834fb3 KH |
585 | extern char *x_get_keysym_name (); |
586 | ||
8eb4d8ef RS |
587 | static void record_menu_key (); |
588 | ||
f4eef8b4 RS |
589 | Lisp_Object Qpolling_period; |
590 | ||
d9d4c147 | 591 | /* List of absolute timers. Appears in order of next scheduled event. */ |
c04cbc3b RS |
592 | Lisp_Object Vtimer_list; |
593 | ||
d9d4c147 KH |
594 | /* List of idle time timers. Appears in order of next scheduled event. */ |
595 | Lisp_Object Vtimer_idle_list; | |
596 | ||
87dd9b9b RS |
597 | /* Incremented whenever a timer is run. */ |
598 | int timers_run; | |
599 | ||
a9f16aa9 KH |
600 | extern Lisp_Object Vprint_level, Vprint_length; |
601 | ||
ffd56f97 JB |
602 | /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt |
603 | happens. */ | |
604 | EMACS_TIME *input_available_clear_time; | |
284f4730 JB |
605 | |
606 | /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode. | |
607 | Default is 1 if INTERRUPT_INPUT is defined. */ | |
608 | int interrupt_input; | |
609 | ||
610 | /* Nonzero while interrupts are temporarily deferred during redisplay. */ | |
611 | int interrupts_deferred; | |
612 | ||
87dd9b9b | 613 | /* Nonzero means use ^S/^Q for flow control. */ |
284f4730 JB |
614 | int flow_control; |
615 | ||
284f4730 JB |
616 | /* Allow m- file to inhibit use of FIONREAD. */ |
617 | #ifdef BROKEN_FIONREAD | |
618 | #undef FIONREAD | |
619 | #endif | |
620 | ||
621 | /* We are unable to use interrupts if FIONREAD is not available, | |
622 | so flush SIGIO so we won't try. */ | |
623 | #ifndef FIONREAD | |
624 | #ifdef SIGIO | |
625 | #undef SIGIO | |
626 | #endif | |
627 | #endif | |
628 | ||
e98a93eb | 629 | /* If we support a window system, turn on the code to poll periodically |
34f04431 | 630 | to detect C-g. It isn't actually used when doing interrupt input. */ |
e98a93eb | 631 | #ifdef HAVE_WINDOW_SYSTEM |
284f4730 JB |
632 | #define POLL_FOR_INPUT |
633 | #endif | |
adf5cb9c KH |
634 | |
635 | /* After a command is executed, if point is moved into a region that | |
636 | has specific properties (e.g. composition, display), we adjust | |
637 | point to the boundary of the region. But, if a command sets this | |
638 | valiable to non-nil, we suppress this point adjustment. This | |
639 | variable is set to nil before reading a command. */ | |
da8f7368 | 640 | |
adf5cb9c KH |
641 | Lisp_Object Vdisable_point_adjustment; |
642 | ||
643 | /* If non-nil, always disable point adjustment. */ | |
da8f7368 | 644 | |
adf5cb9c KH |
645 | Lisp_Object Vglobal_disable_point_adjustment; |
646 | ||
284f4730 JB |
647 | \f |
648 | /* Global variable declarations. */ | |
649 | ||
650 | /* Function for init_keyboard to call with no args (if nonzero). */ | |
651 | void (*keyboard_init_hook) (); | |
652 | ||
0bbfdc25 GM |
653 | static int read_avail_input P_ ((int)); |
654 | static void get_input_pending P_ ((int *, int)); | |
655 | static int readable_events P_ ((int)); | |
656 | static Lisp_Object read_char_x_menu_prompt P_ ((int, Lisp_Object *, | |
657 | Lisp_Object, int *)); | |
8150596a | 658 | static Lisp_Object read_char_x_menu_prompt (); |
0bbfdc25 GM |
659 | static Lisp_Object read_char_minibuf_menu_prompt P_ ((int, int, |
660 | Lisp_Object *)); | |
661 | static Lisp_Object make_lispy_event P_ ((struct input_event *)); | |
514354e9 | 662 | #ifdef HAVE_MOUSE |
0bbfdc25 GM |
663 | static Lisp_Object make_lispy_movement P_ ((struct frame *, Lisp_Object, |
664 | enum scroll_bar_part, | |
665 | Lisp_Object, Lisp_Object, | |
666 | unsigned long)); | |
514354e9 | 667 | #endif |
0bbfdc25 GM |
668 | static Lisp_Object modify_event_symbol P_ ((int, unsigned, Lisp_Object, |
669 | Lisp_Object, char **, | |
670 | Lisp_Object *, unsigned)); | |
671 | static Lisp_Object make_lispy_switch_frame P_ ((Lisp_Object)); | |
672 | static int parse_solitary_modifier P_ ((Lisp_Object)); | |
3d31316f | 673 | static int parse_solitary_modifier (); |
0bbfdc25 | 674 | static void save_getcjmp P_ ((jmp_buf)); |
dfcf069d | 675 | static void save_getcjmp (); |
0bbfdc25 | 676 | static void restore_getcjmp P_ ((jmp_buf)); |
7ee32cda | 677 | static Lisp_Object apply_modifiers P_ ((int, Lisp_Object)); |
0bbfdc25 | 678 | static void clear_event P_ ((struct input_event *)); |
284f4730 | 679 | |
8026024c KH |
680 | /* Nonzero means don't try to suspend even if the operating system seems |
681 | to support it. */ | |
682 | static int cannot_suspend; | |
683 | ||
284f4730 JB |
684 | #define min(a,b) ((a)<(b)?(a):(b)) |
685 | #define max(a,b) ((a)>(b)?(a):(b)) | |
686 | ||
687 | /* Install the string STR as the beginning of the string of echoing, | |
688 | so that it serves as a prompt for the next character. | |
689 | Also start echoing. */ | |
690 | ||
dfcf069d | 691 | void |
284f4730 JB |
692 | echo_prompt (str) |
693 | char *str; | |
694 | { | |
695 | int len = strlen (str); | |
7a80a6f6 | 696 | |
ba72822c KH |
697 | if (len > ECHOBUFSIZE - 4) |
698 | len = ECHOBUFSIZE - 4; | |
c5fdd383 KH |
699 | bcopy (str, current_kboard->echobuf, len); |
700 | current_kboard->echoptr = current_kboard->echobuf + len; | |
701 | *current_kboard->echoptr = '\0'; | |
284f4730 | 702 | |
c5fdd383 | 703 | current_kboard->echo_after_prompt = len; |
7a80a6f6 | 704 | |
3dbd9ee4 | 705 | echo_now (); |
284f4730 JB |
706 | } |
707 | ||
df0f2ba1 | 708 | /* Add C to the echo string, if echoing is going on. |
284f4730 JB |
709 | C can be a character, which is printed prettily ("M-C-x" and all that |
710 | jazz), or a symbol, whose name is printed. */ | |
711 | ||
dfcf069d | 712 | void |
284f4730 JB |
713 | echo_char (c) |
714 | Lisp_Object c; | |
715 | { | |
716 | extern char *push_key_description (); | |
717 | ||
c5fdd383 | 718 | if (current_kboard->immediate_echo) |
284f4730 | 719 | { |
c5fdd383 | 720 | char *ptr = current_kboard->echoptr; |
df0f2ba1 | 721 | |
c5fdd383 | 722 | if (ptr != current_kboard->echobuf) |
284f4730 JB |
723 | *ptr++ = ' '; |
724 | ||
725 | /* If someone has passed us a composite event, use its head symbol. */ | |
88cb0656 | 726 | c = EVENT_HEAD (c); |
284f4730 | 727 | |
8c18cbfb | 728 | if (INTEGERP (c)) |
284f4730 | 729 | { |
2d0ffc9a KH |
730 | if (ptr - current_kboard->echobuf |
731 | > ECHOBUFSIZE - KEY_DESCRIPTION_SIZE) | |
284f4730 JB |
732 | return; |
733 | ||
cb5df6ae | 734 | ptr = push_key_description (XINT (c), ptr); |
284f4730 | 735 | } |
8c18cbfb | 736 | else if (SYMBOLP (c)) |
284f4730 JB |
737 | { |
738 | struct Lisp_String *name = XSYMBOL (c)->name; | |
fc932ac6 | 739 | if ((ptr - current_kboard->echobuf) + STRING_BYTES (name) + 4 |
301738ed | 740 | > ECHOBUFSIZE) |
284f4730 | 741 | return; |
fc932ac6 RS |
742 | bcopy (name->data, ptr, STRING_BYTES (name)); |
743 | ptr += STRING_BYTES (name); | |
284f4730 JB |
744 | } |
745 | ||
c5fdd383 | 746 | if (current_kboard->echoptr == current_kboard->echobuf |
ecb7cb34 | 747 | && help_char_p (c)) |
284f4730 JB |
748 | { |
749 | strcpy (ptr, " (Type ? for further options)"); | |
750 | ptr += strlen (ptr); | |
751 | } | |
752 | ||
753 | *ptr = 0; | |
c5fdd383 | 754 | current_kboard->echoptr = ptr; |
284f4730 | 755 | |
3dbd9ee4 | 756 | echo_now (); |
284f4730 JB |
757 | } |
758 | } | |
759 | ||
760 | /* Temporarily add a dash to the end of the echo string if it's not | |
761 | empty, so that it serves as a mini-prompt for the very next character. */ | |
762 | ||
dfcf069d | 763 | void |
284f4730 JB |
764 | echo_dash () |
765 | { | |
c5fdd383 KH |
766 | if (!current_kboard->immediate_echo |
767 | && current_kboard->echoptr == current_kboard->echobuf) | |
284f4730 | 768 | return; |
7a80a6f6 | 769 | /* Do nothing if we just printed a prompt. */ |
c5fdd383 KH |
770 | if (current_kboard->echo_after_prompt |
771 | == current_kboard->echoptr - current_kboard->echobuf) | |
7a80a6f6 | 772 | return; |
4bafa972 | 773 | /* Do nothing if not echoing at all. */ |
c5fdd383 | 774 | if (current_kboard->echoptr == 0) |
4bafa972 | 775 | return; |
284f4730 JB |
776 | |
777 | /* Put a dash at the end of the buffer temporarily, | |
778 | but make it go away when the next character is added. */ | |
c5fdd383 KH |
779 | current_kboard->echoptr[0] = '-'; |
780 | current_kboard->echoptr[1] = 0; | |
284f4730 | 781 | |
3dbd9ee4 | 782 | echo_now (); |
284f4730 JB |
783 | } |
784 | ||
785 | /* Display the current echo string, and begin echoing if not already | |
786 | doing so. */ | |
787 | ||
07a59269 | 788 | void |
3dbd9ee4 | 789 | echo_now () |
284f4730 | 790 | { |
c5fdd383 | 791 | if (!current_kboard->immediate_echo) |
284f4730 JB |
792 | { |
793 | int i; | |
c5fdd383 | 794 | current_kboard->immediate_echo = 1; |
284f4730 JB |
795 | |
796 | for (i = 0; i < this_command_key_count; i++) | |
d0a57728 RS |
797 | { |
798 | Lisp_Object c; | |
799 | c = XVECTOR (this_command_keys)->contents[i]; | |
800 | if (! (EVENT_HAS_PARAMETERS (c) | |
801 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_movement))) | |
802 | echo_char (c); | |
803 | } | |
284f4730 JB |
804 | echo_dash (); |
805 | } | |
806 | ||
807 | echoing = 1; | |
301738ed RS |
808 | message2_nolog (current_kboard->echobuf, strlen (current_kboard->echobuf), |
809 | ! NILP (current_buffer->enable_multibyte_characters)); | |
284f4730 JB |
810 | echoing = 0; |
811 | ||
59a84f8e GM |
812 | /* Record in what buffer we echoed, and from which kboard. */ |
813 | echo_message_buffer = echo_area_buffer[0]; | |
814 | echo_kboard = current_kboard; | |
815 | ||
284f4730 JB |
816 | if (waiting_for_input && !NILP (Vquit_flag)) |
817 | quit_throw_to_read_char (); | |
818 | } | |
819 | ||
820 | /* Turn off echoing, for the start of a new command. */ | |
821 | ||
dfcf069d | 822 | void |
284f4730 JB |
823 | cancel_echoing () |
824 | { | |
c5fdd383 KH |
825 | current_kboard->immediate_echo = 0; |
826 | current_kboard->echoptr = current_kboard->echobuf; | |
827 | current_kboard->echo_after_prompt = -1; | |
59a84f8e GM |
828 | ok_to_echo_at_next_pause = NULL; |
829 | echo_kboard = NULL; | |
830 | echo_message_buffer = Qnil; | |
284f4730 JB |
831 | } |
832 | ||
833 | /* Return the length of the current echo string. */ | |
834 | ||
835 | static int | |
836 | echo_length () | |
837 | { | |
c5fdd383 | 838 | return current_kboard->echoptr - current_kboard->echobuf; |
284f4730 JB |
839 | } |
840 | ||
841 | /* Truncate the current echo message to its first LEN chars. | |
842 | This and echo_char get used by read_key_sequence when the user | |
ff11dfa1 | 843 | switches frames while entering a key sequence. */ |
284f4730 JB |
844 | |
845 | static void | |
846 | echo_truncate (len) | |
847 | int len; | |
848 | { | |
c5fdd383 KH |
849 | current_kboard->echobuf[len] = '\0'; |
850 | current_kboard->echoptr = current_kboard->echobuf + len; | |
40932d1a | 851 | truncate_echo_area (len); |
284f4730 JB |
852 | } |
853 | ||
854 | \f | |
855 | /* Functions for manipulating this_command_keys. */ | |
856 | static void | |
857 | add_command_key (key) | |
858 | Lisp_Object key; | |
859 | { | |
6569cc8d JB |
860 | int size = XVECTOR (this_command_keys)->size; |
861 | ||
71918b75 RS |
862 | /* If reset-this-command-length was called recently, obey it now. |
863 | See the doc string of that function for an explanation of why. */ | |
864 | if (before_command_restore_flag) | |
865 | { | |
866 | this_command_key_count = before_command_key_count_1; | |
6321824f RS |
867 | if (this_command_key_count < this_single_command_key_start) |
868 | this_single_command_key_start = this_command_key_count; | |
71918b75 RS |
869 | echo_truncate (before_command_echo_length_1); |
870 | before_command_restore_flag = 0; | |
871 | } | |
872 | ||
6569cc8d | 873 | if (this_command_key_count >= size) |
284f4730 | 874 | { |
9b8eb840 | 875 | Lisp_Object new_keys; |
6569cc8d | 876 | |
9b8eb840 | 877 | new_keys = Fmake_vector (make_number (size * 2), Qnil); |
6569cc8d JB |
878 | bcopy (XVECTOR (this_command_keys)->contents, |
879 | XVECTOR (new_keys)->contents, | |
8f805655 | 880 | size * sizeof (Lisp_Object)); |
6569cc8d JB |
881 | |
882 | this_command_keys = new_keys; | |
284f4730 | 883 | } |
6569cc8d JB |
884 | |
885 | XVECTOR (this_command_keys)->contents[this_command_key_count++] = key; | |
284f4730 JB |
886 | } |
887 | \f | |
888 | Lisp_Object | |
889 | recursive_edit_1 () | |
890 | { | |
891 | int count = specpdl_ptr - specpdl; | |
892 | Lisp_Object val; | |
893 | ||
894 | if (command_loop_level > 0) | |
895 | { | |
896 | specbind (Qstandard_output, Qt); | |
897 | specbind (Qstandard_input, Qt); | |
898 | } | |
899 | ||
84265027 GM |
900 | #ifdef HAVE_X_WINDOWS |
901 | /* The command loop has started a busy-cursor timer, so we have to | |
902 | cancel it here, otherwise it will fire because the recursive edit | |
903 | can take some time. */ | |
904 | if (display_busy_cursor_p) | |
905 | cancel_busy_cursor (); | |
906 | #endif | |
907 | ||
284f4730 JB |
908 | val = command_loop (); |
909 | if (EQ (val, Qt)) | |
910 | Fsignal (Qquit, Qnil); | |
cb252880 RS |
911 | /* Handle throw from read_minibuf when using minibuffer |
912 | while it's active but we're in another window. */ | |
913 | if (STRINGP (val)) | |
914 | Fsignal (Qerror, Fcons (val, Qnil)); | |
284f4730 | 915 | |
cb5df6ae | 916 | return unbind_to (count, Qnil); |
284f4730 JB |
917 | } |
918 | ||
919 | /* When an auto-save happens, record the "time", and don't do again soon. */ | |
5846638c | 920 | |
07a59269 | 921 | void |
284f4730 JB |
922 | record_auto_save () |
923 | { | |
c43b1734 | 924 | last_auto_save = num_nonmacro_input_events; |
284f4730 | 925 | } |
5846638c RS |
926 | |
927 | /* Make an auto save happen as soon as possible at command level. */ | |
928 | ||
dfcf069d | 929 | void |
5846638c RS |
930 | force_auto_save_soon () |
931 | { | |
932 | last_auto_save = - auto_save_interval - 1; | |
241ceaf7 RS |
933 | |
934 | record_asynch_buffer_change (); | |
5846638c | 935 | } |
284f4730 | 936 | \f |
284f4730 JB |
937 | DEFUN ("recursive-edit", Frecursive_edit, Srecursive_edit, 0, 0, "", |
938 | "Invoke the editor command loop recursively.\n\ | |
939 | To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\ | |
940 | that tells this function to return.\n\ | |
941 | Alternately, `(throw 'exit t)' makes this function signal an error.\n\ | |
942 | This function is called by the editor initialization to begin editing.") | |
943 | () | |
944 | { | |
945 | int count = specpdl_ptr - specpdl; | |
284f4730 JB |
946 | |
947 | command_loop_level++; | |
948 | update_mode_lines = 1; | |
949 | ||
1db0076e GM |
950 | /* This function may have been called from a debugger called from |
951 | within redisplay, for instance by Edebugging a function called | |
952 | from fontification-functions. We want to allow redisplay in | |
953 | the debugging session. | |
954 | ||
955 | The recursive edit is left with a `(throw exit ...)'. The `exit' | |
956 | tag is not caught anywhere in redisplay, i.e. when we leave the | |
957 | recursive edit, the original redisplay leading to the recursive | |
958 | edit will be unwound. The outcome should therefore be safe. */ | |
959 | specbind (Qinhibit_redisplay, Qnil); | |
960 | redisplaying_p = 0; | |
961 | ||
284f4730 JB |
962 | record_unwind_protect (recursive_edit_unwind, |
963 | (command_loop_level | |
964 | && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer)) | |
965 | ? Fcurrent_buffer () | |
966 | : Qnil); | |
967 | recursive_edit_1 (); | |
968 | return unbind_to (count, Qnil); | |
969 | } | |
970 | ||
971 | Lisp_Object | |
972 | recursive_edit_unwind (buffer) | |
973 | Lisp_Object buffer; | |
974 | { | |
975 | if (!NILP (buffer)) | |
976 | Fset_buffer (buffer); | |
977 | ||
978 | command_loop_level--; | |
979 | update_mode_lines = 1; | |
980 | return Qnil; | |
981 | } | |
982 | \f | |
604ccd1d | 983 | static void |
1e8bd3da | 984 | any_kboard_state () |
604ccd1d | 985 | { |
1e8bd3da RS |
986 | #ifdef MULTI_KBOARD |
987 | #if 0 /* Theory: if there's anything in Vunread_command_events, | |
988 | it will right away be read by read_key_sequence, | |
989 | and then if we do switch KBOARDS, it will go into the side | |
990 | queue then. So we don't need to do anything special here -- rms. */ | |
604ccd1d | 991 | if (CONSP (Vunread_command_events)) |
4524b161 | 992 | { |
c5fdd383 KH |
993 | current_kboard->kbd_queue |
994 | = nconc2 (Vunread_command_events, current_kboard->kbd_queue); | |
995 | current_kboard->kbd_queue_has_data = 1; | |
4524b161 | 996 | } |
604ccd1d | 997 | Vunread_command_events = Qnil; |
1e8bd3da RS |
998 | #endif |
999 | single_kboard = 0; | |
1000 | #endif | |
604ccd1d | 1001 | } |
1e8bd3da RS |
1002 | |
1003 | /* Switch to the single-kboard state, making current_kboard | |
1004 | the only KBOARD from which further input is accepted. */ | |
1005 | ||
1006 | void | |
1007 | single_kboard_state () | |
1008 | { | |
1009 | #ifdef MULTI_KBOARD | |
1010 | single_kboard = 1; | |
604ccd1d | 1011 | #endif |
1e8bd3da RS |
1012 | } |
1013 | ||
1014 | /* Maintain a stack of kboards, so other parts of Emacs | |
1015 | can switch temporarily to the kboard of a given frame | |
1016 | and then revert to the previous status. */ | |
1017 | ||
1018 | struct kboard_stack | |
1019 | { | |
1020 | KBOARD *kboard; | |
1021 | struct kboard_stack *next; | |
1022 | }; | |
1023 | ||
1024 | static struct kboard_stack *kboard_stack; | |
1025 | ||
1026 | void | |
1027 | push_frame_kboard (f) | |
1028 | FRAME_PTR f; | |
1029 | { | |
ab48365b | 1030 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
1031 | struct kboard_stack *p |
1032 | = (struct kboard_stack *) xmalloc (sizeof (struct kboard_stack)); | |
1033 | ||
1034 | p->next = kboard_stack; | |
1035 | p->kboard = current_kboard; | |
1036 | kboard_stack = p; | |
1037 | ||
1038 | current_kboard = FRAME_KBOARD (f); | |
ab48365b | 1039 | #endif |
1e8bd3da RS |
1040 | } |
1041 | ||
1042 | void | |
1043 | pop_frame_kboard () | |
1044 | { | |
ab48365b | 1045 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
1046 | struct kboard_stack *p = kboard_stack; |
1047 | current_kboard = p->kboard; | |
1048 | kboard_stack = p->next; | |
1049 | xfree (p); | |
ab48365b | 1050 | #endif |
1e8bd3da RS |
1051 | } |
1052 | \f | |
1053 | /* Handle errors that are not handled at inner levels | |
1054 | by printing an error message and returning to the editor command loop. */ | |
604ccd1d | 1055 | |
284f4730 JB |
1056 | Lisp_Object |
1057 | cmd_error (data) | |
1058 | Lisp_Object data; | |
a1341f75 | 1059 | { |
a9f16aa9 | 1060 | Lisp_Object old_level, old_length; |
e881d8b2 RS |
1061 | char macroerror[50]; |
1062 | ||
1063 | if (!NILP (executing_macro)) | |
1064 | { | |
1065 | if (executing_macro_iterations == 1) | |
1066 | sprintf (macroerror, "After 1 kbd macro iteration: "); | |
1067 | else | |
1068 | sprintf (macroerror, "After %d kbd macro iterations: ", | |
1069 | executing_macro_iterations); | |
1070 | } | |
1071 | else | |
1072 | *macroerror = 0; | |
a9f16aa9 | 1073 | |
a1341f75 RS |
1074 | Vstandard_output = Qt; |
1075 | Vstandard_input = Qt; | |
1076 | Vexecuting_macro = Qnil; | |
9f58e89e | 1077 | executing_macro = Qnil; |
d8bcf58e | 1078 | current_kboard->Vprefix_arg = Qnil; |
75045dcb | 1079 | current_kboard->Vlast_prefix_arg = Qnil; |
df0f2ba1 | 1080 | cancel_echoing (); |
a9f16aa9 KH |
1081 | |
1082 | /* Avoid unquittable loop if data contains a circular list. */ | |
1083 | old_level = Vprint_level; | |
1084 | old_length = Vprint_length; | |
0c04a67e RS |
1085 | XSETFASTINT (Vprint_level, 10); |
1086 | XSETFASTINT (Vprint_length, 10); | |
e881d8b2 | 1087 | cmd_error_internal (data, macroerror); |
a9f16aa9 KH |
1088 | Vprint_level = old_level; |
1089 | Vprint_length = old_length; | |
a1341f75 RS |
1090 | |
1091 | Vquit_flag = Qnil; | |
1092 | ||
1093 | Vinhibit_quit = Qnil; | |
c5fdd383 | 1094 | #ifdef MULTI_KBOARD |
1e8bd3da | 1095 | any_kboard_state (); |
ff4b06d3 | 1096 | #endif |
a1341f75 RS |
1097 | |
1098 | return make_number (0); | |
1099 | } | |
1100 | ||
301738ed RS |
1101 | /* Take actions on handling an error. DATA is the data that describes |
1102 | the error. | |
1103 | ||
1104 | CONTEXT is a C-string containing ASCII characters only which | |
1105 | describes the context in which the error happened. If we need to | |
1106 | generalize CONTEXT to allow multibyte characters, make it a Lisp | |
1107 | string. */ | |
1108 | ||
07a59269 | 1109 | void |
a1341f75 RS |
1110 | cmd_error_internal (data, context) |
1111 | Lisp_Object data; | |
1112 | char *context; | |
284f4730 | 1113 | { |
284f4730 | 1114 | Lisp_Object stream; |
7ee32cda | 1115 | int kill_emacs_p = 0; |
788f89eb | 1116 | struct frame *sf = SELECTED_FRAME (); |
284f4730 JB |
1117 | |
1118 | Vquit_flag = Qnil; | |
1119 | Vinhibit_quit = Qt; | |
985f9f66 | 1120 | clear_message (1, 0); |
284f4730 | 1121 | |
ff11dfa1 | 1122 | /* If the window system or terminal frame hasn't been initialized |
284f4730 JB |
1123 | yet, or we're not interactive, it's best to dump this message out |
1124 | to stderr and exit. */ | |
788f89eb | 1125 | if (!sf->glyphs_initialized_p |
7ee32cda GM |
1126 | /* This is the case of the frame dumped with Emacs, when we're |
1127 | running under a window system. */ | |
1128 | || (!NILP (Vwindow_system) | |
1129 | && !inhibit_window_system | |
788f89eb | 1130 | && FRAME_TERMCAP_P (sf)) |
284f4730 | 1131 | || noninteractive) |
7ee32cda GM |
1132 | { |
1133 | stream = Qexternal_debugging_output; | |
1134 | kill_emacs_p = 1; | |
1135 | } | |
284f4730 JB |
1136 | else |
1137 | { | |
1138 | Fdiscard_input (); | |
1139 | bitch_at_user (); | |
1140 | stream = Qt; | |
1141 | } | |
1142 | ||
a1341f75 RS |
1143 | if (context != 0) |
1144 | write_string_1 (context, -1, stream); | |
1145 | ||
22a51344 | 1146 | print_error_message (data, stream); |
284f4730 | 1147 | |
ff11dfa1 | 1148 | /* If the window system or terminal frame hasn't been initialized |
284f4730 | 1149 | yet, or we're in -batch mode, this error should cause Emacs to exit. */ |
7ee32cda | 1150 | if (kill_emacs_p) |
284f4730 JB |
1151 | { |
1152 | Fterpri (stream); | |
1153 | Fkill_emacs (make_number (-1)); | |
1154 | } | |
284f4730 JB |
1155 | } |
1156 | \f | |
1157 | Lisp_Object command_loop_1 (); | |
1158 | Lisp_Object command_loop_2 (); | |
1159 | Lisp_Object top_level_1 (); | |
1160 | ||
1161 | /* Entry to editor-command-loop. | |
1162 | This level has the catches for exiting/returning to editor command loop. | |
1163 | It returns nil to exit recursive edit, t to abort it. */ | |
1164 | ||
1165 | Lisp_Object | |
1166 | command_loop () | |
1167 | { | |
1168 | if (command_loop_level > 0 || minibuf_level > 0) | |
1169 | { | |
07ba902e RS |
1170 | Lisp_Object val; |
1171 | val = internal_catch (Qexit, command_loop_2, Qnil); | |
68c46464 RS |
1172 | executing_macro = Qnil; |
1173 | return val; | |
284f4730 JB |
1174 | } |
1175 | else | |
1176 | while (1) | |
1177 | { | |
1178 | internal_catch (Qtop_level, top_level_1, Qnil); | |
1179 | internal_catch (Qtop_level, command_loop_2, Qnil); | |
68c46464 | 1180 | executing_macro = Qnil; |
df0f2ba1 | 1181 | |
284f4730 JB |
1182 | /* End of file in -batch run causes exit here. */ |
1183 | if (noninteractive) | |
1184 | Fkill_emacs (Qt); | |
1185 | } | |
1186 | } | |
1187 | ||
1188 | /* Here we catch errors in execution of commands within the | |
1189 | editing loop, and reenter the editing loop. | |
1190 | When there is an error, cmd_error runs and returns a non-nil | |
1191 | value to us. A value of nil means that cmd_loop_1 itself | |
1192 | returned due to end of file (or end of kbd macro). */ | |
1193 | ||
1194 | Lisp_Object | |
1195 | command_loop_2 () | |
1196 | { | |
1197 | register Lisp_Object val; | |
1198 | ||
1199 | do | |
1200 | val = internal_condition_case (command_loop_1, Qerror, cmd_error); | |
1201 | while (!NILP (val)); | |
1202 | ||
1203 | return Qnil; | |
1204 | } | |
1205 | ||
1206 | Lisp_Object | |
1207 | top_level_2 () | |
1208 | { | |
1209 | return Feval (Vtop_level); | |
1210 | } | |
1211 | ||
1212 | Lisp_Object | |
1213 | top_level_1 () | |
1214 | { | |
1215 | /* On entry to the outer level, run the startup file */ | |
1216 | if (!NILP (Vtop_level)) | |
1217 | internal_condition_case (top_level_2, Qerror, cmd_error); | |
1218 | else if (!NILP (Vpurify_flag)) | |
1219 | message ("Bare impure Emacs (standard Lisp code not loaded)"); | |
1220 | else | |
1221 | message ("Bare Emacs (standard Lisp code not loaded)"); | |
1222 | return Qnil; | |
1223 | } | |
1224 | ||
1225 | DEFUN ("top-level", Ftop_level, Stop_level, 0, 0, "", | |
1226 | "Exit all recursive editing levels.") | |
1227 | () | |
1228 | { | |
2c9cf2c8 GM |
1229 | #ifdef HAVE_X_WINDOWS |
1230 | if (display_busy_cursor_p) | |
1231 | cancel_busy_cursor (); | |
1232 | #endif | |
8c907a56 | 1233 | return Fthrow (Qtop_level, Qnil); |
284f4730 JB |
1234 | } |
1235 | ||
1236 | DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, "", | |
1237 | "Exit from the innermost recursive edit or minibuffer.") | |
1238 | () | |
1239 | { | |
1240 | if (command_loop_level > 0 || minibuf_level > 0) | |
1241 | Fthrow (Qexit, Qnil); | |
1242 | ||
1243 | error ("No recursive edit is in progress"); | |
8c907a56 | 1244 | return Qnil; |
284f4730 JB |
1245 | } |
1246 | ||
1247 | DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0, 0, "", | |
1248 | "Abort the command that requested this recursive edit or minibuffer input.") | |
1249 | () | |
1250 | { | |
1251 | if (command_loop_level > 0 || minibuf_level > 0) | |
1252 | Fthrow (Qexit, Qt); | |
1253 | ||
1254 | error ("No recursive edit is in progress"); | |
8c907a56 | 1255 | return Qnil; |
284f4730 JB |
1256 | } |
1257 | \f | |
1258 | /* This is the actual command reading loop, | |
1259 | sans error-handling encapsulation. */ | |
1260 | ||
1261 | Lisp_Object Fcommand_execute (); | |
1262 | static int read_key_sequence (); | |
68f297c5 | 1263 | void safe_run_hooks (); |
adf5cb9c | 1264 | static void adjust_point_for_property (); |
284f4730 JB |
1265 | |
1266 | Lisp_Object | |
1267 | command_loop_1 () | |
1268 | { | |
03cee6ae GM |
1269 | Lisp_Object cmd; |
1270 | int lose; | |
284f4730 JB |
1271 | int nonundocount; |
1272 | Lisp_Object keybuf[30]; | |
1273 | int i; | |
284f4730 | 1274 | int no_direct; |
86e5706b | 1275 | int prev_modiff; |
8c907a56 | 1276 | struct buffer *prev_buffer = NULL; |
c5fdd383 | 1277 | #ifdef MULTI_KBOARD |
1e8bd3da | 1278 | int was_locked = single_kboard; |
bded54dd | 1279 | #endif |
284f4730 | 1280 | |
d9b641bb | 1281 | current_kboard->Vprefix_arg = Qnil; |
75045dcb | 1282 | current_kboard->Vlast_prefix_arg = Qnil; |
86e5706b | 1283 | Vdeactivate_mark = Qnil; |
284f4730 | 1284 | waiting_for_input = 0; |
df0f2ba1 | 1285 | cancel_echoing (); |
284f4730 | 1286 | |
284f4730 | 1287 | nonundocount = 0; |
284f4730 | 1288 | this_command_key_count = 0; |
6321824f | 1289 | this_single_command_key_start = 0; |
284f4730 | 1290 | |
a612e298 RS |
1291 | /* Make sure this hook runs after commands that get errors and |
1292 | throw to top level. */ | |
a98ea3f9 RS |
1293 | /* Note that the value cell will never directly contain nil |
1294 | if the symbol is a local variable. */ | |
e98a93eb | 1295 | if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) |
a98ea3f9 | 1296 | safe_run_hooks (Qpost_command_hook); |
a612e298 | 1297 | |
8f12e41d GM |
1298 | /* If displaying a message, resize the echo area window to fit |
1299 | that message's size exactly. */ | |
1300 | if (!NILP (echo_area_buffer[0])) | |
1301 | resize_echo_area_axactly (); | |
1302 | ||
8a792f3a RS |
1303 | if (!NILP (Vdeferred_action_list)) |
1304 | call0 (Vdeferred_action_function); | |
1305 | ||
e98a93eb | 1306 | if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks)) |
59aadc81 RS |
1307 | { |
1308 | if (NILP (Vunread_command_events) | |
7d18f9ae RS |
1309 | && NILP (Vunread_input_method_events) |
1310 | && NILP (Vunread_post_input_method_events) | |
59aadc81 | 1311 | && NILP (Vexecuting_macro) |
41365083 | 1312 | && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1))) |
59aadc81 RS |
1313 | safe_run_hooks (Qpost_command_idle_hook); |
1314 | } | |
1315 | ||
51d5a2c9 | 1316 | /* Do this after running Vpost_command_hook, for consistency. */ |
d5eecefb RS |
1317 | current_kboard->Vlast_command = Vthis_command; |
1318 | current_kboard->Vreal_last_command = real_this_command; | |
51d5a2c9 | 1319 | |
284f4730 JB |
1320 | while (1) |
1321 | { | |
788f89eb | 1322 | if (! FRAME_LIVE_P (XFRAME (selected_frame))) |
a94a4335 KH |
1323 | Fkill_emacs (Qnil); |
1324 | ||
284f4730 JB |
1325 | /* Make sure the current window's buffer is selected. */ |
1326 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
1327 | set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer)); | |
1328 | ||
1329 | /* Display any malloc warning that just came out. Use while because | |
1330 | displaying one warning can cause another. */ | |
1331 | ||
1332 | while (pending_malloc_warning) | |
1333 | display_malloc_warning (); | |
1334 | ||
1335 | no_direct = 0; | |
1336 | ||
86e5706b RS |
1337 | Vdeactivate_mark = Qnil; |
1338 | ||
284f4730 | 1339 | /* If minibuffer on and echo area in use, |
00392ce6 | 1340 | wait a short time and redraw minibuffer. */ |
284f4730 | 1341 | |
7ee32cda | 1342 | if (minibuf_level |
985f9f66 | 1343 | && !NILP (echo_area_buffer[0]) |
00392ce6 MB |
1344 | && EQ (minibuf_window, echo_area_window) |
1345 | && NUMBERP (Vminibuffer_message_timeout)) | |
284f4730 | 1346 | { |
f1bed6d8 RS |
1347 | /* Bind inhibit-quit to t so that C-g gets read in |
1348 | rather than quitting back to the minibuffer. */ | |
1349 | int count = specpdl_ptr - specpdl; | |
1350 | specbind (Qinhibit_quit, Qt); | |
f1bed6d8 | 1351 | |
00392ce6 | 1352 | Fsit_for (Vminibuffer_message_timeout, Qnil, Qnil); |
e6aa7813 | 1353 | /* Clear the echo area. */ |
301738ed | 1354 | message2 (0, 0, 0); |
cdb9d665 | 1355 | safe_run_hooks (Qecho_area_clear_hook); |
e6aa7813 | 1356 | |
db08707d RS |
1357 | unbind_to (count, Qnil); |
1358 | ||
e6aa7813 | 1359 | /* If a C-g came in before, treat it as input now. */ |
284f4730 JB |
1360 | if (!NILP (Vquit_flag)) |
1361 | { | |
1362 | Vquit_flag = Qnil; | |
24597608 | 1363 | Vunread_command_events = Fcons (make_number (quit_char), Qnil); |
284f4730 JB |
1364 | } |
1365 | } | |
1366 | ||
1367 | #ifdef C_ALLOCA | |
ff4b06d3 | 1368 | alloca (0); /* Cause a garbage collection now */ |
284f4730 JB |
1369 | /* Since we can free the most stuff here. */ |
1370 | #endif /* C_ALLOCA */ | |
1371 | ||
8f805655 | 1372 | #if 0 |
8f805655 JB |
1373 | /* Select the frame that the last event came from. Usually, |
1374 | switch-frame events will take care of this, but if some lisp | |
1375 | code swallows a switch-frame event, we'll fix things up here. | |
1376 | Is this a good idea? */ | |
8c18cbfb | 1377 | if (FRAMEP (internal_last_event_frame) |
788f89eb | 1378 | && !EQ (internal_last_event_frame, selected_frame)) |
3c370943 | 1379 | Fselect_frame (internal_last_event_frame, Qnil); |
284f4730 | 1380 | #endif |
48e416d4 RS |
1381 | /* If it has changed current-menubar from previous value, |
1382 | really recompute the menubar from the value. */ | |
a646e520 RS |
1383 | if (! NILP (Vlucid_menu_bar_dirty_flag) |
1384 | && !NILP (Ffboundp (Qrecompute_lucid_menubar))) | |
48e416d4 RS |
1385 | call0 (Qrecompute_lucid_menubar); |
1386 | ||
71918b75 RS |
1387 | before_command_key_count = this_command_key_count; |
1388 | before_command_echo_length = echo_length (); | |
1389 | ||
d5eecefb RS |
1390 | Vthis_command = Qnil; |
1391 | real_this_command = Qnil; | |
d7437ef6 | 1392 | |
8f805655 | 1393 | /* Read next key sequence; i gets its length. */ |
ce98e608 | 1394 | i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0], |
f571ae0d | 1395 | Qnil, 0, 1, 1); |
8f805655 | 1396 | |
6fac1409 | 1397 | /* A filter may have run while we were reading the input. */ |
788f89eb | 1398 | if (! FRAME_LIVE_P (XFRAME (selected_frame))) |
a94a4335 | 1399 | Fkill_emacs (Qnil); |
6fac1409 RS |
1400 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) |
1401 | set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer)); | |
1402 | ||
8f805655 JB |
1403 | ++num_input_keys; |
1404 | ||
284f4730 JB |
1405 | /* Now we have read a key sequence of length I, |
1406 | or else I is 0 and we found end of file. */ | |
1407 | ||
1408 | if (i == 0) /* End of file -- happens only in */ | |
1409 | return Qnil; /* a kbd macro, at the end. */ | |
dcc408a0 RS |
1410 | /* -1 means read_key_sequence got a menu that was rejected. |
1411 | Just loop around and read another command. */ | |
1412 | if (i == -1) | |
1413 | { | |
1414 | cancel_echoing (); | |
1415 | this_command_key_count = 0; | |
6321824f | 1416 | this_single_command_key_start = 0; |
ff4b06d3 | 1417 | goto finalize; |
dcc408a0 | 1418 | } |
284f4730 | 1419 | |
284f4730 JB |
1420 | last_command_char = keybuf[i - 1]; |
1421 | ||
75c0b143 RS |
1422 | /* If the previous command tried to force a specific window-start, |
1423 | forget about that, in case this command moves point far away | |
c422836d KH |
1424 | from that position. But also throw away beg_unchanged and |
1425 | end_unchanged information in that case, so that redisplay will | |
1426 | update the whole window properly. */ | |
1427 | if (!NILP (XWINDOW (selected_window)->force_start)) | |
1428 | { | |
9351ebd0 | 1429 | struct buffer *b; |
c422836d | 1430 | XWINDOW (selected_window)->force_start = Qnil; |
9351ebd0 GM |
1431 | b = XBUFFER (XWINDOW (selected_window)->buffer); |
1432 | BUF_BEG_UNCHANGED (b) = BUF_END_UNCHANGED (b) = 0; | |
c422836d | 1433 | } |
75c0b143 | 1434 | |
284f4730 JB |
1435 | cmd = read_key_sequence_cmd; |
1436 | if (!NILP (Vexecuting_macro)) | |
1437 | { | |
1438 | if (!NILP (Vquit_flag)) | |
1439 | { | |
1440 | Vexecuting_macro = Qt; | |
1441 | QUIT; /* Make some noise. */ | |
1442 | /* Will return since macro now empty. */ | |
1443 | } | |
1444 | } | |
1445 | ||
1446 | /* Do redisplay processing after this command except in special | |
e35b6123 | 1447 | cases identified below. */ |
86e5706b RS |
1448 | prev_buffer = current_buffer; |
1449 | prev_modiff = MODIFF; | |
8746da95 | 1450 | last_point_position = PT; |
18cd2eeb | 1451 | XSETBUFFER (last_point_position_buffer, prev_buffer); |
86e5706b | 1452 | |
adf5cb9c KH |
1453 | /* By default, we adjust point to a boundary of a region that |
1454 | has such a property that should be treated intangible | |
1455 | (e.g. composition, display). But, some commands will set | |
1456 | this variable differently. */ | |
1457 | Vdisable_point_adjustment = Qnil; | |
1458 | ||
284f4730 JB |
1459 | /* Execute the command. */ |
1460 | ||
d5eecefb RS |
1461 | Vthis_command = cmd; |
1462 | real_this_command = cmd; | |
a98ea3f9 RS |
1463 | /* Note that the value cell will never directly contain nil |
1464 | if the symbol is a local variable. */ | |
e98a93eb | 1465 | if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks)) |
a98ea3f9 | 1466 | safe_run_hooks (Qpre_command_hook); |
75045dcb | 1467 | |
d5eecefb | 1468 | if (NILP (Vthis_command)) |
284f4730 JB |
1469 | { |
1470 | /* nil means key is undefined. */ | |
1471 | bitch_at_user (); | |
c5fdd383 | 1472 | current_kboard->defining_kbd_macro = Qnil; |
284f4730 | 1473 | update_mode_lines = 1; |
d8bcf58e | 1474 | current_kboard->Vprefix_arg = Qnil; |
284f4730 JB |
1475 | } |
1476 | else | |
1477 | { | |
d8bcf58e | 1478 | if (NILP (current_kboard->Vprefix_arg) && ! no_direct) |
284f4730 | 1479 | { |
75045dcb RS |
1480 | /* In case we jump to directly_done. */ |
1481 | Vcurrent_prefix_arg = current_kboard->Vprefix_arg; | |
1482 | ||
284f4730 JB |
1483 | /* Recognize some common commands in common situations and |
1484 | do them directly. */ | |
d5eecefb | 1485 | if (EQ (Vthis_command, Qforward_char) && PT < ZV) |
284f4730 | 1486 | { |
51ad8a68 | 1487 | struct Lisp_Char_Table *dp |
284f4730 | 1488 | = window_display_table (XWINDOW (selected_window)); |
aaf35234 | 1489 | lose = FETCH_CHAR (PT_BYTE); |
8458ede6 | 1490 | SET_PT (PT + 1); |
0f7a8fee | 1491 | if ((dp |
82ba47d7 | 1492 | ? (VECTORP (DISP_CHAR_VECTOR (dp, lose)) |
9a5540db RS |
1493 | ? XVECTOR (DISP_CHAR_VECTOR (dp, lose))->size == 1 |
1494 | : (NILP (DISP_CHAR_VECTOR (dp, lose)) | |
1495 | && (lose >= 0x20 && lose < 0x7f))) | |
0f7a8fee | 1496 | : (lose >= 0x20 && lose < 0x7f)) |
37cd9f30 KH |
1497 | /* To extract the case of continuation on |
1498 | wide-column characters. */ | |
8458ede6 | 1499 | && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE)) == 1) |
284f4730 JB |
1500 | && (XFASTINT (XWINDOW (selected_window)->last_modified) |
1501 | >= MODIFF) | |
598ba4c7 RS |
1502 | && (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1503 | >= OVERLAY_MODIFF) | |
284f4730 | 1504 | && (XFASTINT (XWINDOW (selected_window)->last_point) |
8001d352 | 1505 | == PT - 1) |
284f4730 JB |
1506 | && !windows_or_buffers_changed |
1507 | && EQ (current_buffer->selective_display, Qnil) | |
1508 | && !detect_input_pending () | |
962ae636 | 1509 | && NILP (XWINDOW (selected_window)->column_number_displayed) |
284f4730 | 1510 | && NILP (Vexecuting_macro)) |
e35b6123 | 1511 | direct_output_forward_char (1); |
284f4730 JB |
1512 | goto directly_done; |
1513 | } | |
d5eecefb | 1514 | else if (EQ (Vthis_command, Qbackward_char) && PT > BEGV) |
284f4730 | 1515 | { |
51ad8a68 | 1516 | struct Lisp_Char_Table *dp |
284f4730 | 1517 | = window_display_table (XWINDOW (selected_window)); |
8458ede6 | 1518 | SET_PT (PT - 1); |
aaf35234 | 1519 | lose = FETCH_CHAR (PT_BYTE); |
0f7a8fee | 1520 | if ((dp |
ca873d73 | 1521 | ? (VECTORP (DISP_CHAR_VECTOR (dp, lose)) |
9a5540db RS |
1522 | ? XVECTOR (DISP_CHAR_VECTOR (dp, lose))->size == 1 |
1523 | : (NILP (DISP_CHAR_VECTOR (dp, lose)) | |
1524 | && (lose >= 0x20 && lose < 0x7f))) | |
0f7a8fee | 1525 | : (lose >= 0x20 && lose < 0x7f)) |
284f4730 JB |
1526 | && (XFASTINT (XWINDOW (selected_window)->last_modified) |
1527 | >= MODIFF) | |
598ba4c7 RS |
1528 | && (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1529 | >= OVERLAY_MODIFF) | |
284f4730 | 1530 | && (XFASTINT (XWINDOW (selected_window)->last_point) |
8001d352 | 1531 | == PT + 1) |
284f4730 JB |
1532 | && !windows_or_buffers_changed |
1533 | && EQ (current_buffer->selective_display, Qnil) | |
1534 | && !detect_input_pending () | |
962ae636 | 1535 | && NILP (XWINDOW (selected_window)->column_number_displayed) |
284f4730 | 1536 | && NILP (Vexecuting_macro)) |
e35b6123 | 1537 | direct_output_forward_char (-1); |
284f4730 JB |
1538 | goto directly_done; |
1539 | } | |
d5eecefb | 1540 | else if (EQ (Vthis_command, Qself_insert_command) |
284f4730 | 1541 | /* Try this optimization only on ascii keystrokes. */ |
8c18cbfb | 1542 | && INTEGERP (last_command_char)) |
284f4730 | 1543 | { |
89599794 | 1544 | unsigned int c = XINT (last_command_char); |
fc9cce4e | 1545 | int value; |
fc9cce4e RS |
1546 | if (NILP (Vexecuting_macro) |
1547 | && !EQ (minibuf_window, selected_window)) | |
284f4730 JB |
1548 | { |
1549 | if (!nonundocount || nonundocount >= 20) | |
1550 | { | |
1551 | Fundo_boundary (); | |
1552 | nonundocount = 0; | |
1553 | } | |
1554 | nonundocount++; | |
1555 | } | |
7ee32cda | 1556 | |
fc9cce4e RS |
1557 | lose = ((XFASTINT (XWINDOW (selected_window)->last_modified) |
1558 | < MODIFF) | |
598ba4c7 RS |
1559 | || (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1560 | < OVERLAY_MODIFF) | |
fc9cce4e RS |
1561 | || (XFASTINT (XWINDOW (selected_window)->last_point) |
1562 | != PT) | |
4c61f38e | 1563 | || MODIFF <= SAVE_MODIFF |
fc9cce4e RS |
1564 | || windows_or_buffers_changed |
1565 | || !EQ (current_buffer->selective_display, Qnil) | |
1566 | || detect_input_pending () | |
962ae636 | 1567 | || !NILP (XWINDOW (selected_window)->column_number_displayed) |
fc9cce4e | 1568 | || !NILP (Vexecuting_macro)); |
7ee32cda | 1569 | |
fc9cce4e | 1570 | value = internal_self_insert (c, 0); |
7ee32cda | 1571 | |
fc9cce4e RS |
1572 | if (value == 2) |
1573 | nonundocount = 0; | |
1574 | ||
7ee32cda GM |
1575 | /* VALUE == 1 when AFTER-CHANGE functions are |
1576 | installed which is the case most of the time | |
1577 | because FONT-LOCK installs one. */ | |
1578 | if (!lose && !value) | |
e35b6123 | 1579 | direct_output_for_insert (c); |
284f4730 JB |
1580 | goto directly_done; |
1581 | } | |
1582 | } | |
1583 | ||
1584 | /* Here for a command that isn't executed directly */ | |
1585 | ||
7ee32cda GM |
1586 | #ifdef HAVE_X_WINDOWS |
1587 | if (display_busy_cursor_p) | |
d0c48478 | 1588 | start_busy_cursor (); |
7ee32cda GM |
1589 | #endif |
1590 | ||
284f4730 | 1591 | nonundocount = 0; |
d8bcf58e | 1592 | if (NILP (current_kboard->Vprefix_arg)) |
284f4730 | 1593 | Fundo_boundary (); |
d5eecefb | 1594 | Fcommand_execute (Vthis_command, Qnil, Qnil, Qnil); |
d0c48478 GM |
1595 | |
1596 | #ifdef HAVE_X_WINDOWS | |
1597 | if (display_busy_cursor_p) | |
1598 | cancel_busy_cursor (); | |
1599 | #endif | |
284f4730 | 1600 | } |
a764a753 | 1601 | directly_done: ; |
75045dcb | 1602 | current_kboard->Vlast_prefix_arg = Vcurrent_prefix_arg; |
284f4730 | 1603 | |
84ee6048 RS |
1604 | /* Note that the value cell will never directly contain nil |
1605 | if the symbol is a local variable. */ | |
1606 | if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) | |
1607 | safe_run_hooks (Qpost_command_hook); | |
1608 | ||
8f12e41d GM |
1609 | /* If displaying a message, resize the echo area window to fit |
1610 | that message's size exactly. */ | |
1611 | if (!NILP (echo_area_buffer[0])) | |
1612 | resize_echo_area_axactly (); | |
1613 | ||
84ee6048 RS |
1614 | if (!NILP (Vdeferred_action_list)) |
1615 | safe_run_hooks (Qdeferred_action_function); | |
1616 | ||
1617 | if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks)) | |
1618 | { | |
1619 | if (NILP (Vunread_command_events) | |
7d18f9ae RS |
1620 | && NILP (Vunread_input_method_events) |
1621 | && NILP (Vunread_post_input_method_events) | |
84ee6048 RS |
1622 | && NILP (Vexecuting_macro) |
1623 | && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1))) | |
1624 | safe_run_hooks (Qpost_command_idle_hook); | |
1625 | } | |
1626 | ||
284f4730 | 1627 | /* If there is a prefix argument, |
6c7178b9 KH |
1628 | 1) We don't want Vlast_command to be ``universal-argument'' |
1629 | (that would be dumb), so don't set Vlast_command, | |
284f4730 JB |
1630 | 2) we want to leave echoing on so that the prefix will be |
1631 | echoed as part of this key sequence, so don't call | |
1632 | cancel_echoing, and | |
1633 | 3) we want to leave this_command_key_count non-zero, so that | |
1634 | read_char will realize that it is re-reading a character, and | |
217258d5 KH |
1635 | not echo it a second time. |
1636 | ||
1637 | If the command didn't actually create a prefix arg, | |
1638 | but is merely a frame event that is transparent to prefix args, | |
1639 | then the above doesn't apply. */ | |
1640 | if (NILP (current_kboard->Vprefix_arg) || CONSP (last_command_char)) | |
284f4730 | 1641 | { |
d5eecefb RS |
1642 | current_kboard->Vlast_command = Vthis_command; |
1643 | current_kboard->Vreal_last_command = real_this_command; | |
284f4730 JB |
1644 | cancel_echoing (); |
1645 | this_command_key_count = 0; | |
6321824f | 1646 | this_single_command_key_start = 0; |
284f4730 | 1647 | } |
86e5706b | 1648 | |
88ce066e | 1649 | if (!NILP (current_buffer->mark_active) && !NILP (Vrun_hooks)) |
86e5706b RS |
1650 | { |
1651 | if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode)) | |
1652 | { | |
1653 | current_buffer->mark_active = Qnil; | |
1654 | call1 (Vrun_hooks, intern ("deactivate-mark-hook")); | |
1655 | } | |
1656 | else if (current_buffer != prev_buffer || MODIFF != prev_modiff) | |
1657 | call1 (Vrun_hooks, intern ("activate-mark-hook")); | |
1658 | } | |
ff4b06d3 KH |
1659 | |
1660 | finalize: | |
adf5cb9c KH |
1661 | |
1662 | if (current_buffer == prev_buffer | |
1663 | && last_point_position != PT | |
1664 | && NILP (Vdisable_point_adjustment) | |
1665 | && NILP (Vglobal_disable_point_adjustment)) | |
1666 | adjust_point_for_property (last_point_position); | |
1667 | ||
ff4b06d3 KH |
1668 | /* Install chars successfully executed in kbd macro. */ |
1669 | ||
d8bcf58e KH |
1670 | if (!NILP (current_kboard->defining_kbd_macro) |
1671 | && NILP (current_kboard->Vprefix_arg)) | |
ff4b06d3 KH |
1672 | finalize_kbd_macro_chars (); |
1673 | ||
c5fdd383 | 1674 | #ifdef MULTI_KBOARD |
604ccd1d | 1675 | if (!was_locked) |
1e8bd3da | 1676 | any_kboard_state (); |
ff4b06d3 | 1677 | #endif |
284f4730 JB |
1678 | } |
1679 | } | |
1c9784c9 | 1680 | |
adf5cb9c KH |
1681 | extern Lisp_Object Qcomposition, Qdisplay; |
1682 | ||
1683 | /* Adjust point to a boundary of a region that has such a property | |
1684 | that should be treated intangible. For the moment, we check | |
1685 | `composition' and `display' property. LAST_PT is the last position | |
1686 | of point. */ | |
1687 | ||
1688 | static void | |
1689 | adjust_point_for_property (last_pt) | |
1690 | int last_pt; | |
1691 | { | |
1692 | int start, end; | |
1693 | Lisp_Object val; | |
1694 | int check_composition = 1, check_display = 1; | |
1695 | ||
1696 | while (check_composition || check_display) | |
1697 | { | |
1698 | if (check_composition | |
1699 | && PT > BEGV && PT < ZV | |
1700 | && get_property_and_range (PT, Qcomposition, &val, &start, &end, Qnil) | |
1701 | && COMPOSITION_VALID_P (start, end, val) | |
1702 | && start < PT && end > PT | |
1703 | && (last_pt <= start || last_pt >= end)) | |
1704 | { | |
1705 | if (PT < last_pt) | |
1706 | SET_PT (start); | |
1707 | else | |
1708 | SET_PT (end); | |
1709 | check_display = 1; | |
1710 | } | |
1711 | check_composition = 0; | |
1712 | if (check_display | |
1713 | && PT > BEGV && PT < ZV | |
1714 | && get_property_and_range (PT, Qdisplay, &val, &start, &end, Qnil) | |
3e9ac4b7 | 1715 | && display_prop_intangible_p (val) |
adf5cb9c KH |
1716 | && start < PT && end > PT |
1717 | && (last_pt <= start || last_pt >= end)) | |
1718 | { | |
1719 | if (PT < last_pt) | |
1720 | SET_PT (start); | |
1721 | else | |
1722 | SET_PT (end); | |
1723 | check_composition = 1; | |
1724 | } | |
1725 | check_display = 0; | |
1726 | } | |
1727 | } | |
1728 | ||
0bc3db2b RS |
1729 | /* Subroutine for safe_run_hooks: run the hook HOOK. */ |
1730 | ||
1731 | static Lisp_Object | |
1732 | safe_run_hooks_1 (hook) | |
1733 | Lisp_Object hook; | |
1734 | { | |
1735 | return call1 (Vrun_hooks, Vinhibit_quit); | |
1736 | } | |
1737 | ||
1738 | /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */ | |
1739 | ||
1740 | static Lisp_Object | |
1741 | safe_run_hooks_error (data) | |
1742 | Lisp_Object data; | |
1743 | { | |
30690496 | 1744 | return Fset (Vinhibit_quit, Qnil); |
0bc3db2b RS |
1745 | } |
1746 | ||
1c9784c9 KH |
1747 | /* If we get an error while running the hook, cause the hook variable |
1748 | to be nil. Also inhibit quits, so that C-g won't cause the hook | |
1749 | to mysteriously evaporate. */ | |
0bc3db2b | 1750 | |
68f297c5 | 1751 | void |
1c9784c9 | 1752 | safe_run_hooks (hook) |
a98ea3f9 | 1753 | Lisp_Object hook; |
1c9784c9 KH |
1754 | { |
1755 | int count = specpdl_ptr - specpdl; | |
0bc3db2b RS |
1756 | specbind (Qinhibit_quit, hook); |
1757 | ||
e702932d | 1758 | internal_condition_case (safe_run_hooks_1, Qt, safe_run_hooks_error); |
1c9784c9 KH |
1759 | |
1760 | unbind_to (count, Qnil); | |
1761 | } | |
8a9f5d3c | 1762 | |
284f4730 | 1763 | \f |
8a9f5d3c GM |
1764 | /* Number of seconds between polling for input. This is a Lisp |
1765 | variable that can be bound. */ | |
1766 | ||
284f4730 JB |
1767 | int polling_period; |
1768 | ||
eb8c3be9 | 1769 | /* Nonzero means polling for input is temporarily suppressed. */ |
8a9f5d3c | 1770 | |
284f4730 JB |
1771 | int poll_suppress_count; |
1772 | ||
8a9f5d3c GM |
1773 | /* Asynchronous timer for polling. */ |
1774 | ||
1775 | struct atimer *poll_timer; | |
1776 | ||
284f4730 | 1777 | |
36922b18 RS |
1778 | #ifdef POLL_FOR_INPUT |
1779 | ||
8a9f5d3c GM |
1780 | /* Poll for input, so what we catch a C-g if it comes in. This |
1781 | function is called from x_make_frame_visible, see comment | |
1782 | there. */ | |
284f4730 | 1783 | |
8a9f5d3c GM |
1784 | void |
1785 | poll_for_input_1 () | |
284f4730 | 1786 | { |
9ac0d9e0 JB |
1787 | if (interrupt_input_blocked == 0 |
1788 | && !waiting_for_input) | |
1789 | read_avail_input (0); | |
284f4730 JB |
1790 | } |
1791 | ||
8a9f5d3c GM |
1792 | /* Timer callback function for poll_timer. TIMER is equal to |
1793 | poll_timer. */ | |
1794 | ||
1795 | void | |
1796 | poll_for_input (timer) | |
1797 | struct atimer *timer; | |
1798 | { | |
1799 | if (poll_suppress_count == 0) | |
1800 | poll_for_input_1 (); | |
1801 | } | |
1802 | ||
1803 | #endif /* POLL_FOR_INPUT */ | |
284f4730 JB |
1804 | |
1805 | /* Begin signals to poll for input, if they are appropriate. | |
1806 | This function is called unconditionally from various places. */ | |
1807 | ||
07a59269 | 1808 | void |
284f4730 JB |
1809 | start_polling () |
1810 | { | |
1811 | #ifdef POLL_FOR_INPUT | |
34f04431 | 1812 | if (read_socket_hook && !interrupt_input) |
284f4730 | 1813 | { |
8a9f5d3c GM |
1814 | /* Turn alarm handling on unconditionally. It might have |
1815 | been turned off in process.c. */ | |
1816 | turn_on_atimers (1); | |
1817 | ||
1818 | /* If poll timer doesn't exist, are we need one with | |
1819 | a different interval, start a new one. */ | |
1820 | if (poll_timer == NULL | |
1821 | || EMACS_SECS (poll_timer->interval) != polling_period) | |
284f4730 | 1822 | { |
8a9f5d3c GM |
1823 | EMACS_TIME interval; |
1824 | ||
1825 | if (poll_timer) | |
1826 | cancel_atimer (poll_timer); | |
1827 | ||
1828 | EMACS_SET_SECS_USECS (interval, polling_period, 0); | |
1829 | poll_timer = start_atimer (ATIMER_CONTINUOUS, interval, | |
1830 | poll_for_input, NULL); | |
284f4730 | 1831 | } |
8a9f5d3c GM |
1832 | |
1833 | /* Let the timer's callback function poll for input | |
1834 | if this becomes zero. */ | |
1835 | --poll_suppress_count; | |
284f4730 JB |
1836 | } |
1837 | #endif | |
1838 | } | |
1839 | ||
1d3195db RS |
1840 | /* Nonzero if we are using polling to handle input asynchronously. */ |
1841 | ||
1842 | int | |
1843 | input_polling_used () | |
1844 | { | |
1845 | #ifdef POLL_FOR_INPUT | |
1846 | return read_socket_hook && !interrupt_input; | |
1847 | #else | |
1848 | return 0; | |
1849 | #endif | |
1850 | } | |
1851 | ||
284f4730 JB |
1852 | /* Turn off polling. */ |
1853 | ||
07a59269 | 1854 | void |
284f4730 JB |
1855 | stop_polling () |
1856 | { | |
1857 | #ifdef POLL_FOR_INPUT | |
34f04431 | 1858 | if (read_socket_hook && !interrupt_input) |
8a9f5d3c | 1859 | ++poll_suppress_count; |
284f4730 JB |
1860 | #endif |
1861 | } | |
fe8aeef3 RS |
1862 | |
1863 | /* Set the value of poll_suppress_count to COUNT | |
1864 | and start or stop polling accordingly. */ | |
1865 | ||
1866 | void | |
1867 | set_poll_suppress_count (count) | |
1868 | int count; | |
1869 | { | |
1870 | #ifdef POLL_FOR_INPUT | |
1871 | if (count == 0 && poll_suppress_count != 0) | |
1872 | { | |
1873 | poll_suppress_count = 1; | |
1874 | start_polling (); | |
1875 | } | |
1876 | else if (count != 0 && poll_suppress_count == 0) | |
1877 | { | |
1878 | stop_polling (); | |
1879 | } | |
1880 | poll_suppress_count = count; | |
1881 | #endif | |
1882 | } | |
f4eef8b4 | 1883 | |
d0a57728 RS |
1884 | /* Bind polling_period to a value at least N. |
1885 | But don't decrease it. */ | |
1886 | ||
07a59269 | 1887 | void |
f4eef8b4 RS |
1888 | bind_polling_period (n) |
1889 | int n; | |
1890 | { | |
1891 | #ifdef POLL_FOR_INPUT | |
d0a57728 RS |
1892 | int new = polling_period; |
1893 | ||
1894 | if (n > new) | |
1895 | new = n; | |
1896 | ||
6fe007f7 | 1897 | stop_other_atimers (poll_timer); |
f4eef8b4 | 1898 | stop_polling (); |
d0a57728 RS |
1899 | specbind (Qpolling_period, make_number (new)); |
1900 | /* Start a new alarm with the new period. */ | |
f4eef8b4 RS |
1901 | start_polling (); |
1902 | #endif | |
1903 | } | |
284f4730 | 1904 | \f |
6da3dd3a RS |
1905 | /* Apply the control modifier to CHARACTER. */ |
1906 | ||
faf5e407 JB |
1907 | int |
1908 | make_ctrl_char (c) | |
1909 | int c; | |
1910 | { | |
d205953b JB |
1911 | /* Save the upper bits here. */ |
1912 | int upper = c & ~0177; | |
1913 | ||
1914 | c &= 0177; | |
1915 | ||
1916 | /* Everything in the columns containing the upper-case letters | |
1917 | denotes a control character. */ | |
1918 | if (c >= 0100 && c < 0140) | |
1919 | { | |
1920 | int oc = c; | |
1921 | c &= ~0140; | |
1922 | /* Set the shift modifier for a control char | |
1923 | made from a shifted letter. But only for letters! */ | |
1924 | if (oc >= 'A' && oc <= 'Z') | |
1925 | c |= shift_modifier; | |
1926 | } | |
1927 | ||
1928 | /* The lower-case letters denote control characters too. */ | |
1929 | else if (c >= 'a' && c <= 'z') | |
1930 | c &= ~0140; | |
1931 | ||
1932 | /* Include the bits for control and shift | |
1933 | only if the basic ASCII code can't indicate them. */ | |
1934 | else if (c >= ' ') | |
1935 | c |= ctrl_modifier; | |
1936 | ||
1937 | /* Replace the high bits. */ | |
1938 | c |= (upper & ~ctrl_modifier); | |
faf5e407 JB |
1939 | |
1940 | return c; | |
1941 | } | |
1942 | ||
d4e68eea GM |
1943 | /* Display help echo in the echo area. |
1944 | ||
8dfd92c9 GM |
1945 | HELP a string means display that string, HELP nil means clear the |
1946 | help echo. If HELP is a function, call it with OBJECT and POS as | |
1947 | arguments; the function should return a help string or nil for | |
1948 | none. For all other types of HELP evaluate it to obtain a string. | |
1949 | ||
2190735a GM |
1950 | WINDOW is the window in which the help was generated, if any. |
1951 | It is nil if not in a window. | |
1952 | ||
5b2ec2d0 GM |
1953 | If OBJECT is a buffer, POS is the position in the buffer where the |
1954 | `help-echo' text property was found. | |
1955 | ||
1956 | If OBJECT is an overlay, that overlay has a `help-echo' property, | |
1957 | and POS is the position in the overlay's buffer under the mouse. | |
1958 | ||
1959 | If OBJECT is a string (an overlay string or a string displayed with | |
1960 | the `display' property). POS is the position in that string under | |
1961 | the mouse. | |
d4e68eea GM |
1962 | |
1963 | OK_TO_IVERWRITE_KEYSTROKE_ECHO non-zero means it's okay if the help | |
1964 | echo overwrites a keystroke echo currently displayed in the echo | |
1965 | area. | |
1966 | ||
8dfd92c9 GM |
1967 | Note: this function may only be called with HELP nil or a string |
1968 | from X code running asynchronously. */ | |
d4e68eea | 1969 | |
31f84d03 | 1970 | void |
2190735a GM |
1971 | show_help_echo (help, window, object, pos, ok_to_overwrite_keystroke_echo) |
1972 | Lisp_Object help, window, object, pos; | |
adc84f48 | 1973 | int ok_to_overwrite_keystroke_echo; |
31f84d03 | 1974 | { |
8dfd92c9 | 1975 | if (!NILP (help) && !STRINGP (help)) |
d4e68eea | 1976 | { |
8dfd92c9 GM |
1977 | if (FUNCTIONP (help)) |
1978 | { | |
2190735a | 1979 | Lisp_Object args[4]; |
8dfd92c9 | 1980 | args[0] = help; |
2190735a GM |
1981 | args[1] = window; |
1982 | args[2] = object; | |
1983 | args[3] = pos; | |
1db0076e | 1984 | help = safe_call (4, args); |
8dfd92c9 GM |
1985 | } |
1986 | else | |
1db0076e | 1987 | help = safe_eval (help); |
8dfd92c9 GM |
1988 | |
1989 | if (!STRINGP (help)) | |
d4e68eea | 1990 | return; |
31f84d03 SM |
1991 | } |
1992 | ||
8dfd92c9 | 1993 | if (STRINGP (help) || NILP (help)) |
d4e68eea GM |
1994 | { |
1995 | if (!NILP (Vshow_help_function)) | |
8dfd92c9 | 1996 | call1 (Vshow_help_function, help); |
d4e68eea GM |
1997 | else if (/* Don't overwrite minibuffer contents. */ |
1998 | !MINI_WINDOW_P (XWINDOW (selected_window)) | |
1999 | /* Don't overwrite a keystroke echo. */ | |
8dfd92c9 GM |
2000 | && (NILP (echo_message_buffer) |
2001 | || ok_to_overwrite_keystroke_echo) | |
d4e68eea GM |
2002 | /* Don't overwrite a prompt. */ |
2003 | && !cursor_in_echo_area) | |
2004 | { | |
8dfd92c9 | 2005 | if (STRINGP (help)) |
d4e68eea GM |
2006 | { |
2007 | int count = specpdl_ptr - specpdl; | |
2008 | specbind (Qmessage_truncate_lines, Qt); | |
5ca020fc | 2009 | message3_nolog (help, STRING_BYTES (XSTRING (help)), |
8dfd92c9 | 2010 | STRING_MULTIBYTE (help)); |
d4e68eea GM |
2011 | unbind_to (count, Qnil); |
2012 | } | |
2013 | else | |
5295a500 | 2014 | message (0); |
d4e68eea | 2015 | } |
5295a500 GM |
2016 | |
2017 | help_echo_showing_p = STRINGP (help); | |
d4e68eea | 2018 | } |
31f84d03 SM |
2019 | } |
2020 | ||
faf5e407 JB |
2021 | |
2022 | \f | |
284f4730 JB |
2023 | /* Input of single characters from keyboard */ |
2024 | ||
2025 | Lisp_Object print_help (); | |
2026 | static Lisp_Object kbd_buffer_get_event (); | |
e4fe371d | 2027 | static void record_char (); |
284f4730 | 2028 | |
c5fdd383 KH |
2029 | #ifdef MULTI_KBOARD |
2030 | static jmp_buf wrong_kboard_jmpbuf; | |
bded54dd | 2031 | #endif |
beecf6a1 | 2032 | |
284f4730 JB |
2033 | /* read a character from the keyboard; call the redisplay if needed */ |
2034 | /* commandflag 0 means do not do auto-saving, but do do redisplay. | |
2035 | -1 means do not do redisplay, but do do autosaving. | |
2036 | 1 means do both. */ | |
2037 | ||
7d6de002 RS |
2038 | /* The arguments MAPS and NMAPS are for menu prompting. |
2039 | MAPS is an array of keymaps; NMAPS is the length of MAPS. | |
2040 | ||
2041 | PREV_EVENT is the previous input event, or nil if we are reading | |
b638f328 RS |
2042 | the first event of a key sequence (or not reading a key sequence). |
2043 | If PREV_EVENT is t, that is a "magic" value that says | |
2044 | not to run input methods, but in other respects to act as if | |
2045 | not reading a key sequence. | |
7d6de002 | 2046 | |
83d68044 | 2047 | If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1 |
6569cc8d | 2048 | if we used a mouse menu to read the input, or zero otherwise. If |
83d68044 | 2049 | USED_MOUSE_MENU is null, we don't dereference it. |
dcc408a0 RS |
2050 | |
2051 | Value is t if we showed a menu and the user rejected it. */ | |
7d6de002 | 2052 | |
284f4730 | 2053 | Lisp_Object |
7d6de002 | 2054 | read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu) |
284f4730 | 2055 | int commandflag; |
7d6de002 RS |
2056 | int nmaps; |
2057 | Lisp_Object *maps; | |
2058 | Lisp_Object prev_event; | |
2059 | int *used_mouse_menu; | |
284f4730 | 2060 | { |
8c907a56 | 2061 | volatile Lisp_Object c; |
284f4730 | 2062 | int count; |
410d4de9 | 2063 | jmp_buf local_getcjmp; |
284f4730 | 2064 | jmp_buf save_jump; |
8c907a56 | 2065 | volatile int key_already_recorded = 0; |
017c7cb6 | 2066 | Lisp_Object tem, save; |
8c907a56 GM |
2067 | volatile Lisp_Object previous_echo_area_message; |
2068 | volatile Lisp_Object also_record; | |
2069 | volatile int reread; | |
d5eecefb | 2070 | struct gcpro gcpro1, gcpro2; |
7c3bc944 | 2071 | |
e4fe371d | 2072 | also_record = Qnil; |
284f4730 | 2073 | |
71918b75 RS |
2074 | before_command_key_count = this_command_key_count; |
2075 | before_command_echo_length = echo_length (); | |
ef6661f7 | 2076 | c = Qnil; |
7ee32cda | 2077 | previous_echo_area_message = Qnil; |
71918b75 | 2078 | |
7ee32cda | 2079 | GCPRO2 (c, previous_echo_area_message); |
7c3bc944 | 2080 | |
7f07d5ca RS |
2081 | retry: |
2082 | ||
7d18f9ae RS |
2083 | reread = 0; |
2084 | if (CONSP (Vunread_post_input_method_events)) | |
284f4730 | 2085 | { |
7539e11f | 2086 | c = XCAR (Vunread_post_input_method_events); |
7d18f9ae | 2087 | Vunread_post_input_method_events |
7539e11f | 2088 | = XCDR (Vunread_post_input_method_events); |
284f4730 | 2089 | |
2479e91e RS |
2090 | /* Undo what read_char_x_menu_prompt did when it unread |
2091 | additional keys returned by Fx_popup_menu. */ | |
2092 | if (CONSP (c) | |
7539e11f KR |
2093 | && (SYMBOLP (XCAR (c)) || INTEGERP (XCAR (c))) |
2094 | && NILP (XCDR (c))) | |
2095 | c = XCAR (c); | |
2479e91e | 2096 | |
7d18f9ae RS |
2097 | reread = 1; |
2098 | goto reread_first; | |
284f4730 JB |
2099 | } |
2100 | ||
86e5706b RS |
2101 | if (unread_command_char != -1) |
2102 | { | |
18cd2eeb | 2103 | XSETINT (c, unread_command_char); |
86e5706b RS |
2104 | unread_command_char = -1; |
2105 | ||
7d18f9ae RS |
2106 | reread = 1; |
2107 | goto reread_first; | |
2108 | } | |
2109 | ||
2110 | if (CONSP (Vunread_command_events)) | |
2111 | { | |
7539e11f KR |
2112 | c = XCAR (Vunread_command_events); |
2113 | Vunread_command_events = XCDR (Vunread_command_events); | |
7d18f9ae RS |
2114 | |
2115 | /* Undo what read_char_x_menu_prompt did when it unread | |
2116 | additional keys returned by Fx_popup_menu. */ | |
2117 | if (CONSP (c) | |
7539e11f KR |
2118 | && (SYMBOLP (XCAR (c)) || INTEGERP (XCAR (c))) |
2119 | && NILP (XCDR (c))) | |
2120 | c = XCAR (c); | |
7d18f9ae RS |
2121 | |
2122 | reread = 1; | |
2123 | goto reread_for_input_method; | |
2124 | } | |
2125 | ||
2126 | if (CONSP (Vunread_input_method_events)) | |
2127 | { | |
7539e11f KR |
2128 | c = XCAR (Vunread_input_method_events); |
2129 | Vunread_input_method_events = XCDR (Vunread_input_method_events); | |
7d18f9ae RS |
2130 | |
2131 | /* Undo what read_char_x_menu_prompt did when it unread | |
2132 | additional keys returned by Fx_popup_menu. */ | |
2133 | if (CONSP (c) | |
7539e11f KR |
2134 | && (SYMBOLP (XCAR (c)) || INTEGERP (XCAR (c))) |
2135 | && NILP (XCDR (c))) | |
2136 | c = XCAR (c); | |
7d18f9ae RS |
2137 | reread = 1; |
2138 | goto reread_for_input_method; | |
86e5706b RS |
2139 | } |
2140 | ||
71918b75 RS |
2141 | /* If there is no function key translated before |
2142 | reset-this-command-lengths takes effect, forget about it. */ | |
2143 | before_command_restore_flag = 0; | |
2144 | ||
284f4730 JB |
2145 | if (!NILP (Vexecuting_macro)) |
2146 | { | |
fce33686 JB |
2147 | /* We set this to Qmacro; since that's not a frame, nobody will |
2148 | try to switch frames on us, and the selected window will | |
2149 | remain unchanged. | |
2150 | ||
2151 | Since this event came from a macro, it would be misleading to | |
eb8c3be9 | 2152 | leave internal_last_event_frame set to wherever the last |
3c370943 JB |
2153 | real event came from. Normally, a switch-frame event selects |
2154 | internal_last_event_frame after each command is read, but | |
2155 | events read from a macro should never cause a new frame to be | |
2156 | selected. */ | |
4c52b668 | 2157 | Vlast_event_frame = internal_last_event_frame = Qmacro; |
fce33686 | 2158 | |
663258f2 JB |
2159 | /* Exit the macro if we are at the end. |
2160 | Also, some things replace the macro with t | |
2161 | to force an early exit. */ | |
2162 | if (EQ (Vexecuting_macro, Qt) | |
2163 | || executing_macro_index >= XFASTINT (Flength (Vexecuting_macro))) | |
284f4730 | 2164 | { |
18cd2eeb | 2165 | XSETINT (c, -1); |
7c3bc944 | 2166 | RETURN_UNGCPRO (c); |
284f4730 | 2167 | } |
df0f2ba1 | 2168 | |
284f4730 | 2169 | c = Faref (Vexecuting_macro, make_number (executing_macro_index)); |
8c18cbfb | 2170 | if (STRINGP (Vexecuting_macro) |
86e5706b | 2171 | && (XINT (c) & 0x80)) |
bb9e9bed | 2172 | XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80)); |
86e5706b | 2173 | |
284f4730 JB |
2174 | executing_macro_index++; |
2175 | ||
2176 | goto from_macro; | |
2177 | } | |
2178 | ||
cd21b839 JB |
2179 | if (!NILP (unread_switch_frame)) |
2180 | { | |
2181 | c = unread_switch_frame; | |
2182 | unread_switch_frame = Qnil; | |
2183 | ||
2184 | /* This event should make it into this_command_keys, and get echoed | |
7d18f9ae | 2185 | again, so we do not set `reread'. */ |
f4255cd1 | 2186 | goto reread_first; |
cd21b839 JB |
2187 | } |
2188 | ||
adc1d5c8 | 2189 | /* if redisplay was requested */ |
6e4e64a8 RS |
2190 | if (commandflag >= 0) |
2191 | { | |
adc1d5c8 RS |
2192 | /* If there is pending input, process any events which are not |
2193 | user-visible, such as X selection_request events. */ | |
6e4e64a8 RS |
2194 | if (input_pending |
2195 | || detect_input_pending_run_timers (0)) | |
adc1d5c8 | 2196 | swallow_events (0); /* may clear input_pending */ |
6e4e64a8 | 2197 | |
adc1d5c8 RS |
2198 | /* Redisplay if no pending input. */ |
2199 | while (!input_pending) | |
2200 | { | |
5295a500 GM |
2201 | if (help_echo_showing_p && !EQ (selected_window, minibuf_window)) |
2202 | redisplay_preserve_echo_area (); | |
2203 | else | |
2204 | redisplay (); | |
adc1d5c8 RS |
2205 | |
2206 | if (!input_pending) | |
2207 | /* Normal case: no input arrived during redisplay. */ | |
2208 | break; | |
2209 | ||
2210 | /* Input arrived and pre-empted redisplay. | |
2211 | Process any events which are not user-visible. */ | |
2212 | swallow_events (0); | |
2213 | /* If that cleared input_pending, try again to redisplay. */ | |
2214 | } | |
6e4e64a8 | 2215 | } |
e9bf89a0 | 2216 | |
59a84f8e GM |
2217 | /* Message turns off echoing unless more keystrokes turn it on again. |
2218 | ||
2219 | The code in 20.x for the condition was | |
2220 | ||
2221 | 1. echo_area_glyphs && *echo_area_glyphs | |
2222 | 2. && echo_area_glyphs != current_kboard->echobuf | |
2223 | 3. && ok_to_echo_at_next_pause != echo_area_glyphs | |
2224 | ||
2225 | (1) means there's a current message displayed | |
2226 | ||
2227 | (2) means it's not the message from echoing from the current | |
2228 | kboard. | |
2229 | ||
2230 | (3) There's only one place in 20.x where ok_to_echo_at_next_pause | |
2231 | is set to a non-null value. This is done in read_char and it is | |
2232 | set to echo_area_glyphs after a call to echo_char. That means | |
2233 | ok_to_echo_at_next_pause is either null or | |
2234 | current_kboard->echobuf with the appropriate current_kboard at | |
2235 | that time. | |
2236 | ||
2237 | So, condition (3) means in clear text ok_to_echo_at_next_pause | |
2238 | must be either null, or the current message isn't from echoing at | |
2239 | all, or it's from echoing from a different kboard than the | |
2240 | current one. */ | |
2241 | ||
2242 | if (/* There currently something in the echo area */ | |
985f9f66 | 2243 | !NILP (echo_area_buffer[0]) |
59a84f8e GM |
2244 | && (/* And it's either not from echoing. */ |
2245 | !EQ (echo_area_buffer[0], echo_message_buffer) | |
2246 | /* Or it's an echo from a different kboard. */ | |
2247 | || echo_kboard != current_kboard | |
2248 | /* Or we explicitly allow overwriting whatever there is. */ | |
2249 | || ok_to_echo_at_next_pause == NULL)) | |
7ee32cda | 2250 | cancel_echoing (); |
410d4de9 | 2251 | else |
410d4de9 | 2252 | echo_dash (); |
59a84f8e | 2253 | |
410d4de9 RS |
2254 | /* Try reading a character via menu prompting in the minibuf. |
2255 | Try this before the sit-for, because the sit-for | |
2256 | would do the wrong thing if we are supposed to do | |
2257 | menu prompting. If EVENT_HAS_PARAMETERS then we are reading | |
2258 | after a mouse event so don't try a minibuf menu. */ | |
2259 | c = Qnil; | |
2260 | if (nmaps > 0 && INTERACTIVE | |
2261 | && !NILP (prev_event) && ! EVENT_HAS_PARAMETERS (prev_event) | |
2262 | /* Don't bring up a menu if we already have another event. */ | |
2263 | && NILP (Vunread_command_events) | |
2264 | && unread_command_char < 0 | |
4ec4ed6a | 2265 | && !detect_input_pending_run_timers (0)) |
410d4de9 RS |
2266 | { |
2267 | c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps); | |
2268 | if (! NILP (c)) | |
2269 | { | |
2270 | key_already_recorded = 1; | |
2271 | goto non_reread_1; | |
2272 | } | |
2273 | } | |
284f4730 | 2274 | |
410d4de9 RS |
2275 | /* Make a longjmp point for quits to use, but don't alter getcjmp just yet. |
2276 | We will do that below, temporarily for short sections of code, | |
2277 | when appropriate. local_getcjmp must be in effect | |
2278 | around any call to sit_for or kbd_buffer_get_event; | |
2279 | it *must not* be in effect when we call redisplay. */ | |
284f4730 | 2280 | |
410d4de9 | 2281 | if (_setjmp (local_getcjmp)) |
284f4730 | 2282 | { |
18cd2eeb | 2283 | XSETINT (c, quit_char); |
788f89eb | 2284 | internal_last_event_frame = selected_frame; |
4c52b668 | 2285 | Vlast_event_frame = internal_last_event_frame; |
04904c29 RS |
2286 | /* If we report the quit char as an event, |
2287 | don't do so more than once. */ | |
2288 | if (!NILP (Vinhibit_quit)) | |
2289 | Vquit_flag = Qnil; | |
284f4730 | 2290 | |
c5fdd383 | 2291 | #ifdef MULTI_KBOARD |
df0f2ba1 | 2292 | { |
788f89eb | 2293 | KBOARD *kb = FRAME_KBOARD (XFRAME (selected_frame)); |
c5fdd383 | 2294 | if (kb != current_kboard) |
df0f2ba1 | 2295 | { |
c5fdd383 | 2296 | Lisp_Object *tailp = &kb->kbd_queue; |
1e8bd3da RS |
2297 | /* We shouldn't get here if we were in single-kboard mode! */ |
2298 | if (single_kboard) | |
df0f2ba1 KH |
2299 | abort (); |
2300 | while (CONSP (*tailp)) | |
7539e11f | 2301 | tailp = &XCDR (*tailp); |
df0f2ba1 KH |
2302 | if (!NILP (*tailp)) |
2303 | abort (); | |
2304 | *tailp = Fcons (c, Qnil); | |
c5fdd383 KH |
2305 | kb->kbd_queue_has_data = 1; |
2306 | current_kboard = kb; | |
ef6661f7 RS |
2307 | /* This is going to exit from read_char |
2308 | so we had better get rid of this frame's stuff. */ | |
2309 | UNGCPRO; | |
c5fdd383 | 2310 | longjmp (wrong_kboard_jmpbuf, 1); |
df0f2ba1 KH |
2311 | } |
2312 | } | |
2313 | #endif | |
284f4730 JB |
2314 | goto non_reread; |
2315 | } | |
2316 | ||
d9d4c147 KH |
2317 | timer_start_idle (); |
2318 | ||
284f4730 JB |
2319 | /* If in middle of key sequence and minibuffer not active, |
2320 | start echoing if enough time elapses. */ | |
410d4de9 | 2321 | |
7ee32cda GM |
2322 | if (minibuf_level == 0 |
2323 | && !current_kboard->immediate_echo | |
6c6083a9 | 2324 | && this_command_key_count > 0 |
27203ead | 2325 | && ! noninteractive |
f2647d04 DL |
2326 | && (FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes)) |
2327 | && NILP (Fzerop (Vecho_keystrokes)) | |
985f9f66 GM |
2328 | && (/* No message. */ |
2329 | NILP (echo_area_buffer[0]) | |
2330 | /* Or empty message. */ | |
2331 | || (BUF_BEG (XBUFFER (echo_area_buffer[0])) | |
2332 | == BUF_Z (XBUFFER (echo_area_buffer[0]))) | |
2333 | /* Or already echoing from same kboard. */ | |
2334 | || (echo_kboard && ok_to_echo_at_next_pause == echo_kboard) | |
2335 | /* Or not echoing before and echoing allowed. */ | |
2336 | || (!echo_kboard && ok_to_echo_at_next_pause))) | |
284f4730 JB |
2337 | { |
2338 | Lisp_Object tem0; | |
985f9f66 | 2339 | |
7d6de002 RS |
2340 | /* After a mouse event, start echoing right away. |
2341 | This is because we are probably about to display a menu, | |
2342 | and we don't want to delay before doing so. */ | |
dbc4e1c1 | 2343 | if (EVENT_HAS_PARAMETERS (prev_event)) |
3dbd9ee4 | 2344 | echo_now (); |
7d6de002 RS |
2345 | else |
2346 | { | |
39aab679 DL |
2347 | int sec, usec; |
2348 | double duration = extract_float (Vecho_keystrokes); | |
2349 | sec = (int) duration; | |
15fa88ab | 2350 | usec = (duration - sec) * 1000000; |
410d4de9 RS |
2351 | save_getcjmp (save_jump); |
2352 | restore_getcjmp (local_getcjmp); | |
39aab679 | 2353 | tem0 = sit_for (sec, usec, 1, 1, 0); |
410d4de9 | 2354 | restore_getcjmp (save_jump); |
303b5b3f RS |
2355 | if (EQ (tem0, Qt) |
2356 | && ! CONSP (Vunread_command_events)) | |
3dbd9ee4 | 2357 | echo_now (); |
7d6de002 | 2358 | } |
284f4730 JB |
2359 | } |
2360 | ||
410d4de9 | 2361 | /* Maybe auto save due to number of keystrokes. */ |
284f4730 JB |
2362 | |
2363 | if (commandflag != 0 | |
2364 | && auto_save_interval > 0 | |
c43b1734 | 2365 | && num_nonmacro_input_events - last_auto_save > max (auto_save_interval, 20) |
4ec4ed6a | 2366 | && !detect_input_pending_run_timers (0)) |
284f4730 | 2367 | { |
284f4730 | 2368 | Fdo_auto_save (Qnil, Qnil); |
ef8fd672 RS |
2369 | /* Hooks can actually change some buffers in auto save. */ |
2370 | redisplay (); | |
284f4730 JB |
2371 | } |
2372 | ||
8150596a | 2373 | /* Try reading using an X menu. |
24597608 RS |
2374 | This is never confused with reading using the minibuf |
2375 | because the recursive call of read_char in read_char_minibuf_menu_prompt | |
2376 | does not pass on any keymaps. */ | |
410d4de9 | 2377 | |
24597608 | 2378 | if (nmaps > 0 && INTERACTIVE |
5a8d99e0 KH |
2379 | && !NILP (prev_event) |
2380 | && EVENT_HAS_PARAMETERS (prev_event) | |
7539e11f KR |
2381 | && !EQ (XCAR (prev_event), Qmenu_bar) |
2382 | && !EQ (XCAR (prev_event), Qtool_bar) | |
24597608 RS |
2383 | /* Don't bring up a menu if we already have another event. */ |
2384 | && NILP (Vunread_command_events) | |
b8556aee | 2385 | && unread_command_char < 0) |
8eb4d8ef RS |
2386 | { |
2387 | c = read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu); | |
2388 | ||
2389 | /* Now that we have read an event, Emacs is not idle. */ | |
2390 | timer_stop_idle (); | |
2391 | ||
7c3bc944 | 2392 | RETURN_UNGCPRO (c); |
8eb4d8ef | 2393 | } |
7d6de002 | 2394 | |
410d4de9 RS |
2395 | /* Maybe autosave and/or garbage collect due to idleness. */ |
2396 | ||
26c1639e | 2397 | if (INTERACTIVE && NILP (c)) |
7d6de002 RS |
2398 | { |
2399 | int delay_level, buffer_size; | |
2400 | ||
410d4de9 RS |
2401 | /* Slow down auto saves logarithmically in size of current buffer, |
2402 | and garbage collect while we're at it. */ | |
7d6de002 RS |
2403 | if (! MINI_WINDOW_P (XWINDOW (selected_window))) |
2404 | last_non_minibuf_size = Z - BEG; | |
2405 | buffer_size = (last_non_minibuf_size >> 8) + 1; | |
2406 | delay_level = 0; | |
2407 | while (buffer_size > 64) | |
2408 | delay_level++, buffer_size -= buffer_size >> 2; | |
2409 | if (delay_level < 4) delay_level = 4; | |
2410 | /* delay_level is 4 for files under around 50k, 7 at 100k, | |
2411 | 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */ | |
2412 | ||
2413 | /* Auto save if enough time goes by without input. */ | |
2414 | if (commandflag != 0 | |
c43b1734 | 2415 | && num_nonmacro_input_events > last_auto_save |
8c18cbfb | 2416 | && INTEGERP (Vauto_save_timeout) |
7d6de002 RS |
2417 | && XINT (Vauto_save_timeout) > 0) |
2418 | { | |
2419 | Lisp_Object tem0; | |
410d4de9 RS |
2420 | |
2421 | save_getcjmp (save_jump); | |
2422 | restore_getcjmp (local_getcjmp); | |
d9d4c147 | 2423 | tem0 = sit_for (delay_level * XFASTINT (Vauto_save_timeout) / 4, |
41365083 | 2424 | 0, 1, 1, 0); |
410d4de9 RS |
2425 | restore_getcjmp (save_jump); |
2426 | ||
303b5b3f RS |
2427 | if (EQ (tem0, Qt) |
2428 | && ! CONSP (Vunread_command_events)) | |
7d6de002 | 2429 | { |
7d6de002 | 2430 | Fdo_auto_save (Qnil, Qnil); |
7d6de002 RS |
2431 | |
2432 | /* If we have auto-saved and there is still no input | |
2433 | available, garbage collect if there has been enough | |
2434 | consing going on to make it worthwhile. */ | |
4ec4ed6a | 2435 | if (!detect_input_pending_run_timers (0) |
7d6de002 | 2436 | && consing_since_gc > gc_cons_threshold / 2) |
ef8fd672 | 2437 | Fgarbage_collect (); |
410d4de9 | 2438 | |
ef8fd672 | 2439 | redisplay (); |
7d6de002 RS |
2440 | } |
2441 | } | |
2442 | } | |
284f4730 | 2443 | |
303b5b3f RS |
2444 | /* If this has become non-nil here, it has been set by a timer |
2445 | or sentinel or filter. */ | |
2446 | if (CONSP (Vunread_command_events)) | |
2447 | { | |
7539e11f KR |
2448 | c = XCAR (Vunread_command_events); |
2449 | Vunread_command_events = XCDR (Vunread_command_events); | |
303b5b3f RS |
2450 | } |
2451 | ||
410d4de9 RS |
2452 | /* Read something from current KBOARD's side queue, if possible. */ |
2453 | ||
beecf6a1 | 2454 | if (NILP (c)) |
1e12dd87 | 2455 | { |
c5fdd383 | 2456 | if (current_kboard->kbd_queue_has_data) |
beecf6a1 | 2457 | { |
c5fdd383 | 2458 | if (!CONSP (current_kboard->kbd_queue)) |
4524b161 | 2459 | abort (); |
7539e11f | 2460 | c = XCAR (current_kboard->kbd_queue); |
c5fdd383 | 2461 | current_kboard->kbd_queue |
7539e11f | 2462 | = XCDR (current_kboard->kbd_queue); |
c5fdd383 KH |
2463 | if (NILP (current_kboard->kbd_queue)) |
2464 | current_kboard->kbd_queue_has_data = 0; | |
d9d4c147 | 2465 | input_pending = readable_events (0); |
4c52b668 KH |
2466 | if (EVENT_HAS_PARAMETERS (c) |
2467 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qswitch_frame)) | |
7539e11f | 2468 | internal_last_event_frame = XCAR (XCDR (c)); |
4c52b668 | 2469 | Vlast_event_frame = internal_last_event_frame; |
beecf6a1 | 2470 | } |
1e8bd3da RS |
2471 | } |
2472 | ||
c5fdd383 | 2473 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
2474 | /* If current_kboard's side queue is empty check the other kboards. |
2475 | If one of them has data that we have not yet seen here, | |
2476 | switch to it and process the data waiting for it. | |
2477 | ||
2478 | Note: if the events queued up for another kboard | |
2479 | have already been seen here, and therefore are not a complete command, | |
2480 | the kbd_queue_has_data field is 0, so we skip that kboard here. | |
2481 | That's to avoid an infinite loop switching between kboards here. */ | |
2482 | if (NILP (c) && !single_kboard) | |
2483 | { | |
2484 | KBOARD *kb; | |
2485 | for (kb = all_kboards; kb; kb = kb->next_kboard) | |
2486 | if (kb->kbd_queue_has_data) | |
2487 | { | |
2488 | current_kboard = kb; | |
ef6661f7 RS |
2489 | /* This is going to exit from read_char |
2490 | so we had better get rid of this frame's stuff. */ | |
2491 | UNGCPRO; | |
1e8bd3da RS |
2492 | longjmp (wrong_kboard_jmpbuf, 1); |
2493 | } | |
2494 | } | |
df0f2ba1 KH |
2495 | #endif |
2496 | ||
410d4de9 RS |
2497 | wrong_kboard: |
2498 | ||
2499 | stop_polling (); | |
2500 | ||
1e8bd3da RS |
2501 | /* Finally, we read from the main queue, |
2502 | and if that gives us something we can't use yet, we put it on the | |
2503 | appropriate side queue and try again. */ | |
410d4de9 | 2504 | |
1e8bd3da RS |
2505 | if (NILP (c)) |
2506 | { | |
2507 | KBOARD *kb; | |
2508 | ||
1e8bd3da | 2509 | /* Actually read a character, waiting if necessary. */ |
410d4de9 RS |
2510 | save_getcjmp (save_jump); |
2511 | restore_getcjmp (local_getcjmp); | |
5b7bc0da | 2512 | timer_start_idle (); |
83d68044 | 2513 | c = kbd_buffer_get_event (&kb, used_mouse_menu); |
410d4de9 RS |
2514 | restore_getcjmp (save_jump); |
2515 | ||
c5fdd383 | 2516 | #ifdef MULTI_KBOARD |
410d4de9 | 2517 | if (! NILP (c) && (kb != current_kboard)) |
1e8bd3da RS |
2518 | { |
2519 | Lisp_Object *tailp = &kb->kbd_queue; | |
2520 | while (CONSP (*tailp)) | |
7539e11f | 2521 | tailp = &XCDR (*tailp); |
1e8bd3da RS |
2522 | if (!NILP (*tailp)) |
2523 | abort (); | |
2524 | *tailp = Fcons (c, Qnil); | |
2525 | kb->kbd_queue_has_data = 1; | |
46b84797 | 2526 | c = Qnil; |
1e8bd3da RS |
2527 | if (single_kboard) |
2528 | goto wrong_kboard; | |
2529 | current_kboard = kb; | |
ef6661f7 RS |
2530 | /* This is going to exit from read_char |
2531 | so we had better get rid of this frame's stuff. */ | |
2532 | UNGCPRO; | |
1e8bd3da | 2533 | longjmp (wrong_kboard_jmpbuf, 1); |
df0f2ba1 | 2534 | } |
1e8bd3da | 2535 | #endif |
beecf6a1 | 2536 | } |
1e8bd3da | 2537 | |
284f4730 | 2538 | /* Terminate Emacs in batch mode if at eof. */ |
8c18cbfb | 2539 | if (noninteractive && INTEGERP (c) && XINT (c) < 0) |
284f4730 JB |
2540 | Fkill_emacs (make_number (1)); |
2541 | ||
8c18cbfb | 2542 | if (INTEGERP (c)) |
80645119 JB |
2543 | { |
2544 | /* Add in any extra modifiers, where appropriate. */ | |
2545 | if ((extra_keyboard_modifiers & CHAR_CTL) | |
2546 | || ((extra_keyboard_modifiers & 0177) < ' ' | |
2547 | && (extra_keyboard_modifiers & 0177) != 0)) | |
faf5e407 | 2548 | XSETINT (c, make_ctrl_char (XINT (c))); |
80645119 JB |
2549 | |
2550 | /* Transfer any other modifier bits directly from | |
2551 | extra_keyboard_modifiers to c. Ignore the actual character code | |
2552 | in the low 16 bits of extra_keyboard_modifiers. */ | |
b8d9050d | 2553 | XSETINT (c, XINT (c) | (extra_keyboard_modifiers & ~0xff7f & ~CHAR_CTL)); |
80645119 | 2554 | } |
9fa4395d | 2555 | |
284f4730 JB |
2556 | non_reread: |
2557 | ||
2fb9049e | 2558 | timer_stop_idle (); |
284f4730 JB |
2559 | start_polling (); |
2560 | ||
410d4de9 RS |
2561 | if (NILP (c)) |
2562 | { | |
2563 | if (commandflag >= 0 | |
4ec4ed6a | 2564 | && !input_pending && !detect_input_pending_run_timers (0)) |
410d4de9 RS |
2565 | redisplay (); |
2566 | ||
2567 | goto wrong_kboard; | |
2568 | } | |
2569 | ||
2570 | non_reread_1: | |
2571 | ||
dfd11da7 | 2572 | /* Buffer switch events are only for internal wakeups |
7c3bc944 RS |
2573 | so don't show them to the user. |
2574 | Also, don't record a key if we already did. */ | |
2575 | if (BUFFERP (c) || key_already_recorded) | |
2576 | RETURN_UNGCPRO (c); | |
a1341f75 | 2577 | |
7f07d5ca RS |
2578 | /* Process special events within read_char |
2579 | and loop around to read another event. */ | |
017c7cb6 RS |
2580 | save = Vquit_flag; |
2581 | Vquit_flag = Qnil; | |
02067692 | 2582 | tem = access_keymap (get_keymap (Vspecial_event_map, 0, 1), c, 0, 0, 1); |
017c7cb6 | 2583 | Vquit_flag = save; |
7f07d5ca RS |
2584 | |
2585 | if (!NILP (tem)) | |
2586 | { | |
ba8dfba8 RS |
2587 | int was_locked = single_kboard; |
2588 | ||
7f07d5ca | 2589 | last_input_char = c; |
158f7532 | 2590 | Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt); |
ba8dfba8 RS |
2591 | |
2592 | /* Resume allowing input from any kboard, if that was true before. */ | |
2593 | if (!was_locked) | |
2594 | any_kboard_state (); | |
2595 | ||
7f07d5ca RS |
2596 | goto retry; |
2597 | } | |
2598 | ||
284f4730 | 2599 | /* Handle things that only apply to characters. */ |
8c18cbfb | 2600 | if (INTEGERP (c)) |
284f4730 JB |
2601 | { |
2602 | /* If kbd_buffer_get_event gave us an EOF, return that. */ | |
86e5706b | 2603 | if (XINT (c) == -1) |
7c3bc944 | 2604 | RETURN_UNGCPRO (c); |
284f4730 | 2605 | |
301738ed RS |
2606 | if ((STRINGP (Vkeyboard_translate_table) |
2607 | && XSTRING (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) | |
2608 | || (VECTORP (Vkeyboard_translate_table) | |
2609 | && XVECTOR (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) | |
2610 | || (CHAR_TABLE_P (Vkeyboard_translate_table) | |
2611 | && CHAR_TABLE_ORDINARY_SLOTS > (unsigned) XFASTINT (c))) | |
f9414d62 RS |
2612 | { |
2613 | Lisp_Object d; | |
2614 | d = Faref (Vkeyboard_translate_table, c); | |
2615 | /* nil in keyboard-translate-table means no translation. */ | |
2616 | if (!NILP (d)) | |
2617 | c = d; | |
2618 | } | |
284f4730 JB |
2619 | } |
2620 | ||
e4fe371d RS |
2621 | /* If this event is a mouse click in the menu bar, |
2622 | return just menu-bar for now. Modify the mouse click event | |
2623 | so we won't do this twice, then queue it up. */ | |
2624 | if (EVENT_HAS_PARAMETERS (c) | |
7539e11f | 2625 | && CONSP (XCDR (c)) |
e4fe371d | 2626 | && CONSP (EVENT_START (c)) |
7539e11f | 2627 | && CONSP (XCDR (EVENT_START (c)))) |
284f4730 | 2628 | { |
e4fe371d | 2629 | Lisp_Object posn; |
284f4730 | 2630 | |
e4fe371d RS |
2631 | posn = POSN_BUFFER_POSN (EVENT_START (c)); |
2632 | /* Handle menu-bar events: | |
2633 | insert the dummy prefix event `menu-bar'. */ | |
9ea173e8 | 2634 | if (EQ (posn, Qmenu_bar) || EQ (posn, Qtool_bar)) |
e4fe371d RS |
2635 | { |
2636 | /* Change menu-bar to (menu-bar) as the event "position". */ | |
2637 | POSN_BUFFER_POSN (EVENT_START (c)) = Fcons (posn, Qnil); | |
284f4730 | 2638 | |
e4fe371d RS |
2639 | also_record = c; |
2640 | Vunread_command_events = Fcons (c, Vunread_command_events); | |
2641 | c = posn; | |
284f4730 | 2642 | } |
284f4730 JB |
2643 | } |
2644 | ||
7d18f9ae RS |
2645 | /* Store these characters into recent_keys, the dribble file if any, |
2646 | and the keyboard macro being defined, if any. */ | |
e4fe371d RS |
2647 | record_char (c); |
2648 | if (! NILP (also_record)) | |
2649 | record_char (also_record); | |
51172b6d | 2650 | |
d5eecefb RS |
2651 | /* Wipe the echo area. |
2652 | But first, if we are about to use an input method, | |
2653 | save the echo area contents for it to refer to. */ | |
2654 | if (INTEGERP (c) | |
2655 | && ! NILP (Vinput_method_function) | |
2656 | && (unsigned) XINT (c) >= ' ' | |
8d769115 KH |
2657 | && (unsigned) XINT (c) != 127 |
2658 | && (unsigned) XINT (c) < 256) | |
7ee32cda GM |
2659 | { |
2660 | previous_echo_area_message = Fcurrent_message (); | |
2661 | Vinput_method_previous_message = previous_echo_area_message; | |
2662 | } | |
d5eecefb | 2663 | |
1172eb8d GM |
2664 | /* Now wipe the echo area, except for help events which do their |
2665 | own stuff with the echo area. */ | |
2666 | if (!CONSP (c) || !(EQ (Qhelp_echo, XCAR (c)))) | |
2667 | { | |
2668 | if (!NILP (echo_area_buffer[0])) | |
2669 | safe_run_hooks (Qecho_area_clear_hook); | |
2670 | clear_message (1, 0); | |
2671 | } | |
d5eecefb | 2672 | |
7d18f9ae | 2673 | reread_for_input_method: |
284f4730 | 2674 | from_macro: |
7d18f9ae | 2675 | /* Pass this to the input method, if appropriate. */ |
d5eecefb RS |
2676 | if (INTEGERP (c) |
2677 | && ! NILP (Vinput_method_function) | |
b638f328 RS |
2678 | /* Don't run the input method within a key sequence, |
2679 | after the first event of the key sequence. */ | |
2680 | && NILP (prev_event) | |
d5eecefb | 2681 | && (unsigned) XINT (c) >= ' ' |
8d769115 KH |
2682 | && (unsigned) XINT (c) != 127 |
2683 | && (unsigned) XINT (c) < 256) | |
d5eecefb RS |
2684 | { |
2685 | Lisp_Object keys; | |
6e5742a0 | 2686 | int key_count; |
d5eecefb | 2687 | struct gcpro gcpro1; |
b638f328 | 2688 | int count = specpdl_ptr - specpdl; |
d5eecefb | 2689 | |
6e5742a0 RS |
2690 | /* Save the echo status. */ |
2691 | int saved_immediate_echo = current_kboard->immediate_echo; | |
985f9f66 | 2692 | struct kboard *saved_ok_to_echo = ok_to_echo_at_next_pause; |
6e5742a0 RS |
2693 | int saved_echo_after_prompt = current_kboard->echo_after_prompt; |
2694 | ||
2695 | if (before_command_restore_flag) | |
2696 | { | |
2697 | this_command_key_count = before_command_key_count_1; | |
2698 | if (this_command_key_count < this_single_command_key_start) | |
2699 | this_single_command_key_start = this_command_key_count; | |
2700 | echo_truncate (before_command_echo_length_1); | |
2701 | before_command_restore_flag = 0; | |
2702 | } | |
2703 | ||
2704 | /* Save the this_command_keys status. */ | |
2705 | key_count = this_command_key_count; | |
2706 | ||
2707 | if (key_count > 0) | |
2708 | keys = Fcopy_sequence (this_command_keys); | |
2709 | else | |
2710 | keys = Qnil; | |
d5eecefb | 2711 | GCPRO1 (keys); |
6e5742a0 RS |
2712 | |
2713 | /* Clear out this_command_keys. */ | |
2714 | this_command_key_count = 0; | |
2715 | ||
2716 | /* Now wipe the echo area. */ | |
985f9f66 | 2717 | if (!NILP (echo_area_buffer[0])) |
6e5742a0 | 2718 | safe_run_hooks (Qecho_area_clear_hook); |
985f9f66 | 2719 | clear_message (1, 0); |
6e5742a0 RS |
2720 | echo_truncate (0); |
2721 | ||
b638f328 RS |
2722 | /* If we are not reading a key sequence, |
2723 | never use the echo area. */ | |
2724 | if (maps == 0) | |
2725 | { | |
b638f328 RS |
2726 | specbind (Qinput_method_use_echo_area, Qt); |
2727 | } | |
2728 | ||
6e5742a0 | 2729 | /* Call the input method. */ |
d5eecefb | 2730 | tem = call1 (Vinput_method_function, c); |
b638f328 RS |
2731 | |
2732 | tem = unbind_to (count, tem); | |
2733 | ||
6e5742a0 RS |
2734 | /* Restore the saved echoing state |
2735 | and this_command_keys state. */ | |
2736 | this_command_key_count = key_count; | |
2737 | if (key_count > 0) | |
2738 | this_command_keys = keys; | |
2739 | ||
2740 | cancel_echoing (); | |
2741 | ok_to_echo_at_next_pause = saved_ok_to_echo; | |
2742 | current_kboard->echo_after_prompt = saved_echo_after_prompt; | |
2743 | if (saved_immediate_echo) | |
2744 | echo_now (); | |
2745 | ||
d5eecefb | 2746 | UNGCPRO; |
6e5742a0 | 2747 | |
d5eecefb RS |
2748 | /* The input method can return no events. */ |
2749 | if (! CONSP (tem)) | |
7d18f9ae | 2750 | { |
d5eecefb | 2751 | /* Bring back the previous message, if any. */ |
7ee32cda GM |
2752 | if (! NILP (previous_echo_area_message)) |
2753 | message_with_string ("%s", previous_echo_area_message, 0); | |
d5eecefb | 2754 | goto retry; |
7d18f9ae | 2755 | } |
d5eecefb | 2756 | /* It returned one event or more. */ |
7539e11f | 2757 | c = XCAR (tem); |
d5eecefb | 2758 | Vunread_post_input_method_events |
7539e11f | 2759 | = nconc2 (XCDR (tem), Vunread_post_input_method_events); |
7d18f9ae | 2760 | } |
7c3bc944 | 2761 | |
7d18f9ae | 2762 | reread_first: |
284f4730 | 2763 | |
7ee32cda | 2764 | /* Display help if not echoing. */ |
1172eb8d | 2765 | if (CONSP (c) && EQ (XCAR (c), Qhelp_echo)) |
7ee32cda | 2766 | { |
2190735a GM |
2767 | /* (help-echo FRAME HELP WINDOW OBJECT POS). */ |
2768 | Lisp_Object help, object, position, window; | |
8dfd92c9 | 2769 | help = Fnth (make_number (2), c); |
2190735a GM |
2770 | window = Fnth (make_number (3), c); |
2771 | object = Fnth (make_number (4), c); | |
2772 | position = Fnth (make_number (5), c); | |
2773 | show_help_echo (help, window, object, position, 0); | |
7ee32cda GM |
2774 | goto retry; |
2775 | } | |
2776 | ||
7d18f9ae | 2777 | if (this_command_key_count == 0 || ! reread) |
e4fe371d | 2778 | { |
7d18f9ae RS |
2779 | before_command_key_count = this_command_key_count; |
2780 | before_command_echo_length = echo_length (); | |
2781 | ||
2782 | /* Don't echo mouse motion events. */ | |
f2647d04 DL |
2783 | if ((FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes)) |
2784 | && NILP (Fzerop (Vecho_keystrokes)) | |
7d18f9ae RS |
2785 | && ! (EVENT_HAS_PARAMETERS (c) |
2786 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_movement))) | |
2787 | { | |
2788 | echo_char (c); | |
2789 | if (! NILP (also_record)) | |
2790 | echo_char (also_record); | |
2791 | /* Once we reread a character, echoing can happen | |
2792 | the next time we pause to read a new one. */ | |
985f9f66 | 2793 | ok_to_echo_at_next_pause = current_kboard; |
7d18f9ae RS |
2794 | } |
2795 | ||
2796 | /* Record this character as part of the current key. */ | |
2797 | add_command_key (c); | |
e4fe371d | 2798 | if (! NILP (also_record)) |
7d18f9ae | 2799 | add_command_key (also_record); |
e4fe371d | 2800 | } |
b8556aee | 2801 | |
284f4730 | 2802 | last_input_char = c; |
c43b1734 | 2803 | num_input_events++; |
284f4730 JB |
2804 | |
2805 | /* Process the help character specially if enabled */ | |
ecb7cb34 | 2806 | if (!NILP (Vhelp_form) && help_char_p (c)) |
284f4730 JB |
2807 | { |
2808 | Lisp_Object tem0; | |
2809 | count = specpdl_ptr - specpdl; | |
2810 | ||
2811 | record_unwind_protect (Fset_window_configuration, | |
2812 | Fcurrent_window_configuration (Qnil)); | |
2813 | ||
2814 | tem0 = Feval (Vhelp_form); | |
8c18cbfb | 2815 | if (STRINGP (tem0)) |
284f4730 JB |
2816 | internal_with_output_to_temp_buffer ("*Help*", print_help, tem0); |
2817 | ||
2818 | cancel_echoing (); | |
3cb81011 KH |
2819 | do |
2820 | c = read_char (0, 0, 0, Qnil, 0); | |
8c18cbfb | 2821 | while (BUFFERP (c)); |
ff11dfa1 | 2822 | /* Remove the help from the frame */ |
284f4730 | 2823 | unbind_to (count, Qnil); |
410d4de9 | 2824 | |
284f4730 JB |
2825 | redisplay (); |
2826 | if (EQ (c, make_number (040))) | |
2827 | { | |
2828 | cancel_echoing (); | |
3cb81011 KH |
2829 | do |
2830 | c = read_char (0, 0, 0, Qnil, 0); | |
8c18cbfb | 2831 | while (BUFFERP (c)); |
284f4730 JB |
2832 | } |
2833 | } | |
2834 | ||
7c3bc944 | 2835 | RETURN_UNGCPRO (c); |
284f4730 JB |
2836 | } |
2837 | ||
8eb4d8ef RS |
2838 | /* Record a key that came from a mouse menu. |
2839 | Record it for echoing, for this-command-keys, and so on. */ | |
2840 | ||
2841 | static void | |
2842 | record_menu_key (c) | |
2843 | Lisp_Object c; | |
2844 | { | |
2845 | /* Wipe the echo area. */ | |
985f9f66 | 2846 | clear_message (1, 0); |
8eb4d8ef RS |
2847 | |
2848 | record_char (c); | |
2849 | ||
2850 | before_command_key_count = this_command_key_count; | |
2851 | before_command_echo_length = echo_length (); | |
2852 | ||
2853 | /* Don't echo mouse motion events. */ | |
f2647d04 DL |
2854 | if ((FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes)) |
2855 | && NILP (Fzerop (Vecho_keystrokes))) | |
8eb4d8ef RS |
2856 | { |
2857 | echo_char (c); | |
2858 | ||
2859 | /* Once we reread a character, echoing can happen | |
2860 | the next time we pause to read a new one. */ | |
2861 | ok_to_echo_at_next_pause = 0; | |
2862 | } | |
2863 | ||
2864 | /* Record this character as part of the current key. */ | |
2865 | add_command_key (c); | |
2866 | ||
2867 | /* Re-reading in the middle of a command */ | |
2868 | last_input_char = c; | |
c43b1734 | 2869 | num_input_events++; |
8eb4d8ef RS |
2870 | } |
2871 | ||
ecb7cb34 KH |
2872 | /* Return 1 if should recognize C as "the help character". */ |
2873 | ||
2874 | int | |
2875 | help_char_p (c) | |
2876 | Lisp_Object c; | |
2877 | { | |
2878 | Lisp_Object tail; | |
2879 | ||
2880 | if (EQ (c, Vhelp_char)) | |
2881 | return 1; | |
7539e11f KR |
2882 | for (tail = Vhelp_event_list; CONSP (tail); tail = XCDR (tail)) |
2883 | if (EQ (c, XCAR (tail))) | |
ecb7cb34 KH |
2884 | return 1; |
2885 | return 0; | |
2886 | } | |
2887 | ||
e4fe371d RS |
2888 | /* Record the input event C in various ways. */ |
2889 | ||
2890 | static void | |
2891 | record_char (c) | |
2892 | Lisp_Object c; | |
2893 | { | |
2894 | total_keys++; | |
2895 | XVECTOR (recent_keys)->contents[recent_keys_index] = c; | |
2896 | if (++recent_keys_index >= NUM_RECENT_KEYS) | |
2897 | recent_keys_index = 0; | |
2898 | ||
2899 | /* Write c to the dribble file. If c is a lispy event, write | |
2900 | the event's symbol to the dribble file, in <brackets>. Bleaugh. | |
2901 | If you, dear reader, have a better idea, you've got the source. :-) */ | |
2902 | if (dribble) | |
2903 | { | |
2904 | if (INTEGERP (c)) | |
2905 | { | |
2906 | if (XUINT (c) < 0x100) | |
2907 | putc (XINT (c), dribble); | |
2908 | else | |
6de34814 | 2909 | fprintf (dribble, " 0x%x", (int) XUINT (c)); |
e4fe371d RS |
2910 | } |
2911 | else | |
2912 | { | |
2913 | Lisp_Object dribblee; | |
2914 | ||
2915 | /* If it's a structured event, take the event header. */ | |
2916 | dribblee = EVENT_HEAD (c); | |
2917 | ||
2918 | if (SYMBOLP (dribblee)) | |
2919 | { | |
2920 | putc ('<', dribble); | |
2921 | fwrite (XSYMBOL (dribblee)->name->data, sizeof (char), | |
fc932ac6 | 2922 | STRING_BYTES (XSYMBOL (dribblee)->name), |
e4fe371d RS |
2923 | dribble); |
2924 | putc ('>', dribble); | |
2925 | } | |
2926 | } | |
2927 | ||
2928 | fflush (dribble); | |
2929 | } | |
2930 | ||
2931 | store_kbd_macro_char (c); | |
2932 | ||
c43b1734 | 2933 | num_nonmacro_input_events++; |
e4fe371d RS |
2934 | } |
2935 | ||
284f4730 JB |
2936 | Lisp_Object |
2937 | print_help (object) | |
2938 | Lisp_Object object; | |
2939 | { | |
622de3e9 | 2940 | struct buffer *old = current_buffer; |
284f4730 | 2941 | Fprinc (object, Qnil); |
622de3e9 KH |
2942 | set_buffer_internal (XBUFFER (Vstandard_output)); |
2943 | call0 (intern ("help-mode")); | |
2944 | set_buffer_internal (old); | |
284f4730 JB |
2945 | return Qnil; |
2946 | } | |
2947 | ||
2948 | /* Copy out or in the info on where C-g should throw to. | |
2949 | This is used when running Lisp code from within get_char, | |
2950 | in case get_char is called recursively. | |
2951 | See read_process_output. */ | |
2952 | ||
dfcf069d | 2953 | static void |
284f4730 JB |
2954 | save_getcjmp (temp) |
2955 | jmp_buf temp; | |
2956 | { | |
2957 | bcopy (getcjmp, temp, sizeof getcjmp); | |
2958 | } | |
2959 | ||
dfcf069d | 2960 | static void |
284f4730 JB |
2961 | restore_getcjmp (temp) |
2962 | jmp_buf temp; | |
2963 | { | |
2964 | bcopy (temp, getcjmp, sizeof getcjmp); | |
2965 | } | |
284f4730 | 2966 | \f |
2eb6bfbe RM |
2967 | #ifdef HAVE_MOUSE |
2968 | ||
284f4730 JB |
2969 | /* Restore mouse tracking enablement. See Ftrack_mouse for the only use |
2970 | of this function. */ | |
a9d77f1f | 2971 | |
284f4730 JB |
2972 | static Lisp_Object |
2973 | tracking_off (old_value) | |
2974 | Lisp_Object old_value; | |
2975 | { | |
71edead1 RS |
2976 | do_mouse_tracking = old_value; |
2977 | if (NILP (old_value)) | |
284f4730 | 2978 | { |
284f4730 JB |
2979 | /* Redisplay may have been preempted because there was input |
2980 | available, and it assumes it will be called again after the | |
2981 | input has been processed. If the only input available was | |
2982 | the sort that we have just disabled, then we need to call | |
2983 | redisplay. */ | |
d9d4c147 | 2984 | if (!readable_events (1)) |
284f4730 JB |
2985 | { |
2986 | redisplay_preserve_echo_area (); | |
d9d4c147 | 2987 | get_input_pending (&input_pending, 1); |
284f4730 JB |
2988 | } |
2989 | } | |
30690496 | 2990 | return Qnil; |
284f4730 JB |
2991 | } |
2992 | ||
2993 | DEFUN ("track-mouse", Ftrack_mouse, Strack_mouse, 0, UNEVALLED, 0, | |
4bb994d1 JB |
2994 | "Evaluate BODY with mouse movement events enabled.\n\ |
2995 | Within a `track-mouse' form, mouse motion generates input events that\n\ | |
2996 | you can read with `read-event'.\n\ | |
2997 | Normally, mouse motion is ignored.") | |
284f4730 JB |
2998 | (args) |
2999 | Lisp_Object args; | |
3000 | { | |
3001 | int count = specpdl_ptr - specpdl; | |
3002 | Lisp_Object val; | |
3003 | ||
a9d77f1f | 3004 | record_unwind_protect (tracking_off, do_mouse_tracking); |
284f4730 | 3005 | |
f3253854 | 3006 | do_mouse_tracking = Qt; |
df0f2ba1 | 3007 | |
284f4730 JB |
3008 | val = Fprogn (args); |
3009 | return unbind_to (count, val); | |
3010 | } | |
2eb6bfbe | 3011 | |
f3253854 KH |
3012 | /* If mouse has moved on some frame, return one of those frames. |
3013 | Return 0 otherwise. */ | |
3014 | ||
3015 | static FRAME_PTR | |
3016 | some_mouse_moved () | |
3017 | { | |
3018 | Lisp_Object tail, frame; | |
3019 | ||
3020 | FOR_EACH_FRAME (tail, frame) | |
3021 | { | |
3022 | if (XFRAME (frame)->mouse_moved) | |
3023 | return XFRAME (frame); | |
3024 | } | |
3025 | ||
3026 | return 0; | |
3027 | } | |
3028 | ||
2eb6bfbe | 3029 | #endif /* HAVE_MOUSE */ |
a612e298 RS |
3030 | \f |
3031 | /* Low level keyboard/mouse input. | |
3032 | kbd_buffer_store_event places events in kbd_buffer, and | |
0646c0dd | 3033 | kbd_buffer_get_event retrieves them. */ |
a612e298 RS |
3034 | |
3035 | /* Return true iff there are any events in the queue that read-char | |
3036 | would return. If this returns false, a read-char would block. */ | |
3037 | static int | |
d9d4c147 KH |
3038 | readable_events (do_timers_now) |
3039 | int do_timers_now; | |
a612e298 | 3040 | { |
4ec4ed6a RS |
3041 | if (do_timers_now) |
3042 | timer_check (do_timers_now); | |
3043 | ||
beecf6a1 KH |
3044 | if (kbd_fetch_ptr != kbd_store_ptr) |
3045 | return 1; | |
3046 | #ifdef HAVE_MOUSE | |
f3253854 | 3047 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
beecf6a1 KH |
3048 | return 1; |
3049 | #endif | |
1e8bd3da | 3050 | if (single_kboard) |
4c52b668 | 3051 | { |
c5fdd383 | 3052 | if (current_kboard->kbd_queue_has_data) |
4c52b668 KH |
3053 | return 1; |
3054 | } | |
3055 | else | |
3056 | { | |
c5fdd383 KH |
3057 | KBOARD *kb; |
3058 | for (kb = all_kboards; kb; kb = kb->next_kboard) | |
3059 | if (kb->kbd_queue_has_data) | |
4c52b668 KH |
3060 | return 1; |
3061 | } | |
beecf6a1 | 3062 | return 0; |
a612e298 RS |
3063 | } |
3064 | ||
3065 | /* Set this for debugging, to have a way to get out */ | |
3066 | int stop_character; | |
284f4730 | 3067 | |
c5fdd383 KH |
3068 | #ifdef MULTI_KBOARD |
3069 | static KBOARD * | |
3070 | event_to_kboard (event) | |
5798cf15 KH |
3071 | struct input_event *event; |
3072 | { | |
3073 | Lisp_Object frame; | |
3074 | frame = event->frame_or_window; | |
3075 | if (CONSP (frame)) | |
7539e11f | 3076 | frame = XCAR (frame); |
5798cf15 KH |
3077 | else if (WINDOWP (frame)) |
3078 | frame = WINDOW_FRAME (XWINDOW (frame)); | |
3079 | ||
3080 | /* There are still some events that don't set this field. | |
f5b56972 KH |
3081 | For now, just ignore the problem. |
3082 | Also ignore dead frames here. */ | |
3083 | if (!FRAMEP (frame) || !FRAME_LIVE_P (XFRAME (frame))) | |
5798cf15 KH |
3084 | return 0; |
3085 | else | |
c5fdd383 | 3086 | return FRAME_KBOARD (XFRAME (frame)); |
5798cf15 KH |
3087 | } |
3088 | #endif | |
3089 | ||
284f4730 JB |
3090 | /* Store an event obtained at interrupt level into kbd_buffer, fifo */ |
3091 | ||
3092 | void | |
3093 | kbd_buffer_store_event (event) | |
3094 | register struct input_event *event; | |
3095 | { | |
3096 | if (event->kind == no_event) | |
3097 | abort (); | |
3098 | ||
3099 | if (event->kind == ascii_keystroke) | |
3100 | { | |
e9bf89a0 | 3101 | register int c = event->code & 0377; |
284f4730 | 3102 | |
faf5e407 JB |
3103 | if (event->modifiers & ctrl_modifier) |
3104 | c = make_ctrl_char (c); | |
3105 | ||
9fd7d808 RS |
3106 | c |= (event->modifiers |
3107 | & (meta_modifier | alt_modifier | |
3108 | | hyper_modifier | super_modifier)); | |
3109 | ||
86e5706b | 3110 | if (c == quit_char) |
284f4730 | 3111 | { |
3e51c7b7 | 3112 | extern SIGTYPE interrupt_signal (); |
c5fdd383 KH |
3113 | #ifdef MULTI_KBOARD |
3114 | KBOARD *kb; | |
5798cf15 KH |
3115 | struct input_event *sp; |
3116 | ||
1e8bd3da | 3117 | if (single_kboard |
c5fdd383 KH |
3118 | && (kb = FRAME_KBOARD (XFRAME (event->frame_or_window)), |
3119 | kb != current_kboard)) | |
5798cf15 | 3120 | { |
c5fdd383 | 3121 | kb->kbd_queue |
5798cf15 KH |
3122 | = Fcons (make_lispy_switch_frame (event->frame_or_window), |
3123 | Fcons (make_number (c), Qnil)); | |
c5fdd383 | 3124 | kb->kbd_queue_has_data = 1; |
5798cf15 KH |
3125 | for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++) |
3126 | { | |
3127 | if (sp == kbd_buffer + KBD_BUFFER_SIZE) | |
3128 | sp = kbd_buffer; | |
3129 | ||
c5fdd383 | 3130 | if (event_to_kboard (sp) == kb) |
5798cf15 KH |
3131 | { |
3132 | sp->kind = no_event; | |
3133 | sp->frame_or_window = Qnil; | |
da8f7368 | 3134 | sp->arg = Qnil; |
5798cf15 KH |
3135 | } |
3136 | } | |
3137 | return; | |
3138 | } | |
3139 | #endif | |
3e51c7b7 | 3140 | |
284f4730 | 3141 | /* If this results in a quit_char being returned to Emacs as |
3c370943 | 3142 | input, set Vlast_event_frame properly. If this doesn't |
284f4730 | 3143 | get returned to Emacs as an event, the next event read |
ff11dfa1 | 3144 | will set Vlast_event_frame again, so this is safe to do. */ |
4bb994d1 | 3145 | { |
9b8eb840 | 3146 | Lisp_Object focus; |
4bb994d1 | 3147 | |
9b8eb840 | 3148 | focus = FRAME_FOCUS_FRAME (XFRAME (event->frame_or_window)); |
4bb994d1 | 3149 | if (NILP (focus)) |
beecf6a1 | 3150 | focus = event->frame_or_window; |
4c52b668 KH |
3151 | internal_last_event_frame = focus; |
3152 | Vlast_event_frame = focus; | |
4bb994d1 | 3153 | } |
3e51c7b7 | 3154 | |
ffd56f97 | 3155 | last_event_timestamp = event->timestamp; |
284f4730 JB |
3156 | interrupt_signal (); |
3157 | return; | |
3158 | } | |
3159 | ||
3160 | if (c && c == stop_character) | |
3161 | { | |
3162 | sys_suspend (); | |
3163 | return; | |
3164 | } | |
284f4730 | 3165 | } |
3fe8e9a2 RS |
3166 | /* Don't insert two buffer_switch_event's in a row. |
3167 | Just ignore the second one. */ | |
3168 | else if (event->kind == buffer_switch_event | |
3169 | && kbd_fetch_ptr != kbd_store_ptr | |
3170 | && kbd_store_ptr->kind == buffer_switch_event) | |
3171 | return; | |
284f4730 | 3172 | |
beecf6a1 KH |
3173 | if (kbd_store_ptr - kbd_buffer == KBD_BUFFER_SIZE) |
3174 | kbd_store_ptr = kbd_buffer; | |
284f4730 JB |
3175 | |
3176 | /* Don't let the very last slot in the buffer become full, | |
3177 | since that would make the two pointers equal, | |
3178 | and that is indistinguishable from an empty buffer. | |
3179 | Discard the event if it would fill the last slot. */ | |
beecf6a1 | 3180 | if (kbd_fetch_ptr - 1 != kbd_store_ptr) |
284f4730 | 3181 | { |
da8f7368 GM |
3182 | int idx; |
3183 | ||
3184 | #if 0 /* The selection_request_event case looks bogus, and it's error | |
3185 | prone to assign individual members for other events, in case | |
3186 | the input_event structure is changed. --2000-07-13, gerd. */ | |
7ee32cda | 3187 | struct input_event *sp = kbd_store_ptr; |
612b78ef | 3188 | sp->kind = event->kind; |
27203ead RS |
3189 | if (event->kind == selection_request_event) |
3190 | { | |
3191 | /* We must not use the ordinary copying code for this case, | |
3192 | since `part' is an enum and copying it might not copy enough | |
3193 | in this case. */ | |
612b78ef | 3194 | bcopy (event, (char *) sp, sizeof (*event)); |
27203ead RS |
3195 | } |
3196 | else | |
da8f7368 | 3197 | |
27203ead | 3198 | { |
612b78ef KH |
3199 | sp->code = event->code; |
3200 | sp->part = event->part; | |
3201 | sp->frame_or_window = event->frame_or_window; | |
da8f7368 | 3202 | sp->arg = event->arg; |
612b78ef KH |
3203 | sp->modifiers = event->modifiers; |
3204 | sp->x = event->x; | |
3205 | sp->y = event->y; | |
3206 | sp->timestamp = event->timestamp; | |
27203ead | 3207 | } |
da8f7368 GM |
3208 | #else |
3209 | *kbd_store_ptr = *event; | |
3210 | #endif | |
284f4730 | 3211 | |
da8f7368 GM |
3212 | idx = 2 * (kbd_store_ptr - kbd_buffer); |
3213 | ASET (kbd_buffer_gcpro, idx, event->frame_or_window); | |
3214 | ASET (kbd_buffer_gcpro, idx + 1, event->arg); | |
3215 | ++kbd_store_ptr; | |
284f4730 JB |
3216 | } |
3217 | } | |
8dfd92c9 GM |
3218 | |
3219 | ||
f139e559 | 3220 | /* Generate HELP_EVENT input_events in BUFP which has room for |
0bbfdc25 GM |
3221 | SIZE events. If there's not enough room in BUFP, ignore this |
3222 | event. | |
8dfd92c9 GM |
3223 | |
3224 | HELP is the help form. | |
3225 | ||
3226 | FRAME is the frame on which the help is generated. OBJECT is the | |
5b2ec2d0 GM |
3227 | Lisp object where the help was found (a buffer, a string, an |
3228 | overlay, or nil if neither from a string nor from a buffer. POS is | |
3229 | the position within OBJECT where the help was found. | |
8dfd92c9 GM |
3230 | |
3231 | Value is the number of input_events generated. */ | |
3232 | ||
3233 | int | |
0bbfdc25 | 3234 | gen_help_event (bufp, size, help, frame, window, object, pos) |
8dfd92c9 | 3235 | struct input_event *bufp; |
0bbfdc25 | 3236 | int size; |
2190735a | 3237 | Lisp_Object help, frame, object, window; |
8dfd92c9 GM |
3238 | int pos; |
3239 | { | |
0bbfdc25 GM |
3240 | int nevents_stored = 0; |
3241 | ||
3242 | if (size >= 2) | |
3243 | { | |
3244 | bufp->kind = HELP_EVENT; | |
3245 | bufp->frame_or_window = frame; | |
3246 | bufp->arg = object; | |
3247 | bufp->x = make_number (pos); | |
3248 | bufp->code = 0; | |
8dfd92c9 | 3249 | |
0bbfdc25 GM |
3250 | ++bufp; |
3251 | bufp->kind = HELP_EVENT; | |
3252 | bufp->frame_or_window = WINDOWP (window) ? window : frame; | |
3253 | bufp->arg = help; | |
3254 | bufp->code = 1; | |
3255 | nevents_stored = 2; | |
3256 | } | |
2190735a | 3257 | |
0bbfdc25 | 3258 | return nevents_stored; |
8dfd92c9 GM |
3259 | } |
3260 | ||
3261 | ||
3262 | /* Store HELP_EVENTs for HELP on FRAME in the input queue. */ | |
3263 | ||
3264 | void | |
3265 | kbd_buffer_store_help_event (frame, help) | |
3266 | Lisp_Object frame, help; | |
3267 | { | |
3268 | struct input_event event; | |
3269 | ||
3270 | event.kind = HELP_EVENT; | |
3271 | event.frame_or_window = frame; | |
3272 | event.arg = Qnil; | |
3273 | event.x = make_number (0); | |
3274 | event.code = 0; | |
3275 | kbd_buffer_store_event (&event); | |
3276 | ||
3277 | event.kind = HELP_EVENT; | |
3278 | event.frame_or_window = frame; | |
3279 | event.arg = help; | |
3280 | event.x = make_number (0); | |
3281 | event.code = 1; | |
3282 | kbd_buffer_store_event (&event); | |
3283 | } | |
3284 | ||
a612e298 | 3285 | \f |
07de30b9 GV |
3286 | /* Discard any mouse events in the event buffer by setting them to |
3287 | no_event. */ | |
3288 | void | |
3289 | discard_mouse_events () | |
3290 | { | |
3291 | struct input_event *sp; | |
3292 | for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++) | |
3293 | { | |
3294 | if (sp == kbd_buffer + KBD_BUFFER_SIZE) | |
3295 | sp = kbd_buffer; | |
3296 | ||
3297 | if (sp->kind == mouse_click | |
3298 | #ifdef WINDOWSNT | |
3299 | || sp->kind == w32_scroll_bar_click | |
3300 | #endif | |
3301 | || sp->kind == scroll_bar_click) | |
3302 | { | |
3303 | sp->kind = no_event; | |
3304 | } | |
3305 | } | |
3306 | } | |
eeabfe76 | 3307 | |
0bbfdc25 GM |
3308 | |
3309 | /* Return non-zero if there are any real events waiting in the event | |
3310 | buffer, not counting `no_event's. | |
3311 | ||
3312 | If DISCARD is non-zero, discard no_event events at the front of | |
3313 | the input queue, possibly leaving the input queue empty if there | |
3314 | are no real input events. */ | |
3315 | ||
eeabfe76 EZ |
3316 | int |
3317 | kbd_buffer_events_waiting (discard) | |
3318 | int discard; | |
3319 | { | |
3320 | struct input_event *sp; | |
0bbfdc25 GM |
3321 | |
3322 | for (sp = kbd_fetch_ptr; | |
3323 | sp != kbd_store_ptr && sp->kind == no_event; | |
3324 | ++sp) | |
eeabfe76 EZ |
3325 | { |
3326 | if (sp == kbd_buffer + KBD_BUFFER_SIZE) | |
3327 | sp = kbd_buffer; | |
eeabfe76 | 3328 | } |
0bbfdc25 | 3329 | |
eeabfe76 EZ |
3330 | if (discard) |
3331 | kbd_fetch_ptr = sp; | |
0bbfdc25 GM |
3332 | |
3333 | return sp != kbd_store_ptr && sp->kind != no_event; | |
eeabfe76 | 3334 | } |
0bbfdc25 | 3335 | |
07de30b9 | 3336 | \f |
0bbfdc25 GM |
3337 | /* Clear input event EVENT. */ |
3338 | ||
3339 | static INLINE void | |
3340 | clear_event (event) | |
3341 | struct input_event *event; | |
3342 | { | |
3343 | int idx = 2 * (event - kbd_buffer); | |
3344 | ASET (kbd_buffer_gcpro, idx, Qnil); | |
3345 | ASET (kbd_buffer_gcpro, idx + 1, Qnil); | |
3346 | event->kind = no_event; | |
3347 | } | |
3348 | ||
3349 | ||
a612e298 RS |
3350 | /* Read one event from the event buffer, waiting if necessary. |
3351 | The value is a Lisp object representing the event. | |
3352 | The value is nil for an event that should be ignored, | |
3353 | or that was handled here. | |
3354 | We always read and discard one event. */ | |
284f4730 JB |
3355 | |
3356 | static Lisp_Object | |
83d68044 | 3357 | kbd_buffer_get_event (kbp, used_mouse_menu) |
410d4de9 | 3358 | KBOARD **kbp; |
83d68044 | 3359 | int *used_mouse_menu; |
284f4730 JB |
3360 | { |
3361 | register int c; | |
3362 | Lisp_Object obj; | |
3363 | ||
3364 | if (noninteractive) | |
3365 | { | |
3366 | c = getchar (); | |
18cd2eeb | 3367 | XSETINT (obj, c); |
f5b56972 | 3368 | *kbp = current_kboard; |
284f4730 JB |
3369 | return obj; |
3370 | } | |
3371 | ||
3372 | /* Wait until there is input available. */ | |
3373 | for (;;) | |
3374 | { | |
beecf6a1 KH |
3375 | if (kbd_fetch_ptr != kbd_store_ptr) |
3376 | break; | |
3377 | #ifdef HAVE_MOUSE | |
f3253854 | 3378 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
284f4730 | 3379 | break; |
beecf6a1 | 3380 | #endif |
284f4730 JB |
3381 | |
3382 | /* If the quit flag is set, then read_char will return | |
3383 | quit_char, so that counts as "available input." */ | |
3384 | if (!NILP (Vquit_flag)) | |
3385 | quit_throw_to_read_char (); | |
3386 | ||
3387 | /* One way or another, wait until input is available; then, if | |
3388 | interrupt handlers have not read it, read it now. */ | |
3389 | ||
3390 | #ifdef OLDVMS | |
3391 | wait_for_kbd_input (); | |
3392 | #else | |
3393 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
3394 | #ifdef SIGIO | |
3395 | gobble_input (0); | |
3396 | #endif /* SIGIO */ | |
beecf6a1 KH |
3397 | if (kbd_fetch_ptr != kbd_store_ptr) |
3398 | break; | |
3399 | #ifdef HAVE_MOUSE | |
f3253854 | 3400 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
beecf6a1 KH |
3401 | break; |
3402 | #endif | |
3403 | { | |
3404 | Lisp_Object minus_one; | |
f76475ad | 3405 | |
beecf6a1 | 3406 | XSETINT (minus_one, -1); |
d9d4c147 | 3407 | wait_reading_process_input (0, 0, minus_one, 1); |
284f4730 | 3408 | |
beecf6a1 KH |
3409 | if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr) |
3410 | /* Pass 1 for EXPECT since we just waited to have input. */ | |
3411 | read_avail_input (1); | |
3412 | } | |
284f4730 JB |
3413 | #endif /* not VMS */ |
3414 | } | |
3415 | ||
303b5b3f RS |
3416 | if (CONSP (Vunread_command_events)) |
3417 | { | |
3418 | Lisp_Object first; | |
7539e11f KR |
3419 | first = XCAR (Vunread_command_events); |
3420 | Vunread_command_events = XCDR (Vunread_command_events); | |
303b5b3f RS |
3421 | *kbp = current_kboard; |
3422 | return first; | |
3423 | } | |
3424 | ||
284f4730 JB |
3425 | /* At this point, we know that there is a readable event available |
3426 | somewhere. If the event queue is empty, then there must be a | |
3427 | mouse movement enabled and available. */ | |
beecf6a1 | 3428 | if (kbd_fetch_ptr != kbd_store_ptr) |
284f4730 | 3429 | { |
cd21b839 | 3430 | struct input_event *event; |
3e51c7b7 | 3431 | |
beecf6a1 KH |
3432 | event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE) |
3433 | ? kbd_fetch_ptr | |
3434 | : kbd_buffer); | |
3e51c7b7 | 3435 | |
cd21b839 | 3436 | last_event_timestamp = event->timestamp; |
cd21b839 | 3437 | |
c5fdd383 KH |
3438 | #ifdef MULTI_KBOARD |
3439 | *kbp = event_to_kboard (event); | |
3440 | if (*kbp == 0) | |
3441 | *kbp = current_kboard; /* Better than returning null ptr? */ | |
5798cf15 | 3442 | #else |
c5fdd383 | 3443 | *kbp = &the_only_kboard; |
5798cf15 | 3444 | #endif |
beecf6a1 | 3445 | |
4bb994d1 JB |
3446 | obj = Qnil; |
3447 | ||
48e416d4 | 3448 | /* These two kinds of events get special handling |
a612e298 RS |
3449 | and don't actually appear to the command loop. |
3450 | We return nil for them. */ | |
48e416d4 RS |
3451 | if (event->kind == selection_request_event) |
3452 | { | |
598a9fa7 | 3453 | #ifdef HAVE_X11 |
1e8bd3da RS |
3454 | struct input_event copy; |
3455 | ||
4581e928 RS |
3456 | /* Remove it from the buffer before processing it, |
3457 | since otherwise swallow_events will see it | |
3458 | and process it again. */ | |
1e8bd3da | 3459 | copy = *event; |
beecf6a1 | 3460 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3461 | input_pending = readable_events (0); |
4581e928 | 3462 | x_handle_selection_request (©); |
598a9fa7 JB |
3463 | #else |
3464 | /* We're getting selection request events, but we don't have | |
3465 | a window system. */ | |
3466 | abort (); | |
3467 | #endif | |
48e416d4 RS |
3468 | } |
3469 | ||
1e12dd87 | 3470 | else if (event->kind == selection_clear_event) |
48e416d4 | 3471 | { |
598a9fa7 | 3472 | #ifdef HAVE_X11 |
e0301c07 RS |
3473 | struct input_event copy; |
3474 | ||
3475 | /* Remove it from the buffer before processing it. */ | |
3476 | copy = *event; | |
beecf6a1 | 3477 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3478 | input_pending = readable_events (0); |
90c2bb0c | 3479 | x_handle_selection_clear (©); |
598a9fa7 JB |
3480 | #else |
3481 | /* We're getting selection request events, but we don't have | |
3482 | a window system. */ | |
3483 | abort (); | |
3484 | #endif | |
48e416d4 | 3485 | } |
1a578e9b | 3486 | #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (macintosh) |
990acea3 RS |
3487 | else if (event->kind == delete_window_event) |
3488 | { | |
bbdc2092 RS |
3489 | /* Make an event (delete-frame (FRAME)). */ |
3490 | obj = Fcons (event->frame_or_window, Qnil); | |
af17bd2b | 3491 | obj = Fcons (Qdelete_frame, Fcons (obj, Qnil)); |
beecf6a1 | 3492 | kbd_fetch_ptr = event + 1; |
af17bd2b | 3493 | } |
1a578e9b AC |
3494 | #endif |
3495 | #if defined (HAVE_X11) || defined (HAVE_NTGUI) | |
af17bd2b KH |
3496 | else if (event->kind == iconify_event) |
3497 | { | |
3498 | /* Make an event (iconify-frame (FRAME)). */ | |
3499 | obj = Fcons (event->frame_or_window, Qnil); | |
3500 | obj = Fcons (Qiconify_frame, Fcons (obj, Qnil)); | |
beecf6a1 | 3501 | kbd_fetch_ptr = event + 1; |
af17bd2b KH |
3502 | } |
3503 | else if (event->kind == deiconify_event) | |
3504 | { | |
3505 | /* Make an event (make-frame-visible (FRAME)). */ | |
3506 | obj = Fcons (event->frame_or_window, Qnil); | |
3507 | obj = Fcons (Qmake_frame_visible, Fcons (obj, Qnil)); | |
beecf6a1 | 3508 | kbd_fetch_ptr = event + 1; |
990acea3 RS |
3509 | } |
3510 | #endif | |
a8015ab5 KH |
3511 | else if (event->kind == buffer_switch_event) |
3512 | { | |
3513 | /* The value doesn't matter here; only the type is tested. */ | |
18cd2eeb | 3514 | XSETBUFFER (obj, current_buffer); |
beecf6a1 | 3515 | kbd_fetch_ptr = event + 1; |
a8015ab5 | 3516 | } |
1a578e9b | 3517 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh) |
099787c1 RS |
3518 | else if (event->kind == menu_bar_activate_event) |
3519 | { | |
3520 | kbd_fetch_ptr = event + 1; | |
d9d4c147 | 3521 | input_pending = readable_events (0); |
e649d076 RS |
3522 | if (FRAME_LIVE_P (XFRAME (event->frame_or_window))) |
3523 | x_activate_menubar (XFRAME (event->frame_or_window)); | |
099787c1 | 3524 | } |
1161d367 GV |
3525 | #endif |
3526 | #ifdef WINDOWSNT | |
3527 | else if (event->kind == language_change_event) | |
3528 | { | |
3529 | /* Make an event (language-change (FRAME CHARSET LCID)). */ | |
3530 | obj = Fcons (event->modifiers, Qnil); | |
3531 | obj = Fcons (event->code, Qnil); | |
3532 | obj = Fcons (event->frame_or_window, obj); | |
3533 | obj = Fcons (Qlanguage_change, Fcons (obj, Qnil)); | |
3534 | kbd_fetch_ptr = event + 1; | |
3535 | } | |
099787c1 | 3536 | #endif |
a612e298 | 3537 | /* Just discard these, by returning nil. |
c5fdd383 | 3538 | With MULTI_KBOARD, these events are used as placeholders |
5798cf15 KH |
3539 | when we need to randomly delete events from the queue. |
3540 | (They shouldn't otherwise be found in the buffer, | |
3541 | but on some machines it appears they do show up | |
c5fdd383 | 3542 | even without MULTI_KBOARD.) */ |
07de30b9 GV |
3543 | /* On Windows NT/9X, no_event is used to delete extraneous |
3544 | mouse events during a popup-menu call. */ | |
a612e298 | 3545 | else if (event->kind == no_event) |
beecf6a1 | 3546 | kbd_fetch_ptr = event + 1; |
7ee32cda GM |
3547 | else if (event->kind == HELP_EVENT) |
3548 | { | |
e4457b09 | 3549 | /* There are always two HELP_EVENTs in the input queue. */ |
2190735a | 3550 | Lisp_Object object, position, help, frame, window; |
e4457b09 | 3551 | |
8dfd92c9 GM |
3552 | xassert (event->code == 0); |
3553 | frame = event->frame_or_window; | |
3554 | object = event->arg; | |
3555 | position = event->x; | |
0bbfdc25 | 3556 | clear_event (event); |
e4457b09 GM |
3557 | |
3558 | kbd_fetch_ptr = event + 1; | |
3559 | event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE) | |
3560 | ? kbd_fetch_ptr | |
3561 | : kbd_buffer); | |
3562 | xassert (event->code == 1); | |
3563 | help = event->arg; | |
3564 | window = event->frame_or_window; | |
2190735a GM |
3565 | if (!WINDOWP (window)) |
3566 | window = Qnil; | |
3567 | obj = Fcons (Qhelp_echo, | |
3568 | list5 (frame, help, window, object, position)); | |
0bbfdc25 | 3569 | clear_event (event); |
e4457b09 | 3570 | kbd_fetch_ptr = event + 1; |
7ee32cda | 3571 | } |
c51c7093 GM |
3572 | else if (event->kind == FOCUS_IN_EVENT) |
3573 | { | |
3574 | /* Notification of a FocusIn event. The frame receiving the | |
3575 | focus is in event->frame_or_window. Generate a | |
3576 | switch-frame event if necessary. */ | |
3577 | Lisp_Object frame, focus; | |
3578 | ||
3579 | frame = event->frame_or_window; | |
3580 | focus = FRAME_FOCUS_FRAME (XFRAME (frame)); | |
3581 | if (FRAMEP (focus)) | |
3582 | frame = focus; | |
3583 | ||
3584 | if (!EQ (frame, internal_last_event_frame) | |
3585 | && !EQ (frame, selected_frame)) | |
3586 | obj = make_lispy_switch_frame (frame); | |
3587 | internal_last_event_frame = frame; | |
3588 | kbd_fetch_ptr = event + 1; | |
3589 | } | |
1e12dd87 RS |
3590 | else |
3591 | { | |
c51c7093 GM |
3592 | /* If this event is on a different frame, return a switch-frame this |
3593 | time, and leave the event in the queue for next time. */ | |
9b8eb840 | 3594 | Lisp_Object frame; |
1e12dd87 | 3595 | Lisp_Object focus; |
7b4aedb9 | 3596 | |
9b8eb840 | 3597 | frame = event->frame_or_window; |
2470a66f | 3598 | if (CONSP (frame)) |
7539e11f | 3599 | frame = XCAR (frame); |
2470a66f | 3600 | else if (WINDOWP (frame)) |
1e12dd87 | 3601 | frame = WINDOW_FRAME (XWINDOW (frame)); |
4bb994d1 | 3602 | |
1e12dd87 RS |
3603 | focus = FRAME_FOCUS_FRAME (XFRAME (frame)); |
3604 | if (! NILP (focus)) | |
3605 | frame = focus; | |
07d2b8de | 3606 | |
4c52b668 | 3607 | if (! EQ (frame, internal_last_event_frame) |
788f89eb | 3608 | && !EQ (frame, selected_frame)) |
1e12dd87 | 3609 | obj = make_lispy_switch_frame (frame); |
4c52b668 | 3610 | internal_last_event_frame = frame; |
4bb994d1 | 3611 | |
1e12dd87 RS |
3612 | /* If we didn't decide to make a switch-frame event, go ahead |
3613 | and build a real event from the queue entry. */ | |
cd21b839 | 3614 | |
1e12dd87 RS |
3615 | if (NILP (obj)) |
3616 | { | |
da8f7368 GM |
3617 | int idx; |
3618 | ||
1e12dd87 | 3619 | obj = make_lispy_event (event); |
da8f7368 | 3620 | |
e98a93eb | 3621 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
83d68044 KH |
3622 | /* If this was a menu selection, then set the flag to inhibit |
3623 | writing to last_nonmenu_event. Don't do this if the event | |
3624 | we're returning is (menu-bar), though; that indicates the | |
3625 | beginning of the menu sequence, and we might as well leave | |
3626 | that as the `event with parameters' for this selection. */ | |
da8f7368 GM |
3627 | if (used_mouse_menu |
3628 | && !EQ (event->frame_or_window, event->arg) | |
3629 | && (event->kind == MENU_BAR_EVENT | |
3630 | || event->kind == TOOL_BAR_EVENT)) | |
83d68044 KH |
3631 | *used_mouse_menu = 1; |
3632 | #endif | |
1e12dd87 RS |
3633 | |
3634 | /* Wipe out this event, to catch bugs. */ | |
0bbfdc25 | 3635 | clear_event (event); |
beecf6a1 | 3636 | kbd_fetch_ptr = event + 1; |
1e12dd87 | 3637 | } |
4bb994d1 | 3638 | } |
284f4730 | 3639 | } |
2eb6bfbe | 3640 | #ifdef HAVE_MOUSE |
a612e298 | 3641 | /* Try generating a mouse motion event. */ |
f3253854 | 3642 | else if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
284f4730 | 3643 | { |
f3253854 | 3644 | FRAME_PTR f = some_mouse_moved (); |
7b4aedb9 | 3645 | Lisp_Object bar_window; |
3c370943 | 3646 | enum scroll_bar_part part; |
e5d77022 JB |
3647 | Lisp_Object x, y; |
3648 | unsigned long time; | |
284f4730 | 3649 | |
c5fdd383 | 3650 | *kbp = current_kboard; |
e177ac3a RS |
3651 | /* Note that this uses F to determine which display to look at. |
3652 | If there is no valid info, it does not store anything | |
3653 | so x remains nil. */ | |
3654 | x = Qnil; | |
dd26ab75 | 3655 | (*mouse_position_hook) (&f, 0, &bar_window, &part, &x, &y, &time); |
4bb994d1 JB |
3656 | |
3657 | obj = Qnil; | |
284f4730 | 3658 | |
4bb994d1 JB |
3659 | /* Decide if we should generate a switch-frame event. Don't |
3660 | generate switch-frame events for motion outside of all Emacs | |
3661 | frames. */ | |
e177ac3a | 3662 | if (!NILP (x) && f) |
cd21b839 | 3663 | { |
9b8eb840 | 3664 | Lisp_Object frame; |
4bb994d1 | 3665 | |
9b8eb840 | 3666 | frame = FRAME_FOCUS_FRAME (f); |
4bb994d1 | 3667 | if (NILP (frame)) |
18cd2eeb | 3668 | XSETFRAME (frame, f); |
4bb994d1 | 3669 | |
4c52b668 | 3670 | if (! EQ (frame, internal_last_event_frame) |
788f89eb | 3671 | && !EQ (frame, selected_frame)) |
764cb3f9 | 3672 | obj = make_lispy_switch_frame (frame); |
4c52b668 | 3673 | internal_last_event_frame = frame; |
cd21b839 | 3674 | } |
4bb994d1 | 3675 | |
df0f2ba1 | 3676 | /* If we didn't decide to make a switch-frame event, go ahead and |
4bb994d1 | 3677 | return a mouse-motion event. */ |
e177ac3a | 3678 | if (!NILP (x) && NILP (obj)) |
7b4aedb9 | 3679 | obj = make_lispy_movement (f, bar_window, part, x, y, time); |
6cbff1cb | 3680 | } |
2eb6bfbe | 3681 | #endif /* HAVE_MOUSE */ |
284f4730 JB |
3682 | else |
3683 | /* We were promised by the above while loop that there was | |
3684 | something for us to read! */ | |
3685 | abort (); | |
3686 | ||
d9d4c147 | 3687 | input_pending = readable_events (0); |
284f4730 | 3688 | |
4c52b668 | 3689 | Vlast_event_frame = internal_last_event_frame; |
3c370943 | 3690 | |
284f4730 JB |
3691 | return (obj); |
3692 | } | |
a612e298 RS |
3693 | \f |
3694 | /* Process any events that are not user-visible, | |
3695 | then return, without reading any user-visible events. */ | |
3a3b9632 RS |
3696 | |
3697 | void | |
d9d4c147 KH |
3698 | swallow_events (do_display) |
3699 | int do_display; | |
3a3b9632 | 3700 | { |
87dd9b9b RS |
3701 | int old_timers_run; |
3702 | ||
beecf6a1 | 3703 | while (kbd_fetch_ptr != kbd_store_ptr) |
3a3b9632 RS |
3704 | { |
3705 | struct input_event *event; | |
3706 | ||
beecf6a1 KH |
3707 | event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE) |
3708 | ? kbd_fetch_ptr | |
3709 | : kbd_buffer); | |
3a3b9632 RS |
3710 | |
3711 | last_event_timestamp = event->timestamp; | |
3712 | ||
3713 | /* These two kinds of events get special handling | |
3714 | and don't actually appear to the command loop. */ | |
3715 | if (event->kind == selection_request_event) | |
3716 | { | |
3717 | #ifdef HAVE_X11 | |
4581e928 | 3718 | struct input_event copy; |
e0301c07 RS |
3719 | |
3720 | /* Remove it from the buffer before processing it, | |
3721 | since otherwise swallow_events called recursively could see it | |
3722 | and process it again. */ | |
4581e928 | 3723 | copy = *event; |
beecf6a1 | 3724 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3725 | input_pending = readable_events (0); |
4581e928 | 3726 | x_handle_selection_request (©); |
3a3b9632 RS |
3727 | #else |
3728 | /* We're getting selection request events, but we don't have | |
3729 | a window system. */ | |
3730 | abort (); | |
3731 | #endif | |
3732 | } | |
3733 | ||
3734 | else if (event->kind == selection_clear_event) | |
3735 | { | |
3736 | #ifdef HAVE_X11 | |
e0301c07 RS |
3737 | struct input_event copy; |
3738 | ||
3739 | /* Remove it from the buffer before processing it, */ | |
3740 | copy = *event; | |
3741 | ||
beecf6a1 | 3742 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3743 | input_pending = readable_events (0); |
90c2bb0c | 3744 | x_handle_selection_clear (©); |
3a3b9632 RS |
3745 | #else |
3746 | /* We're getting selection request events, but we don't have | |
3747 | a window system. */ | |
3748 | abort (); | |
3749 | #endif | |
3750 | } | |
3751 | else | |
3752 | break; | |
3753 | } | |
3754 | ||
87dd9b9b | 3755 | old_timers_run = timers_run; |
d9d4c147 | 3756 | get_input_pending (&input_pending, 1); |
87dd9b9b RS |
3757 | |
3758 | if (timers_run != old_timers_run && do_display) | |
3759 | redisplay_preserve_echo_area (); | |
3a3b9632 | 3760 | } |
a612e298 | 3761 | \f |
d9d4c147 KH |
3762 | static EMACS_TIME timer_idleness_start_time; |
3763 | ||
3764 | /* Record the start of when Emacs is idle, | |
3765 | for the sake of running idle-time timers. */ | |
3766 | ||
07a59269 | 3767 | void |
d9d4c147 KH |
3768 | timer_start_idle () |
3769 | { | |
3770 | Lisp_Object timers; | |
3771 | ||
3772 | /* If we are already in the idle state, do nothing. */ | |
3773 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3774 | return; | |
3775 | ||
3776 | EMACS_GET_TIME (timer_idleness_start_time); | |
3777 | ||
3778 | /* Mark all idle-time timers as once again candidates for running. */ | |
7539e11f | 3779 | for (timers = Vtimer_idle_list; CONSP (timers); timers = XCDR (timers)) |
d9d4c147 KH |
3780 | { |
3781 | Lisp_Object timer; | |
3782 | ||
7539e11f | 3783 | timer = XCAR (timers); |
d9d4c147 KH |
3784 | |
3785 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) | |
3786 | continue; | |
3787 | XVECTOR (timer)->contents[0] = Qnil; | |
3788 | } | |
3789 | } | |
3790 | ||
3791 | /* Record that Emacs is no longer idle, so stop running idle-time timers. */ | |
3792 | ||
07a59269 | 3793 | void |
d9d4c147 KH |
3794 | timer_stop_idle () |
3795 | { | |
3796 | EMACS_SET_SECS_USECS (timer_idleness_start_time, -1, -1); | |
3797 | } | |
3798 | ||
e044e87c RS |
3799 | /* This is only for debugging. */ |
3800 | struct input_event last_timer_event; | |
3801 | ||
c04cbc3b RS |
3802 | /* Check whether a timer has fired. To prevent larger problems we simply |
3803 | disregard elements that are not proper timers. Do not make a circular | |
3804 | timer list for the time being. | |
3805 | ||
3806 | Returns the number of seconds to wait until the next timer fires. If a | |
3807 | timer is triggering now, return zero seconds. | |
3808 | If no timer is active, return -1 seconds. | |
3809 | ||
4ec4ed6a RS |
3810 | If a timer is ripe, we run it, with quitting turned off. |
3811 | ||
3812 | DO_IT_NOW is now ignored. It used to mean that we should | |
3813 | run the timer directly instead of queueing a timer-event. | |
3814 | Now we always run timers directly. */ | |
c04cbc3b RS |
3815 | |
3816 | EMACS_TIME | |
3817 | timer_check (do_it_now) | |
3818 | int do_it_now; | |
3819 | { | |
3820 | EMACS_TIME nexttime; | |
9291c072 RS |
3821 | EMACS_TIME now, idleness_now; |
3822 | Lisp_Object timers, idle_timers, chosen_timer; | |
9291c072 | 3823 | struct gcpro gcpro1, gcpro2, gcpro3; |
c04cbc3b | 3824 | |
c04cbc3b RS |
3825 | EMACS_SET_SECS (nexttime, -1); |
3826 | EMACS_SET_USECS (nexttime, -1); | |
3827 | ||
9291c072 | 3828 | /* Always consider the ordinary timers. */ |
7ea13e12 | 3829 | timers = Vtimer_list; |
9291c072 RS |
3830 | /* Consider the idle timers only if Emacs is idle. */ |
3831 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3832 | idle_timers = Vtimer_idle_list; | |
3833 | else | |
3834 | idle_timers = Qnil; | |
3835 | chosen_timer = Qnil; | |
3836 | GCPRO3 (timers, idle_timers, chosen_timer); | |
7ea13e12 | 3837 | |
9291c072 | 3838 | if (CONSP (timers) || CONSP (idle_timers)) |
c04cbc3b | 3839 | { |
9291c072 RS |
3840 | EMACS_GET_TIME (now); |
3841 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3842 | EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time); | |
3843 | } | |
c04cbc3b | 3844 | |
9291c072 RS |
3845 | while (CONSP (timers) || CONSP (idle_timers)) |
3846 | { | |
9291c072 | 3847 | Lisp_Object *vector; |
8c907a56 | 3848 | Lisp_Object timer = Qnil, idle_timer = Qnil; |
9291c072 RS |
3849 | EMACS_TIME timer_time, idle_timer_time; |
3850 | EMACS_TIME difference, timer_difference, idle_timer_difference; | |
3851 | ||
3852 | /* Skip past invalid timers and timers already handled. */ | |
3853 | if (!NILP (timers)) | |
c04cbc3b | 3854 | { |
7539e11f | 3855 | timer = XCAR (timers); |
9291c072 RS |
3856 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) |
3857 | { | |
7539e11f | 3858 | timers = XCDR (timers); |
9291c072 RS |
3859 | continue; |
3860 | } | |
3861 | vector = XVECTOR (timer)->contents; | |
d9d4c147 | 3862 | |
9291c072 RS |
3863 | if (!INTEGERP (vector[1]) || !INTEGERP (vector[2]) |
3864 | || !INTEGERP (vector[3]) | |
3865 | || ! NILP (vector[0])) | |
3866 | { | |
7539e11f | 3867 | timers = XCDR (timers); |
9291c072 RS |
3868 | continue; |
3869 | } | |
3870 | } | |
3871 | if (!NILP (idle_timers)) | |
3872 | { | |
7539e11f | 3873 | timer = XCAR (idle_timers); |
d9d4c147 | 3874 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) |
9291c072 | 3875 | { |
7539e11f | 3876 | idle_timers = XCDR (idle_timers); |
9291c072 RS |
3877 | continue; |
3878 | } | |
d9d4c147 KH |
3879 | vector = XVECTOR (timer)->contents; |
3880 | ||
3881 | if (!INTEGERP (vector[1]) || !INTEGERP (vector[2]) | |
9291c072 RS |
3882 | || !INTEGERP (vector[3]) |
3883 | || ! NILP (vector[0])) | |
3884 | { | |
7539e11f | 3885 | idle_timers = XCDR (idle_timers); |
9291c072 RS |
3886 | continue; |
3887 | } | |
3888 | } | |
d9d4c147 | 3889 | |
9291c072 RS |
3890 | /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE |
3891 | based on the next ordinary timer. | |
3892 | TIMER_DIFFERENCE is the distance in time from NOW to when | |
3893 | this timer becomes ripe (negative if it's already ripe). */ | |
3894 | if (!NILP (timers)) | |
3895 | { | |
7539e11f | 3896 | timer = XCAR (timers); |
9291c072 | 3897 | vector = XVECTOR (timer)->contents; |
d9d4c147 KH |
3898 | EMACS_SET_SECS (timer_time, |
3899 | (XINT (vector[1]) << 16) | (XINT (vector[2]))); | |
3900 | EMACS_SET_USECS (timer_time, XINT (vector[3])); | |
9291c072 RS |
3901 | EMACS_SUB_TIME (timer_difference, timer_time, now); |
3902 | } | |
ba8dfba8 | 3903 | |
9291c072 RS |
3904 | /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE |
3905 | based on the next idle timer. */ | |
3906 | if (!NILP (idle_timers)) | |
3907 | { | |
7539e11f | 3908 | idle_timer = XCAR (idle_timers); |
9291c072 RS |
3909 | vector = XVECTOR (idle_timer)->contents; |
3910 | EMACS_SET_SECS (idle_timer_time, | |
3911 | (XINT (vector[1]) << 16) | (XINT (vector[2]))); | |
3912 | EMACS_SET_USECS (idle_timer_time, XINT (vector[3])); | |
3913 | EMACS_SUB_TIME (idle_timer_difference, idle_timer_time, idleness_now); | |
3914 | } | |
ba8dfba8 | 3915 | |
9291c072 RS |
3916 | /* Decide which timer is the next timer, |
3917 | and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly. | |
3918 | Also step down the list where we found that timer. */ | |
d9d4c147 | 3919 | |
9291c072 RS |
3920 | if (! NILP (timers) && ! NILP (idle_timers)) |
3921 | { | |
3922 | EMACS_TIME temp; | |
3923 | EMACS_SUB_TIME (temp, timer_difference, idle_timer_difference); | |
3924 | if (EMACS_TIME_NEG_P (temp)) | |
3925 | { | |
3926 | chosen_timer = timer; | |
7539e11f | 3927 | timers = XCDR (timers); |
9291c072 | 3928 | difference = timer_difference; |
c04cbc3b | 3929 | } |
d9d4c147 | 3930 | else |
d9d4c147 | 3931 | { |
9291c072 | 3932 | chosen_timer = idle_timer; |
7539e11f | 3933 | idle_timers = XCDR (idle_timers); |
9291c072 | 3934 | difference = idle_timer_difference; |
d9d4c147 | 3935 | } |
7ea13e12 | 3936 | } |
9291c072 RS |
3937 | else if (! NILP (timers)) |
3938 | { | |
3939 | chosen_timer = timer; | |
7539e11f | 3940 | timers = XCDR (timers); |
9291c072 RS |
3941 | difference = timer_difference; |
3942 | } | |
3943 | else | |
3944 | { | |
3945 | chosen_timer = idle_timer; | |
7539e11f | 3946 | idle_timers = XCDR (idle_timers); |
9291c072 RS |
3947 | difference = idle_timer_difference; |
3948 | } | |
3949 | vector = XVECTOR (chosen_timer)->contents; | |
3950 | ||
bd55b860 | 3951 | /* If timer is ripe, run it if it hasn't been run. */ |
9291c072 RS |
3952 | if (EMACS_TIME_NEG_P (difference) |
3953 | || (EMACS_SECS (difference) == 0 | |
3954 | && EMACS_USECS (difference) == 0)) | |
3955 | { | |
3956 | if (NILP (vector[0])) | |
3957 | { | |
d925fb39 RS |
3958 | int was_locked = single_kboard; |
3959 | int count = specpdl_ptr - specpdl; | |
3960 | ||
9291c072 RS |
3961 | /* Mark the timer as triggered to prevent problems if the lisp |
3962 | code fails to reschedule it right. */ | |
3963 | vector[0] = Qt; | |
3964 | ||
d925fb39 | 3965 | specbind (Qinhibit_quit, Qt); |
9291c072 | 3966 | |
d925fb39 RS |
3967 | call1 (Qtimer_event_handler, chosen_timer); |
3968 | timers_run++; | |
9291c072 | 3969 | |
d925fb39 | 3970 | unbind_to (count, Qnil); |
4ec4ed6a | 3971 | |
d925fb39 RS |
3972 | /* Resume allowing input from any kboard, if that was true before. */ |
3973 | if (!was_locked) | |
3974 | any_kboard_state (); | |
9291c072 | 3975 | |
d925fb39 RS |
3976 | /* Since we have handled the event, |
3977 | we don't need to tell the caller to wake up and do it. */ | |
9291c072 RS |
3978 | } |
3979 | } | |
3980 | else | |
3981 | /* When we encounter a timer that is still waiting, | |
3982 | return the amount of time to wait before it is ripe. */ | |
3983 | { | |
3984 | UNGCPRO; | |
9291c072 RS |
3985 | return difference; |
3986 | } | |
c04cbc3b | 3987 | } |
9291c072 | 3988 | |
7ea13e12 RS |
3989 | /* No timers are pending in the future. */ |
3990 | /* Return 0 if we generated an event, and -1 if not. */ | |
3991 | UNGCPRO; | |
c04cbc3b RS |
3992 | return nexttime; |
3993 | } | |
3994 | \f | |
284f4730 | 3995 | /* Caches for modify_event_symbol. */ |
e9bf89a0 | 3996 | static Lisp_Object accent_key_syms; |
284f4730 JB |
3997 | static Lisp_Object func_key_syms; |
3998 | static Lisp_Object mouse_syms; | |
07de30b9 GV |
3999 | #ifdef WINDOWSNT |
4000 | static Lisp_Object mouse_wheel_syms; | |
4001 | #endif | |
a24dc617 | 4002 | static Lisp_Object drag_n_drop_syms; |
284f4730 | 4003 | |
e9bf89a0 RS |
4004 | /* This is a list of keysym codes for special "accent" characters. |
4005 | It parallels lispy_accent_keys. */ | |
4006 | ||
4007 | static int lispy_accent_codes[] = | |
4008 | { | |
79a7046c | 4009 | #ifdef XK_dead_circumflex |
e9bf89a0 | 4010 | XK_dead_circumflex, |
79a7046c RS |
4011 | #else |
4012 | 0, | |
4013 | #endif | |
4014 | #ifdef XK_dead_grave | |
e9bf89a0 | 4015 | XK_dead_grave, |
79a7046c RS |
4016 | #else |
4017 | 0, | |
4018 | #endif | |
4019 | #ifdef XK_dead_tilde | |
e9bf89a0 | 4020 | XK_dead_tilde, |
79a7046c RS |
4021 | #else |
4022 | 0, | |
4023 | #endif | |
4024 | #ifdef XK_dead_diaeresis | |
e9bf89a0 | 4025 | XK_dead_diaeresis, |
79a7046c RS |
4026 | #else |
4027 | 0, | |
4028 | #endif | |
4029 | #ifdef XK_dead_macron | |
e9bf89a0 | 4030 | XK_dead_macron, |
79a7046c RS |
4031 | #else |
4032 | 0, | |
4033 | #endif | |
4034 | #ifdef XK_dead_degree | |
e9bf89a0 | 4035 | XK_dead_degree, |
79a7046c RS |
4036 | #else |
4037 | 0, | |
4038 | #endif | |
4039 | #ifdef XK_dead_acute | |
e9bf89a0 | 4040 | XK_dead_acute, |
79a7046c RS |
4041 | #else |
4042 | 0, | |
4043 | #endif | |
4044 | #ifdef XK_dead_cedilla | |
e9bf89a0 | 4045 | XK_dead_cedilla, |
79a7046c RS |
4046 | #else |
4047 | 0, | |
4048 | #endif | |
4049 | #ifdef XK_dead_breve | |
e9bf89a0 | 4050 | XK_dead_breve, |
79a7046c RS |
4051 | #else |
4052 | 0, | |
4053 | #endif | |
4054 | #ifdef XK_dead_ogonek | |
e9bf89a0 | 4055 | XK_dead_ogonek, |
79a7046c RS |
4056 | #else |
4057 | 0, | |
4058 | #endif | |
4059 | #ifdef XK_dead_caron | |
e9bf89a0 | 4060 | XK_dead_caron, |
79a7046c RS |
4061 | #else |
4062 | 0, | |
4063 | #endif | |
4064 | #ifdef XK_dead_doubleacute | |
e9bf89a0 | 4065 | XK_dead_doubleacute, |
79a7046c RS |
4066 | #else |
4067 | 0, | |
4068 | #endif | |
4069 | #ifdef XK_dead_abovedot | |
e9bf89a0 | 4070 | XK_dead_abovedot, |
79a7046c RS |
4071 | #else |
4072 | 0, | |
4073 | #endif | |
e9bf89a0 RS |
4074 | }; |
4075 | ||
4076 | /* This is a list of Lisp names for special "accent" characters. | |
4077 | It parallels lispy_accent_codes. */ | |
4078 | ||
4079 | static char *lispy_accent_keys[] = | |
4080 | { | |
4081 | "dead-circumflex", | |
4082 | "dead-grave", | |
4083 | "dead-tilde", | |
4084 | "dead-diaeresis", | |
4085 | "dead-macron", | |
4086 | "dead-degree", | |
4087 | "dead-acute", | |
4088 | "dead-cedilla", | |
4089 | "dead-breve", | |
4090 | "dead-ogonek", | |
4091 | "dead-caron", | |
4092 | "dead-doubleacute", | |
4093 | "dead-abovedot", | |
4094 | }; | |
4095 | ||
e98a93eb GV |
4096 | #ifdef HAVE_NTGUI |
4097 | #define FUNCTION_KEY_OFFSET 0x0 | |
4098 | ||
4099 | char *lispy_function_keys[] = | |
4100 | { | |
4101 | 0, /* 0 */ | |
4102 | ||
4103 | 0, /* VK_LBUTTON 0x01 */ | |
4104 | 0, /* VK_RBUTTON 0x02 */ | |
4105 | "cancel", /* VK_CANCEL 0x03 */ | |
4106 | 0, /* VK_MBUTTON 0x04 */ | |
4107 | ||
4108 | 0, 0, 0, /* 0x05 .. 0x07 */ | |
4109 | ||
4110 | "backspace", /* VK_BACK 0x08 */ | |
4111 | "tab", /* VK_TAB 0x09 */ | |
4112 | ||
4113 | 0, 0, /* 0x0A .. 0x0B */ | |
4114 | ||
4115 | "clear", /* VK_CLEAR 0x0C */ | |
4116 | "return", /* VK_RETURN 0x0D */ | |
4117 | ||
4118 | 0, 0, /* 0x0E .. 0x0F */ | |
4119 | ||
1161d367 GV |
4120 | 0, /* VK_SHIFT 0x10 */ |
4121 | 0, /* VK_CONTROL 0x11 */ | |
4122 | 0, /* VK_MENU 0x12 */ | |
e98a93eb | 4123 | "pause", /* VK_PAUSE 0x13 */ |
1161d367 | 4124 | "capslock", /* VK_CAPITAL 0x14 */ |
e98a93eb GV |
4125 | |
4126 | 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */ | |
4127 | ||
1161d367 | 4128 | "escape", /* VK_ESCAPE 0x1B */ |
e98a93eb GV |
4129 | |
4130 | 0, 0, 0, 0, /* 0x1C .. 0x1F */ | |
4131 | ||
4132 | 0, /* VK_SPACE 0x20 */ | |
4133 | "prior", /* VK_PRIOR 0x21 */ | |
4134 | "next", /* VK_NEXT 0x22 */ | |
4135 | "end", /* VK_END 0x23 */ | |
4136 | "home", /* VK_HOME 0x24 */ | |
4137 | "left", /* VK_LEFT 0x25 */ | |
4138 | "up", /* VK_UP 0x26 */ | |
4139 | "right", /* VK_RIGHT 0x27 */ | |
4140 | "down", /* VK_DOWN 0x28 */ | |
4141 | "select", /* VK_SELECT 0x29 */ | |
4142 | "print", /* VK_PRINT 0x2A */ | |
4143 | "execute", /* VK_EXECUTE 0x2B */ | |
4144 | "snapshot", /* VK_SNAPSHOT 0x2C */ | |
4145 | "insert", /* VK_INSERT 0x2D */ | |
4146 | "delete", /* VK_DELETE 0x2E */ | |
4147 | "help", /* VK_HELP 0x2F */ | |
4148 | ||
4149 | /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ | |
4150 | ||
4151 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
4152 | ||
4153 | 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */ | |
4154 | ||
4155 | /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ | |
4156 | ||
4157 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
4158 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
4159 | 0, 0, 0, 0, 0, 0, 0, 0, | |
4160 | ||
e376f90d RS |
4161 | "lwindow", /* VK_LWIN 0x5B */ |
4162 | "rwindow", /* VK_RWIN 0x5C */ | |
4163 | "apps", /* VK_APPS 0x5D */ | |
e98a93eb GV |
4164 | |
4165 | 0, 0, /* 0x5E .. 0x5F */ | |
4166 | ||
4167 | "kp-0", /* VK_NUMPAD0 0x60 */ | |
4168 | "kp-1", /* VK_NUMPAD1 0x61 */ | |
4169 | "kp-2", /* VK_NUMPAD2 0x62 */ | |
4170 | "kp-3", /* VK_NUMPAD3 0x63 */ | |
4171 | "kp-4", /* VK_NUMPAD4 0x64 */ | |
4172 | "kp-5", /* VK_NUMPAD5 0x65 */ | |
4173 | "kp-6", /* VK_NUMPAD6 0x66 */ | |
4174 | "kp-7", /* VK_NUMPAD7 0x67 */ | |
4175 | "kp-8", /* VK_NUMPAD8 0x68 */ | |
4176 | "kp-9", /* VK_NUMPAD9 0x69 */ | |
4177 | "kp-multiply", /* VK_MULTIPLY 0x6A */ | |
4178 | "kp-add", /* VK_ADD 0x6B */ | |
4179 | "kp-separator", /* VK_SEPARATOR 0x6C */ | |
4180 | "kp-subtract", /* VK_SUBTRACT 0x6D */ | |
4181 | "kp-decimal", /* VK_DECIMAL 0x6E */ | |
4182 | "kp-divide", /* VK_DIVIDE 0x6F */ | |
4183 | "f1", /* VK_F1 0x70 */ | |
4184 | "f2", /* VK_F2 0x71 */ | |
4185 | "f3", /* VK_F3 0x72 */ | |
4186 | "f4", /* VK_F4 0x73 */ | |
4187 | "f5", /* VK_F5 0x74 */ | |
4188 | "f6", /* VK_F6 0x75 */ | |
4189 | "f7", /* VK_F7 0x76 */ | |
4190 | "f8", /* VK_F8 0x77 */ | |
4191 | "f9", /* VK_F9 0x78 */ | |
4192 | "f10", /* VK_F10 0x79 */ | |
4193 | "f11", /* VK_F11 0x7A */ | |
4194 | "f12", /* VK_F12 0x7B */ | |
4195 | "f13", /* VK_F13 0x7C */ | |
4196 | "f14", /* VK_F14 0x7D */ | |
4197 | "f15", /* VK_F15 0x7E */ | |
4198 | "f16", /* VK_F16 0x7F */ | |
4199 | "f17", /* VK_F17 0x80 */ | |
4200 | "f18", /* VK_F18 0x81 */ | |
4201 | "f19", /* VK_F19 0x82 */ | |
4202 | "f20", /* VK_F20 0x83 */ | |
4203 | "f21", /* VK_F21 0x84 */ | |
4204 | "f22", /* VK_F22 0x85 */ | |
4205 | "f23", /* VK_F23 0x86 */ | |
4206 | "f24", /* VK_F24 0x87 */ | |
4207 | ||
4208 | 0, 0, 0, 0, /* 0x88 .. 0x8B */ | |
4209 | 0, 0, 0, 0, /* 0x8C .. 0x8F */ | |
4210 | ||
4211 | "kp-numlock", /* VK_NUMLOCK 0x90 */ | |
4212 | "scroll", /* VK_SCROLL 0x91 */ | |
4213 | ||
e376f90d RS |
4214 | "kp-space", /* VK_NUMPAD_CLEAR 0x92 */ |
4215 | "kp-enter", /* VK_NUMPAD_ENTER 0x93 */ | |
4216 | "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */ | |
4217 | "kp-next", /* VK_NUMPAD_NEXT 0x95 */ | |
4218 | "kp-end", /* VK_NUMPAD_END 0x96 */ | |
4219 | "kp-home", /* VK_NUMPAD_HOME 0x97 */ | |
4220 | "kp-left", /* VK_NUMPAD_LEFT 0x98 */ | |
4221 | "kp-up", /* VK_NUMPAD_UP 0x99 */ | |
4222 | "kp-right", /* VK_NUMPAD_RIGHT 0x9A */ | |
4223 | "kp-down", /* VK_NUMPAD_DOWN 0x9B */ | |
4224 | "kp-insert", /* VK_NUMPAD_INSERT 0x9C */ | |
4225 | "kp-delete", /* VK_NUMPAD_DELETE 0x9D */ | |
4226 | ||
4227 | 0, 0, /* 0x9E .. 0x9F */ | |
4228 | ||
e98a93eb GV |
4229 | /* |
4230 | * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys. | |
e8886a1d | 4231 | * Used only as parameters to GetAsyncKeyState and GetKeyState. |
e98a93eb GV |
4232 | * No other API or message will distinguish left and right keys this way. |
4233 | */ | |
4234 | /* 0xA0 .. 0xEF */ | |
4235 | ||
4236 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
4237 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
4238 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
4239 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
4240 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
4241 | ||
4242 | /* 0xF0 .. 0xF5 */ | |
4243 | ||
4244 | 0, 0, 0, 0, 0, 0, | |
4245 | ||
4246 | "attn", /* VK_ATTN 0xF6 */ | |
4247 | "crsel", /* VK_CRSEL 0xF7 */ | |
4248 | "exsel", /* VK_EXSEL 0xF8 */ | |
4249 | "ereof", /* VK_EREOF 0xF9 */ | |
4250 | "play", /* VK_PLAY 0xFA */ | |
4251 | "zoom", /* VK_ZOOM 0xFB */ | |
4252 | "noname", /* VK_NONAME 0xFC */ | |
4253 | "pa1", /* VK_PA1 0xFD */ | |
4254 | "oem_clear", /* VK_OEM_CLEAR 0xFE */ | |
1161d367 | 4255 | 0 /* 0xFF */ |
e98a93eb GV |
4256 | }; |
4257 | ||
04f215f0 | 4258 | #else /* not HAVE_NTGUI */ |
e98a93eb | 4259 | |
37cd9f30 KH |
4260 | #ifdef XK_kana_A |
4261 | static char *lispy_kana_keys[] = | |
4262 | { | |
4263 | /* X Keysym value */ | |
4264 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */ | |
4265 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */ | |
4266 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */ | |
4267 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */ | |
4268 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */ | |
4269 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */ | |
4270 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */ | |
4271 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0, | |
4272 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */ | |
4273 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */ | |
4274 | 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket", | |
4275 | "kana-comma", "kana-conjunctive", "kana-WO", "kana-a", | |
4276 | "kana-i", "kana-u", "kana-e", "kana-o", | |
4277 | "kana-ya", "kana-yu", "kana-yo", "kana-tsu", | |
4278 | "prolongedsound", "kana-A", "kana-I", "kana-U", | |
4279 | "kana-E", "kana-O", "kana-KA", "kana-KI", | |
4280 | "kana-KU", "kana-KE", "kana-KO", "kana-SA", | |
4281 | "kana-SHI", "kana-SU", "kana-SE", "kana-SO", | |
4282 | "kana-TA", "kana-CHI", "kana-TSU", "kana-TE", | |
4283 | "kana-TO", "kana-NA", "kana-NI", "kana-NU", | |
4284 | "kana-NE", "kana-NO", "kana-HA", "kana-HI", | |
4285 | "kana-FU", "kana-HE", "kana-HO", "kana-MA", | |
4286 | "kana-MI", "kana-MU", "kana-ME", "kana-MO", | |
4287 | "kana-YA", "kana-YU", "kana-YO", "kana-RA", | |
4288 | "kana-RI", "kana-RU", "kana-RE", "kana-RO", | |
4289 | "kana-WA", "kana-N", "voicedsound", "semivoicedsound", | |
4290 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */ | |
4291 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */ | |
4292 | }; | |
4293 | #endif /* XK_kana_A */ | |
4294 | ||
04f215f0 RS |
4295 | #define FUNCTION_KEY_OFFSET 0xff00 |
4296 | ||
284f4730 JB |
4297 | /* You'll notice that this table is arranged to be conveniently |
4298 | indexed by X Windows keysym values. */ | |
4299 | static char *lispy_function_keys[] = | |
4300 | { | |
4301 | /* X Keysym value */ | |
4302 | ||
75045dcb RS |
4303 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */ |
4304 | "backspace", "tab", "linefeed", "clear", | |
4305 | 0, "return", 0, 0, | |
4306 | 0, 0, 0, "pause", /* 0xff10...1f */ | |
4307 | 0, 0, 0, 0, 0, 0, 0, "escape", | |
86e5706b | 4308 | 0, 0, 0, 0, |
75045dcb RS |
4309 | 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */ |
4310 | "romaji", "hiragana", "katakana", "hiragana-katakana", | |
4311 | "zenkaku", "hankaku", "zenkaku-hankaku", "touroku", | |
4312 | "massyo", "kana-lock", "kana-shift", "eisu-shift", | |
4313 | "eisu-toggle", /* 0xff30...3f */ | |
4314 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
86e5706b RS |
4315 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */ |
4316 | ||
75045dcb RS |
4317 | "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */ |
4318 | "down", "prior", "next", "end", | |
4319 | "begin", 0, 0, 0, 0, 0, 0, 0, | |
284f4730 JB |
4320 | "select", /* 0xff60 */ /* IsMiscFunctionKey */ |
4321 | "print", | |
4322 | "execute", | |
4323 | "insert", | |
4324 | 0, /* 0xff64 */ | |
4325 | "undo", | |
4326 | "redo", | |
4327 | "menu", | |
4328 | "find", | |
4329 | "cancel", | |
4330 | "help", | |
4331 | "break", /* 0xff6b */ | |
4332 | ||
75045dcb RS |
4333 | 0, 0, 0, 0, |
4334 | 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */ | |
4335 | 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */ | |
284f4730 JB |
4336 | "kp-space", /* 0xff80 */ /* IsKeypadKey */ |
4337 | 0, 0, 0, 0, 0, 0, 0, 0, | |
4338 | "kp-tab", /* 0xff89 */ | |
4339 | 0, 0, 0, | |
4340 | "kp-enter", /* 0xff8d */ | |
4341 | 0, 0, 0, | |
4342 | "kp-f1", /* 0xff91 */ | |
4343 | "kp-f2", | |
4344 | "kp-f3", | |
4345 | "kp-f4", | |
872157e7 RS |
4346 | "kp-home", /* 0xff95 */ |
4347 | "kp-left", | |
4348 | "kp-up", | |
4349 | "kp-right", | |
4350 | "kp-down", | |
4351 | "kp-prior", /* kp-page-up */ | |
4352 | "kp-next", /* kp-page-down */ | |
4353 | "kp-end", | |
4354 | "kp-begin", | |
4355 | "kp-insert", | |
4356 | "kp-delete", | |
4357 | 0, /* 0xffa0 */ | |
4358 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
284f4730 JB |
4359 | "kp-multiply", /* 0xffaa */ |
4360 | "kp-add", | |
4361 | "kp-separator", | |
4362 | "kp-subtract", | |
4363 | "kp-decimal", | |
4364 | "kp-divide", /* 0xffaf */ | |
4365 | "kp-0", /* 0xffb0 */ | |
4366 | "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9", | |
4367 | 0, /* 0xffba */ | |
4368 | 0, 0, | |
4369 | "kp-equal", /* 0xffbd */ | |
4370 | "f1", /* 0xffbe */ /* IsFunctionKey */ | |
86e5706b RS |
4371 | "f2", |
4372 | "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */ | |
4373 | "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", | |
4374 | "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */ | |
4375 | "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34", | |
4376 | "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */ | |
4377 | 0, 0, 0, 0, 0, 0, 0, 0, | |
4378 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */ | |
4379 | 0, 0, 0, 0, 0, 0, 0, "delete" | |
04f215f0 | 4380 | }; |
284f4730 | 4381 | |
04f215f0 RS |
4382 | /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */ |
4383 | #define ISO_FUNCTION_KEY_OFFSET 0xfe00 | |
4384 | ||
4385 | static char *iso_lispy_function_keys[] = | |
4386 | { | |
4387 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */ | |
4388 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */ | |
4389 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */ | |
4390 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */ | |
4391 | "iso-lefttab", /* 0xfe20 */ | |
4392 | "iso-move-line-up", "iso-move-line-down", | |
4393 | "iso-partial-line-up", "iso-partial-line-down", | |
4394 | "iso-partial-space-left", "iso-partial-space-right", | |
4395 | "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */ | |
4396 | "iso-release-margin-left", "iso-release-margin-right", | |
4397 | "iso-release-both-margins", | |
4398 | "iso-fast-cursor-left", "iso-fast-cursor-right", | |
4399 | "iso-fast-cursor-up", "iso-fast-cursor-down", | |
4400 | "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */ | |
4401 | "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */ | |
4402 | }; | |
4403 | ||
4404 | #endif /* not HAVE_NTGUI */ | |
e98a93eb | 4405 | |
8e1e4240 | 4406 | Lisp_Object Vlispy_mouse_stem; |
284f4730 | 4407 | |
07de30b9 GV |
4408 | #ifdef WINDOWSNT |
4409 | /* mouse-wheel events are generated by the wheel on devices such as | |
4410 | the MS Intellimouse. The wheel sits in between the left and right | |
4411 | mouse buttons, and is typically used to scroll or zoom the window | |
4412 | underneath the pointer. mouse-wheel events specify the object on | |
4413 | which they operate, and a delta corresponding to the amount and | |
4414 | direction that the wheel is rotated. Clicking the mouse-wheel | |
4415 | generates a mouse-2 event. */ | |
4416 | static char *lispy_mouse_wheel_names[] = | |
4417 | { | |
4418 | "mouse-wheel" | |
4419 | }; | |
a24dc617 | 4420 | |
07de30b9 GV |
4421 | #endif /* WINDOWSNT */ |
4422 | ||
a24dc617 RS |
4423 | /* drag-n-drop events are generated when a set of selected files are |
4424 | dragged from another application and dropped onto an Emacs window. */ | |
4425 | static char *lispy_drag_n_drop_names[] = | |
4426 | { | |
4427 | "drag-n-drop" | |
4428 | }; | |
4429 | ||
3c370943 | 4430 | /* Scroll bar parts. */ |
4bb994d1 | 4431 | Lisp_Object Qabove_handle, Qhandle, Qbelow_handle; |
7ee32cda | 4432 | Lisp_Object Qup, Qdown, Qbottom, Qend_scroll; |
eef28553 | 4433 | Lisp_Object Qtop, Qratio; |
4bb994d1 | 4434 | |
3c370943 JB |
4435 | /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */ |
4436 | Lisp_Object *scroll_bar_parts[] = { | |
db08707d | 4437 | &Qabove_handle, &Qhandle, &Qbelow_handle, |
eef28553 | 4438 | &Qup, &Qdown, &Qtop, &Qbottom, &Qend_scroll, &Qratio |
4bb994d1 JB |
4439 | }; |
4440 | ||
5bf68f6e AS |
4441 | /* User signal events. */ |
4442 | Lisp_Object Qusr1_signal, Qusr2_signal; | |
4443 | ||
4444 | Lisp_Object *lispy_user_signals[] = | |
4445 | { | |
4446 | &Qusr1_signal, &Qusr2_signal | |
4447 | }; | |
4448 | ||
4bb994d1 | 4449 | |
7b4aedb9 | 4450 | /* A vector, indexed by button number, giving the down-going location |
3c370943 | 4451 | of currently depressed buttons, both scroll bar and non-scroll bar. |
7b4aedb9 JB |
4452 | |
4453 | The elements have the form | |
4454 | (BUTTON-NUMBER MODIFIER-MASK . REST) | |
4455 | where REST is the cdr of a position as it would be reported in the event. | |
4456 | ||
4457 | The make_lispy_event function stores positions here to tell the | |
4458 | difference between click and drag events, and to store the starting | |
4459 | location to be included in drag events. */ | |
4460 | ||
4461 | static Lisp_Object button_down_location; | |
88cb0656 | 4462 | |
fbcd35bd JB |
4463 | /* Information about the most recent up-going button event: Which |
4464 | button, what location, and what time. */ | |
4465 | ||
559f9d04 RS |
4466 | static int last_mouse_button; |
4467 | static int last_mouse_x; | |
4468 | static int last_mouse_y; | |
4469 | static unsigned long button_down_time; | |
fbcd35bd | 4470 | |
564dc952 JB |
4471 | /* The maximum time between clicks to make a double-click, |
4472 | or Qnil to disable double-click detection, | |
4473 | or Qt for no time limit. */ | |
4474 | Lisp_Object Vdouble_click_time; | |
fbcd35bd JB |
4475 | |
4476 | /* The number of clicks in this multiple-click. */ | |
4477 | ||
4478 | int double_click_count; | |
4479 | ||
284f4730 JB |
4480 | /* Given a struct input_event, build the lisp event which represents |
4481 | it. If EVENT is 0, build a mouse movement event from the mouse | |
88cb0656 JB |
4482 | movement buffer, which should have a movement event in it. |
4483 | ||
4484 | Note that events must be passed to this function in the order they | |
4485 | are received; this function stores the location of button presses | |
4486 | in order to build drag events when the button is released. */ | |
284f4730 JB |
4487 | |
4488 | static Lisp_Object | |
4489 | make_lispy_event (event) | |
4490 | struct input_event *event; | |
4491 | { | |
79a7046c RS |
4492 | int i; |
4493 | ||
0220c518 | 4494 | switch (SWITCH_ENUM_CAST (event->kind)) |
284f4730 | 4495 | { |
284f4730 JB |
4496 | /* A simple keystroke. */ |
4497 | case ascii_keystroke: | |
86e5706b | 4498 | { |
9343ab07 | 4499 | Lisp_Object lispy_c; |
e9bf89a0 | 4500 | int c = event->code & 0377; |
5a1c6df8 JB |
4501 | /* Turn ASCII characters into control characters |
4502 | when proper. */ | |
4503 | if (event->modifiers & ctrl_modifier) | |
d205953b JB |
4504 | c = make_ctrl_char (c); |
4505 | ||
4506 | /* Add in the other modifier bits. We took care of ctrl_modifier | |
4507 | just above, and the shift key was taken care of by the X code, | |
4508 | and applied to control characters by make_ctrl_char. */ | |
86e5706b RS |
4509 | c |= (event->modifiers |
4510 | & (meta_modifier | alt_modifier | |
4511 | | hyper_modifier | super_modifier)); | |
32454a9f RS |
4512 | /* Distinguish Shift-SPC from SPC. */ |
4513 | if ((event->code & 0377) == 040 | |
4514 | && event->modifiers & shift_modifier) | |
4515 | c |= shift_modifier; | |
559f9d04 | 4516 | button_down_time = 0; |
bb9e9bed | 4517 | XSETFASTINT (lispy_c, c); |
9343ab07 | 4518 | return lispy_c; |
86e5706b | 4519 | } |
284f4730 | 4520 | |
a50e723f KH |
4521 | case multibyte_char_keystroke: |
4522 | { | |
4523 | Lisp_Object lispy_c; | |
4524 | ||
4525 | XSETFASTINT (lispy_c, event->code); | |
4526 | return lispy_c; | |
4527 | } | |
4528 | ||
284f4730 JB |
4529 | /* A function key. The symbol may need to have modifier prefixes |
4530 | tacked onto it. */ | |
4531 | case non_ascii_keystroke: | |
559f9d04 | 4532 | button_down_time = 0; |
e9bf89a0 RS |
4533 | |
4534 | for (i = 0; i < sizeof (lispy_accent_codes) / sizeof (int); i++) | |
4535 | if (event->code == lispy_accent_codes[i]) | |
4536 | return modify_event_symbol (i, | |
4537 | event->modifiers, | |
80e4aa30 | 4538 | Qfunction_key, Qnil, |
e9bf89a0 RS |
4539 | lispy_accent_keys, &accent_key_syms, |
4540 | (sizeof (lispy_accent_keys) | |
4541 | / sizeof (lispy_accent_keys[0]))); | |
4542 | ||
270a208f | 4543 | /* Handle system-specific keysyms. */ |
80e4aa30 RS |
4544 | if (event->code & (1 << 28)) |
4545 | { | |
4546 | /* We need to use an alist rather than a vector as the cache | |
4547 | since we can't make a vector long enuf. */ | |
142e6c73 KH |
4548 | if (NILP (current_kboard->system_key_syms)) |
4549 | current_kboard->system_key_syms = Fcons (Qnil, Qnil); | |
2c834fb3 | 4550 | return modify_event_symbol (event->code, |
80e4aa30 | 4551 | event->modifiers, |
7c97ffdc KH |
4552 | Qfunction_key, |
4553 | current_kboard->Vsystem_key_alist, | |
142e6c73 KH |
4554 | 0, ¤t_kboard->system_key_syms, |
4555 | (unsigned)-1); | |
80e4aa30 RS |
4556 | } |
4557 | ||
37cd9f30 KH |
4558 | #ifdef XK_kana_A |
4559 | if (event->code >= 0x400 && event->code < 0x500) | |
4560 | return modify_event_symbol (event->code - 0x400, | |
4561 | event->modifiers & ~shift_modifier, | |
4562 | Qfunction_key, Qnil, | |
4563 | lispy_kana_keys, &func_key_syms, | |
4564 | (sizeof (lispy_kana_keys) | |
4565 | / sizeof (lispy_kana_keys[0]))); | |
4566 | #endif /* XK_kana_A */ | |
4567 | ||
111c4138 | 4568 | #ifdef ISO_FUNCTION_KEY_OFFSET |
04f215f0 RS |
4569 | if (event->code < FUNCTION_KEY_OFFSET |
4570 | && event->code >= ISO_FUNCTION_KEY_OFFSET) | |
4571 | return modify_event_symbol (event->code - ISO_FUNCTION_KEY_OFFSET, | |
4572 | event->modifiers, | |
4573 | Qfunction_key, Qnil, | |
4574 | iso_lispy_function_keys, &func_key_syms, | |
4575 | (sizeof (iso_lispy_function_keys) | |
4576 | / sizeof (iso_lispy_function_keys[0]))); | |
4577 | else | |
111c4138 | 4578 | #endif |
04f215f0 RS |
4579 | return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET, |
4580 | event->modifiers, | |
4581 | Qfunction_key, Qnil, | |
4582 | lispy_function_keys, &func_key_syms, | |
4583 | (sizeof (lispy_function_keys) | |
4584 | / sizeof (lispy_function_keys[0]))); | |
284f4730 | 4585 | |
514354e9 | 4586 | #ifdef HAVE_MOUSE |
df0f2ba1 | 4587 | /* A mouse click. Figure out where it is, decide whether it's |
88cb0656 | 4588 | a press, click or drag, and build the appropriate structure. */ |
284f4730 | 4589 | case mouse_click: |
7ee32cda | 4590 | #ifndef USE_TOOLKIT_SCROLL_BARS |
3c370943 | 4591 | case scroll_bar_click: |
7ee32cda | 4592 | #endif |
284f4730 | 4593 | { |
e9bf89a0 | 4594 | int button = event->code; |
559f9d04 | 4595 | int is_double; |
7b4aedb9 | 4596 | Lisp_Object position; |
dbc4e1c1 JB |
4597 | Lisp_Object *start_pos_ptr; |
4598 | Lisp_Object start_pos; | |
284f4730 | 4599 | |
8c907a56 GM |
4600 | position = Qnil; |
4601 | ||
7b4aedb9 JB |
4602 | /* Build the position as appropriate for this mouse click. */ |
4603 | if (event->kind == mouse_click) | |
284f4730 | 4604 | { |
7b4aedb9 | 4605 | int part; |
598a9fa7 | 4606 | FRAME_PTR f = XFRAME (event->frame_or_window); |
0aafc975 | 4607 | Lisp_Object window; |
7b4aedb9 | 4608 | Lisp_Object posn; |
7ee32cda | 4609 | Lisp_Object string_info = Qnil; |
9e20143a RS |
4610 | int row, column; |
4611 | ||
5da3133a RS |
4612 | /* Ignore mouse events that were made on frame that |
4613 | have been deleted. */ | |
4614 | if (! FRAME_LIVE_P (f)) | |
4615 | return Qnil; | |
4616 | ||
7ee32cda GM |
4617 | /* EVENT->x and EVENT->y are frame-relative pixel |
4618 | coordinates at this place. Under old redisplay, COLUMN | |
4619 | and ROW are set to frame relative glyph coordinates | |
4620 | which are then used to determine whether this click is | |
4621 | in a menu (non-toolkit version). */ | |
4622 | pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), | |
4623 | &column, &row, NULL, 1); | |
7b4aedb9 | 4624 | |
eef045bf RS |
4625 | #ifndef USE_X_TOOLKIT |
4626 | /* In the non-toolkit version, clicks on the menu bar | |
4627 | are ordinary button events in the event buffer. | |
4628 | Distinguish them, and invoke the menu. | |
4629 | ||
4630 | (In the toolkit version, the toolkit handles the menu bar | |
4631 | and Emacs doesn't know about it until after the user | |
4632 | makes a selection.) */ | |
2ee250ec RS |
4633 | if (row >= 0 && row < FRAME_MENU_BAR_LINES (f) |
4634 | && (event->modifiers & down_modifier)) | |
bb936752 | 4635 | { |
b7c49376 | 4636 | Lisp_Object items, item; |
0a0e8fe6 RS |
4637 | int hpos; |
4638 | int i; | |
4639 | ||
2ee250ec | 4640 | #if 0 |
0a0e8fe6 RS |
4641 | /* Activate the menu bar on the down event. If the |
4642 | up event comes in before the menu code can deal with it, | |
4643 | just ignore it. */ | |
4644 | if (! (event->modifiers & down_modifier)) | |
4645 | return Qnil; | |
2ee250ec | 4646 | #endif |
0aafc975 | 4647 | |
7ee32cda | 4648 | /* Find the menu bar item under `column'. */ |
f2ae6b3f | 4649 | item = Qnil; |
5ec75a55 | 4650 | items = FRAME_MENU_BAR_ITEMS (f); |
35b3402f | 4651 | for (i = 0; i < XVECTOR (items)->size; i += 4) |
5ec75a55 RS |
4652 | { |
4653 | Lisp_Object pos, string; | |
b7c49376 | 4654 | string = XVECTOR (items)->contents[i + 1]; |
35b3402f | 4655 | pos = XVECTOR (items)->contents[i + 3]; |
b7c49376 RS |
4656 | if (NILP (string)) |
4657 | break; | |
9e20143a RS |
4658 | if (column >= XINT (pos) |
4659 | && column < XINT (pos) + XSTRING (string)->size) | |
b7c49376 RS |
4660 | { |
4661 | item = XVECTOR (items)->contents[i]; | |
4662 | break; | |
4663 | } | |
5ec75a55 | 4664 | } |
9e20143a | 4665 | |
7ee32cda GM |
4666 | /* ELisp manual 2.4b says (x y) are window relative but |
4667 | code says they are frame-relative. */ | |
5ec75a55 RS |
4668 | position |
4669 | = Fcons (event->frame_or_window, | |
4670 | Fcons (Qmenu_bar, | |
4671 | Fcons (Fcons (event->x, event->y), | |
4672 | Fcons (make_number (event->timestamp), | |
4673 | Qnil)))); | |
4674 | ||
b7c49376 | 4675 | return Fcons (item, Fcons (position, Qnil)); |
5ec75a55 | 4676 | } |
eef045bf | 4677 | #endif /* not USE_X_TOOLKIT */ |
0aafc975 | 4678 | |
7ee32cda GM |
4679 | /* Set `window' to the window under frame pixel coordinates |
4680 | event->x/event->y. */ | |
4681 | window = window_from_coordinates (f, XINT (event->x), | |
4682 | XINT (event->y), &part, 0); | |
0aafc975 | 4683 | |
8c18cbfb | 4684 | if (!WINDOWP (window)) |
78ced549 RS |
4685 | { |
4686 | window = event->frame_or_window; | |
4687 | posn = Qnil; | |
4688 | } | |
284f4730 | 4689 | else |
7b4aedb9 | 4690 | { |
7ee32cda GM |
4691 | /* It's a click in window window at frame coordinates |
4692 | event->x/ event->y. */ | |
4693 | struct window *w = XWINDOW (window); | |
4694 | ||
4695 | /* Get window relative coordinates. Original code | |
4696 | `rounded' this to glyph boundaries. */ | |
4697 | int wx = FRAME_TO_WINDOW_PIXEL_X (w, XINT (event->x)); | |
4698 | int wy = FRAME_TO_WINDOW_PIXEL_Y (w, XINT (event->y)); | |
4699 | ||
4700 | /* Set event coordinates to window-relative coordinates | |
4701 | for constructing the Lisp event below. */ | |
4702 | XSETINT (event->x, wx); | |
4703 | XSETINT (event->y, wy); | |
4704 | ||
4705 | if (part == 1 || part == 3) | |
4706 | { | |
4707 | /* Mode line or top line. Look for a string under | |
4708 | the mouse that may have a `local-map' property. */ | |
4709 | Lisp_Object string; | |
4710 | int charpos; | |
4711 | ||
045dee35 | 4712 | posn = part == 1 ? Qmode_line : Qheader_line; |
7ee32cda GM |
4713 | string = mode_line_string (w, wx, wy, part == 1, &charpos); |
4714 | if (STRINGP (string)) | |
4715 | string_info = Fcons (string, make_number (charpos)); | |
4716 | } | |
7b4aedb9 JB |
4717 | else if (part == 2) |
4718 | posn = Qvertical_line; | |
4719 | else | |
7ee32cda | 4720 | XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy)); |
7b4aedb9 JB |
4721 | } |
4722 | ||
5ec75a55 RS |
4723 | position |
4724 | = Fcons (window, | |
4725 | Fcons (posn, | |
4726 | Fcons (Fcons (event->x, event->y), | |
4727 | Fcons (make_number (event->timestamp), | |
7ee32cda GM |
4728 | (NILP (string_info) |
4729 | ? Qnil | |
4730 | : Fcons (string_info, Qnil)))))); | |
284f4730 | 4731 | } |
7ee32cda | 4732 | #ifndef USE_TOOLKIT_SCROLL_BARS |
7b4aedb9 | 4733 | else |
88cb0656 | 4734 | { |
7ee32cda | 4735 | /* It's a scrollbar click. */ |
9e20143a RS |
4736 | Lisp_Object window; |
4737 | Lisp_Object portion_whole; | |
4738 | Lisp_Object part; | |
4739 | ||
4740 | window = event->frame_or_window; | |
4741 | portion_whole = Fcons (event->x, event->y); | |
4742 | part = *scroll_bar_parts[(int) event->part]; | |
7b4aedb9 | 4743 | |
db08707d RS |
4744 | position |
4745 | = Fcons (window, | |
4746 | Fcons (Qvertical_scroll_bar, | |
4747 | Fcons (portion_whole, | |
4748 | Fcons (make_number (event->timestamp), | |
4749 | Fcons (part, Qnil))))); | |
88cb0656 | 4750 | } |
7ee32cda | 4751 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
88cb0656 | 4752 | |
8e1e4240 GM |
4753 | if (button >= XVECTOR (button_down_location)->size) |
4754 | { | |
4755 | button_down_location = larger_vector (button_down_location, | |
4756 | button + 1, Qnil); | |
4757 | mouse_syms = larger_vector (mouse_syms, button + 1, Qnil); | |
4758 | } | |
4759 | ||
dbc4e1c1 JB |
4760 | start_pos_ptr = &XVECTOR (button_down_location)->contents[button]; |
4761 | ||
4762 | start_pos = *start_pos_ptr; | |
4763 | *start_pos_ptr = Qnil; | |
7b4aedb9 | 4764 | |
559f9d04 RS |
4765 | is_double = (button == last_mouse_button |
4766 | && XINT (event->x) == last_mouse_x | |
4767 | && XINT (event->y) == last_mouse_y | |
4768 | && button_down_time != 0 | |
4769 | && (EQ (Vdouble_click_time, Qt) | |
4770 | || (INTEGERP (Vdouble_click_time) | |
4771 | && ((int)(event->timestamp - button_down_time) | |
4772 | < XINT (Vdouble_click_time))))); | |
4773 | last_mouse_button = button; | |
4774 | last_mouse_x = XINT (event->x); | |
4775 | last_mouse_y = XINT (event->y); | |
4776 | ||
7b4aedb9 JB |
4777 | /* If this is a button press, squirrel away the location, so |
4778 | we can decide later whether it was a click or a drag. */ | |
4779 | if (event->modifiers & down_modifier) | |
559f9d04 RS |
4780 | { |
4781 | if (is_double) | |
4782 | { | |
4783 | double_click_count++; | |
4784 | event->modifiers |= ((double_click_count > 2) | |
4785 | ? triple_modifier | |
4786 | : double_modifier); | |
4787 | } | |
4788 | else | |
4789 | double_click_count = 1; | |
4790 | button_down_time = event->timestamp; | |
4791 | *start_pos_ptr = Fcopy_alist (position); | |
4792 | } | |
7b4aedb9 | 4793 | |
88cb0656 | 4794 | /* Now we're releasing a button - check the co-ordinates to |
7b4aedb9 | 4795 | see if this was a click or a drag. */ |
88cb0656 JB |
4796 | else if (event->modifiers & up_modifier) |
4797 | { | |
48e416d4 RS |
4798 | /* If we did not see a down before this up, |
4799 | ignore the up. Probably this happened because | |
4800 | the down event chose a menu item. | |
4801 | It would be an annoyance to treat the release | |
4802 | of the button that chose the menu item | |
4803 | as a separate event. */ | |
4804 | ||
8c18cbfb | 4805 | if (!CONSP (start_pos)) |
48e416d4 RS |
4806 | return Qnil; |
4807 | ||
88cb0656 | 4808 | event->modifiers &= ~up_modifier; |
48e416d4 | 4809 | #if 0 /* Formerly we treated an up with no down as a click event. */ |
8c18cbfb | 4810 | if (!CONSP (start_pos)) |
dbc4e1c1 JB |
4811 | event->modifiers |= click_modifier; |
4812 | else | |
48e416d4 | 4813 | #endif |
dbc4e1c1 JB |
4814 | { |
4815 | /* The third element of every position should be the (x,y) | |
4816 | pair. */ | |
9b8eb840 | 4817 | Lisp_Object down; |
dbc4e1c1 | 4818 | |
9b8eb840 | 4819 | down = Fnth (make_number (2), start_pos); |
7539e11f KR |
4820 | if (EQ (event->x, XCAR (down)) |
4821 | && EQ (event->y, XCDR (down))) | |
fbcd35bd | 4822 | { |
bc536d84 | 4823 | event->modifiers |= click_modifier; |
fbcd35bd JB |
4824 | } |
4825 | else | |
4826 | { | |
559f9d04 | 4827 | button_down_time = 0; |
fbcd35bd JB |
4828 | event->modifiers |= drag_modifier; |
4829 | } | |
bc536d84 RS |
4830 | /* Don't check is_double; treat this as multiple |
4831 | if the down-event was multiple. */ | |
4832 | if (double_click_count > 1) | |
4833 | event->modifiers |= ((double_click_count > 2) | |
4834 | ? triple_modifier | |
4835 | : double_modifier); | |
dbc4e1c1 | 4836 | } |
88cb0656 JB |
4837 | } |
4838 | else | |
4839 | /* Every mouse event should either have the down_modifier or | |
7b4aedb9 | 4840 | the up_modifier set. */ |
88cb0656 JB |
4841 | abort (); |
4842 | ||
88cb0656 | 4843 | { |
7b4aedb9 | 4844 | /* Get the symbol we should use for the mouse click. */ |
9b8eb840 KH |
4845 | Lisp_Object head; |
4846 | ||
4847 | head = modify_event_symbol (button, | |
4848 | event->modifiers, | |
8e1e4240 GM |
4849 | Qmouse_click, Vlispy_mouse_stem, |
4850 | NULL, | |
4851 | &mouse_syms, | |
4852 | XVECTOR (mouse_syms)->size); | |
88cb0656 | 4853 | if (event->modifiers & drag_modifier) |
dbc4e1c1 JB |
4854 | return Fcons (head, |
4855 | Fcons (start_pos, | |
4856 | Fcons (position, | |
4857 | Qnil))); | |
fbcd35bd JB |
4858 | else if (event->modifiers & (double_modifier | triple_modifier)) |
4859 | return Fcons (head, | |
4860 | Fcons (position, | |
4861 | Fcons (make_number (double_click_count), | |
4862 | Qnil))); | |
88cb0656 JB |
4863 | else |
4864 | return Fcons (head, | |
7b4aedb9 | 4865 | Fcons (position, |
88cb0656 JB |
4866 | Qnil)); |
4867 | } | |
284f4730 | 4868 | } |
db08707d | 4869 | |
7ee32cda GM |
4870 | #if USE_TOOLKIT_SCROLL_BARS |
4871 | ||
4872 | /* We don't have down and up events if using toolkit scroll bars, | |
4873 | so make this always a click event. Store in the `part' of | |
4874 | the Lisp event a symbol which maps to the following actions: | |
4875 | ||
4876 | `above_handle' page up | |
4877 | `below_handle' page down | |
4878 | `up' line up | |
4879 | `down' line down | |
4880 | `top' top of buffer | |
4881 | `bottom' bottom of buffer | |
4882 | `handle' thumb has been dragged. | |
4883 | `end-scroll' end of interaction with scroll bar | |
4884 | ||
4885 | The incoming input_event contains in its `part' member an | |
4886 | index of type `enum scroll_bar_part' which we can use as an | |
4887 | index in scroll_bar_parts to get the appropriate symbol. */ | |
4888 | ||
4889 | case scroll_bar_click: | |
4890 | { | |
4891 | Lisp_Object position, head, window, portion_whole, part; | |
4892 | ||
4893 | window = event->frame_or_window; | |
4894 | portion_whole = Fcons (event->x, event->y); | |
4895 | part = *scroll_bar_parts[(int) event->part]; | |
4896 | ||
4897 | position | |
4898 | = Fcons (window, | |
4899 | Fcons (Qvertical_scroll_bar, | |
4900 | Fcons (portion_whole, | |
4901 | Fcons (make_number (event->timestamp), | |
4902 | Fcons (part, Qnil))))); | |
4903 | ||
4904 | /* Always treat scroll bar events as clicks. */ | |
4905 | event->modifiers |= click_modifier; | |
4906 | ||
4907 | /* Get the symbol we should use for the mouse click. */ | |
4908 | head = modify_event_symbol (event->code, | |
4909 | event->modifiers, | |
8e1e4240 GM |
4910 | Qmouse_click, |
4911 | Vlispy_mouse_stem, | |
4912 | NULL, &mouse_syms, | |
4913 | XVECTOR (mouse_syms)->size); | |
7ee32cda GM |
4914 | return Fcons (head, Fcons (position, Qnil)); |
4915 | } | |
4916 | ||
4917 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
4918 | ||
db08707d | 4919 | #ifdef WINDOWSNT |
fbd6baed | 4920 | case w32_scroll_bar_click: |
db08707d RS |
4921 | { |
4922 | int button = event->code; | |
4923 | int is_double; | |
4924 | Lisp_Object position; | |
4925 | Lisp_Object *start_pos_ptr; | |
4926 | Lisp_Object start_pos; | |
4927 | ||
db08707d RS |
4928 | { |
4929 | Lisp_Object window; | |
4930 | Lisp_Object portion_whole; | |
4931 | Lisp_Object part; | |
4932 | ||
4933 | window = event->frame_or_window; | |
4934 | portion_whole = Fcons (event->x, event->y); | |
4935 | part = *scroll_bar_parts[(int) event->part]; | |
4936 | ||
e8886a1d RS |
4937 | position |
4938 | = Fcons (window, | |
4939 | Fcons (Qvertical_scroll_bar, | |
4940 | Fcons (portion_whole, | |
4941 | Fcons (make_number (event->timestamp), | |
4942 | Fcons (part, Qnil))))); | |
db08707d RS |
4943 | } |
4944 | ||
fbd6baed | 4945 | /* Always treat W32 scroll bar events as clicks. */ |
db08707d RS |
4946 | event->modifiers |= click_modifier; |
4947 | ||
4948 | { | |
4949 | /* Get the symbol we should use for the mouse click. */ | |
4950 | Lisp_Object head; | |
4951 | ||
4952 | head = modify_event_symbol (button, | |
4953 | event->modifiers, | |
8e1e4240 GM |
4954 | Qmouse_click, |
4955 | Vlispy_mouse_stem, | |
4956 | NULL, &mouse_syms, | |
4957 | XVECTOR (mouse_syms)->size); | |
db08707d RS |
4958 | return Fcons (head, |
4959 | Fcons (position, | |
4960 | Qnil)); | |
4961 | } | |
4962 | } | |
07de30b9 GV |
4963 | case mouse_wheel: |
4964 | { | |
4965 | int part; | |
4966 | FRAME_PTR f = XFRAME (event->frame_or_window); | |
4967 | Lisp_Object window; | |
4968 | Lisp_Object posn; | |
4969 | Lisp_Object head, position; | |
4970 | int row, column; | |
4971 | ||
4972 | /* Ignore mouse events that were made on frame that | |
4973 | have been deleted. */ | |
4974 | if (! FRAME_LIVE_P (f)) | |
4975 | return Qnil; | |
4976 | pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), | |
4977 | &column, &row, NULL, 1); | |
afabdbe5 JR |
4978 | window = window_from_coordinates (f, XINT (event->x), |
4979 | XINT (event->y), &part, 0); | |
07de30b9 GV |
4980 | |
4981 | if (!WINDOWP (window)) | |
4982 | { | |
4983 | window = event->frame_or_window; | |
4984 | posn = Qnil; | |
4985 | } | |
4986 | else | |
4987 | { | |
4988 | int pixcolumn, pixrow; | |
4989 | column -= XINT (XWINDOW (window)->left); | |
4990 | row -= XINT (XWINDOW (window)->top); | |
e1bfeab2 JR |
4991 | glyph_to_pixel_coords (XWINDOW(window), column, row, |
4992 | &pixcolumn, &pixrow); | |
07de30b9 GV |
4993 | XSETINT (event->x, pixcolumn); |
4994 | XSETINT (event->y, pixrow); | |
4995 | ||
4996 | if (part == 1) | |
4997 | posn = Qmode_line; | |
4998 | else if (part == 2) | |
4999 | posn = Qvertical_line; | |
7ee32cda | 5000 | else if (part == 3) |
045dee35 | 5001 | posn = Qheader_line; |
07de30b9 GV |
5002 | else |
5003 | XSETINT (posn, | |
5004 | buffer_posn_from_coords (XWINDOW (window), | |
3cd2f327 | 5005 | &column, &row)); |
07de30b9 | 5006 | } |
db08707d | 5007 | |
07de30b9 GV |
5008 | { |
5009 | Lisp_Object head, position; | |
5010 | ||
5011 | position | |
5012 | = Fcons (window, | |
5013 | Fcons (posn, | |
5014 | Fcons (Fcons (event->x, event->y), | |
5015 | Fcons (make_number (event->timestamp), | |
5016 | Qnil)))); | |
5017 | ||
5018 | head = modify_event_symbol (0, event->modifiers, | |
5019 | Qmouse_wheel, Qnil, | |
5020 | lispy_mouse_wheel_names, | |
5021 | &mouse_wheel_syms, 1); | |
5022 | return Fcons (head, | |
5023 | Fcons (position, | |
5024 | Fcons (make_number (event->code), | |
5025 | Qnil))); | |
5026 | } | |
5027 | } | |
5028 | #endif /* WINDOWSNT */ | |
a24dc617 RS |
5029 | |
5030 | case drag_n_drop: | |
5031 | { | |
5032 | int part; | |
5033 | FRAME_PTR f; | |
5034 | Lisp_Object window; | |
5035 | Lisp_Object posn; | |
a24dc617 | 5036 | Lisp_Object files; |
a24dc617 RS |
5037 | |
5038 | /* The frame_or_window field should be a cons of the frame in | |
5039 | which the event occurred and a list of the filenames | |
5040 | dropped. */ | |
5041 | if (! CONSP (event->frame_or_window)) | |
5042 | abort (); | |
5043 | ||
7539e11f KR |
5044 | f = XFRAME (XCAR (event->frame_or_window)); |
5045 | files = XCDR (event->frame_or_window); | |
a24dc617 RS |
5046 | |
5047 | /* Ignore mouse events that were made on frames that | |
5048 | have been deleted. */ | |
5049 | if (! FRAME_LIVE_P (f)) | |
5050 | return Qnil; | |
afabdbe5 JR |
5051 | |
5052 | window = window_from_coordinates (f, XINT (event->x), | |
5053 | XINT (event->y), &part, 0); | |
a24dc617 RS |
5054 | |
5055 | if (!WINDOWP (window)) | |
5056 | { | |
7539e11f | 5057 | window = XCAR (event->frame_or_window); |
a24dc617 RS |
5058 | posn = Qnil; |
5059 | } | |
5060 | else | |
5061 | { | |
7ee32cda GM |
5062 | /* It's an event in window `window' at frame coordinates |
5063 | event->x/ event->y. */ | |
5064 | struct window *w = XWINDOW (window); | |
5065 | ||
5066 | /* Get window relative coordinates. */ | |
5067 | int wx = FRAME_TO_WINDOW_PIXEL_X (w, XINT (event->x)); | |
5068 | int wy = FRAME_TO_WINDOW_PIXEL_Y (w, XINT (event->y)); | |
5069 | ||
5070 | /* Set event coordinates to window-relative coordinates | |
5071 | for constructing the Lisp event below. */ | |
5072 | XSETINT (event->x, wx); | |
5073 | XSETINT (event->y, wy); | |
a24dc617 RS |
5074 | |
5075 | if (part == 1) | |
5076 | posn = Qmode_line; | |
5077 | else if (part == 2) | |
5078 | posn = Qvertical_line; | |
7ee32cda | 5079 | else if (part == 3) |
045dee35 | 5080 | posn = Qheader_line; |
a24dc617 | 5081 | else |
7ee32cda | 5082 | XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy)); |
a24dc617 RS |
5083 | } |
5084 | ||
5085 | { | |
5086 | Lisp_Object head, position; | |
5087 | ||
5088 | position | |
5089 | = Fcons (window, | |
5090 | Fcons (posn, | |
5091 | Fcons (Fcons (event->x, event->y), | |
5092 | Fcons (make_number (event->timestamp), | |
5093 | Qnil)))); | |
5094 | ||
5095 | head = modify_event_symbol (0, event->modifiers, | |
5096 | Qdrag_n_drop, Qnil, | |
5097 | lispy_drag_n_drop_names, | |
5098 | &drag_n_drop_syms, 1); | |
5099 | return Fcons (head, | |
5100 | Fcons (position, | |
5101 | Fcons (files, | |
5102 | Qnil))); | |
5103 | } | |
5104 | } | |
514354e9 | 5105 | #endif /* HAVE_MOUSE */ |
284f4730 | 5106 | |
1a578e9b | 5107 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh) |
da8f7368 GM |
5108 | case MENU_BAR_EVENT: |
5109 | if (EQ (event->arg, event->frame_or_window)) | |
5110 | /* This is the prefix key. We translate this to | |
5111 | `(menu_bar)' because the code in keyboard.c for menu | |
5112 | events, which we use, relies on this. */ | |
5113 | return Fcons (Qmenu_bar, Qnil); | |
5114 | return event->arg; | |
2470a66f KH |
5115 | #endif |
5116 | ||
9ea173e8 | 5117 | case TOOL_BAR_EVENT: |
da8f7368 GM |
5118 | if (EQ (event->arg, event->frame_or_window)) |
5119 | /* This is the prefix key. We translate this to | |
5120 | `(tool_bar)' because the code in keyboard.c for menu | |
5121 | events, which we use, relies on this. */ | |
5122 | return Fcons (Qtool_bar, Qnil); | |
5123 | else if (SYMBOLP (event->arg)) | |
5124 | return apply_modifiers (event->modifiers, event->arg); | |
5125 | return event->arg; | |
5126 | ||
5127 | case USER_SIGNAL_EVENT: | |
5bf68f6e AS |
5128 | /* A user signal. */ |
5129 | return *lispy_user_signals[event->code]; | |
5130 | ||
284f4730 JB |
5131 | /* The 'kind' field of the event is something we don't recognize. */ |
5132 | default: | |
48e416d4 | 5133 | abort (); |
284f4730 JB |
5134 | } |
5135 | } | |
5136 | ||
514354e9 | 5137 | #ifdef HAVE_MOUSE |
6cbff1cb | 5138 | |
284f4730 | 5139 | static Lisp_Object |
7b4aedb9 | 5140 | make_lispy_movement (frame, bar_window, part, x, y, time) |
ff11dfa1 | 5141 | FRAME_PTR frame; |
7b4aedb9 | 5142 | Lisp_Object bar_window; |
3c370943 | 5143 | enum scroll_bar_part part; |
284f4730 | 5144 | Lisp_Object x, y; |
e5d77022 | 5145 | unsigned long time; |
284f4730 | 5146 | { |
3c370943 | 5147 | /* Is it a scroll bar movement? */ |
7b4aedb9 | 5148 | if (frame && ! NILP (bar_window)) |
4bb994d1 | 5149 | { |
9b8eb840 | 5150 | Lisp_Object part_sym; |
4bb994d1 | 5151 | |
9b8eb840 | 5152 | part_sym = *scroll_bar_parts[(int) part]; |
3c370943 | 5153 | return Fcons (Qscroll_bar_movement, |
7b4aedb9 | 5154 | (Fcons (Fcons (bar_window, |
3c370943 | 5155 | Fcons (Qvertical_scroll_bar, |
4bb994d1 JB |
5156 | Fcons (Fcons (x, y), |
5157 | Fcons (make_number (time), | |
cb5df6ae | 5158 | Fcons (part_sym, |
4bb994d1 JB |
5159 | Qnil))))), |
5160 | Qnil))); | |
5161 | } | |
5162 | ||
5163 | /* Or is it an ordinary mouse movement? */ | |
284f4730 JB |
5164 | else |
5165 | { | |
4bb994d1 | 5166 | int area; |
9e20143a | 5167 | Lisp_Object window; |
4bb994d1 | 5168 | Lisp_Object posn; |
9e20143a | 5169 | |
9e20143a | 5170 | if (frame) |
7ee32cda GM |
5171 | /* It's in a frame; which window on that frame? */ |
5172 | window = window_from_coordinates (frame, XINT (x), XINT (y), &area, 0); | |
9e20143a RS |
5173 | else |
5174 | window = Qnil; | |
4bb994d1 | 5175 | |
8c18cbfb | 5176 | if (WINDOWP (window)) |
4bb994d1 | 5177 | { |
7ee32cda | 5178 | struct window *w = XWINDOW (window); |
7ee32cda | 5179 | int wx, wy; |
7ee32cda GM |
5180 | |
5181 | /* Get window relative coordinates. */ | |
5182 | wx = FRAME_TO_WINDOW_PIXEL_X (w, XINT (x)); | |
5183 | wy = FRAME_TO_WINDOW_PIXEL_Y (w, XINT (y)); | |
5184 | XSETINT (x, wx); | |
5185 | XSETINT (y, wy); | |
5186 | ||
4bb994d1 JB |
5187 | if (area == 1) |
5188 | posn = Qmode_line; | |
5189 | else if (area == 2) | |
5190 | posn = Qvertical_line; | |
7ee32cda | 5191 | else if (area == 3) |
045dee35 | 5192 | posn = Qheader_line; |
4bb994d1 | 5193 | else |
7ee32cda | 5194 | XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy)); |
4bb994d1 | 5195 | } |
e9bf89a0 RS |
5196 | else if (frame != 0) |
5197 | { | |
18cd2eeb | 5198 | XSETFRAME (window, frame); |
e9bf89a0 RS |
5199 | posn = Qnil; |
5200 | } | |
284f4730 | 5201 | else |
4bb994d1 JB |
5202 | { |
5203 | window = Qnil; | |
5204 | posn = Qnil; | |
bb9e9bed KH |
5205 | XSETFASTINT (x, 0); |
5206 | XSETFASTINT (y, 0); | |
4bb994d1 | 5207 | } |
284f4730 | 5208 | |
4bb994d1 JB |
5209 | return Fcons (Qmouse_movement, |
5210 | Fcons (Fcons (window, | |
5211 | Fcons (posn, | |
5212 | Fcons (Fcons (x, y), | |
5213 | Fcons (make_number (time), | |
5214 | Qnil)))), | |
5215 | Qnil)); | |
5216 | } | |
284f4730 JB |
5217 | } |
5218 | ||
514354e9 | 5219 | #endif /* HAVE_MOUSE */ |
6cbff1cb | 5220 | |
cd21b839 JB |
5221 | /* Construct a switch frame event. */ |
5222 | static Lisp_Object | |
5223 | make_lispy_switch_frame (frame) | |
5224 | Lisp_Object frame; | |
5225 | { | |
5226 | return Fcons (Qswitch_frame, Fcons (frame, Qnil)); | |
5227 | } | |
0a7f1fc0 JB |
5228 | \f |
5229 | /* Manipulating modifiers. */ | |
284f4730 | 5230 | |
0a7f1fc0 | 5231 | /* Parse the name of SYMBOL, and return the set of modifiers it contains. |
284f4730 | 5232 | |
0a7f1fc0 JB |
5233 | If MODIFIER_END is non-zero, set *MODIFIER_END to the position in |
5234 | SYMBOL's name of the end of the modifiers; the string from this | |
5235 | position is the unmodified symbol name. | |
284f4730 | 5236 | |
0a7f1fc0 | 5237 | This doesn't use any caches. */ |
6da3dd3a | 5238 | |
0a7f1fc0 JB |
5239 | static int |
5240 | parse_modifiers_uncached (symbol, modifier_end) | |
284f4730 | 5241 | Lisp_Object symbol; |
0a7f1fc0 | 5242 | int *modifier_end; |
284f4730 JB |
5243 | { |
5244 | struct Lisp_String *name; | |
5245 | int i; | |
5246 | int modifiers; | |
284f4730 JB |
5247 | |
5248 | CHECK_SYMBOL (symbol, 1); | |
df0f2ba1 | 5249 | |
284f4730 JB |
5250 | modifiers = 0; |
5251 | name = XSYMBOL (symbol)->name; | |
5252 | ||
fc932ac6 | 5253 | for (i = 0; i+2 <= STRING_BYTES (name); ) |
6da3dd3a RS |
5254 | { |
5255 | int this_mod_end = 0; | |
5256 | int this_mod = 0; | |
284f4730 | 5257 | |
6da3dd3a RS |
5258 | /* See if the name continues with a modifier word. |
5259 | Check that the word appears, but don't check what follows it. | |
5260 | Set this_mod and this_mod_end to record what we find. */ | |
fce33686 | 5261 | |
6da3dd3a RS |
5262 | switch (name->data[i]) |
5263 | { | |
5264 | #define SINGLE_LETTER_MOD(BIT) \ | |
5265 | (this_mod_end = i + 1, this_mod = BIT) | |
5266 | ||
6da3dd3a RS |
5267 | case 'A': |
5268 | SINGLE_LETTER_MOD (alt_modifier); | |
5269 | break; | |
284f4730 | 5270 | |
6da3dd3a RS |
5271 | case 'C': |
5272 | SINGLE_LETTER_MOD (ctrl_modifier); | |
5273 | break; | |
284f4730 | 5274 | |
6da3dd3a RS |
5275 | case 'H': |
5276 | SINGLE_LETTER_MOD (hyper_modifier); | |
5277 | break; | |
5278 | ||
6da3dd3a RS |
5279 | case 'M': |
5280 | SINGLE_LETTER_MOD (meta_modifier); | |
5281 | break; | |
5282 | ||
6da3dd3a RS |
5283 | case 'S': |
5284 | SINGLE_LETTER_MOD (shift_modifier); | |
5285 | break; | |
5286 | ||
5287 | case 's': | |
6da3dd3a RS |
5288 | SINGLE_LETTER_MOD (super_modifier); |
5289 | break; | |
5290 | ||
0a7f1fc0 | 5291 | #undef SINGLE_LETTER_MOD |
6da3dd3a RS |
5292 | } |
5293 | ||
5294 | /* If we found no modifier, stop looking for them. */ | |
5295 | if (this_mod_end == 0) | |
5296 | break; | |
5297 | ||
5298 | /* Check there is a dash after the modifier, so that it | |
5299 | really is a modifier. */ | |
fc932ac6 RS |
5300 | if (this_mod_end >= STRING_BYTES (name) |
5301 | || name->data[this_mod_end] != '-') | |
6da3dd3a RS |
5302 | break; |
5303 | ||
5304 | /* This modifier is real; look for another. */ | |
5305 | modifiers |= this_mod; | |
5306 | i = this_mod_end + 1; | |
5307 | } | |
284f4730 | 5308 | |
0a7f1fc0 | 5309 | /* Should we include the `click' modifier? */ |
fbcd35bd JB |
5310 | if (! (modifiers & (down_modifier | drag_modifier |
5311 | | double_modifier | triple_modifier)) | |
fc932ac6 | 5312 | && i + 7 == STRING_BYTES (name) |
4bb994d1 | 5313 | && strncmp (name->data + i, "mouse-", 6) == 0 |
6569cc8d | 5314 | && ('0' <= name->data[i + 6] && name->data[i + 6] <= '9')) |
0a7f1fc0 JB |
5315 | modifiers |= click_modifier; |
5316 | ||
5317 | if (modifier_end) | |
5318 | *modifier_end = i; | |
5319 | ||
5320 | return modifiers; | |
5321 | } | |
5322 | ||
0a7f1fc0 JB |
5323 | /* Return a symbol whose name is the modifier prefixes for MODIFIERS |
5324 | prepended to the string BASE[0..BASE_LEN-1]. | |
5325 | This doesn't use any caches. */ | |
5326 | static Lisp_Object | |
301738ed | 5327 | apply_modifiers_uncached (modifiers, base, base_len, base_len_byte) |
0a7f1fc0 JB |
5328 | int modifiers; |
5329 | char *base; | |
301738ed | 5330 | int base_len, base_len_byte; |
0a7f1fc0 JB |
5331 | { |
5332 | /* Since BASE could contain nulls, we can't use intern here; we have | |
5333 | to use Fintern, which expects a genuine Lisp_String, and keeps a | |
5334 | reference to it. */ | |
301738ed RS |
5335 | char *new_mods |
5336 | = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-")); | |
0a7f1fc0 | 5337 | int mod_len; |
284f4730 | 5338 | |
284f4730 | 5339 | { |
0a7f1fc0 JB |
5340 | char *p = new_mods; |
5341 | ||
5342 | /* Only the event queue may use the `up' modifier; it should always | |
5343 | be turned into a click or drag event before presented to lisp code. */ | |
5344 | if (modifiers & up_modifier) | |
5345 | abort (); | |
5346 | ||
5347 | if (modifiers & alt_modifier) { *p++ = 'A'; *p++ = '-'; } | |
5348 | if (modifiers & ctrl_modifier) { *p++ = 'C'; *p++ = '-'; } | |
5349 | if (modifiers & hyper_modifier) { *p++ = 'H'; *p++ = '-'; } | |
5350 | if (modifiers & meta_modifier) { *p++ = 'M'; *p++ = '-'; } | |
5351 | if (modifiers & shift_modifier) { *p++ = 'S'; *p++ = '-'; } | |
86e5706b | 5352 | if (modifiers & super_modifier) { *p++ = 's'; *p++ = '-'; } |
fbcd35bd JB |
5353 | if (modifiers & double_modifier) { strcpy (p, "double-"); p += 7; } |
5354 | if (modifiers & triple_modifier) { strcpy (p, "triple-"); p += 7; } | |
559f9d04 RS |
5355 | if (modifiers & down_modifier) { strcpy (p, "down-"); p += 5; } |
5356 | if (modifiers & drag_modifier) { strcpy (p, "drag-"); p += 5; } | |
0a7f1fc0 JB |
5357 | /* The click modifier is denoted by the absence of other modifiers. */ |
5358 | ||
5359 | *p = '\0'; | |
5360 | ||
5361 | mod_len = p - new_mods; | |
5362 | } | |
284f4730 | 5363 | |
0a7f1fc0 | 5364 | { |
9b8eb840 | 5365 | Lisp_Object new_name; |
df0f2ba1 | 5366 | |
301738ed RS |
5367 | new_name = make_uninit_multibyte_string (mod_len + base_len, |
5368 | mod_len + base_len_byte); | |
0a7f1fc0 | 5369 | bcopy (new_mods, XSTRING (new_name)->data, mod_len); |
301738ed | 5370 | bcopy (base, XSTRING (new_name)->data + mod_len, base_len_byte); |
284f4730 JB |
5371 | |
5372 | return Fintern (new_name, Qnil); | |
5373 | } | |
5374 | } | |
5375 | ||
5376 | ||
0a7f1fc0 JB |
5377 | static char *modifier_names[] = |
5378 | { | |
fbcd35bd | 5379 | "up", "down", "drag", "click", "double", "triple", 0, 0, |
f335fabe | 5380 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
86e5706b | 5381 | 0, 0, "alt", "super", "hyper", "shift", "control", "meta" |
0a7f1fc0 | 5382 | }; |
80645119 | 5383 | #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0])) |
0a7f1fc0 JB |
5384 | |
5385 | static Lisp_Object modifier_symbols; | |
5386 | ||
5387 | /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */ | |
5388 | static Lisp_Object | |
5389 | lispy_modifier_list (modifiers) | |
5390 | int modifiers; | |
5391 | { | |
5392 | Lisp_Object modifier_list; | |
5393 | int i; | |
5394 | ||
5395 | modifier_list = Qnil; | |
80645119 | 5396 | for (i = 0; (1<<i) <= modifiers && i < NUM_MOD_NAMES; i++) |
0a7f1fc0 | 5397 | if (modifiers & (1<<i)) |
80645119 JB |
5398 | modifier_list = Fcons (XVECTOR (modifier_symbols)->contents[i], |
5399 | modifier_list); | |
0a7f1fc0 JB |
5400 | |
5401 | return modifier_list; | |
5402 | } | |
5403 | ||
5404 | ||
5405 | /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK), | |
5406 | where UNMODIFIED is the unmodified form of SYMBOL, | |
5407 | MASK is the set of modifiers present in SYMBOL's name. | |
5408 | This is similar to parse_modifiers_uncached, but uses the cache in | |
5409 | SYMBOL's Qevent_symbol_element_mask property, and maintains the | |
5410 | Qevent_symbol_elements property. */ | |
3d31316f | 5411 | |
1161d367 | 5412 | Lisp_Object |
0a7f1fc0 JB |
5413 | parse_modifiers (symbol) |
5414 | Lisp_Object symbol; | |
5415 | { | |
9b8eb840 | 5416 | Lisp_Object elements; |
0a7f1fc0 | 5417 | |
9b8eb840 | 5418 | elements = Fget (symbol, Qevent_symbol_element_mask); |
0a7f1fc0 JB |
5419 | if (CONSP (elements)) |
5420 | return elements; | |
5421 | else | |
5422 | { | |
5423 | int end; | |
ec0faad2 | 5424 | int modifiers = parse_modifiers_uncached (symbol, &end); |
9b8eb840 | 5425 | Lisp_Object unmodified; |
0a7f1fc0 JB |
5426 | Lisp_Object mask; |
5427 | ||
9b8eb840 | 5428 | unmodified = Fintern (make_string (XSYMBOL (symbol)->name->data + end, |
fc932ac6 | 5429 | STRING_BYTES (XSYMBOL (symbol)->name) - end), |
9b8eb840 KH |
5430 | Qnil); |
5431 | ||
ec0faad2 | 5432 | if (modifiers & ~(((EMACS_INT)1 << VALBITS) - 1)) |
734fef94 | 5433 | abort (); |
bb9e9bed | 5434 | XSETFASTINT (mask, modifiers); |
0a7f1fc0 JB |
5435 | elements = Fcons (unmodified, Fcons (mask, Qnil)); |
5436 | ||
5437 | /* Cache the parsing results on SYMBOL. */ | |
5438 | Fput (symbol, Qevent_symbol_element_mask, | |
5439 | elements); | |
5440 | Fput (symbol, Qevent_symbol_elements, | |
5441 | Fcons (unmodified, lispy_modifier_list (modifiers))); | |
5442 | ||
5443 | /* Since we know that SYMBOL is modifiers applied to unmodified, | |
5444 | it would be nice to put that in unmodified's cache. | |
5445 | But we can't, since we're not sure that parse_modifiers is | |
5446 | canonical. */ | |
5447 | ||
5448 | return elements; | |
5449 | } | |
5450 | } | |
5451 | ||
5452 | /* Apply the modifiers MODIFIERS to the symbol BASE. | |
5453 | BASE must be unmodified. | |
5454 | ||
5455 | This is like apply_modifiers_uncached, but uses BASE's | |
5456 | Qmodifier_cache property, if present. It also builds | |
cd21b839 JB |
5457 | Qevent_symbol_elements properties, since it has that info anyway. |
5458 | ||
5459 | apply_modifiers copies the value of BASE's Qevent_kind property to | |
5460 | the modified symbol. */ | |
0a7f1fc0 JB |
5461 | static Lisp_Object |
5462 | apply_modifiers (modifiers, base) | |
5463 | int modifiers; | |
5464 | Lisp_Object base; | |
5465 | { | |
7b4aedb9 | 5466 | Lisp_Object cache, index, entry, new_symbol; |
0a7f1fc0 | 5467 | |
80645119 | 5468 | /* Mask out upper bits. We don't know where this value's been. */ |
ec0faad2 | 5469 | modifiers &= ((EMACS_INT)1 << VALBITS) - 1; |
80645119 | 5470 | |
0a7f1fc0 | 5471 | /* The click modifier never figures into cache indices. */ |
0a7f1fc0 | 5472 | cache = Fget (base, Qmodifier_cache); |
bb9e9bed | 5473 | XSETFASTINT (index, (modifiers & ~click_modifier)); |
697e4895 | 5474 | entry = assq_no_quit (index, cache); |
0a7f1fc0 JB |
5475 | |
5476 | if (CONSP (entry)) | |
7539e11f | 5477 | new_symbol = XCDR (entry); |
7b4aedb9 JB |
5478 | else |
5479 | { | |
df0f2ba1 | 5480 | /* We have to create the symbol ourselves. */ |
7b4aedb9 JB |
5481 | new_symbol = apply_modifiers_uncached (modifiers, |
5482 | XSYMBOL (base)->name->data, | |
301738ed | 5483 | XSYMBOL (base)->name->size, |
fc932ac6 | 5484 | STRING_BYTES (XSYMBOL (base)->name)); |
7b4aedb9 JB |
5485 | |
5486 | /* Add the new symbol to the base's cache. */ | |
5487 | entry = Fcons (index, new_symbol); | |
5488 | Fput (base, Qmodifier_cache, Fcons (entry, cache)); | |
5489 | ||
5490 | /* We have the parsing info now for free, so add it to the caches. */ | |
bb9e9bed | 5491 | XSETFASTINT (index, modifiers); |
7b4aedb9 JB |
5492 | Fput (new_symbol, Qevent_symbol_element_mask, |
5493 | Fcons (base, Fcons (index, Qnil))); | |
5494 | Fput (new_symbol, Qevent_symbol_elements, | |
5495 | Fcons (base, lispy_modifier_list (modifiers))); | |
5496 | } | |
0a7f1fc0 | 5497 | |
df0f2ba1 | 5498 | /* Make sure this symbol is of the same kind as BASE. |
7b4aedb9 JB |
5499 | |
5500 | You'd think we could just set this once and for all when we | |
5501 | intern the symbol above, but reorder_modifiers may call us when | |
5502 | BASE's property isn't set right; we can't assume that just | |
80645119 JB |
5503 | because it has a Qmodifier_cache property it must have its |
5504 | Qevent_kind set right as well. */ | |
7b4aedb9 JB |
5505 | if (NILP (Fget (new_symbol, Qevent_kind))) |
5506 | { | |
9b8eb840 | 5507 | Lisp_Object kind; |
7b4aedb9 | 5508 | |
9b8eb840 | 5509 | kind = Fget (base, Qevent_kind); |
7b4aedb9 JB |
5510 | if (! NILP (kind)) |
5511 | Fput (new_symbol, Qevent_kind, kind); | |
5512 | } | |
5513 | ||
5514 | return new_symbol; | |
0a7f1fc0 JB |
5515 | } |
5516 | ||
5517 | ||
5518 | /* Given a symbol whose name begins with modifiers ("C-", "M-", etc), | |
5519 | return a symbol with the modifiers placed in the canonical order. | |
5520 | Canonical order is alphabetical, except for down and drag, which | |
5521 | always come last. The 'click' modifier is never written out. | |
5522 | ||
5523 | Fdefine_key calls this to make sure that (for example) C-M-foo | |
5524 | and M-C-foo end up being equivalent in the keymap. */ | |
5525 | ||
5526 | Lisp_Object | |
5527 | reorder_modifiers (symbol) | |
5528 | Lisp_Object symbol; | |
5529 | { | |
5530 | /* It's hopefully okay to write the code this way, since everything | |
5531 | will soon be in caches, and no consing will be done at all. */ | |
9b8eb840 | 5532 | Lisp_Object parsed; |
0a7f1fc0 | 5533 | |
9b8eb840 | 5534 | parsed = parse_modifiers (symbol); |
7539e11f KR |
5535 | return apply_modifiers ((int) XINT (XCAR (XCDR (parsed))), |
5536 | XCAR (parsed)); | |
0a7f1fc0 JB |
5537 | } |
5538 | ||
5539 | ||
284f4730 JB |
5540 | /* For handling events, we often want to produce a symbol whose name |
5541 | is a series of modifier key prefixes ("M-", "C-", etcetera) attached | |
5542 | to some base, like the name of a function key or mouse button. | |
5543 | modify_event_symbol produces symbols of this sort. | |
5544 | ||
5545 | NAME_TABLE should point to an array of strings, such that NAME_TABLE[i] | |
5546 | is the name of the i'th symbol. TABLE_SIZE is the number of elements | |
5547 | in the table. | |
5548 | ||
8e1e4240 GM |
5549 | Alternatively, NAME_ALIST_OR_STEM is either an alist mapping codes |
5550 | into symbol names, or a string specifying a name stem used to | |
a50e723f | 5551 | construct a symbol name or the form `STEM-N', where N is the decimal |
8e1e4240 GM |
5552 | representation of SYMBOL_NUM. NAME_ALIST_OR_STEM is used if it is |
5553 | non-nil; otherwise NAME_TABLE is used. | |
80e4aa30 | 5554 | |
284f4730 JB |
5555 | SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will |
5556 | persist between calls to modify_event_symbol that it can use to | |
5557 | store a cache of the symbols it's generated for this NAME_TABLE | |
80e4aa30 | 5558 | before. The object stored there may be a vector or an alist. |
284f4730 JB |
5559 | |
5560 | SYMBOL_NUM is the number of the base name we want from NAME_TABLE. | |
df0f2ba1 | 5561 | |
284f4730 JB |
5562 | MODIFIERS is a set of modifier bits (as given in struct input_events) |
5563 | whose prefixes should be applied to the symbol name. | |
5564 | ||
5565 | SYMBOL_KIND is the value to be placed in the event_kind property of | |
df0f2ba1 | 5566 | the returned symbol. |
88cb0656 JB |
5567 | |
5568 | The symbols we create are supposed to have an | |
eb8c3be9 | 5569 | `event-symbol-elements' property, which lists the modifiers present |
88cb0656 JB |
5570 | in the symbol's name. */ |
5571 | ||
284f4730 | 5572 | static Lisp_Object |
8e1e4240 | 5573 | modify_event_symbol (symbol_num, modifiers, symbol_kind, name_alist_or_stem, |
80e4aa30 | 5574 | name_table, symbol_table, table_size) |
284f4730 JB |
5575 | int symbol_num; |
5576 | unsigned modifiers; | |
5577 | Lisp_Object symbol_kind; | |
8e1e4240 | 5578 | Lisp_Object name_alist_or_stem; |
284f4730 JB |
5579 | char **name_table; |
5580 | Lisp_Object *symbol_table; | |
2c834fb3 | 5581 | unsigned int table_size; |
284f4730 | 5582 | { |
80e4aa30 RS |
5583 | Lisp_Object value; |
5584 | Lisp_Object symbol_int; | |
5585 | ||
2c834fb3 KH |
5586 | /* Get rid of the "vendor-specific" bit here. */ |
5587 | XSETINT (symbol_int, symbol_num & 0xffffff); | |
284f4730 JB |
5588 | |
5589 | /* Is this a request for a valid symbol? */ | |
88cb0656 | 5590 | if (symbol_num < 0 || symbol_num >= table_size) |
0c2611c5 | 5591 | return Qnil; |
284f4730 | 5592 | |
80e4aa30 RS |
5593 | if (CONSP (*symbol_table)) |
5594 | value = Fcdr (assq_no_quit (symbol_int, *symbol_table)); | |
5595 | ||
0a7f1fc0 | 5596 | /* If *symbol_table doesn't seem to be initialized properly, fix that. |
88cb0656 | 5597 | *symbol_table should be a lisp vector TABLE_SIZE elements long, |
4bb994d1 JB |
5598 | where the Nth element is the symbol for NAME_TABLE[N], or nil if |
5599 | we've never used that symbol before. */ | |
80e4aa30 | 5600 | else |
88cb0656 | 5601 | { |
80e4aa30 RS |
5602 | if (! VECTORP (*symbol_table) |
5603 | || XVECTOR (*symbol_table)->size != table_size) | |
5604 | { | |
5605 | Lisp_Object size; | |
0a7f1fc0 | 5606 | |
bb9e9bed | 5607 | XSETFASTINT (size, table_size); |
80e4aa30 RS |
5608 | *symbol_table = Fmake_vector (size, Qnil); |
5609 | } | |
284f4730 | 5610 | |
80e4aa30 RS |
5611 | value = XVECTOR (*symbol_table)->contents[symbol_num]; |
5612 | } | |
284f4730 | 5613 | |
0a7f1fc0 | 5614 | /* Have we already used this symbol before? */ |
80e4aa30 | 5615 | if (NILP (value)) |
284f4730 | 5616 | { |
0a7f1fc0 | 5617 | /* No; let's create it. */ |
8e1e4240 GM |
5618 | if (CONSP (name_alist_or_stem)) |
5619 | value = Fcdr_safe (Fassq (symbol_int, name_alist_or_stem)); | |
5620 | else if (STRINGP (name_alist_or_stem)) | |
5621 | { | |
5622 | int len = STRING_BYTES (XSTRING (name_alist_or_stem)); | |
5623 | char *buf = (char *) alloca (len + 50); | |
5624 | sprintf (buf, "%s-%d", XSTRING (name_alist_or_stem)->data, | |
5625 | XINT (symbol_int) + 1); | |
5626 | value = intern (buf); | |
5627 | } | |
2ff6714d | 5628 | else if (name_table != 0 && name_table[symbol_num]) |
80e4aa30 | 5629 | value = intern (name_table[symbol_num]); |
b64b4075 | 5630 | |
e98a93eb | 5631 | #ifdef HAVE_WINDOW_SYSTEM |
2c834fb3 KH |
5632 | if (NILP (value)) |
5633 | { | |
5634 | char *name = x_get_keysym_name (symbol_num); | |
5635 | if (name) | |
5636 | value = intern (name); | |
5637 | } | |
5638 | #endif | |
5639 | ||
b64b4075 | 5640 | if (NILP (value)) |
d1f50460 RS |
5641 | { |
5642 | char buf[20]; | |
5643 | sprintf (buf, "key-%d", symbol_num); | |
80e4aa30 | 5644 | value = intern (buf); |
d1f50460 | 5645 | } |
0a7f1fc0 | 5646 | |
80e4aa30 | 5647 | if (CONSP (*symbol_table)) |
4205cb08 | 5648 | *symbol_table = Fcons (Fcons (symbol_int, value), *symbol_table); |
80e4aa30 RS |
5649 | else |
5650 | XVECTOR (*symbol_table)->contents[symbol_num] = value; | |
5651 | ||
df0f2ba1 | 5652 | /* Fill in the cache entries for this symbol; this also |
0a7f1fc0 JB |
5653 | builds the Qevent_symbol_elements property, which the user |
5654 | cares about. */ | |
80e4aa30 RS |
5655 | apply_modifiers (modifiers & click_modifier, value); |
5656 | Fput (value, Qevent_kind, symbol_kind); | |
284f4730 | 5657 | } |
88cb0656 | 5658 | |
0a7f1fc0 | 5659 | /* Apply modifiers to that symbol. */ |
80e4aa30 | 5660 | return apply_modifiers (modifiers, value); |
284f4730 | 5661 | } |
6da3dd3a RS |
5662 | \f |
5663 | /* Convert a list that represents an event type, | |
5664 | such as (ctrl meta backspace), into the usual representation of that | |
5665 | event type as a number or a symbol. */ | |
5666 | ||
a1706c30 | 5667 | DEFUN ("event-convert-list", Fevent_convert_list, Sevent_convert_list, 1, 1, 0, |
e57d8fd8 EN |
5668 | "Convert the event description list EVENT-DESC to an event type.\n\ |
5669 | EVENT-DESC should contain one base event type (a character or symbol)\n\ | |
a1706c30 | 5670 | and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\ |
377f24f5 | 5671 | drag, down, double or triple). The base must be last.\n\ |
a1706c30 KH |
5672 | The return value is an event type (a character or symbol) which\n\ |
5673 | has the same base event type and all the specified modifiers.") | |
e57d8fd8 EN |
5674 | (event_desc) |
5675 | Lisp_Object event_desc; | |
6da3dd3a RS |
5676 | { |
5677 | Lisp_Object base; | |
5678 | int modifiers = 0; | |
5679 | Lisp_Object rest; | |
5680 | ||
5681 | base = Qnil; | |
e57d8fd8 | 5682 | rest = event_desc; |
6da3dd3a RS |
5683 | while (CONSP (rest)) |
5684 | { | |
5685 | Lisp_Object elt; | |
5686 | int this = 0; | |
5687 | ||
7539e11f KR |
5688 | elt = XCAR (rest); |
5689 | rest = XCDR (rest); | |
6da3dd3a | 5690 | |
3d31316f | 5691 | /* Given a symbol, see if it is a modifier name. */ |
377f24f5 | 5692 | if (SYMBOLP (elt) && CONSP (rest)) |
3d31316f | 5693 | this = parse_solitary_modifier (elt); |
6da3dd3a RS |
5694 | |
5695 | if (this != 0) | |
5696 | modifiers |= this; | |
5697 | else if (!NILP (base)) | |
5698 | error ("Two bases given in one event"); | |
5699 | else | |
5700 | base = elt; | |
5701 | ||
6da3dd3a RS |
5702 | } |
5703 | ||
3d31316f RS |
5704 | /* Let the symbol A refer to the character A. */ |
5705 | if (SYMBOLP (base) && XSYMBOL (base)->name->size == 1) | |
5706 | XSETINT (base, XSYMBOL (base)->name->data[0]); | |
5707 | ||
6da3dd3a RS |
5708 | if (INTEGERP (base)) |
5709 | { | |
3d31316f RS |
5710 | /* Turn (shift a) into A. */ |
5711 | if ((modifiers & shift_modifier) != 0 | |
5712 | && (XINT (base) >= 'a' && XINT (base) <= 'z')) | |
5713 | { | |
5714 | XSETINT (base, XINT (base) - ('a' - 'A')); | |
5715 | modifiers &= ~shift_modifier; | |
5716 | } | |
5717 | ||
5718 | /* Turn (control a) into C-a. */ | |
6da3dd3a | 5719 | if (modifiers & ctrl_modifier) |
3d31316f | 5720 | return make_number ((modifiers & ~ctrl_modifier) |
6da3dd3a RS |
5721 | | make_ctrl_char (XINT (base))); |
5722 | else | |
5723 | return make_number (modifiers | XINT (base)); | |
5724 | } | |
5725 | else if (SYMBOLP (base)) | |
5726 | return apply_modifiers (modifiers, base); | |
5727 | else | |
8c907a56 GM |
5728 | { |
5729 | error ("Invalid base event"); | |
5730 | return Qnil; | |
5731 | } | |
6da3dd3a RS |
5732 | } |
5733 | ||
3d31316f RS |
5734 | /* Try to recognize SYMBOL as a modifier name. |
5735 | Return the modifier flag bit, or 0 if not recognized. */ | |
5736 | ||
5737 | static int | |
5738 | parse_solitary_modifier (symbol) | |
5739 | Lisp_Object symbol; | |
5740 | { | |
5741 | struct Lisp_String *name = XSYMBOL (symbol)->name; | |
5742 | ||
5743 | switch (name->data[0]) | |
5744 | { | |
5745 | #define SINGLE_LETTER_MOD(BIT) \ | |
fc932ac6 | 5746 | if (STRING_BYTES (name) == 1) \ |
3d31316f RS |
5747 | return BIT; |
5748 | ||
5749 | #define MULTI_LETTER_MOD(BIT, NAME, LEN) \ | |
fc932ac6 | 5750 | if (LEN == STRING_BYTES (name) \ |
3d31316f RS |
5751 | && ! strncmp (name->data, NAME, LEN)) \ |
5752 | return BIT; | |
5753 | ||
5754 | case 'A': | |
5755 | SINGLE_LETTER_MOD (alt_modifier); | |
5756 | break; | |
5757 | ||
5758 | case 'a': | |
5759 | MULTI_LETTER_MOD (alt_modifier, "alt", 3); | |
5760 | break; | |
5761 | ||
5762 | case 'C': | |
5763 | SINGLE_LETTER_MOD (ctrl_modifier); | |
5764 | break; | |
5765 | ||
5766 | case 'c': | |
5767 | MULTI_LETTER_MOD (ctrl_modifier, "ctrl", 4); | |
5768 | MULTI_LETTER_MOD (ctrl_modifier, "control", 7); | |
5769 | break; | |
5770 | ||
5771 | case 'H': | |
5772 | SINGLE_LETTER_MOD (hyper_modifier); | |
5773 | break; | |
5774 | ||
5775 | case 'h': | |
5776 | MULTI_LETTER_MOD (hyper_modifier, "hyper", 5); | |
5777 | break; | |
5778 | ||
5779 | case 'M': | |
5780 | SINGLE_LETTER_MOD (meta_modifier); | |
5781 | break; | |
5782 | ||
5783 | case 'm': | |
5784 | MULTI_LETTER_MOD (meta_modifier, "meta", 4); | |
5785 | break; | |
5786 | ||
5787 | case 'S': | |
5788 | SINGLE_LETTER_MOD (shift_modifier); | |
5789 | break; | |
5790 | ||
5791 | case 's': | |
5792 | MULTI_LETTER_MOD (shift_modifier, "shift", 5); | |
5793 | MULTI_LETTER_MOD (super_modifier, "super", 5); | |
5794 | SINGLE_LETTER_MOD (super_modifier); | |
5795 | break; | |
5796 | ||
5797 | case 'd': | |
5798 | MULTI_LETTER_MOD (drag_modifier, "drag", 4); | |
5799 | MULTI_LETTER_MOD (down_modifier, "down", 4); | |
5800 | MULTI_LETTER_MOD (double_modifier, "double", 6); | |
5801 | break; | |
5802 | ||
5803 | case 't': | |
5804 | MULTI_LETTER_MOD (triple_modifier, "triple", 6); | |
5805 | break; | |
5806 | ||
5807 | #undef SINGLE_LETTER_MOD | |
5808 | #undef MULTI_LETTER_MOD | |
5809 | } | |
5810 | ||
5811 | return 0; | |
5812 | } | |
5813 | ||
6da3dd3a RS |
5814 | /* Return 1 if EVENT is a list whose elements are all integers or symbols. |
5815 | Such a list is not valid as an event, | |
5816 | but it can be a Lucid-style event type list. */ | |
5817 | ||
5818 | int | |
5819 | lucid_event_type_list_p (object) | |
5820 | Lisp_Object object; | |
5821 | { | |
5822 | Lisp_Object tail; | |
5823 | ||
5824 | if (! CONSP (object)) | |
5825 | return 0; | |
5826 | ||
7539e11f | 5827 | for (tail = object; CONSP (tail); tail = XCDR (tail)) |
6da3dd3a RS |
5828 | { |
5829 | Lisp_Object elt; | |
7539e11f | 5830 | elt = XCAR (tail); |
6da3dd3a RS |
5831 | if (! (INTEGERP (elt) || SYMBOLP (elt))) |
5832 | return 0; | |
5833 | } | |
5834 | ||
5835 | return NILP (tail); | |
5836 | } | |
284f4730 | 5837 | \f |
284f4730 JB |
5838 | /* Store into *addr a value nonzero if terminal input chars are available. |
5839 | Serves the purpose of ioctl (0, FIONREAD, addr) | |
5840 | but works even if FIONREAD does not exist. | |
d9d4c147 KH |
5841 | (In fact, this may actually read some input.) |
5842 | ||
5843 | If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */ | |
284f4730 JB |
5844 | |
5845 | static void | |
d9d4c147 | 5846 | get_input_pending (addr, do_timers_now) |
284f4730 | 5847 | int *addr; |
d9d4c147 | 5848 | int do_timers_now; |
284f4730 JB |
5849 | { |
5850 | /* First of all, have we already counted some input? */ | |
d9d4c147 | 5851 | *addr = !NILP (Vquit_flag) || readable_events (do_timers_now); |
284f4730 JB |
5852 | |
5853 | /* If input is being read as it arrives, and we have none, there is none. */ | |
5854 | if (*addr > 0 || (interrupt_input && ! interrupts_deferred)) | |
5855 | return; | |
5856 | ||
5857 | /* Try to read some input and see how much we get. */ | |
5858 | gobble_input (0); | |
d9d4c147 | 5859 | *addr = !NILP (Vquit_flag) || readable_events (do_timers_now); |
284f4730 JB |
5860 | } |
5861 | ||
81931ba1 | 5862 | /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */ |
284f4730 | 5863 | |
07a59269 | 5864 | void |
284f4730 JB |
5865 | gobble_input (expected) |
5866 | int expected; | |
5867 | { | |
5868 | #ifndef VMS | |
5869 | #ifdef SIGIO | |
5870 | if (interrupt_input) | |
5871 | { | |
32676c08 | 5872 | SIGMASKTYPE mask; |
4f8aaa74 | 5873 | mask = sigblock (sigmask (SIGIO)); |
284f4730 | 5874 | read_avail_input (expected); |
e065a56e | 5875 | sigsetmask (mask); |
284f4730 JB |
5876 | } |
5877 | else | |
81931ba1 RS |
5878 | #ifdef POLL_FOR_INPUT |
5879 | if (read_socket_hook && !interrupt_input && poll_suppress_count == 0) | |
5880 | { | |
5881 | SIGMASKTYPE mask; | |
4f8aaa74 | 5882 | mask = sigblock (sigmask (SIGALRM)); |
81931ba1 RS |
5883 | read_avail_input (expected); |
5884 | sigsetmask (mask); | |
5885 | } | |
5886 | else | |
87485d6f | 5887 | #endif |
284f4730 JB |
5888 | #endif |
5889 | read_avail_input (expected); | |
5890 | #endif | |
5891 | } | |
a8015ab5 | 5892 | |
241ceaf7 RS |
5893 | /* Put a buffer_switch_event in the buffer |
5894 | so that read_key_sequence will notice the new current buffer. */ | |
5895 | ||
07a59269 | 5896 | void |
a8015ab5 KH |
5897 | record_asynch_buffer_change () |
5898 | { | |
5899 | struct input_event event; | |
a30f0615 RS |
5900 | Lisp_Object tem; |
5901 | ||
a8015ab5 KH |
5902 | event.kind = buffer_switch_event; |
5903 | event.frame_or_window = Qnil; | |
da8f7368 | 5904 | event.arg = Qnil; |
241ceaf7 | 5905 | |
f65e6f7d | 5906 | #ifdef subprocesses |
a30f0615 RS |
5907 | /* We don't need a buffer-switch event unless Emacs is waiting for input. |
5908 | The purpose of the event is to make read_key_sequence look up the | |
5909 | keymaps again. If we aren't in read_key_sequence, we don't need one, | |
5910 | and the event could cause trouble by messing up (input-pending-p). */ | |
5911 | tem = Fwaiting_for_user_input_p (); | |
5912 | if (NILP (tem)) | |
5913 | return; | |
f65e6f7d RS |
5914 | #else |
5915 | /* We never need these events if we have no asynchronous subprocesses. */ | |
5916 | return; | |
5917 | #endif | |
a30f0615 | 5918 | |
241ceaf7 RS |
5919 | /* Make sure no interrupt happens while storing the event. */ |
5920 | #ifdef SIGIO | |
5921 | if (interrupt_input) | |
5922 | { | |
5923 | SIGMASKTYPE mask; | |
4f8aaa74 | 5924 | mask = sigblock (sigmask (SIGIO)); |
241ceaf7 RS |
5925 | kbd_buffer_store_event (&event); |
5926 | sigsetmask (mask); | |
5927 | } | |
5928 | else | |
5929 | #endif | |
5930 | { | |
5931 | stop_polling (); | |
5932 | kbd_buffer_store_event (&event); | |
5933 | start_polling (); | |
5934 | } | |
a8015ab5 | 5935 | } |
284f4730 JB |
5936 | \f |
5937 | #ifndef VMS | |
5938 | ||
5939 | /* Read any terminal input already buffered up by the system | |
5940 | into the kbd_buffer, but do not wait. | |
5941 | ||
5942 | EXPECTED should be nonzero if the caller knows there is some input. | |
5943 | ||
5944 | Except on VMS, all input is read by this function. | |
5945 | If interrupt_input is nonzero, this function MUST be called | |
5946 | only when SIGIO is blocked. | |
5947 | ||
5948 | Returns the number of keyboard chars read, or -1 meaning | |
5949 | this is a bad time to try to read input. */ | |
5950 | ||
5951 | static int | |
5952 | read_avail_input (expected) | |
5953 | int expected; | |
5954 | { | |
5955 | struct input_event buf[KBD_BUFFER_SIZE]; | |
5956 | register int i; | |
5957 | int nread; | |
5958 | ||
5959 | if (read_socket_hook) | |
5960 | /* No need for FIONREAD or fcntl; just say don't wait. */ | |
33e19c6e | 5961 | nread = (*read_socket_hook) (input_fd, buf, KBD_BUFFER_SIZE, expected); |
284f4730 JB |
5962 | else |
5963 | { | |
17270835 RS |
5964 | /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than |
5965 | the kbd_buffer can really hold. That may prevent loss | |
5966 | of characters on some systems when input is stuffed at us. */ | |
5967 | unsigned char cbuf[KBD_BUFFER_SIZE - 1]; | |
58788063 | 5968 | int n_to_read; |
284f4730 | 5969 | |
58788063 | 5970 | /* Determine how many characters we should *try* to read. */ |
bc536d84 RS |
5971 | #ifdef WINDOWSNT |
5972 | return 0; | |
5973 | #else /* not WINDOWSNT */ | |
80e4aa30 | 5974 | #ifdef MSDOS |
58788063 RS |
5975 | n_to_read = dos_keysns (); |
5976 | if (n_to_read == 0) | |
5977 | return 0; | |
c3a2738c | 5978 | #else /* not MSDOS */ |
284f4730 JB |
5979 | #ifdef FIONREAD |
5980 | /* Find out how much input is available. */ | |
437f6112 | 5981 | if (ioctl (input_fd, FIONREAD, &n_to_read) < 0) |
284f4730 JB |
5982 | /* Formerly simply reported no input, but that sometimes led to |
5983 | a failure of Emacs to terminate. | |
5984 | SIGHUP seems appropriate if we can't reach the terminal. */ | |
e4535288 RS |
5985 | /* ??? Is it really right to send the signal just to this process |
5986 | rather than to the whole process group? | |
5987 | Perhaps on systems with FIONREAD Emacs is alone in its group. */ | |
284f4730 | 5988 | kill (getpid (), SIGHUP); |
58788063 | 5989 | if (n_to_read == 0) |
284f4730 | 5990 | return 0; |
58788063 RS |
5991 | if (n_to_read > sizeof cbuf) |
5992 | n_to_read = sizeof cbuf; | |
284f4730 | 5993 | #else /* no FIONREAD */ |
0c04a67e | 5994 | #if defined (USG) || defined (DGUX) |
284f4730 | 5995 | /* Read some input if available, but don't wait. */ |
58788063 | 5996 | n_to_read = sizeof cbuf; |
437f6112 | 5997 | fcntl (input_fd, F_SETFL, O_NDELAY); |
284f4730 JB |
5998 | #else |
5999 | you lose; | |
6000 | #endif | |
6001 | #endif | |
80e4aa30 | 6002 | #endif /* not MSDOS */ |
bc536d84 | 6003 | #endif /* not WINDOWSNT */ |
284f4730 | 6004 | |
58788063 RS |
6005 | /* Now read; for one reason or another, this will not block. |
6006 | NREAD is set to the number of chars read. */ | |
9134775b | 6007 | do |
284f4730 | 6008 | { |
80e4aa30 | 6009 | #ifdef MSDOS |
0c04a67e | 6010 | cbuf[0] = dos_keyread (); |
80e4aa30 RS |
6011 | nread = 1; |
6012 | #else | |
68c45bf0 | 6013 | nread = emacs_read (input_fd, cbuf, n_to_read); |
80e4aa30 | 6014 | #endif |
49854566 RS |
6015 | /* POSIX infers that processes which are not in the session leader's |
6016 | process group won't get SIGHUP's at logout time. BSDI adheres to | |
e8886a1d | 6017 | this part standard and returns -1 from read (0) with errno==EIO |
49854566 RS |
6018 | when the control tty is taken away. |
6019 | Jeffrey Honig <jch@bsdi.com> says this is generally safe. */ | |
6020 | if (nread == -1 && errno == EIO) | |
6021 | kill (0, SIGHUP); | |
762f2b92 | 6022 | #if defined (AIX) && (! defined (aix386) && defined (_BSD)) |
284f4730 JB |
6023 | /* The kernel sometimes fails to deliver SIGHUP for ptys. |
6024 | This looks incorrect, but it isn't, because _BSD causes | |
6025 | O_NDELAY to be defined in fcntl.h as O_NONBLOCK, | |
6026 | and that causes a value other than 0 when there is no input. */ | |
854f3a54 | 6027 | if (nread == 0) |
80e4aa30 | 6028 | kill (0, SIGHUP); |
284f4730 | 6029 | #endif |
9134775b | 6030 | } |
791587ee KH |
6031 | while ( |
6032 | /* We used to retry the read if it was interrupted. | |
6033 | But this does the wrong thing when O_NDELAY causes | |
6034 | an EAGAIN error. Does anybody know of a situation | |
6035 | where a retry is actually needed? */ | |
6036 | #if 0 | |
6037 | nread < 0 && (errno == EAGAIN | |
6aec06f5 | 6038 | #ifdef EFAULT |
9134775b | 6039 | || errno == EFAULT |
80e4aa30 | 6040 | #endif |
284f4730 | 6041 | #ifdef EBADSLT |
9134775b | 6042 | || errno == EBADSLT |
284f4730 | 6043 | #endif |
791587ee KH |
6044 | ) |
6045 | #else | |
6046 | 0 | |
6047 | #endif | |
6048 | ); | |
284f4730 JB |
6049 | |
6050 | #ifndef FIONREAD | |
02c2c53f | 6051 | #if defined (USG) || defined (DGUX) |
437f6112 | 6052 | fcntl (input_fd, F_SETFL, 0); |
02c2c53f | 6053 | #endif /* USG or DGUX */ |
284f4730 JB |
6054 | #endif /* no FIONREAD */ |
6055 | for (i = 0; i < nread; i++) | |
6056 | { | |
6057 | buf[i].kind = ascii_keystroke; | |
86e5706b | 6058 | buf[i].modifiers = 0; |
b04904fb | 6059 | if (meta_key == 1 && (cbuf[i] & 0x80)) |
86e5706b | 6060 | buf[i].modifiers = meta_modifier; |
b04904fb RS |
6061 | if (meta_key != 2) |
6062 | cbuf[i] &= ~0x80; | |
f3e59d5e KH |
6063 | |
6064 | buf[i].code = cbuf[i]; | |
788f89eb | 6065 | buf[i].frame_or_window = selected_frame; |
da8f7368 | 6066 | buf[i].arg = Qnil; |
284f4730 JB |
6067 | } |
6068 | } | |
6069 | ||
6070 | /* Scan the chars for C-g and store them in kbd_buffer. */ | |
6071 | for (i = 0; i < nread; i++) | |
6072 | { | |
6073 | kbd_buffer_store_event (&buf[i]); | |
6074 | /* Don't look at input that follows a C-g too closely. | |
6075 | This reduces lossage due to autorepeat on C-g. */ | |
6076 | if (buf[i].kind == ascii_keystroke | |
9343ab07 | 6077 | && buf[i].code == quit_char) |
284f4730 JB |
6078 | break; |
6079 | } | |
6080 | ||
6081 | return nread; | |
6082 | } | |
6083 | #endif /* not VMS */ | |
6084 | \f | |
6085 | #ifdef SIGIO /* for entire page */ | |
6086 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
6087 | ||
2ce30ea2 | 6088 | SIGTYPE |
284f4730 JB |
6089 | input_available_signal (signo) |
6090 | int signo; | |
6091 | { | |
6092 | /* Must preserve main program's value of errno. */ | |
6093 | int old_errno = errno; | |
6094 | #ifdef BSD4_1 | |
6095 | extern int select_alarmed; | |
6096 | #endif | |
6097 | ||
5970a8cb | 6098 | #if defined (USG) && !defined (POSIX_SIGNALS) |
284f4730 JB |
6099 | /* USG systems forget handlers when they are used; |
6100 | must reestablish each time */ | |
6101 | signal (signo, input_available_signal); | |
6102 | #endif /* USG */ | |
6103 | ||
6104 | #ifdef BSD4_1 | |
6105 | sigisheld (SIGIO); | |
6106 | #endif | |
6107 | ||
ffd56f97 JB |
6108 | if (input_available_clear_time) |
6109 | EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); | |
284f4730 JB |
6110 | |
6111 | while (1) | |
6112 | { | |
6113 | int nread; | |
6114 | nread = read_avail_input (1); | |
6115 | /* -1 means it's not ok to read the input now. | |
6116 | UNBLOCK_INPUT will read it later; now, avoid infinite loop. | |
6117 | 0 means there was no keyboard input available. */ | |
6118 | if (nread <= 0) | |
6119 | break; | |
6120 | ||
6121 | #ifdef BSD4_1 | |
6122 | select_alarmed = 1; /* Force the select emulator back to life */ | |
6123 | #endif | |
6124 | } | |
6125 | ||
6126 | #ifdef BSD4_1 | |
6127 | sigfree (); | |
6128 | #endif | |
6129 | errno = old_errno; | |
6130 | } | |
6131 | #endif /* SIGIO */ | |
ad163903 JB |
6132 | |
6133 | /* Send ourselves a SIGIO. | |
6134 | ||
6135 | This function exists so that the UNBLOCK_INPUT macro in | |
6136 | blockinput.h can have some way to take care of input we put off | |
6137 | dealing with, without assuming that every file which uses | |
6138 | UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */ | |
6139 | void | |
6140 | reinvoke_input_signal () | |
6141 | { | |
df0f2ba1 | 6142 | #ifdef SIGIO |
87dd9b9b | 6143 | kill (getpid (), SIGIO); |
ad163903 JB |
6144 | #endif |
6145 | } | |
6146 | ||
6147 | ||
284f4730 JB |
6148 | \f |
6149 | /* Return the prompt-string of a sparse keymap. | |
6150 | This is the first element which is a string. | |
6151 | Return nil if there is none. */ | |
6152 | ||
6153 | Lisp_Object | |
6154 | map_prompt (map) | |
6155 | Lisp_Object map; | |
6156 | { | |
6157 | while (CONSP (map)) | |
6158 | { | |
6159 | register Lisp_Object tem; | |
6160 | tem = Fcar (map); | |
8c18cbfb | 6161 | if (STRINGP (tem)) |
284f4730 JB |
6162 | return tem; |
6163 | map = Fcdr (map); | |
6164 | } | |
6165 | return Qnil; | |
6166 | } | |
6167 | ||
25126faa GM |
6168 | static void menu_bar_item P_ ((Lisp_Object, Lisp_Object)); |
6169 | static void menu_bar_one_keymap P_ ((Lisp_Object)); | |
b7c49376 RS |
6170 | |
6171 | /* These variables hold the vector under construction within | |
6172 | menu_bar_items and its subroutines, and the current index | |
6173 | for storing into that vector. */ | |
6174 | static Lisp_Object menu_bar_items_vector; | |
9343ab07 | 6175 | static int menu_bar_items_index; |
5ec75a55 | 6176 | |
b7c49376 RS |
6177 | /* Return a vector of menu items for a menu bar, appropriate |
6178 | to the current buffer. Each item has three elements in the vector: | |
f5e09c8b | 6179 | KEY STRING MAPLIST. |
b7c49376 RS |
6180 | |
6181 | OLD is an old vector we can optionally reuse, or nil. */ | |
5ec75a55 RS |
6182 | |
6183 | Lisp_Object | |
b7c49376 RS |
6184 | menu_bar_items (old) |
6185 | Lisp_Object old; | |
5ec75a55 RS |
6186 | { |
6187 | /* The number of keymaps we're scanning right now, and the number of | |
6188 | keymaps we have allocated space for. */ | |
6189 | int nmaps; | |
6190 | ||
6191 | /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] | |
6192 | in the current keymaps, or nil where it is not a prefix. */ | |
6193 | Lisp_Object *maps; | |
6194 | ||
9f9c0e27 | 6195 | Lisp_Object def, tem, tail; |
5ec75a55 RS |
6196 | |
6197 | Lisp_Object result; | |
6198 | ||
6199 | int mapno; | |
47d319aa | 6200 | Lisp_Object oquit; |
5ec75a55 | 6201 | |
b7c49376 RS |
6202 | int i; |
6203 | ||
6204 | struct gcpro gcpro1; | |
6205 | ||
db60d856 JB |
6206 | /* In order to build the menus, we need to call the keymap |
6207 | accessors. They all call QUIT. But this function is called | |
6208 | during redisplay, during which a quit is fatal. So inhibit | |
47d319aa RS |
6209 | quitting while building the menus. |
6210 | We do this instead of specbind because (1) errors will clear it anyway | |
6211 | and (2) this avoids risk of specpdl overflow. */ | |
6212 | oquit = Vinhibit_quit; | |
df0f2ba1 | 6213 | Vinhibit_quit = Qt; |
db60d856 | 6214 | |
b7c49376 RS |
6215 | if (!NILP (old)) |
6216 | menu_bar_items_vector = old; | |
6217 | else | |
6218 | menu_bar_items_vector = Fmake_vector (make_number (24), Qnil); | |
6219 | menu_bar_items_index = 0; | |
6220 | ||
6221 | GCPRO1 (menu_bar_items_vector); | |
6222 | ||
5ec75a55 RS |
6223 | /* Build our list of keymaps. |
6224 | If we recognize a function key and replace its escape sequence in | |
6225 | keybuf with its symbol, or if the sequence starts with a mouse | |
6226 | click and we need to switch buffers, we jump back here to rebuild | |
6227 | the initial keymaps from the current buffer. */ | |
df0f2ba1 | 6228 | { |
5ec75a55 RS |
6229 | Lisp_Object *tmaps; |
6230 | ||
217258d5 | 6231 | /* Should overriding-terminal-local-map and overriding-local-map apply? */ |
d0a49716 | 6232 | if (!NILP (Voverriding_local_map_menu_flag)) |
9dd3131c | 6233 | { |
217258d5 KH |
6234 | /* Yes, use them (if non-nil) as well as the global map. */ |
6235 | maps = (Lisp_Object *) alloca (3 * sizeof (maps[0])); | |
6236 | nmaps = 0; | |
6237 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
6238 | maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
6239 | if (!NILP (Voverriding_local_map)) | |
6240 | maps[nmaps++] = Voverriding_local_map; | |
9dd3131c RS |
6241 | } |
6242 | else | |
6243 | { | |
30690496 DL |
6244 | /* No, so use major and minor mode keymaps and keymap property. */ |
6245 | int extra_maps = 2; | |
6246 | Lisp_Object map = get_local_map (PT, current_buffer, keymap); | |
6247 | if (!NILP (map)) | |
6248 | extra_maps = 3; | |
217258d5 | 6249 | nmaps = current_minor_maps (NULL, &tmaps); |
30690496 DL |
6250 | maps = (Lisp_Object *) alloca ((nmaps + extra_maps) |
6251 | * sizeof (maps[0])); | |
217258d5 | 6252 | bcopy (tmaps, maps, nmaps * sizeof (maps[0])); |
30690496 | 6253 | if (!NILP (map)) |
9f83cf0b | 6254 | maps[nmaps++] = map; |
30690496 | 6255 | maps[nmaps++] = get_local_map (PT, current_buffer, local_map); |
9dd3131c | 6256 | } |
217258d5 | 6257 | maps[nmaps++] = current_global_map; |
5ec75a55 RS |
6258 | } |
6259 | ||
6260 | /* Look up in each map the dummy prefix key `menu-bar'. */ | |
6261 | ||
6262 | result = Qnil; | |
6263 | ||
e58aa385 | 6264 | for (mapno = nmaps - 1; mapno >= 0; mapno--) |
25126faa GM |
6265 | if (!NILP (maps[mapno])) |
6266 | { | |
02067692 SM |
6267 | def = get_keymap (access_keymap (maps[mapno], Qmenu_bar, 1, 0, 0), |
6268 | 0, 0); | |
6269 | if (CONSP (def)) | |
25126faa GM |
6270 | menu_bar_one_keymap (def); |
6271 | } | |
5ec75a55 | 6272 | |
b7c49376 RS |
6273 | /* Move to the end those items that should be at the end. */ |
6274 | ||
7539e11f | 6275 | for (tail = Vmenu_bar_final_items; CONSP (tail); tail = XCDR (tail)) |
9f9c0e27 | 6276 | { |
b7c49376 RS |
6277 | int i; |
6278 | int end = menu_bar_items_index; | |
6279 | ||
35b3402f | 6280 | for (i = 0; i < end; i += 4) |
7539e11f | 6281 | if (EQ (XCAR (tail), XVECTOR (menu_bar_items_vector)->contents[i])) |
b7c49376 | 6282 | { |
35b3402f | 6283 | Lisp_Object tem0, tem1, tem2, tem3; |
0301268e RS |
6284 | /* Move the item at index I to the end, |
6285 | shifting all the others forward. */ | |
6286 | tem0 = XVECTOR (menu_bar_items_vector)->contents[i + 0]; | |
6287 | tem1 = XVECTOR (menu_bar_items_vector)->contents[i + 1]; | |
6288 | tem2 = XVECTOR (menu_bar_items_vector)->contents[i + 2]; | |
35b3402f RS |
6289 | tem3 = XVECTOR (menu_bar_items_vector)->contents[i + 3]; |
6290 | if (end > i + 4) | |
6291 | bcopy (&XVECTOR (menu_bar_items_vector)->contents[i + 4], | |
0301268e | 6292 | &XVECTOR (menu_bar_items_vector)->contents[i], |
35b3402f RS |
6293 | (end - i - 4) * sizeof (Lisp_Object)); |
6294 | XVECTOR (menu_bar_items_vector)->contents[end - 4] = tem0; | |
6295 | XVECTOR (menu_bar_items_vector)->contents[end - 3] = tem1; | |
6296 | XVECTOR (menu_bar_items_vector)->contents[end - 2] = tem2; | |
6297 | XVECTOR (menu_bar_items_vector)->contents[end - 1] = tem3; | |
0301268e | 6298 | break; |
b7c49376 RS |
6299 | } |
6300 | } | |
9f9c0e27 | 6301 | |
0c9071cd | 6302 | /* Add nil, nil, nil, nil at the end. */ |
b7c49376 | 6303 | i = menu_bar_items_index; |
35b3402f | 6304 | if (i + 4 > XVECTOR (menu_bar_items_vector)->size) |
b7c49376 RS |
6305 | { |
6306 | Lisp_Object tem; | |
b7c49376 RS |
6307 | tem = Fmake_vector (make_number (2 * i), Qnil); |
6308 | bcopy (XVECTOR (menu_bar_items_vector)->contents, | |
6309 | XVECTOR (tem)->contents, i * sizeof (Lisp_Object)); | |
6310 | menu_bar_items_vector = tem; | |
9f9c0e27 | 6311 | } |
b7c49376 RS |
6312 | /* Add this item. */ |
6313 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
6314 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
6315 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
35b3402f | 6316 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; |
b7c49376 | 6317 | menu_bar_items_index = i; |
a73c5e29 | 6318 | |
47d319aa | 6319 | Vinhibit_quit = oquit; |
b7c49376 RS |
6320 | UNGCPRO; |
6321 | return menu_bar_items_vector; | |
5ec75a55 RS |
6322 | } |
6323 | \f | |
6324 | /* Scan one map KEYMAP, accumulating any menu items it defines | |
f5e09c8b | 6325 | in menu_bar_items_vector. */ |
5ec75a55 | 6326 | |
759860a6 RS |
6327 | static Lisp_Object menu_bar_one_keymap_changed_items; |
6328 | ||
b7c49376 RS |
6329 | static void |
6330 | menu_bar_one_keymap (keymap) | |
6331 | Lisp_Object keymap; | |
5ec75a55 | 6332 | { |
03cee6ae | 6333 | Lisp_Object tail, item; |
5ec75a55 | 6334 | |
759860a6 RS |
6335 | menu_bar_one_keymap_changed_items = Qnil; |
6336 | ||
5ec75a55 | 6337 | /* Loop over all keymap entries that have menu strings. */ |
7539e11f | 6338 | for (tail = keymap; CONSP (tail); tail = XCDR (tail)) |
5ec75a55 | 6339 | { |
7539e11f | 6340 | item = XCAR (tail); |
8c18cbfb | 6341 | if (CONSP (item)) |
7539e11f | 6342 | menu_bar_item (XCAR (item), XCDR (item)); |
8c18cbfb | 6343 | else if (VECTORP (item)) |
5ec75a55 RS |
6344 | { |
6345 | /* Loop over the char values represented in the vector. */ | |
6346 | int len = XVECTOR (item)->size; | |
6347 | int c; | |
6348 | for (c = 0; c < len; c++) | |
6349 | { | |
6350 | Lisp_Object character; | |
bb9e9bed | 6351 | XSETFASTINT (character, c); |
e8886a1d | 6352 | menu_bar_item (character, XVECTOR (item)->contents[c]); |
5ec75a55 RS |
6353 | } |
6354 | } | |
6355 | } | |
5ec75a55 RS |
6356 | } |
6357 | ||
f5e09c8b RS |
6358 | /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF. |
6359 | If there's already an item for KEY, add this DEF to it. */ | |
6360 | ||
e8886a1d RS |
6361 | Lisp_Object item_properties; |
6362 | ||
b7c49376 | 6363 | static void |
e8886a1d RS |
6364 | menu_bar_item (key, item) |
6365 | Lisp_Object key, item; | |
5ec75a55 | 6366 | { |
e8886a1d | 6367 | struct gcpro gcpro1; |
b7c49376 | 6368 | int i; |
759860a6 | 6369 | Lisp_Object tem; |
5ec75a55 | 6370 | |
e8886a1d | 6371 | if (EQ (item, Qundefined)) |
e58aa385 | 6372 | { |
f5e09c8b | 6373 | /* If a map has an explicit `undefined' as definition, |
e58aa385 | 6374 | discard any previously made menu bar item. */ |
b7c49376 | 6375 | |
35b3402f | 6376 | for (i = 0; i < menu_bar_items_index; i += 4) |
b7c49376 RS |
6377 | if (EQ (key, XVECTOR (menu_bar_items_vector)->contents[i])) |
6378 | { | |
35b3402f RS |
6379 | if (menu_bar_items_index > i + 4) |
6380 | bcopy (&XVECTOR (menu_bar_items_vector)->contents[i + 4], | |
b7c49376 | 6381 | &XVECTOR (menu_bar_items_vector)->contents[i], |
35b3402f RS |
6382 | (menu_bar_items_index - i - 4) * sizeof (Lisp_Object)); |
6383 | menu_bar_items_index -= 4; | |
b7c49376 | 6384 | } |
e58aa385 RS |
6385 | } |
6386 | ||
759860a6 RS |
6387 | /* If this keymap has already contributed to this KEY, |
6388 | don't contribute to it a second time. */ | |
6389 | tem = Fmemq (key, menu_bar_one_keymap_changed_items); | |
9cd2ced7 | 6390 | if (!NILP (tem) || NILP (item)) |
759860a6 RS |
6391 | return; |
6392 | ||
6393 | menu_bar_one_keymap_changed_items | |
6394 | = Fcons (key, menu_bar_one_keymap_changed_items); | |
6395 | ||
9cd2ced7 SM |
6396 | /* We add to menu_bar_one_keymap_changed_items before doing the |
6397 | parse_menu_item, so that if it turns out it wasn't a menu item, | |
6398 | it still correctly hides any further menu item. */ | |
6399 | GCPRO1 (key); | |
6400 | i = parse_menu_item (item, 0, 1); | |
6401 | UNGCPRO; | |
6402 | if (!i) | |
6403 | return; | |
6404 | ||
e8886a1d RS |
6405 | item = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF]; |
6406 | ||
f5e09c8b | 6407 | /* Find any existing item for this KEY. */ |
35b3402f | 6408 | for (i = 0; i < menu_bar_items_index; i += 4) |
b7c49376 RS |
6409 | if (EQ (key, XVECTOR (menu_bar_items_vector)->contents[i])) |
6410 | break; | |
6411 | ||
f5e09c8b | 6412 | /* If we did not find this KEY, add it at the end. */ |
b7c49376 RS |
6413 | if (i == menu_bar_items_index) |
6414 | { | |
6415 | /* If vector is too small, get a bigger one. */ | |
35b3402f | 6416 | if (i + 4 > XVECTOR (menu_bar_items_vector)->size) |
b7c49376 RS |
6417 | { |
6418 | Lisp_Object tem; | |
b7c49376 RS |
6419 | tem = Fmake_vector (make_number (2 * i), Qnil); |
6420 | bcopy (XVECTOR (menu_bar_items_vector)->contents, | |
6421 | XVECTOR (tem)->contents, i * sizeof (Lisp_Object)); | |
6422 | menu_bar_items_vector = tem; | |
6423 | } | |
e8886a1d | 6424 | |
b7c49376 RS |
6425 | /* Add this item. */ |
6426 | XVECTOR (menu_bar_items_vector)->contents[i++] = key; | |
e8886a1d RS |
6427 | XVECTOR (menu_bar_items_vector)->contents[i++] |
6428 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; | |
6429 | XVECTOR (menu_bar_items_vector)->contents[i++] = Fcons (item, Qnil); | |
35b3402f | 6430 | XVECTOR (menu_bar_items_vector)->contents[i++] = make_number (0); |
b7c49376 RS |
6431 | menu_bar_items_index = i; |
6432 | } | |
e8886a1d | 6433 | /* We did find an item for this KEY. Add ITEM to its list of maps. */ |
f5e09c8b RS |
6434 | else |
6435 | { | |
6436 | Lisp_Object old; | |
6437 | old = XVECTOR (menu_bar_items_vector)->contents[i + 2]; | |
e8886a1d | 6438 | XVECTOR (menu_bar_items_vector)->contents[i + 2] = Fcons (item, old); |
f5e09c8b | 6439 | } |
5ec75a55 RS |
6440 | } |
6441 | \f | |
e8886a1d RS |
6442 | /* This is used as the handler when calling menu_item_eval_property. */ |
6443 | static Lisp_Object | |
6444 | menu_item_eval_property_1 (arg) | |
6445 | Lisp_Object arg; | |
6446 | { | |
6447 | /* If we got a quit from within the menu computation, | |
6448 | quit all the way out of it. This takes care of C-] in the debugger. */ | |
7539e11f | 6449 | if (CONSP (arg) && EQ (XCAR (arg), Qquit)) |
e8886a1d RS |
6450 | Fsignal (Qquit, Qnil); |
6451 | ||
6452 | return Qnil; | |
6453 | } | |
6454 | ||
6455 | /* Evaluate an expression and return the result (or nil if something | |
6456 | went wrong). Used to evaluate dynamic parts of menu items. */ | |
7ee32cda | 6457 | Lisp_Object |
e8886a1d RS |
6458 | menu_item_eval_property (sexpr) |
6459 | Lisp_Object sexpr; | |
6460 | { | |
44e553a3 | 6461 | int count = specpdl_ptr - specpdl; |
e8886a1d | 6462 | Lisp_Object val; |
44e553a3 | 6463 | specbind (Qinhibit_redisplay, Qt); |
e8886a1d RS |
6464 | val = internal_condition_case_1 (Feval, sexpr, Qerror, |
6465 | menu_item_eval_property_1); | |
44e553a3 | 6466 | return unbind_to (count, val); |
e8886a1d RS |
6467 | } |
6468 | ||
6469 | /* This function parses a menu item and leaves the result in the | |
6470 | vector item_properties. | |
6471 | ITEM is a key binding, a possible menu item. | |
6472 | If NOTREAL is nonzero, only check for equivalent key bindings, don't | |
6473 | evaluate dynamic expressions in the menu item. | |
fd3613d7 | 6474 | INMENUBAR is > 0 when this is considered for an entry in a menu bar |
e8886a1d | 6475 | top level. |
fd3613d7 | 6476 | INMENUBAR is < 0 when this is considered for an entry in a keyboard menu. |
e8886a1d RS |
6477 | parse_menu_item returns true if the item is a menu item and false |
6478 | otherwise. */ | |
6479 | ||
6480 | int | |
6481 | parse_menu_item (item, notreal, inmenubar) | |
6482 | Lisp_Object item; | |
6483 | int notreal, inmenubar; | |
6484 | { | |
adc1d5c8 | 6485 | Lisp_Object def, tem, item_string, start; |
07ba902e RS |
6486 | Lisp_Object cachelist; |
6487 | Lisp_Object filter; | |
6488 | Lisp_Object keyhint; | |
e8886a1d | 6489 | int i; |
74c1de23 RS |
6490 | int newcache = 0; |
6491 | ||
07ba902e RS |
6492 | cachelist = Qnil; |
6493 | filter = Qnil; | |
6494 | keyhint = Qnil; | |
6495 | ||
e8886a1d RS |
6496 | if (!CONSP (item)) |
6497 | return 0; | |
6498 | ||
e8886a1d RS |
6499 | /* Create item_properties vector if necessary. */ |
6500 | if (NILP (item_properties)) | |
6501 | item_properties | |
6502 | = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE + 1), Qnil); | |
6503 | ||
6504 | /* Initialize optional entries. */ | |
6505 | for (i = ITEM_PROPERTY_DEF; i < ITEM_PROPERTY_ENABLE; i++) | |
3626fb1a GM |
6506 | AREF (item_properties, i) = Qnil; |
6507 | AREF (item_properties, ITEM_PROPERTY_ENABLE) = Qt; | |
e8886a1d RS |
6508 | |
6509 | /* Save the item here to protect it from GC. */ | |
3626fb1a | 6510 | AREF (item_properties, ITEM_PROPERTY_ITEM) = item; |
e8886a1d | 6511 | |
7539e11f | 6512 | item_string = XCAR (item); |
e8886a1d RS |
6513 | |
6514 | start = item; | |
7539e11f | 6515 | item = XCDR (item); |
e8886a1d RS |
6516 | if (STRINGP (item_string)) |
6517 | { | |
6518 | /* Old format menu item. */ | |
3626fb1a | 6519 | AREF (item_properties, ITEM_PROPERTY_NAME) = item_string; |
e8886a1d RS |
6520 | |
6521 | /* Maybe help string. */ | |
7539e11f | 6522 | if (CONSP (item) && STRINGP (XCAR (item))) |
e8886a1d | 6523 | { |
3626fb1a | 6524 | AREF (item_properties, ITEM_PROPERTY_HELP) = XCAR (item); |
e8886a1d | 6525 | start = item; |
7539e11f | 6526 | item = XCDR (item); |
e8886a1d RS |
6527 | } |
6528 | ||
31f84d03 | 6529 | /* Maybe key binding cache. */ |
7539e11f KR |
6530 | if (CONSP (item) && CONSP (XCAR (item)) |
6531 | && (NILP (XCAR (XCAR (item))) | |
6532 | || VECTORP (XCAR (XCAR (item))))) | |
e8886a1d | 6533 | { |
7539e11f KR |
6534 | cachelist = XCAR (item); |
6535 | item = XCDR (item); | |
e8886a1d RS |
6536 | } |
6537 | ||
6538 | /* This is the real definition--the function to run. */ | |
3626fb1a | 6539 | AREF (item_properties, ITEM_PROPERTY_DEF) = item; |
e8886a1d RS |
6540 | |
6541 | /* Get enable property, if any. */ | |
6542 | if (SYMBOLP (item)) | |
6543 | { | |
6544 | tem = Fget (item, Qmenu_enable); | |
6545 | if (!NILP (tem)) | |
3626fb1a | 6546 | AREF (item_properties, ITEM_PROPERTY_ENABLE) = tem; |
e8886a1d RS |
6547 | } |
6548 | } | |
6549 | else if (EQ (item_string, Qmenu_item) && CONSP (item)) | |
6550 | { | |
6551 | /* New format menu item. */ | |
3626fb1a | 6552 | AREF (item_properties, ITEM_PROPERTY_NAME) = XCAR (item); |
7539e11f | 6553 | start = XCDR (item); |
e8886a1d RS |
6554 | if (CONSP (start)) |
6555 | { | |
6556 | /* We have a real binding. */ | |
3626fb1a | 6557 | AREF (item_properties, ITEM_PROPERTY_DEF) = XCAR (start); |
e8886a1d | 6558 | |
7539e11f | 6559 | item = XCDR (start); |
e8886a1d | 6560 | /* Is there a cache list with key equivalences. */ |
7539e11f | 6561 | if (CONSP (item) && CONSP (XCAR (item))) |
e8886a1d | 6562 | { |
7539e11f KR |
6563 | cachelist = XCAR (item); |
6564 | item = XCDR (item); | |
e8886a1d RS |
6565 | } |
6566 | ||
6567 | /* Parse properties. */ | |
7539e11f | 6568 | while (CONSP (item) && CONSP (XCDR (item))) |
e8886a1d | 6569 | { |
7539e11f KR |
6570 | tem = XCAR (item); |
6571 | item = XCDR (item); | |
e8886a1d RS |
6572 | |
6573 | if (EQ (tem, QCenable)) | |
3626fb1a | 6574 | AREF (item_properties, ITEM_PROPERTY_ENABLE) = XCAR (item); |
e8886a1d RS |
6575 | else if (EQ (tem, QCvisible) && !notreal) |
6576 | { | |
6577 | /* If got a visible property and that evaluates to nil | |
6578 | then ignore this item. */ | |
7539e11f | 6579 | tem = menu_item_eval_property (XCAR (item)); |
e8886a1d | 6580 | if (NILP (tem)) |
adc1d5c8 | 6581 | return 0; |
e8886a1d RS |
6582 | } |
6583 | else if (EQ (tem, QChelp)) | |
3626fb1a | 6584 | AREF (item_properties, ITEM_PROPERTY_HELP) = XCAR (item); |
e8886a1d | 6585 | else if (EQ (tem, QCfilter)) |
74c1de23 RS |
6586 | filter = item; |
6587 | else if (EQ (tem, QCkey_sequence)) | |
6588 | { | |
7539e11f | 6589 | tem = XCAR (item); |
74c1de23 RS |
6590 | if (NILP (cachelist) |
6591 | && (SYMBOLP (tem) || STRINGP (tem) || VECTORP (tem))) | |
6592 | /* Be GC protected. Set keyhint to item instead of tem. */ | |
6593 | keyhint = item; | |
6594 | } | |
6595 | else if (EQ (tem, QCkeys)) | |
6596 | { | |
7539e11f | 6597 | tem = XCAR (item); |
03cee6ae | 6598 | if (CONSP (tem) || (STRINGP (tem) && NILP (cachelist))) |
3626fb1a | 6599 | AREF (item_properties, ITEM_PROPERTY_KEYEQ) = tem; |
74c1de23 | 6600 | } |
7539e11f | 6601 | else if (EQ (tem, QCbutton) && CONSP (XCAR (item))) |
e8886a1d | 6602 | { |
74c1de23 | 6603 | Lisp_Object type; |
7539e11f KR |
6604 | tem = XCAR (item); |
6605 | type = XCAR (tem); | |
e8886a1d RS |
6606 | if (EQ (type, QCtoggle) || EQ (type, QCradio)) |
6607 | { | |
3626fb1a | 6608 | AREF (item_properties, ITEM_PROPERTY_SELECTED) |
7539e11f | 6609 | = XCDR (tem); |
3626fb1a | 6610 | AREF (item_properties, ITEM_PROPERTY_TYPE) |
e8886a1d RS |
6611 | = type; |
6612 | } | |
6613 | } | |
7539e11f | 6614 | item = XCDR (item); |
e8886a1d RS |
6615 | } |
6616 | } | |
6617 | else if (inmenubar || !NILP (start)) | |
adc1d5c8 | 6618 | return 0; |
e8886a1d RS |
6619 | } |
6620 | else | |
adc1d5c8 | 6621 | return 0; /* not a menu item */ |
e8886a1d RS |
6622 | |
6623 | /* If item string is not a string, evaluate it to get string. | |
6624 | If we don't get a string, skip this item. */ | |
3626fb1a | 6625 | item_string = AREF (item_properties, ITEM_PROPERTY_NAME); |
e8886a1d RS |
6626 | if (!(STRINGP (item_string) || notreal)) |
6627 | { | |
6628 | item_string = menu_item_eval_property (item_string); | |
6629 | if (!STRINGP (item_string)) | |
adc1d5c8 | 6630 | return 0; |
3626fb1a | 6631 | AREF (item_properties, ITEM_PROPERTY_NAME) = item_string; |
e8886a1d RS |
6632 | } |
6633 | ||
6634 | /* If got a filter apply it on definition. */ | |
3626fb1a | 6635 | def = AREF (item_properties, ITEM_PROPERTY_DEF); |
e8886a1d RS |
6636 | if (!NILP (filter)) |
6637 | { | |
7539e11f | 6638 | def = menu_item_eval_property (list2 (XCAR (filter), |
c5c5a6f8 RS |
6639 | list2 (Qquote, def))); |
6640 | ||
3626fb1a | 6641 | AREF (item_properties, ITEM_PROPERTY_DEF) = def; |
e8886a1d RS |
6642 | } |
6643 | ||
6644 | /* If we got no definition, this item is just unselectable text which | |
74c1de23 | 6645 | is OK in a submenu but not in the menubar. */ |
e8886a1d | 6646 | if (NILP (def)) |
adc1d5c8 | 6647 | return (inmenubar ? 0 : 1); |
e8886a1d RS |
6648 | |
6649 | /* Enable or disable selection of item. */ | |
3626fb1a | 6650 | tem = AREF (item_properties, ITEM_PROPERTY_ENABLE); |
e8886a1d RS |
6651 | if (!EQ (tem, Qt)) |
6652 | { | |
6653 | if (notreal) | |
6654 | tem = Qt; | |
6655 | else | |
6656 | tem = menu_item_eval_property (tem); | |
6657 | if (inmenubar && NILP (tem)) | |
adc1d5c8 | 6658 | return 0; /* Ignore disabled items in menu bar. */ |
3626fb1a | 6659 | AREF (item_properties, ITEM_PROPERTY_ENABLE) = tem; |
e8886a1d RS |
6660 | } |
6661 | ||
6662 | /* See if this is a separate pane or a submenu. */ | |
3626fb1a | 6663 | def = AREF (item_properties, ITEM_PROPERTY_DEF); |
02067692 | 6664 | tem = get_keymap (def, 0, 1); |
9ac425d1 | 6665 | /* For a subkeymap, just record its details and exit. */ |
02067692 | 6666 | if (CONSP (tem)) |
e8886a1d | 6667 | { |
3626fb1a GM |
6668 | AREF (item_properties, ITEM_PROPERTY_MAP) = tem; |
6669 | AREF (item_properties, ITEM_PROPERTY_DEF) = tem; | |
e8886a1d RS |
6670 | return 1; |
6671 | } | |
3626fb1a | 6672 | |
9ac425d1 RS |
6673 | /* At the top level in the menu bar, do likewise for commands also. |
6674 | The menu bar does not display equivalent key bindings anyway. | |
6675 | ITEM_PROPERTY_DEF is already set up properly. */ | |
6676 | if (inmenubar > 0) | |
6677 | return 1; | |
e8886a1d RS |
6678 | |
6679 | /* This is a command. See if there is an equivalent key binding. */ | |
6680 | if (NILP (cachelist)) | |
6681 | { | |
74c1de23 | 6682 | /* We have to create a cachelist. */ |
e8886a1d | 6683 | CHECK_IMPURE (start); |
7539e11f KR |
6684 | XCDR (start) = Fcons (Fcons (Qnil, Qnil), XCDR (start)); |
6685 | cachelist = XCAR (XCDR (start)); | |
74c1de23 | 6686 | newcache = 1; |
3626fb1a | 6687 | tem = AREF (item_properties, ITEM_PROPERTY_KEYEQ); |
74c1de23 RS |
6688 | if (!NILP (keyhint)) |
6689 | { | |
7539e11f | 6690 | XCAR (cachelist) = XCAR (keyhint); |
74c1de23 RS |
6691 | newcache = 0; |
6692 | } | |
6693 | else if (STRINGP (tem)) | |
6694 | { | |
7539e11f KR |
6695 | XCDR (cachelist) = Fsubstitute_command_keys (tem); |
6696 | XCAR (cachelist) = Qt; | |
74c1de23 RS |
6697 | } |
6698 | } | |
3626fb1a | 6699 | |
7539e11f | 6700 | tem = XCAR (cachelist); |
74c1de23 RS |
6701 | if (!EQ (tem, Qt)) |
6702 | { | |
6703 | int chkcache = 0; | |
6704 | Lisp_Object prefix; | |
6705 | ||
6706 | if (!NILP (tem)) | |
6707 | tem = Fkey_binding (tem, Qnil); | |
6708 | ||
3626fb1a | 6709 | prefix = AREF (item_properties, ITEM_PROPERTY_KEYEQ); |
74c1de23 RS |
6710 | if (CONSP (prefix)) |
6711 | { | |
7539e11f KR |
6712 | def = XCAR (prefix); |
6713 | prefix = XCDR (prefix); | |
74c1de23 | 6714 | } |
e8886a1d | 6715 | else |
3626fb1a | 6716 | def = AREF (item_properties, ITEM_PROPERTY_DEF); |
74c1de23 | 6717 | |
3626fb1a GM |
6718 | if (!update_menu_bindings) |
6719 | chkcache = 0; | |
6720 | else if (NILP (XCAR (cachelist))) /* Have no saved key. */ | |
74c1de23 RS |
6721 | { |
6722 | if (newcache /* Always check first time. */ | |
6723 | /* Should we check everything when precomputing key | |
6724 | bindings? */ | |
74c1de23 RS |
6725 | /* If something had no key binding before, don't recheck it |
6726 | because that is too slow--except if we have a list of | |
6727 | rebound commands in Vdefine_key_rebound_commands, do | |
6728 | recheck any command that appears in that list. */ | |
6729 | || (CONSP (Vdefine_key_rebound_commands) | |
6730 | && !NILP (Fmemq (def, Vdefine_key_rebound_commands)))) | |
6731 | chkcache = 1; | |
6732 | } | |
6733 | /* We had a saved key. Is it still bound to the command? */ | |
6734 | else if (NILP (tem) | |
03cee6ae GM |
6735 | || (!EQ (tem, def) |
6736 | /* If the command is an alias for another | |
6737 | (such as lmenu.el set it up), check if the | |
6738 | original command matches the cached command. */ | |
6739 | && !(SYMBOLP (def) && EQ (tem, XSYMBOL (def)->function)))) | |
74c1de23 RS |
6740 | chkcache = 1; /* Need to recompute key binding. */ |
6741 | ||
6742 | if (chkcache) | |
6743 | { | |
6744 | /* Recompute equivalent key binding. If the command is an alias | |
6745 | for another (such as lmenu.el set it up), see if the original | |
6746 | command name has equivalent keys. Otherwise look up the | |
6747 | specified command itself. We don't try both, because that | |
6748 | makes lmenu menus slow. */ | |
3626fb1a GM |
6749 | if (SYMBOLP (def) |
6750 | && SYMBOLP (XSYMBOL (def)->function) | |
74c1de23 RS |
6751 | && ! NILP (Fget (def, Qmenu_alias))) |
6752 | def = XSYMBOL (def)->function; | |
6753 | tem = Fwhere_is_internal (def, Qnil, Qt, Qnil); | |
7539e11f | 6754 | XCAR (cachelist) = tem; |
74c1de23 RS |
6755 | if (NILP (tem)) |
6756 | { | |
7539e11f | 6757 | XCDR (cachelist) = Qnil; |
74c1de23 RS |
6758 | chkcache = 0; |
6759 | } | |
6760 | } | |
7539e11f | 6761 | else if (!NILP (keyhint) && !NILP (XCAR (cachelist))) |
74c1de23 | 6762 | { |
7539e11f | 6763 | tem = XCAR (cachelist); |
74c1de23 RS |
6764 | chkcache = 1; |
6765 | } | |
6766 | ||
6767 | newcache = chkcache; | |
6768 | if (chkcache) | |
6769 | { | |
6770 | tem = Fkey_description (tem); | |
6771 | if (CONSP (prefix)) | |
6772 | { | |
7539e11f KR |
6773 | if (STRINGP (XCAR (prefix))) |
6774 | tem = concat2 (XCAR (prefix), tem); | |
6775 | if (STRINGP (XCDR (prefix))) | |
6776 | tem = concat2 (tem, XCDR (prefix)); | |
74c1de23 | 6777 | } |
7539e11f | 6778 | XCDR (cachelist) = tem; |
74c1de23 RS |
6779 | } |
6780 | } | |
6781 | ||
7539e11f | 6782 | tem = XCDR (cachelist); |
74c1de23 | 6783 | if (newcache && !NILP (tem)) |
e8886a1d | 6784 | { |
74c1de23 | 6785 | tem = concat3 (build_string (" ("), tem, build_string (")")); |
7539e11f | 6786 | XCDR (cachelist) = tem; |
e8886a1d RS |
6787 | } |
6788 | ||
6789 | /* If we only want to precompute equivalent key bindings, stop here. */ | |
6790 | if (notreal) | |
adc1d5c8 | 6791 | return 1; |
e8886a1d RS |
6792 | |
6793 | /* If we have an equivalent key binding, use that. */ | |
3626fb1a | 6794 | AREF (item_properties, ITEM_PROPERTY_KEYEQ) = tem; |
adc1d5c8 RS |
6795 | |
6796 | /* Include this when menu help is implemented. | |
6797 | tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP]; | |
6798 | if (!(NILP (tem) || STRINGP (tem))) | |
6799 | { | |
6800 | tem = menu_item_eval_property (tem); | |
6801 | if (!STRINGP (tem)) | |
6802 | tem = Qnil; | |
6803 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem; | |
6804 | } | |
e8886a1d RS |
6805 | */ |
6806 | ||
6807 | /* Handle radio buttons or toggle boxes. */ | |
3626fb1a | 6808 | tem = AREF (item_properties, ITEM_PROPERTY_SELECTED); |
e8886a1d | 6809 | if (!NILP (tem)) |
3626fb1a | 6810 | AREF (item_properties, ITEM_PROPERTY_SELECTED) |
e8886a1d RS |
6811 | = menu_item_eval_property (tem); |
6812 | ||
e8886a1d RS |
6813 | return 1; |
6814 | } | |
7ee32cda GM |
6815 | |
6816 | ||
6817 | \f | |
6818 | /*********************************************************************** | |
6819 | Tool-bars | |
6820 | ***********************************************************************/ | |
6821 | ||
9ea173e8 GM |
6822 | /* A vector holding tool bar items while they are parsed in function |
6823 | tool_bar_items runs Each item occupies TOOL_BAR_ITEM_NSCLOTS elements | |
6824 | in the vector. */ | |
7ee32cda | 6825 | |
9ea173e8 | 6826 | static Lisp_Object tool_bar_items_vector; |
7ee32cda | 6827 | |
9ea173e8 GM |
6828 | /* A vector holding the result of parse_tool_bar_item. Layout is like |
6829 | the one for a single item in tool_bar_items_vector. */ | |
7ee32cda | 6830 | |
9ea173e8 | 6831 | static Lisp_Object tool_bar_item_properties; |
7ee32cda | 6832 | |
9ea173e8 | 6833 | /* Next free index in tool_bar_items_vector. */ |
7ee32cda | 6834 | |
9ea173e8 | 6835 | static int ntool_bar_items; |
7ee32cda | 6836 | |
9ea173e8 | 6837 | /* The symbols `tool-bar', and `:image'. */ |
7ee32cda | 6838 | |
9ea173e8 | 6839 | extern Lisp_Object Qtool_bar; |
7ee32cda GM |
6840 | Lisp_Object QCimage; |
6841 | ||
6842 | /* Function prototypes. */ | |
6843 | ||
9ea173e8 GM |
6844 | static void init_tool_bar_items P_ ((Lisp_Object)); |
6845 | static void process_tool_bar_item P_ ((Lisp_Object, Lisp_Object)); | |
6846 | static int parse_tool_bar_item P_ ((Lisp_Object, Lisp_Object)); | |
6847 | static void append_tool_bar_item P_ ((void)); | |
7ee32cda GM |
6848 | |
6849 | ||
9ea173e8 | 6850 | /* Return a vector of tool bar items for keymaps currently in effect. |
7ee32cda | 6851 | Reuse vector REUSE if non-nil. Return in *NITEMS the number of |
9ea173e8 | 6852 | tool bar items found. */ |
7ee32cda GM |
6853 | |
6854 | Lisp_Object | |
9ea173e8 | 6855 | tool_bar_items (reuse, nitems) |
7ee32cda GM |
6856 | Lisp_Object reuse; |
6857 | int *nitems; | |
6858 | { | |
6859 | Lisp_Object *maps; | |
6860 | int nmaps, i; | |
6861 | Lisp_Object oquit; | |
6862 | Lisp_Object *tmaps; | |
6863 | extern Lisp_Object Voverriding_local_map_menu_flag; | |
6864 | extern Lisp_Object Voverriding_local_map; | |
6865 | ||
6866 | *nitems = 0; | |
6867 | ||
6868 | /* In order to build the menus, we need to call the keymap | |
6869 | accessors. They all call QUIT. But this function is called | |
6870 | during redisplay, during which a quit is fatal. So inhibit | |
6871 | quitting while building the menus. We do this instead of | |
6872 | specbind because (1) errors will clear it anyway and (2) this | |
6873 | avoids risk of specpdl overflow. */ | |
6874 | oquit = Vinhibit_quit; | |
6875 | Vinhibit_quit = Qt; | |
6876 | ||
9ea173e8 GM |
6877 | /* Initialize tool_bar_items_vector and protect it from GC. */ |
6878 | init_tool_bar_items (reuse); | |
7ee32cda GM |
6879 | |
6880 | /* Build list of keymaps in maps. Set nmaps to the number of maps | |
6881 | to process. */ | |
6882 | ||
6883 | /* Should overriding-terminal-local-map and overriding-local-map apply? */ | |
6884 | if (!NILP (Voverriding_local_map_menu_flag)) | |
6885 | { | |
6886 | /* Yes, use them (if non-nil) as well as the global map. */ | |
6887 | maps = (Lisp_Object *) alloca (3 * sizeof (maps[0])); | |
6888 | nmaps = 0; | |
6889 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
6890 | maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
6891 | if (!NILP (Voverriding_local_map)) | |
6892 | maps[nmaps++] = Voverriding_local_map; | |
6893 | } | |
6894 | else | |
6895 | { | |
30690496 DL |
6896 | /* No, so use major and minor mode keymaps and keymap property. */ |
6897 | int extra_maps = 2; | |
6898 | Lisp_Object map = get_local_map (PT, current_buffer, keymap); | |
6899 | if (!NILP (map)) | |
6900 | extra_maps = 3; | |
7ee32cda | 6901 | nmaps = current_minor_maps (NULL, &tmaps); |
30690496 DL |
6902 | maps = (Lisp_Object *) alloca ((nmaps + extra_maps) |
6903 | * sizeof (maps[0])); | |
7ee32cda | 6904 | bcopy (tmaps, maps, nmaps * sizeof (maps[0])); |
30690496 | 6905 | if (!NILP (map)) |
9f83cf0b | 6906 | maps[nmaps++] = map; |
30690496 | 6907 | maps[nmaps++] = get_local_map (PT, current_buffer, local_map); |
7ee32cda GM |
6908 | } |
6909 | ||
6910 | /* Add global keymap at the end. */ | |
6911 | maps[nmaps++] = current_global_map; | |
6912 | ||
6913 | /* Process maps in reverse order and look up in each map the prefix | |
9ea173e8 | 6914 | key `tool-bar'. */ |
7ee32cda GM |
6915 | for (i = nmaps - 1; i >= 0; --i) |
6916 | if (!NILP (maps[i])) | |
6917 | { | |
6918 | Lisp_Object keymap; | |
db785038 SM |
6919 | |
6920 | /* Why set the `noinherit' flag ? -sm */ | |
02067692 SM |
6921 | keymap = get_keymap (access_keymap (maps[i], Qtool_bar, 1, 1, 0), 0, 0); |
6922 | if (CONSP (keymap)) | |
7ee32cda GM |
6923 | { |
6924 | Lisp_Object tail; | |
6925 | ||
6926 | /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */ | |
7539e11f | 6927 | for (tail = keymap; CONSP (tail); tail = XCDR (tail)) |
7ee32cda GM |
6928 | { |
6929 | Lisp_Object keydef = XCAR (tail); | |
6930 | if (CONSP (keydef)) | |
9ea173e8 | 6931 | process_tool_bar_item (XCAR (keydef), XCDR (keydef)); |
7ee32cda GM |
6932 | } |
6933 | } | |
6934 | } | |
6935 | ||
6936 | Vinhibit_quit = oquit; | |
9ea173e8 GM |
6937 | *nitems = ntool_bar_items / TOOL_BAR_ITEM_NSLOTS; |
6938 | return tool_bar_items_vector; | |
7ee32cda GM |
6939 | } |
6940 | ||
6941 | ||
6942 | /* Process the definition of KEY which is DEF. */ | |
6943 | ||
6944 | static void | |
9ea173e8 | 6945 | process_tool_bar_item (key, def) |
7ee32cda GM |
6946 | Lisp_Object key, def; |
6947 | { | |
6948 | int i; | |
6949 | extern Lisp_Object Qundefined; | |
6950 | struct gcpro gcpro1, gcpro2; | |
6951 | ||
9ea173e8 | 6952 | /* Protect KEY and DEF from GC because parse_tool_bar_item may call |
7ee32cda GM |
6953 | eval. */ |
6954 | GCPRO2 (key, def); | |
6955 | ||
6956 | if (EQ (def, Qundefined)) | |
6957 | { | |
6958 | /* If a map has an explicit `undefined' as definition, | |
6959 | discard any previously made item. */ | |
9ea173e8 | 6960 | for (i = 0; i < ntool_bar_items; i += TOOL_BAR_ITEM_NSLOTS) |
7ee32cda | 6961 | { |
9ea173e8 | 6962 | Lisp_Object *v = XVECTOR (tool_bar_items_vector)->contents + i; |
7ee32cda | 6963 | |
9ea173e8 | 6964 | if (EQ (key, v[TOOL_BAR_ITEM_KEY])) |
7ee32cda | 6965 | { |
9ea173e8 GM |
6966 | if (ntool_bar_items > i + TOOL_BAR_ITEM_NSLOTS) |
6967 | bcopy (v + TOOL_BAR_ITEM_NSLOTS, v, | |
6968 | ((ntool_bar_items - i - TOOL_BAR_ITEM_NSLOTS) | |
7ee32cda | 6969 | * sizeof (Lisp_Object))); |
9ea173e8 | 6970 | ntool_bar_items -= TOOL_BAR_ITEM_NSLOTS; |
7ee32cda GM |
6971 | break; |
6972 | } | |
6973 | } | |
6974 | } | |
9ea173e8 GM |
6975 | else if (parse_tool_bar_item (key, def)) |
6976 | /* Append a new tool bar item to tool_bar_items_vector. Accept | |
7ee32cda | 6977 | more than one definition for the same key. */ |
9ea173e8 | 6978 | append_tool_bar_item (); |
7ee32cda GM |
6979 | |
6980 | UNGCPRO; | |
6981 | } | |
6982 | ||
6983 | ||
9ea173e8 GM |
6984 | /* Parse a tool bar item specification ITEM for key KEY and return the |
6985 | result in tool_bar_item_properties. Value is zero if ITEM is | |
7ee32cda GM |
6986 | invalid. |
6987 | ||
6988 | ITEM is a list `(menu-item CAPTION BINDING PROPS...)'. | |
6989 | ||
6990 | CAPTION is the caption of the item, If it's not a string, it is | |
6991 | evaluated to get a string. | |
6992 | ||
9ea173e8 | 6993 | BINDING is the tool bar item's binding. Tool-bar items with keymaps |
7ee32cda GM |
6994 | as binding are currently ignored. |
6995 | ||
6996 | The following properties are recognized: | |
6997 | ||
6998 | - `:enable FORM'. | |
6999 | ||
9ea173e8 GM |
7000 | FORM is evaluated and specifies whether the tool bar item is |
7001 | enabled or disabled. | |
7ee32cda GM |
7002 | |
7003 | - `:visible FORM' | |
7004 | ||
9ea173e8 | 7005 | FORM is evaluated and specifies whether the tool bar item is visible. |
7ee32cda GM |
7006 | |
7007 | - `:filter FUNCTION' | |
7008 | ||
7009 | FUNCTION is invoked with one parameter `(quote BINDING)'. Its | |
7010 | result is stored as the new binding. | |
7011 | ||
7012 | - `:button (TYPE SELECTED)' | |
7013 | ||
7014 | TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated | |
7015 | and specifies whether the button is selected (pressed) or not. | |
7016 | ||
7017 | - `:image IMAGES' | |
7018 | ||
7019 | IMAGES is either a single image specification or a vector of four | |
9ea173e8 | 7020 | image specifications. See enum tool_bar_item_images. |
7ee32cda GM |
7021 | |
7022 | - `:help HELP-STRING'. | |
7023 | ||
9ea173e8 | 7024 | Gives a help string to display for the tool bar item. */ |
7ee32cda GM |
7025 | |
7026 | static int | |
9ea173e8 | 7027 | parse_tool_bar_item (key, item) |
7ee32cda GM |
7028 | Lisp_Object key, item; |
7029 | { | |
9ea173e8 GM |
7030 | /* Access slot with index IDX of vector tool_bar_item_properties. */ |
7031 | #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX] | |
7ee32cda GM |
7032 | |
7033 | Lisp_Object filter = Qnil; | |
7034 | Lisp_Object caption; | |
7035 | extern Lisp_Object QCenable, QCvisible, QChelp, QCfilter; | |
7036 | extern Lisp_Object QCbutton, QCtoggle, QCradio; | |
7037 | int i; | |
7ee32cda | 7038 | |
8c907a56 GM |
7039 | /* Defininition looks like `(menu-item CAPTION BINDING PROPS...)'. |
7040 | Rule out items that aren't lists, don't start with | |
7041 | `menu-item' or whose rest following `tool-bar-item' is not a | |
7ee32cda GM |
7042 | list. */ |
7043 | if (!CONSP (item) | |
7044 | || !EQ (XCAR (item), Qmenu_item) | |
7045 | || (item = XCDR (item), | |
7046 | !CONSP (item))) | |
7047 | return 0; | |
7048 | ||
9ea173e8 | 7049 | /* Create tool_bar_item_properties vector if necessary. Reset it to |
7ee32cda | 7050 | defaults. */ |
9ea173e8 | 7051 | if (VECTORP (tool_bar_item_properties)) |
7ee32cda | 7052 | { |
9ea173e8 | 7053 | for (i = 0; i < TOOL_BAR_ITEM_NSLOTS; ++i) |
7ee32cda GM |
7054 | PROP (i) = Qnil; |
7055 | } | |
7056 | else | |
9ea173e8 GM |
7057 | tool_bar_item_properties |
7058 | = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS), Qnil); | |
7ee32cda GM |
7059 | |
7060 | /* Set defaults. */ | |
9ea173e8 GM |
7061 | PROP (TOOL_BAR_ITEM_KEY) = key; |
7062 | PROP (TOOL_BAR_ITEM_ENABLED_P) = Qt; | |
7ee32cda GM |
7063 | |
7064 | /* Get the caption of the item. If the caption is not a string, | |
7065 | evaluate it to get a string. If we don't get a string, skip this | |
7066 | item. */ | |
7067 | caption = XCAR (item); | |
7068 | if (!STRINGP (caption)) | |
7069 | { | |
7070 | caption = menu_item_eval_property (caption); | |
7071 | if (!STRINGP (caption)) | |
7072 | return 0; | |
7073 | } | |
9ea173e8 | 7074 | PROP (TOOL_BAR_ITEM_CAPTION) = caption; |
7ee32cda GM |
7075 | |
7076 | /* Give up if rest following the caption is not a list. */ | |
7077 | item = XCDR (item); | |
7078 | if (!CONSP (item)) | |
7079 | return 0; | |
7080 | ||
7081 | /* Store the binding. */ | |
9ea173e8 | 7082 | PROP (TOOL_BAR_ITEM_BINDING) = XCAR (item); |
7ee32cda GM |
7083 | item = XCDR (item); |
7084 | ||
8c907a56 GM |
7085 | /* Ignore cached key binding, if any. */ |
7086 | if (CONSP (item) && CONSP (XCAR (item))) | |
7087 | item = XCDR (item); | |
7088 | ||
7ee32cda GM |
7089 | /* Process the rest of the properties. */ |
7090 | for (; CONSP (item) && CONSP (XCDR (item)); item = XCDR (XCDR (item))) | |
7091 | { | |
7092 | Lisp_Object key, value; | |
7093 | ||
7094 | key = XCAR (item); | |
7095 | value = XCAR (XCDR (item)); | |
7096 | ||
7097 | if (EQ (key, QCenable)) | |
7098 | /* `:enable FORM'. */ | |
9ea173e8 | 7099 | PROP (TOOL_BAR_ITEM_ENABLED_P) = value; |
7ee32cda GM |
7100 | else if (EQ (key, QCvisible)) |
7101 | { | |
7102 | /* `:visible FORM'. If got a visible property and that | |
7103 | evaluates to nil then ignore this item. */ | |
7104 | if (NILP (menu_item_eval_property (value))) | |
7105 | return 0; | |
7106 | } | |
7107 | else if (EQ (key, QChelp)) | |
7108 | /* `:help HELP-STRING'. */ | |
9ea173e8 | 7109 | PROP (TOOL_BAR_ITEM_HELP) = value; |
7ee32cda GM |
7110 | else if (EQ (key, QCfilter)) |
7111 | /* ':filter FORM'. */ | |
7112 | filter = value; | |
7113 | else if (EQ (key, QCbutton) && CONSP (value)) | |
7114 | { | |
7115 | /* `:button (TYPE . SELECTED)'. */ | |
7116 | Lisp_Object type, selected; | |
7117 | ||
7118 | type = XCAR (value); | |
7119 | selected = XCDR (value); | |
7120 | if (EQ (type, QCtoggle) || EQ (type, QCradio)) | |
7121 | { | |
9ea173e8 GM |
7122 | PROP (TOOL_BAR_ITEM_SELECTED_P) = selected; |
7123 | PROP (TOOL_BAR_ITEM_TYPE) = type; | |
7ee32cda GM |
7124 | } |
7125 | } | |
7126 | else if (EQ (key, QCimage) | |
7127 | && (CONSP (value) | |
7128 | || (VECTORP (value) && XVECTOR (value)->size == 4))) | |
7129 | /* Value is either a single image specification or a vector | |
7130 | of 4 such specifications for the different buttion states. */ | |
9ea173e8 | 7131 | PROP (TOOL_BAR_ITEM_IMAGES) = value; |
7ee32cda GM |
7132 | } |
7133 | ||
7134 | /* If got a filter apply it on binding. */ | |
7135 | if (!NILP (filter)) | |
9ea173e8 | 7136 | PROP (TOOL_BAR_ITEM_BINDING) |
7ee32cda GM |
7137 | = menu_item_eval_property (list2 (filter, |
7138 | list2 (Qquote, | |
9ea173e8 | 7139 | PROP (TOOL_BAR_ITEM_BINDING)))); |
7ee32cda GM |
7140 | |
7141 | /* See if the binding is a keymap. Give up if it is. */ | |
02067692 | 7142 | if (CONSP (get_keymap (PROP (TOOL_BAR_ITEM_BINDING), 0, 1))) |
7ee32cda GM |
7143 | return 0; |
7144 | ||
7145 | /* Enable or disable selection of item. */ | |
9ea173e8 GM |
7146 | if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P), Qt)) |
7147 | PROP (TOOL_BAR_ITEM_ENABLED_P) | |
7148 | = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P)); | |
7ee32cda GM |
7149 | |
7150 | /* Handle radio buttons or toggle boxes. */ | |
9ea173e8 GM |
7151 | if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P))) |
7152 | PROP (TOOL_BAR_ITEM_SELECTED_P) | |
7153 | = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P)); | |
7ee32cda GM |
7154 | |
7155 | return 1; | |
7156 | ||
7157 | #undef PROP | |
7158 | } | |
7159 | ||
7160 | ||
9ea173e8 GM |
7161 | /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector |
7162 | that can be reused. */ | |
7ee32cda GM |
7163 | |
7164 | static void | |
9ea173e8 | 7165 | init_tool_bar_items (reuse) |
7ee32cda GM |
7166 | Lisp_Object reuse; |
7167 | { | |
7168 | if (VECTORP (reuse)) | |
9ea173e8 | 7169 | tool_bar_items_vector = reuse; |
7ee32cda | 7170 | else |
9ea173e8 GM |
7171 | tool_bar_items_vector = Fmake_vector (make_number (64), Qnil); |
7172 | ntool_bar_items = 0; | |
7ee32cda GM |
7173 | } |
7174 | ||
7175 | ||
9ea173e8 GM |
7176 | /* Append parsed tool bar item properties from |
7177 | tool_bar_item_properties */ | |
7ee32cda GM |
7178 | |
7179 | static void | |
9ea173e8 | 7180 | append_tool_bar_item () |
7ee32cda GM |
7181 | { |
7182 | Lisp_Object *to, *from; | |
7183 | ||
9ea173e8 GM |
7184 | /* Enlarge tool_bar_items_vector if necessary. */ |
7185 | if (ntool_bar_items + TOOL_BAR_ITEM_NSLOTS | |
7186 | >= XVECTOR (tool_bar_items_vector)->size) | |
7ee32cda GM |
7187 | { |
7188 | Lisp_Object new_vector; | |
9ea173e8 | 7189 | int old_size = XVECTOR (tool_bar_items_vector)->size; |
7ee32cda GM |
7190 | |
7191 | new_vector = Fmake_vector (make_number (2 * old_size), Qnil); | |
9ea173e8 | 7192 | bcopy (XVECTOR (tool_bar_items_vector)->contents, |
7ee32cda GM |
7193 | XVECTOR (new_vector)->contents, |
7194 | old_size * sizeof (Lisp_Object)); | |
9ea173e8 | 7195 | tool_bar_items_vector = new_vector; |
7ee32cda GM |
7196 | } |
7197 | ||
9ea173e8 GM |
7198 | /* Append entries from tool_bar_item_properties to the end of |
7199 | tool_bar_items_vector. */ | |
7200 | to = XVECTOR (tool_bar_items_vector)->contents + ntool_bar_items; | |
7201 | from = XVECTOR (tool_bar_item_properties)->contents; | |
7202 | bcopy (from, to, TOOL_BAR_ITEM_NSLOTS * sizeof *to); | |
7203 | ntool_bar_items += TOOL_BAR_ITEM_NSLOTS; | |
7ee32cda GM |
7204 | } |
7205 | ||
7206 | ||
7207 | ||
7208 | ||
e8886a1d | 7209 | \f |
dcc408a0 RS |
7210 | /* Read a character using menus based on maps in the array MAPS. |
7211 | NMAPS is the length of MAPS. Return nil if there are no menus in the maps. | |
7212 | Return t if we displayed a menu but the user rejected it. | |
7d6de002 RS |
7213 | |
7214 | PREV_EVENT is the previous input event, or nil if we are reading | |
7215 | the first event of a key sequence. | |
7216 | ||
83d68044 | 7217 | If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1 |
6569cc8d | 7218 | if we used a mouse menu to read the input, or zero otherwise. If |
83d68044 | 7219 | USED_MOUSE_MENU is null, we don't dereference it. |
284f4730 JB |
7220 | |
7221 | The prompting is done based on the prompt-string of the map | |
df0f2ba1 | 7222 | and the strings associated with various map elements. |
8150596a RS |
7223 | |
7224 | This can be done with X menus or with menus put in the minibuf. | |
7225 | These are done in different ways, depending on how the input will be read. | |
7226 | Menus using X are done after auto-saving in read-char, getting the input | |
7227 | event from Fx_popup_menu; menus using the minibuf use read_char recursively | |
7228 | and do auto-saving in the inner call of read_char. */ | |
284f4730 | 7229 | |
7617111f | 7230 | static Lisp_Object |
8150596a | 7231 | read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu) |
7d6de002 RS |
7232 | int nmaps; |
7233 | Lisp_Object *maps; | |
7234 | Lisp_Object prev_event; | |
7235 | int *used_mouse_menu; | |
284f4730 | 7236 | { |
7d6de002 RS |
7237 | int mapno; |
7238 | register Lisp_Object name; | |
7d6de002 | 7239 | |
6569cc8d JB |
7240 | if (used_mouse_menu) |
7241 | *used_mouse_menu = 0; | |
284f4730 JB |
7242 | |
7243 | /* Use local over global Menu maps */ | |
7244 | ||
7d6de002 RS |
7245 | if (! menu_prompting) |
7246 | return Qnil; | |
7247 | ||
03361bcc RS |
7248 | /* Optionally disregard all but the global map. */ |
7249 | if (inhibit_local_menu_bar_menus) | |
7250 | { | |
7251 | maps += (nmaps - 1); | |
7252 | nmaps = 1; | |
7253 | } | |
7254 | ||
7d6de002 RS |
7255 | /* Get the menu name from the first map that has one (a prompt string). */ |
7256 | for (mapno = 0; mapno < nmaps; mapno++) | |
7257 | { | |
7258 | name = map_prompt (maps[mapno]); | |
7259 | if (!NILP (name)) | |
7260 | break; | |
7261 | } | |
284f4730 | 7262 | |
7d6de002 | 7263 | /* If we don't have any menus, just read a character normally. */ |
dbc4e1c1 | 7264 | if (mapno >= nmaps) |
7d6de002 RS |
7265 | return Qnil; |
7266 | ||
1f5b1641 | 7267 | #ifdef HAVE_MENUS |
7d6de002 RS |
7268 | /* If we got to this point via a mouse click, |
7269 | use a real menu for mouse selection. */ | |
5a8d99e0 | 7270 | if (EVENT_HAS_PARAMETERS (prev_event) |
7539e11f KR |
7271 | && !EQ (XCAR (prev_event), Qmenu_bar) |
7272 | && !EQ (XCAR (prev_event), Qtool_bar)) | |
7d6de002 RS |
7273 | { |
7274 | /* Display the menu and get the selection. */ | |
7275 | Lisp_Object *realmaps | |
7276 | = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); | |
7277 | Lisp_Object value; | |
7278 | int nmaps1 = 0; | |
7279 | ||
7280 | /* Use the maps that are not nil. */ | |
7281 | for (mapno = 0; mapno < nmaps; mapno++) | |
7282 | if (!NILP (maps[mapno])) | |
7283 | realmaps[nmaps1++] = maps[mapno]; | |
7284 | ||
7285 | value = Fx_popup_menu (prev_event, Flist (nmaps1, realmaps)); | |
663258f2 JB |
7286 | if (CONSP (value)) |
7287 | { | |
68f297c5 RS |
7288 | Lisp_Object tem; |
7289 | ||
7539e11f | 7290 | record_menu_key (XCAR (value)); |
8eb4d8ef | 7291 | |
68f297c5 RS |
7292 | /* If we got multiple events, unread all but |
7293 | the first. | |
7294 | There is no way to prevent those unread events | |
7295 | from showing up later in last_nonmenu_event. | |
7296 | So turn symbol and integer events into lists, | |
7297 | to indicate that they came from a mouse menu, | |
7298 | so that when present in last_nonmenu_event | |
7299 | they won't confuse things. */ | |
7539e11f KR |
7300 | for (tem = XCDR (value); !NILP (tem); |
7301 | tem = XCDR (tem)) | |
8eb4d8ef | 7302 | { |
7539e11f KR |
7303 | record_menu_key (XCAR (tem)); |
7304 | if (SYMBOLP (XCAR (tem)) | |
7305 | || INTEGERP (XCAR (tem))) | |
7306 | XCAR (tem) | |
7307 | = Fcons (XCAR (tem), Qnil); | |
8eb4d8ef | 7308 | } |
68f297c5 | 7309 | |
663258f2 JB |
7310 | /* If we got more than one event, put all but the first |
7311 | onto this list to be read later. | |
7312 | Return just the first event now. */ | |
24597608 | 7313 | Vunread_command_events |
7539e11f KR |
7314 | = nconc2 (XCDR (value), Vunread_command_events); |
7315 | value = XCAR (value); | |
663258f2 | 7316 | } |
1c90c381 | 7317 | else if (NILP (value)) |
dcc408a0 | 7318 | value = Qt; |
6569cc8d JB |
7319 | if (used_mouse_menu) |
7320 | *used_mouse_menu = 1; | |
7d6de002 RS |
7321 | return value; |
7322 | } | |
1f5b1641 | 7323 | #endif /* HAVE_MENUS */ |
8150596a RS |
7324 | return Qnil ; |
7325 | } | |
7326 | ||
68e0de82 RS |
7327 | /* Buffer in use so far for the minibuf prompts for menu keymaps. |
7328 | We make this bigger when necessary, and never free it. */ | |
7329 | static char *read_char_minibuf_menu_text; | |
7330 | /* Size of that buffer. */ | |
7331 | static int read_char_minibuf_menu_width; | |
7332 | ||
8150596a | 7333 | static Lisp_Object |
24597608 | 7334 | read_char_minibuf_menu_prompt (commandflag, nmaps, maps) |
8150596a RS |
7335 | int commandflag ; |
7336 | int nmaps; | |
7337 | Lisp_Object *maps; | |
7338 | { | |
7339 | int mapno; | |
7340 | register Lisp_Object name; | |
7341 | int nlength; | |
788f89eb | 7342 | int width = FRAME_WIDTH (SELECTED_FRAME ()) - 4; |
8150596a | 7343 | int idx = -1; |
9fdbfdf8 | 7344 | int nobindings = 1; |
8150596a | 7345 | Lisp_Object rest, vector; |
68e0de82 | 7346 | char *menu; |
8150596a | 7347 | |
8c907a56 GM |
7348 | vector = Qnil; |
7349 | ||
8150596a RS |
7350 | if (! menu_prompting) |
7351 | return Qnil; | |
7352 | ||
68e0de82 RS |
7353 | /* Make sure we have a big enough buffer for the menu text. */ |
7354 | if (read_char_minibuf_menu_text == 0) | |
7355 | { | |
7356 | read_char_minibuf_menu_width = width + 4; | |
7357 | read_char_minibuf_menu_text = (char *) xmalloc (width + 4); | |
7358 | } | |
7359 | else if (width + 4 > read_char_minibuf_menu_width) | |
7360 | { | |
7361 | read_char_minibuf_menu_width = width + 4; | |
7362 | read_char_minibuf_menu_text | |
7363 | = (char *) xrealloc (read_char_minibuf_menu_text, width + 4); | |
7364 | } | |
7365 | menu = read_char_minibuf_menu_text; | |
7366 | ||
8150596a RS |
7367 | /* Get the menu name from the first map that has one (a prompt string). */ |
7368 | for (mapno = 0; mapno < nmaps; mapno++) | |
7369 | { | |
7370 | name = map_prompt (maps[mapno]); | |
7371 | if (!NILP (name)) | |
7372 | break; | |
7373 | } | |
7374 | ||
7375 | /* If we don't have any menus, just read a character normally. */ | |
7376 | if (mapno >= nmaps) | |
7377 | return Qnil; | |
284f4730 JB |
7378 | |
7379 | /* Prompt string always starts with map's prompt, and a space. */ | |
7380 | strcpy (menu, XSTRING (name)->data); | |
fc932ac6 | 7381 | nlength = STRING_BYTES (XSTRING (name)); |
7d6de002 | 7382 | menu[nlength++] = ':'; |
284f4730 JB |
7383 | menu[nlength++] = ' '; |
7384 | menu[nlength] = 0; | |
7385 | ||
7d6de002 RS |
7386 | /* Start prompting at start of first map. */ |
7387 | mapno = 0; | |
7388 | rest = maps[mapno]; | |
284f4730 JB |
7389 | |
7390 | /* Present the documented bindings, a line at a time. */ | |
7391 | while (1) | |
7392 | { | |
7393 | int notfirst = 0; | |
7394 | int i = nlength; | |
7395 | Lisp_Object obj; | |
7396 | int ch; | |
8066f1a1 | 7397 | Lisp_Object orig_defn_macro; |
284f4730 | 7398 | |
284f4730 | 7399 | /* Loop over elements of map. */ |
7d6de002 | 7400 | while (i < width) |
284f4730 | 7401 | { |
fd3613d7 | 7402 | Lisp_Object elt; |
284f4730 | 7403 | |
7d6de002 RS |
7404 | /* If reached end of map, start at beginning of next map. */ |
7405 | if (NILP (rest)) | |
7406 | { | |
7407 | mapno++; | |
7408 | /* At end of last map, wrap around to first map if just starting, | |
7409 | or end this line if already have something on it. */ | |
7410 | if (mapno == nmaps) | |
284f4730 | 7411 | { |
8150596a | 7412 | mapno = 0; |
40932d1a | 7413 | if (notfirst || nobindings) break; |
284f4730 | 7414 | } |
7d6de002 | 7415 | rest = maps[mapno]; |
284f4730 | 7416 | } |
7d6de002 RS |
7417 | |
7418 | /* Look at the next element of the map. */ | |
7419 | if (idx >= 0) | |
7420 | elt = XVECTOR (vector)->contents[idx]; | |
284f4730 | 7421 | else |
7d6de002 RS |
7422 | elt = Fcar_safe (rest); |
7423 | ||
8c18cbfb | 7424 | if (idx < 0 && VECTORP (elt)) |
284f4730 | 7425 | { |
7d6de002 RS |
7426 | /* If we found a dense table in the keymap, |
7427 | advanced past it, but start scanning its contents. */ | |
7428 | rest = Fcdr_safe (rest); | |
7429 | vector = elt; | |
7430 | idx = 0; | |
284f4730 | 7431 | } |
7d6de002 RS |
7432 | else |
7433 | { | |
7434 | /* An ordinary element. */ | |
fd3613d7 | 7435 | Lisp_Object event, tem; |
0a2ea221 KH |
7436 | |
7437 | if (idx < 0) | |
7438 | { | |
fd3613d7 RS |
7439 | event = Fcar_safe (elt); /* alist */ |
7440 | elt = Fcdr_safe (elt); | |
0a2ea221 | 7441 | } |
8150596a | 7442 | else |
7d6de002 | 7443 | { |
fd3613d7 | 7444 | XSETINT (event, idx); /* vector */ |
0a2ea221 KH |
7445 | } |
7446 | ||
7447 | /* Ignore the element if it has no prompt string. */ | |
fd3613d7 | 7448 | if (INTEGERP (event) && parse_menu_item (elt, 0, -1)) |
0a2ea221 KH |
7449 | { |
7450 | /* 1 if the char to type matches the string. */ | |
7451 | int char_matches; | |
7452 | Lisp_Object upcased_event, downcased_event; | |
8c907a56 | 7453 | Lisp_Object desc = Qnil; |
fd3613d7 RS |
7454 | Lisp_Object s |
7455 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; | |
0a2ea221 KH |
7456 | |
7457 | upcased_event = Fupcase (event); | |
7458 | downcased_event = Fdowncase (event); | |
7459 | char_matches = (XINT (upcased_event) == XSTRING (s)->data[0] | |
7460 | || XINT (downcased_event) == XSTRING (s)->data[0]); | |
7461 | if (! char_matches) | |
efff6e49 | 7462 | desc = Fsingle_key_description (event, Qnil); |
0a2ea221 | 7463 | |
fd3613d7 RS |
7464 | tem |
7465 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ]; | |
7466 | if (!NILP (tem)) | |
7467 | /* Insert equivalent keybinding. */ | |
7468 | s = concat2 (s, tem); | |
7469 | ||
7470 | tem | |
7471 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE]; | |
7472 | if (EQ (tem, QCradio) || EQ (tem, QCtoggle)) | |
7473 | { | |
7474 | /* Insert button prefix. */ | |
7475 | Lisp_Object selected | |
7476 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]; | |
7477 | if (EQ (tem, QCradio)) | |
7478 | tem = build_string (NILP (selected) ? "(*) " : "( ) "); | |
7479 | else | |
7480 | tem = build_string (NILP (selected) ? "[X] " : "[ ] "); | |
7481 | s = concat2 (tem, s); | |
7482 | } | |
7483 | ||
7484 | ||
0a2ea221 KH |
7485 | /* If we have room for the prompt string, add it to this line. |
7486 | If this is the first on the line, always add it. */ | |
7487 | if ((XSTRING (s)->size + i + 2 | |
7488 | + (char_matches ? 0 : XSTRING (desc)->size + 3)) | |
7489 | < width | |
7490 | || !notfirst) | |
7491 | { | |
7492 | int thiswidth; | |
7493 | ||
7494 | /* Punctuate between strings. */ | |
7495 | if (notfirst) | |
7496 | { | |
7497 | strcpy (menu + i, ", "); | |
7498 | i += 2; | |
7499 | } | |
7500 | notfirst = 1; | |
7501 | nobindings = 0 ; | |
284f4730 | 7502 | |
0a2ea221 KH |
7503 | /* If the char to type doesn't match the string's |
7504 | first char, explicitly show what char to type. */ | |
7505 | if (! char_matches) | |
7506 | { | |
7507 | /* Add as much of string as fits. */ | |
7508 | thiswidth = XSTRING (desc)->size; | |
7509 | if (thiswidth + i > width) | |
7510 | thiswidth = width - i; | |
7511 | bcopy (XSTRING (desc)->data, menu + i, thiswidth); | |
7512 | i += thiswidth; | |
7513 | strcpy (menu + i, " = "); | |
7514 | i += 3; | |
7515 | } | |
7516 | ||
7517 | /* Add as much of string as fits. */ | |
7518 | thiswidth = XSTRING (s)->size; | |
7519 | if (thiswidth + i > width) | |
7520 | thiswidth = width - i; | |
7521 | bcopy (XSTRING (s)->data, menu + i, thiswidth); | |
7522 | i += thiswidth; | |
7523 | menu[i] = 0; | |
7524 | } | |
7525 | else | |
7d6de002 | 7526 | { |
0a2ea221 KH |
7527 | /* If this element does not fit, end the line now, |
7528 | and save the element for the next line. */ | |
7529 | strcpy (menu + i, "..."); | |
7530 | break; | |
7d6de002 | 7531 | } |
7d6de002 RS |
7532 | } |
7533 | ||
7534 | /* Move past this element. */ | |
8150596a | 7535 | if (idx >= 0 && idx + 1 >= XVECTOR (vector)->size) |
7d6de002 RS |
7536 | /* Handle reaching end of dense table. */ |
7537 | idx = -1; | |
7538 | if (idx >= 0) | |
7539 | idx++; | |
7540 | else | |
7541 | rest = Fcdr_safe (rest); | |
7542 | } | |
284f4730 JB |
7543 | } |
7544 | ||
7545 | /* Prompt with that and read response. */ | |
301738ed RS |
7546 | message2_nolog (menu, strlen (menu), |
7547 | ! NILP (current_buffer->enable_multibyte_characters)); | |
8150596a | 7548 | |
df0f2ba1 | 7549 | /* Make believe its not a keyboard macro in case the help char |
8150596a RS |
7550 | is pressed. Help characters are not recorded because menu prompting |
7551 | is not used on replay. | |
7552 | */ | |
c5fdd383 KH |
7553 | orig_defn_macro = current_kboard->defining_kbd_macro; |
7554 | current_kboard->defining_kbd_macro = Qnil; | |
3cb81011 | 7555 | do |
7735786b | 7556 | obj = read_char (commandflag, 0, 0, Qt, 0); |
8c18cbfb | 7557 | while (BUFFERP (obj)); |
c5fdd383 | 7558 | current_kboard->defining_kbd_macro = orig_defn_macro; |
284f4730 | 7559 | |
8c18cbfb | 7560 | if (!INTEGERP (obj)) |
284f4730 JB |
7561 | return obj; |
7562 | else | |
7563 | ch = XINT (obj); | |
7564 | ||
f4255cd1 | 7565 | if (! EQ (obj, menu_prompt_more_char) |
8c18cbfb | 7566 | && (!INTEGERP (menu_prompt_more_char) |
f4255cd1 | 7567 | || ! EQ (obj, make_number (Ctl (XINT (menu_prompt_more_char)))))) |
8150596a | 7568 | { |
c5fdd383 | 7569 | if (!NILP (current_kboard->defining_kbd_macro)) |
8066f1a1 | 7570 | store_kbd_macro_char (obj); |
8150596a RS |
7571 | return obj; |
7572 | } | |
7573 | /* Help char - go round again */ | |
284f4730 JB |
7574 | } |
7575 | } | |
284f4730 JB |
7576 | \f |
7577 | /* Reading key sequences. */ | |
7578 | ||
7579 | /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings | |
7580 | in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a | |
7581 | keymap, or nil otherwise. Return the index of the first keymap in | |
7582 | which KEY has any binding, or NMAPS if no map has a binding. | |
7583 | ||
7584 | If KEY is a meta ASCII character, treat it like meta-prefix-char | |
7585 | followed by the corresponding non-meta character. Keymaps in | |
7586 | CURRENT with non-prefix bindings for meta-prefix-char become nil in | |
7587 | NEXT. | |
7588 | ||
88cb0656 JB |
7589 | If KEY has no bindings in any of the CURRENT maps, NEXT is left |
7590 | unmodified. | |
7591 | ||
569871d2 | 7592 | NEXT may be the same array as CURRENT. */ |
284f4730 JB |
7593 | |
7594 | static int | |
4e50f26a | 7595 | follow_key (key, nmaps, current, defs, next) |
284f4730 JB |
7596 | Lisp_Object key; |
7597 | Lisp_Object *current, *defs, *next; | |
7598 | int nmaps; | |
7599 | { | |
7600 | int i, first_binding; | |
569871d2 | 7601 | int did_meta = 0; |
284f4730 | 7602 | |
284f4730 JB |
7603 | first_binding = nmaps; |
7604 | for (i = nmaps - 1; i >= 0; i--) | |
7605 | { | |
7606 | if (! NILP (current[i])) | |
7607 | { | |
569871d2 RS |
7608 | Lisp_Object map; |
7609 | if (did_meta) | |
7610 | map = defs[i]; | |
7611 | else | |
7612 | map = current[i]; | |
7613 | ||
db785038 | 7614 | defs[i] = access_keymap (map, key, 1, 0, 1); |
284f4730 JB |
7615 | if (! NILP (defs[i])) |
7616 | first_binding = i; | |
7617 | } | |
7618 | else | |
7619 | defs[i] = Qnil; | |
7620 | } | |
7621 | ||
284f4730 | 7622 | /* Given the set of bindings we've found, produce the next set of maps. */ |
0a7f1fc0 JB |
7623 | if (first_binding < nmaps) |
7624 | for (i = 0; i < nmaps; i++) | |
02067692 | 7625 | next[i] = NILP (defs[i]) ? Qnil : get_keymap (defs[i], 0, 1); |
284f4730 JB |
7626 | |
7627 | return first_binding; | |
7628 | } | |
7629 | ||
df0f2ba1 | 7630 | /* Read a sequence of keys that ends with a non prefix character, |
f4255cd1 JB |
7631 | storing it in KEYBUF, a buffer of size BUFSIZE. |
7632 | Prompt with PROMPT. | |
284f4730 | 7633 | Return the length of the key sequence stored. |
dcc408a0 | 7634 | Return -1 if the user rejected a command menu. |
284f4730 | 7635 | |
f4255cd1 JB |
7636 | Echo starting immediately unless `prompt' is 0. |
7637 | ||
7638 | Where a key sequence ends depends on the currently active keymaps. | |
7639 | These include any minor mode keymaps active in the current buffer, | |
7640 | the current buffer's local map, and the global map. | |
7641 | ||
7642 | If a key sequence has no other bindings, we check Vfunction_key_map | |
7643 | to see if some trailing subsequence might be the beginning of a | |
7644 | function key's sequence. If so, we try to read the whole function | |
7645 | key, and substitute its symbolic name into the key sequence. | |
7646 | ||
fbcd35bd JB |
7647 | We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and |
7648 | `double-' events into similar click events, if that would make them | |
7649 | bound. We try to turn `triple-' events first into `double-' events, | |
7650 | then into clicks. | |
f4255cd1 JB |
7651 | |
7652 | If we get a mouse click in a mode line, vertical divider, or other | |
7653 | non-text area, we treat the click as if it were prefixed by the | |
7654 | symbol denoting that area - `mode-line', `vertical-line', or | |
7655 | whatever. | |
7656 | ||
7657 | If the sequence starts with a mouse click, we read the key sequence | |
7658 | with respect to the buffer clicked on, not the current buffer. | |
284f4730 | 7659 | |
f4255cd1 JB |
7660 | If the user switches frames in the midst of a key sequence, we put |
7661 | off the switch-frame event until later; the next call to | |
f571ae0d RS |
7662 | read_char will return it. |
7663 | ||
7664 | If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer | |
7665 | from the selected window's buffer. */ | |
48e416d4 | 7666 | |
284f4730 | 7667 | static int |
ce98e608 | 7668 | read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last, |
f571ae0d | 7669 | can_return_switch_frame, fix_current_buffer) |
284f4730 JB |
7670 | Lisp_Object *keybuf; |
7671 | int bufsize; | |
84d91fda | 7672 | Lisp_Object prompt; |
309b0fc8 | 7673 | int dont_downcase_last; |
ce98e608 | 7674 | int can_return_switch_frame; |
f571ae0d | 7675 | int fix_current_buffer; |
284f4730 | 7676 | { |
8c907a56 | 7677 | volatile int count = specpdl_ptr - specpdl; |
f4255cd1 | 7678 | |
284f4730 | 7679 | /* How many keys there are in the current key sequence. */ |
8c907a56 | 7680 | volatile int t; |
284f4730 | 7681 | |
284f4730 JB |
7682 | /* The length of the echo buffer when we started reading, and |
7683 | the length of this_command_keys when we started reading. */ | |
8c907a56 GM |
7684 | volatile int echo_start; |
7685 | volatile int keys_start; | |
284f4730 JB |
7686 | |
7687 | /* The number of keymaps we're scanning right now, and the number of | |
7688 | keymaps we have allocated space for. */ | |
8c907a56 GM |
7689 | volatile int nmaps; |
7690 | volatile int nmaps_allocated = 0; | |
284f4730 | 7691 | |
284f4730 JB |
7692 | /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in |
7693 | the current keymaps. */ | |
8c907a56 | 7694 | Lisp_Object *volatile defs = NULL; |
284f4730 | 7695 | |
f4255cd1 JB |
7696 | /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] |
7697 | in the current keymaps, or nil where it is not a prefix. */ | |
8c907a56 | 7698 | Lisp_Object *volatile submaps = NULL; |
f4255cd1 | 7699 | |
e0dff5f6 | 7700 | /* The local map to start out with at start of key sequence. */ |
8c907a56 | 7701 | volatile Lisp_Object orig_local_map; |
e0dff5f6 | 7702 | |
30690496 DL |
7703 | /* The map from the `keymap' property to start out with at start of |
7704 | key sequence. */ | |
8c907a56 | 7705 | volatile Lisp_Object orig_keymap; |
30690496 | 7706 | |
e0dff5f6 RS |
7707 | /* 1 if we have already considered switching to the local-map property |
7708 | of the place where a mouse click occurred. */ | |
8c907a56 | 7709 | volatile int localized_local_map = 0; |
e0dff5f6 | 7710 | |
f4255cd1 JB |
7711 | /* The index in defs[] of the first keymap that has a binding for |
7712 | this key sequence. In other words, the lowest i such that | |
7713 | defs[i] is non-nil. */ | |
8c907a56 | 7714 | volatile int first_binding; |
284f4730 | 7715 | |
f4255cd1 | 7716 | /* If t < mock_input, then KEYBUF[t] should be read as the next |
253598e4 JB |
7717 | input key. |
7718 | ||
7719 | We use this to recover after recognizing a function key. Once we | |
7720 | realize that a suffix of the current key sequence is actually a | |
7721 | function key's escape sequence, we replace the suffix with the | |
7722 | function key's binding from Vfunction_key_map. Now keybuf | |
f4255cd1 JB |
7723 | contains a new and different key sequence, so the echo area, |
7724 | this_command_keys, and the submaps and defs arrays are wrong. In | |
7725 | this situation, we set mock_input to t, set t to 0, and jump to | |
7726 | restart_sequence; the loop will read keys from keybuf up until | |
7727 | mock_input, thus rebuilding the state; and then it will resume | |
7728 | reading characters from the keyboard. */ | |
8c907a56 | 7729 | volatile int mock_input = 0; |
284f4730 | 7730 | |
253598e4 | 7731 | /* If the sequence is unbound in submaps[], then |
f4255cd1 JB |
7732 | keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map, |
7733 | and fkey_map is its binding. | |
253598e4 | 7734 | |
f4255cd1 JB |
7735 | These might be > t, indicating that all function key scanning |
7736 | should hold off until t reaches them. We do this when we've just | |
7737 | recognized a function key, to avoid searching for the function | |
7738 | key's again in Vfunction_key_map. */ | |
8c907a56 GM |
7739 | volatile int fkey_start = 0, fkey_end = 0; |
7740 | volatile Lisp_Object fkey_map; | |
284f4730 | 7741 | |
a612e298 | 7742 | /* Likewise, for key_translation_map. */ |
8c907a56 GM |
7743 | volatile int keytran_start = 0, keytran_end = 0; |
7744 | volatile Lisp_Object keytran_map; | |
a612e298 | 7745 | |
cd21b839 JB |
7746 | /* If we receive a ``switch-frame'' event in the middle of a key sequence, |
7747 | we put it off for later. While we're reading, we keep the event here. */ | |
8c907a56 | 7748 | volatile Lisp_Object delayed_switch_frame; |
cd21b839 | 7749 | |
51763820 BF |
7750 | /* See the comment below... */ |
7751 | #if defined (GOBBLE_FIRST_EVENT) | |
4efda7dd | 7752 | Lisp_Object first_event; |
51763820 | 7753 | #endif |
4efda7dd | 7754 | |
8c907a56 GM |
7755 | volatile Lisp_Object original_uppercase; |
7756 | volatile int original_uppercase_position = -1; | |
309b0fc8 | 7757 | |
bc536d84 | 7758 | /* Gets around Microsoft compiler limitations. */ |
309b0fc8 | 7759 | int dummyflag = 0; |
bc536d84 | 7760 | |
3b9189f8 RS |
7761 | struct buffer *starting_buffer; |
7762 | ||
e9bf89a0 RS |
7763 | /* Nonzero if we seem to have got the beginning of a binding |
7764 | in function_key_map. */ | |
8c907a56 GM |
7765 | volatile int function_key_possible = 0; |
7766 | volatile int key_translation_possible = 0; | |
e9bf89a0 | 7767 | |
3fe8e9a2 RS |
7768 | /* Save the status of key translation before each step, |
7769 | so that we can restore this after downcasing. */ | |
7770 | Lisp_Object prev_fkey_map; | |
3fdfceb3 RS |
7771 | int prev_fkey_start; |
7772 | int prev_fkey_end; | |
3fe8e9a2 RS |
7773 | |
7774 | Lisp_Object prev_keytran_map; | |
3fdfceb3 RS |
7775 | int prev_keytran_start; |
7776 | int prev_keytran_end; | |
3fe8e9a2 | 7777 | |
03cee6ae | 7778 | #if defined (GOBBLE_FIRST_EVENT) |
4efda7dd | 7779 | int junk; |
03cee6ae | 7780 | #endif |
4efda7dd | 7781 | |
7d18f9ae RS |
7782 | raw_keybuf_count = 0; |
7783 | ||
4efda7dd RS |
7784 | last_nonmenu_event = Qnil; |
7785 | ||
7786 | delayed_switch_frame = Qnil; | |
7787 | fkey_map = Vfunction_key_map; | |
a612e298 | 7788 | keytran_map = Vkey_translation_map; |
f4255cd1 | 7789 | |
a612e298 | 7790 | /* If there is no function-key-map, turn off function key scanning. */ |
02067692 | 7791 | if (!KEYMAPP (Vfunction_key_map)) |
f4255cd1 JB |
7792 | fkey_start = fkey_end = bufsize + 1; |
7793 | ||
a612e298 | 7794 | /* If there is no key-translation-map, turn off scanning. */ |
02067692 | 7795 | if (!KEYMAPP (Vkey_translation_map)) |
a612e298 RS |
7796 | keytran_start = keytran_end = bufsize + 1; |
7797 | ||
284f4730 JB |
7798 | if (INTERACTIVE) |
7799 | { | |
84d91fda RS |
7800 | if (!NILP (prompt)) |
7801 | echo_prompt (XSTRING (prompt)->data); | |
f2647d04 DL |
7802 | else if (cursor_in_echo_area |
7803 | && (FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes)) | |
7804 | && NILP (Fzerop (Vecho_keystrokes))) | |
284f4730 JB |
7805 | /* This doesn't put in a dash if the echo buffer is empty, so |
7806 | you don't always see a dash hanging out in the minibuffer. */ | |
7807 | echo_dash (); | |
284f4730 JB |
7808 | } |
7809 | ||
f4255cd1 JB |
7810 | /* Record the initial state of the echo area and this_command_keys; |
7811 | we will need to restore them if we replay a key sequence. */ | |
0a7f1fc0 | 7812 | if (INTERACTIVE) |
df0f2ba1 | 7813 | echo_start = echo_length (); |
f4255cd1 | 7814 | keys_start = this_command_key_count; |
6321824f | 7815 | this_single_command_key_start = keys_start; |
0a7f1fc0 | 7816 | |
51763820 BF |
7817 | #if defined (GOBBLE_FIRST_EVENT) |
7818 | /* This doesn't quite work, because some of the things that read_char | |
7819 | does cannot safely be bypassed. It seems too risky to try to make | |
df0f2ba1 | 7820 | this work right. */ |
51763820 | 7821 | |
4efda7dd RS |
7822 | /* Read the first char of the sequence specially, before setting |
7823 | up any keymaps, in case a filter runs and switches buffers on us. */ | |
84d91fda | 7824 | first_event = read_char (NILP (prompt), 0, submaps, last_nonmenu_event, |
4efda7dd | 7825 | &junk); |
51763820 | 7826 | #endif /* GOBBLE_FIRST_EVENT */ |
4efda7dd | 7827 | |
30690496 DL |
7828 | orig_local_map = get_local_map (PT, current_buffer, local_map); |
7829 | orig_keymap = get_local_map (PT, current_buffer, keymap); | |
e0dff5f6 | 7830 | |
7b4aedb9 JB |
7831 | /* We jump here when the key sequence has been thoroughly changed, and |
7832 | we need to rescan it starting from the beginning. When we jump here, | |
7833 | keybuf[0..mock_input] holds the sequence we should reread. */ | |
07d2b8de | 7834 | replay_sequence: |
7b4aedb9 | 7835 | |
3b9189f8 | 7836 | starting_buffer = current_buffer; |
e9bf89a0 | 7837 | function_key_possible = 0; |
00a78037 | 7838 | key_translation_possible = 0; |
3b9189f8 | 7839 | |
f4255cd1 | 7840 | /* Build our list of keymaps. |
07d2b8de JB |
7841 | If we recognize a function key and replace its escape sequence in |
7842 | keybuf with its symbol, or if the sequence starts with a mouse | |
7843 | click and we need to switch buffers, we jump back here to rebuild | |
7844 | the initial keymaps from the current buffer. */ | |
df0f2ba1 | 7845 | { |
284f4730 JB |
7846 | Lisp_Object *maps; |
7847 | ||
217258d5 KH |
7848 | if (!NILP (current_kboard->Voverriding_terminal_local_map) |
7849 | || !NILP (Voverriding_local_map)) | |
284f4730 | 7850 | { |
217258d5 | 7851 | if (3 > nmaps_allocated) |
9dd3131c | 7852 | { |
217258d5 KH |
7853 | submaps = (Lisp_Object *) alloca (3 * sizeof (submaps[0])); |
7854 | defs = (Lisp_Object *) alloca (3 * sizeof (defs[0])); | |
7855 | nmaps_allocated = 3; | |
9dd3131c | 7856 | } |
217258d5 KH |
7857 | nmaps = 0; |
7858 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
7859 | submaps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
7860 | if (!NILP (Voverriding_local_map)) | |
7861 | submaps[nmaps++] = Voverriding_local_map; | |
284f4730 | 7862 | } |
9dd3131c RS |
7863 | else |
7864 | { | |
30690496 | 7865 | int extra_maps = 2; |
217258d5 | 7866 | nmaps = current_minor_maps (0, &maps); |
30690496 DL |
7867 | if (!NILP (orig_keymap)) |
7868 | extra_maps = 3; | |
7869 | if (nmaps + extra_maps > nmaps_allocated) | |
9dd3131c | 7870 | { |
30690496 DL |
7871 | submaps = (Lisp_Object *) alloca ((nmaps+extra_maps) |
7872 | * sizeof (submaps[0])); | |
7873 | defs = (Lisp_Object *) alloca ((nmaps+extra_maps) | |
7874 | * sizeof (defs[0])); | |
7875 | nmaps_allocated = nmaps + extra_maps; | |
9dd3131c | 7876 | } |
8c907a56 | 7877 | bcopy (maps, (void *) submaps, nmaps * sizeof (submaps[0])); |
30690496 DL |
7878 | if (!NILP (orig_keymap)) |
7879 | submaps[nmaps++] = orig_keymap; | |
217258d5 | 7880 | submaps[nmaps++] = orig_local_map; |
9dd3131c | 7881 | } |
217258d5 | 7882 | submaps[nmaps++] = current_global_map; |
284f4730 JB |
7883 | } |
7884 | ||
7885 | /* Find an accurate initial value for first_binding. */ | |
7886 | for (first_binding = 0; first_binding < nmaps; first_binding++) | |
253598e4 | 7887 | if (! NILP (submaps[first_binding])) |
284f4730 JB |
7888 | break; |
7889 | ||
3b9189f8 | 7890 | /* Start from the beginning in keybuf. */ |
f4255cd1 JB |
7891 | t = 0; |
7892 | ||
7893 | /* These are no-ops the first time through, but if we restart, they | |
7894 | revert the echo area and this_command_keys to their original state. */ | |
7895 | this_command_key_count = keys_start; | |
df0f2ba1 | 7896 | if (INTERACTIVE && t < mock_input) |
f4255cd1 JB |
7897 | echo_truncate (echo_start); |
7898 | ||
cca310da JB |
7899 | /* If the best binding for the current key sequence is a keymap, or |
7900 | we may be looking at a function key's escape sequence, keep on | |
7901 | reading. */ | |
253598e4 | 7902 | while ((first_binding < nmaps && ! NILP (submaps[first_binding])) |
cca310da JB |
7903 | || (first_binding >= nmaps |
7904 | && fkey_start < t | |
7905 | /* mock input is never part of a function key's sequence. */ | |
a612e298 | 7906 | && mock_input <= fkey_start) |
0d882d52 KH |
7907 | || (first_binding >= nmaps |
7908 | && keytran_start < t && key_translation_possible) | |
e9bf89a0 RS |
7909 | /* Don't return in the middle of a possible function key sequence, |
7910 | if the only bindings we found were via case conversion. | |
7911 | Thus, if ESC O a has a function-key-map translation | |
7912 | and ESC o has a binding, don't return after ESC O, | |
7913 | so that we can translate ESC O plus the next character. */ | |
4e50f26a | 7914 | ) |
284f4730 JB |
7915 | { |
7916 | Lisp_Object key; | |
7d6de002 | 7917 | int used_mouse_menu = 0; |
284f4730 | 7918 | |
7b4aedb9 JB |
7919 | /* Where the last real key started. If we need to throw away a |
7920 | key that has expanded into more than one element of keybuf | |
7921 | (say, a mouse click on the mode line which is being treated | |
7922 | as [mode-line (mouse-...)], then we backtrack to this point | |
7923 | of keybuf. */ | |
8c907a56 | 7924 | volatile int last_real_key_start; |
7b4aedb9 | 7925 | |
0a7f1fc0 JB |
7926 | /* These variables are analogous to echo_start and keys_start; |
7927 | while those allow us to restart the entire key sequence, | |
7928 | echo_local_start and keys_local_start allow us to throw away | |
7929 | just one key. */ | |
8c907a56 | 7930 | volatile int echo_local_start, keys_local_start, local_first_binding; |
f4255cd1 | 7931 | |
284f4730 | 7932 | if (t >= bufsize) |
3fe8e9a2 | 7933 | error ("Key sequence too long"); |
284f4730 | 7934 | |
f4255cd1 JB |
7935 | if (INTERACTIVE) |
7936 | echo_local_start = echo_length (); | |
7937 | keys_local_start = this_command_key_count; | |
7938 | local_first_binding = first_binding; | |
df0f2ba1 | 7939 | |
f4255cd1 | 7940 | replay_key: |
0a7f1fc0 | 7941 | /* These are no-ops, unless we throw away a keystroke below and |
f4255cd1 JB |
7942 | jumped back up to replay_key; in that case, these restore the |
7943 | variables to their original state, allowing us to replay the | |
0a7f1fc0 | 7944 | loop. */ |
40932d1a | 7945 | if (INTERACTIVE && t < mock_input) |
f4255cd1 | 7946 | echo_truncate (echo_local_start); |
0a7f1fc0 JB |
7947 | this_command_key_count = keys_local_start; |
7948 | first_binding = local_first_binding; | |
7949 | ||
7e85b935 RS |
7950 | /* By default, assume each event is "real". */ |
7951 | last_real_key_start = t; | |
7952 | ||
f4255cd1 | 7953 | /* Does mock_input indicate that we are re-reading a key sequence? */ |
284f4730 JB |
7954 | if (t < mock_input) |
7955 | { | |
7956 | key = keybuf[t]; | |
7957 | add_command_key (key); | |
f2647d04 DL |
7958 | if ((FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes)) |
7959 | && NILP (Fzerop (Vecho_keystrokes))) | |
a98ea3f9 | 7960 | echo_char (key); |
284f4730 | 7961 | } |
253598e4 JB |
7962 | |
7963 | /* If not, we should actually read a character. */ | |
284f4730 JB |
7964 | else |
7965 | { | |
beecf6a1 | 7966 | { |
c5fdd383 KH |
7967 | #ifdef MULTI_KBOARD |
7968 | KBOARD *interrupted_kboard = current_kboard; | |
788f89eb | 7969 | struct frame *interrupted_frame = SELECTED_FRAME (); |
c5fdd383 | 7970 | if (setjmp (wrong_kboard_jmpbuf)) |
beecf6a1 | 7971 | { |
5798cf15 KH |
7972 | if (!NILP (delayed_switch_frame)) |
7973 | { | |
c5fdd383 | 7974 | interrupted_kboard->kbd_queue |
5798cf15 | 7975 | = Fcons (delayed_switch_frame, |
c5fdd383 | 7976 | interrupted_kboard->kbd_queue); |
5798cf15 KH |
7977 | delayed_switch_frame = Qnil; |
7978 | } | |
beecf6a1 | 7979 | while (t > 0) |
c5fdd383 KH |
7980 | interrupted_kboard->kbd_queue |
7981 | = Fcons (keybuf[--t], interrupted_kboard->kbd_queue); | |
5798cf15 KH |
7982 | |
7983 | /* If the side queue is non-empty, ensure it begins with a | |
7984 | switch-frame, so we'll replay it in the right context. */ | |
c5fdd383 | 7985 | if (CONSP (interrupted_kboard->kbd_queue) |
7539e11f | 7986 | && (key = XCAR (interrupted_kboard->kbd_queue), |
5798cf15 KH |
7987 | !(EVENT_HAS_PARAMETERS (key) |
7988 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key)), | |
7989 | Qswitch_frame)))) | |
df0f2ba1 KH |
7990 | { |
7991 | Lisp_Object frame; | |
7992 | XSETFRAME (frame, interrupted_frame); | |
c5fdd383 | 7993 | interrupted_kboard->kbd_queue |
df0f2ba1 | 7994 | = Fcons (make_lispy_switch_frame (frame), |
c5fdd383 | 7995 | interrupted_kboard->kbd_queue); |
df0f2ba1 | 7996 | } |
beecf6a1 | 7997 | mock_input = 0; |
30690496 DL |
7998 | orig_local_map = get_local_map (PT, current_buffer, local_map); |
7999 | orig_keymap = get_local_map (PT, current_buffer, keymap); | |
beecf6a1 KH |
8000 | goto replay_sequence; |
8001 | } | |
bded54dd | 8002 | #endif |
8c907a56 GM |
8003 | key = read_char (NILP (prompt), nmaps, |
8004 | (Lisp_Object *) submaps, last_nonmenu_event, | |
beecf6a1 KH |
8005 | &used_mouse_menu); |
8006 | } | |
284f4730 | 8007 | |
dcc408a0 RS |
8008 | /* read_char returns t when it shows a menu and the user rejects it. |
8009 | Just return -1. */ | |
8010 | if (EQ (key, Qt)) | |
7d18f9ae RS |
8011 | { |
8012 | unbind_to (count, Qnil); | |
8013 | return -1; | |
8014 | } | |
dcc408a0 | 8015 | |
f4255cd1 | 8016 | /* read_char returns -1 at the end of a macro. |
284f4730 JB |
8017 | Emacs 18 handles this by returning immediately with a |
8018 | zero, so that's what we'll do. */ | |
8c18cbfb | 8019 | if (INTEGERP (key) && XINT (key) == -1) |
cd21b839 | 8020 | { |
f4255cd1 | 8021 | t = 0; |
bc536d84 RS |
8022 | /* The Microsoft C compiler can't handle the goto that |
8023 | would go here. */ | |
309b0fc8 | 8024 | dummyflag = 1; |
bc536d84 | 8025 | break; |
cd21b839 | 8026 | } |
df0f2ba1 | 8027 | |
3cb81011 KH |
8028 | /* If the current buffer has been changed from under us, the |
8029 | keymap may have changed, so replay the sequence. */ | |
8c18cbfb | 8030 | if (BUFFERP (key)) |
3cb81011 KH |
8031 | { |
8032 | mock_input = t; | |
f571ae0d RS |
8033 | /* Reset the current buffer from the selected window |
8034 | in case something changed the former and not the latter. | |
8035 | This is to be more consistent with the behavior | |
8036 | of the command_loop_1. */ | |
8037 | if (fix_current_buffer) | |
a94a4335 | 8038 | { |
788f89eb | 8039 | if (! FRAME_LIVE_P (XFRAME (selected_frame))) |
a94a4335 KH |
8040 | Fkill_emacs (Qnil); |
8041 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
8042 | Fset_buffer (XWINDOW (selected_window)->buffer); | |
8043 | } | |
f571ae0d | 8044 | |
30690496 DL |
8045 | orig_local_map = get_local_map (PT, current_buffer, local_map); |
8046 | orig_keymap = get_local_map (PT, current_buffer, keymap); | |
3cb81011 KH |
8047 | goto replay_sequence; |
8048 | } | |
8049 | ||
3b9189f8 RS |
8050 | /* If we have a quit that was typed in another frame, and |
8051 | quit_throw_to_read_char switched buffers, | |
8052 | replay to get the right keymap. */ | |
9343ab07 | 8053 | if (XINT (key) == quit_char && current_buffer != starting_buffer) |
3b9189f8 | 8054 | { |
7d18f9ae RS |
8055 | GROW_RAW_KEYBUF; |
8056 | XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key; | |
3b9189f8 RS |
8057 | keybuf[t++] = key; |
8058 | mock_input = t; | |
8059 | Vquit_flag = Qnil; | |
30690496 DL |
8060 | orig_local_map = get_local_map (PT, current_buffer, local_map); |
8061 | orig_keymap = get_local_map (PT, current_buffer, keymap); | |
3b9189f8 RS |
8062 | goto replay_sequence; |
8063 | } | |
3cb81011 | 8064 | |
284f4730 | 8065 | Vquit_flag = Qnil; |
7d18f9ae RS |
8066 | |
8067 | if (EVENT_HAS_PARAMETERS (key) | |
8068 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key)), Qswitch_frame)) | |
8069 | { | |
8070 | /* If we're at the beginning of a key sequence, and the caller | |
8071 | says it's okay, go ahead and return this event. If we're | |
8072 | in the midst of a key sequence, delay it until the end. */ | |
8073 | if (t > 0 || !can_return_switch_frame) | |
8074 | { | |
8075 | delayed_switch_frame = key; | |
8076 | goto replay_key; | |
8077 | } | |
8078 | } | |
8079 | ||
8080 | GROW_RAW_KEYBUF; | |
8081 | XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key; | |
7e85b935 | 8082 | } |
284f4730 | 8083 | |
df0f2ba1 | 8084 | /* Clicks in non-text areas get prefixed by the symbol |
7e85b935 RS |
8085 | in their CHAR-ADDRESS field. For example, a click on |
8086 | the mode line is prefixed by the symbol `mode-line'. | |
8087 | ||
8088 | Furthermore, key sequences beginning with mouse clicks | |
8089 | are read using the keymaps of the buffer clicked on, not | |
8090 | the current buffer. So we may have to switch the buffer | |
8091 | here. | |
8092 | ||
8093 | When we turn one event into two events, we must make sure | |
8094 | that neither of the two looks like the original--so that, | |
8095 | if we replay the events, they won't be expanded again. | |
8096 | If not for this, such reexpansion could happen either here | |
8097 | or when user programs play with this-command-keys. */ | |
8098 | if (EVENT_HAS_PARAMETERS (key)) | |
8099 | { | |
9b8eb840 | 8100 | Lisp_Object kind; |
cca310da | 8101 | |
9b8eb840 | 8102 | kind = EVENT_HEAD_KIND (EVENT_HEAD (key)); |
7e85b935 | 8103 | if (EQ (kind, Qmouse_click)) |
0a7f1fc0 | 8104 | { |
9b8eb840 | 8105 | Lisp_Object window, posn; |
f4255cd1 | 8106 | |
9b8eb840 KH |
8107 | window = POSN_WINDOW (EVENT_START (key)); |
8108 | posn = POSN_BUFFER_POSN (EVENT_START (key)); | |
7ee32cda | 8109 | |
8c18cbfb | 8110 | if (CONSP (posn)) |
0a7f1fc0 | 8111 | { |
7e85b935 RS |
8112 | /* We're looking at the second event of a |
8113 | sequence which we expanded before. Set | |
8114 | last_real_key_start appropriately. */ | |
8115 | if (t > 0) | |
8116 | last_real_key_start = t - 1; | |
cd21b839 | 8117 | } |
7e85b935 RS |
8118 | |
8119 | /* Key sequences beginning with mouse clicks are | |
8120 | read using the keymaps in the buffer clicked on, | |
8121 | not the current buffer. If we're at the | |
8122 | beginning of a key sequence, switch buffers. */ | |
8123 | if (last_real_key_start == 0 | |
8c18cbfb KH |
8124 | && WINDOWP (window) |
8125 | && BUFFERP (XWINDOW (window)->buffer) | |
7e85b935 | 8126 | && XBUFFER (XWINDOW (window)->buffer) != current_buffer) |
cd21b839 | 8127 | { |
7d18f9ae | 8128 | XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key; |
7e85b935 RS |
8129 | keybuf[t] = key; |
8130 | mock_input = t + 1; | |
8131 | ||
8132 | /* Arrange to go back to the original buffer once we're | |
8133 | done reading the key sequence. Note that we can't | |
8134 | use save_excursion_{save,restore} here, because they | |
8135 | save point as well as the current buffer; we don't | |
8136 | want to save point, because redisplay may change it, | |
8137 | to accommodate a Fset_window_start or something. We | |
8138 | don't want to do this at the top of the function, | |
8139 | because we may get input from a subprocess which | |
8140 | wants to change the selected window and stuff (say, | |
8141 | emacsclient). */ | |
8142 | record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
8143 | ||
788f89eb | 8144 | if (! FRAME_LIVE_P (XFRAME (selected_frame))) |
a94a4335 | 8145 | Fkill_emacs (Qnil); |
30690496 DL |
8146 | set_buffer_internal (XBUFFER (XWINDOW |
8147 | (window)->buffer) | |
8148 | ); | |
8149 | orig_local_map = get_local_map (PT, current_buffer, | |
8150 | local_map); | |
8151 | orig_keymap = get_local_map (PT, current_buffer, keymap); | |
7e85b935 | 8152 | goto replay_sequence; |
0a7f1fc0 | 8153 | } |
7ee32cda | 8154 | |
e0dff5f6 RS |
8155 | /* For a mouse click, get the local text-property keymap |
8156 | of the place clicked on, rather than point. */ | |
7ee32cda | 8157 | if (last_real_key_start == 0 |
7539e11f | 8158 | && CONSP (XCDR (key)) |
e0dff5f6 | 8159 | && ! localized_local_map) |
5ec75a55 | 8160 | { |
e0dff5f6 RS |
8161 | Lisp_Object map_here, start, pos; |
8162 | ||
8163 | localized_local_map = 1; | |
8164 | start = EVENT_START (key); | |
7ee32cda | 8165 | |
7539e11f | 8166 | if (CONSP (start) && CONSP (XCDR (start))) |
e0dff5f6 RS |
8167 | { |
8168 | pos = POSN_BUFFER_POSN (start); | |
b78ce8fb RS |
8169 | if (INTEGERP (pos) |
8170 | && XINT (pos) >= BEG && XINT (pos) <= Z) | |
e0dff5f6 | 8171 | { |
30690496 DL |
8172 | map_here = get_local_map (XINT (pos), |
8173 | current_buffer, local_map); | |
e0dff5f6 RS |
8174 | if (!EQ (map_here, orig_local_map)) |
8175 | { | |
8176 | orig_local_map = map_here; | |
8177 | keybuf[t] = key; | |
8178 | mock_input = t + 1; | |
5ec75a55 | 8179 | |
30690496 DL |
8180 | goto replay_sequence; |
8181 | } | |
8182 | map_here = get_local_map (XINT (pos), | |
8183 | current_buffer, keymap); | |
8184 | if (!EQ (map_here, orig_keymap)) | |
8185 | { | |
8186 | orig_keymap = map_here; | |
8187 | keybuf[t] = key; | |
8188 | mock_input = t + 1; | |
8189 | ||
e0dff5f6 RS |
8190 | goto replay_sequence; |
8191 | } | |
8192 | } | |
8193 | } | |
8194 | } | |
8195 | ||
8196 | /* Expand mode-line and scroll-bar events into two events: | |
8197 | use posn as a fake prefix key. */ | |
8198 | if (SYMBOLP (posn)) | |
8199 | { | |
7e85b935 | 8200 | if (t + 1 >= bufsize) |
3fe8e9a2 | 8201 | error ("Key sequence too long"); |
7e85b935 RS |
8202 | keybuf[t] = posn; |
8203 | keybuf[t+1] = key; | |
8204 | mock_input = t + 2; | |
7ee32cda | 8205 | |
7e85b935 RS |
8206 | /* Zap the position in key, so we know that we've |
8207 | expanded it, and don't try to do so again. */ | |
8208 | POSN_BUFFER_POSN (EVENT_START (key)) | |
8209 | = Fcons (posn, Qnil); | |
7ee32cda GM |
8210 | |
8211 | /* If on a mode line string with a local keymap, | |
8212 | reconsider the key sequence with that keymap. */ | |
8213 | if (CONSP (POSN_STRING (EVENT_START (key)))) | |
8214 | { | |
30690496 | 8215 | Lisp_Object string, pos, map, map2; |
7ee32cda GM |
8216 | |
8217 | string = POSN_STRING (EVENT_START (key)); | |
8218 | pos = XCDR (string); | |
8219 | string = XCAR (string); | |
52e386c2 KR |
8220 | if (XINT (pos) >= 0 |
8221 | && XINT (pos) < XSTRING (string)->size) | |
30690496 DL |
8222 | { |
8223 | map = Fget_text_property (pos, Qlocal_map, string); | |
8224 | if (!NILP (map)) | |
8225 | orig_local_map = map; | |
8226 | map2 = Fget_text_property (pos, Qkeymap, string); | |
8227 | if (!NILP (map2)) | |
8228 | orig_keymap = map2; | |
8229 | if (!NILP (map) || !NILP (map2)) | |
8230 | goto replay_sequence; | |
8231 | } | |
7ee32cda GM |
8232 | } |
8233 | ||
7e85b935 | 8234 | goto replay_key; |
5ec75a55 | 8235 | } |
0a7f1fc0 | 8236 | } |
7539e11f | 8237 | else if (CONSP (XCDR (key)) |
7a80a6f6 | 8238 | && CONSP (EVENT_START (key)) |
7539e11f | 8239 | && CONSP (XCDR (EVENT_START (key)))) |
7e85b935 | 8240 | { |
9b8eb840 | 8241 | Lisp_Object posn; |
7e85b935 | 8242 | |
9b8eb840 | 8243 | posn = POSN_BUFFER_POSN (EVENT_START (key)); |
7e85b935 RS |
8244 | /* Handle menu-bar events: |
8245 | insert the dummy prefix event `menu-bar'. */ | |
9ea173e8 | 8246 | if (EQ (posn, Qmenu_bar) || EQ (posn, Qtool_bar)) |
7e85b935 RS |
8247 | { |
8248 | if (t + 1 >= bufsize) | |
3fe8e9a2 | 8249 | error ("Key sequence too long"); |
7e85b935 RS |
8250 | keybuf[t] = posn; |
8251 | keybuf[t+1] = key; | |
8252 | ||
8253 | /* Zap the position in key, so we know that we've | |
8254 | expanded it, and don't try to do so again. */ | |
8255 | POSN_BUFFER_POSN (EVENT_START (key)) | |
8256 | = Fcons (posn, Qnil); | |
8257 | ||
8258 | mock_input = t + 2; | |
8259 | goto replay_sequence; | |
8260 | } | |
8c18cbfb | 8261 | else if (CONSP (posn)) |
7e85b935 RS |
8262 | { |
8263 | /* We're looking at the second event of a | |
8264 | sequence which we expanded before. Set | |
8265 | last_real_key_start appropriately. */ | |
8266 | if (last_real_key_start == t && t > 0) | |
8267 | last_real_key_start = t - 1; | |
8268 | } | |
a6d53864 | 8269 | } |
284f4730 | 8270 | } |
f4255cd1 JB |
8271 | |
8272 | /* We have finally decided that KEY is something we might want | |
8273 | to look up. */ | |
284f4730 JB |
8274 | first_binding = (follow_key (key, |
8275 | nmaps - first_binding, | |
253598e4 | 8276 | submaps + first_binding, |
284f4730 | 8277 | defs + first_binding, |
4e50f26a | 8278 | submaps + first_binding) |
284f4730 | 8279 | + first_binding); |
0a7f1fc0 | 8280 | |
f4255cd1 | 8281 | /* If KEY wasn't bound, we'll try some fallbacks. */ |
0a7f1fc0 JB |
8282 | if (first_binding >= nmaps) |
8283 | { | |
9b8eb840 | 8284 | Lisp_Object head; |
0a7f1fc0 | 8285 | |
9b8eb840 | 8286 | head = EVENT_HEAD (key); |
24736fbc | 8287 | if (help_char_p (head) && t > 0) |
7e85b935 RS |
8288 | { |
8289 | read_key_sequence_cmd = Vprefix_help_command; | |
8290 | keybuf[t++] = key; | |
8291 | last_nonmenu_event = key; | |
bc536d84 RS |
8292 | /* The Microsoft C compiler can't handle the goto that |
8293 | would go here. */ | |
309b0fc8 | 8294 | dummyflag = 1; |
0d882d52 | 8295 | break; |
7e85b935 RS |
8296 | } |
8297 | ||
8c18cbfb | 8298 | if (SYMBOLP (head)) |
0a7f1fc0 | 8299 | { |
9b8eb840 KH |
8300 | Lisp_Object breakdown; |
8301 | int modifiers; | |
0a7f1fc0 | 8302 | |
9b8eb840 | 8303 | breakdown = parse_modifiers (head); |
7539e11f | 8304 | modifiers = XINT (XCAR (XCDR (breakdown))); |
559f9d04 RS |
8305 | /* Attempt to reduce an unbound mouse event to a simpler |
8306 | event that is bound: | |
8307 | Drags reduce to clicks. | |
8308 | Double-clicks reduce to clicks. | |
8309 | Triple-clicks reduce to double-clicks, then to clicks. | |
8310 | Down-clicks are eliminated. | |
8311 | Double-downs reduce to downs, then are eliminated. | |
8312 | Triple-downs reduce to double-downs, then to downs, | |
8313 | then are eliminated. */ | |
8314 | if (modifiers & (down_modifier | drag_modifier | |
8315 | | double_modifier | triple_modifier)) | |
0a7f1fc0 | 8316 | { |
559f9d04 RS |
8317 | while (modifiers & (down_modifier | drag_modifier |
8318 | | double_modifier | triple_modifier)) | |
fbcd35bd JB |
8319 | { |
8320 | Lisp_Object new_head, new_click; | |
8321 | if (modifiers & triple_modifier) | |
8322 | modifiers ^= (double_modifier | triple_modifier); | |
bc536d84 RS |
8323 | else if (modifiers & double_modifier) |
8324 | modifiers &= ~double_modifier; | |
8325 | else if (modifiers & drag_modifier) | |
8326 | modifiers &= ~drag_modifier; | |
559f9d04 RS |
8327 | else |
8328 | { | |
8329 | /* Dispose of this `down' event by simply jumping | |
8330 | back to replay_key, to get another event. | |
8331 | ||
8332 | Note that if this event came from mock input, | |
8333 | then just jumping back to replay_key will just | |
8334 | hand it to us again. So we have to wipe out any | |
8335 | mock input. | |
8336 | ||
8337 | We could delete keybuf[t] and shift everything | |
8338 | after that to the left by one spot, but we'd also | |
8339 | have to fix up any variable that points into | |
8340 | keybuf, and shifting isn't really necessary | |
8341 | anyway. | |
8342 | ||
8343 | Adding prefixes for non-textual mouse clicks | |
8344 | creates two characters of mock input, and both | |
8345 | must be thrown away. If we're only looking at | |
8346 | the prefix now, we can just jump back to | |
8347 | replay_key. On the other hand, if we've already | |
8348 | processed the prefix, and now the actual click | |
8349 | itself is giving us trouble, then we've lost the | |
8350 | state of the keymaps we want to backtrack to, and | |
8351 | we need to replay the whole sequence to rebuild | |
8352 | it. | |
8353 | ||
8354 | Beyond that, only function key expansion could | |
8355 | create more than two keys, but that should never | |
8356 | generate mouse events, so it's okay to zero | |
8357 | mock_input in that case too. | |
8358 | ||
8359 | Isn't this just the most wonderful code ever? */ | |
8360 | if (t == last_real_key_start) | |
8361 | { | |
8362 | mock_input = 0; | |
8363 | goto replay_key; | |
8364 | } | |
8365 | else | |
8366 | { | |
8367 | mock_input = last_real_key_start; | |
8368 | goto replay_sequence; | |
8369 | } | |
8370 | } | |
8371 | ||
27203ead | 8372 | new_head |
7539e11f | 8373 | = apply_modifiers (modifiers, XCAR (breakdown)); |
27203ead RS |
8374 | new_click |
8375 | = Fcons (new_head, Fcons (EVENT_START (key), Qnil)); | |
fbcd35bd JB |
8376 | |
8377 | /* Look for a binding for this new key. follow_key | |
8378 | promises that it didn't munge submaps the | |
8379 | last time we called it, since key was unbound. */ | |
27203ead RS |
8380 | first_binding |
8381 | = (follow_key (new_click, | |
8382 | nmaps - local_first_binding, | |
8383 | submaps + local_first_binding, | |
8384 | defs + local_first_binding, | |
4e50f26a | 8385 | submaps + local_first_binding) |
27203ead | 8386 | + local_first_binding); |
fbcd35bd JB |
8387 | |
8388 | /* If that click is bound, go for it. */ | |
8389 | if (first_binding < nmaps) | |
8390 | { | |
8391 | key = new_click; | |
8392 | break; | |
8393 | } | |
8394 | /* Otherwise, we'll leave key set to the drag event. */ | |
8395 | } | |
0a7f1fc0 JB |
8396 | } |
8397 | } | |
8398 | } | |
8399 | ||
284f4730 | 8400 | keybuf[t++] = key; |
7d6de002 RS |
8401 | /* Normally, last_nonmenu_event gets the previous key we read. |
8402 | But when a mouse popup menu is being used, | |
8403 | we don't update last_nonmenu_event; it continues to hold the mouse | |
8404 | event that preceded the first level of menu. */ | |
8405 | if (!used_mouse_menu) | |
8406 | last_nonmenu_event = key; | |
284f4730 | 8407 | |
6321824f RS |
8408 | /* Record what part of this_command_keys is the current key sequence. */ |
8409 | this_single_command_key_start = this_command_key_count - t; | |
8410 | ||
3fe8e9a2 RS |
8411 | prev_fkey_map = fkey_map; |
8412 | prev_fkey_start = fkey_start; | |
8413 | prev_fkey_end = fkey_end; | |
8414 | ||
8415 | prev_keytran_map = keytran_map; | |
8416 | prev_keytran_start = keytran_start; | |
8417 | prev_keytran_end = keytran_end; | |
8418 | ||
284f4730 | 8419 | /* If the sequence is unbound, see if we can hang a function key |
253598e4 JB |
8420 | off the end of it. We only want to scan real keyboard input |
8421 | for function key sequences, so if mock_input says that we're | |
f4255cd1 | 8422 | re-reading old events, don't examine it. */ |
4e50f26a | 8423 | if (first_binding >= nmaps |
253598e4 | 8424 | && t >= mock_input) |
284f4730 JB |
8425 | { |
8426 | Lisp_Object fkey_next; | |
8427 | ||
e9bf89a0 RS |
8428 | /* Continue scan from fkey_end until we find a bound suffix. |
8429 | If we fail, increment fkey_start | |
8430 | and start fkey_end from there. */ | |
284f4730 JB |
8431 | while (fkey_end < t) |
8432 | { | |
f4255cd1 JB |
8433 | Lisp_Object key; |
8434 | ||
8435 | key = keybuf[fkey_end++]; | |
e74fbc70 | 8436 | fkey_next |
db785038 | 8437 | = access_keymap (fkey_map, key, 1, 0, 1); |
c700c260 RS |
8438 | |
8439 | /* Handle symbol with autoload definition. */ | |
0afc861b RS |
8440 | if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) |
8441 | && CONSP (XSYMBOL (fkey_next)->function) | |
7539e11f | 8442 | && EQ (XCAR (XSYMBOL (fkey_next)->function), Qautoload)) |
0afc861b RS |
8443 | do_autoload (XSYMBOL (fkey_next)->function, |
8444 | fkey_next); | |
c700c260 RS |
8445 | |
8446 | /* Handle a symbol whose function definition is a keymap | |
8447 | or an array. */ | |
0afc861b RS |
8448 | if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) |
8449 | && (!NILP (Farrayp (XSYMBOL (fkey_next)->function)) | |
02067692 | 8450 | || KEYMAPP (XSYMBOL (fkey_next)->function))) |
0afc861b | 8451 | fkey_next = XSYMBOL (fkey_next)->function; |
067ffa38 | 8452 | |
7a80a6f6 RS |
8453 | #if 0 /* I didn't turn this on, because it might cause trouble |
8454 | for the mapping of return into C-m and tab into C-i. */ | |
8455 | /* Optionally don't map function keys into other things. | |
8456 | This enables the user to redefine kp- keys easily. */ | |
8457 | if (SYMBOLP (key) && !NILP (Vinhibit_function_key_mapping)) | |
8458 | fkey_next = Qnil; | |
8459 | #endif | |
8460 | ||
1abe6abe RS |
8461 | /* If the function key map gives a function, not an |
8462 | array, then call the function with no args and use | |
8463 | its value instead. */ | |
8464 | if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) | |
8465 | && fkey_end == t) | |
8466 | { | |
8467 | struct gcpro gcpro1, gcpro2, gcpro3; | |
8468 | Lisp_Object tem; | |
8469 | tem = fkey_next; | |
8470 | ||
8471 | GCPRO3 (fkey_map, keytran_map, delayed_switch_frame); | |
84d91fda | 8472 | fkey_next = call1 (fkey_next, prompt); |
1abe6abe RS |
8473 | UNGCPRO; |
8474 | /* If the function returned something invalid, | |
8475 | barf--don't ignore it. | |
df0f2ba1 | 8476 | (To ignore it safely, we would need to gcpro a bunch of |
1abe6abe RS |
8477 | other variables.) */ |
8478 | if (! (VECTORP (fkey_next) || STRINGP (fkey_next))) | |
6321824f | 8479 | error ("Function in key-translation-map returns invalid key sequence"); |
1abe6abe RS |
8480 | } |
8481 | ||
e9bf89a0 RS |
8482 | function_key_possible = ! NILP (fkey_next); |
8483 | ||
85bc5181 | 8484 | /* If keybuf[fkey_start..fkey_end] is bound in the |
a764a753 | 8485 | function key map and it's a suffix of the current |
85bc5181 | 8486 | sequence (i.e. fkey_end == t), replace it with |
a764a753 | 8487 | the binding and restart with fkey_start at the end. */ |
f5ea6163 | 8488 | if ((VECTORP (fkey_next) || STRINGP (fkey_next)) |
284f4730 JB |
8489 | && fkey_end == t) |
8490 | { | |
2e864a76 | 8491 | int len = XFASTINT (Flength (fkey_next)); |
f5ea6163 JB |
8492 | |
8493 | t = fkey_start + len; | |
284f4730 | 8494 | if (t >= bufsize) |
3fe8e9a2 | 8495 | error ("Key sequence too long"); |
284f4730 | 8496 | |
f5ea6163 JB |
8497 | if (VECTORP (fkey_next)) |
8498 | bcopy (XVECTOR (fkey_next)->contents, | |
8499 | keybuf + fkey_start, | |
8500 | (t - fkey_start) * sizeof (keybuf[0])); | |
8501 | else if (STRINGP (fkey_next)) | |
8502 | { | |
8503 | int i; | |
8504 | ||
8505 | for (i = 0; i < len; i++) | |
bb9e9bed KH |
8506 | XSETFASTINT (keybuf[fkey_start + i], |
8507 | XSTRING (fkey_next)->data[i]); | |
f5ea6163 | 8508 | } |
df0f2ba1 | 8509 | |
284f4730 JB |
8510 | mock_input = t; |
8511 | fkey_start = fkey_end = t; | |
32e6d806 | 8512 | fkey_map = Vfunction_key_map; |
284f4730 | 8513 | |
3bd0dffb KH |
8514 | /* Do pass the results through key-translation-map. |
8515 | But don't retranslate what key-translation-map | |
8516 | has already translated. */ | |
8517 | keytran_end = keytran_start; | |
00a78037 RS |
8518 | keytran_map = Vkey_translation_map; |
8519 | ||
f4255cd1 | 8520 | goto replay_sequence; |
284f4730 | 8521 | } |
df0f2ba1 | 8522 | |
02067692 | 8523 | fkey_map = get_keymap (fkey_next, 0, 1); |
284f4730 | 8524 | |
df0f2ba1 | 8525 | /* If we no longer have a bound suffix, try a new positions for |
a764a753 | 8526 | fkey_start. */ |
02067692 | 8527 | if (!CONSP (fkey_map)) |
284f4730 JB |
8528 | { |
8529 | fkey_end = ++fkey_start; | |
8530 | fkey_map = Vfunction_key_map; | |
e9bf89a0 | 8531 | function_key_possible = 0; |
284f4730 JB |
8532 | } |
8533 | } | |
8534 | } | |
a612e298 RS |
8535 | |
8536 | /* Look for this sequence in key-translation-map. */ | |
8537 | { | |
8538 | Lisp_Object keytran_next; | |
8539 | ||
8540 | /* Scan from keytran_end until we find a bound suffix. */ | |
8541 | while (keytran_end < t) | |
8542 | { | |
8543 | Lisp_Object key; | |
8544 | ||
8545 | key = keybuf[keytran_end++]; | |
a612e298 | 8546 | keytran_next |
db785038 | 8547 | = access_keymap (keytran_map, key, 1, 0, 1); |
a612e298 | 8548 | |
c700c260 | 8549 | /* Handle symbol with autoload definition. */ |
e83f6bb0 RS |
8550 | if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) |
8551 | && CONSP (XSYMBOL (keytran_next)->function) | |
7539e11f | 8552 | && EQ (XCAR (XSYMBOL (keytran_next)->function), Qautoload)) |
e83f6bb0 RS |
8553 | do_autoload (XSYMBOL (keytran_next)->function, |
8554 | keytran_next); | |
8555 | ||
c700c260 RS |
8556 | /* Handle a symbol whose function definition is a keymap |
8557 | or an array. */ | |
e83f6bb0 | 8558 | if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) |
c700c260 | 8559 | && (!NILP (Farrayp (XSYMBOL (keytran_next)->function)) |
02067692 | 8560 | || KEYMAPP (XSYMBOL (keytran_next)->function))) |
e83f6bb0 RS |
8561 | keytran_next = XSYMBOL (keytran_next)->function; |
8562 | ||
1abe6abe | 8563 | /* If the key translation map gives a function, not an |
e83f6bb0 | 8564 | array, then call the function with one arg and use |
1abe6abe RS |
8565 | its value instead. */ |
8566 | if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) | |
8567 | && keytran_end == t) | |
8568 | { | |
8569 | struct gcpro gcpro1, gcpro2, gcpro3; | |
8570 | Lisp_Object tem; | |
8571 | tem = keytran_next; | |
8572 | ||
40932d1a | 8573 | GCPRO3 (fkey_map, keytran_map, delayed_switch_frame); |
84d91fda | 8574 | keytran_next = call1 (keytran_next, prompt); |
1abe6abe RS |
8575 | UNGCPRO; |
8576 | /* If the function returned something invalid, | |
8577 | barf--don't ignore it. | |
df0f2ba1 | 8578 | (To ignore it safely, we would need to gcpro a bunch of |
1abe6abe RS |
8579 | other variables.) */ |
8580 | if (! (VECTORP (keytran_next) || STRINGP (keytran_next))) | |
40932d1a | 8581 | error ("Function in key-translation-map returns invalid key sequence"); |
1abe6abe RS |
8582 | } |
8583 | ||
00a78037 RS |
8584 | key_translation_possible = ! NILP (keytran_next); |
8585 | ||
a612e298 | 8586 | /* If keybuf[keytran_start..keytran_end] is bound in the |
1abe6abe | 8587 | key translation map and it's a suffix of the current |
a612e298 RS |
8588 | sequence (i.e. keytran_end == t), replace it with |
8589 | the binding and restart with keytran_start at the end. */ | |
8590 | if ((VECTORP (keytran_next) || STRINGP (keytran_next)) | |
8591 | && keytran_end == t) | |
8592 | { | |
2e864a76 | 8593 | int len = XFASTINT (Flength (keytran_next)); |
a612e298 RS |
8594 | |
8595 | t = keytran_start + len; | |
8596 | if (t >= bufsize) | |
3fe8e9a2 | 8597 | error ("Key sequence too long"); |
a612e298 RS |
8598 | |
8599 | if (VECTORP (keytran_next)) | |
8600 | bcopy (XVECTOR (keytran_next)->contents, | |
8601 | keybuf + keytran_start, | |
8602 | (t - keytran_start) * sizeof (keybuf[0])); | |
8603 | else if (STRINGP (keytran_next)) | |
8604 | { | |
8605 | int i; | |
8606 | ||
8607 | for (i = 0; i < len; i++) | |
bb9e9bed KH |
8608 | XSETFASTINT (keybuf[keytran_start + i], |
8609 | XSTRING (keytran_next)->data[i]); | |
a612e298 RS |
8610 | } |
8611 | ||
8612 | mock_input = t; | |
8613 | keytran_start = keytran_end = t; | |
8614 | keytran_map = Vkey_translation_map; | |
8615 | ||
00a78037 RS |
8616 | /* Don't pass the results of key-translation-map |
8617 | through function-key-map. */ | |
8618 | fkey_start = fkey_end = t; | |
3bd0dffb | 8619 | fkey_map = Vfunction_key_map; |
00a78037 | 8620 | |
a612e298 RS |
8621 | goto replay_sequence; |
8622 | } | |
8623 | ||
02067692 | 8624 | keytran_map = get_keymap (keytran_next, 0, 1); |
a612e298 | 8625 | |
df0f2ba1 | 8626 | /* If we no longer have a bound suffix, try a new positions for |
a612e298 | 8627 | keytran_start. */ |
02067692 | 8628 | if (!CONSP (keytran_map)) |
a612e298 RS |
8629 | { |
8630 | keytran_end = ++keytran_start; | |
8631 | keytran_map = Vkey_translation_map; | |
00a78037 | 8632 | key_translation_possible = 0; |
a612e298 RS |
8633 | } |
8634 | } | |
8635 | } | |
4e50f26a RS |
8636 | |
8637 | /* If KEY is not defined in any of the keymaps, | |
8638 | and cannot be part of a function key or translation, | |
8639 | and is an upper case letter | |
8640 | use the corresponding lower-case letter instead. */ | |
8641 | if (first_binding == nmaps && ! function_key_possible | |
00a78037 | 8642 | && ! key_translation_possible |
8c18cbfb | 8643 | && INTEGERP (key) |
4e50f26a | 8644 | && ((((XINT (key) & 0x3ffff) |
301738ed | 8645 | < XCHAR_TABLE (current_buffer->downcase_table)->size) |
4e50f26a RS |
8646 | && UPPERCASEP (XINT (key) & 0x3ffff)) |
8647 | || (XINT (key) & shift_modifier))) | |
8648 | { | |
569871d2 | 8649 | Lisp_Object new_key; |
569871d2 | 8650 | |
309b0fc8 RS |
8651 | original_uppercase = key; |
8652 | original_uppercase_position = t - 1; | |
8653 | ||
831f35a2 | 8654 | if (XINT (key) & shift_modifier) |
569871d2 | 8655 | XSETINT (new_key, XINT (key) & ~shift_modifier); |
4e50f26a | 8656 | else |
569871d2 RS |
8657 | XSETINT (new_key, (DOWNCASE (XINT (key) & 0x3ffff) |
8658 | | (XINT (key) & ~0x3ffff))); | |
8659 | ||
3fe8e9a2 RS |
8660 | /* We have to do this unconditionally, regardless of whether |
8661 | the lower-case char is defined in the keymaps, because they | |
8662 | might get translated through function-key-map. */ | |
8663 | keybuf[t - 1] = new_key; | |
8664 | mock_input = t; | |
8665 | ||
8666 | fkey_map = prev_fkey_map; | |
8667 | fkey_start = prev_fkey_start; | |
8668 | fkey_end = prev_fkey_end; | |
8669 | ||
8670 | keytran_map = prev_keytran_map; | |
8671 | keytran_start = prev_keytran_start; | |
8672 | keytran_end = prev_keytran_end; | |
8673 | ||
8674 | goto replay_sequence; | |
4e50f26a | 8675 | } |
ef8fd672 RS |
8676 | /* If KEY is not defined in any of the keymaps, |
8677 | and cannot be part of a function key or translation, | |
8678 | and is a shifted function key, | |
8679 | use the corresponding unshifted function key instead. */ | |
8680 | if (first_binding == nmaps && ! function_key_possible | |
8681 | && ! key_translation_possible | |
8682 | && SYMBOLP (key)) | |
8683 | { | |
8684 | Lisp_Object breakdown; | |
8685 | int modifiers; | |
8686 | ||
8687 | breakdown = parse_modifiers (key); | |
7539e11f | 8688 | modifiers = XINT (XCAR (XCDR (breakdown))); |
ef8fd672 RS |
8689 | if (modifiers & shift_modifier) |
8690 | { | |
569871d2 | 8691 | Lisp_Object new_key; |
3fe8e9a2 RS |
8692 | |
8693 | original_uppercase = key; | |
8694 | original_uppercase_position = t - 1; | |
ef8fd672 | 8695 | |
569871d2 RS |
8696 | modifiers &= ~shift_modifier; |
8697 | new_key = apply_modifiers (modifiers, | |
7539e11f | 8698 | XCAR (breakdown)); |
569871d2 | 8699 | |
3fe8e9a2 RS |
8700 | keybuf[t - 1] = new_key; |
8701 | mock_input = t; | |
8702 | ||
8703 | fkey_map = prev_fkey_map; | |
8704 | fkey_start = prev_fkey_start; | |
8705 | fkey_end = prev_fkey_end; | |
8706 | ||
8707 | keytran_map = prev_keytran_map; | |
8708 | keytran_start = prev_keytran_start; | |
8709 | keytran_end = prev_keytran_end; | |
8710 | ||
8711 | goto replay_sequence; | |
ef8fd672 RS |
8712 | } |
8713 | } | |
284f4730 JB |
8714 | } |
8715 | ||
309b0fc8 | 8716 | if (!dummyflag) |
bc536d84 RS |
8717 | read_key_sequence_cmd = (first_binding < nmaps |
8718 | ? defs[first_binding] | |
8719 | : Qnil); | |
284f4730 | 8720 | |
cd21b839 | 8721 | unread_switch_frame = delayed_switch_frame; |
f4255cd1 | 8722 | unbind_to (count, Qnil); |
07f76a14 | 8723 | |
3fe8e9a2 RS |
8724 | /* Don't downcase the last character if the caller says don't. |
8725 | Don't downcase it if the result is undefined, either. */ | |
8726 | if ((dont_downcase_last || first_binding >= nmaps) | |
8727 | && t - 1 == original_uppercase_position) | |
309b0fc8 RS |
8728 | keybuf[t - 1] = original_uppercase; |
8729 | ||
07f76a14 JB |
8730 | /* Occasionally we fabricate events, perhaps by expanding something |
8731 | according to function-key-map, or by adding a prefix symbol to a | |
8732 | mouse click in the scroll bar or modeline. In this cases, return | |
8733 | the entire generated key sequence, even if we hit an unbound | |
8734 | prefix or a definition before the end. This means that you will | |
8735 | be able to push back the event properly, and also means that | |
8736 | read-key-sequence will always return a logical unit. | |
8737 | ||
8738 | Better ideas? */ | |
cca310da JB |
8739 | for (; t < mock_input; t++) |
8740 | { | |
f2647d04 DL |
8741 | if ((FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes)) |
8742 | && NILP (Fzerop (Vecho_keystrokes))) | |
a98ea3f9 | 8743 | echo_char (keybuf[t]); |
cca310da JB |
8744 | add_command_key (keybuf[t]); |
8745 | } | |
07f76a14 | 8746 | |
7d18f9ae RS |
8747 | |
8748 | ||
284f4730 JB |
8749 | return t; |
8750 | } | |
8751 | ||
a612e298 RS |
8752 | #if 0 /* This doc string is too long for some compilers. |
8753 | This commented-out definition serves for DOC. */ | |
ce98e608 | 8754 | DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 4, 0, |
284f4730 JB |
8755 | "Read a sequence of keystrokes and return as a string or vector.\n\ |
8756 | The sequence is sufficient to specify a non-prefix command in the\n\ | |
8757 | current local and global maps.\n\ | |
8758 | \n\ | |
c0a58692 RS |
8759 | First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\ |
8760 | Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\ | |
8761 | as a continuation of the previous key.\n\ | |
284f4730 | 8762 | \n\ |
309b0fc8 RS |
8763 | The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\ |
8764 | convert the last event to lower case. (Normally any upper case event\n\ | |
8765 | is converted to lower case if the original event is undefined and the lower\n\ | |
8766 | case equivalent is defined.) A non-nil value is appropriate for reading\n\ | |
8767 | a key sequence to be defined.\n\ | |
8768 | \n\ | |
cb5df6ae JB |
8769 | A C-g typed while in this function is treated like any other character,\n\ |
8770 | and `quit-flag' is not set.\n\ | |
8771 | \n\ | |
8772 | If the key sequence starts with a mouse click, then the sequence is read\n\ | |
8773 | using the keymaps of the buffer of the window clicked in, not the buffer\n\ | |
8774 | of the selected window as normal.\n\ | |
ede41463 | 8775 | ""\n\ |
cb5df6ae JB |
8776 | `read-key-sequence' drops unbound button-down events, since you normally\n\ |
8777 | only care about the click or drag events which follow them. If a drag\n\ | |
fbcd35bd JB |
8778 | or multi-click event is unbound, but the corresponding click event would\n\ |
8779 | be bound, `read-key-sequence' turns the event into a click event at the\n\ | |
cb5df6ae | 8780 | drag's starting position. This means that you don't have to distinguish\n\ |
fbcd35bd | 8781 | between click and drag, double, or triple events unless you want to.\n\ |
cb5df6ae JB |
8782 | \n\ |
8783 | `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\ | |
3c370943 JB |
8784 | lines separating windows, and scroll bars with imaginary keys\n\ |
8785 | `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\ | |
cb5df6ae | 8786 | \n\ |
ce98e608 KH |
8787 | Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\ |
8788 | function will process a switch-frame event if the user switches frames\n\ | |
8789 | before typing anything. If the user switches frames in the middle of a\n\ | |
8790 | key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\ | |
8791 | is nil, then the event will be put off until after the current key sequence.\n\ | |
cb5df6ae JB |
8792 | \n\ |
8793 | `read-key-sequence' checks `function-key-map' for function key\n\ | |
8794 | sequences, where they wouldn't conflict with ordinary bindings. See\n\ | |
d5eecefb RS |
8795 | `function-key-map' for more details.\n\ |
8796 | \n\ | |
8797 | The optional fifth argument COMMAND-LOOP, if non-nil, means\n\ | |
8798 | that this key sequence is being read by something that will\n\ | |
8799 | read commands one after another. It should be nil if the caller\n\ | |
8800 | will read just one key sequence.") | |
b638f328 | 8801 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame, command-loop) |
a612e298 RS |
8802 | #endif |
8803 | ||
d5eecefb | 8804 | DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0, |
a612e298 | 8805 | 0) |
d5eecefb RS |
8806 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame, |
8807 | command_loop) | |
309b0fc8 | 8808 | Lisp_Object prompt, continue_echo, dont_downcase_last; |
d5eecefb | 8809 | Lisp_Object can_return_switch_frame, command_loop; |
284f4730 JB |
8810 | { |
8811 | Lisp_Object keybuf[30]; | |
8812 | register int i; | |
03cee6ae | 8813 | struct gcpro gcpro1; |
d5eecefb | 8814 | int count = specpdl_ptr - specpdl; |
284f4730 JB |
8815 | |
8816 | if (!NILP (prompt)) | |
8817 | CHECK_STRING (prompt, 0); | |
8818 | QUIT; | |
8819 | ||
d5eecefb RS |
8820 | specbind (Qinput_method_exit_on_first_char, |
8821 | (NILP (command_loop) ? Qt : Qnil)); | |
8822 | specbind (Qinput_method_use_echo_area, | |
8823 | (NILP (command_loop) ? Qt : Qnil)); | |
8824 | ||
284f4730 JB |
8825 | bzero (keybuf, sizeof keybuf); |
8826 | GCPRO1 (keybuf[0]); | |
8827 | gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); | |
8828 | ||
daa37602 | 8829 | if (NILP (continue_echo)) |
6321824f RS |
8830 | { |
8831 | this_command_key_count = 0; | |
8832 | this_single_command_key_start = 0; | |
8833 | } | |
c0a58692 | 8834 | |
d0c48478 GM |
8835 | #ifdef HAVE_X_WINDOWS |
8836 | if (display_busy_cursor_p) | |
8837 | cancel_busy_cursor (); | |
8838 | #endif | |
8839 | ||
309b0fc8 | 8840 | i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), |
ce98e608 | 8841 | prompt, ! NILP (dont_downcase_last), |
f571ae0d | 8842 | ! NILP (can_return_switch_frame), 0); |
284f4730 | 8843 | |
d0c48478 GM |
8844 | #ifdef HAVE_X_WINDOWS |
8845 | if (display_busy_cursor_p) | |
8846 | start_busy_cursor (); | |
8847 | #endif | |
8848 | ||
dcc408a0 RS |
8849 | if (i == -1) |
8850 | { | |
8851 | Vquit_flag = Qt; | |
8852 | QUIT; | |
8853 | } | |
284f4730 | 8854 | UNGCPRO; |
d5eecefb | 8855 | return unbind_to (count, make_event_array (i, keybuf)); |
284f4730 | 8856 | } |
e39da3d7 RS |
8857 | |
8858 | DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector, | |
d5eecefb | 8859 | Sread_key_sequence_vector, 1, 5, 0, |
e39da3d7 | 8860 | "Like `read-key-sequence' but always return a vector.") |
d5eecefb RS |
8861 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame, |
8862 | command_loop) | |
e39da3d7 | 8863 | Lisp_Object prompt, continue_echo, dont_downcase_last; |
d5eecefb | 8864 | Lisp_Object can_return_switch_frame, command_loop; |
e39da3d7 RS |
8865 | { |
8866 | Lisp_Object keybuf[30]; | |
8867 | register int i; | |
03cee6ae | 8868 | struct gcpro gcpro1; |
d5eecefb | 8869 | int count = specpdl_ptr - specpdl; |
e39da3d7 RS |
8870 | |
8871 | if (!NILP (prompt)) | |
8872 | CHECK_STRING (prompt, 0); | |
8873 | QUIT; | |
8874 | ||
d5eecefb RS |
8875 | specbind (Qinput_method_exit_on_first_char, |
8876 | (NILP (command_loop) ? Qt : Qnil)); | |
8877 | specbind (Qinput_method_use_echo_area, | |
8878 | (NILP (command_loop) ? Qt : Qnil)); | |
8879 | ||
e39da3d7 RS |
8880 | bzero (keybuf, sizeof keybuf); |
8881 | GCPRO1 (keybuf[0]); | |
8882 | gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); | |
8883 | ||
8884 | if (NILP (continue_echo)) | |
8885 | { | |
8886 | this_command_key_count = 0; | |
8887 | this_single_command_key_start = 0; | |
8888 | } | |
8889 | ||
d0c48478 GM |
8890 | #ifdef HAVE_X_WINDOWS |
8891 | if (display_busy_cursor_p) | |
8892 | cancel_busy_cursor (); | |
8893 | #endif | |
8894 | ||
e39da3d7 RS |
8895 | i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), |
8896 | prompt, ! NILP (dont_downcase_last), | |
8897 | ! NILP (can_return_switch_frame), 0); | |
8898 | ||
d0c48478 GM |
8899 | #ifdef HAVE_X_WINDOWS |
8900 | if (display_busy_cursor_p) | |
8901 | start_busy_cursor (); | |
8902 | #endif | |
8903 | ||
e39da3d7 RS |
8904 | if (i == -1) |
8905 | { | |
8906 | Vquit_flag = Qt; | |
8907 | QUIT; | |
8908 | } | |
8909 | UNGCPRO; | |
d5eecefb | 8910 | return unbind_to (count, Fvector (i, keybuf)); |
e39da3d7 | 8911 | } |
284f4730 | 8912 | \f |
158f7532 | 8913 | DEFUN ("command-execute", Fcommand_execute, Scommand_execute, 1, 4, 0, |
284f4730 JB |
8914 | "Execute CMD as an editor command.\n\ |
8915 | CMD must be a symbol that satisfies the `commandp' predicate.\n\ | |
8916 | Optional second arg RECORD-FLAG non-nil\n\ | |
8917 | means unconditionally put this command in `command-history'.\n\ | |
aaf2ead7 RS |
8918 | Otherwise, that is done only if an arg is read using the minibuffer.\n\ |
8919 | The argument KEYS specifies the value to use instead of (this-command-keys)\n\ | |
6321824f | 8920 | when reading the arguments; if it is nil, (this-command-keys) is used.\n\ |
158f7532 RS |
8921 | The argument SPECIAL, if non-nil, means that this command is executing\n\ |
8922 | a special event, so ignore the prefix argument and don't clear it.") | |
8923 | (cmd, record_flag, keys, special) | |
8924 | Lisp_Object cmd, record_flag, keys, special; | |
284f4730 JB |
8925 | { |
8926 | register Lisp_Object final; | |
8927 | register Lisp_Object tem; | |
8928 | Lisp_Object prefixarg; | |
8929 | struct backtrace backtrace; | |
8930 | extern int debug_on_next_call; | |
8931 | ||
284f4730 JB |
8932 | debug_on_next_call = 0; |
8933 | ||
158f7532 RS |
8934 | if (NILP (special)) |
8935 | { | |
8936 | prefixarg = current_kboard->Vprefix_arg; | |
8937 | Vcurrent_prefix_arg = prefixarg; | |
8938 | current_kboard->Vprefix_arg = Qnil; | |
8939 | } | |
8940 | else | |
8941 | prefixarg = Qnil; | |
8942 | ||
8c18cbfb | 8943 | if (SYMBOLP (cmd)) |
284f4730 JB |
8944 | { |
8945 | tem = Fget (cmd, Qdisabled); | |
88ce066e | 8946 | if (!NILP (tem) && !NILP (Vrun_hooks)) |
b78ce8fb RS |
8947 | { |
8948 | tem = Fsymbol_value (Qdisabled_command_hook); | |
8949 | if (!NILP (tem)) | |
8950 | return call1 (Vrun_hooks, Qdisabled_command_hook); | |
8951 | } | |
284f4730 JB |
8952 | } |
8953 | ||
01e26217 | 8954 | while (1) |
284f4730 | 8955 | { |
ffd56f97 | 8956 | final = Findirect_function (cmd); |
284f4730 JB |
8957 | |
8958 | if (CONSP (final) && (tem = Fcar (final), EQ (tem, Qautoload))) | |
b516a185 RS |
8959 | { |
8960 | struct gcpro gcpro1, gcpro2; | |
8961 | ||
8962 | GCPRO2 (cmd, prefixarg); | |
8963 | do_autoload (final, cmd); | |
8964 | UNGCPRO; | |
8965 | } | |
284f4730 JB |
8966 | else |
8967 | break; | |
8968 | } | |
8969 | ||
8c18cbfb | 8970 | if (STRINGP (final) || VECTORP (final)) |
284f4730 JB |
8971 | { |
8972 | /* If requested, place the macro in the command history. For | |
8973 | other sorts of commands, call-interactively takes care of | |
8974 | this. */ | |
e57d8fd8 | 8975 | if (!NILP (record_flag)) |
f4385381 RS |
8976 | { |
8977 | Vcommand_history | |
8978 | = Fcons (Fcons (Qexecute_kbd_macro, | |
8979 | Fcons (final, Fcons (prefixarg, Qnil))), | |
8980 | Vcommand_history); | |
8981 | ||
8982 | /* Don't keep command history around forever. */ | |
8983 | if (NUMBERP (Vhistory_length) && XINT (Vhistory_length) > 0) | |
8984 | { | |
8985 | tem = Fnthcdr (Vhistory_length, Vcommand_history); | |
8986 | if (CONSP (tem)) | |
7539e11f | 8987 | XCDR (tem) = Qnil; |
f4385381 RS |
8988 | } |
8989 | } | |
284f4730 JB |
8990 | |
8991 | return Fexecute_kbd_macro (final, prefixarg); | |
8992 | } | |
f4385381 | 8993 | |
8c18cbfb | 8994 | if (CONSP (final) || SUBRP (final) || COMPILEDP (final)) |
284f4730 JB |
8995 | { |
8996 | backtrace.next = backtrace_list; | |
8997 | backtrace_list = &backtrace; | |
8998 | backtrace.function = &Qcall_interactively; | |
8999 | backtrace.args = &cmd; | |
9000 | backtrace.nargs = 1; | |
9001 | backtrace.evalargs = 0; | |
9002 | ||
e57d8fd8 | 9003 | tem = Fcall_interactively (cmd, record_flag, keys); |
284f4730 JB |
9004 | |
9005 | backtrace_list = backtrace.next; | |
9006 | return tem; | |
9007 | } | |
9008 | return Qnil; | |
9009 | } | |
9010 | \f | |
284f4730 JB |
9011 | DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_command, |
9012 | 1, 1, "P", | |
9013 | "Read function name, then read its arguments and call it.") | |
9014 | (prefixarg) | |
9015 | Lisp_Object prefixarg; | |
9016 | { | |
9017 | Lisp_Object function; | |
9018 | char buf[40]; | |
9019 | Lisp_Object saved_keys; | |
5434fce6 | 9020 | Lisp_Object bindings, value; |
214360e9 | 9021 | struct gcpro gcpro1, gcpro2; |
284f4730 | 9022 | |
b0f2a7bf KH |
9023 | saved_keys = Fvector (this_command_key_count, |
9024 | XVECTOR (this_command_keys)->contents); | |
284f4730 | 9025 | buf[0] = 0; |
fde7aff8 | 9026 | GCPRO2 (saved_keys, prefixarg); |
284f4730 JB |
9027 | |
9028 | if (EQ (prefixarg, Qminus)) | |
9029 | strcpy (buf, "- "); | |
7539e11f | 9030 | else if (CONSP (prefixarg) && XINT (XCAR (prefixarg)) == 4) |
284f4730 | 9031 | strcpy (buf, "C-u "); |
7539e11f | 9032 | else if (CONSP (prefixarg) && INTEGERP (XCAR (prefixarg))) |
5d5b907f RS |
9033 | { |
9034 | if (sizeof (int) == sizeof (EMACS_INT)) | |
7539e11f | 9035 | sprintf (buf, "%d ", XINT (XCAR (prefixarg))); |
5d5b907f | 9036 | else if (sizeof (long) == sizeof (EMACS_INT)) |
7539e11f | 9037 | sprintf (buf, "%ld ", (long) XINT (XCAR (prefixarg))); |
5d5b907f RS |
9038 | else |
9039 | abort (); | |
9040 | } | |
8c18cbfb | 9041 | else if (INTEGERP (prefixarg)) |
5d5b907f RS |
9042 | { |
9043 | if (sizeof (int) == sizeof (EMACS_INT)) | |
9044 | sprintf (buf, "%d ", XINT (prefixarg)); | |
9045 | else if (sizeof (long) == sizeof (EMACS_INT)) | |
03cee6ae | 9046 | sprintf (buf, "%ld ", (long) XINT (prefixarg)); |
5d5b907f RS |
9047 | else |
9048 | abort (); | |
9049 | } | |
284f4730 JB |
9050 | |
9051 | /* This isn't strictly correct if execute-extended-command | |
9052 | is bound to anything else. Perhaps it should use | |
9053 | this_command_keys? */ | |
9054 | strcat (buf, "M-x "); | |
9055 | ||
9056 | /* Prompt with buf, and then read a string, completing from and | |
9057 | restricting to the set of all defined commands. Don't provide | |
51763820 | 9058 | any initial input. Save the command read on the extended-command |
03b4122a | 9059 | history list. */ |
284f4730 JB |
9060 | function = Fcompleting_read (build_string (buf), |
9061 | Vobarray, Qcommandp, | |
4328577a KH |
9062 | Qt, Qnil, Qextended_command_history, Qnil, |
9063 | Qnil); | |
284f4730 | 9064 | |
1f5b1641 RS |
9065 | if (STRINGP (function) && XSTRING (function)->size == 0) |
9066 | error ("No command name given"); | |
9067 | ||
1113d9db JB |
9068 | /* Set this_command_keys to the concatenation of saved_keys and |
9069 | function, followed by a RET. */ | |
284f4730 | 9070 | { |
1113d9db | 9071 | struct Lisp_String *str; |
b0f2a7bf | 9072 | Lisp_Object *keys; |
284f4730 | 9073 | int i; |
284f4730 | 9074 | |
1113d9db | 9075 | this_command_key_count = 0; |
6321824f | 9076 | this_single_command_key_start = 0; |
1113d9db | 9077 | |
b0f2a7bf KH |
9078 | keys = XVECTOR (saved_keys)->contents; |
9079 | for (i = 0; i < XVECTOR (saved_keys)->size; i++) | |
9080 | add_command_key (keys[i]); | |
1113d9db JB |
9081 | |
9082 | str = XSTRING (function); | |
9083 | for (i = 0; i < str->size; i++) | |
301738ed | 9084 | add_command_key (Faref (function, make_number (i))); |
1113d9db | 9085 | |
301738ed | 9086 | add_command_key (make_number ('\015')); |
284f4730 JB |
9087 | } |
9088 | ||
9089 | UNGCPRO; | |
9090 | ||
0a7f1fc0 | 9091 | function = Fintern (function, Qnil); |
d8bcf58e | 9092 | current_kboard->Vprefix_arg = prefixarg; |
d5eecefb RS |
9093 | Vthis_command = function; |
9094 | real_this_command = function; | |
284f4730 | 9095 | |
6526ab49 RS |
9096 | /* If enabled, show which key runs this command. */ |
9097 | if (!NILP (Vsuggest_key_bindings) | |
71012575 | 9098 | && NILP (Vexecuting_macro) |
6526ab49 | 9099 | && SYMBOLP (function)) |
5434fce6 RS |
9100 | bindings = Fwhere_is_internal (function, Voverriding_local_map, |
9101 | Qt, Qnil); | |
9102 | else | |
9103 | bindings = Qnil; | |
6526ab49 | 9104 | |
5434fce6 RS |
9105 | value = Qnil; |
9106 | GCPRO2 (bindings, value); | |
9107 | value = Fcommand_execute (function, Qt, Qnil, Qnil); | |
6526ab49 | 9108 | |
5434fce6 | 9109 | /* If the command has a key binding, print it now. */ |
3ababa60 | 9110 | if (!NILP (bindings) |
ee112567 KH |
9111 | && ! (VECTORP (bindings) && EQ (Faref (bindings, make_number (0)), |
9112 | Qmouse_movement))) | |
5434fce6 RS |
9113 | { |
9114 | /* But first wait, and skip the message if there is input. */ | |
426939cc | 9115 | int delay_time; |
985f9f66 | 9116 | if (!NILP (echo_area_buffer[0])) |
426939cc RS |
9117 | /* This command displayed something in the echo area; |
9118 | so wait a few seconds, then display our suggestion message. */ | |
9119 | delay_time = (NUMBERP (Vsuggest_key_bindings) | |
9120 | ? XINT (Vsuggest_key_bindings) : 2); | |
9121 | else | |
9122 | /* This command left the echo area empty, | |
9123 | so display our message immediately. */ | |
9124 | delay_time = 0; | |
9125 | ||
9126 | if (!NILP (Fsit_for (make_number (delay_time), Qnil, Qnil)) | |
303b5b3f | 9127 | && ! CONSP (Vunread_command_events)) |
6526ab49 | 9128 | { |
5434fce6 RS |
9129 | Lisp_Object binding; |
9130 | char *newmessage; | |
985f9f66 | 9131 | int message_p = push_message (); |
5434fce6 RS |
9132 | |
9133 | binding = Fkey_description (bindings); | |
9134 | ||
9135 | newmessage | |
9136 | = (char *) alloca (XSYMBOL (function)->name->size | |
fc932ac6 | 9137 | + STRING_BYTES (XSTRING (binding)) |
5434fce6 | 9138 | + 100); |
3ababa60 | 9139 | sprintf (newmessage, "You can run the command `%s' with %s", |
6526ab49 | 9140 | XSYMBOL (function)->name->data, |
5434fce6 | 9141 | XSTRING (binding)->data); |
301738ed RS |
9142 | message2_nolog (newmessage, |
9143 | strlen (newmessage), | |
9144 | STRING_MULTIBYTE (binding)); | |
5434fce6 RS |
9145 | if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings) |
9146 | ? Vsuggest_key_bindings : make_number (2)), | |
985f9f66 GM |
9147 | Qnil, Qnil)) |
9148 | && message_p) | |
9149 | restore_message (); | |
9150 | ||
9151 | pop_message (); | |
6526ab49 RS |
9152 | } |
9153 | } | |
9154 | ||
5434fce6 | 9155 | RETURN_UNGCPRO (value); |
284f4730 | 9156 | } |
6526ab49 RS |
9157 | |
9158 | /* Find the set of keymaps now active. | |
9159 | Store into *MAPS_P a vector holding the various maps | |
9160 | and return the number of them. The vector was malloc'd | |
9161 | and the caller should free it. */ | |
9162 | ||
9163 | int | |
9164 | current_active_maps (maps_p) | |
9165 | Lisp_Object **maps_p; | |
9166 | { | |
9167 | Lisp_Object *tmaps, *maps; | |
9168 | int nmaps; | |
9169 | ||
9170 | /* Should overriding-terminal-local-map and overriding-local-map apply? */ | |
9171 | if (!NILP (Voverriding_local_map_menu_flag)) | |
9172 | { | |
9173 | /* Yes, use them (if non-nil) as well as the global map. */ | |
9174 | maps = (Lisp_Object *) xmalloc (3 * sizeof (maps[0])); | |
9175 | nmaps = 0; | |
9176 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
9177 | maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
9178 | if (!NILP (Voverriding_local_map)) | |
9179 | maps[nmaps++] = Voverriding_local_map; | |
9180 | } | |
9181 | else | |
9182 | { | |
30690496 DL |
9183 | /* No, so use major and minor mode keymaps and keymap property. */ |
9184 | int extra_maps = 2; | |
9185 | Lisp_Object map = get_local_map (PT, current_buffer, keymap); | |
9186 | if (!NILP (map)) | |
9187 | extra_maps = 3; | |
6526ab49 | 9188 | nmaps = current_minor_maps (NULL, &tmaps); |
30690496 DL |
9189 | maps = (Lisp_Object *) alloca ((nmaps + extra_maps) |
9190 | * sizeof (maps[0])); | |
6526ab49 | 9191 | bcopy (tmaps, maps, nmaps * sizeof (maps[0])); |
30690496 | 9192 | if (!NILP (map)) |
9f83cf0b | 9193 | maps[nmaps++] = map; |
30690496 | 9194 | maps[nmaps++] = get_local_map (PT, current_buffer, local_map); |
6526ab49 RS |
9195 | } |
9196 | maps[nmaps++] = current_global_map; | |
9197 | ||
9198 | *maps_p = maps; | |
9199 | return nmaps; | |
9200 | } | |
284f4730 | 9201 | \f |
d9d4c147 | 9202 | /* Return nonzero if input events are pending. */ |
284f4730 | 9203 | |
dfcf069d | 9204 | int |
284f4730 JB |
9205 | detect_input_pending () |
9206 | { | |
9207 | if (!input_pending) | |
d9d4c147 KH |
9208 | get_input_pending (&input_pending, 0); |
9209 | ||
9210 | return input_pending; | |
9211 | } | |
9212 | ||
b1878f45 | 9213 | /* Return nonzero if input events are pending, and run any pending timers. */ |
d9d4c147 | 9214 | |
dfcf069d | 9215 | int |
87dd9b9b RS |
9216 | detect_input_pending_run_timers (do_display) |
9217 | int do_display; | |
d9d4c147 | 9218 | { |
87dd9b9b RS |
9219 | int old_timers_run = timers_run; |
9220 | ||
d9d4c147 KH |
9221 | if (!input_pending) |
9222 | get_input_pending (&input_pending, 1); | |
284f4730 | 9223 | |
87dd9b9b | 9224 | if (old_timers_run != timers_run && do_display) |
7ee32cda GM |
9225 | { |
9226 | redisplay_preserve_echo_area (); | |
9227 | /* The following fixes a bug when using lazy-lock with | |
9228 | lazy-lock-defer-on-the-fly set to t, i.e. when fontifying | |
9229 | from an idle timer function. The symptom of the bug is that | |
9230 | the cursor sometimes doesn't become visible until the next X | |
9231 | event is processed. --gerd. */ | |
9232 | if (rif) | |
9233 | rif->flush_display (NULL); | |
9234 | } | |
87dd9b9b | 9235 | |
284f4730 JB |
9236 | return input_pending; |
9237 | } | |
9238 | ||
ffd56f97 JB |
9239 | /* This is called in some cases before a possible quit. |
9240 | It cases the next call to detect_input_pending to recompute input_pending. | |
9241 | So calling this function unnecessarily can't do any harm. */ | |
07a59269 KH |
9242 | |
9243 | void | |
ffd56f97 JB |
9244 | clear_input_pending () |
9245 | { | |
9246 | input_pending = 0; | |
9247 | } | |
9248 | ||
b1878f45 RS |
9249 | /* Return nonzero if there are pending requeued events. |
9250 | This isn't used yet. The hope is to make wait_reading_process_input | |
9251 | call it, and return return if it runs Lisp code that unreads something. | |
9252 | The problem is, kbd_buffer_get_event needs to be fixed to know what | |
9253 | to do in that case. It isn't trivial. */ | |
9254 | ||
dfcf069d | 9255 | int |
b1878f45 RS |
9256 | requeued_events_pending_p () |
9257 | { | |
9258 | return (!NILP (Vunread_command_events) || unread_command_char != -1); | |
9259 | } | |
9260 | ||
9261 | ||
284f4730 JB |
9262 | DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0, |
9263 | "T if command input is currently available with no waiting.\n\ | |
9264 | Actually, the value is nil only if we can be sure that no input is available.") | |
9265 | () | |
9266 | { | |
24597608 | 9267 | if (!NILP (Vunread_command_events) || unread_command_char != -1) |
284f4730 JB |
9268 | return (Qt); |
9269 | ||
d9d4c147 KH |
9270 | get_input_pending (&input_pending, 1); |
9271 | return input_pending > 0 ? Qt : Qnil; | |
284f4730 JB |
9272 | } |
9273 | ||
9274 | DEFUN ("recent-keys", Frecent_keys, Srecent_keys, 0, 0, 0, | |
22d7cb89 | 9275 | "Return vector of last 100 events, not counting those from keyboard macros.") |
284f4730 JB |
9276 | () |
9277 | { | |
5160df46 | 9278 | Lisp_Object *keys = XVECTOR (recent_keys)->contents; |
284f4730 JB |
9279 | Lisp_Object val; |
9280 | ||
9281 | if (total_keys < NUM_RECENT_KEYS) | |
5160df46 | 9282 | return Fvector (total_keys, keys); |
284f4730 JB |
9283 | else |
9284 | { | |
5160df46 JB |
9285 | val = Fvector (NUM_RECENT_KEYS, keys); |
9286 | bcopy (keys + recent_keys_index, | |
284f4730 JB |
9287 | XVECTOR (val)->contents, |
9288 | (NUM_RECENT_KEYS - recent_keys_index) * sizeof (Lisp_Object)); | |
5160df46 | 9289 | bcopy (keys, |
284f4730 JB |
9290 | XVECTOR (val)->contents + NUM_RECENT_KEYS - recent_keys_index, |
9291 | recent_keys_index * sizeof (Lisp_Object)); | |
9292 | return val; | |
9293 | } | |
9294 | } | |
9295 | ||
9296 | DEFUN ("this-command-keys", Fthis_command_keys, Sthis_command_keys, 0, 0, 0, | |
e5f920d7 RS |
9297 | "Return the key sequence that invoked this command.\n\ |
9298 | The value is a string or a vector.") | |
284f4730 JB |
9299 | () |
9300 | { | |
86e5706b RS |
9301 | return make_event_array (this_command_key_count, |
9302 | XVECTOR (this_command_keys)->contents); | |
284f4730 JB |
9303 | } |
9304 | ||
e39da3d7 RS |
9305 | DEFUN ("this-command-keys-vector", Fthis_command_keys_vector, Sthis_command_keys_vector, 0, 0, 0, |
9306 | "Return the key sequence that invoked this command, as a vector.") | |
9307 | () | |
9308 | { | |
9309 | return Fvector (this_command_key_count, | |
9310 | XVECTOR (this_command_keys)->contents); | |
9311 | } | |
9312 | ||
6321824f RS |
9313 | DEFUN ("this-single-command-keys", Fthis_single_command_keys, |
9314 | Sthis_single_command_keys, 0, 0, 0, | |
9315 | "Return the key sequence that invoked this command.\n\ | |
9316 | Unlike `this-command-keys', this function's value\n\ | |
9317 | does not include prefix arguments.\n\ | |
e39da3d7 | 9318 | The value is always a vector.") |
6321824f RS |
9319 | () |
9320 | { | |
e39da3d7 RS |
9321 | return Fvector (this_command_key_count |
9322 | - this_single_command_key_start, | |
9323 | (XVECTOR (this_command_keys)->contents | |
9324 | + this_single_command_key_start)); | |
6321824f RS |
9325 | } |
9326 | ||
7d18f9ae RS |
9327 | DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys, |
9328 | Sthis_single_command_raw_keys, 0, 0, 0, | |
9329 | "Return the raw events that were read for this command.\n\ | |
9330 | Unlike `this-single-command-keys', this function's value\n\ | |
9331 | shows the events before all translations (except for input methods).\n\ | |
9332 | The value is always a vector.") | |
9333 | () | |
9334 | { | |
9335 | return Fvector (raw_keybuf_count, | |
9336 | (XVECTOR (raw_keybuf)->contents)); | |
9337 | } | |
9338 | ||
71918b75 RS |
9339 | DEFUN ("reset-this-command-lengths", Freset_this_command_lengths, |
9340 | Sreset_this_command_lengths, 0, 0, 0, | |
9341 | "Used for complicated reasons in `universal-argument-other-key'.\n\ | |
9342 | \n\ | |
9343 | `universal-argument-other-key' rereads the event just typed.\n\ | |
9344 | It then gets translated through `function-key-map'.\n\ | |
9345 | The translated event gets included in the echo area and in\n\ | |
9346 | the value of `this-command-keys' in addition to the raw original event.\n\ | |
9347 | That is not right.\n\ | |
9348 | \n\ | |
9349 | Calling this function directs the translated event to replace\n\ | |
9350 | the original event, so that only one version of the event actually\n\ | |
9351 | appears in the echo area and in the value of `this-command-keys.'.") | |
9352 | () | |
9353 | { | |
9354 | before_command_restore_flag = 1; | |
9355 | before_command_key_count_1 = before_command_key_count; | |
9356 | before_command_echo_length_1 = before_command_echo_length; | |
6e5742a0 | 9357 | return Qnil; |
71918b75 RS |
9358 | } |
9359 | ||
82e6e5af RS |
9360 | DEFUN ("clear-this-command-keys", Fclear_this_command_keys, |
9361 | Sclear_this_command_keys, 0, 0, 0, | |
e27b53f6 GM |
9362 | "Clear out the vector that `this-command-keys' returns.\n\ |
9363 | Clear vector containing last 100 events.") | |
82e6e5af RS |
9364 | () |
9365 | { | |
fb0dde6c GM |
9366 | int i; |
9367 | ||
82e6e5af | 9368 | this_command_key_count = 0; |
fb0dde6c GM |
9369 | |
9370 | for (i = 0; i < XVECTOR (recent_keys)->size; ++i) | |
9371 | XVECTOR (recent_keys)->contents[i] = Qnil; | |
9372 | total_keys = 0; | |
9373 | recent_keys_index = 0; | |
82e6e5af RS |
9374 | return Qnil; |
9375 | } | |
9376 | ||
284f4730 JB |
9377 | DEFUN ("recursion-depth", Frecursion_depth, Srecursion_depth, 0, 0, 0, |
9378 | "Return the current depth in recursive edits.") | |
9379 | () | |
9380 | { | |
9381 | Lisp_Object temp; | |
bb9e9bed | 9382 | XSETFASTINT (temp, command_loop_level + minibuf_level); |
284f4730 JB |
9383 | return temp; |
9384 | } | |
9385 | ||
9386 | DEFUN ("open-dribble-file", Fopen_dribble_file, Sopen_dribble_file, 1, 1, | |
9387 | "FOpen dribble file: ", | |
9b2471df RS |
9388 | "Start writing all keyboard characters to a dribble file called FILE.\n\ |
9389 | If FILE is nil, close any open dribble file.") | |
284f4730 JB |
9390 | (file) |
9391 | Lisp_Object file; | |
9392 | { | |
6cb52def | 9393 | if (dribble) |
284f4730 | 9394 | { |
6cb52def KH |
9395 | fclose (dribble); |
9396 | dribble = 0; | |
284f4730 | 9397 | } |
6cb52def | 9398 | if (!NILP (file)) |
284f4730 JB |
9399 | { |
9400 | file = Fexpand_file_name (file, Qnil); | |
9401 | dribble = fopen (XSTRING (file)->data, "w"); | |
ab6ca1de KH |
9402 | if (dribble == 0) |
9403 | report_file_error ("Opening dribble", Fcons (file, Qnil)); | |
284f4730 JB |
9404 | } |
9405 | return Qnil; | |
9406 | } | |
9407 | ||
9408 | DEFUN ("discard-input", Fdiscard_input, Sdiscard_input, 0, 0, 0, | |
9409 | "Discard the contents of the terminal input buffer.\n\ | |
9410 | Also cancel any kbd macro being defined.") | |
9411 | () | |
9412 | { | |
c5fdd383 | 9413 | current_kboard->defining_kbd_macro = Qnil; |
284f4730 JB |
9414 | update_mode_lines++; |
9415 | ||
24597608 | 9416 | Vunread_command_events = Qnil; |
86e5706b | 9417 | unread_command_char = -1; |
284f4730 JB |
9418 | |
9419 | discard_tty_input (); | |
9420 | ||
7ee32cda | 9421 | kbd_fetch_ptr = kbd_store_ptr; |
da8f7368 | 9422 | Ffillarray (kbd_buffer_gcpro, Qnil); |
284f4730 JB |
9423 | input_pending = 0; |
9424 | ||
9425 | return Qnil; | |
9426 | } | |
9427 | \f | |
9428 | DEFUN ("suspend-emacs", Fsuspend_emacs, Ssuspend_emacs, 0, 1, "", | |
9429 | "Stop Emacs and return to superior process. You can resume later.\n\ | |
8026024c KH |
9430 | If `cannot-suspend' is non-nil, or if the system doesn't support job\n\ |
9431 | control, run a subshell instead.\n\n\ | |
284f4730 | 9432 | If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\ |
b7d2ebbf RS |
9433 | to be read as terminal input by Emacs's parent, after suspension.\n\ |
9434 | \n\ | |
bbdc2092 RS |
9435 | Before suspending, run the normal hook `suspend-hook'.\n\ |
9436 | After resumption run the normal hook `suspend-resume-hook'.\n\ | |
284f4730 JB |
9437 | \n\ |
9438 | Some operating systems cannot stop the Emacs process and resume it later.\n\ | |
b7d2ebbf | 9439 | On such systems, Emacs starts a subshell instead of suspending.") |
284f4730 JB |
9440 | (stuffstring) |
9441 | Lisp_Object stuffstring; | |
9442 | { | |
284f4730 JB |
9443 | int count = specpdl_ptr - specpdl; |
9444 | int old_height, old_width; | |
9445 | int width, height; | |
03cee6ae | 9446 | struct gcpro gcpro1; |
284f4730 JB |
9447 | |
9448 | if (!NILP (stuffstring)) | |
9449 | CHECK_STRING (stuffstring, 0); | |
284f4730 | 9450 | |
1e95ed28 JB |
9451 | /* Run the functions in suspend-hook. */ |
9452 | if (!NILP (Vrun_hooks)) | |
9453 | call1 (Vrun_hooks, intern ("suspend-hook")); | |
284f4730 | 9454 | |
b7d2ebbf | 9455 | GCPRO1 (stuffstring); |
ff11dfa1 | 9456 | get_frame_size (&old_width, &old_height); |
284f4730 JB |
9457 | reset_sys_modes (); |
9458 | /* sys_suspend can get an error if it tries to fork a subshell | |
9459 | and the system resources aren't available for that. */ | |
91a0da02 | 9460 | record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes, |
d52a7a92 | 9461 | Qnil); |
284f4730 | 9462 | stuff_buffered_input (stuffstring); |
8026024c KH |
9463 | if (cannot_suspend) |
9464 | sys_subshell (); | |
9465 | else | |
9466 | sys_suspend (); | |
284f4730 JB |
9467 | unbind_to (count, Qnil); |
9468 | ||
9469 | /* Check if terminal/window size has changed. | |
9470 | Note that this is not useful when we are running directly | |
9471 | with a window system; but suspend should be disabled in that case. */ | |
ff11dfa1 | 9472 | get_frame_size (&width, &height); |
284f4730 | 9473 | if (width != old_width || height != old_height) |
788f89eb | 9474 | change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0); |
284f4730 | 9475 | |
1e95ed28 | 9476 | /* Run suspend-resume-hook. */ |
284f4730 JB |
9477 | if (!NILP (Vrun_hooks)) |
9478 | call1 (Vrun_hooks, intern ("suspend-resume-hook")); | |
df0f2ba1 | 9479 | |
284f4730 JB |
9480 | UNGCPRO; |
9481 | return Qnil; | |
9482 | } | |
9483 | ||
9484 | /* If STUFFSTRING is a string, stuff its contents as pending terminal input. | |
eb8c3be9 | 9485 | Then in any case stuff anything Emacs has read ahead and not used. */ |
284f4730 | 9486 | |
07a59269 | 9487 | void |
284f4730 JB |
9488 | stuff_buffered_input (stuffstring) |
9489 | Lisp_Object stuffstring; | |
9490 | { | |
284f4730 | 9491 | /* stuff_char works only in BSD, versions 4.2 and up. */ |
6df54671 | 9492 | #ifdef BSD_SYSTEM |
284f4730 | 9493 | #ifndef BSD4_1 |
612b78ef | 9494 | register unsigned char *p; |
612b78ef | 9495 | |
8c18cbfb | 9496 | if (STRINGP (stuffstring)) |
284f4730 JB |
9497 | { |
9498 | register int count; | |
9499 | ||
9500 | p = XSTRING (stuffstring)->data; | |
fc932ac6 | 9501 | count = STRING_BYTES (XSTRING (stuffstring)); |
284f4730 JB |
9502 | while (count-- > 0) |
9503 | stuff_char (*p++); | |
9504 | stuff_char ('\n'); | |
9505 | } | |
da8f7368 | 9506 | |
284f4730 | 9507 | /* Anything we have read ahead, put back for the shell to read. */ |
beecf6a1 | 9508 | /* ?? What should this do when we have multiple keyboards?? |
c5fdd383 | 9509 | Should we ignore anything that was typed in at the "wrong" kboard? */ |
beecf6a1 | 9510 | for (; kbd_fetch_ptr != kbd_store_ptr; kbd_fetch_ptr++) |
284f4730 | 9511 | { |
da8f7368 GM |
9512 | int idx; |
9513 | ||
beecf6a1 KH |
9514 | if (kbd_fetch_ptr == kbd_buffer + KBD_BUFFER_SIZE) |
9515 | kbd_fetch_ptr = kbd_buffer; | |
9516 | if (kbd_fetch_ptr->kind == ascii_keystroke) | |
9517 | stuff_char (kbd_fetch_ptr->code); | |
da8f7368 | 9518 | |
beecf6a1 | 9519 | kbd_fetch_ptr->kind = no_event; |
da8f7368 GM |
9520 | idx = 2 * (kbd_fetch_ptr - kbd_buffer); |
9521 | ASET (kbd_buffer_gcpro, idx, Qnil); | |
9522 | ASET (kbd_buffer_gcpro, idx + 1, Qnil); | |
284f4730 | 9523 | } |
da8f7368 | 9524 | |
284f4730 JB |
9525 | input_pending = 0; |
9526 | #endif | |
6df54671 | 9527 | #endif /* BSD_SYSTEM and not BSD4_1 */ |
284f4730 JB |
9528 | } |
9529 | \f | |
dfcf069d | 9530 | void |
ffd56f97 JB |
9531 | set_waiting_for_input (time_to_clear) |
9532 | EMACS_TIME *time_to_clear; | |
284f4730 | 9533 | { |
ffd56f97 | 9534 | input_available_clear_time = time_to_clear; |
284f4730 JB |
9535 | |
9536 | /* Tell interrupt_signal to throw back to read_char, */ | |
9537 | waiting_for_input = 1; | |
9538 | ||
9539 | /* If interrupt_signal was called before and buffered a C-g, | |
9540 | make it run again now, to avoid timing error. */ | |
9541 | if (!NILP (Vquit_flag)) | |
9542 | quit_throw_to_read_char (); | |
284f4730 JB |
9543 | } |
9544 | ||
07a59269 | 9545 | void |
284f4730 JB |
9546 | clear_waiting_for_input () |
9547 | { | |
9548 | /* Tell interrupt_signal not to throw back to read_char, */ | |
9549 | waiting_for_input = 0; | |
ffd56f97 | 9550 | input_available_clear_time = 0; |
284f4730 JB |
9551 | } |
9552 | ||
9553 | /* This routine is called at interrupt level in response to C-G. | |
d4e68eea GM |
9554 | |
9555 | If interrupt_input, this is the handler for SIGINT. Otherwise, it | |
9556 | is called from kbd_buffer_store_event, in handling SIGIO or | |
9557 | SIGTINT. | |
284f4730 | 9558 | |
d4e68eea GM |
9559 | If `waiting_for_input' is non zero, then unless `echoing' is |
9560 | nonzero, immediately throw back to read_char. | |
284f4730 | 9561 | |
d4e68eea GM |
9562 | Otherwise it sets the Lisp variable quit-flag not-nil. This causes |
9563 | eval to throw, when it gets a chance. If quit-flag is already | |
9564 | non-nil, it stops the job right away. */ | |
284f4730 JB |
9565 | |
9566 | SIGTYPE | |
91c049d4 RS |
9567 | interrupt_signal (signalnum) /* If we don't have an argument, */ |
9568 | int signalnum; /* some compilers complain in signal calls. */ | |
284f4730 JB |
9569 | { |
9570 | char c; | |
9571 | /* Must preserve main program's value of errno. */ | |
9572 | int old_errno = errno; | |
788f89eb | 9573 | struct frame *sf = SELECTED_FRAME (); |
284f4730 | 9574 | |
5970a8cb | 9575 | #if defined (USG) && !defined (POSIX_SIGNALS) |
7a80a6f6 RS |
9576 | if (!read_socket_hook && NILP (Vwindow_system)) |
9577 | { | |
9578 | /* USG systems forget handlers when they are used; | |
9579 | must reestablish each time */ | |
9580 | signal (SIGINT, interrupt_signal); | |
9581 | signal (SIGQUIT, interrupt_signal); | |
9582 | } | |
284f4730 JB |
9583 | #endif /* USG */ |
9584 | ||
9585 | cancel_echoing (); | |
9586 | ||
31e4e97b | 9587 | if (!NILP (Vquit_flag) |
788f89eb | 9588 | && (FRAME_TERMCAP_P (sf) || FRAME_MSDOS_P (sf))) |
284f4730 | 9589 | { |
31e4e97b EZ |
9590 | /* If SIGINT isn't blocked, don't let us be interrupted by |
9591 | another SIGINT, it might be harmful due to non-reentrancy | |
9592 | in I/O functions. */ | |
9593 | sigblock (sigmask (SIGINT)); | |
9594 | ||
284f4730 JB |
9595 | fflush (stdout); |
9596 | reset_sys_modes (); | |
31e4e97b | 9597 | |
284f4730 JB |
9598 | #ifdef SIGTSTP /* Support possible in later USG versions */ |
9599 | /* | |
9600 | * On systems which can suspend the current process and return to the original | |
9601 | * shell, this command causes the user to end up back at the shell. | |
9602 | * The "Auto-save" and "Abort" questions are not asked until | |
9603 | * the user elects to return to emacs, at which point he can save the current | |
9604 | * job and either dump core or continue. | |
9605 | */ | |
9606 | sys_suspend (); | |
9607 | #else | |
9608 | #ifdef VMS | |
9609 | if (sys_suspend () == -1) | |
9610 | { | |
9611 | printf ("Not running as a subprocess;\n"); | |
9612 | printf ("you can continue or abort.\n"); | |
9613 | } | |
9614 | #else /* not VMS */ | |
9615 | /* Perhaps should really fork an inferior shell? | |
9616 | But that would not provide any way to get back | |
9617 | to the original shell, ever. */ | |
9618 | printf ("No support for stopping a process on this operating system;\n"); | |
9619 | printf ("you can continue or abort.\n"); | |
9620 | #endif /* not VMS */ | |
9621 | #endif /* not SIGTSTP */ | |
80e4aa30 RS |
9622 | #ifdef MSDOS |
9623 | /* We must remain inside the screen area when the internal terminal | |
9624 | is used. Note that [Enter] is not echoed by dos. */ | |
9625 | cursor_to (0, 0); | |
9626 | #endif | |
118d6ca9 RS |
9627 | /* It doesn't work to autosave while GC is in progress; |
9628 | the code used for auto-saving doesn't cope with the mark bit. */ | |
9629 | if (!gc_in_progress) | |
9fd7d808 | 9630 | { |
118d6ca9 RS |
9631 | printf ("Auto-save? (y or n) "); |
9632 | fflush (stdout); | |
9633 | if (((c = getchar ()) & ~040) == 'Y') | |
9634 | { | |
9635 | Fdo_auto_save (Qt, Qnil); | |
80e4aa30 | 9636 | #ifdef MSDOS |
118d6ca9 | 9637 | printf ("\r\nAuto-save done"); |
80e4aa30 | 9638 | #else /* not MSDOS */ |
118d6ca9 | 9639 | printf ("Auto-save done\n"); |
80e4aa30 | 9640 | #endif /* not MSDOS */ |
118d6ca9 RS |
9641 | } |
9642 | while (c != '\n') c = getchar (); | |
9fd7d808 | 9643 | } |
118d6ca9 RS |
9644 | else |
9645 | { | |
9646 | /* During GC, it must be safe to reenable quitting again. */ | |
9647 | Vinhibit_quit = Qnil; | |
9648 | #ifdef MSDOS | |
9649 | printf ("\r\n"); | |
9650 | #endif /* not MSDOS */ | |
9651 | printf ("Garbage collection in progress; cannot auto-save now\r\n"); | |
9652 | printf ("but will instead do a real quit after garbage collection ends\r\n"); | |
9653 | fflush (stdout); | |
9654 | } | |
9655 | ||
80e4aa30 RS |
9656 | #ifdef MSDOS |
9657 | printf ("\r\nAbort? (y or n) "); | |
9658 | #else /* not MSDOS */ | |
284f4730 JB |
9659 | #ifdef VMS |
9660 | printf ("Abort (and enter debugger)? (y or n) "); | |
9661 | #else /* not VMS */ | |
9662 | printf ("Abort (and dump core)? (y or n) "); | |
9663 | #endif /* not VMS */ | |
80e4aa30 | 9664 | #endif /* not MSDOS */ |
284f4730 JB |
9665 | fflush (stdout); |
9666 | if (((c = getchar ()) & ~040) == 'Y') | |
9667 | abort (); | |
9668 | while (c != '\n') c = getchar (); | |
80e4aa30 RS |
9669 | #ifdef MSDOS |
9670 | printf ("\r\nContinuing...\r\n"); | |
9671 | #else /* not MSDOS */ | |
284f4730 | 9672 | printf ("Continuing...\n"); |
80e4aa30 | 9673 | #endif /* not MSDOS */ |
284f4730 JB |
9674 | fflush (stdout); |
9675 | init_sys_modes (); | |
31e4e97b | 9676 | sigfree (); |
284f4730 JB |
9677 | } |
9678 | else | |
9679 | { | |
9680 | /* If executing a function that wants to be interrupted out of | |
9681 | and the user has not deferred quitting by binding `inhibit-quit' | |
9682 | then quit right away. */ | |
9683 | if (immediate_quit && NILP (Vinhibit_quit)) | |
9684 | { | |
e39da3d7 RS |
9685 | struct gl_state_s saved; |
9686 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
9687 | ||
284f4730 JB |
9688 | immediate_quit = 0; |
9689 | sigfree (); | |
e39da3d7 RS |
9690 | saved = gl_state; |
9691 | GCPRO4 (saved.object, saved.global_code, | |
9692 | saved.current_syntax_table, saved.old_prop); | |
284f4730 | 9693 | Fsignal (Qquit, Qnil); |
e39da3d7 RS |
9694 | gl_state = saved; |
9695 | UNGCPRO; | |
284f4730 JB |
9696 | } |
9697 | else | |
9698 | /* Else request quit when it's safe */ | |
9699 | Vquit_flag = Qt; | |
9700 | } | |
9701 | ||
9702 | if (waiting_for_input && !echoing) | |
9703 | quit_throw_to_read_char (); | |
9704 | ||
9705 | errno = old_errno; | |
9706 | } | |
9707 | ||
9708 | /* Handle a C-g by making read_char return C-g. */ | |
9709 | ||
07a59269 | 9710 | void |
284f4730 JB |
9711 | quit_throw_to_read_char () |
9712 | { | |
284f4730 JB |
9713 | sigfree (); |
9714 | /* Prevent another signal from doing this before we finish. */ | |
f76475ad | 9715 | clear_waiting_for_input (); |
284f4730 JB |
9716 | input_pending = 0; |
9717 | ||
24597608 | 9718 | Vunread_command_events = Qnil; |
86e5706b | 9719 | unread_command_char = -1; |
284f4730 | 9720 | |
087feab3 RS |
9721 | #if 0 /* Currently, sit_for is called from read_char without turning |
9722 | off polling. And that can call set_waiting_for_input. | |
9723 | It seems to be harmless. */ | |
e6b01c14 JB |
9724 | #ifdef POLL_FOR_INPUT |
9725 | /* May be > 1 if in recursive minibuffer. */ | |
9726 | if (poll_suppress_count == 0) | |
9727 | abort (); | |
9728 | #endif | |
087feab3 | 9729 | #endif |
4c52b668 | 9730 | if (FRAMEP (internal_last_event_frame) |
788f89eb | 9731 | && !EQ (internal_last_event_frame, selected_frame)) |
719191cf RS |
9732 | do_switch_frame (make_lispy_switch_frame (internal_last_event_frame), |
9733 | Qnil, 0); | |
e6b01c14 | 9734 | |
284f4730 JB |
9735 | _longjmp (getcjmp, 1); |
9736 | } | |
9737 | \f | |
9738 | DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, | |
9739 | "Set mode of reading keyboard input.\n\ | |
464f8898 RS |
9740 | First arg INTERRUPT non-nil means use input interrupts;\n\ |
9741 | nil means use CBREAK mode.\n\ | |
9742 | Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\ | |
284f4730 | 9743 | (no effect except in CBREAK mode).\n\ |
b04904fb RS |
9744 | Third arg META t means accept 8-bit input (for a Meta key).\n\ |
9745 | META nil means ignore the top bit, on the assumption it is parity.\n\ | |
9746 | Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\ | |
a8ee7ef9 RS |
9747 | Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\ |
9748 | See also `current-input-mode'.") | |
284f4730 JB |
9749 | (interrupt, flow, meta, quit) |
9750 | Lisp_Object interrupt, flow, meta, quit; | |
9751 | { | |
9752 | if (!NILP (quit) | |
8c18cbfb | 9753 | && (!INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400)) |
34f04431 RS |
9754 | error ("set-input-mode: QUIT must be an ASCII character"); |
9755 | ||
9756 | #ifdef POLL_FOR_INPUT | |
9757 | stop_polling (); | |
9758 | #endif | |
284f4730 | 9759 | |
07de30b9 | 9760 | #ifndef DOS_NT |
2ee250ec | 9761 | /* this causes startup screen to be restored and messes with the mouse */ |
284f4730 | 9762 | reset_sys_modes (); |
2ee250ec RS |
9763 | #endif |
9764 | ||
284f4730 JB |
9765 | #ifdef SIGIO |
9766 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
284f4730 | 9767 | if (read_socket_hook) |
9a0f60bb KH |
9768 | { |
9769 | /* When using X, don't give the user a real choice, | |
9770 | because we haven't implemented the mechanisms to support it. */ | |
9771 | #ifdef NO_SOCK_SIGIO | |
9772 | interrupt_input = 0; | |
9773 | #else /* not NO_SOCK_SIGIO */ | |
9774 | interrupt_input = 1; | |
284f4730 | 9775 | #endif /* NO_SOCK_SIGIO */ |
9a0f60bb KH |
9776 | } |
9777 | else | |
284f4730 JB |
9778 | interrupt_input = !NILP (interrupt); |
9779 | #else /* not SIGIO */ | |
9780 | interrupt_input = 0; | |
9781 | #endif /* not SIGIO */ | |
9a0f60bb | 9782 | |
284f4730 JB |
9783 | /* Our VMS input only works by interrupts, as of now. */ |
9784 | #ifdef VMS | |
9785 | interrupt_input = 1; | |
9786 | #endif | |
9a0f60bb | 9787 | |
284f4730 | 9788 | flow_control = !NILP (flow); |
b04904fb RS |
9789 | if (NILP (meta)) |
9790 | meta_key = 0; | |
9791 | else if (EQ (meta, Qt)) | |
9792 | meta_key = 1; | |
9793 | else | |
9794 | meta_key = 2; | |
284f4730 JB |
9795 | if (!NILP (quit)) |
9796 | /* Don't let this value be out of range. */ | |
9797 | quit_char = XINT (quit) & (meta_key ? 0377 : 0177); | |
9798 | ||
07de30b9 | 9799 | #ifndef DOS_NT |
284f4730 | 9800 | init_sys_modes (); |
2ee250ec | 9801 | #endif |
34f04431 RS |
9802 | |
9803 | #ifdef POLL_FOR_INPUT | |
9804 | poll_suppress_count = 1; | |
9805 | start_polling (); | |
9806 | #endif | |
284f4730 JB |
9807 | return Qnil; |
9808 | } | |
80645119 JB |
9809 | |
9810 | DEFUN ("current-input-mode", Fcurrent_input_mode, Scurrent_input_mode, 0, 0, 0, | |
9811 | "Return information about the way Emacs currently reads keyboard input.\n\ | |
9812 | The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\ | |
9813 | INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\ | |
9814 | nil, Emacs is using CBREAK mode.\n\ | |
9815 | FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\ | |
9816 | terminal; this does not apply if Emacs uses interrupt-driven input.\n\ | |
a8ee7ef9 RS |
9817 | META is t if accepting 8-bit input with 8th bit as Meta flag.\n\ |
9818 | META nil means ignoring the top bit, on the assumption it is parity.\n\ | |
9819 | META is neither t nor nil if accepting 8-bit input and using\n\ | |
9820 | all 8 bits as the character code.\n\ | |
80645119 JB |
9821 | QUIT is the character Emacs currently uses to quit.\n\ |
9822 | The elements of this list correspond to the arguments of\n\ | |
a8ee7ef9 | 9823 | `set-input-mode'.") |
80645119 JB |
9824 | () |
9825 | { | |
9826 | Lisp_Object val[4]; | |
9827 | ||
9828 | val[0] = interrupt_input ? Qt : Qnil; | |
9829 | val[1] = flow_control ? Qt : Qnil; | |
a8ee7ef9 | 9830 | val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil; |
bb9e9bed | 9831 | XSETFASTINT (val[3], quit_char); |
80645119 | 9832 | |
bf673a7a | 9833 | return Flist (sizeof (val) / sizeof (val[0]), val); |
80645119 JB |
9834 | } |
9835 | ||
284f4730 | 9836 | \f |
6c6083a9 | 9837 | /* |
c5fdd383 | 9838 | * Set up a new kboard object with reasonable initial values. |
6c6083a9 KH |
9839 | */ |
9840 | void | |
c5fdd383 KH |
9841 | init_kboard (kb) |
9842 | KBOARD *kb; | |
6c6083a9 | 9843 | { |
217258d5 | 9844 | kb->Voverriding_terminal_local_map = Qnil; |
6c7178b9 | 9845 | kb->Vlast_command = Qnil; |
75045dcb | 9846 | kb->Vreal_last_command = Qnil; |
d8bcf58e | 9847 | kb->Vprefix_arg = Qnil; |
75045dcb | 9848 | kb->Vlast_prefix_arg = Qnil; |
c5fdd383 KH |
9849 | kb->kbd_queue = Qnil; |
9850 | kb->kbd_queue_has_data = 0; | |
9851 | kb->immediate_echo = 0; | |
9852 | kb->echoptr = kb->echobuf; | |
9853 | kb->echo_after_prompt = -1; | |
9854 | kb->kbd_macro_buffer = 0; | |
9855 | kb->kbd_macro_bufsize = 0; | |
9856 | kb->defining_kbd_macro = Qnil; | |
9857 | kb->Vlast_kbd_macro = Qnil; | |
9858 | kb->reference_count = 0; | |
7c97ffdc | 9859 | kb->Vsystem_key_alist = Qnil; |
142e6c73 | 9860 | kb->system_key_syms = Qnil; |
9ba47203 | 9861 | kb->Vdefault_minibuffer_frame = Qnil; |
6c6083a9 KH |
9862 | } |
9863 | ||
9864 | /* | |
c5fdd383 | 9865 | * Destroy the contents of a kboard object, but not the object itself. |
8e6208c5 | 9866 | * We use this just before deleting it, or if we're going to initialize |
6c6083a9 KH |
9867 | * it a second time. |
9868 | */ | |
e50b8090 | 9869 | static void |
c5fdd383 KH |
9870 | wipe_kboard (kb) |
9871 | KBOARD *kb; | |
6c6083a9 | 9872 | { |
c5fdd383 KH |
9873 | if (kb->kbd_macro_buffer) |
9874 | xfree (kb->kbd_macro_buffer); | |
6c6083a9 KH |
9875 | } |
9876 | ||
e50b8090 KH |
9877 | #ifdef MULTI_KBOARD |
9878 | void | |
9879 | delete_kboard (kb) | |
9880 | KBOARD *kb; | |
9881 | { | |
9882 | KBOARD **kbp; | |
9883 | for (kbp = &all_kboards; *kbp != kb; kbp = &(*kbp)->next_kboard) | |
9884 | if (*kbp == NULL) | |
9885 | abort (); | |
9886 | *kbp = kb->next_kboard; | |
9887 | wipe_kboard (kb); | |
9888 | xfree (kb); | |
9889 | } | |
9890 | #endif | |
9891 | ||
dfcf069d | 9892 | void |
284f4730 JB |
9893 | init_keyboard () |
9894 | { | |
284f4730 JB |
9895 | /* This is correct before outermost invocation of the editor loop */ |
9896 | command_loop_level = -1; | |
9897 | immediate_quit = 0; | |
9898 | quit_char = Ctl ('g'); | |
24597608 | 9899 | Vunread_command_events = Qnil; |
86e5706b | 9900 | unread_command_char = -1; |
87dd9b9b | 9901 | EMACS_SET_SECS_USECS (timer_idleness_start_time, -1, -1); |
284f4730 | 9902 | total_keys = 0; |
9deb415a | 9903 | recent_keys_index = 0; |
beecf6a1 KH |
9904 | kbd_fetch_ptr = kbd_buffer; |
9905 | kbd_store_ptr = kbd_buffer; | |
da8f7368 | 9906 | kbd_buffer_gcpro = Fmake_vector (make_number (2 * KBD_BUFFER_SIZE), Qnil); |
2eb6bfbe | 9907 | #ifdef HAVE_MOUSE |
a9d77f1f | 9908 | do_mouse_tracking = Qnil; |
2eb6bfbe | 9909 | #endif |
284f4730 JB |
9910 | input_pending = 0; |
9911 | ||
4c52b668 KH |
9912 | /* This means that command_loop_1 won't try to select anything the first |
9913 | time through. */ | |
9914 | internal_last_event_frame = Qnil; | |
9915 | Vlast_event_frame = internal_last_event_frame; | |
4c52b668 | 9916 | |
c5fdd383 | 9917 | #ifdef MULTI_KBOARD |
aaca43a1 | 9918 | current_kboard = initial_kboard; |
6c6083a9 | 9919 | #endif |
aaca43a1 | 9920 | wipe_kboard (current_kboard); |
c5fdd383 | 9921 | init_kboard (current_kboard); |
07d2b8de | 9922 | |
7a80a6f6 | 9923 | if (!noninteractive && !read_socket_hook && NILP (Vwindow_system)) |
284f4730 JB |
9924 | { |
9925 | signal (SIGINT, interrupt_signal); | |
cb5df6ae | 9926 | #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) |
284f4730 JB |
9927 | /* For systems with SysV TERMIO, C-g is set up for both SIGINT and |
9928 | SIGQUIT and we can't tell which one it will give us. */ | |
9929 | signal (SIGQUIT, interrupt_signal); | |
9930 | #endif /* HAVE_TERMIO */ | |
7a80a6f6 | 9931 | } |
284f4730 JB |
9932 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ |
9933 | #ifdef SIGIO | |
7a80a6f6 RS |
9934 | if (!noninteractive) |
9935 | signal (SIGIO, input_available_signal); | |
8ea0a720 | 9936 | #endif /* SIGIO */ |
284f4730 JB |
9937 | |
9938 | /* Use interrupt input by default, if it works and noninterrupt input | |
9939 | has deficiencies. */ | |
9940 | ||
9941 | #ifdef INTERRUPT_INPUT | |
9942 | interrupt_input = 1; | |
9943 | #else | |
9944 | interrupt_input = 0; | |
9945 | #endif | |
9946 | ||
9947 | /* Our VMS input only works by interrupts, as of now. */ | |
9948 | #ifdef VMS | |
9949 | interrupt_input = 1; | |
9950 | #endif | |
9951 | ||
9952 | sigfree (); | |
9953 | dribble = 0; | |
9954 | ||
9955 | if (keyboard_init_hook) | |
9956 | (*keyboard_init_hook) (); | |
9957 | ||
9958 | #ifdef POLL_FOR_INPUT | |
9959 | poll_suppress_count = 1; | |
9960 | start_polling (); | |
9961 | #endif | |
9962 | } | |
9963 | ||
df0f2ba1 | 9964 | /* This type's only use is in syms_of_keyboard, to initialize the |
284f4730 JB |
9965 | event header symbols and put properties on them. */ |
9966 | struct event_head { | |
9967 | Lisp_Object *var; | |
9968 | char *name; | |
9969 | Lisp_Object *kind; | |
9970 | }; | |
9971 | ||
9972 | struct event_head head_table[] = { | |
7b4aedb9 | 9973 | &Qmouse_movement, "mouse-movement", &Qmouse_movement, |
3c370943 | 9974 | &Qscroll_bar_movement, "scroll-bar-movement", &Qmouse_movement, |
7b4aedb9 | 9975 | &Qswitch_frame, "switch-frame", &Qswitch_frame, |
bbdc2092 | 9976 | &Qdelete_frame, "delete-frame", &Qdelete_frame, |
af17bd2b KH |
9977 | &Qiconify_frame, "iconify-frame", &Qiconify_frame, |
9978 | &Qmake_frame_visible, "make-frame-visible", &Qmake_frame_visible, | |
284f4730 JB |
9979 | }; |
9980 | ||
dfcf069d | 9981 | void |
284f4730 JB |
9982 | syms_of_keyboard () |
9983 | { | |
8e1e4240 GM |
9984 | Vlispy_mouse_stem = build_string ("mouse"); |
9985 | staticpro (&Vlispy_mouse_stem); | |
9986 | ||
9ea173e8 | 9987 | /* Tool-bars. */ |
7ee32cda GM |
9988 | QCimage = intern (":image"); |
9989 | staticpro (&QCimage); | |
9990 | ||
9991 | staticpro (&Qhelp_echo); | |
9992 | Qhelp_echo = intern ("help-echo"); | |
9993 | ||
e8886a1d RS |
9994 | staticpro (&item_properties); |
9995 | item_properties = Qnil; | |
9996 | ||
9ea173e8 GM |
9997 | staticpro (&tool_bar_item_properties); |
9998 | tool_bar_item_properties = Qnil; | |
9999 | staticpro (&tool_bar_items_vector); | |
10000 | tool_bar_items_vector = Qnil; | |
7ee32cda | 10001 | |
d5eecefb RS |
10002 | staticpro (&real_this_command); |
10003 | real_this_command = Qnil; | |
10004 | ||
d925fb39 RS |
10005 | Qtimer_event_handler = intern ("timer-event-handler"); |
10006 | staticpro (&Qtimer_event_handler); | |
10007 | ||
2e894dab RS |
10008 | Qdisabled_command_hook = intern ("disabled-command-hook"); |
10009 | staticpro (&Qdisabled_command_hook); | |
10010 | ||
284f4730 JB |
10011 | Qself_insert_command = intern ("self-insert-command"); |
10012 | staticpro (&Qself_insert_command); | |
10013 | ||
10014 | Qforward_char = intern ("forward-char"); | |
10015 | staticpro (&Qforward_char); | |
10016 | ||
10017 | Qbackward_char = intern ("backward-char"); | |
10018 | staticpro (&Qbackward_char); | |
10019 | ||
10020 | Qdisabled = intern ("disabled"); | |
10021 | staticpro (&Qdisabled); | |
10022 | ||
e58aa385 RS |
10023 | Qundefined = intern ("undefined"); |
10024 | staticpro (&Qundefined); | |
10025 | ||
86e5706b RS |
10026 | Qpre_command_hook = intern ("pre-command-hook"); |
10027 | staticpro (&Qpre_command_hook); | |
10028 | ||
10029 | Qpost_command_hook = intern ("post-command-hook"); | |
10030 | staticpro (&Qpost_command_hook); | |
10031 | ||
59aadc81 RS |
10032 | Qpost_command_idle_hook = intern ("post-command-idle-hook"); |
10033 | staticpro (&Qpost_command_idle_hook); | |
10034 | ||
3ef14e46 RS |
10035 | Qdeferred_action_function = intern ("deferred-action-function"); |
10036 | staticpro (&Qdeferred_action_function); | |
10037 | ||
40932d1a RS |
10038 | Qcommand_hook_internal = intern ("command-hook-internal"); |
10039 | staticpro (&Qcommand_hook_internal); | |
10040 | ||
284f4730 JB |
10041 | Qfunction_key = intern ("function-key"); |
10042 | staticpro (&Qfunction_key); | |
13b5e56c | 10043 | Qmouse_click = intern ("mouse-click"); |
284f4730 | 10044 | staticpro (&Qmouse_click); |
07de30b9 GV |
10045 | #ifdef WINDOWSNT |
10046 | Qmouse_wheel = intern ("mouse-wheel"); | |
10047 | staticpro (&Qmouse_wheel); | |
1161d367 GV |
10048 | Qlanguage_change = intern ("language-change"); |
10049 | staticpro (&Qlanguage_change); | |
07de30b9 | 10050 | #endif |
a24dc617 RS |
10051 | Qdrag_n_drop = intern ("drag-n-drop"); |
10052 | staticpro (&Qdrag_n_drop); | |
284f4730 | 10053 | |
5bf68f6e AS |
10054 | Qusr1_signal = intern ("usr1-signal"); |
10055 | staticpro (&Qusr1_signal); | |
10056 | Qusr2_signal = intern ("usr2-signal"); | |
10057 | staticpro (&Qusr2_signal); | |
10058 | ||
598a9fa7 JB |
10059 | Qmenu_enable = intern ("menu-enable"); |
10060 | staticpro (&Qmenu_enable); | |
e8886a1d RS |
10061 | Qmenu_alias = intern ("menu-alias"); |
10062 | staticpro (&Qmenu_alias); | |
10063 | QCenable = intern (":enable"); | |
10064 | staticpro (&QCenable); | |
10065 | QCvisible = intern (":visible"); | |
10066 | staticpro (&QCvisible); | |
7ee32cda GM |
10067 | QChelp = intern (":help"); |
10068 | staticpro (&QChelp); | |
e8886a1d RS |
10069 | QCfilter = intern (":filter"); |
10070 | staticpro (&QCfilter); | |
10071 | QCbutton = intern (":button"); | |
10072 | staticpro (&QCbutton); | |
74c1de23 RS |
10073 | QCkeys = intern (":keys"); |
10074 | staticpro (&QCkeys); | |
10075 | QCkey_sequence = intern (":key-sequence"); | |
10076 | staticpro (&QCkey_sequence); | |
e8886a1d RS |
10077 | QCtoggle = intern (":toggle"); |
10078 | staticpro (&QCtoggle); | |
10079 | QCradio = intern (":radio"); | |
10080 | staticpro (&QCradio); | |
598a9fa7 | 10081 | |
284f4730 JB |
10082 | Qmode_line = intern ("mode-line"); |
10083 | staticpro (&Qmode_line); | |
e5d77022 JB |
10084 | Qvertical_line = intern ("vertical-line"); |
10085 | staticpro (&Qvertical_line); | |
3c370943 JB |
10086 | Qvertical_scroll_bar = intern ("vertical-scroll-bar"); |
10087 | staticpro (&Qvertical_scroll_bar); | |
5ec75a55 RS |
10088 | Qmenu_bar = intern ("menu-bar"); |
10089 | staticpro (&Qmenu_bar); | |
4bb994d1 JB |
10090 | |
10091 | Qabove_handle = intern ("above-handle"); | |
10092 | staticpro (&Qabove_handle); | |
10093 | Qhandle = intern ("handle"); | |
10094 | staticpro (&Qhandle); | |
10095 | Qbelow_handle = intern ("below-handle"); | |
10096 | staticpro (&Qbelow_handle); | |
db08707d RS |
10097 | Qup = intern ("up"); |
10098 | staticpro (&Qup); | |
10099 | Qdown = intern ("down"); | |
10100 | staticpro (&Qdown); | |
7ee32cda GM |
10101 | Qtop = intern ("top"); |
10102 | staticpro (&Qtop); | |
10103 | Qbottom = intern ("bottom"); | |
10104 | staticpro (&Qbottom); | |
10105 | Qend_scroll = intern ("end-scroll"); | |
10106 | staticpro (&Qend_scroll); | |
eef28553 SM |
10107 | Qratio = intern ("ratio"); |
10108 | staticpro (&Qratio); | |
284f4730 | 10109 | |
cd21b839 | 10110 | Qevent_kind = intern ("event-kind"); |
284f4730 | 10111 | staticpro (&Qevent_kind); |
88cb0656 JB |
10112 | Qevent_symbol_elements = intern ("event-symbol-elements"); |
10113 | staticpro (&Qevent_symbol_elements); | |
0a7f1fc0 JB |
10114 | Qevent_symbol_element_mask = intern ("event-symbol-element-mask"); |
10115 | staticpro (&Qevent_symbol_element_mask); | |
10116 | Qmodifier_cache = intern ("modifier-cache"); | |
10117 | staticpro (&Qmodifier_cache); | |
284f4730 | 10118 | |
48e416d4 RS |
10119 | Qrecompute_lucid_menubar = intern ("recompute-lucid-menubar"); |
10120 | staticpro (&Qrecompute_lucid_menubar); | |
10121 | Qactivate_menubar_hook = intern ("activate-menubar-hook"); | |
10122 | staticpro (&Qactivate_menubar_hook); | |
10123 | ||
f4eef8b4 RS |
10124 | Qpolling_period = intern ("polling-period"); |
10125 | staticpro (&Qpolling_period); | |
10126 | ||
7d18f9ae RS |
10127 | Qinput_method_function = intern ("input-method-function"); |
10128 | staticpro (&Qinput_method_function); | |
10129 | ||
d5eecefb RS |
10130 | Qinput_method_exit_on_first_char = intern ("input-method-exit-on-first-char"); |
10131 | staticpro (&Qinput_method_exit_on_first_char); | |
10132 | Qinput_method_use_echo_area = intern ("input-method-use-echo-area"); | |
10133 | staticpro (&Qinput_method_use_echo_area); | |
10134 | ||
10135 | Fset (Qinput_method_exit_on_first_char, Qnil); | |
10136 | Fset (Qinput_method_use_echo_area, Qnil); | |
10137 | ||
e18dfbf4 KR |
10138 | last_point_position_buffer = Qnil; |
10139 | ||
284f4730 JB |
10140 | { |
10141 | struct event_head *p; | |
10142 | ||
10143 | for (p = head_table; | |
10144 | p < head_table + (sizeof (head_table) / sizeof (head_table[0])); | |
10145 | p++) | |
10146 | { | |
10147 | *p->var = intern (p->name); | |
10148 | staticpro (p->var); | |
10149 | Fput (*p->var, Qevent_kind, *p->kind); | |
88cb0656 | 10150 | Fput (*p->var, Qevent_symbol_elements, Fcons (*p->var, Qnil)); |
284f4730 JB |
10151 | } |
10152 | } | |
10153 | ||
8e1e4240 | 10154 | button_down_location = Fmake_vector (make_number (1), Qnil); |
7b4aedb9 | 10155 | staticpro (&button_down_location); |
8e1e4240 GM |
10156 | mouse_syms = Fmake_vector (make_number (1), Qnil); |
10157 | staticpro (&mouse_syms); | |
88cb0656 JB |
10158 | |
10159 | { | |
10160 | int i; | |
10161 | int len = sizeof (modifier_names) / sizeof (modifier_names[0]); | |
10162 | ||
10163 | modifier_symbols = Fmake_vector (make_number (len), Qnil); | |
10164 | for (i = 0; i < len; i++) | |
86e5706b RS |
10165 | if (modifier_names[i]) |
10166 | XVECTOR (modifier_symbols)->contents[i] = intern (modifier_names[i]); | |
88cb0656 JB |
10167 | staticpro (&modifier_symbols); |
10168 | } | |
10169 | ||
9deb415a JB |
10170 | recent_keys = Fmake_vector (make_number (NUM_RECENT_KEYS), Qnil); |
10171 | staticpro (&recent_keys); | |
10172 | ||
6569cc8d | 10173 | this_command_keys = Fmake_vector (make_number (40), Qnil); |
715d9345 | 10174 | staticpro (&this_command_keys); |
6569cc8d | 10175 | |
7d18f9ae RS |
10176 | raw_keybuf = Fmake_vector (make_number (30), Qnil); |
10177 | staticpro (&raw_keybuf); | |
10178 | ||
03b4122a BF |
10179 | Qextended_command_history = intern ("extended-command-history"); |
10180 | Fset (Qextended_command_history, Qnil); | |
10181 | staticpro (&Qextended_command_history); | |
10182 | ||
da8f7368 GM |
10183 | kbd_buffer_gcpro = Fmake_vector (make_number (2 * KBD_BUFFER_SIZE), Qnil); |
10184 | staticpro (&kbd_buffer_gcpro); | |
beecf6a1 | 10185 | |
24597608 RS |
10186 | accent_key_syms = Qnil; |
10187 | staticpro (&accent_key_syms); | |
10188 | ||
284f4730 JB |
10189 | func_key_syms = Qnil; |
10190 | staticpro (&func_key_syms); | |
10191 | ||
07de30b9 GV |
10192 | #ifdef WINDOWSNT |
10193 | mouse_wheel_syms = Qnil; | |
10194 | staticpro (&mouse_wheel_syms); | |
a24dc617 RS |
10195 | |
10196 | drag_n_drop_syms = Qnil; | |
10197 | staticpro (&drag_n_drop_syms); | |
07de30b9 GV |
10198 | #endif |
10199 | ||
cd21b839 JB |
10200 | unread_switch_frame = Qnil; |
10201 | staticpro (&unread_switch_frame); | |
10202 | ||
fe412364 EN |
10203 | internal_last_event_frame = Qnil; |
10204 | staticpro (&internal_last_event_frame); | |
10205 | ||
10206 | read_key_sequence_cmd = Qnil; | |
10207 | staticpro (&read_key_sequence_cmd); | |
10208 | ||
759860a6 RS |
10209 | menu_bar_one_keymap_changed_items = Qnil; |
10210 | staticpro (&menu_bar_one_keymap_changed_items); | |
10211 | ||
a1706c30 | 10212 | defsubr (&Sevent_convert_list); |
284f4730 | 10213 | defsubr (&Sread_key_sequence); |
e39da3d7 | 10214 | defsubr (&Sread_key_sequence_vector); |
284f4730 | 10215 | defsubr (&Srecursive_edit); |
2eb6bfbe | 10216 | #ifdef HAVE_MOUSE |
284f4730 | 10217 | defsubr (&Strack_mouse); |
2eb6bfbe | 10218 | #endif |
284f4730 JB |
10219 | defsubr (&Sinput_pending_p); |
10220 | defsubr (&Scommand_execute); | |
10221 | defsubr (&Srecent_keys); | |
10222 | defsubr (&Sthis_command_keys); | |
e39da3d7 | 10223 | defsubr (&Sthis_command_keys_vector); |
6321824f | 10224 | defsubr (&Sthis_single_command_keys); |
7d18f9ae | 10225 | defsubr (&Sthis_single_command_raw_keys); |
71918b75 | 10226 | defsubr (&Sreset_this_command_lengths); |
82e6e5af | 10227 | defsubr (&Sclear_this_command_keys); |
284f4730 JB |
10228 | defsubr (&Ssuspend_emacs); |
10229 | defsubr (&Sabort_recursive_edit); | |
10230 | defsubr (&Sexit_recursive_edit); | |
10231 | defsubr (&Srecursion_depth); | |
10232 | defsubr (&Stop_level); | |
10233 | defsubr (&Sdiscard_input); | |
10234 | defsubr (&Sopen_dribble_file); | |
10235 | defsubr (&Sset_input_mode); | |
80645119 | 10236 | defsubr (&Scurrent_input_mode); |
284f4730 JB |
10237 | defsubr (&Sexecute_extended_command); |
10238 | ||
284f4730 | 10239 | DEFVAR_LISP ("last-command-char", &last_command_char, |
86e5706b RS |
10240 | "Last input event that was part of a command."); |
10241 | ||
186cf719 | 10242 | DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char, |
86e5706b | 10243 | "Last input event that was part of a command."); |
284f4730 | 10244 | |
7d6de002 | 10245 | DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event, |
86e5706b | 10246 | "Last input event in a command, except for mouse menu events.\n\ |
7d6de002 RS |
10247 | Mouse menus give back keys that don't look like mouse events;\n\ |
10248 | this variable holds the actual mouse event that led to the menu,\n\ | |
10249 | so that you can determine whether the command was run by mouse or not."); | |
10250 | ||
284f4730 | 10251 | DEFVAR_LISP ("last-input-char", &last_input_char, |
86e5706b RS |
10252 | "Last input event."); |
10253 | ||
186cf719 | 10254 | DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char, |
86e5706b | 10255 | "Last input event."); |
284f4730 | 10256 | |
24597608 | 10257 | DEFVAR_LISP ("unread-command-events", &Vunread_command_events, |
7d18f9ae RS |
10258 | "List of events to be read as the command input.\n\ |
10259 | These events are processed first, before actual keyboard input."); | |
10260 | Vunread_command_events = Qnil; | |
284f4730 | 10261 | |
86e5706b RS |
10262 | DEFVAR_INT ("unread-command-char", &unread_command_char, |
10263 | "If not -1, an object to be read as next command input event."); | |
10264 | ||
7d18f9ae RS |
10265 | DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events, |
10266 | "List of events to be processed as input by input methods.\n\ | |
10267 | These events are processed after `unread-command-events', but\n\ | |
10268 | before actual keyboard input."); | |
10269 | Vunread_post_input_method_events = Qnil; | |
10270 | ||
10271 | DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events, | |
10272 | "List of events to be processed as input by input methods.\n\ | |
10273 | These events are processed after `unread-command-events', but\n\ | |
10274 | before actual keyboard input."); | |
10275 | Vunread_input_method_events = Qnil; | |
10276 | ||
284f4730 | 10277 | DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char, |
b283f79e KH |
10278 | "Meta-prefix character code.\n\ |
10279 | Meta-foo as command input turns into this character followed by foo."); | |
18cd2eeb | 10280 | XSETINT (meta_prefix_char, 033); |
284f4730 | 10281 | |
6c7178b9 | 10282 | DEFVAR_KBOARD ("last-command", Vlast_command, |
b283f79e KH |
10283 | "The last command executed.\n\ |
10284 | Normally a symbol with a function definition, but can be whatever was found\n\ | |
10285 | in the keymap, or whatever the variable `this-command' was set to by that\n\ | |
10286 | command.\n\ | |
18f29056 RS |
10287 | \n\ |
10288 | The value `mode-exit' is special; it means that the previous command\n\ | |
10289 | read an event that told it to exit, and it did so and unread that event.\n\ | |
10290 | In other words, the present command is the event that made the previous\n\ | |
10291 | command exit.\n\ | |
10292 | \n\ | |
10293 | The value `kill-region' is special; it means that the previous command\n\ | |
10294 | was a kill command."); | |
284f4730 | 10295 | |
75045dcb RS |
10296 | DEFVAR_KBOARD ("real-last-command", Vreal_last_command, |
10297 | "Same as `last-command', but never altered by Lisp code."); | |
10298 | ||
d5eecefb | 10299 | DEFVAR_LISP ("this-command", &Vthis_command, |
284f4730 JB |
10300 | "The command now being executed.\n\ |
10301 | The command can set this variable; whatever is put here\n\ | |
10302 | will be in `last-command' during the following command."); | |
d5eecefb | 10303 | Vthis_command = Qnil; |
284f4730 JB |
10304 | |
10305 | DEFVAR_INT ("auto-save-interval", &auto_save_interval, | |
dace7f4e | 10306 | "*Number of input events between auto-saves.\n\ |
284f4730 JB |
10307 | Zero means disable autosaving due to number of characters typed."); |
10308 | auto_save_interval = 300; | |
10309 | ||
10310 | DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout, | |
10311 | "*Number of seconds idle time before auto-save.\n\ | |
06ef7355 RS |
10312 | Zero or nil means disable auto-saving due to idleness.\n\ |
10313 | After auto-saving due to this many seconds of idle time,\n\ | |
84447c71 | 10314 | Emacs also does a garbage collection if that seems to be warranted."); |
bb9e9bed | 10315 | XSETFASTINT (Vauto_save_timeout, 30); |
284f4730 | 10316 | |
39aab679 | 10317 | DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes, |
f2647d04 DL |
10318 | "*Nonzero means echo unfinished commands after this many seconds of pause.\n\ |
10319 | The value may be integer or floating point."); | |
39aab679 | 10320 | Vecho_keystrokes = make_number (1); |
284f4730 JB |
10321 | |
10322 | DEFVAR_INT ("polling-period", &polling_period, | |
10323 | "*Interval between polling for input during Lisp execution.\n\ | |
10324 | The reason for polling is to make C-g work to stop a running program.\n\ | |
10325 | Polling is needed only when using X windows and SIGIO does not work.\n\ | |
10326 | Polling is automatically disabled in all other cases."); | |
10327 | polling_period = 2; | |
df0f2ba1 | 10328 | |
564dc952 | 10329 | DEFVAR_LISP ("double-click-time", &Vdouble_click_time, |
fbcd35bd | 10330 | "*Maximum time between mouse clicks to make a double-click.\n\ |
564dc952 JB |
10331 | Measured in milliseconds. nil means disable double-click recognition;\n\ |
10332 | t means double-clicks have no time limit and are detected\n\ | |
fbcd35bd | 10333 | by position only."); |
aab06933 | 10334 | Vdouble_click_time = make_number (500); |
fbcd35bd | 10335 | |
03361bcc RS |
10336 | DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus, |
10337 | "*Non-nil means inhibit local map menu bar menus."); | |
10338 | inhibit_local_menu_bar_menus = 0; | |
10339 | ||
284f4730 | 10340 | DEFVAR_INT ("num-input-keys", &num_input_keys, |
c43b1734 | 10341 | "Number of complete key sequences read as input so far.\n\ |
58ce35fb KH |
10342 | This includes key sequences read from keyboard macros.\n\ |
10343 | The number is effectively the number of interactive command invocations."); | |
284f4730 JB |
10344 | num_input_keys = 0; |
10345 | ||
c43b1734 RS |
10346 | DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events, |
10347 | "Number of input events read from the keyboard so far.\n\ | |
10348 | This does not include events generated by keyboard macros."); | |
10349 | num_nonmacro_input_events = 0; | |
fa90970d | 10350 | |
4c52b668 KH |
10351 | DEFVAR_LISP ("last-event-frame", &Vlast_event_frame, |
10352 | "The frame in which the most recently read event occurred.\n\ | |
10353 | If the last event came from a keyboard macro, this is set to `macro'."); | |
10354 | Vlast_event_frame = Qnil; | |
10355 | ||
fa90970d RS |
10356 | /* This variable is set up in sysdep.c. */ |
10357 | DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char, | |
10358 | "The ERASE character as set by the user with stty."); | |
10359 | ||
7e85b935 | 10360 | DEFVAR_LISP ("help-char", &Vhelp_char, |
284f4730 JB |
10361 | "Character to recognize as meaning Help.\n\ |
10362 | When it is read, do `(eval help-form)', and display result if it's a string.\n\ | |
10363 | If the value of `help-form' is nil, this char can be read normally."); | |
18cd2eeb | 10364 | XSETINT (Vhelp_char, Ctl ('H')); |
284f4730 | 10365 | |
ecb7cb34 KH |
10366 | DEFVAR_LISP ("help-event-list", &Vhelp_event_list, |
10367 | "List of input events to recognize as meaning Help.\n\ | |
10368 | These work just like the value of `help-char' (see that)."); | |
10369 | Vhelp_event_list = Qnil; | |
10370 | ||
284f4730 | 10371 | DEFVAR_LISP ("help-form", &Vhelp_form, |
7e85b935 | 10372 | "Form to execute when character `help-char' is read.\n\ |
284f4730 JB |
10373 | If the form returns a string, that string is displayed.\n\ |
10374 | If `help-form' is nil, the help char is not recognized."); | |
10375 | Vhelp_form = Qnil; | |
10376 | ||
7e85b935 RS |
10377 | DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command, |
10378 | "Command to run when `help-char' character follows a prefix key.\n\ | |
10379 | This command is used only when there is no actual binding\n\ | |
10380 | for that character after that prefix key."); | |
10381 | Vprefix_help_command = Qnil; | |
10382 | ||
284f4730 JB |
10383 | DEFVAR_LISP ("top-level", &Vtop_level, |
10384 | "Form to evaluate when Emacs starts up.\n\ | |
10385 | Useful to set before you dump a modified Emacs."); | |
10386 | Vtop_level = Qnil; | |
10387 | ||
10388 | DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table, | |
f9414d62 | 10389 | "Translate table for keyboard input, or nil.\n\ |
284f4730 | 10390 | Each character is looked up in this string and the contents used instead.\n\ |
f9414d62 RS |
10391 | The value may be a string, a vector, or a char-table.\n\ |
10392 | If it is a string or vector of length N,\n\ | |
10393 | character codes N and up are untranslated.\n\ | |
10394 | In a vector or a char-table, an element which is nil means \"no translation\"."); | |
284f4730 JB |
10395 | Vkeyboard_translate_table = Qnil; |
10396 | ||
8026024c | 10397 | DEFVAR_BOOL ("cannot-suspend", &cannot_suspend, |
b283f79e KH |
10398 | "Non-nil means to always spawn a subshell instead of suspending.\n\ |
10399 | \(Even if the operating system has support for stopping a process.\)"); | |
8026024c KH |
10400 | cannot_suspend = 0; |
10401 | ||
284f4730 | 10402 | DEFVAR_BOOL ("menu-prompting", &menu_prompting, |
7d6de002 | 10403 | "Non-nil means prompt with menus when appropriate.\n\ |
284f4730 | 10404 | This is done when reading from a keymap that has a prompt string,\n\ |
7d6de002 RS |
10405 | for elements that have prompt strings.\n\ |
10406 | The menu is displayed on the screen\n\ | |
10407 | if X menus were enabled at configuration\n\ | |
10408 | time and the previous event was a mouse click prefix key.\n\ | |
10409 | Otherwise, menu prompting uses the echo area."); | |
284f4730 JB |
10410 | menu_prompting = 1; |
10411 | ||
10412 | DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char, | |
10413 | "Character to see next line of menu prompt.\n\ | |
10414 | Type this character while in a menu prompt to rotate around the lines of it."); | |
18cd2eeb | 10415 | XSETINT (menu_prompt_more_char, ' '); |
9fa4395d RS |
10416 | |
10417 | DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers, | |
10418 | "A mask of additional modifier keys to use with every keyboard character.\n\ | |
ad163903 JB |
10419 | Emacs applies the modifiers of the character stored here to each keyboard\n\ |
10420 | character it reads. For example, after evaluating the expression\n\ | |
9d9f56dd | 10421 | (setq extra-keyboard-modifiers ?\\C-x)\n\ |
80645119 JB |
10422 | all input characters will have the control modifier applied to them.\n\ |
10423 | \n\ | |
9d9f56dd | 10424 | Note that the character ?\\C-@, equivalent to the integer zero, does\n\ |
80645119 | 10425 | not count as a control character; rather, it counts as a character\n\ |
27203ead | 10426 | with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\ |
80645119 | 10427 | cancels any modification."); |
9fa4395d | 10428 | extra_keyboard_modifiers = 0; |
86e5706b RS |
10429 | |
10430 | DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark, | |
10431 | "If an editing command sets this to t, deactivate the mark afterward.\n\ | |
10432 | The command loop sets this to nil before each command,\n\ | |
10433 | and tests the value when the command returns.\n\ | |
10434 | Buffer modification stores t in this variable."); | |
10435 | Vdeactivate_mark = Qnil; | |
10436 | ||
b0f2a7bf KH |
10437 | DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal, |
10438 | "Temporary storage of pre-command-hook or post-command-hook."); | |
10439 | Vcommand_hook_internal = Qnil; | |
10440 | ||
86e5706b | 10441 | DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook, |
a1fd42c0 | 10442 | "Normal hook run before each command is executed.\n\ |
307958d6 RS |
10443 | If an unhandled error happens in running this hook,\n\ |
10444 | the hook value is set to nil, since otherwise the error\n\ | |
10445 | might happen repeatedly and make Emacs nonfunctional."); | |
86e5706b RS |
10446 | Vpre_command_hook = Qnil; |
10447 | ||
10448 | DEFVAR_LISP ("post-command-hook", &Vpost_command_hook, | |
a1fd42c0 | 10449 | "Normal hook run after each command is executed.\n\ |
307958d6 RS |
10450 | If an unhandled error happens in running this hook,\n\ |
10451 | the hook value is set to nil, since otherwise the error\n\ | |
10452 | might happen repeatedly and make Emacs nonfunctional."); | |
86e5706b | 10453 | Vpost_command_hook = Qnil; |
48e416d4 | 10454 | |
59aadc81 RS |
10455 | DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook, |
10456 | "Normal hook run after each command is executed, if idle.\n\ | |
d4d62e8d RS |
10457 | Errors running the hook are caught and ignored.\n\ |
10458 | This feature is obsolete; use idle timers instead. See `etc/NEWS'."); | |
59aadc81 RS |
10459 | Vpost_command_idle_hook = Qnil; |
10460 | ||
10461 | DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay, | |
7051b69b | 10462 | "Delay time before running `post-command-idle-hook'.\n\ |
59aadc81 RS |
10463 | This is measured in microseconds."); |
10464 | post_command_idle_delay = 100000; | |
10465 | ||
cdb9d665 RS |
10466 | #if 0 |
10467 | DEFVAR_LISP ("echo-area-clear-hook", ..., | |
10468 | "Normal hook run when clearing the echo area."); | |
10469 | #endif | |
10470 | Qecho_area_clear_hook = intern ("echo-area-clear-hook"); | |
10471 | XSYMBOL (Qecho_area_clear_hook)->value = Qnil; | |
10472 | ||
48e416d4 RS |
10473 | DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag, |
10474 | "t means menu bar, specified Lucid style, needs to be recomputed."); | |
10475 | Vlucid_menu_bar_dirty_flag = Qnil; | |
a73c5e29 | 10476 | |
9f9c0e27 RS |
10477 | DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items, |
10478 | "List of menu bar items to move to the end of the menu bar.\n\ | |
a612e298 | 10479 | The elements of the list are event types that may have menu bar bindings."); |
9f9c0e27 | 10480 | Vmenu_bar_final_items = Qnil; |
e9bf89a0 | 10481 | |
217258d5 KH |
10482 | DEFVAR_KBOARD ("overriding-terminal-local-map", |
10483 | Voverriding_terminal_local_map, | |
779b34df | 10484 | "Per-terminal keymap that overrides all other local keymaps.\n\ |
217258d5 | 10485 | If this variable is non-nil, it is used as a keymap instead of the\n\ |
779b34df RS |
10486 | buffer's local map, and the minor mode keymaps and text property keymaps.\n\ |
10487 | This variable is intended to let commands such as `universal-argumemnt'\n\ | |
10488 | set up a different keymap for reading the next command."); | |
217258d5 | 10489 | |
9dd3131c RS |
10490 | DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map, |
10491 | "Keymap that overrides all other local keymaps.\n\ | |
10492 | If this variable is non-nil, it is used as a keymap instead of the\n\ | |
10493 | buffer's local map, and the minor mode keymaps and text property keymaps."); | |
10494 | Voverriding_local_map = Qnil; | |
10495 | ||
d0a49716 RS |
10496 | DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag, |
10497 | "Non-nil means `overriding-local-map' applies to the menu bar.\n\ | |
10498 | Otherwise, the menu bar continues to reflect the buffer's local map\n\ | |
10499 | and the minor mode maps regardless of `overriding-local-map'."); | |
10500 | Voverriding_local_map_menu_flag = Qnil; | |
10501 | ||
7f07d5ca RS |
10502 | DEFVAR_LISP ("special-event-map", &Vspecial_event_map, |
10503 | "Keymap defining bindings for special events to execute at low level."); | |
10504 | Vspecial_event_map = Fcons (intern ("keymap"), Qnil); | |
10505 | ||
71edead1 | 10506 | DEFVAR_LISP ("track-mouse", &do_mouse_tracking, |
a53c7666 | 10507 | "*Non-nil means generate motion events for mouse motion."); |
80e4aa30 | 10508 | |
7c97ffdc | 10509 | DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist, |
270a208f | 10510 | "Alist of system-specific X windows key symbols.\n\ |
80e4aa30 | 10511 | Each element should have the form (N . SYMBOL) where N is the\n\ |
270a208f | 10512 | numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\ |
80e4aa30 | 10513 | and SYMBOL is its name."); |
8a792f3a RS |
10514 | |
10515 | DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list, | |
10516 | "List of deferred actions to be performed at a later time.\n\ | |
10517 | The precise format isn't relevant here; we just check whether it is nil."); | |
10518 | Vdeferred_action_list = Qnil; | |
10519 | ||
10520 | DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function, | |
10521 | "Function to call to handle deferred actions, after each command.\n\ | |
10522 | This function is called with no arguments after each command\n\ | |
10523 | whenever `deferred-action-list' is non-nil."); | |
10524 | Vdeferred_action_function = Qnil; | |
6526ab49 RS |
10525 | |
10526 | DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings, | |
ac52ebd5 | 10527 | "*Non-nil means show the equivalent key-binding when M-x command has one.\n\ |
6526ab49 RS |
10528 | The value can be a length of time to show the message for.\n\ |
10529 | If the value is non-nil and not a number, we wait 2 seconds."); | |
10530 | Vsuggest_key_bindings = Qt; | |
8bb1c042 | 10531 | |
c04cbc3b | 10532 | DEFVAR_LISP ("timer-list", &Vtimer_list, |
d9d4c147 | 10533 | "List of active absolute time timers in order of increasing time"); |
c04cbc3b | 10534 | Vtimer_list = Qnil; |
d9d4c147 KH |
10535 | |
10536 | DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list, | |
10537 | "List of active idle-time timers in order of increasing time"); | |
10538 | Vtimer_idle_list = Qnil; | |
7d18f9ae RS |
10539 | |
10540 | DEFVAR_LISP ("input-method-function", &Vinput_method_function, | |
10541 | "If non-nil, the function that implements the current input method.\n\ | |
10542 | It's called with one argument, a printing character that was just read.\n\ | |
10543 | \(That means a character with code 040...0176.)\n\ | |
10544 | Typically this function uses `read-event' to read additional events.\n\ | |
10545 | When it does so, it should first bind `input-method-function' to nil\n\ | |
10546 | so it will not be called recursively.\n\ | |
10547 | \n\ | |
10548 | The function should return a list of zero or more events\n\ | |
10549 | to be used as input. If it wants to put back some events\n\ | |
10550 | to be reconsidered, separately, by the input method,\n\ | |
d5eecefb RS |
10551 | it can add them to the beginning of `unread-command-events'.\n\ |
10552 | \n\ | |
10553 | The input method function can find in `input-method-previous-method'\n\ | |
10554 | the previous echo area message.\n\ | |
10555 | \n\ | |
10556 | The input method function should refer to the variables\n\ | |
10557 | `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\ | |
10558 | for guidance on what to do."); | |
7d18f9ae | 10559 | Vinput_method_function = Qnil; |
d5eecefb RS |
10560 | |
10561 | DEFVAR_LISP ("input-method-previous-message", | |
10562 | &Vinput_method_previous_message, | |
a8b13665 | 10563 | "When `input-method-function' is called, hold the previous echo area message.\n\ |
d5eecefb RS |
10564 | This variable exists because `read-event' clears the echo area\n\ |
10565 | before running the input method. It is nil if there was no message."); | |
10566 | Vinput_method_previous_message = Qnil; | |
7ee32cda GM |
10567 | |
10568 | DEFVAR_LISP ("show-help-function", &Vshow_help_function, | |
10569 | "If non-nil, the function that implements the display of help.\n\ | |
10570 | It's called with one argument, the help string to display."); | |
10571 | Vshow_help_function = Qnil; | |
adf5cb9c KH |
10572 | |
10573 | DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment, | |
10574 | "If non-nil, suppress point adjustment after executing a command.\n\ | |
10575 | \n\ | |
10576 | After a command is executed, if point is moved into a region that has\n\ | |
10577 | special properties (e.g. composition, display), we adjust point to\n\ | |
10578 | the boundary of the region. But, several special commands sets this\n\ | |
10579 | variable to non-nil, then we suppress the point adjustment.\n\ | |
10580 | \n\ | |
10581 | This variable is set to nil before reading a command, and is checked\n\ | |
10582 | just after executing the command"); | |
10583 | Vdisable_point_adjustment = Qnil; | |
10584 | ||
10585 | DEFVAR_LISP ("global-disable-point-adjustment", | |
10586 | &Vglobal_disable_point_adjustment, | |
10587 | "*If non-nil, always suppress point adjustment.\n\ | |
10588 | \n\ | |
10589 | The default value is nil, in which case, point adjustment are\n\ | |
10590 | suppressed only after special commands that set\n\ | |
10591 | `disable-point-adjustment' (which see) to non-nil."); | |
10592 | Vglobal_disable_point_adjustment = Qnil; | |
3626fb1a | 10593 | |
a1d34b1e | 10594 | DEFVAR_BOOL ("update-menu-bindings", &update_menu_bindings, |
3626fb1a GM |
10595 | "Non-nil means updating menu bindings is allowed.\n\ |
10596 | A value of nil means menu bindings should not be updated.\n\ | |
10597 | Used during Emacs' startup."); | |
10598 | update_menu_bindings = 1; | |
00392ce6 MB |
10599 | |
10600 | DEFVAR_LISP ("minibuffer-message-timeout", &Vminibuffer_message_timeout, | |
10601 | "*How long to display an echo-area message when the minibuffer is active.\n\ | |
10602 | If the value is not a number, such messages don't time out."); | |
10603 | Vminibuffer_message_timeout = make_number (2); | |
284f4730 JB |
10604 | } |
10605 | ||
dfcf069d | 10606 | void |
284f4730 JB |
10607 | keys_of_keyboard () |
10608 | { | |
10609 | initial_define_key (global_map, Ctl ('Z'), "suspend-emacs"); | |
10610 | initial_define_key (control_x_map, Ctl ('Z'), "suspend-emacs"); | |
10611 | initial_define_key (meta_map, Ctl ('C'), "exit-recursive-edit"); | |
10612 | initial_define_key (global_map, Ctl (']'), "abort-recursive-edit"); | |
10613 | initial_define_key (meta_map, 'x', "execute-extended-command"); | |
7f07d5ca RS |
10614 | |
10615 | initial_define_lispy_key (Vspecial_event_map, "delete-frame", | |
10616 | "handle-delete-frame"); | |
10617 | initial_define_lispy_key (Vspecial_event_map, "iconify-frame", | |
10618 | "ignore-event"); | |
10619 | initial_define_lispy_key (Vspecial_event_map, "make-frame-visible", | |
10620 | "ignore-event"); | |
284f4730 | 10621 | } |