Commit | Line | Data |
---|---|---|
284f4730 | 1 | /* Keyboard and mouse input; editor command loop. |
d925fb39 | 2 | Copyright (C) 1985,86,87,88,89,93,94,95,96,97 Free Software Foundation, Inc. |
284f4730 JB |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
6 | GNU Emacs is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
7b4aedb9 | 8 | the Free Software Foundation; either version 2, or (at your option) |
284f4730 JB |
9 | any later version. |
10 | ||
11 | GNU Emacs is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Emacs; see the file COPYING. If not, write to | |
3b7ad313 EN |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
284f4730 JB |
20 | |
21 | /* Allow config.h to undefine symbols found here. */ | |
22 | #include <signal.h> | |
23 | ||
18160b98 | 24 | #include <config.h> |
284f4730 | 25 | #include <stdio.h> |
284f4730 JB |
26 | #include "termchar.h" |
27 | #include "termopts.h" | |
28 | #include "lisp.h" | |
29 | #include "termhooks.h" | |
30 | #include "macros.h" | |
ff11dfa1 | 31 | #include "frame.h" |
284f4730 JB |
32 | #include "window.h" |
33 | #include "commands.h" | |
34 | #include "buffer.h" | |
37cd9f30 | 35 | #include "charset.h" |
284f4730 | 36 | #include "disptab.h" |
f4255cd1 | 37 | #include "dispextern.h" |
284f4730 | 38 | #include "keyboard.h" |
e39da3d7 | 39 | #include "syntax.h" |
497ba7a1 | 40 | #include "intervals.h" |
9ac0d9e0 | 41 | #include "blockinput.h" |
e8886a1d | 42 | #include "puresize.h" |
284f4730 JB |
43 | #include <setjmp.h> |
44 | #include <errno.h> | |
45 | ||
80e4aa30 RS |
46 | #ifdef MSDOS |
47 | #include "msdos.h" | |
48 | #include <time.h> | |
49 | #else /* not MSDOS */ | |
284f4730 JB |
50 | #ifndef VMS |
51 | #include <sys/ioctl.h> | |
284f4730 | 52 | #endif |
80e4aa30 | 53 | #endif /* not MSDOS */ |
284f4730 | 54 | |
52baf19e | 55 | #include "syssignal.h" |
6ef5b54f | 56 | #include "systty.h" |
52baf19e | 57 | |
c5e3b6c5 RS |
58 | /* This is to get the definitions of the XK_ symbols. */ |
59 | #ifdef HAVE_X_WINDOWS | |
60 | #include "xterm.h" | |
61 | #endif | |
62 | ||
e98a93eb GV |
63 | #ifdef HAVE_NTGUI |
64 | #include "w32term.h" | |
65 | #endif /* HAVE_NTGUI */ | |
66 | ||
0c2611c5 RS |
67 | /* Include systime.h after xterm.h to avoid double inclusion of time.h. */ |
68 | #include "systime.h" | |
69 | ||
52baf19e JB |
70 | extern int errno; |
71 | ||
9ac0d9e0 JB |
72 | /* Variables for blockinput.h: */ |
73 | ||
74 | /* Non-zero if interrupt input is blocked right now. */ | |
63927c41 | 75 | int interrupt_input_blocked; |
9ac0d9e0 JB |
76 | |
77 | /* Nonzero means an input interrupt has arrived | |
78 | during the current critical section. */ | |
63927c41 | 79 | int interrupt_input_pending; |
9ac0d9e0 JB |
80 | |
81 | ||
437f6112 RS |
82 | /* File descriptor to use for input. */ |
83 | extern int input_fd; | |
284f4730 | 84 | |
e98a93eb | 85 | #ifdef HAVE_WINDOW_SYSTEM |
284f4730 JB |
86 | /* Make all keyboard buffers much bigger when using X windows. */ |
87 | #define KBD_BUFFER_SIZE 4096 | |
88 | #else /* No X-windows, character input */ | |
89 | #define KBD_BUFFER_SIZE 256 | |
90 | #endif /* No X-windows */ | |
91 | ||
92 | /* Following definition copied from eval.c */ | |
93 | ||
94 | struct backtrace | |
95 | { | |
96 | struct backtrace *next; | |
97 | Lisp_Object *function; | |
98 | Lisp_Object *args; /* Points to vector of args. */ | |
99 | int nargs; /* length of vector. If nargs is UNEVALLED, | |
100 | args points to slot holding list of | |
101 | unevalled args */ | |
102 | char evalargs; | |
103 | }; | |
104 | ||
c5fdd383 KH |
105 | #ifdef MULTI_KBOARD |
106 | KBOARD *initial_kboard; | |
107 | KBOARD *current_kboard; | |
108 | KBOARD *all_kboards; | |
1e8bd3da | 109 | int single_kboard; |
6c6083a9 | 110 | #else |
c5fdd383 | 111 | KBOARD the_only_kboard; |
6c6083a9 | 112 | #endif |
612b78ef | 113 | |
284f4730 JB |
114 | /* Non-nil disable property on a command means |
115 | do not execute it; call disabled-command-hook's value instead. */ | |
2e894dab | 116 | Lisp_Object Qdisabled, Qdisabled_command_hook; |
284f4730 JB |
117 | |
118 | #define NUM_RECENT_KEYS (100) | |
119 | int recent_keys_index; /* Index for storing next element into recent_keys */ | |
120 | int total_keys; /* Total number of elements stored into recent_keys */ | |
5160df46 | 121 | Lisp_Object recent_keys; /* A vector, holding the last 100 keystrokes */ |
284f4730 | 122 | |
6569cc8d JB |
123 | /* Vector holding the key sequence that invoked the current command. |
124 | It is reused for each command, and it may be longer than the current | |
125 | sequence; this_command_key_count indicates how many elements | |
126 | actually mean something. | |
127 | It's easier to staticpro a single Lisp_Object than an array. */ | |
128 | Lisp_Object this_command_keys; | |
129 | int this_command_key_count; | |
284f4730 | 130 | |
6321824f RS |
131 | /* Number of elements of this_command_keys |
132 | that precede this key sequence. */ | |
133 | int this_single_command_key_start; | |
134 | ||
71918b75 RS |
135 | /* Record values of this_command_key_count and echo_length () |
136 | before this command was read. */ | |
137 | static int before_command_key_count; | |
138 | static int before_command_echo_length; | |
139 | /* Values of before_command_key_count and before_command_echo_length | |
140 | saved by reset-this-command-lengths. */ | |
141 | static int before_command_key_count_1; | |
142 | static int before_command_echo_length_1; | |
143 | /* Flag set by reset-this-command-lengths, | |
144 | saying to reset the lengths when add_command_key is called. */ | |
145 | static int before_command_restore_flag; | |
146 | ||
284f4730 JB |
147 | extern int minbuf_level; |
148 | ||
a59b172a RS |
149 | extern int message_enable_multibyte; |
150 | ||
284f4730 JB |
151 | extern struct backtrace *backtrace_list; |
152 | ||
153 | /* Nonzero means do menu prompting. */ | |
154 | static int menu_prompting; | |
155 | ||
156 | /* Character to see next line of menu prompt. */ | |
157 | static Lisp_Object menu_prompt_more_char; | |
158 | ||
159 | /* For longjmp to where kbd input is being done. */ | |
160 | static jmp_buf getcjmp; | |
161 | ||
162 | /* True while doing kbd input. */ | |
163 | int waiting_for_input; | |
164 | ||
165 | /* True while displaying for echoing. Delays C-g throwing. */ | |
166 | static int echoing; | |
167 | ||
1fc93d49 RS |
168 | /* True means we can start echoing at the next input pause |
169 | even though there is something in the echo area. */ | |
0c04a67e | 170 | static char *ok_to_echo_at_next_pause; |
1fc93d49 | 171 | |
03361bcc RS |
172 | /* Nonzero means disregard local maps for the menu bar. */ |
173 | static int inhibit_local_menu_bar_menus; | |
174 | ||
80e4aa30 | 175 | /* Nonzero means C-g should cause immediate error-signal. */ |
284f4730 JB |
176 | int immediate_quit; |
177 | ||
fa90970d RS |
178 | /* The user's ERASE setting. */ |
179 | Lisp_Object Vtty_erase_char; | |
180 | ||
284f4730 | 181 | /* Character to recognize as the help char. */ |
7e85b935 | 182 | Lisp_Object Vhelp_char; |
284f4730 | 183 | |
ecb7cb34 KH |
184 | /* List of other event types to recognize as meaning "help". */ |
185 | Lisp_Object Vhelp_event_list; | |
186 | ||
284f4730 JB |
187 | /* Form to execute when help char is typed. */ |
188 | Lisp_Object Vhelp_form; | |
189 | ||
7e85b935 RS |
190 | /* Command to run when the help character follows a prefix key. */ |
191 | Lisp_Object Vprefix_help_command; | |
192 | ||
9f9c0e27 RS |
193 | /* List of items that should move to the end of the menu bar. */ |
194 | Lisp_Object Vmenu_bar_final_items; | |
a73c5e29 | 195 | |
6526ab49 RS |
196 | /* Non-nil means show the equivalent key-binding for |
197 | any M-x command that has one. | |
198 | The value can be a length of time to show the message for. | |
199 | If the value is non-nil and not a number, we wait 2 seconds. */ | |
200 | Lisp_Object Vsuggest_key_bindings; | |
201 | ||
284f4730 JB |
202 | /* Character that causes a quit. Normally C-g. |
203 | ||
204 | If we are running on an ordinary terminal, this must be an ordinary | |
205 | ASCII char, since we want to make it our interrupt character. | |
206 | ||
207 | If we are not running on an ordinary terminal, it still needs to be | |
208 | an ordinary ASCII char. This character needs to be recognized in | |
209 | the input interrupt handler. At this point, the keystroke is | |
210 | represented as a struct input_event, while the desired quit | |
211 | character is specified as a lispy event. The mapping from struct | |
212 | input_events to lispy events cannot run in an interrupt handler, | |
213 | and the reverse mapping is difficult for anything but ASCII | |
214 | keystrokes. | |
215 | ||
216 | FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an | |
217 | ASCII character. */ | |
218 | int quit_char; | |
219 | ||
220 | extern Lisp_Object current_global_map; | |
221 | extern int minibuf_level; | |
222 | ||
9dd3131c RS |
223 | /* If non-nil, this is a map that overrides all other local maps. */ |
224 | Lisp_Object Voverriding_local_map; | |
225 | ||
d0a49716 RS |
226 | /* If non-nil, Voverriding_local_map applies to the menu bar. */ |
227 | Lisp_Object Voverriding_local_map_menu_flag; | |
228 | ||
7f07d5ca RS |
229 | /* Keymap that defines special misc events that should |
230 | be processed immediately at a low level. */ | |
231 | Lisp_Object Vspecial_event_map; | |
232 | ||
284f4730 JB |
233 | /* Current depth in recursive edits. */ |
234 | int command_loop_level; | |
235 | ||
236 | /* Total number of times command_loop has read a key sequence. */ | |
237 | int num_input_keys; | |
238 | ||
239 | /* Last input character read as a command. */ | |
240 | Lisp_Object last_command_char; | |
241 | ||
7d6de002 RS |
242 | /* Last input character read as a command, not counting menus |
243 | reached by the mouse. */ | |
244 | Lisp_Object last_nonmenu_event; | |
245 | ||
284f4730 JB |
246 | /* Last input character read for any purpose. */ |
247 | Lisp_Object last_input_char; | |
248 | ||
dbc4e1c1 | 249 | /* If not Qnil, a list of objects to be read as subsequent command input. */ |
24597608 | 250 | Lisp_Object Vunread_command_events; |
284f4730 | 251 | |
86e5706b RS |
252 | /* If not -1, an event to be read as subsequent command input. */ |
253 | int unread_command_char; | |
254 | ||
cd21b839 JB |
255 | /* If not Qnil, this is a switch-frame event which we decided to put |
256 | off until the end of a key sequence. This should be read as the | |
dbc4e1c1 | 257 | next command input, after any unread_command_events. |
8f805655 JB |
258 | |
259 | read_key_sequence uses this to delay switch-frame events until the | |
260 | end of the key sequence; Fread_char uses it to put off switch-frame | |
261 | events until a non-ASCII event is acceptable as input. */ | |
262 | Lisp_Object unread_switch_frame; | |
cd21b839 | 263 | |
9fa4395d RS |
264 | /* A mask of extra modifier bits to put into every keyboard char. */ |
265 | int extra_keyboard_modifiers; | |
266 | ||
284f4730 JB |
267 | /* Char to use as prefix when a meta character is typed in. |
268 | This is bound on entry to minibuffer in case ESC is changed there. */ | |
269 | ||
270 | Lisp_Object meta_prefix_char; | |
271 | ||
272 | /* Last size recorded for a current buffer which is not a minibuffer. */ | |
273 | static int last_non_minibuf_size; | |
274 | ||
06ef7355 | 275 | /* Number of idle seconds before an auto-save and garbage collection. */ |
284f4730 JB |
276 | static Lisp_Object Vauto_save_timeout; |
277 | ||
278 | /* Total number of times read_char has returned. */ | |
4abfba1f | 279 | int num_input_events; |
284f4730 | 280 | |
51172b6d | 281 | /* Total number of times read_char has returned, outside of macros. */ |
c43b1734 | 282 | int num_nonmacro_input_events; |
51172b6d | 283 | |
284f4730 JB |
284 | /* Auto-save automatically when this many characters have been typed |
285 | since the last time. */ | |
286 | ||
287 | static int auto_save_interval; | |
288 | ||
c43b1734 | 289 | /* Value of num_nonmacro_input_events as of last auto save. */ |
284f4730 JB |
290 | |
291 | int last_auto_save; | |
292 | ||
284f4730 | 293 | /* The command being executed by the command loop. |
6c7178b9 KH |
294 | Commands may set this, and the value set will be copied into |
295 | current_kboard->Vlast_command instead of the actual command. */ | |
284f4730 JB |
296 | Lisp_Object this_command; |
297 | ||
b453f72e KH |
298 | /* The value of point when the last command was executed. */ |
299 | int last_point_position; | |
300 | ||
047688cb RS |
301 | /* The buffer that was current when the last command was started. */ |
302 | Lisp_Object last_point_position_buffer; | |
303 | ||
4c52b668 KH |
304 | /* The frame in which the last input event occurred, or Qmacro if the |
305 | last event came from a macro. We use this to determine when to | |
306 | generate switch-frame events. This may be cleared by functions | |
307 | like Fselect_frame, to make sure that a switch-frame event is | |
308 | generated by the next character. */ | |
309 | Lisp_Object internal_last_event_frame; | |
4c52b668 KH |
310 | |
311 | /* A user-visible version of the above, intended to allow users to | |
312 | figure out where the last event came from, if the event doesn't | |
313 | carry that information itself (i.e. if it was a character). */ | |
314 | Lisp_Object Vlast_event_frame; | |
315 | ||
1113d9db JB |
316 | /* The timestamp of the last input event we received from the X server. |
317 | X Windows wants this for selection ownership. */ | |
284f4730 JB |
318 | unsigned long last_event_timestamp; |
319 | ||
320 | Lisp_Object Qself_insert_command; | |
321 | Lisp_Object Qforward_char; | |
322 | Lisp_Object Qbackward_char; | |
e58aa385 | 323 | Lisp_Object Qundefined; |
d925fb39 | 324 | Lisp_Object Qtimer_event_handler; |
284f4730 JB |
325 | |
326 | /* read_key_sequence stores here the command definition of the | |
327 | key sequence that it reads. */ | |
328 | Lisp_Object read_key_sequence_cmd; | |
329 | ||
330 | /* Form to evaluate (if non-nil) when Emacs is started. */ | |
331 | Lisp_Object Vtop_level; | |
332 | ||
333 | /* User-supplied string to translate input characters through. */ | |
334 | Lisp_Object Vkeyboard_translate_table; | |
335 | ||
336 | /* Keymap mapping ASCII function key sequences onto their preferred forms. */ | |
337 | extern Lisp_Object Vfunction_key_map; | |
338 | ||
e0301c07 RS |
339 | /* Another keymap that maps key sequences into key sequences. |
340 | This one takes precedence over ordinary definitions. */ | |
341 | extern Lisp_Object Vkey_translation_map; | |
a612e298 | 342 | |
86e5706b RS |
343 | /* Non-nil means deactivate the mark at end of this command. */ |
344 | Lisp_Object Vdeactivate_mark; | |
345 | ||
48e416d4 RS |
346 | /* Menu bar specified in Lucid Emacs fashion. */ |
347 | ||
348 | Lisp_Object Vlucid_menu_bar_dirty_flag; | |
349 | Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook; | |
350 | ||
cdb9d665 RS |
351 | Lisp_Object Qecho_area_clear_hook; |
352 | ||
86e5706b | 353 | /* Hooks to run before and after each command. */ |
59aadc81 RS |
354 | Lisp_Object Qpre_command_hook, Vpre_command_hook; |
355 | Lisp_Object Qpost_command_hook, Vpost_command_hook; | |
40932d1a | 356 | Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal; |
59aadc81 RS |
357 | /* Hook run after a command if there's no more input soon. */ |
358 | Lisp_Object Qpost_command_idle_hook, Vpost_command_idle_hook; | |
359 | ||
360 | /* Delay time in microseconds before running post-command-idle-hook. */ | |
361 | int post_command_idle_delay; | |
86e5706b | 362 | |
8a792f3a RS |
363 | /* List of deferred actions to be performed at a later time. |
364 | The precise format isn't relevant here; we just check whether it is nil. */ | |
365 | Lisp_Object Vdeferred_action_list; | |
366 | ||
367 | /* Function to call to handle deferred actions, when there are any. */ | |
368 | Lisp_Object Vdeferred_action_function; | |
3ef14e46 | 369 | Lisp_Object Qdeferred_action_function; |
8a792f3a | 370 | |
284f4730 JB |
371 | /* File in which we write all commands we read. */ |
372 | FILE *dribble; | |
373 | ||
374 | /* Nonzero if input is available. */ | |
375 | int input_pending; | |
376 | ||
b04904fb RS |
377 | /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should |
378 | keep 0200 bit in input chars. 0 to ignore the 0200 bit. */ | |
379 | ||
284f4730 JB |
380 | int meta_key; |
381 | ||
382 | extern char *pending_malloc_warning; | |
383 | ||
beecf6a1 KH |
384 | /* Circular buffer for pre-read keyboard input. */ |
385 | static struct input_event kbd_buffer[KBD_BUFFER_SIZE]; | |
386 | ||
387 | /* Vector to GCPRO the frames and windows mentioned in kbd_buffer. | |
388 | ||
389 | The interrupt-level event handlers will never enqueue an event on a | |
390 | frame which is not in Vframe_list, and once an event is dequeued, | |
391 | internal_last_event_frame or the event itself points to the frame. | |
392 | So that's all fine. | |
393 | ||
394 | But while the event is sitting in the queue, it's completely | |
395 | unprotected. Suppose the user types one command which will run for | |
396 | a while and then delete a frame, and then types another event at | |
397 | the frame that will be deleted, before the command gets around to | |
398 | it. Suppose there are no references to this frame elsewhere in | |
399 | Emacs, and a GC occurs before the second event is dequeued. Now we | |
400 | have an event referring to a freed frame, which will crash Emacs | |
401 | when it is dequeued. | |
402 | ||
403 | Similar things happen when an event on a scroll bar is enqueued; the | |
404 | window may be deleted while the event is in the queue. | |
405 | ||
406 | So, we use this vector to protect the frame_or_window field in the | |
407 | event queue. That way, they'll be dequeued as dead frames or | |
408 | windows, but still valid lisp objects. | |
409 | ||
410 | If kbd_buffer[i].kind != no_event, then | |
411 | (XVECTOR (kbd_buffer_frame_or_window)->contents[i] | |
412 | == kbd_buffer[i].frame_or_window. */ | |
413 | static Lisp_Object kbd_buffer_frame_or_window; | |
414 | ||
415 | /* Pointer to next available character in kbd_buffer. | |
416 | If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty. | |
417 | This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the | |
418 | next available char is in kbd_buffer[0]. */ | |
419 | static struct input_event *kbd_fetch_ptr; | |
420 | ||
421 | /* Pointer to next place to store character in kbd_buffer. This | |
422 | may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next | |
423 | character should go in kbd_buffer[0]. */ | |
424 | static volatile struct input_event *kbd_store_ptr; | |
425 | ||
426 | /* The above pair of variables forms a "queue empty" flag. When we | |
427 | enqueue a non-hook event, we increment kbd_store_ptr. When we | |
428 | dequeue a non-hook event, we increment kbd_fetch_ptr. We say that | |
429 | there is input available iff the two pointers are not equal. | |
430 | ||
431 | Why not just have a flag set and cleared by the enqueuing and | |
432 | dequeuing functions? Such a flag could be screwed up by interrupts | |
433 | at inopportune times. */ | |
434 | ||
f3253854 | 435 | /* If this flag is non-nil, we check mouse_moved to see when the |
a9d77f1f RS |
436 | mouse moves, and motion events will appear in the input stream. |
437 | Otherwise, mouse motion is ignored. */ | |
438 | static Lisp_Object do_mouse_tracking; | |
284f4730 | 439 | |
284f4730 JB |
440 | /* Symbols to head events. */ |
441 | Lisp_Object Qmouse_movement; | |
3c370943 | 442 | Lisp_Object Qscroll_bar_movement; |
cd21b839 | 443 | Lisp_Object Qswitch_frame; |
bbdc2092 | 444 | Lisp_Object Qdelete_frame; |
af17bd2b KH |
445 | Lisp_Object Qiconify_frame; |
446 | Lisp_Object Qmake_frame_visible; | |
cd21b839 | 447 | |
284f4730 JB |
448 | /* Symbols to denote kinds of events. */ |
449 | Lisp_Object Qfunction_key; | |
450 | Lisp_Object Qmouse_click; | |
07de30b9 GV |
451 | #ifdef WINDOWSNT |
452 | Lisp_Object Qmouse_wheel; | |
453 | #endif | |
a24dc617 | 454 | Lisp_Object Qdrag_n_drop; |
284f4730 | 455 | /* Lisp_Object Qmouse_movement; - also an event header */ |
284f4730 JB |
456 | |
457 | /* Properties of event headers. */ | |
458 | Lisp_Object Qevent_kind; | |
88cb0656 | 459 | Lisp_Object Qevent_symbol_elements; |
284f4730 | 460 | |
e8886a1d RS |
461 | /* menu item parts */ |
462 | Lisp_Object Qmenu_alias; | |
598a9fa7 | 463 | Lisp_Object Qmenu_enable; |
74c1de23 RS |
464 | Lisp_Object QCenable, QCvisible, QChelp, QCfilter, QCkeys, QCkey_sequence; |
465 | Lisp_Object QCbutton, QCtoggle, QCradio; | |
e8886a1d RS |
466 | extern Lisp_Object Vdefine_key_rebound_commands; |
467 | extern Lisp_Object Qmenu_item; | |
598a9fa7 | 468 | |
0a7f1fc0 JB |
469 | /* An event header symbol HEAD may have a property named |
470 | Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS); | |
471 | BASE is the base, unmodified version of HEAD, and MODIFIERS is the | |
472 | mask of modifiers applied to it. If present, this is used to help | |
473 | speed up parse_modifiers. */ | |
474 | Lisp_Object Qevent_symbol_element_mask; | |
475 | ||
476 | /* An unmodified event header BASE may have a property named | |
477 | Qmodifier_cache, which is an alist mapping modifier masks onto | |
478 | modified versions of BASE. If present, this helps speed up | |
479 | apply_modifiers. */ | |
480 | Lisp_Object Qmodifier_cache; | |
481 | ||
5ec75a55 | 482 | /* Symbols to use for parts of windows. */ |
284f4730 | 483 | Lisp_Object Qmode_line; |
e5d77022 | 484 | Lisp_Object Qvertical_line; |
3c370943 | 485 | Lisp_Object Qvertical_scroll_bar; |
5ec75a55 RS |
486 | Lisp_Object Qmenu_bar; |
487 | ||
f4255cd1 JB |
488 | Lisp_Object recursive_edit_unwind (), command_loop (); |
489 | Lisp_Object Fthis_command_keys (); | |
03b4122a | 490 | Lisp_Object Qextended_command_history; |
c04cbc3b | 491 | EMACS_TIME timer_check (); |
284f4730 | 492 | |
f4385381 RS |
493 | extern Lisp_Object Vhistory_length; |
494 | ||
2c834fb3 KH |
495 | extern char *x_get_keysym_name (); |
496 | ||
8eb4d8ef RS |
497 | static void record_menu_key (); |
498 | ||
f4eef8b4 RS |
499 | Lisp_Object Qpolling_period; |
500 | ||
d9d4c147 | 501 | /* List of absolute timers. Appears in order of next scheduled event. */ |
c04cbc3b RS |
502 | Lisp_Object Vtimer_list; |
503 | ||
d9d4c147 KH |
504 | /* List of idle time timers. Appears in order of next scheduled event. */ |
505 | Lisp_Object Vtimer_idle_list; | |
506 | ||
87dd9b9b RS |
507 | /* Incremented whenever a timer is run. */ |
508 | int timers_run; | |
509 | ||
a9f16aa9 KH |
510 | extern Lisp_Object Vprint_level, Vprint_length; |
511 | ||
ffd56f97 JB |
512 | /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt |
513 | happens. */ | |
514 | EMACS_TIME *input_available_clear_time; | |
284f4730 JB |
515 | |
516 | /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode. | |
517 | Default is 1 if INTERRUPT_INPUT is defined. */ | |
518 | int interrupt_input; | |
519 | ||
520 | /* Nonzero while interrupts are temporarily deferred during redisplay. */ | |
521 | int interrupts_deferred; | |
522 | ||
87dd9b9b | 523 | /* Nonzero means use ^S/^Q for flow control. */ |
284f4730 JB |
524 | int flow_control; |
525 | ||
284f4730 JB |
526 | /* Allow m- file to inhibit use of FIONREAD. */ |
527 | #ifdef BROKEN_FIONREAD | |
528 | #undef FIONREAD | |
529 | #endif | |
530 | ||
531 | /* We are unable to use interrupts if FIONREAD is not available, | |
532 | so flush SIGIO so we won't try. */ | |
533 | #ifndef FIONREAD | |
534 | #ifdef SIGIO | |
535 | #undef SIGIO | |
536 | #endif | |
537 | #endif | |
538 | ||
e98a93eb | 539 | /* If we support a window system, turn on the code to poll periodically |
34f04431 | 540 | to detect C-g. It isn't actually used when doing interrupt input. */ |
e98a93eb | 541 | #ifdef HAVE_WINDOW_SYSTEM |
284f4730 JB |
542 | #define POLL_FOR_INPUT |
543 | #endif | |
284f4730 JB |
544 | \f |
545 | /* Global variable declarations. */ | |
546 | ||
547 | /* Function for init_keyboard to call with no args (if nonzero). */ | |
548 | void (*keyboard_init_hook) (); | |
549 | ||
550 | static int read_avail_input (); | |
551 | static void get_input_pending (); | |
9fd7d808 | 552 | static int readable_events (); |
8150596a RS |
553 | static Lisp_Object read_char_x_menu_prompt (); |
554 | static Lisp_Object read_char_minibuf_menu_prompt (); | |
a612e298 | 555 | static Lisp_Object make_lispy_event (); |
514354e9 | 556 | #ifdef HAVE_MOUSE |
a612e298 | 557 | static Lisp_Object make_lispy_movement (); |
514354e9 | 558 | #endif |
a612e298 RS |
559 | static Lisp_Object modify_event_symbol (); |
560 | static Lisp_Object make_lispy_switch_frame (); | |
3d31316f | 561 | static int parse_solitary_modifier (); |
dfcf069d AS |
562 | static void save_getcjmp (); |
563 | static void restore_getcjmp (); | |
284f4730 JB |
564 | |
565 | /* > 0 if we are to echo keystrokes. */ | |
566 | static int echo_keystrokes; | |
567 | ||
8026024c KH |
568 | /* Nonzero means don't try to suspend even if the operating system seems |
569 | to support it. */ | |
570 | static int cannot_suspend; | |
571 | ||
284f4730 JB |
572 | #define min(a,b) ((a)<(b)?(a):(b)) |
573 | #define max(a,b) ((a)>(b)?(a):(b)) | |
574 | ||
575 | /* Install the string STR as the beginning of the string of echoing, | |
576 | so that it serves as a prompt for the next character. | |
577 | Also start echoing. */ | |
578 | ||
dfcf069d | 579 | void |
284f4730 JB |
580 | echo_prompt (str) |
581 | char *str; | |
582 | { | |
583 | int len = strlen (str); | |
7a80a6f6 | 584 | |
ba72822c KH |
585 | if (len > ECHOBUFSIZE - 4) |
586 | len = ECHOBUFSIZE - 4; | |
c5fdd383 KH |
587 | bcopy (str, current_kboard->echobuf, len); |
588 | current_kboard->echoptr = current_kboard->echobuf + len; | |
589 | *current_kboard->echoptr = '\0'; | |
284f4730 | 590 | |
c5fdd383 | 591 | current_kboard->echo_after_prompt = len; |
7a80a6f6 | 592 | |
3dbd9ee4 | 593 | echo_now (); |
284f4730 JB |
594 | } |
595 | ||
df0f2ba1 | 596 | /* Add C to the echo string, if echoing is going on. |
284f4730 JB |
597 | C can be a character, which is printed prettily ("M-C-x" and all that |
598 | jazz), or a symbol, whose name is printed. */ | |
599 | ||
dfcf069d | 600 | void |
284f4730 JB |
601 | echo_char (c) |
602 | Lisp_Object c; | |
603 | { | |
604 | extern char *push_key_description (); | |
605 | ||
c5fdd383 | 606 | if (current_kboard->immediate_echo) |
284f4730 | 607 | { |
c5fdd383 | 608 | char *ptr = current_kboard->echoptr; |
df0f2ba1 | 609 | |
c5fdd383 | 610 | if (ptr != current_kboard->echobuf) |
284f4730 JB |
611 | *ptr++ = ' '; |
612 | ||
613 | /* If someone has passed us a composite event, use its head symbol. */ | |
88cb0656 | 614 | c = EVENT_HEAD (c); |
284f4730 | 615 | |
8c18cbfb | 616 | if (INTEGERP (c)) |
284f4730 | 617 | { |
c5fdd383 | 618 | if (ptr - current_kboard->echobuf > ECHOBUFSIZE - 6) |
284f4730 JB |
619 | return; |
620 | ||
cb5df6ae | 621 | ptr = push_key_description (XINT (c), ptr); |
284f4730 | 622 | } |
8c18cbfb | 623 | else if (SYMBOLP (c)) |
284f4730 JB |
624 | { |
625 | struct Lisp_String *name = XSYMBOL (c)->name; | |
fc932ac6 | 626 | if ((ptr - current_kboard->echobuf) + STRING_BYTES (name) + 4 |
301738ed | 627 | > ECHOBUFSIZE) |
284f4730 | 628 | return; |
fc932ac6 RS |
629 | bcopy (name->data, ptr, STRING_BYTES (name)); |
630 | ptr += STRING_BYTES (name); | |
284f4730 JB |
631 | } |
632 | ||
c5fdd383 | 633 | if (current_kboard->echoptr == current_kboard->echobuf |
ecb7cb34 | 634 | && help_char_p (c)) |
284f4730 JB |
635 | { |
636 | strcpy (ptr, " (Type ? for further options)"); | |
637 | ptr += strlen (ptr); | |
638 | } | |
639 | ||
640 | *ptr = 0; | |
c5fdd383 | 641 | current_kboard->echoptr = ptr; |
284f4730 | 642 | |
3dbd9ee4 | 643 | echo_now (); |
284f4730 JB |
644 | } |
645 | } | |
646 | ||
647 | /* Temporarily add a dash to the end of the echo string if it's not | |
648 | empty, so that it serves as a mini-prompt for the very next character. */ | |
649 | ||
dfcf069d | 650 | void |
284f4730 JB |
651 | echo_dash () |
652 | { | |
c5fdd383 KH |
653 | if (!current_kboard->immediate_echo |
654 | && current_kboard->echoptr == current_kboard->echobuf) | |
284f4730 | 655 | return; |
7a80a6f6 | 656 | /* Do nothing if we just printed a prompt. */ |
c5fdd383 KH |
657 | if (current_kboard->echo_after_prompt |
658 | == current_kboard->echoptr - current_kboard->echobuf) | |
7a80a6f6 | 659 | return; |
4bafa972 | 660 | /* Do nothing if not echoing at all. */ |
c5fdd383 | 661 | if (current_kboard->echoptr == 0) |
4bafa972 | 662 | return; |
284f4730 JB |
663 | |
664 | /* Put a dash at the end of the buffer temporarily, | |
665 | but make it go away when the next character is added. */ | |
c5fdd383 KH |
666 | current_kboard->echoptr[0] = '-'; |
667 | current_kboard->echoptr[1] = 0; | |
284f4730 | 668 | |
3dbd9ee4 | 669 | echo_now (); |
284f4730 JB |
670 | } |
671 | ||
672 | /* Display the current echo string, and begin echoing if not already | |
673 | doing so. */ | |
674 | ||
07a59269 | 675 | void |
3dbd9ee4 | 676 | echo_now () |
284f4730 | 677 | { |
c5fdd383 | 678 | if (!current_kboard->immediate_echo) |
284f4730 JB |
679 | { |
680 | int i; | |
c5fdd383 | 681 | current_kboard->immediate_echo = 1; |
284f4730 JB |
682 | |
683 | for (i = 0; i < this_command_key_count; i++) | |
d0a57728 RS |
684 | { |
685 | Lisp_Object c; | |
686 | c = XVECTOR (this_command_keys)->contents[i]; | |
687 | if (! (EVENT_HAS_PARAMETERS (c) | |
688 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_movement))) | |
689 | echo_char (c); | |
690 | } | |
284f4730 JB |
691 | echo_dash (); |
692 | } | |
693 | ||
694 | echoing = 1; | |
301738ed RS |
695 | message2_nolog (current_kboard->echobuf, strlen (current_kboard->echobuf), |
696 | ! NILP (current_buffer->enable_multibyte_characters)); | |
697 | ||
284f4730 JB |
698 | echoing = 0; |
699 | ||
700 | if (waiting_for_input && !NILP (Vquit_flag)) | |
701 | quit_throw_to_read_char (); | |
702 | } | |
703 | ||
704 | /* Turn off echoing, for the start of a new command. */ | |
705 | ||
dfcf069d | 706 | void |
284f4730 JB |
707 | cancel_echoing () |
708 | { | |
c5fdd383 KH |
709 | current_kboard->immediate_echo = 0; |
710 | current_kboard->echoptr = current_kboard->echobuf; | |
711 | current_kboard->echo_after_prompt = -1; | |
1fc93d49 | 712 | ok_to_echo_at_next_pause = 0; |
284f4730 JB |
713 | } |
714 | ||
715 | /* Return the length of the current echo string. */ | |
716 | ||
717 | static int | |
718 | echo_length () | |
719 | { | |
c5fdd383 | 720 | return current_kboard->echoptr - current_kboard->echobuf; |
284f4730 JB |
721 | } |
722 | ||
723 | /* Truncate the current echo message to its first LEN chars. | |
724 | This and echo_char get used by read_key_sequence when the user | |
ff11dfa1 | 725 | switches frames while entering a key sequence. */ |
284f4730 JB |
726 | |
727 | static void | |
728 | echo_truncate (len) | |
729 | int len; | |
730 | { | |
c5fdd383 KH |
731 | current_kboard->echobuf[len] = '\0'; |
732 | current_kboard->echoptr = current_kboard->echobuf + len; | |
40932d1a | 733 | truncate_echo_area (len); |
284f4730 JB |
734 | } |
735 | ||
736 | \f | |
737 | /* Functions for manipulating this_command_keys. */ | |
738 | static void | |
739 | add_command_key (key) | |
740 | Lisp_Object key; | |
741 | { | |
6569cc8d JB |
742 | int size = XVECTOR (this_command_keys)->size; |
743 | ||
71918b75 RS |
744 | /* If reset-this-command-length was called recently, obey it now. |
745 | See the doc string of that function for an explanation of why. */ | |
746 | if (before_command_restore_flag) | |
747 | { | |
748 | this_command_key_count = before_command_key_count_1; | |
6321824f RS |
749 | if (this_command_key_count < this_single_command_key_start) |
750 | this_single_command_key_start = this_command_key_count; | |
71918b75 RS |
751 | echo_truncate (before_command_echo_length_1); |
752 | before_command_restore_flag = 0; | |
753 | } | |
754 | ||
6569cc8d | 755 | if (this_command_key_count >= size) |
284f4730 | 756 | { |
9b8eb840 | 757 | Lisp_Object new_keys; |
6569cc8d | 758 | |
9b8eb840 | 759 | new_keys = Fmake_vector (make_number (size * 2), Qnil); |
6569cc8d JB |
760 | bcopy (XVECTOR (this_command_keys)->contents, |
761 | XVECTOR (new_keys)->contents, | |
8f805655 | 762 | size * sizeof (Lisp_Object)); |
6569cc8d JB |
763 | |
764 | this_command_keys = new_keys; | |
284f4730 | 765 | } |
6569cc8d JB |
766 | |
767 | XVECTOR (this_command_keys)->contents[this_command_key_count++] = key; | |
284f4730 JB |
768 | } |
769 | \f | |
770 | Lisp_Object | |
771 | recursive_edit_1 () | |
772 | { | |
773 | int count = specpdl_ptr - specpdl; | |
774 | Lisp_Object val; | |
775 | ||
776 | if (command_loop_level > 0) | |
777 | { | |
778 | specbind (Qstandard_output, Qt); | |
779 | specbind (Qstandard_input, Qt); | |
780 | } | |
781 | ||
782 | val = command_loop (); | |
783 | if (EQ (val, Qt)) | |
784 | Fsignal (Qquit, Qnil); | |
cb252880 RS |
785 | /* Handle throw from read_minibuf when using minibuffer |
786 | while it's active but we're in another window. */ | |
787 | if (STRINGP (val)) | |
788 | Fsignal (Qerror, Fcons (val, Qnil)); | |
284f4730 | 789 | |
cb5df6ae | 790 | return unbind_to (count, Qnil); |
284f4730 JB |
791 | } |
792 | ||
793 | /* When an auto-save happens, record the "time", and don't do again soon. */ | |
5846638c | 794 | |
07a59269 | 795 | void |
284f4730 JB |
796 | record_auto_save () |
797 | { | |
c43b1734 | 798 | last_auto_save = num_nonmacro_input_events; |
284f4730 | 799 | } |
5846638c RS |
800 | |
801 | /* Make an auto save happen as soon as possible at command level. */ | |
802 | ||
dfcf069d | 803 | void |
5846638c RS |
804 | force_auto_save_soon () |
805 | { | |
806 | last_auto_save = - auto_save_interval - 1; | |
241ceaf7 RS |
807 | |
808 | record_asynch_buffer_change (); | |
5846638c | 809 | } |
284f4730 | 810 | \f |
284f4730 JB |
811 | DEFUN ("recursive-edit", Frecursive_edit, Srecursive_edit, 0, 0, "", |
812 | "Invoke the editor command loop recursively.\n\ | |
813 | To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\ | |
814 | that tells this function to return.\n\ | |
815 | Alternately, `(throw 'exit t)' makes this function signal an error.\n\ | |
816 | This function is called by the editor initialization to begin editing.") | |
817 | () | |
818 | { | |
819 | int count = specpdl_ptr - specpdl; | |
820 | Lisp_Object val; | |
821 | ||
822 | command_loop_level++; | |
823 | update_mode_lines = 1; | |
824 | ||
825 | record_unwind_protect (recursive_edit_unwind, | |
826 | (command_loop_level | |
827 | && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer)) | |
828 | ? Fcurrent_buffer () | |
829 | : Qnil); | |
830 | recursive_edit_1 (); | |
831 | return unbind_to (count, Qnil); | |
832 | } | |
833 | ||
834 | Lisp_Object | |
835 | recursive_edit_unwind (buffer) | |
836 | Lisp_Object buffer; | |
837 | { | |
838 | if (!NILP (buffer)) | |
839 | Fset_buffer (buffer); | |
840 | ||
841 | command_loop_level--; | |
842 | update_mode_lines = 1; | |
843 | return Qnil; | |
844 | } | |
845 | \f | |
604ccd1d | 846 | static void |
1e8bd3da | 847 | any_kboard_state () |
604ccd1d | 848 | { |
1e8bd3da RS |
849 | #ifdef MULTI_KBOARD |
850 | #if 0 /* Theory: if there's anything in Vunread_command_events, | |
851 | it will right away be read by read_key_sequence, | |
852 | and then if we do switch KBOARDS, it will go into the side | |
853 | queue then. So we don't need to do anything special here -- rms. */ | |
604ccd1d | 854 | if (CONSP (Vunread_command_events)) |
4524b161 | 855 | { |
c5fdd383 KH |
856 | current_kboard->kbd_queue |
857 | = nconc2 (Vunread_command_events, current_kboard->kbd_queue); | |
858 | current_kboard->kbd_queue_has_data = 1; | |
4524b161 | 859 | } |
604ccd1d | 860 | Vunread_command_events = Qnil; |
1e8bd3da RS |
861 | #endif |
862 | single_kboard = 0; | |
863 | #endif | |
604ccd1d | 864 | } |
1e8bd3da RS |
865 | |
866 | /* Switch to the single-kboard state, making current_kboard | |
867 | the only KBOARD from which further input is accepted. */ | |
868 | ||
869 | void | |
870 | single_kboard_state () | |
871 | { | |
872 | #ifdef MULTI_KBOARD | |
873 | single_kboard = 1; | |
604ccd1d | 874 | #endif |
1e8bd3da RS |
875 | } |
876 | ||
877 | /* Maintain a stack of kboards, so other parts of Emacs | |
878 | can switch temporarily to the kboard of a given frame | |
879 | and then revert to the previous status. */ | |
880 | ||
881 | struct kboard_stack | |
882 | { | |
883 | KBOARD *kboard; | |
884 | struct kboard_stack *next; | |
885 | }; | |
886 | ||
887 | static struct kboard_stack *kboard_stack; | |
888 | ||
889 | void | |
890 | push_frame_kboard (f) | |
891 | FRAME_PTR f; | |
892 | { | |
ab48365b | 893 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
894 | struct kboard_stack *p |
895 | = (struct kboard_stack *) xmalloc (sizeof (struct kboard_stack)); | |
896 | ||
897 | p->next = kboard_stack; | |
898 | p->kboard = current_kboard; | |
899 | kboard_stack = p; | |
900 | ||
901 | current_kboard = FRAME_KBOARD (f); | |
ab48365b | 902 | #endif |
1e8bd3da RS |
903 | } |
904 | ||
905 | void | |
906 | pop_frame_kboard () | |
907 | { | |
ab48365b | 908 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
909 | struct kboard_stack *p = kboard_stack; |
910 | current_kboard = p->kboard; | |
911 | kboard_stack = p->next; | |
912 | xfree (p); | |
ab48365b | 913 | #endif |
1e8bd3da RS |
914 | } |
915 | \f | |
916 | /* Handle errors that are not handled at inner levels | |
917 | by printing an error message and returning to the editor command loop. */ | |
604ccd1d | 918 | |
284f4730 JB |
919 | Lisp_Object |
920 | cmd_error (data) | |
921 | Lisp_Object data; | |
a1341f75 | 922 | { |
a9f16aa9 | 923 | Lisp_Object old_level, old_length; |
e881d8b2 RS |
924 | char macroerror[50]; |
925 | ||
926 | if (!NILP (executing_macro)) | |
927 | { | |
928 | if (executing_macro_iterations == 1) | |
929 | sprintf (macroerror, "After 1 kbd macro iteration: "); | |
930 | else | |
931 | sprintf (macroerror, "After %d kbd macro iterations: ", | |
932 | executing_macro_iterations); | |
933 | } | |
934 | else | |
935 | *macroerror = 0; | |
a9f16aa9 | 936 | |
a1341f75 RS |
937 | Vstandard_output = Qt; |
938 | Vstandard_input = Qt; | |
939 | Vexecuting_macro = Qnil; | |
9f58e89e | 940 | executing_macro = Qnil; |
d8bcf58e | 941 | current_kboard->Vprefix_arg = Qnil; |
75045dcb | 942 | current_kboard->Vlast_prefix_arg = Qnil; |
df0f2ba1 | 943 | cancel_echoing (); |
a9f16aa9 KH |
944 | |
945 | /* Avoid unquittable loop if data contains a circular list. */ | |
946 | old_level = Vprint_level; | |
947 | old_length = Vprint_length; | |
0c04a67e RS |
948 | XSETFASTINT (Vprint_level, 10); |
949 | XSETFASTINT (Vprint_length, 10); | |
e881d8b2 | 950 | cmd_error_internal (data, macroerror); |
a9f16aa9 KH |
951 | Vprint_level = old_level; |
952 | Vprint_length = old_length; | |
a1341f75 RS |
953 | |
954 | Vquit_flag = Qnil; | |
955 | ||
956 | Vinhibit_quit = Qnil; | |
c5fdd383 | 957 | #ifdef MULTI_KBOARD |
1e8bd3da | 958 | any_kboard_state (); |
ff4b06d3 | 959 | #endif |
a1341f75 RS |
960 | |
961 | return make_number (0); | |
962 | } | |
963 | ||
301738ed RS |
964 | /* Take actions on handling an error. DATA is the data that describes |
965 | the error. | |
966 | ||
967 | CONTEXT is a C-string containing ASCII characters only which | |
968 | describes the context in which the error happened. If we need to | |
969 | generalize CONTEXT to allow multibyte characters, make it a Lisp | |
970 | string. */ | |
971 | ||
07a59269 | 972 | void |
a1341f75 RS |
973 | cmd_error_internal (data, context) |
974 | Lisp_Object data; | |
975 | char *context; | |
284f4730 | 976 | { |
284f4730 | 977 | Lisp_Object stream; |
284f4730 JB |
978 | |
979 | Vquit_flag = Qnil; | |
980 | Vinhibit_quit = Qt; | |
284f4730 JB |
981 | echo_area_glyphs = 0; |
982 | ||
ff11dfa1 | 983 | /* If the window system or terminal frame hasn't been initialized |
284f4730 JB |
984 | yet, or we're not interactive, it's best to dump this message out |
985 | to stderr and exit. */ | |
ff11dfa1 | 986 | if (! FRAME_MESSAGE_BUF (selected_frame) |
284f4730 JB |
987 | || noninteractive) |
988 | stream = Qexternal_debugging_output; | |
989 | else | |
990 | { | |
991 | Fdiscard_input (); | |
992 | bitch_at_user (); | |
993 | stream = Qt; | |
994 | } | |
995 | ||
a1341f75 RS |
996 | if (context != 0) |
997 | write_string_1 (context, -1, stream); | |
998 | ||
22a51344 | 999 | print_error_message (data, stream); |
284f4730 | 1000 | |
ff11dfa1 | 1001 | /* If the window system or terminal frame hasn't been initialized |
284f4730 | 1002 | yet, or we're in -batch mode, this error should cause Emacs to exit. */ |
ff11dfa1 | 1003 | if (! FRAME_MESSAGE_BUF (selected_frame) |
284f4730 JB |
1004 | || noninteractive) |
1005 | { | |
1006 | Fterpri (stream); | |
1007 | Fkill_emacs (make_number (-1)); | |
1008 | } | |
284f4730 JB |
1009 | } |
1010 | \f | |
1011 | Lisp_Object command_loop_1 (); | |
1012 | Lisp_Object command_loop_2 (); | |
1013 | Lisp_Object top_level_1 (); | |
1014 | ||
1015 | /* Entry to editor-command-loop. | |
1016 | This level has the catches for exiting/returning to editor command loop. | |
1017 | It returns nil to exit recursive edit, t to abort it. */ | |
1018 | ||
1019 | Lisp_Object | |
1020 | command_loop () | |
1021 | { | |
1022 | if (command_loop_level > 0 || minibuf_level > 0) | |
1023 | { | |
1024 | return internal_catch (Qexit, command_loop_2, Qnil); | |
1025 | } | |
1026 | else | |
1027 | while (1) | |
1028 | { | |
1029 | internal_catch (Qtop_level, top_level_1, Qnil); | |
1030 | internal_catch (Qtop_level, command_loop_2, Qnil); | |
df0f2ba1 | 1031 | |
284f4730 JB |
1032 | /* End of file in -batch run causes exit here. */ |
1033 | if (noninteractive) | |
1034 | Fkill_emacs (Qt); | |
1035 | } | |
1036 | } | |
1037 | ||
1038 | /* Here we catch errors in execution of commands within the | |
1039 | editing loop, and reenter the editing loop. | |
1040 | When there is an error, cmd_error runs and returns a non-nil | |
1041 | value to us. A value of nil means that cmd_loop_1 itself | |
1042 | returned due to end of file (or end of kbd macro). */ | |
1043 | ||
1044 | Lisp_Object | |
1045 | command_loop_2 () | |
1046 | { | |
1047 | register Lisp_Object val; | |
1048 | ||
1049 | do | |
1050 | val = internal_condition_case (command_loop_1, Qerror, cmd_error); | |
1051 | while (!NILP (val)); | |
1052 | ||
1053 | return Qnil; | |
1054 | } | |
1055 | ||
1056 | Lisp_Object | |
1057 | top_level_2 () | |
1058 | { | |
1059 | return Feval (Vtop_level); | |
1060 | } | |
1061 | ||
1062 | Lisp_Object | |
1063 | top_level_1 () | |
1064 | { | |
1065 | /* On entry to the outer level, run the startup file */ | |
1066 | if (!NILP (Vtop_level)) | |
1067 | internal_condition_case (top_level_2, Qerror, cmd_error); | |
1068 | else if (!NILP (Vpurify_flag)) | |
1069 | message ("Bare impure Emacs (standard Lisp code not loaded)"); | |
1070 | else | |
1071 | message ("Bare Emacs (standard Lisp code not loaded)"); | |
1072 | return Qnil; | |
1073 | } | |
1074 | ||
1075 | DEFUN ("top-level", Ftop_level, Stop_level, 0, 0, "", | |
1076 | "Exit all recursive editing levels.") | |
1077 | () | |
1078 | { | |
1079 | Fthrow (Qtop_level, Qnil); | |
1080 | } | |
1081 | ||
1082 | DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, "", | |
1083 | "Exit from the innermost recursive edit or minibuffer.") | |
1084 | () | |
1085 | { | |
1086 | if (command_loop_level > 0 || minibuf_level > 0) | |
1087 | Fthrow (Qexit, Qnil); | |
1088 | ||
1089 | error ("No recursive edit is in progress"); | |
1090 | } | |
1091 | ||
1092 | DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0, 0, "", | |
1093 | "Abort the command that requested this recursive edit or minibuffer input.") | |
1094 | () | |
1095 | { | |
1096 | if (command_loop_level > 0 || minibuf_level > 0) | |
1097 | Fthrow (Qexit, Qt); | |
1098 | ||
1099 | error ("No recursive edit is in progress"); | |
1100 | } | |
1101 | \f | |
1102 | /* This is the actual command reading loop, | |
1103 | sans error-handling encapsulation. */ | |
1104 | ||
1105 | Lisp_Object Fcommand_execute (); | |
1106 | static int read_key_sequence (); | |
68f297c5 | 1107 | void safe_run_hooks (); |
284f4730 JB |
1108 | |
1109 | Lisp_Object | |
1110 | command_loop_1 () | |
1111 | { | |
48e416d4 | 1112 | Lisp_Object cmd, tem; |
37cd9f30 | 1113 | int lose, lose2; |
284f4730 JB |
1114 | int nonundocount; |
1115 | Lisp_Object keybuf[30]; | |
1116 | int i; | |
1117 | int no_redisplay; | |
1118 | int no_direct; | |
86e5706b RS |
1119 | int prev_modiff; |
1120 | struct buffer *prev_buffer; | |
c5fdd383 | 1121 | #ifdef MULTI_KBOARD |
1e8bd3da | 1122 | int was_locked = single_kboard; |
bded54dd | 1123 | #endif |
284f4730 | 1124 | |
d9b641bb | 1125 | current_kboard->Vprefix_arg = Qnil; |
75045dcb | 1126 | current_kboard->Vlast_prefix_arg = Qnil; |
86e5706b | 1127 | Vdeactivate_mark = Qnil; |
284f4730 | 1128 | waiting_for_input = 0; |
df0f2ba1 | 1129 | cancel_echoing (); |
284f4730 | 1130 | |
284f4730 JB |
1131 | nonundocount = 0; |
1132 | no_redisplay = 0; | |
1133 | this_command_key_count = 0; | |
6321824f | 1134 | this_single_command_key_start = 0; |
284f4730 | 1135 | |
a612e298 RS |
1136 | /* Make sure this hook runs after commands that get errors and |
1137 | throw to top level. */ | |
a98ea3f9 RS |
1138 | /* Note that the value cell will never directly contain nil |
1139 | if the symbol is a local variable. */ | |
e98a93eb | 1140 | if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) |
a98ea3f9 | 1141 | safe_run_hooks (Qpost_command_hook); |
a612e298 | 1142 | |
8a792f3a RS |
1143 | if (!NILP (Vdeferred_action_list)) |
1144 | call0 (Vdeferred_action_function); | |
1145 | ||
e98a93eb | 1146 | if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks)) |
59aadc81 RS |
1147 | { |
1148 | if (NILP (Vunread_command_events) | |
1149 | && NILP (Vexecuting_macro) | |
41365083 | 1150 | && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1))) |
59aadc81 RS |
1151 | safe_run_hooks (Qpost_command_idle_hook); |
1152 | } | |
1153 | ||
51d5a2c9 | 1154 | /* Do this after running Vpost_command_hook, for consistency. */ |
6c7178b9 | 1155 | current_kboard->Vlast_command = this_command; |
75045dcb | 1156 | current_kboard->Vreal_last_command = this_command; |
51d5a2c9 | 1157 | |
284f4730 JB |
1158 | while (1) |
1159 | { | |
284f4730 JB |
1160 | /* Make sure the current window's buffer is selected. */ |
1161 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
1162 | set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer)); | |
1163 | ||
1164 | /* Display any malloc warning that just came out. Use while because | |
1165 | displaying one warning can cause another. */ | |
1166 | ||
1167 | while (pending_malloc_warning) | |
1168 | display_malloc_warning (); | |
1169 | ||
1170 | no_direct = 0; | |
1171 | ||
86e5706b RS |
1172 | Vdeactivate_mark = Qnil; |
1173 | ||
284f4730 | 1174 | /* If minibuffer on and echo area in use, |
eb8c3be9 | 1175 | wait 2 sec and redraw minibuffer. */ |
284f4730 | 1176 | |
93127526 RS |
1177 | if (minibuf_level && echo_area_glyphs |
1178 | && EQ (minibuf_window, echo_area_window)) | |
284f4730 | 1179 | { |
f1bed6d8 RS |
1180 | /* Bind inhibit-quit to t so that C-g gets read in |
1181 | rather than quitting back to the minibuffer. */ | |
1182 | int count = specpdl_ptr - specpdl; | |
1183 | specbind (Qinhibit_quit, Qt); | |
f1bed6d8 | 1184 | |
db08707d | 1185 | Fsit_for (make_number (2), Qnil, Qnil); |
e6aa7813 | 1186 | /* Clear the echo area. */ |
301738ed | 1187 | message2 (0, 0, 0); |
cdb9d665 | 1188 | safe_run_hooks (Qecho_area_clear_hook); |
e6aa7813 | 1189 | |
db08707d RS |
1190 | unbind_to (count, Qnil); |
1191 | ||
e6aa7813 | 1192 | /* If a C-g came in before, treat it as input now. */ |
284f4730 JB |
1193 | if (!NILP (Vquit_flag)) |
1194 | { | |
1195 | Vquit_flag = Qnil; | |
24597608 | 1196 | Vunread_command_events = Fcons (make_number (quit_char), Qnil); |
284f4730 JB |
1197 | } |
1198 | } | |
1199 | ||
1200 | #ifdef C_ALLOCA | |
ff4b06d3 | 1201 | alloca (0); /* Cause a garbage collection now */ |
284f4730 JB |
1202 | /* Since we can free the most stuff here. */ |
1203 | #endif /* C_ALLOCA */ | |
1204 | ||
8f805655 | 1205 | #if 0 |
8f805655 JB |
1206 | /* Select the frame that the last event came from. Usually, |
1207 | switch-frame events will take care of this, but if some lisp | |
1208 | code swallows a switch-frame event, we'll fix things up here. | |
1209 | Is this a good idea? */ | |
8c18cbfb | 1210 | if (FRAMEP (internal_last_event_frame) |
3c370943 JB |
1211 | && XFRAME (internal_last_event_frame) != selected_frame) |
1212 | Fselect_frame (internal_last_event_frame, Qnil); | |
284f4730 | 1213 | #endif |
48e416d4 RS |
1214 | /* If it has changed current-menubar from previous value, |
1215 | really recompute the menubar from the value. */ | |
a646e520 RS |
1216 | if (! NILP (Vlucid_menu_bar_dirty_flag) |
1217 | && !NILP (Ffboundp (Qrecompute_lucid_menubar))) | |
48e416d4 RS |
1218 | call0 (Qrecompute_lucid_menubar); |
1219 | ||
71918b75 RS |
1220 | before_command_key_count = this_command_key_count; |
1221 | before_command_echo_length = echo_length (); | |
1222 | ||
d7437ef6 RS |
1223 | this_command = Qnil; |
1224 | ||
8f805655 | 1225 | /* Read next key sequence; i gets its length. */ |
ce98e608 | 1226 | i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0], |
f571ae0d | 1227 | Qnil, 0, 1, 1); |
8f805655 | 1228 | |
6fac1409 RS |
1229 | /* A filter may have run while we were reading the input. */ |
1230 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
1231 | set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer)); | |
1232 | ||
8f805655 JB |
1233 | ++num_input_keys; |
1234 | ||
284f4730 JB |
1235 | /* Now we have read a key sequence of length I, |
1236 | or else I is 0 and we found end of file. */ | |
1237 | ||
1238 | if (i == 0) /* End of file -- happens only in */ | |
1239 | return Qnil; /* a kbd macro, at the end. */ | |
dcc408a0 RS |
1240 | /* -1 means read_key_sequence got a menu that was rejected. |
1241 | Just loop around and read another command. */ | |
1242 | if (i == -1) | |
1243 | { | |
1244 | cancel_echoing (); | |
1245 | this_command_key_count = 0; | |
6321824f | 1246 | this_single_command_key_start = 0; |
ff4b06d3 | 1247 | goto finalize; |
dcc408a0 | 1248 | } |
284f4730 | 1249 | |
284f4730 JB |
1250 | last_command_char = keybuf[i - 1]; |
1251 | ||
75c0b143 RS |
1252 | /* If the previous command tried to force a specific window-start, |
1253 | forget about that, in case this command moves point far away | |
c422836d KH |
1254 | from that position. But also throw away beg_unchanged and |
1255 | end_unchanged information in that case, so that redisplay will | |
1256 | update the whole window properly. */ | |
1257 | if (!NILP (XWINDOW (selected_window)->force_start)) | |
1258 | { | |
1259 | XWINDOW (selected_window)->force_start = Qnil; | |
1260 | beg_unchanged = end_unchanged = 0; | |
1261 | } | |
75c0b143 | 1262 | |
284f4730 JB |
1263 | cmd = read_key_sequence_cmd; |
1264 | if (!NILP (Vexecuting_macro)) | |
1265 | { | |
1266 | if (!NILP (Vquit_flag)) | |
1267 | { | |
1268 | Vexecuting_macro = Qt; | |
1269 | QUIT; /* Make some noise. */ | |
1270 | /* Will return since macro now empty. */ | |
1271 | } | |
1272 | } | |
1273 | ||
1274 | /* Do redisplay processing after this command except in special | |
40932d1a RS |
1275 | cases identified below that set no_redisplay to 1. |
1276 | (actually, there's currently no way to prevent the redisplay, | |
1277 | and no_redisplay is ignored. | |
beecf6a1 | 1278 | Perhaps someday we will really implement it.) */ |
284f4730 JB |
1279 | no_redisplay = 0; |
1280 | ||
86e5706b RS |
1281 | prev_buffer = current_buffer; |
1282 | prev_modiff = MODIFF; | |
8746da95 | 1283 | last_point_position = PT; |
18cd2eeb | 1284 | XSETBUFFER (last_point_position_buffer, prev_buffer); |
86e5706b | 1285 | |
284f4730 JB |
1286 | /* Execute the command. */ |
1287 | ||
86e5706b | 1288 | this_command = cmd; |
a98ea3f9 RS |
1289 | /* Note that the value cell will never directly contain nil |
1290 | if the symbol is a local variable. */ | |
e98a93eb | 1291 | if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks)) |
a98ea3f9 | 1292 | safe_run_hooks (Qpre_command_hook); |
75045dcb | 1293 | |
258bf746 | 1294 | if (NILP (this_command)) |
284f4730 JB |
1295 | { |
1296 | /* nil means key is undefined. */ | |
1297 | bitch_at_user (); | |
c5fdd383 | 1298 | current_kboard->defining_kbd_macro = Qnil; |
284f4730 | 1299 | update_mode_lines = 1; |
d8bcf58e | 1300 | current_kboard->Vprefix_arg = Qnil; |
284f4730 JB |
1301 | } |
1302 | else | |
1303 | { | |
d8bcf58e | 1304 | if (NILP (current_kboard->Vprefix_arg) && ! no_direct) |
284f4730 | 1305 | { |
75045dcb RS |
1306 | /* In case we jump to directly_done. */ |
1307 | Vcurrent_prefix_arg = current_kboard->Vprefix_arg; | |
1308 | ||
284f4730 JB |
1309 | /* Recognize some common commands in common situations and |
1310 | do them directly. */ | |
8001d352 | 1311 | if (EQ (this_command, Qforward_char) && PT < ZV) |
284f4730 | 1312 | { |
51ad8a68 | 1313 | struct Lisp_Char_Table *dp |
284f4730 | 1314 | = window_display_table (XWINDOW (selected_window)); |
aaf35234 | 1315 | lose = FETCH_CHAR (PT_BYTE); |
8458ede6 | 1316 | SET_PT (PT + 1); |
0f7a8fee | 1317 | if ((dp |
82ba47d7 | 1318 | ? (VECTORP (DISP_CHAR_VECTOR (dp, lose)) |
9a5540db RS |
1319 | ? XVECTOR (DISP_CHAR_VECTOR (dp, lose))->size == 1 |
1320 | : (NILP (DISP_CHAR_VECTOR (dp, lose)) | |
1321 | && (lose >= 0x20 && lose < 0x7f))) | |
0f7a8fee | 1322 | : (lose >= 0x20 && lose < 0x7f)) |
37cd9f30 KH |
1323 | /* To extract the case of continuation on |
1324 | wide-column characters. */ | |
8458ede6 | 1325 | && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE)) == 1) |
284f4730 JB |
1326 | && (XFASTINT (XWINDOW (selected_window)->last_modified) |
1327 | >= MODIFF) | |
598ba4c7 RS |
1328 | && (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1329 | >= OVERLAY_MODIFF) | |
284f4730 | 1330 | && (XFASTINT (XWINDOW (selected_window)->last_point) |
8001d352 | 1331 | == PT - 1) |
284f4730 JB |
1332 | && !windows_or_buffers_changed |
1333 | && EQ (current_buffer->selective_display, Qnil) | |
1334 | && !detect_input_pending () | |
962ae636 | 1335 | && NILP (XWINDOW (selected_window)->column_number_displayed) |
284f4730 JB |
1336 | && NILP (Vexecuting_macro)) |
1337 | no_redisplay = direct_output_forward_char (1); | |
1338 | goto directly_done; | |
1339 | } | |
8001d352 | 1340 | else if (EQ (this_command, Qbackward_char) && PT > BEGV) |
284f4730 | 1341 | { |
51ad8a68 | 1342 | struct Lisp_Char_Table *dp |
284f4730 | 1343 | = window_display_table (XWINDOW (selected_window)); |
8458ede6 | 1344 | SET_PT (PT - 1); |
aaf35234 | 1345 | lose = FETCH_CHAR (PT_BYTE); |
0f7a8fee | 1346 | if ((dp |
ca873d73 | 1347 | ? (VECTORP (DISP_CHAR_VECTOR (dp, lose)) |
9a5540db RS |
1348 | ? XVECTOR (DISP_CHAR_VECTOR (dp, lose))->size == 1 |
1349 | : (NILP (DISP_CHAR_VECTOR (dp, lose)) | |
1350 | && (lose >= 0x20 && lose < 0x7f))) | |
0f7a8fee | 1351 | : (lose >= 0x20 && lose < 0x7f)) |
284f4730 JB |
1352 | && (XFASTINT (XWINDOW (selected_window)->last_modified) |
1353 | >= MODIFF) | |
598ba4c7 RS |
1354 | && (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1355 | >= OVERLAY_MODIFF) | |
284f4730 | 1356 | && (XFASTINT (XWINDOW (selected_window)->last_point) |
8001d352 | 1357 | == PT + 1) |
284f4730 JB |
1358 | && !windows_or_buffers_changed |
1359 | && EQ (current_buffer->selective_display, Qnil) | |
1360 | && !detect_input_pending () | |
962ae636 | 1361 | && NILP (XWINDOW (selected_window)->column_number_displayed) |
284f4730 JB |
1362 | && NILP (Vexecuting_macro)) |
1363 | no_redisplay = direct_output_forward_char (-1); | |
1364 | goto directly_done; | |
1365 | } | |
258bf746 | 1366 | else if (EQ (this_command, Qself_insert_command) |
284f4730 | 1367 | /* Try this optimization only on ascii keystrokes. */ |
8c18cbfb | 1368 | && INTEGERP (last_command_char)) |
284f4730 | 1369 | { |
89599794 | 1370 | unsigned int c = XINT (last_command_char); |
fc9cce4e | 1371 | int value; |
284f4730 | 1372 | |
fc9cce4e RS |
1373 | if (NILP (Vexecuting_macro) |
1374 | && !EQ (minibuf_window, selected_window)) | |
284f4730 JB |
1375 | { |
1376 | if (!nonundocount || nonundocount >= 20) | |
1377 | { | |
1378 | Fundo_boundary (); | |
1379 | nonundocount = 0; | |
1380 | } | |
1381 | nonundocount++; | |
1382 | } | |
fc9cce4e RS |
1383 | lose = ((XFASTINT (XWINDOW (selected_window)->last_modified) |
1384 | < MODIFF) | |
598ba4c7 RS |
1385 | || (XFASTINT (XWINDOW (selected_window)->last_overlay_modified) |
1386 | < OVERLAY_MODIFF) | |
fc9cce4e RS |
1387 | || (XFASTINT (XWINDOW (selected_window)->last_point) |
1388 | != PT) | |
4c61f38e | 1389 | || MODIFF <= SAVE_MODIFF |
fc9cce4e RS |
1390 | || windows_or_buffers_changed |
1391 | || !EQ (current_buffer->selective_display, Qnil) | |
1392 | || detect_input_pending () | |
962ae636 | 1393 | || !NILP (XWINDOW (selected_window)->column_number_displayed) |
fc9cce4e RS |
1394 | || !NILP (Vexecuting_macro)); |
1395 | value = internal_self_insert (c, 0); | |
1396 | if (value) | |
1397 | lose = 1; | |
1398 | if (value == 2) | |
1399 | nonundocount = 0; | |
1400 | ||
1401 | if (!lose | |
8458ede6 | 1402 | && (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n')) |
284f4730 | 1403 | { |
51ad8a68 | 1404 | struct Lisp_Char_Table *dp |
284f4730 | 1405 | = window_display_table (XWINDOW (selected_window)); |
b8d9050d | 1406 | int lose = c; |
284f4730 | 1407 | |
e3ee7487 RS |
1408 | /* Add the offset to the character, for Finsert_char. |
1409 | We pass internal_self_insert the unmodified character | |
1410 | because it itself does this offsetting. */ | |
2e9dc125 RS |
1411 | if (! NILP (current_buffer->enable_multibyte_characters)) |
1412 | lose = unibyte_char_to_multibyte (lose); | |
e3ee7487 | 1413 | |
0f7a8fee JB |
1414 | if (dp) |
1415 | { | |
9b8eb840 | 1416 | Lisp_Object obj; |
0f7a8fee | 1417 | |
9b8eb840 | 1418 | obj = DISP_CHAR_VECTOR (dp, lose); |
054c8675 | 1419 | if (NILP (obj)) |
8e91f441 RS |
1420 | { |
1421 | /* Do it only for char codes | |
1422 | that by default display as themselves. */ | |
1423 | if (lose >= 0x20 && lose <= 0x7e) | |
1424 | no_redisplay = direct_output_for_insert (lose); | |
1425 | } | |
8c18cbfb | 1426 | else if (VECTORP (obj) |
054c8675 | 1427 | && XVECTOR (obj)->size == 1 |
8c18cbfb KH |
1428 | && (obj = XVECTOR (obj)->contents[0], |
1429 | INTEGERP (obj)) | |
054c8675 RS |
1430 | /* Insist face not specified in glyph. */ |
1431 | && (XINT (obj) & ((-1) << 8)) == 0) | |
bd48a052 RS |
1432 | no_redisplay |
1433 | = direct_output_for_insert (XINT (obj)); | |
0f7a8fee JB |
1434 | } |
1435 | else | |
1436 | { | |
1437 | if (lose >= 0x20 && lose <= 0x7e) | |
1438 | no_redisplay = direct_output_for_insert (lose); | |
1439 | } | |
284f4730 JB |
1440 | } |
1441 | goto directly_done; | |
1442 | } | |
1443 | } | |
1444 | ||
1445 | /* Here for a command that isn't executed directly */ | |
1446 | ||
1447 | nonundocount = 0; | |
d8bcf58e | 1448 | if (NILP (current_kboard->Vprefix_arg)) |
284f4730 | 1449 | Fundo_boundary (); |
158f7532 | 1450 | Fcommand_execute (this_command, Qnil, Qnil, Qnil); |
284f4730 | 1451 | } |
a764a753 | 1452 | directly_done: ; |
75045dcb | 1453 | current_kboard->Vlast_prefix_arg = Vcurrent_prefix_arg; |
284f4730 | 1454 | |
84ee6048 RS |
1455 | /* Note that the value cell will never directly contain nil |
1456 | if the symbol is a local variable. */ | |
1457 | if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks)) | |
1458 | safe_run_hooks (Qpost_command_hook); | |
1459 | ||
1460 | if (!NILP (Vdeferred_action_list)) | |
1461 | safe_run_hooks (Qdeferred_action_function); | |
1462 | ||
1463 | if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks)) | |
1464 | { | |
1465 | if (NILP (Vunread_command_events) | |
1466 | && NILP (Vexecuting_macro) | |
1467 | && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1))) | |
1468 | safe_run_hooks (Qpost_command_idle_hook); | |
1469 | } | |
1470 | ||
284f4730 | 1471 | /* If there is a prefix argument, |
6c7178b9 KH |
1472 | 1) We don't want Vlast_command to be ``universal-argument'' |
1473 | (that would be dumb), so don't set Vlast_command, | |
284f4730 JB |
1474 | 2) we want to leave echoing on so that the prefix will be |
1475 | echoed as part of this key sequence, so don't call | |
1476 | cancel_echoing, and | |
1477 | 3) we want to leave this_command_key_count non-zero, so that | |
1478 | read_char will realize that it is re-reading a character, and | |
217258d5 KH |
1479 | not echo it a second time. |
1480 | ||
1481 | If the command didn't actually create a prefix arg, | |
1482 | but is merely a frame event that is transparent to prefix args, | |
1483 | then the above doesn't apply. */ | |
1484 | if (NILP (current_kboard->Vprefix_arg) || CONSP (last_command_char)) | |
284f4730 | 1485 | { |
6c7178b9 | 1486 | current_kboard->Vlast_command = this_command; |
75045dcb | 1487 | current_kboard->Vreal_last_command = this_command; |
284f4730 JB |
1488 | cancel_echoing (); |
1489 | this_command_key_count = 0; | |
6321824f | 1490 | this_single_command_key_start = 0; |
284f4730 | 1491 | } |
86e5706b | 1492 | |
88ce066e | 1493 | if (!NILP (current_buffer->mark_active) && !NILP (Vrun_hooks)) |
86e5706b RS |
1494 | { |
1495 | if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode)) | |
1496 | { | |
1497 | current_buffer->mark_active = Qnil; | |
1498 | call1 (Vrun_hooks, intern ("deactivate-mark-hook")); | |
1499 | } | |
1500 | else if (current_buffer != prev_buffer || MODIFF != prev_modiff) | |
1501 | call1 (Vrun_hooks, intern ("activate-mark-hook")); | |
1502 | } | |
ff4b06d3 KH |
1503 | |
1504 | finalize: | |
1505 | /* Install chars successfully executed in kbd macro. */ | |
1506 | ||
d8bcf58e KH |
1507 | if (!NILP (current_kboard->defining_kbd_macro) |
1508 | && NILP (current_kboard->Vprefix_arg)) | |
ff4b06d3 KH |
1509 | finalize_kbd_macro_chars (); |
1510 | ||
c5fdd383 | 1511 | #ifdef MULTI_KBOARD |
604ccd1d | 1512 | if (!was_locked) |
1e8bd3da | 1513 | any_kboard_state (); |
ff4b06d3 | 1514 | #endif |
284f4730 JB |
1515 | } |
1516 | } | |
1c9784c9 | 1517 | |
0bc3db2b RS |
1518 | /* Subroutine for safe_run_hooks: run the hook HOOK. */ |
1519 | ||
1520 | static Lisp_Object | |
1521 | safe_run_hooks_1 (hook) | |
1522 | Lisp_Object hook; | |
1523 | { | |
1524 | return call1 (Vrun_hooks, Vinhibit_quit); | |
1525 | } | |
1526 | ||
1527 | /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */ | |
1528 | ||
1529 | static Lisp_Object | |
1530 | safe_run_hooks_error (data) | |
1531 | Lisp_Object data; | |
1532 | { | |
1533 | Fset (Vinhibit_quit, Qnil); | |
1534 | } | |
1535 | ||
1c9784c9 KH |
1536 | /* If we get an error while running the hook, cause the hook variable |
1537 | to be nil. Also inhibit quits, so that C-g won't cause the hook | |
1538 | to mysteriously evaporate. */ | |
0bc3db2b | 1539 | |
68f297c5 | 1540 | void |
1c9784c9 | 1541 | safe_run_hooks (hook) |
a98ea3f9 | 1542 | Lisp_Object hook; |
1c9784c9 | 1543 | { |
68553292 | 1544 | Lisp_Object value; |
1c9784c9 | 1545 | int count = specpdl_ptr - specpdl; |
0bc3db2b RS |
1546 | specbind (Qinhibit_quit, hook); |
1547 | ||
e702932d | 1548 | internal_condition_case (safe_run_hooks_1, Qt, safe_run_hooks_error); |
1c9784c9 KH |
1549 | |
1550 | unbind_to (count, Qnil); | |
1551 | } | |
284f4730 JB |
1552 | \f |
1553 | /* Number of seconds between polling for input. */ | |
1554 | int polling_period; | |
1555 | ||
eb8c3be9 | 1556 | /* Nonzero means polling for input is temporarily suppressed. */ |
284f4730 JB |
1557 | int poll_suppress_count; |
1558 | ||
36922b18 | 1559 | /* Nonzero if polling_for_input is actually being used. */ |
284f4730 JB |
1560 | int polling_for_input; |
1561 | ||
36922b18 RS |
1562 | #ifdef POLL_FOR_INPUT |
1563 | ||
284f4730 JB |
1564 | /* Handle an alarm once each second and read pending input |
1565 | so as to handle a C-g if it comces in. */ | |
1566 | ||
1567 | SIGTYPE | |
91c049d4 RS |
1568 | input_poll_signal (signalnum) /* If we don't have an argument, */ |
1569 | int signalnum; /* some compilers complain in signal calls. */ | |
284f4730 | 1570 | { |
87dd9b9b RS |
1571 | /* This causes the call to start_polling at the end |
1572 | to do its job. It also arranges for a quit or error | |
1573 | from within read_avail_input to resume polling. */ | |
1574 | poll_suppress_count++; | |
9ac0d9e0 JB |
1575 | if (interrupt_input_blocked == 0 |
1576 | && !waiting_for_input) | |
1577 | read_avail_input (0); | |
87dd9b9b RS |
1578 | /* Turn on the SIGALRM handler and request another alarm. */ |
1579 | start_polling (); | |
284f4730 JB |
1580 | } |
1581 | ||
1582 | #endif | |
1583 | ||
1584 | /* Begin signals to poll for input, if they are appropriate. | |
1585 | This function is called unconditionally from various places. */ | |
1586 | ||
07a59269 | 1587 | void |
284f4730 JB |
1588 | start_polling () |
1589 | { | |
1590 | #ifdef POLL_FOR_INPUT | |
34f04431 | 1591 | if (read_socket_hook && !interrupt_input) |
284f4730 JB |
1592 | { |
1593 | poll_suppress_count--; | |
1594 | if (poll_suppress_count == 0) | |
1595 | { | |
1596 | signal (SIGALRM, input_poll_signal); | |
1597 | polling_for_input = 1; | |
1598 | alarm (polling_period); | |
1599 | } | |
1600 | } | |
1601 | #endif | |
1602 | } | |
1603 | ||
1d3195db RS |
1604 | /* Nonzero if we are using polling to handle input asynchronously. */ |
1605 | ||
1606 | int | |
1607 | input_polling_used () | |
1608 | { | |
1609 | #ifdef POLL_FOR_INPUT | |
1610 | return read_socket_hook && !interrupt_input; | |
1611 | #else | |
1612 | return 0; | |
1613 | #endif | |
1614 | } | |
1615 | ||
284f4730 JB |
1616 | /* Turn off polling. */ |
1617 | ||
07a59269 | 1618 | void |
284f4730 JB |
1619 | stop_polling () |
1620 | { | |
1621 | #ifdef POLL_FOR_INPUT | |
34f04431 | 1622 | if (read_socket_hook && !interrupt_input) |
284f4730 JB |
1623 | { |
1624 | if (poll_suppress_count == 0) | |
1625 | { | |
1626 | polling_for_input = 0; | |
1627 | alarm (0); | |
1628 | } | |
1629 | poll_suppress_count++; | |
1630 | } | |
1631 | #endif | |
1632 | } | |
fe8aeef3 RS |
1633 | |
1634 | /* Set the value of poll_suppress_count to COUNT | |
1635 | and start or stop polling accordingly. */ | |
1636 | ||
1637 | void | |
1638 | set_poll_suppress_count (count) | |
1639 | int count; | |
1640 | { | |
1641 | #ifdef POLL_FOR_INPUT | |
1642 | if (count == 0 && poll_suppress_count != 0) | |
1643 | { | |
1644 | poll_suppress_count = 1; | |
1645 | start_polling (); | |
1646 | } | |
1647 | else if (count != 0 && poll_suppress_count == 0) | |
1648 | { | |
1649 | stop_polling (); | |
1650 | } | |
1651 | poll_suppress_count = count; | |
1652 | #endif | |
1653 | } | |
f4eef8b4 | 1654 | |
d0a57728 RS |
1655 | /* Bind polling_period to a value at least N. |
1656 | But don't decrease it. */ | |
1657 | ||
07a59269 | 1658 | void |
f4eef8b4 RS |
1659 | bind_polling_period (n) |
1660 | int n; | |
1661 | { | |
1662 | #ifdef POLL_FOR_INPUT | |
d0a57728 RS |
1663 | int new = polling_period; |
1664 | ||
1665 | if (n > new) | |
1666 | new = n; | |
1667 | ||
f4eef8b4 | 1668 | stop_polling (); |
d0a57728 RS |
1669 | specbind (Qpolling_period, make_number (new)); |
1670 | /* Start a new alarm with the new period. */ | |
f4eef8b4 RS |
1671 | start_polling (); |
1672 | #endif | |
1673 | } | |
284f4730 | 1674 | \f |
6da3dd3a RS |
1675 | /* Apply the control modifier to CHARACTER. */ |
1676 | ||
faf5e407 JB |
1677 | int |
1678 | make_ctrl_char (c) | |
1679 | int c; | |
1680 | { | |
d205953b JB |
1681 | /* Save the upper bits here. */ |
1682 | int upper = c & ~0177; | |
1683 | ||
1684 | c &= 0177; | |
1685 | ||
1686 | /* Everything in the columns containing the upper-case letters | |
1687 | denotes a control character. */ | |
1688 | if (c >= 0100 && c < 0140) | |
1689 | { | |
1690 | int oc = c; | |
1691 | c &= ~0140; | |
1692 | /* Set the shift modifier for a control char | |
1693 | made from a shifted letter. But only for letters! */ | |
1694 | if (oc >= 'A' && oc <= 'Z') | |
1695 | c |= shift_modifier; | |
1696 | } | |
1697 | ||
1698 | /* The lower-case letters denote control characters too. */ | |
1699 | else if (c >= 'a' && c <= 'z') | |
1700 | c &= ~0140; | |
1701 | ||
1702 | /* Include the bits for control and shift | |
1703 | only if the basic ASCII code can't indicate them. */ | |
1704 | else if (c >= ' ') | |
1705 | c |= ctrl_modifier; | |
1706 | ||
1707 | /* Replace the high bits. */ | |
1708 | c |= (upper & ~ctrl_modifier); | |
faf5e407 JB |
1709 | |
1710 | return c; | |
1711 | } | |
1712 | ||
1713 | ||
1714 | \f | |
284f4730 JB |
1715 | /* Input of single characters from keyboard */ |
1716 | ||
1717 | Lisp_Object print_help (); | |
1718 | static Lisp_Object kbd_buffer_get_event (); | |
e4fe371d | 1719 | static void record_char (); |
284f4730 | 1720 | |
c5fdd383 KH |
1721 | #ifdef MULTI_KBOARD |
1722 | static jmp_buf wrong_kboard_jmpbuf; | |
bded54dd | 1723 | #endif |
beecf6a1 | 1724 | |
284f4730 JB |
1725 | /* read a character from the keyboard; call the redisplay if needed */ |
1726 | /* commandflag 0 means do not do auto-saving, but do do redisplay. | |
1727 | -1 means do not do redisplay, but do do autosaving. | |
1728 | 1 means do both. */ | |
1729 | ||
7d6de002 RS |
1730 | /* The arguments MAPS and NMAPS are for menu prompting. |
1731 | MAPS is an array of keymaps; NMAPS is the length of MAPS. | |
1732 | ||
1733 | PREV_EVENT is the previous input event, or nil if we are reading | |
1734 | the first event of a key sequence. | |
1735 | ||
83d68044 | 1736 | If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1 |
6569cc8d | 1737 | if we used a mouse menu to read the input, or zero otherwise. If |
83d68044 | 1738 | USED_MOUSE_MENU is null, we don't dereference it. |
dcc408a0 RS |
1739 | |
1740 | Value is t if we showed a menu and the user rejected it. */ | |
7d6de002 | 1741 | |
284f4730 | 1742 | Lisp_Object |
7d6de002 | 1743 | read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu) |
284f4730 | 1744 | int commandflag; |
7d6de002 RS |
1745 | int nmaps; |
1746 | Lisp_Object *maps; | |
1747 | Lisp_Object prev_event; | |
1748 | int *used_mouse_menu; | |
284f4730 | 1749 | { |
7c3bc944 | 1750 | Lisp_Object c; |
284f4730 | 1751 | int count; |
410d4de9 | 1752 | jmp_buf local_getcjmp; |
284f4730 | 1753 | jmp_buf save_jump; |
a1341f75 | 1754 | int key_already_recorded = 0; |
017c7cb6 | 1755 | Lisp_Object tem, save; |
e4fe371d | 1756 | Lisp_Object also_record; |
7c3bc944 RS |
1757 | struct gcpro gcpro1; |
1758 | ||
e4fe371d | 1759 | also_record = Qnil; |
284f4730 | 1760 | |
71918b75 RS |
1761 | before_command_key_count = this_command_key_count; |
1762 | before_command_echo_length = echo_length (); | |
ef6661f7 | 1763 | c = Qnil; |
71918b75 | 1764 | |
7c3bc944 RS |
1765 | GCPRO1 (c); |
1766 | ||
7f07d5ca RS |
1767 | retry: |
1768 | ||
24597608 | 1769 | if (CONSP (Vunread_command_events)) |
284f4730 | 1770 | { |
24597608 RS |
1771 | c = XCONS (Vunread_command_events)->car; |
1772 | Vunread_command_events = XCONS (Vunread_command_events)->cdr; | |
284f4730 | 1773 | |
2479e91e RS |
1774 | /* Undo what read_char_x_menu_prompt did when it unread |
1775 | additional keys returned by Fx_popup_menu. */ | |
1776 | if (CONSP (c) | |
1777 | && (SYMBOLP (XCONS (c)->car) || INTEGERP (XCONS (c)->car)) | |
1778 | && NILP (XCONS (c)->cdr)) | |
1779 | c = XCONS (c)->car; | |
1780 | ||
284f4730 JB |
1781 | if (this_command_key_count == 0) |
1782 | goto reread_first; | |
1783 | else | |
1784 | goto reread; | |
1785 | } | |
1786 | ||
86e5706b RS |
1787 | if (unread_command_char != -1) |
1788 | { | |
18cd2eeb | 1789 | XSETINT (c, unread_command_char); |
86e5706b RS |
1790 | unread_command_char = -1; |
1791 | ||
1792 | if (this_command_key_count == 0) | |
1793 | goto reread_first; | |
1794 | else | |
1795 | goto reread; | |
1796 | } | |
1797 | ||
71918b75 RS |
1798 | /* If there is no function key translated before |
1799 | reset-this-command-lengths takes effect, forget about it. */ | |
1800 | before_command_restore_flag = 0; | |
1801 | ||
284f4730 JB |
1802 | if (!NILP (Vexecuting_macro)) |
1803 | { | |
fce33686 JB |
1804 | /* We set this to Qmacro; since that's not a frame, nobody will |
1805 | try to switch frames on us, and the selected window will | |
1806 | remain unchanged. | |
1807 | ||
1808 | Since this event came from a macro, it would be misleading to | |
eb8c3be9 | 1809 | leave internal_last_event_frame set to wherever the last |
3c370943 JB |
1810 | real event came from. Normally, a switch-frame event selects |
1811 | internal_last_event_frame after each command is read, but | |
1812 | events read from a macro should never cause a new frame to be | |
1813 | selected. */ | |
4c52b668 | 1814 | Vlast_event_frame = internal_last_event_frame = Qmacro; |
fce33686 | 1815 | |
663258f2 JB |
1816 | /* Exit the macro if we are at the end. |
1817 | Also, some things replace the macro with t | |
1818 | to force an early exit. */ | |
1819 | if (EQ (Vexecuting_macro, Qt) | |
1820 | || executing_macro_index >= XFASTINT (Flength (Vexecuting_macro))) | |
284f4730 | 1821 | { |
18cd2eeb | 1822 | XSETINT (c, -1); |
7c3bc944 | 1823 | RETURN_UNGCPRO (c); |
284f4730 | 1824 | } |
df0f2ba1 | 1825 | |
284f4730 | 1826 | c = Faref (Vexecuting_macro, make_number (executing_macro_index)); |
8c18cbfb | 1827 | if (STRINGP (Vexecuting_macro) |
86e5706b | 1828 | && (XINT (c) & 0x80)) |
bb9e9bed | 1829 | XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80)); |
86e5706b | 1830 | |
284f4730 JB |
1831 | executing_macro_index++; |
1832 | ||
1833 | goto from_macro; | |
1834 | } | |
1835 | ||
cd21b839 JB |
1836 | if (!NILP (unread_switch_frame)) |
1837 | { | |
1838 | c = unread_switch_frame; | |
1839 | unread_switch_frame = Qnil; | |
1840 | ||
1841 | /* This event should make it into this_command_keys, and get echoed | |
f4255cd1 JB |
1842 | again, so we go to reread_first, rather than reread. */ |
1843 | goto reread_first; | |
cd21b839 JB |
1844 | } |
1845 | ||
adc1d5c8 | 1846 | /* if redisplay was requested */ |
6e4e64a8 RS |
1847 | if (commandflag >= 0) |
1848 | { | |
adc1d5c8 RS |
1849 | /* If there is pending input, process any events which are not |
1850 | user-visible, such as X selection_request events. */ | |
6e4e64a8 RS |
1851 | if (input_pending |
1852 | || detect_input_pending_run_timers (0)) | |
adc1d5c8 | 1853 | swallow_events (0); /* may clear input_pending */ |
6e4e64a8 | 1854 | |
adc1d5c8 RS |
1855 | /* Redisplay if no pending input. */ |
1856 | while (!input_pending) | |
1857 | { | |
1858 | redisplay (); | |
1859 | ||
1860 | if (!input_pending) | |
1861 | /* Normal case: no input arrived during redisplay. */ | |
1862 | break; | |
1863 | ||
1864 | /* Input arrived and pre-empted redisplay. | |
1865 | Process any events which are not user-visible. */ | |
1866 | swallow_events (0); | |
1867 | /* If that cleared input_pending, try again to redisplay. */ | |
1868 | } | |
6e4e64a8 | 1869 | } |
e9bf89a0 | 1870 | |
410d4de9 RS |
1871 | /* Message turns off echoing unless more keystrokes turn it on again. */ |
1872 | if (echo_area_glyphs && *echo_area_glyphs | |
1fc93d49 | 1873 | && echo_area_glyphs != current_kboard->echobuf |
0c04a67e | 1874 | && ok_to_echo_at_next_pause != echo_area_glyphs) |
410d4de9 RS |
1875 | cancel_echoing (); |
1876 | else | |
1877 | /* If already echoing, continue. */ | |
1878 | echo_dash (); | |
284f4730 | 1879 | |
410d4de9 RS |
1880 | /* Try reading a character via menu prompting in the minibuf. |
1881 | Try this before the sit-for, because the sit-for | |
1882 | would do the wrong thing if we are supposed to do | |
1883 | menu prompting. If EVENT_HAS_PARAMETERS then we are reading | |
1884 | after a mouse event so don't try a minibuf menu. */ | |
1885 | c = Qnil; | |
1886 | if (nmaps > 0 && INTERACTIVE | |
1887 | && !NILP (prev_event) && ! EVENT_HAS_PARAMETERS (prev_event) | |
1888 | /* Don't bring up a menu if we already have another event. */ | |
1889 | && NILP (Vunread_command_events) | |
1890 | && unread_command_char < 0 | |
4ec4ed6a | 1891 | && !detect_input_pending_run_timers (0)) |
410d4de9 RS |
1892 | { |
1893 | c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps); | |
1894 | if (! NILP (c)) | |
1895 | { | |
1896 | key_already_recorded = 1; | |
1897 | goto non_reread_1; | |
1898 | } | |
1899 | } | |
284f4730 | 1900 | |
410d4de9 RS |
1901 | /* Make a longjmp point for quits to use, but don't alter getcjmp just yet. |
1902 | We will do that below, temporarily for short sections of code, | |
1903 | when appropriate. local_getcjmp must be in effect | |
1904 | around any call to sit_for or kbd_buffer_get_event; | |
1905 | it *must not* be in effect when we call redisplay. */ | |
284f4730 | 1906 | |
410d4de9 | 1907 | if (_setjmp (local_getcjmp)) |
284f4730 | 1908 | { |
18cd2eeb | 1909 | XSETINT (c, quit_char); |
4c52b668 KH |
1910 | XSETFRAME (internal_last_event_frame, selected_frame); |
1911 | Vlast_event_frame = internal_last_event_frame; | |
04904c29 RS |
1912 | /* If we report the quit char as an event, |
1913 | don't do so more than once. */ | |
1914 | if (!NILP (Vinhibit_quit)) | |
1915 | Vquit_flag = Qnil; | |
284f4730 | 1916 | |
c5fdd383 | 1917 | #ifdef MULTI_KBOARD |
df0f2ba1 | 1918 | { |
c5fdd383 KH |
1919 | KBOARD *kb = FRAME_KBOARD (selected_frame); |
1920 | if (kb != current_kboard) | |
df0f2ba1 | 1921 | { |
c5fdd383 | 1922 | Lisp_Object *tailp = &kb->kbd_queue; |
1e8bd3da RS |
1923 | /* We shouldn't get here if we were in single-kboard mode! */ |
1924 | if (single_kboard) | |
df0f2ba1 KH |
1925 | abort (); |
1926 | while (CONSP (*tailp)) | |
1927 | tailp = &XCONS (*tailp)->cdr; | |
1928 | if (!NILP (*tailp)) | |
1929 | abort (); | |
1930 | *tailp = Fcons (c, Qnil); | |
c5fdd383 KH |
1931 | kb->kbd_queue_has_data = 1; |
1932 | current_kboard = kb; | |
ef6661f7 RS |
1933 | /* This is going to exit from read_char |
1934 | so we had better get rid of this frame's stuff. */ | |
1935 | UNGCPRO; | |
c5fdd383 | 1936 | longjmp (wrong_kboard_jmpbuf, 1); |
df0f2ba1 KH |
1937 | } |
1938 | } | |
1939 | #endif | |
284f4730 JB |
1940 | goto non_reread; |
1941 | } | |
1942 | ||
d9d4c147 KH |
1943 | timer_start_idle (); |
1944 | ||
284f4730 JB |
1945 | /* If in middle of key sequence and minibuffer not active, |
1946 | start echoing if enough time elapses. */ | |
410d4de9 | 1947 | |
c5fdd383 | 1948 | if (minibuf_level == 0 && !current_kboard->immediate_echo |
6c6083a9 | 1949 | && this_command_key_count > 0 |
27203ead | 1950 | && ! noninteractive |
284f4730 | 1951 | && echo_keystrokes > 0 |
1fc93d49 | 1952 | && (echo_area_glyphs == 0 || *echo_area_glyphs == 0 |
0c04a67e | 1953 | || ok_to_echo_at_next_pause == echo_area_glyphs)) |
284f4730 JB |
1954 | { |
1955 | Lisp_Object tem0; | |
1956 | ||
7d6de002 RS |
1957 | /* After a mouse event, start echoing right away. |
1958 | This is because we are probably about to display a menu, | |
1959 | and we don't want to delay before doing so. */ | |
dbc4e1c1 | 1960 | if (EVENT_HAS_PARAMETERS (prev_event)) |
3dbd9ee4 | 1961 | echo_now (); |
7d6de002 RS |
1962 | else |
1963 | { | |
410d4de9 RS |
1964 | save_getcjmp (save_jump); |
1965 | restore_getcjmp (local_getcjmp); | |
41365083 | 1966 | tem0 = sit_for (echo_keystrokes, 0, 1, 1, 0); |
410d4de9 | 1967 | restore_getcjmp (save_jump); |
303b5b3f RS |
1968 | if (EQ (tem0, Qt) |
1969 | && ! CONSP (Vunread_command_events)) | |
3dbd9ee4 | 1970 | echo_now (); |
7d6de002 | 1971 | } |
284f4730 JB |
1972 | } |
1973 | ||
410d4de9 | 1974 | /* Maybe auto save due to number of keystrokes. */ |
284f4730 JB |
1975 | |
1976 | if (commandflag != 0 | |
1977 | && auto_save_interval > 0 | |
c43b1734 | 1978 | && num_nonmacro_input_events - last_auto_save > max (auto_save_interval, 20) |
4ec4ed6a | 1979 | && !detect_input_pending_run_timers (0)) |
284f4730 | 1980 | { |
284f4730 | 1981 | Fdo_auto_save (Qnil, Qnil); |
ef8fd672 RS |
1982 | /* Hooks can actually change some buffers in auto save. */ |
1983 | redisplay (); | |
284f4730 JB |
1984 | } |
1985 | ||
8150596a | 1986 | /* Try reading using an X menu. |
24597608 RS |
1987 | This is never confused with reading using the minibuf |
1988 | because the recursive call of read_char in read_char_minibuf_menu_prompt | |
1989 | does not pass on any keymaps. */ | |
410d4de9 | 1990 | |
24597608 | 1991 | if (nmaps > 0 && INTERACTIVE |
5a8d99e0 KH |
1992 | && !NILP (prev_event) |
1993 | && EVENT_HAS_PARAMETERS (prev_event) | |
1994 | && !EQ (XCONS (prev_event)->car, Qmenu_bar) | |
24597608 RS |
1995 | /* Don't bring up a menu if we already have another event. */ |
1996 | && NILP (Vunread_command_events) | |
b8556aee | 1997 | && unread_command_char < 0) |
8eb4d8ef RS |
1998 | { |
1999 | c = read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu); | |
2000 | ||
2001 | /* Now that we have read an event, Emacs is not idle. */ | |
2002 | timer_stop_idle (); | |
2003 | ||
7c3bc944 | 2004 | RETURN_UNGCPRO (c); |
8eb4d8ef | 2005 | } |
7d6de002 | 2006 | |
410d4de9 RS |
2007 | /* Maybe autosave and/or garbage collect due to idleness. */ |
2008 | ||
26c1639e | 2009 | if (INTERACTIVE && NILP (c)) |
7d6de002 RS |
2010 | { |
2011 | int delay_level, buffer_size; | |
2012 | ||
410d4de9 RS |
2013 | /* Slow down auto saves logarithmically in size of current buffer, |
2014 | and garbage collect while we're at it. */ | |
7d6de002 RS |
2015 | if (! MINI_WINDOW_P (XWINDOW (selected_window))) |
2016 | last_non_minibuf_size = Z - BEG; | |
2017 | buffer_size = (last_non_minibuf_size >> 8) + 1; | |
2018 | delay_level = 0; | |
2019 | while (buffer_size > 64) | |
2020 | delay_level++, buffer_size -= buffer_size >> 2; | |
2021 | if (delay_level < 4) delay_level = 4; | |
2022 | /* delay_level is 4 for files under around 50k, 7 at 100k, | |
2023 | 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */ | |
2024 | ||
2025 | /* Auto save if enough time goes by without input. */ | |
2026 | if (commandflag != 0 | |
c43b1734 | 2027 | && num_nonmacro_input_events > last_auto_save |
8c18cbfb | 2028 | && INTEGERP (Vauto_save_timeout) |
7d6de002 RS |
2029 | && XINT (Vauto_save_timeout) > 0) |
2030 | { | |
2031 | Lisp_Object tem0; | |
410d4de9 RS |
2032 | |
2033 | save_getcjmp (save_jump); | |
2034 | restore_getcjmp (local_getcjmp); | |
d9d4c147 | 2035 | tem0 = sit_for (delay_level * XFASTINT (Vauto_save_timeout) / 4, |
41365083 | 2036 | 0, 1, 1, 0); |
410d4de9 RS |
2037 | restore_getcjmp (save_jump); |
2038 | ||
303b5b3f RS |
2039 | if (EQ (tem0, Qt) |
2040 | && ! CONSP (Vunread_command_events)) | |
7d6de002 | 2041 | { |
7d6de002 | 2042 | Fdo_auto_save (Qnil, Qnil); |
7d6de002 RS |
2043 | |
2044 | /* If we have auto-saved and there is still no input | |
2045 | available, garbage collect if there has been enough | |
2046 | consing going on to make it worthwhile. */ | |
4ec4ed6a | 2047 | if (!detect_input_pending_run_timers (0) |
7d6de002 | 2048 | && consing_since_gc > gc_cons_threshold / 2) |
ef8fd672 | 2049 | Fgarbage_collect (); |
410d4de9 | 2050 | |
ef8fd672 | 2051 | redisplay (); |
7d6de002 RS |
2052 | } |
2053 | } | |
2054 | } | |
284f4730 | 2055 | |
303b5b3f RS |
2056 | /* If this has become non-nil here, it has been set by a timer |
2057 | or sentinel or filter. */ | |
2058 | if (CONSP (Vunread_command_events)) | |
2059 | { | |
2060 | c = XCONS (Vunread_command_events)->car; | |
2061 | Vunread_command_events = XCONS (Vunread_command_events)->cdr; | |
2062 | } | |
2063 | ||
410d4de9 RS |
2064 | /* Read something from current KBOARD's side queue, if possible. */ |
2065 | ||
beecf6a1 | 2066 | if (NILP (c)) |
1e12dd87 | 2067 | { |
c5fdd383 | 2068 | if (current_kboard->kbd_queue_has_data) |
beecf6a1 | 2069 | { |
c5fdd383 | 2070 | if (!CONSP (current_kboard->kbd_queue)) |
4524b161 | 2071 | abort (); |
c5fdd383 KH |
2072 | c = XCONS (current_kboard->kbd_queue)->car; |
2073 | current_kboard->kbd_queue | |
2074 | = XCONS (current_kboard->kbd_queue)->cdr; | |
2075 | if (NILP (current_kboard->kbd_queue)) | |
2076 | current_kboard->kbd_queue_has_data = 0; | |
d9d4c147 | 2077 | input_pending = readable_events (0); |
4c52b668 KH |
2078 | if (EVENT_HAS_PARAMETERS (c) |
2079 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qswitch_frame)) | |
2080 | internal_last_event_frame = XCONS (XCONS (c)->cdr)->car; | |
2081 | Vlast_event_frame = internal_last_event_frame; | |
beecf6a1 | 2082 | } |
1e8bd3da RS |
2083 | } |
2084 | ||
c5fdd383 | 2085 | #ifdef MULTI_KBOARD |
1e8bd3da RS |
2086 | /* If current_kboard's side queue is empty check the other kboards. |
2087 | If one of them has data that we have not yet seen here, | |
2088 | switch to it and process the data waiting for it. | |
2089 | ||
2090 | Note: if the events queued up for another kboard | |
2091 | have already been seen here, and therefore are not a complete command, | |
2092 | the kbd_queue_has_data field is 0, so we skip that kboard here. | |
2093 | That's to avoid an infinite loop switching between kboards here. */ | |
2094 | if (NILP (c) && !single_kboard) | |
2095 | { | |
2096 | KBOARD *kb; | |
2097 | for (kb = all_kboards; kb; kb = kb->next_kboard) | |
2098 | if (kb->kbd_queue_has_data) | |
2099 | { | |
2100 | current_kboard = kb; | |
ef6661f7 RS |
2101 | /* This is going to exit from read_char |
2102 | so we had better get rid of this frame's stuff. */ | |
2103 | UNGCPRO; | |
1e8bd3da RS |
2104 | longjmp (wrong_kboard_jmpbuf, 1); |
2105 | } | |
2106 | } | |
df0f2ba1 KH |
2107 | #endif |
2108 | ||
410d4de9 RS |
2109 | wrong_kboard: |
2110 | ||
2111 | stop_polling (); | |
2112 | ||
1e8bd3da RS |
2113 | /* Finally, we read from the main queue, |
2114 | and if that gives us something we can't use yet, we put it on the | |
2115 | appropriate side queue and try again. */ | |
410d4de9 | 2116 | |
1e8bd3da RS |
2117 | if (NILP (c)) |
2118 | { | |
2119 | KBOARD *kb; | |
2120 | ||
1e8bd3da | 2121 | /* Actually read a character, waiting if necessary. */ |
410d4de9 RS |
2122 | save_getcjmp (save_jump); |
2123 | restore_getcjmp (local_getcjmp); | |
83d68044 | 2124 | c = kbd_buffer_get_event (&kb, used_mouse_menu); |
410d4de9 RS |
2125 | restore_getcjmp (save_jump); |
2126 | ||
c5fdd383 | 2127 | #ifdef MULTI_KBOARD |
410d4de9 | 2128 | if (! NILP (c) && (kb != current_kboard)) |
1e8bd3da RS |
2129 | { |
2130 | Lisp_Object *tailp = &kb->kbd_queue; | |
2131 | while (CONSP (*tailp)) | |
2132 | tailp = &XCONS (*tailp)->cdr; | |
2133 | if (!NILP (*tailp)) | |
2134 | abort (); | |
2135 | *tailp = Fcons (c, Qnil); | |
2136 | kb->kbd_queue_has_data = 1; | |
46b84797 | 2137 | c = Qnil; |
1e8bd3da RS |
2138 | if (single_kboard) |
2139 | goto wrong_kboard; | |
2140 | current_kboard = kb; | |
ef6661f7 RS |
2141 | /* This is going to exit from read_char |
2142 | so we had better get rid of this frame's stuff. */ | |
2143 | UNGCPRO; | |
1e8bd3da | 2144 | longjmp (wrong_kboard_jmpbuf, 1); |
df0f2ba1 | 2145 | } |
1e8bd3da | 2146 | #endif |
beecf6a1 | 2147 | } |
1e8bd3da | 2148 | |
284f4730 | 2149 | /* Terminate Emacs in batch mode if at eof. */ |
8c18cbfb | 2150 | if (noninteractive && INTEGERP (c) && XINT (c) < 0) |
284f4730 JB |
2151 | Fkill_emacs (make_number (1)); |
2152 | ||
8c18cbfb | 2153 | if (INTEGERP (c)) |
80645119 JB |
2154 | { |
2155 | /* Add in any extra modifiers, where appropriate. */ | |
2156 | if ((extra_keyboard_modifiers & CHAR_CTL) | |
2157 | || ((extra_keyboard_modifiers & 0177) < ' ' | |
2158 | && (extra_keyboard_modifiers & 0177) != 0)) | |
faf5e407 | 2159 | XSETINT (c, make_ctrl_char (XINT (c))); |
80645119 JB |
2160 | |
2161 | /* Transfer any other modifier bits directly from | |
2162 | extra_keyboard_modifiers to c. Ignore the actual character code | |
2163 | in the low 16 bits of extra_keyboard_modifiers. */ | |
b8d9050d | 2164 | XSETINT (c, XINT (c) | (extra_keyboard_modifiers & ~0xff7f & ~CHAR_CTL)); |
80645119 | 2165 | } |
9fa4395d | 2166 | |
284f4730 JB |
2167 | non_reread: |
2168 | ||
2fb9049e | 2169 | timer_stop_idle (); |
d9d4c147 | 2170 | |
284f4730 JB |
2171 | start_polling (); |
2172 | ||
410d4de9 RS |
2173 | if (NILP (c)) |
2174 | { | |
2175 | if (commandflag >= 0 | |
4ec4ed6a | 2176 | && !input_pending && !detect_input_pending_run_timers (0)) |
410d4de9 RS |
2177 | redisplay (); |
2178 | ||
2179 | goto wrong_kboard; | |
2180 | } | |
2181 | ||
2182 | non_reread_1: | |
2183 | ||
dfd11da7 | 2184 | /* Buffer switch events are only for internal wakeups |
7c3bc944 RS |
2185 | so don't show them to the user. |
2186 | Also, don't record a key if we already did. */ | |
2187 | if (BUFFERP (c) || key_already_recorded) | |
2188 | RETURN_UNGCPRO (c); | |
a1341f75 | 2189 | |
7f07d5ca RS |
2190 | /* Process special events within read_char |
2191 | and loop around to read another event. */ | |
017c7cb6 RS |
2192 | save = Vquit_flag; |
2193 | Vquit_flag = Qnil; | |
7f07d5ca RS |
2194 | tem = get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map, 0, 0), |
2195 | c, 0, 0), 1); | |
017c7cb6 | 2196 | Vquit_flag = save; |
7f07d5ca RS |
2197 | |
2198 | if (!NILP (tem)) | |
2199 | { | |
ba8dfba8 RS |
2200 | int was_locked = single_kboard; |
2201 | ||
7f07d5ca | 2202 | last_input_char = c; |
158f7532 | 2203 | Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt); |
ba8dfba8 RS |
2204 | |
2205 | /* Resume allowing input from any kboard, if that was true before. */ | |
2206 | if (!was_locked) | |
2207 | any_kboard_state (); | |
2208 | ||
7f07d5ca RS |
2209 | goto retry; |
2210 | } | |
2211 | ||
dfd11da7 | 2212 | /* Wipe the echo area. */ |
cdb9d665 RS |
2213 | if (echo_area_glyphs) |
2214 | safe_run_hooks (Qecho_area_clear_hook); | |
dfd11da7 | 2215 | echo_area_glyphs = 0; |
284f4730 JB |
2216 | |
2217 | /* Handle things that only apply to characters. */ | |
8c18cbfb | 2218 | if (INTEGERP (c)) |
284f4730 JB |
2219 | { |
2220 | /* If kbd_buffer_get_event gave us an EOF, return that. */ | |
86e5706b | 2221 | if (XINT (c) == -1) |
7c3bc944 | 2222 | RETURN_UNGCPRO (c); |
284f4730 | 2223 | |
301738ed RS |
2224 | if ((STRINGP (Vkeyboard_translate_table) |
2225 | && XSTRING (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) | |
2226 | || (VECTORP (Vkeyboard_translate_table) | |
2227 | && XVECTOR (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) | |
2228 | || (CHAR_TABLE_P (Vkeyboard_translate_table) | |
2229 | && CHAR_TABLE_ORDINARY_SLOTS > (unsigned) XFASTINT (c))) | |
f9414d62 RS |
2230 | { |
2231 | Lisp_Object d; | |
2232 | d = Faref (Vkeyboard_translate_table, c); | |
2233 | /* nil in keyboard-translate-table means no translation. */ | |
2234 | if (!NILP (d)) | |
2235 | c = d; | |
2236 | } | |
284f4730 JB |
2237 | } |
2238 | ||
e4fe371d RS |
2239 | /* If this event is a mouse click in the menu bar, |
2240 | return just menu-bar for now. Modify the mouse click event | |
2241 | so we won't do this twice, then queue it up. */ | |
2242 | if (EVENT_HAS_PARAMETERS (c) | |
2243 | && CONSP (XCONS (c)->cdr) | |
2244 | && CONSP (EVENT_START (c)) | |
2245 | && CONSP (XCONS (EVENT_START (c))->cdr)) | |
284f4730 | 2246 | { |
e4fe371d | 2247 | Lisp_Object posn; |
284f4730 | 2248 | |
e4fe371d RS |
2249 | posn = POSN_BUFFER_POSN (EVENT_START (c)); |
2250 | /* Handle menu-bar events: | |
2251 | insert the dummy prefix event `menu-bar'. */ | |
2252 | if (EQ (posn, Qmenu_bar)) | |
2253 | { | |
2254 | /* Change menu-bar to (menu-bar) as the event "position". */ | |
2255 | POSN_BUFFER_POSN (EVENT_START (c)) = Fcons (posn, Qnil); | |
284f4730 | 2256 | |
e4fe371d RS |
2257 | also_record = c; |
2258 | Vunread_command_events = Fcons (c, Vunread_command_events); | |
2259 | c = posn; | |
284f4730 | 2260 | } |
284f4730 JB |
2261 | } |
2262 | ||
e4fe371d RS |
2263 | record_char (c); |
2264 | if (! NILP (also_record)) | |
2265 | record_char (also_record); | |
51172b6d | 2266 | |
284f4730 JB |
2267 | from_macro: |
2268 | reread_first: | |
7c3bc944 | 2269 | |
71918b75 RS |
2270 | before_command_key_count = this_command_key_count; |
2271 | before_command_echo_length = echo_length (); | |
284f4730 | 2272 | |
b8556aee | 2273 | /* Don't echo mouse motion events. */ |
8ea231fc RS |
2274 | if (echo_keystrokes |
2275 | && ! (EVENT_HAS_PARAMETERS (c) | |
2276 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_movement))) | |
e4fe371d RS |
2277 | { |
2278 | echo_char (c); | |
2279 | if (! NILP (also_record)) | |
2280 | echo_char (also_record); | |
1fc93d49 RS |
2281 | /* Once we reread a character, echoing can happen |
2282 | the next time we pause to read a new one. */ | |
0c04a67e | 2283 | ok_to_echo_at_next_pause = echo_area_glyphs; |
e4fe371d | 2284 | } |
b8556aee | 2285 | |
db8c1663 | 2286 | /* Record this character as part of the current key. */ |
b8556aee | 2287 | add_command_key (c); |
e4fe371d RS |
2288 | if (! NILP (also_record)) |
2289 | add_command_key (also_record); | |
284f4730 JB |
2290 | |
2291 | /* Re-reading in the middle of a command */ | |
2292 | reread: | |
2293 | last_input_char = c; | |
c43b1734 | 2294 | num_input_events++; |
284f4730 JB |
2295 | |
2296 | /* Process the help character specially if enabled */ | |
ecb7cb34 | 2297 | if (!NILP (Vhelp_form) && help_char_p (c)) |
284f4730 JB |
2298 | { |
2299 | Lisp_Object tem0; | |
2300 | count = specpdl_ptr - specpdl; | |
2301 | ||
2302 | record_unwind_protect (Fset_window_configuration, | |
2303 | Fcurrent_window_configuration (Qnil)); | |
2304 | ||
2305 | tem0 = Feval (Vhelp_form); | |
8c18cbfb | 2306 | if (STRINGP (tem0)) |
284f4730 JB |
2307 | internal_with_output_to_temp_buffer ("*Help*", print_help, tem0); |
2308 | ||
2309 | cancel_echoing (); | |
3cb81011 KH |
2310 | do |
2311 | c = read_char (0, 0, 0, Qnil, 0); | |
8c18cbfb | 2312 | while (BUFFERP (c)); |
ff11dfa1 | 2313 | /* Remove the help from the frame */ |
284f4730 | 2314 | unbind_to (count, Qnil); |
410d4de9 | 2315 | |
284f4730 JB |
2316 | redisplay (); |
2317 | if (EQ (c, make_number (040))) | |
2318 | { | |
2319 | cancel_echoing (); | |
3cb81011 KH |
2320 | do |
2321 | c = read_char (0, 0, 0, Qnil, 0); | |
8c18cbfb | 2322 | while (BUFFERP (c)); |
284f4730 JB |
2323 | } |
2324 | } | |
2325 | ||
7c3bc944 | 2326 | RETURN_UNGCPRO (c); |
284f4730 JB |
2327 | } |
2328 | ||
8eb4d8ef RS |
2329 | /* Record a key that came from a mouse menu. |
2330 | Record it for echoing, for this-command-keys, and so on. */ | |
2331 | ||
2332 | static void | |
2333 | record_menu_key (c) | |
2334 | Lisp_Object c; | |
2335 | { | |
2336 | /* Wipe the echo area. */ | |
2337 | echo_area_glyphs = 0; | |
2338 | ||
2339 | record_char (c); | |
2340 | ||
2341 | before_command_key_count = this_command_key_count; | |
2342 | before_command_echo_length = echo_length (); | |
2343 | ||
2344 | /* Don't echo mouse motion events. */ | |
2345 | if (echo_keystrokes) | |
2346 | { | |
2347 | echo_char (c); | |
2348 | ||
2349 | /* Once we reread a character, echoing can happen | |
2350 | the next time we pause to read a new one. */ | |
2351 | ok_to_echo_at_next_pause = 0; | |
2352 | } | |
2353 | ||
2354 | /* Record this character as part of the current key. */ | |
2355 | add_command_key (c); | |
2356 | ||
2357 | /* Re-reading in the middle of a command */ | |
2358 | last_input_char = c; | |
c43b1734 | 2359 | num_input_events++; |
8eb4d8ef RS |
2360 | } |
2361 | ||
ecb7cb34 KH |
2362 | /* Return 1 if should recognize C as "the help character". */ |
2363 | ||
2364 | int | |
2365 | help_char_p (c) | |
2366 | Lisp_Object c; | |
2367 | { | |
2368 | Lisp_Object tail; | |
2369 | ||
2370 | if (EQ (c, Vhelp_char)) | |
2371 | return 1; | |
2372 | for (tail = Vhelp_event_list; CONSP (tail); tail = XCONS (tail)->cdr) | |
2373 | if (EQ (c, XCONS (tail)->car)) | |
2374 | return 1; | |
2375 | return 0; | |
2376 | } | |
2377 | ||
e4fe371d RS |
2378 | /* Record the input event C in various ways. */ |
2379 | ||
2380 | static void | |
2381 | record_char (c) | |
2382 | Lisp_Object c; | |
2383 | { | |
2384 | total_keys++; | |
2385 | XVECTOR (recent_keys)->contents[recent_keys_index] = c; | |
2386 | if (++recent_keys_index >= NUM_RECENT_KEYS) | |
2387 | recent_keys_index = 0; | |
2388 | ||
2389 | /* Write c to the dribble file. If c is a lispy event, write | |
2390 | the event's symbol to the dribble file, in <brackets>. Bleaugh. | |
2391 | If you, dear reader, have a better idea, you've got the source. :-) */ | |
2392 | if (dribble) | |
2393 | { | |
2394 | if (INTEGERP (c)) | |
2395 | { | |
2396 | if (XUINT (c) < 0x100) | |
2397 | putc (XINT (c), dribble); | |
2398 | else | |
6de34814 | 2399 | fprintf (dribble, " 0x%x", (int) XUINT (c)); |
e4fe371d RS |
2400 | } |
2401 | else | |
2402 | { | |
2403 | Lisp_Object dribblee; | |
2404 | ||
2405 | /* If it's a structured event, take the event header. */ | |
2406 | dribblee = EVENT_HEAD (c); | |
2407 | ||
2408 | if (SYMBOLP (dribblee)) | |
2409 | { | |
2410 | putc ('<', dribble); | |
2411 | fwrite (XSYMBOL (dribblee)->name->data, sizeof (char), | |
fc932ac6 | 2412 | STRING_BYTES (XSYMBOL (dribblee)->name), |
e4fe371d RS |
2413 | dribble); |
2414 | putc ('>', dribble); | |
2415 | } | |
2416 | } | |
2417 | ||
2418 | fflush (dribble); | |
2419 | } | |
2420 | ||
2421 | store_kbd_macro_char (c); | |
2422 | ||
c43b1734 | 2423 | num_nonmacro_input_events++; |
e4fe371d RS |
2424 | } |
2425 | ||
284f4730 JB |
2426 | Lisp_Object |
2427 | print_help (object) | |
2428 | Lisp_Object object; | |
2429 | { | |
622de3e9 | 2430 | struct buffer *old = current_buffer; |
284f4730 | 2431 | Fprinc (object, Qnil); |
622de3e9 KH |
2432 | set_buffer_internal (XBUFFER (Vstandard_output)); |
2433 | call0 (intern ("help-mode")); | |
2434 | set_buffer_internal (old); | |
284f4730 JB |
2435 | return Qnil; |
2436 | } | |
2437 | ||
2438 | /* Copy out or in the info on where C-g should throw to. | |
2439 | This is used when running Lisp code from within get_char, | |
2440 | in case get_char is called recursively. | |
2441 | See read_process_output. */ | |
2442 | ||
dfcf069d | 2443 | static void |
284f4730 JB |
2444 | save_getcjmp (temp) |
2445 | jmp_buf temp; | |
2446 | { | |
2447 | bcopy (getcjmp, temp, sizeof getcjmp); | |
2448 | } | |
2449 | ||
dfcf069d | 2450 | static void |
284f4730 JB |
2451 | restore_getcjmp (temp) |
2452 | jmp_buf temp; | |
2453 | { | |
2454 | bcopy (temp, getcjmp, sizeof getcjmp); | |
2455 | } | |
284f4730 | 2456 | \f |
2eb6bfbe RM |
2457 | #ifdef HAVE_MOUSE |
2458 | ||
284f4730 JB |
2459 | /* Restore mouse tracking enablement. See Ftrack_mouse for the only use |
2460 | of this function. */ | |
a9d77f1f | 2461 | |
284f4730 JB |
2462 | static Lisp_Object |
2463 | tracking_off (old_value) | |
2464 | Lisp_Object old_value; | |
2465 | { | |
71edead1 RS |
2466 | do_mouse_tracking = old_value; |
2467 | if (NILP (old_value)) | |
284f4730 | 2468 | { |
284f4730 JB |
2469 | /* Redisplay may have been preempted because there was input |
2470 | available, and it assumes it will be called again after the | |
2471 | input has been processed. If the only input available was | |
2472 | the sort that we have just disabled, then we need to call | |
2473 | redisplay. */ | |
d9d4c147 | 2474 | if (!readable_events (1)) |
284f4730 JB |
2475 | { |
2476 | redisplay_preserve_echo_area (); | |
d9d4c147 | 2477 | get_input_pending (&input_pending, 1); |
284f4730 JB |
2478 | } |
2479 | } | |
2480 | } | |
2481 | ||
2482 | DEFUN ("track-mouse", Ftrack_mouse, Strack_mouse, 0, UNEVALLED, 0, | |
4bb994d1 JB |
2483 | "Evaluate BODY with mouse movement events enabled.\n\ |
2484 | Within a `track-mouse' form, mouse motion generates input events that\n\ | |
2485 | you can read with `read-event'.\n\ | |
2486 | Normally, mouse motion is ignored.") | |
284f4730 JB |
2487 | (args) |
2488 | Lisp_Object args; | |
2489 | { | |
2490 | int count = specpdl_ptr - specpdl; | |
2491 | Lisp_Object val; | |
2492 | ||
a9d77f1f | 2493 | record_unwind_protect (tracking_off, do_mouse_tracking); |
284f4730 | 2494 | |
f3253854 | 2495 | do_mouse_tracking = Qt; |
df0f2ba1 | 2496 | |
284f4730 JB |
2497 | val = Fprogn (args); |
2498 | return unbind_to (count, val); | |
2499 | } | |
2eb6bfbe | 2500 | |
f3253854 KH |
2501 | /* If mouse has moved on some frame, return one of those frames. |
2502 | Return 0 otherwise. */ | |
2503 | ||
2504 | static FRAME_PTR | |
2505 | some_mouse_moved () | |
2506 | { | |
2507 | Lisp_Object tail, frame; | |
2508 | ||
2509 | FOR_EACH_FRAME (tail, frame) | |
2510 | { | |
2511 | if (XFRAME (frame)->mouse_moved) | |
2512 | return XFRAME (frame); | |
2513 | } | |
2514 | ||
2515 | return 0; | |
2516 | } | |
2517 | ||
2eb6bfbe | 2518 | #endif /* HAVE_MOUSE */ |
a612e298 RS |
2519 | \f |
2520 | /* Low level keyboard/mouse input. | |
2521 | kbd_buffer_store_event places events in kbd_buffer, and | |
0646c0dd | 2522 | kbd_buffer_get_event retrieves them. */ |
a612e298 RS |
2523 | |
2524 | /* Return true iff there are any events in the queue that read-char | |
2525 | would return. If this returns false, a read-char would block. */ | |
2526 | static int | |
d9d4c147 KH |
2527 | readable_events (do_timers_now) |
2528 | int do_timers_now; | |
a612e298 | 2529 | { |
4ec4ed6a RS |
2530 | if (do_timers_now) |
2531 | timer_check (do_timers_now); | |
2532 | ||
beecf6a1 KH |
2533 | if (kbd_fetch_ptr != kbd_store_ptr) |
2534 | return 1; | |
2535 | #ifdef HAVE_MOUSE | |
f3253854 | 2536 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
beecf6a1 KH |
2537 | return 1; |
2538 | #endif | |
1e8bd3da | 2539 | if (single_kboard) |
4c52b668 | 2540 | { |
c5fdd383 | 2541 | if (current_kboard->kbd_queue_has_data) |
4c52b668 KH |
2542 | return 1; |
2543 | } | |
2544 | else | |
2545 | { | |
c5fdd383 KH |
2546 | KBOARD *kb; |
2547 | for (kb = all_kboards; kb; kb = kb->next_kboard) | |
2548 | if (kb->kbd_queue_has_data) | |
4c52b668 KH |
2549 | return 1; |
2550 | } | |
beecf6a1 | 2551 | return 0; |
a612e298 RS |
2552 | } |
2553 | ||
2554 | /* Set this for debugging, to have a way to get out */ | |
2555 | int stop_character; | |
284f4730 | 2556 | |
c5fdd383 KH |
2557 | #ifdef MULTI_KBOARD |
2558 | static KBOARD * | |
2559 | event_to_kboard (event) | |
5798cf15 KH |
2560 | struct input_event *event; |
2561 | { | |
2562 | Lisp_Object frame; | |
2563 | frame = event->frame_or_window; | |
2564 | if (CONSP (frame)) | |
2565 | frame = XCONS (frame)->car; | |
2566 | else if (WINDOWP (frame)) | |
2567 | frame = WINDOW_FRAME (XWINDOW (frame)); | |
2568 | ||
2569 | /* There are still some events that don't set this field. | |
f5b56972 KH |
2570 | For now, just ignore the problem. |
2571 | Also ignore dead frames here. */ | |
2572 | if (!FRAMEP (frame) || !FRAME_LIVE_P (XFRAME (frame))) | |
5798cf15 KH |
2573 | return 0; |
2574 | else | |
c5fdd383 | 2575 | return FRAME_KBOARD (XFRAME (frame)); |
5798cf15 KH |
2576 | } |
2577 | #endif | |
2578 | ||
284f4730 JB |
2579 | /* Store an event obtained at interrupt level into kbd_buffer, fifo */ |
2580 | ||
2581 | void | |
2582 | kbd_buffer_store_event (event) | |
2583 | register struct input_event *event; | |
2584 | { | |
2585 | if (event->kind == no_event) | |
2586 | abort (); | |
2587 | ||
2588 | if (event->kind == ascii_keystroke) | |
2589 | { | |
e9bf89a0 | 2590 | register int c = event->code & 0377; |
284f4730 | 2591 | |
faf5e407 JB |
2592 | if (event->modifiers & ctrl_modifier) |
2593 | c = make_ctrl_char (c); | |
2594 | ||
9fd7d808 RS |
2595 | c |= (event->modifiers |
2596 | & (meta_modifier | alt_modifier | |
2597 | | hyper_modifier | super_modifier)); | |
2598 | ||
86e5706b | 2599 | if (c == quit_char) |
284f4730 | 2600 | { |
3e51c7b7 | 2601 | extern SIGTYPE interrupt_signal (); |
c5fdd383 KH |
2602 | #ifdef MULTI_KBOARD |
2603 | KBOARD *kb; | |
5798cf15 KH |
2604 | struct input_event *sp; |
2605 | ||
1e8bd3da | 2606 | if (single_kboard |
c5fdd383 KH |
2607 | && (kb = FRAME_KBOARD (XFRAME (event->frame_or_window)), |
2608 | kb != current_kboard)) | |
5798cf15 | 2609 | { |
c5fdd383 | 2610 | kb->kbd_queue |
5798cf15 KH |
2611 | = Fcons (make_lispy_switch_frame (event->frame_or_window), |
2612 | Fcons (make_number (c), Qnil)); | |
c5fdd383 | 2613 | kb->kbd_queue_has_data = 1; |
5798cf15 KH |
2614 | for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++) |
2615 | { | |
2616 | if (sp == kbd_buffer + KBD_BUFFER_SIZE) | |
2617 | sp = kbd_buffer; | |
2618 | ||
c5fdd383 | 2619 | if (event_to_kboard (sp) == kb) |
5798cf15 KH |
2620 | { |
2621 | sp->kind = no_event; | |
2622 | sp->frame_or_window = Qnil; | |
2623 | } | |
2624 | } | |
2625 | return; | |
2626 | } | |
2627 | #endif | |
3e51c7b7 | 2628 | |
284f4730 | 2629 | /* If this results in a quit_char being returned to Emacs as |
3c370943 | 2630 | input, set Vlast_event_frame properly. If this doesn't |
284f4730 | 2631 | get returned to Emacs as an event, the next event read |
ff11dfa1 | 2632 | will set Vlast_event_frame again, so this is safe to do. */ |
4bb994d1 | 2633 | { |
9b8eb840 | 2634 | Lisp_Object focus; |
4bb994d1 | 2635 | |
9b8eb840 | 2636 | focus = FRAME_FOCUS_FRAME (XFRAME (event->frame_or_window)); |
4bb994d1 | 2637 | if (NILP (focus)) |
beecf6a1 | 2638 | focus = event->frame_or_window; |
4c52b668 KH |
2639 | internal_last_event_frame = focus; |
2640 | Vlast_event_frame = focus; | |
4bb994d1 | 2641 | } |
3e51c7b7 | 2642 | |
ffd56f97 | 2643 | last_event_timestamp = event->timestamp; |
284f4730 JB |
2644 | interrupt_signal (); |
2645 | return; | |
2646 | } | |
2647 | ||
2648 | if (c && c == stop_character) | |
2649 | { | |
2650 | sys_suspend (); | |
2651 | return; | |
2652 | } | |
284f4730 | 2653 | } |
3fe8e9a2 RS |
2654 | /* Don't insert two buffer_switch_event's in a row. |
2655 | Just ignore the second one. */ | |
2656 | else if (event->kind == buffer_switch_event | |
2657 | && kbd_fetch_ptr != kbd_store_ptr | |
2658 | && kbd_store_ptr->kind == buffer_switch_event) | |
2659 | return; | |
284f4730 | 2660 | |
beecf6a1 KH |
2661 | if (kbd_store_ptr - kbd_buffer == KBD_BUFFER_SIZE) |
2662 | kbd_store_ptr = kbd_buffer; | |
284f4730 JB |
2663 | |
2664 | /* Don't let the very last slot in the buffer become full, | |
2665 | since that would make the two pointers equal, | |
2666 | and that is indistinguishable from an empty buffer. | |
2667 | Discard the event if it would fill the last slot. */ | |
beecf6a1 | 2668 | if (kbd_fetch_ptr - 1 != kbd_store_ptr) |
284f4730 | 2669 | { |
beecf6a1 | 2670 | volatile struct input_event *sp = kbd_store_ptr; |
612b78ef | 2671 | sp->kind = event->kind; |
27203ead RS |
2672 | if (event->kind == selection_request_event) |
2673 | { | |
2674 | /* We must not use the ordinary copying code for this case, | |
2675 | since `part' is an enum and copying it might not copy enough | |
2676 | in this case. */ | |
612b78ef | 2677 | bcopy (event, (char *) sp, sizeof (*event)); |
27203ead RS |
2678 | } |
2679 | else | |
2680 | { | |
612b78ef KH |
2681 | sp->code = event->code; |
2682 | sp->part = event->part; | |
2683 | sp->frame_or_window = event->frame_or_window; | |
2684 | sp->modifiers = event->modifiers; | |
2685 | sp->x = event->x; | |
2686 | sp->y = event->y; | |
2687 | sp->timestamp = event->timestamp; | |
27203ead | 2688 | } |
beecf6a1 KH |
2689 | (XVECTOR (kbd_buffer_frame_or_window)->contents[kbd_store_ptr |
2690 | - kbd_buffer] | |
7b4aedb9 | 2691 | = event->frame_or_window); |
284f4730 | 2692 | |
beecf6a1 | 2693 | kbd_store_ptr++; |
284f4730 JB |
2694 | } |
2695 | } | |
a612e298 | 2696 | \f |
07de30b9 GV |
2697 | /* Discard any mouse events in the event buffer by setting them to |
2698 | no_event. */ | |
2699 | void | |
2700 | discard_mouse_events () | |
2701 | { | |
2702 | struct input_event *sp; | |
2703 | for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++) | |
2704 | { | |
2705 | if (sp == kbd_buffer + KBD_BUFFER_SIZE) | |
2706 | sp = kbd_buffer; | |
2707 | ||
2708 | if (sp->kind == mouse_click | |
2709 | #ifdef WINDOWSNT | |
2710 | || sp->kind == w32_scroll_bar_click | |
2711 | #endif | |
2712 | || sp->kind == scroll_bar_click) | |
2713 | { | |
2714 | sp->kind = no_event; | |
2715 | } | |
2716 | } | |
2717 | } | |
2718 | \f | |
a612e298 RS |
2719 | /* Read one event from the event buffer, waiting if necessary. |
2720 | The value is a Lisp object representing the event. | |
2721 | The value is nil for an event that should be ignored, | |
2722 | or that was handled here. | |
2723 | We always read and discard one event. */ | |
284f4730 JB |
2724 | |
2725 | static Lisp_Object | |
83d68044 | 2726 | kbd_buffer_get_event (kbp, used_mouse_menu) |
410d4de9 | 2727 | KBOARD **kbp; |
83d68044 | 2728 | int *used_mouse_menu; |
284f4730 JB |
2729 | { |
2730 | register int c; | |
2731 | Lisp_Object obj; | |
c04cbc3b | 2732 | EMACS_TIME next_timer_delay; |
284f4730 JB |
2733 | |
2734 | if (noninteractive) | |
2735 | { | |
2736 | c = getchar (); | |
18cd2eeb | 2737 | XSETINT (obj, c); |
f5b56972 | 2738 | *kbp = current_kboard; |
284f4730 JB |
2739 | return obj; |
2740 | } | |
2741 | ||
2742 | /* Wait until there is input available. */ | |
2743 | for (;;) | |
2744 | { | |
beecf6a1 KH |
2745 | if (kbd_fetch_ptr != kbd_store_ptr) |
2746 | break; | |
2747 | #ifdef HAVE_MOUSE | |
f3253854 | 2748 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
284f4730 | 2749 | break; |
beecf6a1 | 2750 | #endif |
284f4730 JB |
2751 | |
2752 | /* If the quit flag is set, then read_char will return | |
2753 | quit_char, so that counts as "available input." */ | |
2754 | if (!NILP (Vquit_flag)) | |
2755 | quit_throw_to_read_char (); | |
2756 | ||
2757 | /* One way or another, wait until input is available; then, if | |
2758 | interrupt handlers have not read it, read it now. */ | |
2759 | ||
2760 | #ifdef OLDVMS | |
2761 | wait_for_kbd_input (); | |
2762 | #else | |
2763 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
2764 | #ifdef SIGIO | |
2765 | gobble_input (0); | |
2766 | #endif /* SIGIO */ | |
beecf6a1 KH |
2767 | if (kbd_fetch_ptr != kbd_store_ptr) |
2768 | break; | |
2769 | #ifdef HAVE_MOUSE | |
f3253854 | 2770 | if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
beecf6a1 KH |
2771 | break; |
2772 | #endif | |
2773 | { | |
2774 | Lisp_Object minus_one; | |
f76475ad | 2775 | |
beecf6a1 | 2776 | XSETINT (minus_one, -1); |
d9d4c147 | 2777 | wait_reading_process_input (0, 0, minus_one, 1); |
284f4730 | 2778 | |
beecf6a1 KH |
2779 | if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr) |
2780 | /* Pass 1 for EXPECT since we just waited to have input. */ | |
2781 | read_avail_input (1); | |
2782 | } | |
284f4730 JB |
2783 | #endif /* not VMS */ |
2784 | } | |
2785 | ||
303b5b3f RS |
2786 | if (CONSP (Vunread_command_events)) |
2787 | { | |
2788 | Lisp_Object first; | |
2789 | first = XCONS (Vunread_command_events)->car; | |
2790 | Vunread_command_events = XCONS (Vunread_command_events)->cdr; | |
2791 | *kbp = current_kboard; | |
2792 | return first; | |
2793 | } | |
2794 | ||
284f4730 JB |
2795 | /* At this point, we know that there is a readable event available |
2796 | somewhere. If the event queue is empty, then there must be a | |
2797 | mouse movement enabled and available. */ | |
beecf6a1 | 2798 | if (kbd_fetch_ptr != kbd_store_ptr) |
284f4730 | 2799 | { |
cd21b839 | 2800 | struct input_event *event; |
3e51c7b7 | 2801 | |
beecf6a1 KH |
2802 | event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE) |
2803 | ? kbd_fetch_ptr | |
2804 | : kbd_buffer); | |
3e51c7b7 | 2805 | |
cd21b839 | 2806 | last_event_timestamp = event->timestamp; |
cd21b839 | 2807 | |
c5fdd383 KH |
2808 | #ifdef MULTI_KBOARD |
2809 | *kbp = event_to_kboard (event); | |
2810 | if (*kbp == 0) | |
2811 | *kbp = current_kboard; /* Better than returning null ptr? */ | |
5798cf15 | 2812 | #else |
c5fdd383 | 2813 | *kbp = &the_only_kboard; |
5798cf15 | 2814 | #endif |
beecf6a1 | 2815 | |
4bb994d1 JB |
2816 | obj = Qnil; |
2817 | ||
48e416d4 | 2818 | /* These two kinds of events get special handling |
a612e298 RS |
2819 | and don't actually appear to the command loop. |
2820 | We return nil for them. */ | |
48e416d4 RS |
2821 | if (event->kind == selection_request_event) |
2822 | { | |
598a9fa7 | 2823 | #ifdef HAVE_X11 |
1e8bd3da RS |
2824 | struct input_event copy; |
2825 | ||
4581e928 RS |
2826 | /* Remove it from the buffer before processing it, |
2827 | since otherwise swallow_events will see it | |
2828 | and process it again. */ | |
1e8bd3da | 2829 | copy = *event; |
beecf6a1 | 2830 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 2831 | input_pending = readable_events (0); |
4581e928 | 2832 | x_handle_selection_request (©); |
598a9fa7 JB |
2833 | #else |
2834 | /* We're getting selection request events, but we don't have | |
2835 | a window system. */ | |
2836 | abort (); | |
2837 | #endif | |
48e416d4 RS |
2838 | } |
2839 | ||
1e12dd87 | 2840 | else if (event->kind == selection_clear_event) |
48e416d4 | 2841 | { |
598a9fa7 | 2842 | #ifdef HAVE_X11 |
e0301c07 RS |
2843 | struct input_event copy; |
2844 | ||
2845 | /* Remove it from the buffer before processing it. */ | |
2846 | copy = *event; | |
beecf6a1 | 2847 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 2848 | input_pending = readable_events (0); |
90c2bb0c | 2849 | x_handle_selection_clear (©); |
598a9fa7 JB |
2850 | #else |
2851 | /* We're getting selection request events, but we don't have | |
2852 | a window system. */ | |
2853 | abort (); | |
2854 | #endif | |
48e416d4 | 2855 | } |
e98a93eb | 2856 | #if defined (HAVE_X11) || defined (HAVE_NTGUI) |
990acea3 RS |
2857 | else if (event->kind == delete_window_event) |
2858 | { | |
bbdc2092 RS |
2859 | /* Make an event (delete-frame (FRAME)). */ |
2860 | obj = Fcons (event->frame_or_window, Qnil); | |
af17bd2b | 2861 | obj = Fcons (Qdelete_frame, Fcons (obj, Qnil)); |
beecf6a1 | 2862 | kbd_fetch_ptr = event + 1; |
af17bd2b KH |
2863 | } |
2864 | else if (event->kind == iconify_event) | |
2865 | { | |
2866 | /* Make an event (iconify-frame (FRAME)). */ | |
2867 | obj = Fcons (event->frame_or_window, Qnil); | |
2868 | obj = Fcons (Qiconify_frame, Fcons (obj, Qnil)); | |
beecf6a1 | 2869 | kbd_fetch_ptr = event + 1; |
af17bd2b KH |
2870 | } |
2871 | else if (event->kind == deiconify_event) | |
2872 | { | |
2873 | /* Make an event (make-frame-visible (FRAME)). */ | |
2874 | obj = Fcons (event->frame_or_window, Qnil); | |
2875 | obj = Fcons (Qmake_frame_visible, Fcons (obj, Qnil)); | |
beecf6a1 | 2876 | kbd_fetch_ptr = event + 1; |
990acea3 RS |
2877 | } |
2878 | #endif | |
a8015ab5 KH |
2879 | else if (event->kind == buffer_switch_event) |
2880 | { | |
2881 | /* The value doesn't matter here; only the type is tested. */ | |
18cd2eeb | 2882 | XSETBUFFER (obj, current_buffer); |
beecf6a1 | 2883 | kbd_fetch_ptr = event + 1; |
a8015ab5 | 2884 | } |
07de30b9 | 2885 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
099787c1 RS |
2886 | else if (event->kind == menu_bar_activate_event) |
2887 | { | |
2888 | kbd_fetch_ptr = event + 1; | |
d9d4c147 | 2889 | input_pending = readable_events (0); |
e649d076 RS |
2890 | if (FRAME_LIVE_P (XFRAME (event->frame_or_window))) |
2891 | x_activate_menubar (XFRAME (event->frame_or_window)); | |
099787c1 RS |
2892 | } |
2893 | #endif | |
a612e298 | 2894 | /* Just discard these, by returning nil. |
c5fdd383 | 2895 | With MULTI_KBOARD, these events are used as placeholders |
5798cf15 KH |
2896 | when we need to randomly delete events from the queue. |
2897 | (They shouldn't otherwise be found in the buffer, | |
2898 | but on some machines it appears they do show up | |
c5fdd383 | 2899 | even without MULTI_KBOARD.) */ |
07de30b9 GV |
2900 | /* On Windows NT/9X, no_event is used to delete extraneous |
2901 | mouse events during a popup-menu call. */ | |
a612e298 | 2902 | else if (event->kind == no_event) |
beecf6a1 | 2903 | kbd_fetch_ptr = event + 1; |
48e416d4 | 2904 | |
4bb994d1 JB |
2905 | /* If this event is on a different frame, return a switch-frame this |
2906 | time, and leave the event in the queue for next time. */ | |
1e12dd87 RS |
2907 | else |
2908 | { | |
9b8eb840 | 2909 | Lisp_Object frame; |
1e12dd87 | 2910 | Lisp_Object focus; |
7b4aedb9 | 2911 | |
9b8eb840 | 2912 | frame = event->frame_or_window; |
2470a66f KH |
2913 | if (CONSP (frame)) |
2914 | frame = XCONS (frame)->car; | |
2915 | else if (WINDOWP (frame)) | |
1e12dd87 | 2916 | frame = WINDOW_FRAME (XWINDOW (frame)); |
4bb994d1 | 2917 | |
1e12dd87 RS |
2918 | focus = FRAME_FOCUS_FRAME (XFRAME (frame)); |
2919 | if (! NILP (focus)) | |
2920 | frame = focus; | |
07d2b8de | 2921 | |
4c52b668 | 2922 | if (! EQ (frame, internal_last_event_frame) |
1e12dd87 RS |
2923 | && XFRAME (frame) != selected_frame) |
2924 | obj = make_lispy_switch_frame (frame); | |
4c52b668 | 2925 | internal_last_event_frame = frame; |
4bb994d1 | 2926 | |
1e12dd87 RS |
2927 | /* If we didn't decide to make a switch-frame event, go ahead |
2928 | and build a real event from the queue entry. */ | |
cd21b839 | 2929 | |
1e12dd87 RS |
2930 | if (NILP (obj)) |
2931 | { | |
2932 | obj = make_lispy_event (event); | |
e98a93eb | 2933 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
83d68044 KH |
2934 | /* If this was a menu selection, then set the flag to inhibit |
2935 | writing to last_nonmenu_event. Don't do this if the event | |
2936 | we're returning is (menu-bar), though; that indicates the | |
2937 | beginning of the menu sequence, and we might as well leave | |
2938 | that as the `event with parameters' for this selection. */ | |
2939 | if (event->kind == menu_bar_event | |
2940 | && !(CONSP (obj) && EQ (XCONS (obj)->car, Qmenu_bar)) | |
2941 | && used_mouse_menu) | |
2942 | *used_mouse_menu = 1; | |
2943 | #endif | |
1e12dd87 RS |
2944 | |
2945 | /* Wipe out this event, to catch bugs. */ | |
2946 | event->kind = no_event; | |
beecf6a1 | 2947 | XVECTOR (kbd_buffer_frame_or_window)->contents[event - kbd_buffer] = Qnil; |
1e12dd87 | 2948 | |
beecf6a1 | 2949 | kbd_fetch_ptr = event + 1; |
1e12dd87 | 2950 | } |
4bb994d1 | 2951 | } |
284f4730 | 2952 | } |
2eb6bfbe | 2953 | #ifdef HAVE_MOUSE |
a612e298 | 2954 | /* Try generating a mouse motion event. */ |
f3253854 | 2955 | else if (!NILP (do_mouse_tracking) && some_mouse_moved ()) |
284f4730 | 2956 | { |
f3253854 | 2957 | FRAME_PTR f = some_mouse_moved (); |
7b4aedb9 | 2958 | Lisp_Object bar_window; |
3c370943 | 2959 | enum scroll_bar_part part; |
e5d77022 JB |
2960 | Lisp_Object x, y; |
2961 | unsigned long time; | |
284f4730 | 2962 | |
c5fdd383 | 2963 | *kbp = current_kboard; |
e177ac3a RS |
2964 | /* Note that this uses F to determine which display to look at. |
2965 | If there is no valid info, it does not store anything | |
2966 | so x remains nil. */ | |
2967 | x = Qnil; | |
dd26ab75 | 2968 | (*mouse_position_hook) (&f, 0, &bar_window, &part, &x, &y, &time); |
4bb994d1 JB |
2969 | |
2970 | obj = Qnil; | |
284f4730 | 2971 | |
4bb994d1 JB |
2972 | /* Decide if we should generate a switch-frame event. Don't |
2973 | generate switch-frame events for motion outside of all Emacs | |
2974 | frames. */ | |
e177ac3a | 2975 | if (!NILP (x) && f) |
cd21b839 | 2976 | { |
9b8eb840 | 2977 | Lisp_Object frame; |
4bb994d1 | 2978 | |
9b8eb840 | 2979 | frame = FRAME_FOCUS_FRAME (f); |
4bb994d1 | 2980 | if (NILP (frame)) |
18cd2eeb | 2981 | XSETFRAME (frame, f); |
4bb994d1 | 2982 | |
4c52b668 | 2983 | if (! EQ (frame, internal_last_event_frame) |
80645119 | 2984 | && XFRAME (frame) != selected_frame) |
764cb3f9 | 2985 | obj = make_lispy_switch_frame (frame); |
4c52b668 | 2986 | internal_last_event_frame = frame; |
cd21b839 | 2987 | } |
4bb994d1 | 2988 | |
df0f2ba1 | 2989 | /* If we didn't decide to make a switch-frame event, go ahead and |
4bb994d1 | 2990 | return a mouse-motion event. */ |
e177ac3a | 2991 | if (!NILP (x) && NILP (obj)) |
7b4aedb9 | 2992 | obj = make_lispy_movement (f, bar_window, part, x, y, time); |
6cbff1cb | 2993 | } |
2eb6bfbe | 2994 | #endif /* HAVE_MOUSE */ |
284f4730 JB |
2995 | else |
2996 | /* We were promised by the above while loop that there was | |
2997 | something for us to read! */ | |
2998 | abort (); | |
2999 | ||
d9d4c147 | 3000 | input_pending = readable_events (0); |
284f4730 | 3001 | |
4c52b668 | 3002 | Vlast_event_frame = internal_last_event_frame; |
3c370943 | 3003 | |
284f4730 JB |
3004 | return (obj); |
3005 | } | |
a612e298 RS |
3006 | \f |
3007 | /* Process any events that are not user-visible, | |
3008 | then return, without reading any user-visible events. */ | |
3a3b9632 RS |
3009 | |
3010 | void | |
d9d4c147 KH |
3011 | swallow_events (do_display) |
3012 | int do_display; | |
3a3b9632 | 3013 | { |
87dd9b9b RS |
3014 | int old_timers_run; |
3015 | ||
beecf6a1 | 3016 | while (kbd_fetch_ptr != kbd_store_ptr) |
3a3b9632 RS |
3017 | { |
3018 | struct input_event *event; | |
3019 | ||
beecf6a1 KH |
3020 | event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE) |
3021 | ? kbd_fetch_ptr | |
3022 | : kbd_buffer); | |
3a3b9632 RS |
3023 | |
3024 | last_event_timestamp = event->timestamp; | |
3025 | ||
3026 | /* These two kinds of events get special handling | |
3027 | and don't actually appear to the command loop. */ | |
3028 | if (event->kind == selection_request_event) | |
3029 | { | |
3030 | #ifdef HAVE_X11 | |
4581e928 | 3031 | struct input_event copy; |
e0301c07 RS |
3032 | |
3033 | /* Remove it from the buffer before processing it, | |
3034 | since otherwise swallow_events called recursively could see it | |
3035 | and process it again. */ | |
4581e928 | 3036 | copy = *event; |
beecf6a1 | 3037 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3038 | input_pending = readable_events (0); |
4581e928 | 3039 | x_handle_selection_request (©); |
3a3b9632 RS |
3040 | #else |
3041 | /* We're getting selection request events, but we don't have | |
3042 | a window system. */ | |
3043 | abort (); | |
3044 | #endif | |
3045 | } | |
3046 | ||
3047 | else if (event->kind == selection_clear_event) | |
3048 | { | |
3049 | #ifdef HAVE_X11 | |
e0301c07 RS |
3050 | struct input_event copy; |
3051 | ||
3052 | /* Remove it from the buffer before processing it, */ | |
3053 | copy = *event; | |
3054 | ||
beecf6a1 | 3055 | kbd_fetch_ptr = event + 1; |
d9d4c147 | 3056 | input_pending = readable_events (0); |
90c2bb0c | 3057 | x_handle_selection_clear (©); |
3a3b9632 RS |
3058 | #else |
3059 | /* We're getting selection request events, but we don't have | |
3060 | a window system. */ | |
3061 | abort (); | |
3062 | #endif | |
3063 | } | |
3064 | else | |
3065 | break; | |
3066 | } | |
3067 | ||
87dd9b9b | 3068 | old_timers_run = timers_run; |
d9d4c147 | 3069 | get_input_pending (&input_pending, 1); |
87dd9b9b RS |
3070 | |
3071 | if (timers_run != old_timers_run && do_display) | |
3072 | redisplay_preserve_echo_area (); | |
3a3b9632 | 3073 | } |
a612e298 | 3074 | \f |
d9d4c147 KH |
3075 | static EMACS_TIME timer_idleness_start_time; |
3076 | ||
3077 | /* Record the start of when Emacs is idle, | |
3078 | for the sake of running idle-time timers. */ | |
3079 | ||
07a59269 | 3080 | void |
d9d4c147 KH |
3081 | timer_start_idle () |
3082 | { | |
3083 | Lisp_Object timers; | |
3084 | ||
3085 | /* If we are already in the idle state, do nothing. */ | |
3086 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3087 | return; | |
3088 | ||
3089 | EMACS_GET_TIME (timer_idleness_start_time); | |
3090 | ||
3091 | /* Mark all idle-time timers as once again candidates for running. */ | |
3092 | for (timers = Vtimer_idle_list; CONSP (timers); timers = XCONS (timers)->cdr) | |
3093 | { | |
3094 | Lisp_Object timer; | |
3095 | ||
3096 | timer = XCONS (timers)->car; | |
3097 | ||
3098 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) | |
3099 | continue; | |
3100 | XVECTOR (timer)->contents[0] = Qnil; | |
3101 | } | |
3102 | } | |
3103 | ||
3104 | /* Record that Emacs is no longer idle, so stop running idle-time timers. */ | |
3105 | ||
07a59269 | 3106 | void |
d9d4c147 KH |
3107 | timer_stop_idle () |
3108 | { | |
3109 | EMACS_SET_SECS_USECS (timer_idleness_start_time, -1, -1); | |
3110 | } | |
3111 | ||
e044e87c RS |
3112 | /* This is only for debugging. */ |
3113 | struct input_event last_timer_event; | |
3114 | ||
c04cbc3b RS |
3115 | /* Check whether a timer has fired. To prevent larger problems we simply |
3116 | disregard elements that are not proper timers. Do not make a circular | |
3117 | timer list for the time being. | |
3118 | ||
3119 | Returns the number of seconds to wait until the next timer fires. If a | |
3120 | timer is triggering now, return zero seconds. | |
3121 | If no timer is active, return -1 seconds. | |
3122 | ||
4ec4ed6a RS |
3123 | If a timer is ripe, we run it, with quitting turned off. |
3124 | ||
3125 | DO_IT_NOW is now ignored. It used to mean that we should | |
3126 | run the timer directly instead of queueing a timer-event. | |
3127 | Now we always run timers directly. */ | |
c04cbc3b RS |
3128 | |
3129 | EMACS_TIME | |
3130 | timer_check (do_it_now) | |
3131 | int do_it_now; | |
3132 | { | |
3133 | EMACS_TIME nexttime; | |
9291c072 RS |
3134 | EMACS_TIME now, idleness_now; |
3135 | Lisp_Object timers, idle_timers, chosen_timer; | |
9291c072 | 3136 | struct gcpro gcpro1, gcpro2, gcpro3; |
c04cbc3b | 3137 | |
c04cbc3b RS |
3138 | EMACS_SET_SECS (nexttime, -1); |
3139 | EMACS_SET_USECS (nexttime, -1); | |
3140 | ||
9291c072 | 3141 | /* Always consider the ordinary timers. */ |
7ea13e12 | 3142 | timers = Vtimer_list; |
9291c072 RS |
3143 | /* Consider the idle timers only if Emacs is idle. */ |
3144 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3145 | idle_timers = Vtimer_idle_list; | |
3146 | else | |
3147 | idle_timers = Qnil; | |
3148 | chosen_timer = Qnil; | |
3149 | GCPRO3 (timers, idle_timers, chosen_timer); | |
7ea13e12 | 3150 | |
9291c072 | 3151 | if (CONSP (timers) || CONSP (idle_timers)) |
c04cbc3b | 3152 | { |
9291c072 RS |
3153 | EMACS_GET_TIME (now); |
3154 | if (! EMACS_TIME_NEG_P (timer_idleness_start_time)) | |
3155 | EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time); | |
3156 | } | |
c04cbc3b | 3157 | |
9291c072 RS |
3158 | while (CONSP (timers) || CONSP (idle_timers)) |
3159 | { | |
3160 | int triggertime = EMACS_SECS (now); | |
3161 | Lisp_Object *vector; | |
3162 | Lisp_Object timer, idle_timer; | |
3163 | EMACS_TIME timer_time, idle_timer_time; | |
3164 | EMACS_TIME difference, timer_difference, idle_timer_difference; | |
3165 | ||
3166 | /* Skip past invalid timers and timers already handled. */ | |
3167 | if (!NILP (timers)) | |
c04cbc3b | 3168 | { |
d9d4c147 | 3169 | timer = XCONS (timers)->car; |
9291c072 RS |
3170 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) |
3171 | { | |
3172 | timers = XCONS (timers)->cdr; | |
3173 | continue; | |
3174 | } | |
3175 | vector = XVECTOR (timer)->contents; | |
d9d4c147 | 3176 | |
9291c072 RS |
3177 | if (!INTEGERP (vector[1]) || !INTEGERP (vector[2]) |
3178 | || !INTEGERP (vector[3]) | |
3179 | || ! NILP (vector[0])) | |
3180 | { | |
3181 | timers = XCONS (timers)->cdr; | |
3182 | continue; | |
3183 | } | |
3184 | } | |
3185 | if (!NILP (idle_timers)) | |
3186 | { | |
3187 | timer = XCONS (idle_timers)->car; | |
d9d4c147 | 3188 | if (!VECTORP (timer) || XVECTOR (timer)->size != 8) |
9291c072 RS |
3189 | { |
3190 | idle_timers = XCONS (idle_timers)->cdr; | |
3191 | continue; | |
3192 | } | |
d9d4c147 KH |
3193 | vector = XVECTOR (timer)->contents; |
3194 | ||
3195 | if (!INTEGERP (vector[1]) || !INTEGERP (vector[2]) | |
9291c072 RS |
3196 | || !INTEGERP (vector[3]) |
3197 | || ! NILP (vector[0])) | |
3198 | { | |
3199 | idle_timers = XCONS (idle_timers)->cdr; | |
3200 | continue; | |
3201 | } | |
3202 | } | |
d9d4c147 | 3203 | |
9291c072 RS |
3204 | /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE |
3205 | based on the next ordinary timer. | |
3206 | TIMER_DIFFERENCE is the distance in time from NOW to when | |
3207 | this timer becomes ripe (negative if it's already ripe). */ | |
3208 | if (!NILP (timers)) | |
3209 | { | |
3210 | timer = XCONS (timers)->car; | |
3211 | vector = XVECTOR (timer)->contents; | |
d9d4c147 KH |
3212 | EMACS_SET_SECS (timer_time, |
3213 | (XINT (vector[1]) << 16) | (XINT (vector[2]))); | |
3214 | EMACS_SET_USECS (timer_time, XINT (vector[3])); | |
9291c072 RS |
3215 | EMACS_SUB_TIME (timer_difference, timer_time, now); |
3216 | } | |
ba8dfba8 | 3217 | |
9291c072 RS |
3218 | /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE |
3219 | based on the next idle timer. */ | |
3220 | if (!NILP (idle_timers)) | |
3221 | { | |
3222 | idle_timer = XCONS (idle_timers)->car; | |
3223 | vector = XVECTOR (idle_timer)->contents; | |
3224 | EMACS_SET_SECS (idle_timer_time, | |
3225 | (XINT (vector[1]) << 16) | (XINT (vector[2]))); | |
3226 | EMACS_SET_USECS (idle_timer_time, XINT (vector[3])); | |
3227 | EMACS_SUB_TIME (idle_timer_difference, idle_timer_time, idleness_now); | |
3228 | } | |
ba8dfba8 | 3229 | |
9291c072 RS |
3230 | /* Decide which timer is the next timer, |
3231 | and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly. | |
3232 | Also step down the list where we found that timer. */ | |
d9d4c147 | 3233 | |
9291c072 RS |
3234 | if (! NILP (timers) && ! NILP (idle_timers)) |
3235 | { | |
3236 | EMACS_TIME temp; | |
3237 | EMACS_SUB_TIME (temp, timer_difference, idle_timer_difference); | |
3238 | if (EMACS_TIME_NEG_P (temp)) | |
3239 | { | |
3240 | chosen_timer = timer; | |
3241 | timers = XCONS (timers)->cdr; | |
3242 | difference = timer_difference; | |
c04cbc3b | 3243 | } |
d9d4c147 | 3244 | else |
d9d4c147 | 3245 | { |
9291c072 RS |
3246 | chosen_timer = idle_timer; |
3247 | idle_timers = XCONS (idle_timers)->cdr; | |
3248 | difference = idle_timer_difference; | |
d9d4c147 | 3249 | } |
7ea13e12 | 3250 | } |
9291c072 RS |
3251 | else if (! NILP (timers)) |
3252 | { | |
3253 | chosen_timer = timer; | |
3254 | timers = XCONS (timers)->cdr; | |
3255 | difference = timer_difference; | |
3256 | } | |
3257 | else | |
3258 | { | |
3259 | chosen_timer = idle_timer; | |
3260 | idle_timers = XCONS (idle_timers)->cdr; | |
3261 | difference = idle_timer_difference; | |
3262 | } | |
3263 | vector = XVECTOR (chosen_timer)->contents; | |
3264 | ||
3265 | /* If timer is rupe, run it if it hasn't been run. */ | |
3266 | if (EMACS_TIME_NEG_P (difference) | |
3267 | || (EMACS_SECS (difference) == 0 | |
3268 | && EMACS_USECS (difference) == 0)) | |
3269 | { | |
3270 | if (NILP (vector[0])) | |
3271 | { | |
d925fb39 RS |
3272 | Lisp_Object tem; |
3273 | int was_locked = single_kboard; | |
3274 | int count = specpdl_ptr - specpdl; | |
3275 | ||
9291c072 RS |
3276 | /* Mark the timer as triggered to prevent problems if the lisp |
3277 | code fails to reschedule it right. */ | |
3278 | vector[0] = Qt; | |
3279 | ||
d925fb39 | 3280 | specbind (Qinhibit_quit, Qt); |
9291c072 | 3281 | |
d925fb39 RS |
3282 | call1 (Qtimer_event_handler, chosen_timer); |
3283 | timers_run++; | |
9291c072 | 3284 | |
d925fb39 | 3285 | unbind_to (count, Qnil); |
4ec4ed6a | 3286 | |
d925fb39 RS |
3287 | /* Resume allowing input from any kboard, if that was true before. */ |
3288 | if (!was_locked) | |
3289 | any_kboard_state (); | |
9291c072 | 3290 | |
d925fb39 RS |
3291 | /* Since we have handled the event, |
3292 | we don't need to tell the caller to wake up and do it. */ | |
9291c072 RS |
3293 | } |
3294 | } | |
3295 | else | |
3296 | /* When we encounter a timer that is still waiting, | |
3297 | return the amount of time to wait before it is ripe. */ | |
3298 | { | |
3299 | UNGCPRO; | |
9291c072 RS |
3300 | return difference; |
3301 | } | |
c04cbc3b | 3302 | } |
9291c072 | 3303 | |
7ea13e12 RS |
3304 | /* No timers are pending in the future. */ |
3305 | /* Return 0 if we generated an event, and -1 if not. */ | |
3306 | UNGCPRO; | |
c04cbc3b RS |
3307 | return nexttime; |
3308 | } | |
3309 | \f | |
284f4730 | 3310 | /* Caches for modify_event_symbol. */ |
e9bf89a0 | 3311 | static Lisp_Object accent_key_syms; |
284f4730 JB |
3312 | static Lisp_Object func_key_syms; |
3313 | static Lisp_Object mouse_syms; | |
07de30b9 GV |
3314 | #ifdef WINDOWSNT |
3315 | static Lisp_Object mouse_wheel_syms; | |
3316 | #endif | |
a24dc617 | 3317 | static Lisp_Object drag_n_drop_syms; |
284f4730 | 3318 | |
e9bf89a0 RS |
3319 | /* This is a list of keysym codes for special "accent" characters. |
3320 | It parallels lispy_accent_keys. */ | |
3321 | ||
3322 | static int lispy_accent_codes[] = | |
3323 | { | |
79a7046c | 3324 | #ifdef XK_dead_circumflex |
e9bf89a0 | 3325 | XK_dead_circumflex, |
79a7046c RS |
3326 | #else |
3327 | 0, | |
3328 | #endif | |
3329 | #ifdef XK_dead_grave | |
e9bf89a0 | 3330 | XK_dead_grave, |
79a7046c RS |
3331 | #else |
3332 | 0, | |
3333 | #endif | |
3334 | #ifdef XK_dead_tilde | |
e9bf89a0 | 3335 | XK_dead_tilde, |
79a7046c RS |
3336 | #else |
3337 | 0, | |
3338 | #endif | |
3339 | #ifdef XK_dead_diaeresis | |
e9bf89a0 | 3340 | XK_dead_diaeresis, |
79a7046c RS |
3341 | #else |
3342 | 0, | |
3343 | #endif | |
3344 | #ifdef XK_dead_macron | |
e9bf89a0 | 3345 | XK_dead_macron, |
79a7046c RS |
3346 | #else |
3347 | 0, | |
3348 | #endif | |
3349 | #ifdef XK_dead_degree | |
e9bf89a0 | 3350 | XK_dead_degree, |
79a7046c RS |
3351 | #else |
3352 | 0, | |
3353 | #endif | |
3354 | #ifdef XK_dead_acute | |
e9bf89a0 | 3355 | XK_dead_acute, |
79a7046c RS |
3356 | #else |
3357 | 0, | |
3358 | #endif | |
3359 | #ifdef XK_dead_cedilla | |
e9bf89a0 | 3360 | XK_dead_cedilla, |
79a7046c RS |
3361 | #else |
3362 | 0, | |
3363 | #endif | |
3364 | #ifdef XK_dead_breve | |
e9bf89a0 | 3365 | XK_dead_breve, |
79a7046c RS |
3366 | #else |
3367 | 0, | |
3368 | #endif | |
3369 | #ifdef XK_dead_ogonek | |
e9bf89a0 | 3370 | XK_dead_ogonek, |
79a7046c RS |
3371 | #else |
3372 | 0, | |
3373 | #endif | |
3374 | #ifdef XK_dead_caron | |
e9bf89a0 | 3375 | XK_dead_caron, |
79a7046c RS |
3376 | #else |
3377 | 0, | |
3378 | #endif | |
3379 | #ifdef XK_dead_doubleacute | |
e9bf89a0 | 3380 | XK_dead_doubleacute, |
79a7046c RS |
3381 | #else |
3382 | 0, | |
3383 | #endif | |
3384 | #ifdef XK_dead_abovedot | |
e9bf89a0 | 3385 | XK_dead_abovedot, |
79a7046c RS |
3386 | #else |
3387 | 0, | |
3388 | #endif | |
e9bf89a0 RS |
3389 | }; |
3390 | ||
3391 | /* This is a list of Lisp names for special "accent" characters. | |
3392 | It parallels lispy_accent_codes. */ | |
3393 | ||
3394 | static char *lispy_accent_keys[] = | |
3395 | { | |
3396 | "dead-circumflex", | |
3397 | "dead-grave", | |
3398 | "dead-tilde", | |
3399 | "dead-diaeresis", | |
3400 | "dead-macron", | |
3401 | "dead-degree", | |
3402 | "dead-acute", | |
3403 | "dead-cedilla", | |
3404 | "dead-breve", | |
3405 | "dead-ogonek", | |
3406 | "dead-caron", | |
3407 | "dead-doubleacute", | |
3408 | "dead-abovedot", | |
3409 | }; | |
3410 | ||
e98a93eb GV |
3411 | #ifdef HAVE_NTGUI |
3412 | #define FUNCTION_KEY_OFFSET 0x0 | |
3413 | ||
3414 | char *lispy_function_keys[] = | |
3415 | { | |
3416 | 0, /* 0 */ | |
3417 | ||
3418 | 0, /* VK_LBUTTON 0x01 */ | |
3419 | 0, /* VK_RBUTTON 0x02 */ | |
3420 | "cancel", /* VK_CANCEL 0x03 */ | |
3421 | 0, /* VK_MBUTTON 0x04 */ | |
3422 | ||
3423 | 0, 0, 0, /* 0x05 .. 0x07 */ | |
3424 | ||
3425 | "backspace", /* VK_BACK 0x08 */ | |
3426 | "tab", /* VK_TAB 0x09 */ | |
3427 | ||
3428 | 0, 0, /* 0x0A .. 0x0B */ | |
3429 | ||
3430 | "clear", /* VK_CLEAR 0x0C */ | |
3431 | "return", /* VK_RETURN 0x0D */ | |
3432 | ||
3433 | 0, 0, /* 0x0E .. 0x0F */ | |
3434 | ||
3435 | "shift", /* VK_SHIFT 0x10 */ | |
3436 | "control", /* VK_CONTROL 0x11 */ | |
3437 | "menu", /* VK_MENU 0x12 */ | |
3438 | "pause", /* VK_PAUSE 0x13 */ | |
3439 | "capital", /* VK_CAPITAL 0x14 */ | |
3440 | ||
3441 | 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */ | |
3442 | ||
3443 | 0, /* VK_ESCAPE 0x1B */ | |
3444 | ||
3445 | 0, 0, 0, 0, /* 0x1C .. 0x1F */ | |
3446 | ||
3447 | 0, /* VK_SPACE 0x20 */ | |
3448 | "prior", /* VK_PRIOR 0x21 */ | |
3449 | "next", /* VK_NEXT 0x22 */ | |
3450 | "end", /* VK_END 0x23 */ | |
3451 | "home", /* VK_HOME 0x24 */ | |
3452 | "left", /* VK_LEFT 0x25 */ | |
3453 | "up", /* VK_UP 0x26 */ | |
3454 | "right", /* VK_RIGHT 0x27 */ | |
3455 | "down", /* VK_DOWN 0x28 */ | |
3456 | "select", /* VK_SELECT 0x29 */ | |
3457 | "print", /* VK_PRINT 0x2A */ | |
3458 | "execute", /* VK_EXECUTE 0x2B */ | |
3459 | "snapshot", /* VK_SNAPSHOT 0x2C */ | |
3460 | "insert", /* VK_INSERT 0x2D */ | |
3461 | "delete", /* VK_DELETE 0x2E */ | |
3462 | "help", /* VK_HELP 0x2F */ | |
3463 | ||
3464 | /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ | |
3465 | ||
3466 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3467 | ||
3468 | 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */ | |
3469 | ||
3470 | /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ | |
3471 | ||
3472 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3473 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3474 | 0, 0, 0, 0, 0, 0, 0, 0, | |
3475 | ||
e376f90d RS |
3476 | "lwindow", /* VK_LWIN 0x5B */ |
3477 | "rwindow", /* VK_RWIN 0x5C */ | |
3478 | "apps", /* VK_APPS 0x5D */ | |
e98a93eb GV |
3479 | |
3480 | 0, 0, /* 0x5E .. 0x5F */ | |
3481 | ||
3482 | "kp-0", /* VK_NUMPAD0 0x60 */ | |
3483 | "kp-1", /* VK_NUMPAD1 0x61 */ | |
3484 | "kp-2", /* VK_NUMPAD2 0x62 */ | |
3485 | "kp-3", /* VK_NUMPAD3 0x63 */ | |
3486 | "kp-4", /* VK_NUMPAD4 0x64 */ | |
3487 | "kp-5", /* VK_NUMPAD5 0x65 */ | |
3488 | "kp-6", /* VK_NUMPAD6 0x66 */ | |
3489 | "kp-7", /* VK_NUMPAD7 0x67 */ | |
3490 | "kp-8", /* VK_NUMPAD8 0x68 */ | |
3491 | "kp-9", /* VK_NUMPAD9 0x69 */ | |
3492 | "kp-multiply", /* VK_MULTIPLY 0x6A */ | |
3493 | "kp-add", /* VK_ADD 0x6B */ | |
3494 | "kp-separator", /* VK_SEPARATOR 0x6C */ | |
3495 | "kp-subtract", /* VK_SUBTRACT 0x6D */ | |
3496 | "kp-decimal", /* VK_DECIMAL 0x6E */ | |
3497 | "kp-divide", /* VK_DIVIDE 0x6F */ | |
3498 | "f1", /* VK_F1 0x70 */ | |
3499 | "f2", /* VK_F2 0x71 */ | |
3500 | "f3", /* VK_F3 0x72 */ | |
3501 | "f4", /* VK_F4 0x73 */ | |
3502 | "f5", /* VK_F5 0x74 */ | |
3503 | "f6", /* VK_F6 0x75 */ | |
3504 | "f7", /* VK_F7 0x76 */ | |
3505 | "f8", /* VK_F8 0x77 */ | |
3506 | "f9", /* VK_F9 0x78 */ | |
3507 | "f10", /* VK_F10 0x79 */ | |
3508 | "f11", /* VK_F11 0x7A */ | |
3509 | "f12", /* VK_F12 0x7B */ | |
3510 | "f13", /* VK_F13 0x7C */ | |
3511 | "f14", /* VK_F14 0x7D */ | |
3512 | "f15", /* VK_F15 0x7E */ | |
3513 | "f16", /* VK_F16 0x7F */ | |
3514 | "f17", /* VK_F17 0x80 */ | |
3515 | "f18", /* VK_F18 0x81 */ | |
3516 | "f19", /* VK_F19 0x82 */ | |
3517 | "f20", /* VK_F20 0x83 */ | |
3518 | "f21", /* VK_F21 0x84 */ | |
3519 | "f22", /* VK_F22 0x85 */ | |
3520 | "f23", /* VK_F23 0x86 */ | |
3521 | "f24", /* VK_F24 0x87 */ | |
3522 | ||
3523 | 0, 0, 0, 0, /* 0x88 .. 0x8B */ | |
3524 | 0, 0, 0, 0, /* 0x8C .. 0x8F */ | |
3525 | ||
3526 | "kp-numlock", /* VK_NUMLOCK 0x90 */ | |
3527 | "scroll", /* VK_SCROLL 0x91 */ | |
3528 | ||
e376f90d RS |
3529 | "kp-space", /* VK_NUMPAD_CLEAR 0x92 */ |
3530 | "kp-enter", /* VK_NUMPAD_ENTER 0x93 */ | |
3531 | "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */ | |
3532 | "kp-next", /* VK_NUMPAD_NEXT 0x95 */ | |
3533 | "kp-end", /* VK_NUMPAD_END 0x96 */ | |
3534 | "kp-home", /* VK_NUMPAD_HOME 0x97 */ | |
3535 | "kp-left", /* VK_NUMPAD_LEFT 0x98 */ | |
3536 | "kp-up", /* VK_NUMPAD_UP 0x99 */ | |
3537 | "kp-right", /* VK_NUMPAD_RIGHT 0x9A */ | |
3538 | "kp-down", /* VK_NUMPAD_DOWN 0x9B */ | |
3539 | "kp-insert", /* VK_NUMPAD_INSERT 0x9C */ | |
3540 | "kp-delete", /* VK_NUMPAD_DELETE 0x9D */ | |
3541 | ||
3542 | 0, 0, /* 0x9E .. 0x9F */ | |
3543 | ||
e98a93eb GV |
3544 | /* |
3545 | * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys. | |
e8886a1d | 3546 | * Used only as parameters to GetAsyncKeyState and GetKeyState. |
e98a93eb GV |
3547 | * No other API or message will distinguish left and right keys this way. |
3548 | */ | |
3549 | /* 0xA0 .. 0xEF */ | |
3550 | ||
3551 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3552 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3553 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3554 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3555 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3556 | ||
3557 | /* 0xF0 .. 0xF5 */ | |
3558 | ||
3559 | 0, 0, 0, 0, 0, 0, | |
3560 | ||
3561 | "attn", /* VK_ATTN 0xF6 */ | |
3562 | "crsel", /* VK_CRSEL 0xF7 */ | |
3563 | "exsel", /* VK_EXSEL 0xF8 */ | |
3564 | "ereof", /* VK_EREOF 0xF9 */ | |
3565 | "play", /* VK_PLAY 0xFA */ | |
3566 | "zoom", /* VK_ZOOM 0xFB */ | |
3567 | "noname", /* VK_NONAME 0xFC */ | |
3568 | "pa1", /* VK_PA1 0xFD */ | |
3569 | "oem_clear", /* VK_OEM_CLEAR 0xFE */ | |
3570 | }; | |
3571 | ||
04f215f0 | 3572 | #else /* not HAVE_NTGUI */ |
e98a93eb | 3573 | |
37cd9f30 KH |
3574 | #ifdef XK_kana_A |
3575 | static char *lispy_kana_keys[] = | |
3576 | { | |
3577 | /* X Keysym value */ | |
3578 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */ | |
3579 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */ | |
3580 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */ | |
3581 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */ | |
3582 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */ | |
3583 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */ | |
3584 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */ | |
3585 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0, | |
3586 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */ | |
3587 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */ | |
3588 | 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket", | |
3589 | "kana-comma", "kana-conjunctive", "kana-WO", "kana-a", | |
3590 | "kana-i", "kana-u", "kana-e", "kana-o", | |
3591 | "kana-ya", "kana-yu", "kana-yo", "kana-tsu", | |
3592 | "prolongedsound", "kana-A", "kana-I", "kana-U", | |
3593 | "kana-E", "kana-O", "kana-KA", "kana-KI", | |
3594 | "kana-KU", "kana-KE", "kana-KO", "kana-SA", | |
3595 | "kana-SHI", "kana-SU", "kana-SE", "kana-SO", | |
3596 | "kana-TA", "kana-CHI", "kana-TSU", "kana-TE", | |
3597 | "kana-TO", "kana-NA", "kana-NI", "kana-NU", | |
3598 | "kana-NE", "kana-NO", "kana-HA", "kana-HI", | |
3599 | "kana-FU", "kana-HE", "kana-HO", "kana-MA", | |
3600 | "kana-MI", "kana-MU", "kana-ME", "kana-MO", | |
3601 | "kana-YA", "kana-YU", "kana-YO", "kana-RA", | |
3602 | "kana-RI", "kana-RU", "kana-RE", "kana-RO", | |
3603 | "kana-WA", "kana-N", "voicedsound", "semivoicedsound", | |
3604 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */ | |
3605 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */ | |
3606 | }; | |
3607 | #endif /* XK_kana_A */ | |
3608 | ||
04f215f0 RS |
3609 | #define FUNCTION_KEY_OFFSET 0xff00 |
3610 | ||
284f4730 JB |
3611 | /* You'll notice that this table is arranged to be conveniently |
3612 | indexed by X Windows keysym values. */ | |
3613 | static char *lispy_function_keys[] = | |
3614 | { | |
3615 | /* X Keysym value */ | |
3616 | ||
75045dcb RS |
3617 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */ |
3618 | "backspace", "tab", "linefeed", "clear", | |
3619 | 0, "return", 0, 0, | |
3620 | 0, 0, 0, "pause", /* 0xff10...1f */ | |
3621 | 0, 0, 0, 0, 0, 0, 0, "escape", | |
86e5706b | 3622 | 0, 0, 0, 0, |
75045dcb RS |
3623 | 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */ |
3624 | "romaji", "hiragana", "katakana", "hiragana-katakana", | |
3625 | "zenkaku", "hankaku", "zenkaku-hankaku", "touroku", | |
3626 | "massyo", "kana-lock", "kana-shift", "eisu-shift", | |
3627 | "eisu-toggle", /* 0xff30...3f */ | |
3628 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
86e5706b RS |
3629 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */ |
3630 | ||
75045dcb RS |
3631 | "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */ |
3632 | "down", "prior", "next", "end", | |
3633 | "begin", 0, 0, 0, 0, 0, 0, 0, | |
284f4730 JB |
3634 | "select", /* 0xff60 */ /* IsMiscFunctionKey */ |
3635 | "print", | |
3636 | "execute", | |
3637 | "insert", | |
3638 | 0, /* 0xff64 */ | |
3639 | "undo", | |
3640 | "redo", | |
3641 | "menu", | |
3642 | "find", | |
3643 | "cancel", | |
3644 | "help", | |
3645 | "break", /* 0xff6b */ | |
3646 | ||
75045dcb RS |
3647 | 0, 0, 0, 0, |
3648 | 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */ | |
3649 | 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */ | |
284f4730 JB |
3650 | "kp-space", /* 0xff80 */ /* IsKeypadKey */ |
3651 | 0, 0, 0, 0, 0, 0, 0, 0, | |
3652 | "kp-tab", /* 0xff89 */ | |
3653 | 0, 0, 0, | |
3654 | "kp-enter", /* 0xff8d */ | |
3655 | 0, 0, 0, | |
3656 | "kp-f1", /* 0xff91 */ | |
3657 | "kp-f2", | |
3658 | "kp-f3", | |
3659 | "kp-f4", | |
872157e7 RS |
3660 | "kp-home", /* 0xff95 */ |
3661 | "kp-left", | |
3662 | "kp-up", | |
3663 | "kp-right", | |
3664 | "kp-down", | |
3665 | "kp-prior", /* kp-page-up */ | |
3666 | "kp-next", /* kp-page-down */ | |
3667 | "kp-end", | |
3668 | "kp-begin", | |
3669 | "kp-insert", | |
3670 | "kp-delete", | |
3671 | 0, /* 0xffa0 */ | |
3672 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
284f4730 JB |
3673 | "kp-multiply", /* 0xffaa */ |
3674 | "kp-add", | |
3675 | "kp-separator", | |
3676 | "kp-subtract", | |
3677 | "kp-decimal", | |
3678 | "kp-divide", /* 0xffaf */ | |
3679 | "kp-0", /* 0xffb0 */ | |
3680 | "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9", | |
3681 | 0, /* 0xffba */ | |
3682 | 0, 0, | |
3683 | "kp-equal", /* 0xffbd */ | |
3684 | "f1", /* 0xffbe */ /* IsFunctionKey */ | |
86e5706b RS |
3685 | "f2", |
3686 | "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */ | |
3687 | "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", | |
3688 | "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */ | |
3689 | "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34", | |
3690 | "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */ | |
3691 | 0, 0, 0, 0, 0, 0, 0, 0, | |
3692 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */ | |
3693 | 0, 0, 0, 0, 0, 0, 0, "delete" | |
04f215f0 | 3694 | }; |
284f4730 | 3695 | |
04f215f0 RS |
3696 | /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */ |
3697 | #define ISO_FUNCTION_KEY_OFFSET 0xfe00 | |
3698 | ||
3699 | static char *iso_lispy_function_keys[] = | |
3700 | { | |
3701 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */ | |
3702 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */ | |
3703 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */ | |
3704 | 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */ | |
3705 | "iso-lefttab", /* 0xfe20 */ | |
3706 | "iso-move-line-up", "iso-move-line-down", | |
3707 | "iso-partial-line-up", "iso-partial-line-down", | |
3708 | "iso-partial-space-left", "iso-partial-space-right", | |
3709 | "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */ | |
3710 | "iso-release-margin-left", "iso-release-margin-right", | |
3711 | "iso-release-both-margins", | |
3712 | "iso-fast-cursor-left", "iso-fast-cursor-right", | |
3713 | "iso-fast-cursor-up", "iso-fast-cursor-down", | |
3714 | "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */ | |
3715 | "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */ | |
3716 | }; | |
3717 | ||
3718 | #endif /* not HAVE_NTGUI */ | |
e98a93eb | 3719 | |
df0f2ba1 | 3720 | static char *lispy_mouse_names[] = |
284f4730 JB |
3721 | { |
3722 | "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5" | |
3723 | }; | |
3724 | ||
07de30b9 GV |
3725 | #ifdef WINDOWSNT |
3726 | /* mouse-wheel events are generated by the wheel on devices such as | |
3727 | the MS Intellimouse. The wheel sits in between the left and right | |
3728 | mouse buttons, and is typically used to scroll or zoom the window | |
3729 | underneath the pointer. mouse-wheel events specify the object on | |
3730 | which they operate, and a delta corresponding to the amount and | |
3731 | direction that the wheel is rotated. Clicking the mouse-wheel | |
3732 | generates a mouse-2 event. */ | |
3733 | static char *lispy_mouse_wheel_names[] = | |
3734 | { | |
3735 | "mouse-wheel" | |
3736 | }; | |
a24dc617 | 3737 | |
07de30b9 GV |
3738 | #endif /* WINDOWSNT */ |
3739 | ||
a24dc617 RS |
3740 | /* drag-n-drop events are generated when a set of selected files are |
3741 | dragged from another application and dropped onto an Emacs window. */ | |
3742 | static char *lispy_drag_n_drop_names[] = | |
3743 | { | |
3744 | "drag-n-drop" | |
3745 | }; | |
3746 | ||
3c370943 | 3747 | /* Scroll bar parts. */ |
4bb994d1 | 3748 | Lisp_Object Qabove_handle, Qhandle, Qbelow_handle; |
db08707d | 3749 | Lisp_Object Qup, Qdown; |
4bb994d1 | 3750 | |
3c370943 JB |
3751 | /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */ |
3752 | Lisp_Object *scroll_bar_parts[] = { | |
db08707d RS |
3753 | &Qabove_handle, &Qhandle, &Qbelow_handle, |
3754 | &Qup, &Qdown, | |
4bb994d1 JB |
3755 | }; |
3756 | ||
3757 | ||
7b4aedb9 | 3758 | /* A vector, indexed by button number, giving the down-going location |
3c370943 | 3759 | of currently depressed buttons, both scroll bar and non-scroll bar. |
7b4aedb9 JB |
3760 | |
3761 | The elements have the form | |
3762 | (BUTTON-NUMBER MODIFIER-MASK . REST) | |
3763 | where REST is the cdr of a position as it would be reported in the event. | |
3764 | ||
3765 | The make_lispy_event function stores positions here to tell the | |
3766 | difference between click and drag events, and to store the starting | |
3767 | location to be included in drag events. */ | |
3768 | ||
3769 | static Lisp_Object button_down_location; | |
88cb0656 | 3770 | |
fbcd35bd JB |
3771 | /* Information about the most recent up-going button event: Which |
3772 | button, what location, and what time. */ | |
3773 | ||
559f9d04 RS |
3774 | static int last_mouse_button; |
3775 | static int last_mouse_x; | |
3776 | static int last_mouse_y; | |
3777 | static unsigned long button_down_time; | |
fbcd35bd | 3778 | |
564dc952 JB |
3779 | /* The maximum time between clicks to make a double-click, |
3780 | or Qnil to disable double-click detection, | |
3781 | or Qt for no time limit. */ | |
3782 | Lisp_Object Vdouble_click_time; | |
fbcd35bd JB |
3783 | |
3784 | /* The number of clicks in this multiple-click. */ | |
3785 | ||
3786 | int double_click_count; | |
3787 | ||
284f4730 JB |
3788 | /* Given a struct input_event, build the lisp event which represents |
3789 | it. If EVENT is 0, build a mouse movement event from the mouse | |
88cb0656 JB |
3790 | movement buffer, which should have a movement event in it. |
3791 | ||
3792 | Note that events must be passed to this function in the order they | |
3793 | are received; this function stores the location of button presses | |
3794 | in order to build drag events when the button is released. */ | |
284f4730 JB |
3795 | |
3796 | static Lisp_Object | |
3797 | make_lispy_event (event) | |
3798 | struct input_event *event; | |
3799 | { | |
79a7046c RS |
3800 | int i; |
3801 | ||
0220c518 | 3802 | switch (SWITCH_ENUM_CAST (event->kind)) |
284f4730 | 3803 | { |
284f4730 JB |
3804 | /* A simple keystroke. */ |
3805 | case ascii_keystroke: | |
86e5706b | 3806 | { |
9343ab07 | 3807 | Lisp_Object lispy_c; |
e9bf89a0 | 3808 | int c = event->code & 0377; |
5a1c6df8 JB |
3809 | /* Turn ASCII characters into control characters |
3810 | when proper. */ | |
3811 | if (event->modifiers & ctrl_modifier) | |
d205953b JB |
3812 | c = make_ctrl_char (c); |
3813 | ||
3814 | /* Add in the other modifier bits. We took care of ctrl_modifier | |
3815 | just above, and the shift key was taken care of by the X code, | |
3816 | and applied to control characters by make_ctrl_char. */ | |
86e5706b RS |
3817 | c |= (event->modifiers |
3818 | & (meta_modifier | alt_modifier | |
3819 | | hyper_modifier | super_modifier)); | |
32454a9f RS |
3820 | /* Distinguish Shift-SPC from SPC. */ |
3821 | if ((event->code & 0377) == 040 | |
3822 | && event->modifiers & shift_modifier) | |
3823 | c |= shift_modifier; | |
559f9d04 | 3824 | button_down_time = 0; |
bb9e9bed | 3825 | XSETFASTINT (lispy_c, c); |
9343ab07 | 3826 | return lispy_c; |
86e5706b | 3827 | } |
284f4730 JB |
3828 | |
3829 | /* A function key. The symbol may need to have modifier prefixes | |
3830 | tacked onto it. */ | |
3831 | case non_ascii_keystroke: | |
559f9d04 | 3832 | button_down_time = 0; |
e9bf89a0 RS |
3833 | |
3834 | for (i = 0; i < sizeof (lispy_accent_codes) / sizeof (int); i++) | |
3835 | if (event->code == lispy_accent_codes[i]) | |
3836 | return modify_event_symbol (i, | |
3837 | event->modifiers, | |
80e4aa30 | 3838 | Qfunction_key, Qnil, |
e9bf89a0 RS |
3839 | lispy_accent_keys, &accent_key_syms, |
3840 | (sizeof (lispy_accent_keys) | |
3841 | / sizeof (lispy_accent_keys[0]))); | |
3842 | ||
270a208f | 3843 | /* Handle system-specific keysyms. */ |
80e4aa30 RS |
3844 | if (event->code & (1 << 28)) |
3845 | { | |
3846 | /* We need to use an alist rather than a vector as the cache | |
3847 | since we can't make a vector long enuf. */ | |
142e6c73 KH |
3848 | if (NILP (current_kboard->system_key_syms)) |
3849 | current_kboard->system_key_syms = Fcons (Qnil, Qnil); | |
2c834fb3 | 3850 | return modify_event_symbol (event->code, |
80e4aa30 | 3851 | event->modifiers, |
7c97ffdc KH |
3852 | Qfunction_key, |
3853 | current_kboard->Vsystem_key_alist, | |
142e6c73 KH |
3854 | 0, ¤t_kboard->system_key_syms, |
3855 | (unsigned)-1); | |
80e4aa30 RS |
3856 | } |
3857 | ||
37cd9f30 KH |
3858 | #ifdef XK_kana_A |
3859 | if (event->code >= 0x400 && event->code < 0x500) | |
3860 | return modify_event_symbol (event->code - 0x400, | |
3861 | event->modifiers & ~shift_modifier, | |
3862 | Qfunction_key, Qnil, | |
3863 | lispy_kana_keys, &func_key_syms, | |
3864 | (sizeof (lispy_kana_keys) | |
3865 | / sizeof (lispy_kana_keys[0]))); | |
3866 | #endif /* XK_kana_A */ | |
3867 | ||
111c4138 | 3868 | #ifdef ISO_FUNCTION_KEY_OFFSET |
04f215f0 RS |
3869 | if (event->code < FUNCTION_KEY_OFFSET |
3870 | && event->code >= ISO_FUNCTION_KEY_OFFSET) | |
3871 | return modify_event_symbol (event->code - ISO_FUNCTION_KEY_OFFSET, | |
3872 | event->modifiers, | |
3873 | Qfunction_key, Qnil, | |
3874 | iso_lispy_function_keys, &func_key_syms, | |
3875 | (sizeof (iso_lispy_function_keys) | |
3876 | / sizeof (iso_lispy_function_keys[0]))); | |
3877 | else | |
111c4138 | 3878 | #endif |
04f215f0 RS |
3879 | return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET, |
3880 | event->modifiers, | |
3881 | Qfunction_key, Qnil, | |
3882 | lispy_function_keys, &func_key_syms, | |
3883 | (sizeof (lispy_function_keys) | |
3884 | / sizeof (lispy_function_keys[0]))); | |
284f4730 | 3885 | |
514354e9 | 3886 | #ifdef HAVE_MOUSE |
df0f2ba1 | 3887 | /* A mouse click. Figure out where it is, decide whether it's |
88cb0656 | 3888 | a press, click or drag, and build the appropriate structure. */ |
284f4730 | 3889 | case mouse_click: |
3c370943 | 3890 | case scroll_bar_click: |
284f4730 | 3891 | { |
e9bf89a0 | 3892 | int button = event->code; |
559f9d04 | 3893 | int is_double; |
7b4aedb9 | 3894 | Lisp_Object position; |
dbc4e1c1 JB |
3895 | Lisp_Object *start_pos_ptr; |
3896 | Lisp_Object start_pos; | |
284f4730 | 3897 | |
7b4aedb9 | 3898 | if (button < 0 || button >= NUM_MOUSE_BUTTONS) |
88cb0656 JB |
3899 | abort (); |
3900 | ||
7b4aedb9 JB |
3901 | /* Build the position as appropriate for this mouse click. */ |
3902 | if (event->kind == mouse_click) | |
284f4730 | 3903 | { |
7b4aedb9 | 3904 | int part; |
598a9fa7 | 3905 | FRAME_PTR f = XFRAME (event->frame_or_window); |
0aafc975 | 3906 | Lisp_Object window; |
7b4aedb9 | 3907 | Lisp_Object posn; |
9e20143a RS |
3908 | int row, column; |
3909 | ||
5da3133a RS |
3910 | /* Ignore mouse events that were made on frame that |
3911 | have been deleted. */ | |
3912 | if (! FRAME_LIVE_P (f)) | |
3913 | return Qnil; | |
3914 | ||
9e20143a | 3915 | pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), |
6c6a9be8 | 3916 | &column, &row, NULL, 1); |
7b4aedb9 | 3917 | |
eef045bf RS |
3918 | #ifndef USE_X_TOOLKIT |
3919 | /* In the non-toolkit version, clicks on the menu bar | |
3920 | are ordinary button events in the event buffer. | |
3921 | Distinguish them, and invoke the menu. | |
3922 | ||
3923 | (In the toolkit version, the toolkit handles the menu bar | |
3924 | and Emacs doesn't know about it until after the user | |
3925 | makes a selection.) */ | |
2ee250ec RS |
3926 | if (row >= 0 && row < FRAME_MENU_BAR_LINES (f) |
3927 | && (event->modifiers & down_modifier)) | |
bb936752 | 3928 | { |
b7c49376 | 3929 | Lisp_Object items, item; |
0a0e8fe6 RS |
3930 | int hpos; |
3931 | int i; | |
3932 | ||
2ee250ec | 3933 | #if 0 |
0a0e8fe6 RS |
3934 | /* Activate the menu bar on the down event. If the |
3935 | up event comes in before the menu code can deal with it, | |
3936 | just ignore it. */ | |
3937 | if (! (event->modifiers & down_modifier)) | |
3938 | return Qnil; | |
2ee250ec | 3939 | #endif |
0aafc975 | 3940 | |
f2ae6b3f | 3941 | item = Qnil; |
5ec75a55 | 3942 | items = FRAME_MENU_BAR_ITEMS (f); |
35b3402f | 3943 | for (i = 0; i < XVECTOR (items)->size; i += 4) |
5ec75a55 RS |
3944 | { |
3945 | Lisp_Object pos, string; | |
b7c49376 | 3946 | string = XVECTOR (items)->contents[i + 1]; |
35b3402f | 3947 | pos = XVECTOR (items)->contents[i + 3]; |
b7c49376 RS |
3948 | if (NILP (string)) |
3949 | break; | |
9e20143a RS |
3950 | if (column >= XINT (pos) |
3951 | && column < XINT (pos) + XSTRING (string)->size) | |
b7c49376 RS |
3952 | { |
3953 | item = XVECTOR (items)->contents[i]; | |
3954 | break; | |
3955 | } | |
5ec75a55 | 3956 | } |
9e20143a | 3957 | |
5ec75a55 RS |
3958 | position |
3959 | = Fcons (event->frame_or_window, | |
3960 | Fcons (Qmenu_bar, | |
3961 | Fcons (Fcons (event->x, event->y), | |
3962 | Fcons (make_number (event->timestamp), | |
3963 | Qnil)))); | |
3964 | ||
b7c49376 | 3965 | return Fcons (item, Fcons (position, Qnil)); |
5ec75a55 | 3966 | } |
eef045bf | 3967 | #endif /* not USE_X_TOOLKIT */ |
0aafc975 | 3968 | |
9e20143a | 3969 | window = window_from_coordinates (f, column, row, &part); |
0aafc975 | 3970 | |
8c18cbfb | 3971 | if (!WINDOWP (window)) |
78ced549 RS |
3972 | { |
3973 | window = event->frame_or_window; | |
3974 | posn = Qnil; | |
3975 | } | |
284f4730 | 3976 | else |
7b4aedb9 | 3977 | { |
9e20143a | 3978 | int pixcolumn, pixrow; |
c8738c33 | 3979 | column -= WINDOW_LEFT_MARGIN (XWINDOW (window)); |
9e20143a RS |
3980 | row -= XINT (XWINDOW (window)->top); |
3981 | glyph_to_pixel_coords (f, column, row, &pixcolumn, &pixrow); | |
3982 | XSETINT (event->x, pixcolumn); | |
3983 | XSETINT (event->y, pixrow); | |
dbc4e1c1 | 3984 | |
7b4aedb9 JB |
3985 | if (part == 1) |
3986 | posn = Qmode_line; | |
3987 | else if (part == 2) | |
3988 | posn = Qvertical_line; | |
3989 | else | |
18cd2eeb KH |
3990 | XSETINT (posn, |
3991 | buffer_posn_from_coords (XWINDOW (window), | |
3992 | column, row)); | |
7b4aedb9 JB |
3993 | } |
3994 | ||
5ec75a55 RS |
3995 | position |
3996 | = Fcons (window, | |
3997 | Fcons (posn, | |
3998 | Fcons (Fcons (event->x, event->y), | |
3999 | Fcons (make_number (event->timestamp), | |
4000 | Qnil)))); | |
284f4730 | 4001 | } |
7b4aedb9 | 4002 | else |
88cb0656 | 4003 | { |
9e20143a RS |
4004 | Lisp_Object window; |
4005 | Lisp_Object portion_whole; | |
4006 | Lisp_Object part; | |
4007 | ||
4008 | window = event->frame_or_window; | |
4009 | portion_whole = Fcons (event->x, event->y); | |
4010 | part = *scroll_bar_parts[(int) event->part]; | |
7b4aedb9 | 4011 | |
db08707d RS |
4012 | position |
4013 | = Fcons (window, | |
4014 | Fcons (Qvertical_scroll_bar, | |
4015 | Fcons (portion_whole, | |
4016 | Fcons (make_number (event->timestamp), | |
4017 | Fcons (part, Qnil))))); | |
88cb0656 JB |
4018 | } |
4019 | ||
dbc4e1c1 JB |
4020 | start_pos_ptr = &XVECTOR (button_down_location)->contents[button]; |
4021 | ||
4022 | start_pos = *start_pos_ptr; | |
4023 | *start_pos_ptr = Qnil; | |
7b4aedb9 | 4024 | |
559f9d04 RS |
4025 | is_double = (button == last_mouse_button |
4026 | && XINT (event->x) == last_mouse_x | |
4027 | && XINT (event->y) == last_mouse_y | |
4028 | && button_down_time != 0 | |
4029 | && (EQ (Vdouble_click_time, Qt) | |
4030 | || (INTEGERP (Vdouble_click_time) | |
4031 | && ((int)(event->timestamp - button_down_time) | |
4032 | < XINT (Vdouble_click_time))))); | |
4033 | last_mouse_button = button; | |
4034 | last_mouse_x = XINT (event->x); | |
4035 | last_mouse_y = XINT (event->y); | |
4036 | ||
7b4aedb9 JB |
4037 | /* If this is a button press, squirrel away the location, so |
4038 | we can decide later whether it was a click or a drag. */ | |
4039 | if (event->modifiers & down_modifier) | |
559f9d04 RS |
4040 | { |
4041 | if (is_double) | |
4042 | { | |
4043 | double_click_count++; | |
4044 | event->modifiers |= ((double_click_count > 2) | |
4045 | ? triple_modifier | |
4046 | : double_modifier); | |
4047 | } | |
4048 | else | |
4049 | double_click_count = 1; | |
4050 | button_down_time = event->timestamp; | |
4051 | *start_pos_ptr = Fcopy_alist (position); | |
4052 | } | |
7b4aedb9 | 4053 | |
88cb0656 | 4054 | /* Now we're releasing a button - check the co-ordinates to |
7b4aedb9 | 4055 | see if this was a click or a drag. */ |
88cb0656 JB |
4056 | else if (event->modifiers & up_modifier) |
4057 | { | |
48e416d4 RS |
4058 | /* If we did not see a down before this up, |
4059 | ignore the up. Probably this happened because | |
4060 | the down event chose a menu item. | |
4061 | It would be an annoyance to treat the release | |
4062 | of the button that chose the menu item | |
4063 | as a separate event. */ | |
4064 | ||
8c18cbfb | 4065 | if (!CONSP (start_pos)) |
48e416d4 RS |
4066 | return Qnil; |
4067 | ||
88cb0656 | 4068 | event->modifiers &= ~up_modifier; |
48e416d4 | 4069 | #if 0 /* Formerly we treated an up with no down as a click event. */ |
8c18cbfb | 4070 | if (!CONSP (start_pos)) |
dbc4e1c1 JB |
4071 | event->modifiers |= click_modifier; |
4072 | else | |
48e416d4 | 4073 | #endif |
dbc4e1c1 JB |
4074 | { |
4075 | /* The third element of every position should be the (x,y) | |
4076 | pair. */ | |
9b8eb840 | 4077 | Lisp_Object down; |
dbc4e1c1 | 4078 | |
9b8eb840 | 4079 | down = Fnth (make_number (2), start_pos); |
fbcd35bd JB |
4080 | if (EQ (event->x, XCONS (down)->car) |
4081 | && EQ (event->y, XCONS (down)->cdr)) | |
4082 | { | |
bc536d84 | 4083 | event->modifiers |= click_modifier; |
fbcd35bd JB |
4084 | } |
4085 | else | |
4086 | { | |
559f9d04 | 4087 | button_down_time = 0; |
fbcd35bd JB |
4088 | event->modifiers |= drag_modifier; |
4089 | } | |
bc536d84 RS |
4090 | /* Don't check is_double; treat this as multiple |
4091 | if the down-event was multiple. */ | |
4092 | if (double_click_count > 1) | |
4093 | event->modifiers |= ((double_click_count > 2) | |
4094 | ? triple_modifier | |
4095 | : double_modifier); | |
dbc4e1c1 | 4096 | } |
88cb0656 JB |
4097 | } |
4098 | else | |
4099 | /* Every mouse event should either have the down_modifier or | |
7b4aedb9 | 4100 | the up_modifier set. */ |
88cb0656 JB |
4101 | abort (); |
4102 | ||
88cb0656 | 4103 | { |
7b4aedb9 | 4104 | /* Get the symbol we should use for the mouse click. */ |
9b8eb840 KH |
4105 | Lisp_Object head; |
4106 | ||
4107 | head = modify_event_symbol (button, | |
4108 | event->modifiers, | |
4109 | Qmouse_click, Qnil, | |
4110 | lispy_mouse_names, &mouse_syms, | |
4111 | (sizeof (lispy_mouse_names) | |
4112 | / sizeof (lispy_mouse_names[0]))); | |
88cb0656 | 4113 | if (event->modifiers & drag_modifier) |
dbc4e1c1 JB |
4114 | return Fcons (head, |
4115 | Fcons (start_pos, | |
4116 | Fcons (position, | |
4117 | Qnil))); | |
fbcd35bd JB |
4118 | else if (event->modifiers & (double_modifier | triple_modifier)) |
4119 | return Fcons (head, | |
4120 | Fcons (position, | |
4121 | Fcons (make_number (double_click_count), | |
4122 | Qnil))); | |
88cb0656 JB |
4123 | else |
4124 | return Fcons (head, | |
7b4aedb9 | 4125 | Fcons (position, |
88cb0656 JB |
4126 | Qnil)); |
4127 | } | |
284f4730 | 4128 | } |
db08707d RS |
4129 | |
4130 | #ifdef WINDOWSNT | |
fbd6baed | 4131 | case w32_scroll_bar_click: |
db08707d RS |
4132 | { |
4133 | int button = event->code; | |
4134 | int is_double; | |
4135 | Lisp_Object position; | |
4136 | Lisp_Object *start_pos_ptr; | |
4137 | Lisp_Object start_pos; | |
4138 | ||
4139 | if (button < 0 || button >= NUM_MOUSE_BUTTONS) | |
4140 | abort (); | |
4141 | ||
4142 | { | |
4143 | Lisp_Object window; | |
4144 | Lisp_Object portion_whole; | |
4145 | Lisp_Object part; | |
4146 | ||
4147 | window = event->frame_or_window; | |
4148 | portion_whole = Fcons (event->x, event->y); | |
4149 | part = *scroll_bar_parts[(int) event->part]; | |
4150 | ||
e8886a1d RS |
4151 | position |
4152 | = Fcons (window, | |
4153 | Fcons (Qvertical_scroll_bar, | |
4154 | Fcons (portion_whole, | |
4155 | Fcons (make_number (event->timestamp), | |
4156 | Fcons (part, Qnil))))); | |
db08707d RS |
4157 | } |
4158 | ||
fbd6baed | 4159 | /* Always treat W32 scroll bar events as clicks. */ |
db08707d RS |
4160 | event->modifiers |= click_modifier; |
4161 | ||
4162 | { | |
4163 | /* Get the symbol we should use for the mouse click. */ | |
4164 | Lisp_Object head; | |
4165 | ||
4166 | head = modify_event_symbol (button, | |
4167 | event->modifiers, | |
4168 | Qmouse_click, Qnil, | |
4169 | lispy_mouse_names, &mouse_syms, | |
4170 | (sizeof (lispy_mouse_names) | |
4171 | / sizeof (lispy_mouse_names[0]))); | |
4172 | return Fcons (head, | |
4173 | Fcons (position, | |
4174 | Qnil)); | |
4175 | } | |
4176 | } | |
07de30b9 GV |
4177 | case mouse_wheel: |
4178 | { | |
4179 | int part; | |
4180 | FRAME_PTR f = XFRAME (event->frame_or_window); | |
4181 | Lisp_Object window; | |
4182 | Lisp_Object posn; | |
4183 | Lisp_Object head, position; | |
4184 | int row, column; | |
4185 | ||
4186 | /* Ignore mouse events that were made on frame that | |
4187 | have been deleted. */ | |
4188 | if (! FRAME_LIVE_P (f)) | |
4189 | return Qnil; | |
4190 | pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), | |
4191 | &column, &row, NULL, 1); | |
4192 | window = window_from_coordinates (f, column, row, &part); | |
4193 | ||
4194 | if (!WINDOWP (window)) | |
4195 | { | |
4196 | window = event->frame_or_window; | |
4197 | posn = Qnil; | |
4198 | } | |
4199 | else | |
4200 | { | |
4201 | int pixcolumn, pixrow; | |
4202 | column -= XINT (XWINDOW (window)->left); | |
4203 | row -= XINT (XWINDOW (window)->top); | |
4204 | glyph_to_pixel_coords (f, column, row, &pixcolumn, &pixrow); | |
4205 | XSETINT (event->x, pixcolumn); | |
4206 | XSETINT (event->y, pixrow); | |
4207 | ||
4208 | if (part == 1) | |
4209 | posn = Qmode_line; | |
4210 | else if (part == 2) | |
4211 | posn = Qvertical_line; | |
4212 | else | |
4213 | XSETINT (posn, | |
4214 | buffer_posn_from_coords (XWINDOW (window), | |
4215 | column, row)); | |
4216 | } | |
db08707d | 4217 | |
07de30b9 GV |
4218 | { |
4219 | Lisp_Object head, position; | |
4220 | ||
4221 | position | |
4222 | = Fcons (window, | |
4223 | Fcons (posn, | |
4224 | Fcons (Fcons (event->x, event->y), | |
4225 | Fcons (make_number (event->timestamp), | |
4226 | Qnil)))); | |
4227 | ||
4228 | head = modify_event_symbol (0, event->modifiers, | |
4229 | Qmouse_wheel, Qnil, | |
4230 | lispy_mouse_wheel_names, | |
4231 | &mouse_wheel_syms, 1); | |
4232 | return Fcons (head, | |
4233 | Fcons (position, | |
4234 | Fcons (make_number (event->code), | |
4235 | Qnil))); | |
4236 | } | |
4237 | } | |
4238 | #endif /* WINDOWSNT */ | |
a24dc617 RS |
4239 | |
4240 | case drag_n_drop: | |
4241 | { | |
4242 | int part; | |
4243 | FRAME_PTR f; | |
4244 | Lisp_Object window; | |
4245 | Lisp_Object posn; | |
4246 | Lisp_Object head, position; | |
4247 | Lisp_Object files; | |
4248 | int row, column; | |
4249 | ||
4250 | /* The frame_or_window field should be a cons of the frame in | |
4251 | which the event occurred and a list of the filenames | |
4252 | dropped. */ | |
4253 | if (! CONSP (event->frame_or_window)) | |
4254 | abort (); | |
4255 | ||
4256 | f = XFRAME (XCONS (event->frame_or_window)->car); | |
4257 | files = XCONS (event->frame_or_window)->cdr; | |
4258 | ||
4259 | /* Ignore mouse events that were made on frames that | |
4260 | have been deleted. */ | |
4261 | if (! FRAME_LIVE_P (f)) | |
4262 | return Qnil; | |
4263 | pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y), | |
4264 | &column, &row, NULL, 1); | |
4265 | window = window_from_coordinates (f, column, row, &part); | |
4266 | ||
4267 | if (!WINDOWP (window)) | |
4268 | { | |
4269 | window = XCONS (event->frame_or_window)->car; | |
4270 | posn = Qnil; | |
4271 | } | |
4272 | else | |
4273 | { | |
4274 | int pixcolumn, pixrow; | |
4275 | column -= XINT (XWINDOW (window)->left); | |
4276 | row -= XINT (XWINDOW (window)->top); | |
4277 | glyph_to_pixel_coords (f, column, row, &pixcolumn, &pixrow); | |
4278 | XSETINT (event->x, pixcolumn); | |
4279 | XSETINT (event->y, pixrow); | |
4280 | ||
4281 | if (part == 1) | |
4282 | posn = Qmode_line; | |
4283 | else if (part == 2) | |
4284 | posn = Qvertical_line; | |
4285 | else | |
4286 | XSETINT (posn, | |
4287 | buffer_posn_from_coords (XWINDOW (window), | |
4288 | column, row)); | |
4289 | } | |
4290 | ||
4291 | { | |
4292 | Lisp_Object head, position; | |
4293 | ||
4294 | position | |
4295 | = Fcons (window, | |
4296 | Fcons (posn, | |
4297 | Fcons (Fcons (event->x, event->y), | |
4298 | Fcons (make_number (event->timestamp), | |
4299 | Qnil)))); | |
4300 | ||
4301 | head = modify_event_symbol (0, event->modifiers, | |
4302 | Qdrag_n_drop, Qnil, | |
4303 | lispy_drag_n_drop_names, | |
4304 | &drag_n_drop_syms, 1); | |
4305 | return Fcons (head, | |
4306 | Fcons (position, | |
4307 | Fcons (files, | |
4308 | Qnil))); | |
4309 | } | |
4310 | } | |
514354e9 | 4311 | #endif /* HAVE_MOUSE */ |
284f4730 | 4312 | |
e98a93eb | 4313 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
2470a66f KH |
4314 | case menu_bar_event: |
4315 | /* The event value is in the cdr of the frame_or_window slot. */ | |
4316 | if (!CONSP (event->frame_or_window)) | |
4317 | abort (); | |
4318 | return XCONS (event->frame_or_window)->cdr; | |
4319 | #endif | |
4320 | ||
284f4730 JB |
4321 | /* The 'kind' field of the event is something we don't recognize. */ |
4322 | default: | |
48e416d4 | 4323 | abort (); |
284f4730 JB |
4324 | } |
4325 | } | |
4326 | ||
514354e9 | 4327 | #ifdef HAVE_MOUSE |
6cbff1cb | 4328 | |
284f4730 | 4329 | static Lisp_Object |
7b4aedb9 | 4330 | make_lispy_movement (frame, bar_window, part, x, y, time) |
ff11dfa1 | 4331 | FRAME_PTR frame; |
7b4aedb9 | 4332 | Lisp_Object bar_window; |
3c370943 | 4333 | enum scroll_bar_part part; |
284f4730 | 4334 | Lisp_Object x, y; |
e5d77022 | 4335 | unsigned long time; |
284f4730 | 4336 | { |
3c370943 | 4337 | /* Is it a scroll bar movement? */ |
7b4aedb9 | 4338 | if (frame && ! NILP (bar_window)) |
4bb994d1 | 4339 | { |
9b8eb840 | 4340 | Lisp_Object part_sym; |
4bb994d1 | 4341 | |
9b8eb840 | 4342 | part_sym = *scroll_bar_parts[(int) part]; |
3c370943 | 4343 | return Fcons (Qscroll_bar_movement, |
7b4aedb9 | 4344 | (Fcons (Fcons (bar_window, |
3c370943 | 4345 | Fcons (Qvertical_scroll_bar, |
4bb994d1 JB |
4346 | Fcons (Fcons (x, y), |
4347 | Fcons (make_number (time), | |
cb5df6ae | 4348 | Fcons (part_sym, |
4bb994d1 JB |
4349 | Qnil))))), |
4350 | Qnil))); | |
4351 | } | |
4352 | ||
4353 | /* Or is it an ordinary mouse movement? */ | |
284f4730 JB |
4354 | else |
4355 | { | |
4bb994d1 | 4356 | int area; |
9e20143a | 4357 | Lisp_Object window; |
4bb994d1 | 4358 | Lisp_Object posn; |
9e20143a RS |
4359 | int column, row; |
4360 | ||
9e20143a | 4361 | if (frame) |
047688cb RS |
4362 | { |
4363 | /* It's in a frame; which window on that frame? */ | |
6c6a9be8 KH |
4364 | pixel_to_glyph_coords (frame, XINT (x), XINT (y), &column, &row, |
4365 | NULL, 1); | |
047688cb RS |
4366 | window = window_from_coordinates (frame, column, row, &area); |
4367 | } | |
9e20143a RS |
4368 | else |
4369 | window = Qnil; | |
4bb994d1 | 4370 | |
8c18cbfb | 4371 | if (WINDOWP (window)) |
4bb994d1 | 4372 | { |
9e20143a | 4373 | int pixcolumn, pixrow; |
c8738c33 | 4374 | column -= WINDOW_LEFT_MARGIN (XWINDOW (window)); |
9e20143a RS |
4375 | row -= XINT (XWINDOW (window)->top); |
4376 | glyph_to_pixel_coords (frame, column, row, &pixcolumn, &pixrow); | |
4377 | XSETINT (x, pixcolumn); | |
4378 | XSETINT (y, pixrow); | |
4bb994d1 JB |
4379 | |
4380 | if (area == 1) | |
4381 | posn = Qmode_line; | |
4382 | else if (area == 2) | |
4383 | posn = Qvertical_line; | |
4384 | else | |
18cd2eeb KH |
4385 | XSETINT (posn, |
4386 | buffer_posn_from_coords (XWINDOW (window), column, row)); | |
4bb994d1 | 4387 | } |
e9bf89a0 RS |
4388 | else if (frame != 0) |
4389 | { | |
18cd2eeb | 4390 | XSETFRAME (window, frame); |
e9bf89a0 RS |
4391 | posn = Qnil; |
4392 | } | |
284f4730 | 4393 | else |
4bb994d1 JB |
4394 | { |
4395 | window = Qnil; | |
4396 | posn = Qnil; | |
bb9e9bed KH |
4397 | XSETFASTINT (x, 0); |
4398 | XSETFASTINT (y, 0); | |
4bb994d1 | 4399 | } |
284f4730 | 4400 | |
4bb994d1 JB |
4401 | return Fcons (Qmouse_movement, |
4402 | Fcons (Fcons (window, | |
4403 | Fcons (posn, | |
4404 | Fcons (Fcons (x, y), | |
4405 | Fcons (make_number (time), | |
4406 | Qnil)))), | |
4407 | Qnil)); | |
4408 | } | |
284f4730 JB |
4409 | } |
4410 | ||
514354e9 | 4411 | #endif /* HAVE_MOUSE */ |
6cbff1cb | 4412 | |
cd21b839 JB |
4413 | /* Construct a switch frame event. */ |
4414 | static Lisp_Object | |
4415 | make_lispy_switch_frame (frame) | |
4416 | Lisp_Object frame; | |
4417 | { | |
4418 | return Fcons (Qswitch_frame, Fcons (frame, Qnil)); | |
4419 | } | |
0a7f1fc0 JB |
4420 | \f |
4421 | /* Manipulating modifiers. */ | |
284f4730 | 4422 | |
0a7f1fc0 | 4423 | /* Parse the name of SYMBOL, and return the set of modifiers it contains. |
284f4730 | 4424 | |
0a7f1fc0 JB |
4425 | If MODIFIER_END is non-zero, set *MODIFIER_END to the position in |
4426 | SYMBOL's name of the end of the modifiers; the string from this | |
4427 | position is the unmodified symbol name. | |
284f4730 | 4428 | |
0a7f1fc0 | 4429 | This doesn't use any caches. */ |
6da3dd3a | 4430 | |
0a7f1fc0 JB |
4431 | static int |
4432 | parse_modifiers_uncached (symbol, modifier_end) | |
284f4730 | 4433 | Lisp_Object symbol; |
0a7f1fc0 | 4434 | int *modifier_end; |
284f4730 JB |
4435 | { |
4436 | struct Lisp_String *name; | |
4437 | int i; | |
4438 | int modifiers; | |
284f4730 JB |
4439 | |
4440 | CHECK_SYMBOL (symbol, 1); | |
df0f2ba1 | 4441 | |
284f4730 JB |
4442 | modifiers = 0; |
4443 | name = XSYMBOL (symbol)->name; | |
4444 | ||
fc932ac6 | 4445 | for (i = 0; i+2 <= STRING_BYTES (name); ) |
6da3dd3a RS |
4446 | { |
4447 | int this_mod_end = 0; | |
4448 | int this_mod = 0; | |
284f4730 | 4449 | |
6da3dd3a RS |
4450 | /* See if the name continues with a modifier word. |
4451 | Check that the word appears, but don't check what follows it. | |
4452 | Set this_mod and this_mod_end to record what we find. */ | |
fce33686 | 4453 | |
6da3dd3a RS |
4454 | switch (name->data[i]) |
4455 | { | |
4456 | #define SINGLE_LETTER_MOD(BIT) \ | |
4457 | (this_mod_end = i + 1, this_mod = BIT) | |
4458 | ||
6da3dd3a RS |
4459 | case 'A': |
4460 | SINGLE_LETTER_MOD (alt_modifier); | |
4461 | break; | |
284f4730 | 4462 | |
6da3dd3a RS |
4463 | case 'C': |
4464 | SINGLE_LETTER_MOD (ctrl_modifier); | |
4465 | break; | |
284f4730 | 4466 | |
6da3dd3a RS |
4467 | case 'H': |
4468 | SINGLE_LETTER_MOD (hyper_modifier); | |
4469 | break; | |
4470 | ||
6da3dd3a RS |
4471 | case 'M': |
4472 | SINGLE_LETTER_MOD (meta_modifier); | |
4473 | break; | |
4474 | ||
6da3dd3a RS |
4475 | case 'S': |
4476 | SINGLE_LETTER_MOD (shift_modifier); | |
4477 | break; | |
4478 | ||
4479 | case 's': | |
6da3dd3a RS |
4480 | SINGLE_LETTER_MOD (super_modifier); |
4481 | break; | |
4482 | ||
0a7f1fc0 | 4483 | #undef SINGLE_LETTER_MOD |
6da3dd3a RS |
4484 | } |
4485 | ||
4486 | /* If we found no modifier, stop looking for them. */ | |
4487 | if (this_mod_end == 0) | |
4488 | break; | |
4489 | ||
4490 | /* Check there is a dash after the modifier, so that it | |
4491 | really is a modifier. */ | |
fc932ac6 RS |
4492 | if (this_mod_end >= STRING_BYTES (name) |
4493 | || name->data[this_mod_end] != '-') | |
6da3dd3a RS |
4494 | break; |
4495 | ||
4496 | /* This modifier is real; look for another. */ | |
4497 | modifiers |= this_mod; | |
4498 | i = this_mod_end + 1; | |
4499 | } | |
284f4730 | 4500 | |
0a7f1fc0 | 4501 | /* Should we include the `click' modifier? */ |
fbcd35bd JB |
4502 | if (! (modifiers & (down_modifier | drag_modifier |
4503 | | double_modifier | triple_modifier)) | |
fc932ac6 | 4504 | && i + 7 == STRING_BYTES (name) |
4bb994d1 | 4505 | && strncmp (name->data + i, "mouse-", 6) == 0 |
6569cc8d | 4506 | && ('0' <= name->data[i + 6] && name->data[i + 6] <= '9')) |
0a7f1fc0 JB |
4507 | modifiers |= click_modifier; |
4508 | ||
4509 | if (modifier_end) | |
4510 | *modifier_end = i; | |
4511 | ||
4512 | return modifiers; | |
4513 | } | |
4514 | ||
0a7f1fc0 JB |
4515 | /* Return a symbol whose name is the modifier prefixes for MODIFIERS |
4516 | prepended to the string BASE[0..BASE_LEN-1]. | |
4517 | This doesn't use any caches. */ | |
4518 | static Lisp_Object | |
301738ed | 4519 | apply_modifiers_uncached (modifiers, base, base_len, base_len_byte) |
0a7f1fc0 JB |
4520 | int modifiers; |
4521 | char *base; | |
301738ed | 4522 | int base_len, base_len_byte; |
0a7f1fc0 JB |
4523 | { |
4524 | /* Since BASE could contain nulls, we can't use intern here; we have | |
4525 | to use Fintern, which expects a genuine Lisp_String, and keeps a | |
4526 | reference to it. */ | |
301738ed RS |
4527 | char *new_mods |
4528 | = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-")); | |
0a7f1fc0 | 4529 | int mod_len; |
284f4730 | 4530 | |
284f4730 | 4531 | { |
0a7f1fc0 JB |
4532 | char *p = new_mods; |
4533 | ||
4534 | /* Only the event queue may use the `up' modifier; it should always | |
4535 | be turned into a click or drag event before presented to lisp code. */ | |
4536 | if (modifiers & up_modifier) | |
4537 | abort (); | |
4538 | ||
4539 | if (modifiers & alt_modifier) { *p++ = 'A'; *p++ = '-'; } | |
4540 | if (modifiers & ctrl_modifier) { *p++ = 'C'; *p++ = '-'; } | |
4541 | if (modifiers & hyper_modifier) { *p++ = 'H'; *p++ = '-'; } | |
4542 | if (modifiers & meta_modifier) { *p++ = 'M'; *p++ = '-'; } | |
4543 | if (modifiers & shift_modifier) { *p++ = 'S'; *p++ = '-'; } | |
86e5706b | 4544 | if (modifiers & super_modifier) { *p++ = 's'; *p++ = '-'; } |
fbcd35bd JB |
4545 | if (modifiers & double_modifier) { strcpy (p, "double-"); p += 7; } |
4546 | if (modifiers & triple_modifier) { strcpy (p, "triple-"); p += 7; } | |
559f9d04 RS |
4547 | if (modifiers & down_modifier) { strcpy (p, "down-"); p += 5; } |
4548 | if (modifiers & drag_modifier) { strcpy (p, "drag-"); p += 5; } | |
0a7f1fc0 JB |
4549 | /* The click modifier is denoted by the absence of other modifiers. */ |
4550 | ||
4551 | *p = '\0'; | |
4552 | ||
4553 | mod_len = p - new_mods; | |
4554 | } | |
284f4730 | 4555 | |
0a7f1fc0 | 4556 | { |
9b8eb840 | 4557 | Lisp_Object new_name; |
df0f2ba1 | 4558 | |
301738ed RS |
4559 | new_name = make_uninit_multibyte_string (mod_len + base_len, |
4560 | mod_len + base_len_byte); | |
0a7f1fc0 | 4561 | bcopy (new_mods, XSTRING (new_name)->data, mod_len); |
301738ed | 4562 | bcopy (base, XSTRING (new_name)->data + mod_len, base_len_byte); |
284f4730 JB |
4563 | |
4564 | return Fintern (new_name, Qnil); | |
4565 | } | |
4566 | } | |
4567 | ||
4568 | ||
0a7f1fc0 JB |
4569 | static char *modifier_names[] = |
4570 | { | |
fbcd35bd | 4571 | "up", "down", "drag", "click", "double", "triple", 0, 0, |
f335fabe | 4572 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
86e5706b | 4573 | 0, 0, "alt", "super", "hyper", "shift", "control", "meta" |
0a7f1fc0 | 4574 | }; |
80645119 | 4575 | #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0])) |
0a7f1fc0 JB |
4576 | |
4577 | static Lisp_Object modifier_symbols; | |
4578 | ||
4579 | /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */ | |
4580 | static Lisp_Object | |
4581 | lispy_modifier_list (modifiers) | |
4582 | int modifiers; | |
4583 | { | |
4584 | Lisp_Object modifier_list; | |
4585 | int i; | |
4586 | ||
4587 | modifier_list = Qnil; | |
80645119 | 4588 | for (i = 0; (1<<i) <= modifiers && i < NUM_MOD_NAMES; i++) |
0a7f1fc0 | 4589 | if (modifiers & (1<<i)) |
80645119 JB |
4590 | modifier_list = Fcons (XVECTOR (modifier_symbols)->contents[i], |
4591 | modifier_list); | |
0a7f1fc0 JB |
4592 | |
4593 | return modifier_list; | |
4594 | } | |
4595 | ||
4596 | ||
4597 | /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK), | |
4598 | where UNMODIFIED is the unmodified form of SYMBOL, | |
4599 | MASK is the set of modifiers present in SYMBOL's name. | |
4600 | This is similar to parse_modifiers_uncached, but uses the cache in | |
4601 | SYMBOL's Qevent_symbol_element_mask property, and maintains the | |
4602 | Qevent_symbol_elements property. */ | |
3d31316f | 4603 | |
0a7f1fc0 JB |
4604 | static Lisp_Object |
4605 | parse_modifiers (symbol) | |
4606 | Lisp_Object symbol; | |
4607 | { | |
9b8eb840 | 4608 | Lisp_Object elements; |
0a7f1fc0 | 4609 | |
9b8eb840 | 4610 | elements = Fget (symbol, Qevent_symbol_element_mask); |
0a7f1fc0 JB |
4611 | if (CONSP (elements)) |
4612 | return elements; | |
4613 | else | |
4614 | { | |
4615 | int end; | |
ec0faad2 | 4616 | int modifiers = parse_modifiers_uncached (symbol, &end); |
9b8eb840 | 4617 | Lisp_Object unmodified; |
0a7f1fc0 JB |
4618 | Lisp_Object mask; |
4619 | ||
9b8eb840 | 4620 | unmodified = Fintern (make_string (XSYMBOL (symbol)->name->data + end, |
fc932ac6 | 4621 | STRING_BYTES (XSYMBOL (symbol)->name) - end), |
9b8eb840 KH |
4622 | Qnil); |
4623 | ||
ec0faad2 | 4624 | if (modifiers & ~(((EMACS_INT)1 << VALBITS) - 1)) |
734fef94 | 4625 | abort (); |
bb9e9bed | 4626 | XSETFASTINT (mask, modifiers); |
0a7f1fc0 JB |
4627 | elements = Fcons (unmodified, Fcons (mask, Qnil)); |
4628 | ||
4629 | /* Cache the parsing results on SYMBOL. */ | |
4630 | Fput (symbol, Qevent_symbol_element_mask, | |
4631 | elements); | |
4632 | Fput (symbol, Qevent_symbol_elements, | |
4633 | Fcons (unmodified, lispy_modifier_list (modifiers))); | |
4634 | ||
4635 | /* Since we know that SYMBOL is modifiers applied to unmodified, | |
4636 | it would be nice to put that in unmodified's cache. | |
4637 | But we can't, since we're not sure that parse_modifiers is | |
4638 | canonical. */ | |
4639 | ||
4640 | return elements; | |
4641 | } | |
4642 | } | |
4643 | ||
4644 | /* Apply the modifiers MODIFIERS to the symbol BASE. | |
4645 | BASE must be unmodified. | |
4646 | ||
4647 | This is like apply_modifiers_uncached, but uses BASE's | |
4648 | Qmodifier_cache property, if present. It also builds | |
cd21b839 JB |
4649 | Qevent_symbol_elements properties, since it has that info anyway. |
4650 | ||
4651 | apply_modifiers copies the value of BASE's Qevent_kind property to | |
4652 | the modified symbol. */ | |
0a7f1fc0 JB |
4653 | static Lisp_Object |
4654 | apply_modifiers (modifiers, base) | |
4655 | int modifiers; | |
4656 | Lisp_Object base; | |
4657 | { | |
7b4aedb9 | 4658 | Lisp_Object cache, index, entry, new_symbol; |
0a7f1fc0 | 4659 | |
80645119 | 4660 | /* Mask out upper bits. We don't know where this value's been. */ |
ec0faad2 | 4661 | modifiers &= ((EMACS_INT)1 << VALBITS) - 1; |
80645119 | 4662 | |
0a7f1fc0 | 4663 | /* The click modifier never figures into cache indices. */ |
0a7f1fc0 | 4664 | cache = Fget (base, Qmodifier_cache); |
bb9e9bed | 4665 | XSETFASTINT (index, (modifiers & ~click_modifier)); |
697e4895 | 4666 | entry = assq_no_quit (index, cache); |
0a7f1fc0 JB |
4667 | |
4668 | if (CONSP (entry)) | |
7b4aedb9 JB |
4669 | new_symbol = XCONS (entry)->cdr; |
4670 | else | |
4671 | { | |
df0f2ba1 | 4672 | /* We have to create the symbol ourselves. */ |
7b4aedb9 JB |
4673 | new_symbol = apply_modifiers_uncached (modifiers, |
4674 | XSYMBOL (base)->name->data, | |
301738ed | 4675 | XSYMBOL (base)->name->size, |
fc932ac6 | 4676 | STRING_BYTES (XSYMBOL (base)->name)); |
7b4aedb9 JB |
4677 | |
4678 | /* Add the new symbol to the base's cache. */ | |
4679 | entry = Fcons (index, new_symbol); | |
4680 | Fput (base, Qmodifier_cache, Fcons (entry, cache)); | |
4681 | ||
4682 | /* We have the parsing info now for free, so add it to the caches. */ | |
bb9e9bed | 4683 | XSETFASTINT (index, modifiers); |
7b4aedb9 JB |
4684 | Fput (new_symbol, Qevent_symbol_element_mask, |
4685 | Fcons (base, Fcons (index, Qnil))); | |
4686 | Fput (new_symbol, Qevent_symbol_elements, | |
4687 | Fcons (base, lispy_modifier_list (modifiers))); | |
4688 | } | |
0a7f1fc0 | 4689 | |
df0f2ba1 | 4690 | /* Make sure this symbol is of the same kind as BASE. |
7b4aedb9 JB |
4691 | |
4692 | You'd think we could just set this once and for all when we | |
4693 | intern the symbol above, but reorder_modifiers may call us when | |
4694 | BASE's property isn't set right; we can't assume that just | |
80645119 JB |
4695 | because it has a Qmodifier_cache property it must have its |
4696 | Qevent_kind set right as well. */ | |
7b4aedb9 JB |
4697 | if (NILP (Fget (new_symbol, Qevent_kind))) |
4698 | { | |
9b8eb840 | 4699 | Lisp_Object kind; |
7b4aedb9 | 4700 | |
9b8eb840 | 4701 | kind = Fget (base, Qevent_kind); |
7b4aedb9 JB |
4702 | if (! NILP (kind)) |
4703 | Fput (new_symbol, Qevent_kind, kind); | |
4704 | } | |
4705 | ||
4706 | return new_symbol; | |
0a7f1fc0 JB |
4707 | } |
4708 | ||
4709 | ||
4710 | /* Given a symbol whose name begins with modifiers ("C-", "M-", etc), | |
4711 | return a symbol with the modifiers placed in the canonical order. | |
4712 | Canonical order is alphabetical, except for down and drag, which | |
4713 | always come last. The 'click' modifier is never written out. | |
4714 | ||
4715 | Fdefine_key calls this to make sure that (for example) C-M-foo | |
4716 | and M-C-foo end up being equivalent in the keymap. */ | |
4717 | ||
4718 | Lisp_Object | |
4719 | reorder_modifiers (symbol) | |
4720 | Lisp_Object symbol; | |
4721 | { | |
4722 | /* It's hopefully okay to write the code this way, since everything | |
4723 | will soon be in caches, and no consing will be done at all. */ | |
9b8eb840 | 4724 | Lisp_Object parsed; |
0a7f1fc0 | 4725 | |
9b8eb840 | 4726 | parsed = parse_modifiers (symbol); |
54593ed9 | 4727 | return apply_modifiers ((int) XINT (XCONS (XCONS (parsed)->cdr)->car), |
0a7f1fc0 JB |
4728 | XCONS (parsed)->car); |
4729 | } | |
4730 | ||
4731 | ||
284f4730 JB |
4732 | /* For handling events, we often want to produce a symbol whose name |
4733 | is a series of modifier key prefixes ("M-", "C-", etcetera) attached | |
4734 | to some base, like the name of a function key or mouse button. | |
4735 | modify_event_symbol produces symbols of this sort. | |
4736 | ||
4737 | NAME_TABLE should point to an array of strings, such that NAME_TABLE[i] | |
4738 | is the name of the i'th symbol. TABLE_SIZE is the number of elements | |
4739 | in the table. | |
4740 | ||
80e4aa30 RS |
4741 | Alternatively, NAME_ALIST is an alist mapping codes into symbol names. |
4742 | NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used. | |
4743 | ||
284f4730 JB |
4744 | SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will |
4745 | persist between calls to modify_event_symbol that it can use to | |
4746 | store a cache of the symbols it's generated for this NAME_TABLE | |
80e4aa30 | 4747 | before. The object stored there may be a vector or an alist. |
284f4730 JB |
4748 | |
4749 | SYMBOL_NUM is the number of the base name we want from NAME_TABLE. | |
df0f2ba1 | 4750 | |
284f4730 JB |
4751 | MODIFIERS is a set of modifier bits (as given in struct input_events) |
4752 | whose prefixes should be applied to the symbol name. | |
4753 | ||
4754 | SYMBOL_KIND is the value to be placed in the event_kind property of | |
df0f2ba1 | 4755 | the returned symbol. |
88cb0656 JB |
4756 | |
4757 | The symbols we create are supposed to have an | |
eb8c3be9 | 4758 | `event-symbol-elements' property, which lists the modifiers present |
88cb0656 JB |
4759 | in the symbol's name. */ |
4760 | ||
284f4730 | 4761 | static Lisp_Object |
80e4aa30 RS |
4762 | modify_event_symbol (symbol_num, modifiers, symbol_kind, name_alist, |
4763 | name_table, symbol_table, table_size) | |
284f4730 JB |
4764 | int symbol_num; |
4765 | unsigned modifiers; | |
4766 | Lisp_Object symbol_kind; | |
80e4aa30 | 4767 | Lisp_Object name_alist; |
284f4730 JB |
4768 | char **name_table; |
4769 | Lisp_Object *symbol_table; | |
2c834fb3 | 4770 | unsigned int table_size; |
284f4730 | 4771 | { |
80e4aa30 RS |
4772 | Lisp_Object value; |
4773 | Lisp_Object symbol_int; | |
4774 | ||
2c834fb3 KH |
4775 | /* Get rid of the "vendor-specific" bit here. */ |
4776 | XSETINT (symbol_int, symbol_num & 0xffffff); | |
284f4730 JB |
4777 | |
4778 | /* Is this a request for a valid symbol? */ | |
88cb0656 | 4779 | if (symbol_num < 0 || symbol_num >= table_size) |
0c2611c5 | 4780 | return Qnil; |
284f4730 | 4781 | |
80e4aa30 RS |
4782 | if (CONSP (*symbol_table)) |
4783 | value = Fcdr (assq_no_quit (symbol_int, *symbol_table)); | |
4784 | ||
0a7f1fc0 | 4785 | /* If *symbol_table doesn't seem to be initialized properly, fix that. |
88cb0656 | 4786 | *symbol_table should be a lisp vector TABLE_SIZE elements long, |
4bb994d1 JB |
4787 | where the Nth element is the symbol for NAME_TABLE[N], or nil if |
4788 | we've never used that symbol before. */ | |
80e4aa30 | 4789 | else |
88cb0656 | 4790 | { |
80e4aa30 RS |
4791 | if (! VECTORP (*symbol_table) |
4792 | || XVECTOR (*symbol_table)->size != table_size) | |
4793 | { | |
4794 | Lisp_Object size; | |
0a7f1fc0 | 4795 | |
bb9e9bed | 4796 | XSETFASTINT (size, table_size); |
80e4aa30 RS |
4797 | *symbol_table = Fmake_vector (size, Qnil); |
4798 | } | |
284f4730 | 4799 | |
80e4aa30 RS |
4800 | value = XVECTOR (*symbol_table)->contents[symbol_num]; |
4801 | } | |
284f4730 | 4802 | |
0a7f1fc0 | 4803 | /* Have we already used this symbol before? */ |
80e4aa30 | 4804 | if (NILP (value)) |
284f4730 | 4805 | { |
0a7f1fc0 | 4806 | /* No; let's create it. */ |
80e4aa30 | 4807 | if (!NILP (name_alist)) |
b64b4075 | 4808 | value = Fcdr_safe (Fassq (symbol_int, name_alist)); |
2ff6714d | 4809 | else if (name_table != 0 && name_table[symbol_num]) |
80e4aa30 | 4810 | value = intern (name_table[symbol_num]); |
b64b4075 | 4811 | |
e98a93eb | 4812 | #ifdef HAVE_WINDOW_SYSTEM |
2c834fb3 KH |
4813 | if (NILP (value)) |
4814 | { | |
4815 | char *name = x_get_keysym_name (symbol_num); | |
4816 | if (name) | |
4817 | value = intern (name); | |
4818 | } | |
4819 | #endif | |
4820 | ||
b64b4075 | 4821 | if (NILP (value)) |
d1f50460 RS |
4822 | { |
4823 | char buf[20]; | |
4824 | sprintf (buf, "key-%d", symbol_num); | |
80e4aa30 | 4825 | value = intern (buf); |
d1f50460 | 4826 | } |
0a7f1fc0 | 4827 | |
80e4aa30 | 4828 | if (CONSP (*symbol_table)) |
4205cb08 | 4829 | *symbol_table = Fcons (Fcons (symbol_int, value), *symbol_table); |
80e4aa30 RS |
4830 | else |
4831 | XVECTOR (*symbol_table)->contents[symbol_num] = value; | |
4832 | ||
df0f2ba1 | 4833 | /* Fill in the cache entries for this symbol; this also |
0a7f1fc0 JB |
4834 | builds the Qevent_symbol_elements property, which the user |
4835 | cares about. */ | |
80e4aa30 RS |
4836 | apply_modifiers (modifiers & click_modifier, value); |
4837 | Fput (value, Qevent_kind, symbol_kind); | |
284f4730 | 4838 | } |
88cb0656 | 4839 | |
0a7f1fc0 | 4840 | /* Apply modifiers to that symbol. */ |
80e4aa30 | 4841 | return apply_modifiers (modifiers, value); |
284f4730 | 4842 | } |
6da3dd3a RS |
4843 | \f |
4844 | /* Convert a list that represents an event type, | |
4845 | such as (ctrl meta backspace), into the usual representation of that | |
4846 | event type as a number or a symbol. */ | |
4847 | ||
a1706c30 | 4848 | DEFUN ("event-convert-list", Fevent_convert_list, Sevent_convert_list, 1, 1, 0, |
e57d8fd8 EN |
4849 | "Convert the event description list EVENT-DESC to an event type.\n\ |
4850 | EVENT-DESC should contain one base event type (a character or symbol)\n\ | |
a1706c30 | 4851 | and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\ |
377f24f5 | 4852 | drag, down, double or triple). The base must be last.\n\ |
a1706c30 KH |
4853 | The return value is an event type (a character or symbol) which\n\ |
4854 | has the same base event type and all the specified modifiers.") | |
e57d8fd8 EN |
4855 | (event_desc) |
4856 | Lisp_Object event_desc; | |
6da3dd3a RS |
4857 | { |
4858 | Lisp_Object base; | |
4859 | int modifiers = 0; | |
4860 | Lisp_Object rest; | |
4861 | ||
4862 | base = Qnil; | |
e57d8fd8 | 4863 | rest = event_desc; |
6da3dd3a RS |
4864 | while (CONSP (rest)) |
4865 | { | |
4866 | Lisp_Object elt; | |
4867 | int this = 0; | |
4868 | ||
4869 | elt = XCONS (rest)->car; | |
377f24f5 | 4870 | rest = XCONS (rest)->cdr; |
6da3dd3a | 4871 | |
3d31316f | 4872 | /* Given a symbol, see if it is a modifier name. */ |
377f24f5 | 4873 | if (SYMBOLP (elt) && CONSP (rest)) |
3d31316f | 4874 | this = parse_solitary_modifier (elt); |
6da3dd3a RS |
4875 | |
4876 | if (this != 0) | |
4877 | modifiers |= this; | |
4878 | else if (!NILP (base)) | |
4879 | error ("Two bases given in one event"); | |
4880 | else | |
4881 | base = elt; | |
4882 | ||
6da3dd3a RS |
4883 | } |
4884 | ||
3d31316f RS |
4885 | /* Let the symbol A refer to the character A. */ |
4886 | if (SYMBOLP (base) && XSYMBOL (base)->name->size == 1) | |
4887 | XSETINT (base, XSYMBOL (base)->name->data[0]); | |
4888 | ||
6da3dd3a RS |
4889 | if (INTEGERP (base)) |
4890 | { | |
3d31316f RS |
4891 | /* Turn (shift a) into A. */ |
4892 | if ((modifiers & shift_modifier) != 0 | |
4893 | && (XINT (base) >= 'a' && XINT (base) <= 'z')) | |
4894 | { | |
4895 | XSETINT (base, XINT (base) - ('a' - 'A')); | |
4896 | modifiers &= ~shift_modifier; | |
4897 | } | |
4898 | ||
4899 | /* Turn (control a) into C-a. */ | |
6da3dd3a | 4900 | if (modifiers & ctrl_modifier) |
3d31316f | 4901 | return make_number ((modifiers & ~ctrl_modifier) |
6da3dd3a RS |
4902 | | make_ctrl_char (XINT (base))); |
4903 | else | |
4904 | return make_number (modifiers | XINT (base)); | |
4905 | } | |
4906 | else if (SYMBOLP (base)) | |
4907 | return apply_modifiers (modifiers, base); | |
4908 | else | |
4909 | error ("Invalid base event"); | |
4910 | } | |
4911 | ||
3d31316f RS |
4912 | /* Try to recognize SYMBOL as a modifier name. |
4913 | Return the modifier flag bit, or 0 if not recognized. */ | |
4914 | ||
4915 | static int | |
4916 | parse_solitary_modifier (symbol) | |
4917 | Lisp_Object symbol; | |
4918 | { | |
4919 | struct Lisp_String *name = XSYMBOL (symbol)->name; | |
4920 | ||
4921 | switch (name->data[0]) | |
4922 | { | |
4923 | #define SINGLE_LETTER_MOD(BIT) \ | |
fc932ac6 | 4924 | if (STRING_BYTES (name) == 1) \ |
3d31316f RS |
4925 | return BIT; |
4926 | ||
4927 | #define MULTI_LETTER_MOD(BIT, NAME, LEN) \ | |
fc932ac6 | 4928 | if (LEN == STRING_BYTES (name) \ |
3d31316f RS |
4929 | && ! strncmp (name->data, NAME, LEN)) \ |
4930 | return BIT; | |
4931 | ||
4932 | case 'A': | |
4933 | SINGLE_LETTER_MOD (alt_modifier); | |
4934 | break; | |
4935 | ||
4936 | case 'a': | |
4937 | MULTI_LETTER_MOD (alt_modifier, "alt", 3); | |
4938 | break; | |
4939 | ||
4940 | case 'C': | |
4941 | SINGLE_LETTER_MOD (ctrl_modifier); | |
4942 | break; | |
4943 | ||
4944 | case 'c': | |
4945 | MULTI_LETTER_MOD (ctrl_modifier, "ctrl", 4); | |
4946 | MULTI_LETTER_MOD (ctrl_modifier, "control", 7); | |
4947 | break; | |
4948 | ||
4949 | case 'H': | |
4950 | SINGLE_LETTER_MOD (hyper_modifier); | |
4951 | break; | |
4952 | ||
4953 | case 'h': | |
4954 | MULTI_LETTER_MOD (hyper_modifier, "hyper", 5); | |
4955 | break; | |
4956 | ||
4957 | case 'M': | |
4958 | SINGLE_LETTER_MOD (meta_modifier); | |
4959 | break; | |
4960 | ||
4961 | case 'm': | |
4962 | MULTI_LETTER_MOD (meta_modifier, "meta", 4); | |
4963 | break; | |
4964 | ||
4965 | case 'S': | |
4966 | SINGLE_LETTER_MOD (shift_modifier); | |
4967 | break; | |
4968 | ||
4969 | case 's': | |
4970 | MULTI_LETTER_MOD (shift_modifier, "shift", 5); | |
4971 | MULTI_LETTER_MOD (super_modifier, "super", 5); | |
4972 | SINGLE_LETTER_MOD (super_modifier); | |
4973 | break; | |
4974 | ||
4975 | case 'd': | |
4976 | MULTI_LETTER_MOD (drag_modifier, "drag", 4); | |
4977 | MULTI_LETTER_MOD (down_modifier, "down", 4); | |
4978 | MULTI_LETTER_MOD (double_modifier, "double", 6); | |
4979 | break; | |
4980 | ||
4981 | case 't': | |
4982 | MULTI_LETTER_MOD (triple_modifier, "triple", 6); | |
4983 | break; | |
4984 | ||
4985 | #undef SINGLE_LETTER_MOD | |
4986 | #undef MULTI_LETTER_MOD | |
4987 | } | |
4988 | ||
4989 | return 0; | |
4990 | } | |
4991 | ||
6da3dd3a RS |
4992 | /* Return 1 if EVENT is a list whose elements are all integers or symbols. |
4993 | Such a list is not valid as an event, | |
4994 | but it can be a Lucid-style event type list. */ | |
4995 | ||
4996 | int | |
4997 | lucid_event_type_list_p (object) | |
4998 | Lisp_Object object; | |
4999 | { | |
5000 | Lisp_Object tail; | |
5001 | ||
5002 | if (! CONSP (object)) | |
5003 | return 0; | |
5004 | ||
5005 | for (tail = object; CONSP (tail); tail = XCONS (tail)->cdr) | |
5006 | { | |
5007 | Lisp_Object elt; | |
5008 | elt = XCONS (tail)->car; | |
5009 | if (! (INTEGERP (elt) || SYMBOLP (elt))) | |
5010 | return 0; | |
5011 | } | |
5012 | ||
5013 | return NILP (tail); | |
5014 | } | |
284f4730 | 5015 | \f |
284f4730 JB |
5016 | /* Store into *addr a value nonzero if terminal input chars are available. |
5017 | Serves the purpose of ioctl (0, FIONREAD, addr) | |
5018 | but works even if FIONREAD does not exist. | |
d9d4c147 KH |
5019 | (In fact, this may actually read some input.) |
5020 | ||
5021 | If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */ | |
284f4730 JB |
5022 | |
5023 | static void | |
d9d4c147 | 5024 | get_input_pending (addr, do_timers_now) |
284f4730 | 5025 | int *addr; |
d9d4c147 | 5026 | int do_timers_now; |
284f4730 JB |
5027 | { |
5028 | /* First of all, have we already counted some input? */ | |
d9d4c147 | 5029 | *addr = !NILP (Vquit_flag) || readable_events (do_timers_now); |
284f4730 JB |
5030 | |
5031 | /* If input is being read as it arrives, and we have none, there is none. */ | |
5032 | if (*addr > 0 || (interrupt_input && ! interrupts_deferred)) | |
5033 | return; | |
5034 | ||
5035 | /* Try to read some input and see how much we get. */ | |
5036 | gobble_input (0); | |
d9d4c147 | 5037 | *addr = !NILP (Vquit_flag) || readable_events (do_timers_now); |
284f4730 JB |
5038 | } |
5039 | ||
81931ba1 | 5040 | /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */ |
284f4730 | 5041 | |
07a59269 | 5042 | void |
284f4730 JB |
5043 | gobble_input (expected) |
5044 | int expected; | |
5045 | { | |
5046 | #ifndef VMS | |
5047 | #ifdef SIGIO | |
5048 | if (interrupt_input) | |
5049 | { | |
32676c08 | 5050 | SIGMASKTYPE mask; |
4f8aaa74 | 5051 | mask = sigblock (sigmask (SIGIO)); |
284f4730 | 5052 | read_avail_input (expected); |
e065a56e | 5053 | sigsetmask (mask); |
284f4730 JB |
5054 | } |
5055 | else | |
81931ba1 RS |
5056 | #ifdef POLL_FOR_INPUT |
5057 | if (read_socket_hook && !interrupt_input && poll_suppress_count == 0) | |
5058 | { | |
5059 | SIGMASKTYPE mask; | |
4f8aaa74 | 5060 | mask = sigblock (sigmask (SIGALRM)); |
81931ba1 RS |
5061 | read_avail_input (expected); |
5062 | sigsetmask (mask); | |
5063 | } | |
5064 | else | |
87485d6f | 5065 | #endif |
284f4730 JB |
5066 | #endif |
5067 | read_avail_input (expected); | |
5068 | #endif | |
5069 | } | |
a8015ab5 | 5070 | |
241ceaf7 RS |
5071 | /* Put a buffer_switch_event in the buffer |
5072 | so that read_key_sequence will notice the new current buffer. */ | |
5073 | ||
07a59269 | 5074 | void |
a8015ab5 KH |
5075 | record_asynch_buffer_change () |
5076 | { | |
5077 | struct input_event event; | |
a30f0615 RS |
5078 | Lisp_Object tem; |
5079 | ||
a8015ab5 KH |
5080 | event.kind = buffer_switch_event; |
5081 | event.frame_or_window = Qnil; | |
241ceaf7 | 5082 | |
f65e6f7d | 5083 | #ifdef subprocesses |
a30f0615 RS |
5084 | /* We don't need a buffer-switch event unless Emacs is waiting for input. |
5085 | The purpose of the event is to make read_key_sequence look up the | |
5086 | keymaps again. If we aren't in read_key_sequence, we don't need one, | |
5087 | and the event could cause trouble by messing up (input-pending-p). */ | |
5088 | tem = Fwaiting_for_user_input_p (); | |
5089 | if (NILP (tem)) | |
5090 | return; | |
f65e6f7d RS |
5091 | #else |
5092 | /* We never need these events if we have no asynchronous subprocesses. */ | |
5093 | return; | |
5094 | #endif | |
a30f0615 | 5095 | |
241ceaf7 RS |
5096 | /* Make sure no interrupt happens while storing the event. */ |
5097 | #ifdef SIGIO | |
5098 | if (interrupt_input) | |
5099 | { | |
5100 | SIGMASKTYPE mask; | |
4f8aaa74 | 5101 | mask = sigblock (sigmask (SIGIO)); |
241ceaf7 RS |
5102 | kbd_buffer_store_event (&event); |
5103 | sigsetmask (mask); | |
5104 | } | |
5105 | else | |
5106 | #endif | |
5107 | { | |
5108 | stop_polling (); | |
5109 | kbd_buffer_store_event (&event); | |
5110 | start_polling (); | |
5111 | } | |
a8015ab5 | 5112 | } |
284f4730 JB |
5113 | \f |
5114 | #ifndef VMS | |
5115 | ||
5116 | /* Read any terminal input already buffered up by the system | |
5117 | into the kbd_buffer, but do not wait. | |
5118 | ||
5119 | EXPECTED should be nonzero if the caller knows there is some input. | |
5120 | ||
5121 | Except on VMS, all input is read by this function. | |
5122 | If interrupt_input is nonzero, this function MUST be called | |
5123 | only when SIGIO is blocked. | |
5124 | ||
5125 | Returns the number of keyboard chars read, or -1 meaning | |
5126 | this is a bad time to try to read input. */ | |
5127 | ||
5128 | static int | |
5129 | read_avail_input (expected) | |
5130 | int expected; | |
5131 | { | |
5132 | struct input_event buf[KBD_BUFFER_SIZE]; | |
5133 | register int i; | |
5134 | int nread; | |
5135 | ||
5136 | if (read_socket_hook) | |
5137 | /* No need for FIONREAD or fcntl; just say don't wait. */ | |
33e19c6e | 5138 | nread = (*read_socket_hook) (input_fd, buf, KBD_BUFFER_SIZE, expected); |
284f4730 JB |
5139 | else |
5140 | { | |
17270835 RS |
5141 | /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than |
5142 | the kbd_buffer can really hold. That may prevent loss | |
5143 | of characters on some systems when input is stuffed at us. */ | |
5144 | unsigned char cbuf[KBD_BUFFER_SIZE - 1]; | |
58788063 | 5145 | int n_to_read; |
284f4730 | 5146 | |
58788063 | 5147 | /* Determine how many characters we should *try* to read. */ |
bc536d84 RS |
5148 | #ifdef WINDOWSNT |
5149 | return 0; | |
5150 | #else /* not WINDOWSNT */ | |
80e4aa30 | 5151 | #ifdef MSDOS |
58788063 RS |
5152 | n_to_read = dos_keysns (); |
5153 | if (n_to_read == 0) | |
5154 | return 0; | |
c3a2738c | 5155 | #else /* not MSDOS */ |
284f4730 JB |
5156 | #ifdef FIONREAD |
5157 | /* Find out how much input is available. */ | |
437f6112 | 5158 | if (ioctl (input_fd, FIONREAD, &n_to_read) < 0) |
284f4730 JB |
5159 | /* Formerly simply reported no input, but that sometimes led to |
5160 | a failure of Emacs to terminate. | |
5161 | SIGHUP seems appropriate if we can't reach the terminal. */ | |
e4535288 RS |
5162 | /* ??? Is it really right to send the signal just to this process |
5163 | rather than to the whole process group? | |
5164 | Perhaps on systems with FIONREAD Emacs is alone in its group. */ | |
284f4730 | 5165 | kill (getpid (), SIGHUP); |
58788063 | 5166 | if (n_to_read == 0) |
284f4730 | 5167 | return 0; |
58788063 RS |
5168 | if (n_to_read > sizeof cbuf) |
5169 | n_to_read = sizeof cbuf; | |
284f4730 | 5170 | #else /* no FIONREAD */ |
0c04a67e | 5171 | #if defined (USG) || defined (DGUX) |
284f4730 | 5172 | /* Read some input if available, but don't wait. */ |
58788063 | 5173 | n_to_read = sizeof cbuf; |
437f6112 | 5174 | fcntl (input_fd, F_SETFL, O_NDELAY); |
284f4730 JB |
5175 | #else |
5176 | you lose; | |
5177 | #endif | |
5178 | #endif | |
80e4aa30 | 5179 | #endif /* not MSDOS */ |
bc536d84 | 5180 | #endif /* not WINDOWSNT */ |
284f4730 | 5181 | |
58788063 RS |
5182 | /* Now read; for one reason or another, this will not block. |
5183 | NREAD is set to the number of chars read. */ | |
9134775b | 5184 | do |
284f4730 | 5185 | { |
80e4aa30 | 5186 | #ifdef MSDOS |
0c04a67e | 5187 | cbuf[0] = dos_keyread (); |
80e4aa30 RS |
5188 | nread = 1; |
5189 | #else | |
437f6112 | 5190 | nread = read (input_fd, cbuf, n_to_read); |
80e4aa30 | 5191 | #endif |
49854566 RS |
5192 | /* POSIX infers that processes which are not in the session leader's |
5193 | process group won't get SIGHUP's at logout time. BSDI adheres to | |
e8886a1d | 5194 | this part standard and returns -1 from read (0) with errno==EIO |
49854566 RS |
5195 | when the control tty is taken away. |
5196 | Jeffrey Honig <jch@bsdi.com> says this is generally safe. */ | |
5197 | if (nread == -1 && errno == EIO) | |
5198 | kill (0, SIGHUP); | |
762f2b92 | 5199 | #if defined (AIX) && (! defined (aix386) && defined (_BSD)) |
284f4730 JB |
5200 | /* The kernel sometimes fails to deliver SIGHUP for ptys. |
5201 | This looks incorrect, but it isn't, because _BSD causes | |
5202 | O_NDELAY to be defined in fcntl.h as O_NONBLOCK, | |
5203 | and that causes a value other than 0 when there is no input. */ | |
854f3a54 | 5204 | if (nread == 0) |
80e4aa30 | 5205 | kill (0, SIGHUP); |
284f4730 | 5206 | #endif |
9134775b | 5207 | } |
791587ee KH |
5208 | while ( |
5209 | /* We used to retry the read if it was interrupted. | |
5210 | But this does the wrong thing when O_NDELAY causes | |
5211 | an EAGAIN error. Does anybody know of a situation | |
5212 | where a retry is actually needed? */ | |
5213 | #if 0 | |
5214 | nread < 0 && (errno == EAGAIN | |
6aec06f5 | 5215 | #ifdef EFAULT |
9134775b | 5216 | || errno == EFAULT |
80e4aa30 | 5217 | #endif |
284f4730 | 5218 | #ifdef EBADSLT |
9134775b | 5219 | || errno == EBADSLT |
284f4730 | 5220 | #endif |
791587ee KH |
5221 | ) |
5222 | #else | |
5223 | 0 | |
5224 | #endif | |
5225 | ); | |
284f4730 JB |
5226 | |
5227 | #ifndef FIONREAD | |
02c2c53f | 5228 | #if defined (USG) || defined (DGUX) |
437f6112 | 5229 | fcntl (input_fd, F_SETFL, 0); |
02c2c53f | 5230 | #endif /* USG or DGUX */ |
284f4730 JB |
5231 | #endif /* no FIONREAD */ |
5232 | for (i = 0; i < nread; i++) | |
5233 | { | |
5234 | buf[i].kind = ascii_keystroke; | |
86e5706b | 5235 | buf[i].modifiers = 0; |
b04904fb | 5236 | if (meta_key == 1 && (cbuf[i] & 0x80)) |
86e5706b | 5237 | buf[i].modifiers = meta_modifier; |
b04904fb RS |
5238 | if (meta_key != 2) |
5239 | cbuf[i] &= ~0x80; | |
f3e59d5e KH |
5240 | |
5241 | buf[i].code = cbuf[i]; | |
18cd2eeb | 5242 | XSETFRAME (buf[i].frame_or_window, selected_frame); |
284f4730 JB |
5243 | } |
5244 | } | |
5245 | ||
5246 | /* Scan the chars for C-g and store them in kbd_buffer. */ | |
5247 | for (i = 0; i < nread; i++) | |
5248 | { | |
5249 | kbd_buffer_store_event (&buf[i]); | |
5250 | /* Don't look at input that follows a C-g too closely. | |
5251 | This reduces lossage due to autorepeat on C-g. */ | |
5252 | if (buf[i].kind == ascii_keystroke | |
9343ab07 | 5253 | && buf[i].code == quit_char) |
284f4730 JB |
5254 | break; |
5255 | } | |
5256 | ||
5257 | return nread; | |
5258 | } | |
5259 | #endif /* not VMS */ | |
5260 | \f | |
5261 | #ifdef SIGIO /* for entire page */ | |
5262 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
5263 | ||
2ce30ea2 | 5264 | SIGTYPE |
284f4730 JB |
5265 | input_available_signal (signo) |
5266 | int signo; | |
5267 | { | |
5268 | /* Must preserve main program's value of errno. */ | |
5269 | int old_errno = errno; | |
5270 | #ifdef BSD4_1 | |
5271 | extern int select_alarmed; | |
5272 | #endif | |
5273 | ||
5970a8cb | 5274 | #if defined (USG) && !defined (POSIX_SIGNALS) |
284f4730 JB |
5275 | /* USG systems forget handlers when they are used; |
5276 | must reestablish each time */ | |
5277 | signal (signo, input_available_signal); | |
5278 | #endif /* USG */ | |
5279 | ||
5280 | #ifdef BSD4_1 | |
5281 | sigisheld (SIGIO); | |
5282 | #endif | |
5283 | ||
ffd56f97 JB |
5284 | if (input_available_clear_time) |
5285 | EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); | |
284f4730 JB |
5286 | |
5287 | while (1) | |
5288 | { | |
5289 | int nread; | |
5290 | nread = read_avail_input (1); | |
5291 | /* -1 means it's not ok to read the input now. | |
5292 | UNBLOCK_INPUT will read it later; now, avoid infinite loop. | |
5293 | 0 means there was no keyboard input available. */ | |
5294 | if (nread <= 0) | |
5295 | break; | |
5296 | ||
5297 | #ifdef BSD4_1 | |
5298 | select_alarmed = 1; /* Force the select emulator back to life */ | |
5299 | #endif | |
5300 | } | |
5301 | ||
5302 | #ifdef BSD4_1 | |
5303 | sigfree (); | |
5304 | #endif | |
5305 | errno = old_errno; | |
5306 | } | |
5307 | #endif /* SIGIO */ | |
ad163903 JB |
5308 | |
5309 | /* Send ourselves a SIGIO. | |
5310 | ||
5311 | This function exists so that the UNBLOCK_INPUT macro in | |
5312 | blockinput.h can have some way to take care of input we put off | |
5313 | dealing with, without assuming that every file which uses | |
5314 | UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */ | |
5315 | void | |
5316 | reinvoke_input_signal () | |
5317 | { | |
df0f2ba1 | 5318 | #ifdef SIGIO |
87dd9b9b | 5319 | kill (getpid (), SIGIO); |
ad163903 JB |
5320 | #endif |
5321 | } | |
5322 | ||
5323 | ||
284f4730 JB |
5324 | \f |
5325 | /* Return the prompt-string of a sparse keymap. | |
5326 | This is the first element which is a string. | |
5327 | Return nil if there is none. */ | |
5328 | ||
5329 | Lisp_Object | |
5330 | map_prompt (map) | |
5331 | Lisp_Object map; | |
5332 | { | |
5333 | while (CONSP (map)) | |
5334 | { | |
5335 | register Lisp_Object tem; | |
5336 | tem = Fcar (map); | |
8c18cbfb | 5337 | if (STRINGP (tem)) |
284f4730 JB |
5338 | return tem; |
5339 | map = Fcdr (map); | |
5340 | } | |
5341 | return Qnil; | |
5342 | } | |
5343 | ||
b7c49376 RS |
5344 | static void menu_bar_item (); |
5345 | static void menu_bar_one_keymap (); | |
5346 | ||
5347 | /* These variables hold the vector under construction within | |
5348 | menu_bar_items and its subroutines, and the current index | |
5349 | for storing into that vector. */ | |
5350 | static Lisp_Object menu_bar_items_vector; | |
9343ab07 | 5351 | static int menu_bar_items_index; |
5ec75a55 | 5352 | |
b7c49376 RS |
5353 | /* Return a vector of menu items for a menu bar, appropriate |
5354 | to the current buffer. Each item has three elements in the vector: | |
f5e09c8b | 5355 | KEY STRING MAPLIST. |
b7c49376 RS |
5356 | |
5357 | OLD is an old vector we can optionally reuse, or nil. */ | |
5ec75a55 RS |
5358 | |
5359 | Lisp_Object | |
b7c49376 RS |
5360 | menu_bar_items (old) |
5361 | Lisp_Object old; | |
5ec75a55 RS |
5362 | { |
5363 | /* The number of keymaps we're scanning right now, and the number of | |
5364 | keymaps we have allocated space for. */ | |
5365 | int nmaps; | |
5366 | ||
5367 | /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] | |
5368 | in the current keymaps, or nil where it is not a prefix. */ | |
5369 | Lisp_Object *maps; | |
5370 | ||
9f9c0e27 | 5371 | Lisp_Object def, tem, tail; |
5ec75a55 RS |
5372 | |
5373 | Lisp_Object result; | |
5374 | ||
5375 | int mapno; | |
47d319aa | 5376 | Lisp_Object oquit; |
5ec75a55 | 5377 | |
b7c49376 RS |
5378 | int i; |
5379 | ||
5380 | struct gcpro gcpro1; | |
5381 | ||
db60d856 JB |
5382 | /* In order to build the menus, we need to call the keymap |
5383 | accessors. They all call QUIT. But this function is called | |
5384 | during redisplay, during which a quit is fatal. So inhibit | |
47d319aa RS |
5385 | quitting while building the menus. |
5386 | We do this instead of specbind because (1) errors will clear it anyway | |
5387 | and (2) this avoids risk of specpdl overflow. */ | |
5388 | oquit = Vinhibit_quit; | |
df0f2ba1 | 5389 | Vinhibit_quit = Qt; |
db60d856 | 5390 | |
b7c49376 RS |
5391 | if (!NILP (old)) |
5392 | menu_bar_items_vector = old; | |
5393 | else | |
5394 | menu_bar_items_vector = Fmake_vector (make_number (24), Qnil); | |
5395 | menu_bar_items_index = 0; | |
5396 | ||
5397 | GCPRO1 (menu_bar_items_vector); | |
5398 | ||
5ec75a55 RS |
5399 | /* Build our list of keymaps. |
5400 | If we recognize a function key and replace its escape sequence in | |
5401 | keybuf with its symbol, or if the sequence starts with a mouse | |
5402 | click and we need to switch buffers, we jump back here to rebuild | |
5403 | the initial keymaps from the current buffer. */ | |
df0f2ba1 | 5404 | { |
5ec75a55 RS |
5405 | Lisp_Object *tmaps; |
5406 | ||
217258d5 | 5407 | /* Should overriding-terminal-local-map and overriding-local-map apply? */ |
d0a49716 | 5408 | if (!NILP (Voverriding_local_map_menu_flag)) |
9dd3131c | 5409 | { |
217258d5 KH |
5410 | /* Yes, use them (if non-nil) as well as the global map. */ |
5411 | maps = (Lisp_Object *) alloca (3 * sizeof (maps[0])); | |
5412 | nmaps = 0; | |
5413 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
5414 | maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
5415 | if (!NILP (Voverriding_local_map)) | |
5416 | maps[nmaps++] = Voverriding_local_map; | |
9dd3131c RS |
5417 | } |
5418 | else | |
5419 | { | |
d0a49716 | 5420 | /* No, so use major and minor mode keymaps. */ |
217258d5 KH |
5421 | nmaps = current_minor_maps (NULL, &tmaps); |
5422 | maps = (Lisp_Object *) alloca ((nmaps + 2) * sizeof (maps[0])); | |
5423 | bcopy (tmaps, maps, nmaps * sizeof (maps[0])); | |
5ec75a55 | 5424 | #ifdef USE_TEXT_PROPERTIES |
217258d5 | 5425 | maps[nmaps++] = get_local_map (PT, current_buffer); |
5ec75a55 | 5426 | #else |
217258d5 | 5427 | maps[nmaps++] = current_buffer->keymap; |
5ec75a55 | 5428 | #endif |
9dd3131c | 5429 | } |
217258d5 | 5430 | maps[nmaps++] = current_global_map; |
5ec75a55 RS |
5431 | } |
5432 | ||
5433 | /* Look up in each map the dummy prefix key `menu-bar'. */ | |
5434 | ||
5435 | result = Qnil; | |
5436 | ||
e58aa385 | 5437 | for (mapno = nmaps - 1; mapno >= 0; mapno--) |
5ec75a55 RS |
5438 | { |
5439 | if (! NILP (maps[mapno])) | |
c6a67acd | 5440 | def = get_keyelt (access_keymap (maps[mapno], Qmenu_bar, 1, 0), 0); |
5ec75a55 RS |
5441 | else |
5442 | def = Qnil; | |
5443 | ||
5444 | tem = Fkeymapp (def); | |
5445 | if (!NILP (tem)) | |
b7c49376 | 5446 | menu_bar_one_keymap (def); |
5ec75a55 RS |
5447 | } |
5448 | ||
b7c49376 RS |
5449 | /* Move to the end those items that should be at the end. */ |
5450 | ||
9f9c0e27 RS |
5451 | for (tail = Vmenu_bar_final_items; CONSP (tail); tail = XCONS (tail)->cdr) |
5452 | { | |
b7c49376 RS |
5453 | int i; |
5454 | int end = menu_bar_items_index; | |
5455 | ||
35b3402f | 5456 | for (i = 0; i < end; i += 4) |
b7c49376 RS |
5457 | if (EQ (XCONS (tail)->car, XVECTOR (menu_bar_items_vector)->contents[i])) |
5458 | { | |
35b3402f | 5459 | Lisp_Object tem0, tem1, tem2, tem3; |
0301268e RS |
5460 | /* Move the item at index I to the end, |
5461 | shifting all the others forward. */ | |
5462 | tem0 = XVECTOR (menu_bar_items_vector)->contents[i + 0]; | |
5463 | tem1 = XVECTOR (menu_bar_items_vector)->contents[i + 1]; | |
5464 | tem2 = XVECTOR (menu_bar_items_vector)->contents[i + 2]; | |
35b3402f RS |
5465 | tem3 = XVECTOR (menu_bar_items_vector)->contents[i + 3]; |
5466 | if (end > i + 4) | |
5467 | bcopy (&XVECTOR (menu_bar_items_vector)->contents[i + 4], | |
0301268e | 5468 | &XVECTOR (menu_bar_items_vector)->contents[i], |
35b3402f RS |
5469 | (end - i - 4) * sizeof (Lisp_Object)); |
5470 | XVECTOR (menu_bar_items_vector)->contents[end - 4] = tem0; | |
5471 | XVECTOR (menu_bar_items_vector)->contents[end - 3] = tem1; | |
5472 | XVECTOR (menu_bar_items_vector)->contents[end - 2] = tem2; | |
5473 | XVECTOR (menu_bar_items_vector)->contents[end - 1] = tem3; | |
0301268e | 5474 | break; |
b7c49376 RS |
5475 | } |
5476 | } | |
9f9c0e27 | 5477 | |
0c9071cd | 5478 | /* Add nil, nil, nil, nil at the end. */ |
b7c49376 | 5479 | i = menu_bar_items_index; |
35b3402f | 5480 | if (i + 4 > XVECTOR (menu_bar_items_vector)->size) |
b7c49376 RS |
5481 | { |
5482 | Lisp_Object tem; | |
5483 | int newsize = 2 * i; | |
5484 | tem = Fmake_vector (make_number (2 * i), Qnil); | |
5485 | bcopy (XVECTOR (menu_bar_items_vector)->contents, | |
5486 | XVECTOR (tem)->contents, i * sizeof (Lisp_Object)); | |
5487 | menu_bar_items_vector = tem; | |
9f9c0e27 | 5488 | } |
b7c49376 RS |
5489 | /* Add this item. */ |
5490 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
5491 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
5492 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; | |
35b3402f | 5493 | XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil; |
b7c49376 | 5494 | menu_bar_items_index = i; |
a73c5e29 | 5495 | |
47d319aa | 5496 | Vinhibit_quit = oquit; |
b7c49376 RS |
5497 | UNGCPRO; |
5498 | return menu_bar_items_vector; | |
5ec75a55 RS |
5499 | } |
5500 | \f | |
5501 | /* Scan one map KEYMAP, accumulating any menu items it defines | |
f5e09c8b | 5502 | in menu_bar_items_vector. */ |
5ec75a55 | 5503 | |
b7c49376 RS |
5504 | static void |
5505 | menu_bar_one_keymap (keymap) | |
5506 | Lisp_Object keymap; | |
5ec75a55 | 5507 | { |
e8886a1d | 5508 | Lisp_Object tail, item, table; |
5ec75a55 RS |
5509 | |
5510 | /* Loop over all keymap entries that have menu strings. */ | |
8c18cbfb | 5511 | for (tail = keymap; CONSP (tail); tail = XCONS (tail)->cdr) |
5ec75a55 RS |
5512 | { |
5513 | item = XCONS (tail)->car; | |
8c18cbfb | 5514 | if (CONSP (item)) |
e8886a1d | 5515 | menu_bar_item (XCONS (item)->car, XCONS (item)->cdr); |
8c18cbfb | 5516 | else if (VECTORP (item)) |
5ec75a55 RS |
5517 | { |
5518 | /* Loop over the char values represented in the vector. */ | |
5519 | int len = XVECTOR (item)->size; | |
5520 | int c; | |
5521 | for (c = 0; c < len; c++) | |
5522 | { | |
5523 | Lisp_Object character; | |
bb9e9bed | 5524 | XSETFASTINT (character, c); |
e8886a1d | 5525 | menu_bar_item (character, XVECTOR (item)->contents[c]); |
5ec75a55 RS |
5526 | } |
5527 | } | |
5528 | } | |
5ec75a55 RS |
5529 | } |
5530 | ||
f5e09c8b RS |
5531 | /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF. |
5532 | If there's already an item for KEY, add this DEF to it. */ | |
5533 | ||
e8886a1d RS |
5534 | Lisp_Object item_properties; |
5535 | ||
b7c49376 | 5536 | static void |
e8886a1d RS |
5537 | menu_bar_item (key, item) |
5538 | Lisp_Object key, item; | |
5ec75a55 | 5539 | { |
e8886a1d | 5540 | struct gcpro gcpro1; |
b7c49376 | 5541 | int i; |
5ec75a55 | 5542 | |
e8886a1d | 5543 | if (EQ (item, Qundefined)) |
e58aa385 | 5544 | { |
f5e09c8b | 5545 | /* If a map has an explicit `undefined' as definition, |
e58aa385 | 5546 | discard any previously made menu bar item. */ |
b7c49376 | 5547 | |
35b3402f | 5548 | for (i = 0; i < menu_bar_items_index; i += 4) |
b7c49376 RS |
5549 | if (EQ (key, XVECTOR (menu_bar_items_vector)->contents[i])) |
5550 | { | |
35b3402f RS |
5551 | if (menu_bar_items_index > i + 4) |
5552 | bcopy (&XVECTOR (menu_bar_items_vector)->contents[i + 4], | |
b7c49376 | 5553 | &XVECTOR (menu_bar_items_vector)->contents[i], |
35b3402f RS |
5554 | (menu_bar_items_index - i - 4) * sizeof (Lisp_Object)); |
5555 | menu_bar_items_index -= 4; | |
b7c49376 RS |
5556 | return; |
5557 | } | |
8aa034e1 RS |
5558 | |
5559 | /* If there's no definition for this key yet, | |
5560 | just ignore `undefined'. */ | |
5561 | return; | |
e58aa385 RS |
5562 | } |
5563 | ||
e8886a1d RS |
5564 | GCPRO1 (key); /* Is this necessary? */ |
5565 | i = parse_menu_item (item, 0, 1); | |
5566 | UNGCPRO; | |
5567 | if (!i) | |
b7c49376 | 5568 | return; |
5ec75a55 | 5569 | |
e8886a1d RS |
5570 | item = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF]; |
5571 | ||
f5e09c8b | 5572 | /* Find any existing item for this KEY. */ |
35b3402f | 5573 | for (i = 0; i < menu_bar_items_index; i += 4) |
b7c49376 RS |
5574 | if (EQ (key, XVECTOR (menu_bar_items_vector)->contents[i])) |
5575 | break; | |
5576 | ||
f5e09c8b | 5577 | /* If we did not find this KEY, add it at the end. */ |
b7c49376 RS |
5578 | if (i == menu_bar_items_index) |
5579 | { | |
5580 | /* If vector is too small, get a bigger one. */ | |
35b3402f | 5581 | if (i + 4 > XVECTOR (menu_bar_items_vector)->size) |
b7c49376 RS |
5582 | { |
5583 | Lisp_Object tem; | |
5584 | int newsize = 2 * i; | |
5585 | tem = Fmake_vector (make_number (2 * i), Qnil); | |
5586 | bcopy (XVECTOR (menu_bar_items_vector)->contents, | |
5587 | XVECTOR (tem)->contents, i * sizeof (Lisp_Object)); | |
5588 | menu_bar_items_vector = tem; | |
5589 | } | |
e8886a1d | 5590 | |
b7c49376 RS |
5591 | /* Add this item. */ |
5592 | XVECTOR (menu_bar_items_vector)->contents[i++] = key; | |
e8886a1d RS |
5593 | XVECTOR (menu_bar_items_vector)->contents[i++] |
5594 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; | |
5595 | XVECTOR (menu_bar_items_vector)->contents[i++] = Fcons (item, Qnil); | |
35b3402f | 5596 | XVECTOR (menu_bar_items_vector)->contents[i++] = make_number (0); |
b7c49376 RS |
5597 | menu_bar_items_index = i; |
5598 | } | |
e8886a1d | 5599 | /* We did find an item for this KEY. Add ITEM to its list of maps. */ |
f5e09c8b RS |
5600 | else |
5601 | { | |
5602 | Lisp_Object old; | |
5603 | old = XVECTOR (menu_bar_items_vector)->contents[i + 2]; | |
e8886a1d | 5604 | XVECTOR (menu_bar_items_vector)->contents[i + 2] = Fcons (item, old); |
f5e09c8b | 5605 | } |
5ec75a55 RS |
5606 | } |
5607 | \f | |
e8886a1d RS |
5608 | /* This is used as the handler when calling menu_item_eval_property. */ |
5609 | static Lisp_Object | |
5610 | menu_item_eval_property_1 (arg) | |
5611 | Lisp_Object arg; | |
5612 | { | |
5613 | /* If we got a quit from within the menu computation, | |
5614 | quit all the way out of it. This takes care of C-] in the debugger. */ | |
5615 | if (CONSP (arg) && EQ (XCONS (arg)->car, Qquit)) | |
5616 | Fsignal (Qquit, Qnil); | |
5617 | ||
5618 | return Qnil; | |
5619 | } | |
5620 | ||
5621 | /* Evaluate an expression and return the result (or nil if something | |
5622 | went wrong). Used to evaluate dynamic parts of menu items. */ | |
5623 | static Lisp_Object | |
5624 | menu_item_eval_property (sexpr) | |
5625 | Lisp_Object sexpr; | |
5626 | { | |
5627 | Lisp_Object val; | |
5628 | val = internal_condition_case_1 (Feval, sexpr, Qerror, | |
5629 | menu_item_eval_property_1); | |
5630 | return val; | |
5631 | } | |
5632 | ||
5633 | /* This function parses a menu item and leaves the result in the | |
5634 | vector item_properties. | |
5635 | ITEM is a key binding, a possible menu item. | |
5636 | If NOTREAL is nonzero, only check for equivalent key bindings, don't | |
5637 | evaluate dynamic expressions in the menu item. | |
fd3613d7 | 5638 | INMENUBAR is > 0 when this is considered for an entry in a menu bar |
e8886a1d | 5639 | top level. |
fd3613d7 | 5640 | INMENUBAR is < 0 when this is considered for an entry in a keyboard menu. |
e8886a1d RS |
5641 | parse_menu_item returns true if the item is a menu item and false |
5642 | otherwise. */ | |
5643 | ||
5644 | int | |
5645 | parse_menu_item (item, notreal, inmenubar) | |
5646 | Lisp_Object item; | |
5647 | int notreal, inmenubar; | |
5648 | { | |
adc1d5c8 RS |
5649 | Lisp_Object def, tem, item_string, start; |
5650 | Lisp_Object cachelist = Qnil; | |
5651 | Lisp_Object filter = Qnil; | |
5652 | Lisp_Object keyhint = Qnil; | |
e8886a1d | 5653 | int i; |
74c1de23 RS |
5654 | int newcache = 0; |
5655 | ||
e8886a1d RS |
5656 | if (!CONSP (item)) |
5657 | return 0; | |
5658 | ||
e8886a1d RS |
5659 | /* Create item_properties vector if necessary. */ |
5660 | if (NILP (item_properties)) | |
5661 | item_properties | |
5662 | = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE + 1), Qnil); | |
5663 | ||
5664 | /* Initialize optional entries. */ | |
5665 | for (i = ITEM_PROPERTY_DEF; i < ITEM_PROPERTY_ENABLE; i++) | |
5666 | XVECTOR (item_properties)->contents[i] = Qnil; | |
5667 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] = Qt; | |
5668 | ||
5669 | /* Save the item here to protect it from GC. */ | |
5670 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_ITEM] = item; | |
5671 | ||
5672 | item_string = XCONS (item)->car; | |
5673 | ||
5674 | start = item; | |
5675 | item = XCONS (item)->cdr; | |
5676 | if (STRINGP (item_string)) | |
5677 | { | |
5678 | /* Old format menu item. */ | |
5679 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME] = item_string; | |
5680 | ||
5681 | /* Maybe help string. */ | |
5682 | if (CONSP (item) && STRINGP (XCONS (item)->car)) | |
5683 | { | |
5684 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] | |
5685 | = XCONS (item)->car; | |
5686 | start = item; | |
5687 | item = XCONS (item)->cdr; | |
5688 | } | |
5689 | ||
5690 | /* Maybee key binding cache. */ | |
5691 | if (CONSP (item) && CONSP (XCONS (item)->car) | |
5692 | && (NILP (XCONS (XCONS (item)->car)->car) | |
5693 | || VECTORP (XCONS (XCONS (item)->car)->car))) | |
5694 | { | |
5695 | cachelist = XCONS (item)->car; | |
5696 | item = XCONS (item)->cdr; | |
5697 | } | |
5698 | ||
5699 | /* This is the real definition--the function to run. */ | |
5700 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] = item; | |
5701 | ||
5702 | /* Get enable property, if any. */ | |
5703 | if (SYMBOLP (item)) | |
5704 | { | |
5705 | tem = Fget (item, Qmenu_enable); | |
5706 | if (!NILP (tem)) | |
5707 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] = tem; | |
5708 | } | |
5709 | } | |
5710 | else if (EQ (item_string, Qmenu_item) && CONSP (item)) | |
5711 | { | |
5712 | /* New format menu item. */ | |
5713 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME] | |
5714 | = XCONS (item)->car; | |
5715 | start = XCONS (item)->cdr; | |
5716 | if (CONSP (start)) | |
5717 | { | |
5718 | /* We have a real binding. */ | |
5719 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] | |
5720 | = XCONS (start)->car; | |
5721 | ||
5722 | item = XCONS (start)->cdr; | |
5723 | /* Is there a cache list with key equivalences. */ | |
5724 | if (CONSP (item) && CONSP (XCONS (item)->car)) | |
5725 | { | |
5726 | cachelist = XCONS (item)->car; | |
5727 | item = XCONS (item)->cdr; | |
5728 | } | |
5729 | ||
5730 | /* Parse properties. */ | |
5731 | while (CONSP (item) && CONSP (XCONS (item)->cdr)) | |
5732 | { | |
5733 | tem = XCONS (item)->car; | |
5734 | item = XCONS (item)->cdr; | |
5735 | ||
5736 | if (EQ (tem, QCenable)) | |
5737 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] | |
5738 | = XCONS (item)->car; | |
5739 | else if (EQ (tem, QCvisible) && !notreal) | |
5740 | { | |
5741 | /* If got a visible property and that evaluates to nil | |
5742 | then ignore this item. */ | |
5743 | tem = menu_item_eval_property (XCONS (item)->car); | |
5744 | if (NILP (tem)) | |
adc1d5c8 | 5745 | return 0; |
e8886a1d RS |
5746 | } |
5747 | else if (EQ (tem, QChelp)) | |
5748 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] | |
5749 | = XCONS (item)->car; | |
5750 | else if (EQ (tem, QCfilter)) | |
74c1de23 RS |
5751 | filter = item; |
5752 | else if (EQ (tem, QCkey_sequence)) | |
5753 | { | |
5754 | tem = XCONS (item)->car; | |
5755 | if (NILP (cachelist) | |
5756 | && (SYMBOLP (tem) || STRINGP (tem) || VECTORP (tem))) | |
5757 | /* Be GC protected. Set keyhint to item instead of tem. */ | |
5758 | keyhint = item; | |
5759 | } | |
5760 | else if (EQ (tem, QCkeys)) | |
5761 | { | |
5762 | tem = XCONS (item)->car; | |
5763 | if (CONSP (tem) || STRINGP (tem) && NILP (cachelist)) | |
5764 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ] | |
5765 | = tem; | |
5766 | } | |
e8886a1d RS |
5767 | else if (EQ (tem, QCbutton) && CONSP (XCONS (item)->car)) |
5768 | { | |
74c1de23 | 5769 | Lisp_Object type; |
e8886a1d RS |
5770 | tem = XCONS (item)->car; |
5771 | type = XCONS (tem)->car; | |
5772 | if (EQ (type, QCtoggle) || EQ (type, QCradio)) | |
5773 | { | |
5774 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED] | |
5775 | = XCONS (tem)->cdr; | |
5776 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE] | |
5777 | = type; | |
5778 | } | |
5779 | } | |
5780 | item = XCONS (item)->cdr; | |
5781 | } | |
5782 | } | |
5783 | else if (inmenubar || !NILP (start)) | |
adc1d5c8 | 5784 | return 0; |
e8886a1d RS |
5785 | } |
5786 | else | |
adc1d5c8 | 5787 | return 0; /* not a menu item */ |
e8886a1d RS |
5788 | |
5789 | /* If item string is not a string, evaluate it to get string. | |
5790 | If we don't get a string, skip this item. */ | |
5791 | item_string = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; | |
5792 | if (!(STRINGP (item_string) || notreal)) | |
5793 | { | |
5794 | item_string = menu_item_eval_property (item_string); | |
5795 | if (!STRINGP (item_string)) | |
adc1d5c8 | 5796 | return 0; |
e8886a1d RS |
5797 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME] = item_string; |
5798 | } | |
5799 | ||
5800 | /* If got a filter apply it on definition. */ | |
5801 | def = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF]; | |
5802 | if (!NILP (filter)) | |
5803 | { | |
74c1de23 RS |
5804 | def = menu_item_eval_property (Fcons (XCONS (filter)->car, |
5805 | Fcons (def, Qnil))); | |
e8886a1d RS |
5806 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] = def; |
5807 | } | |
5808 | ||
5809 | /* If we got no definition, this item is just unselectable text which | |
74c1de23 | 5810 | is OK in a submenu but not in the menubar. */ |
e8886a1d | 5811 | if (NILP (def)) |
adc1d5c8 | 5812 | return (inmenubar ? 0 : 1); |
e8886a1d RS |
5813 | |
5814 | /* Enable or disable selection of item. */ | |
5815 | tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE]; | |
5816 | if (!EQ (tem, Qt)) | |
5817 | { | |
5818 | if (notreal) | |
5819 | tem = Qt; | |
5820 | else | |
5821 | tem = menu_item_eval_property (tem); | |
5822 | if (inmenubar && NILP (tem)) | |
adc1d5c8 | 5823 | return 0; /* Ignore disabled items in menu bar. */ |
e8886a1d RS |
5824 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] = tem; |
5825 | } | |
5826 | ||
5827 | /* See if this is a separate pane or a submenu. */ | |
74c1de23 | 5828 | def = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF]; |
e8886a1d RS |
5829 | tem = get_keymap_1 (def, 0, 1); |
5830 | if (!NILP (tem)) | |
5831 | { | |
5832 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_MAP] = tem; | |
5833 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] = tem; | |
e8886a1d RS |
5834 | return 1; |
5835 | } | |
adc1d5c8 RS |
5836 | else if (inmenubar > 0) |
5837 | return 0; /* Entries in menu bar must be submenus. */ | |
e8886a1d RS |
5838 | |
5839 | /* This is a command. See if there is an equivalent key binding. */ | |
5840 | if (NILP (cachelist)) | |
5841 | { | |
74c1de23 | 5842 | /* We have to create a cachelist. */ |
e8886a1d RS |
5843 | CHECK_IMPURE (start); |
5844 | XCONS (start)->cdr = Fcons (Fcons (Qnil, Qnil), XCONS (start)->cdr); | |
5845 | cachelist = XCONS (XCONS (start)->cdr)->car; | |
74c1de23 RS |
5846 | newcache = 1; |
5847 | tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ]; | |
5848 | if (!NILP (keyhint)) | |
5849 | { | |
5850 | XCONS (cachelist)->car = XCONS (keyhint)->car; | |
5851 | newcache = 0; | |
5852 | } | |
5853 | else if (STRINGP (tem)) | |
5854 | { | |
5855 | XCONS (cachelist)->cdr = Fsubstitute_command_keys (tem); | |
5856 | XCONS (cachelist)->car = Qt; | |
5857 | } | |
5858 | } | |
5859 | tem = XCONS (cachelist)->car; | |
5860 | if (!EQ (tem, Qt)) | |
5861 | { | |
5862 | int chkcache = 0; | |
5863 | Lisp_Object prefix; | |
5864 | ||
5865 | if (!NILP (tem)) | |
5866 | tem = Fkey_binding (tem, Qnil); | |
5867 | ||
5868 | prefix = XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ]; | |
5869 | if (CONSP (prefix)) | |
5870 | { | |
5871 | def = XCONS (prefix)->car; | |
5872 | prefix = XCONS (prefix)->cdr; | |
5873 | } | |
e8886a1d | 5874 | else |
74c1de23 RS |
5875 | def = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF]; |
5876 | ||
5877 | if (NILP (XCONS (cachelist)->car)) /* Have no saved key. */ | |
5878 | { | |
5879 | if (newcache /* Always check first time. */ | |
5880 | /* Should we check everything when precomputing key | |
5881 | bindings? */ | |
5882 | /* || notreal */ | |
5883 | /* If something had no key binding before, don't recheck it | |
5884 | because that is too slow--except if we have a list of | |
5885 | rebound commands in Vdefine_key_rebound_commands, do | |
5886 | recheck any command that appears in that list. */ | |
5887 | || (CONSP (Vdefine_key_rebound_commands) | |
5888 | && !NILP (Fmemq (def, Vdefine_key_rebound_commands)))) | |
5889 | chkcache = 1; | |
5890 | } | |
5891 | /* We had a saved key. Is it still bound to the command? */ | |
5892 | else if (NILP (tem) | |
5893 | || !EQ (tem, def) | |
5894 | /* If the command is an alias for another | |
5895 | (such as lmenu.el set it up), check if the | |
5896 | original command matches the cached command. */ | |
5897 | && !(SYMBOLP (def) && EQ (tem, XSYMBOL (def)->function))) | |
5898 | chkcache = 1; /* Need to recompute key binding. */ | |
5899 | ||
5900 | if (chkcache) | |
5901 | { | |
5902 | /* Recompute equivalent key binding. If the command is an alias | |
5903 | for another (such as lmenu.el set it up), see if the original | |
5904 | command name has equivalent keys. Otherwise look up the | |
5905 | specified command itself. We don't try both, because that | |
5906 | makes lmenu menus slow. */ | |
5907 | if (SYMBOLP (def) && SYMBOLP (XSYMBOL (def)->function) | |
5908 | && ! NILP (Fget (def, Qmenu_alias))) | |
5909 | def = XSYMBOL (def)->function; | |
5910 | tem = Fwhere_is_internal (def, Qnil, Qt, Qnil); | |
5911 | XCONS (cachelist)->car = tem; | |
5912 | if (NILP (tem)) | |
5913 | { | |
5914 | XCONS (cachelist)->cdr = Qnil; | |
5915 | chkcache = 0; | |
5916 | } | |
5917 | } | |
5918 | else if (!NILP (keyhint) && !NILP (XCONS (cachelist)->car)) | |
5919 | { | |
5920 | tem = XCONS (cachelist)->car; | |
5921 | chkcache = 1; | |
5922 | } | |
5923 | ||
5924 | newcache = chkcache; | |
5925 | if (chkcache) | |
5926 | { | |
5927 | tem = Fkey_description (tem); | |
5928 | if (CONSP (prefix)) | |
5929 | { | |
5930 | if (STRINGP (XCONS (prefix)->car)) | |
5931 | tem = concat2 (XCONS (prefix)->car, tem); | |
5932 | if (STRINGP (XCONS (prefix)->cdr)) | |
5933 | tem = concat2 (tem, XCONS (prefix)->cdr); | |
5934 | } | |
5935 | XCONS (cachelist)->cdr = tem; | |
5936 | } | |
5937 | } | |
5938 | ||
5939 | tem = XCONS (cachelist)->cdr; | |
5940 | if (newcache && !NILP (tem)) | |
e8886a1d | 5941 | { |
74c1de23 RS |
5942 | tem = concat3 (build_string (" ("), tem, build_string (")")); |
5943 | XCONS (cachelist)->cdr = tem; | |
e8886a1d RS |
5944 | } |
5945 | ||
5946 | /* If we only want to precompute equivalent key bindings, stop here. */ | |
5947 | if (notreal) | |
adc1d5c8 | 5948 | return 1; |
e8886a1d RS |
5949 | |
5950 | /* If we have an equivalent key binding, use that. */ | |
adc1d5c8 RS |
5951 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ] = tem; |
5952 | ||
5953 | /* Include this when menu help is implemented. | |
5954 | tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP]; | |
5955 | if (!(NILP (tem) || STRINGP (tem))) | |
5956 | { | |
5957 | tem = menu_item_eval_property (tem); | |
5958 | if (!STRINGP (tem)) | |
5959 | tem = Qnil; | |
5960 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem; | |
5961 | } | |
e8886a1d RS |
5962 | */ |
5963 | ||
5964 | /* Handle radio buttons or toggle boxes. */ | |
5965 | tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]; | |
5966 | if (!NILP (tem)) | |
5967 | XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED] | |
5968 | = menu_item_eval_property (tem); | |
5969 | ||
e8886a1d RS |
5970 | return 1; |
5971 | } | |
5972 | \f | |
dcc408a0 RS |
5973 | /* Read a character using menus based on maps in the array MAPS. |
5974 | NMAPS is the length of MAPS. Return nil if there are no menus in the maps. | |
5975 | Return t if we displayed a menu but the user rejected it. | |
7d6de002 RS |
5976 | |
5977 | PREV_EVENT is the previous input event, or nil if we are reading | |
5978 | the first event of a key sequence. | |
5979 | ||
83d68044 | 5980 | If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1 |
6569cc8d | 5981 | if we used a mouse menu to read the input, or zero otherwise. If |
83d68044 | 5982 | USED_MOUSE_MENU is null, we don't dereference it. |
284f4730 JB |
5983 | |
5984 | The prompting is done based on the prompt-string of the map | |
df0f2ba1 | 5985 | and the strings associated with various map elements. |
8150596a RS |
5986 | |
5987 | This can be done with X menus or with menus put in the minibuf. | |
5988 | These are done in different ways, depending on how the input will be read. | |
5989 | Menus using X are done after auto-saving in read-char, getting the input | |
5990 | event from Fx_popup_menu; menus using the minibuf use read_char recursively | |
5991 | and do auto-saving in the inner call of read_char. */ | |
284f4730 | 5992 | |
7617111f | 5993 | static Lisp_Object |
8150596a | 5994 | read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu) |
7d6de002 RS |
5995 | int nmaps; |
5996 | Lisp_Object *maps; | |
5997 | Lisp_Object prev_event; | |
5998 | int *used_mouse_menu; | |
284f4730 | 5999 | { |
7d6de002 RS |
6000 | int mapno; |
6001 | register Lisp_Object name; | |
7d6de002 RS |
6002 | Lisp_Object rest, vector; |
6003 | ||
6569cc8d JB |
6004 | if (used_mouse_menu) |
6005 | *used_mouse_menu = 0; | |
284f4730 JB |
6006 | |
6007 | /* Use local over global Menu maps */ | |
6008 | ||
7d6de002 RS |
6009 | if (! menu_prompting) |
6010 | return Qnil; | |
6011 | ||
03361bcc RS |
6012 | /* Optionally disregard all but the global map. */ |
6013 | if (inhibit_local_menu_bar_menus) | |
6014 | { | |
6015 | maps += (nmaps - 1); | |
6016 | nmaps = 1; | |
6017 | } | |
6018 | ||
7d6de002 RS |
6019 | /* Get the menu name from the first map that has one (a prompt string). */ |
6020 | for (mapno = 0; mapno < nmaps; mapno++) | |
6021 | { | |
6022 | name = map_prompt (maps[mapno]); | |
6023 | if (!NILP (name)) | |
6024 | break; | |
6025 | } | |
284f4730 | 6026 | |
7d6de002 | 6027 | /* If we don't have any menus, just read a character normally. */ |
dbc4e1c1 | 6028 | if (mapno >= nmaps) |
7d6de002 RS |
6029 | return Qnil; |
6030 | ||
1f5b1641 | 6031 | #ifdef HAVE_MENUS |
7d6de002 RS |
6032 | /* If we got to this point via a mouse click, |
6033 | use a real menu for mouse selection. */ | |
5a8d99e0 KH |
6034 | if (EVENT_HAS_PARAMETERS (prev_event) |
6035 | && !EQ (XCONS (prev_event)->car, Qmenu_bar)) | |
7d6de002 RS |
6036 | { |
6037 | /* Display the menu and get the selection. */ | |
6038 | Lisp_Object *realmaps | |
6039 | = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); | |
6040 | Lisp_Object value; | |
6041 | int nmaps1 = 0; | |
6042 | ||
6043 | /* Use the maps that are not nil. */ | |
6044 | for (mapno = 0; mapno < nmaps; mapno++) | |
6045 | if (!NILP (maps[mapno])) | |
6046 | realmaps[nmaps1++] = maps[mapno]; | |
6047 | ||
6048 | value = Fx_popup_menu (prev_event, Flist (nmaps1, realmaps)); | |
663258f2 JB |
6049 | if (CONSP (value)) |
6050 | { | |
68f297c5 RS |
6051 | Lisp_Object tem; |
6052 | ||
8eb4d8ef RS |
6053 | record_menu_key (XCONS (value)->car); |
6054 | ||
68f297c5 RS |
6055 | /* If we got multiple events, unread all but |
6056 | the first. | |
6057 | There is no way to prevent those unread events | |
6058 | from showing up later in last_nonmenu_event. | |
6059 | So turn symbol and integer events into lists, | |
6060 | to indicate that they came from a mouse menu, | |
6061 | so that when present in last_nonmenu_event | |
6062 | they won't confuse things. */ | |
6063 | for (tem = XCONS (value)->cdr; !NILP (tem); | |
6064 | tem = XCONS (tem)->cdr) | |
8eb4d8ef RS |
6065 | { |
6066 | record_menu_key (XCONS (tem)->car); | |
6067 | if (SYMBOLP (XCONS (tem)->car) | |
6068 | || INTEGERP (XCONS (tem)->car)) | |
6069 | XCONS (tem)->car | |
6070 | = Fcons (XCONS (tem)->car, Qnil); | |
6071 | } | |
68f297c5 | 6072 | |
663258f2 JB |
6073 | /* If we got more than one event, put all but the first |
6074 | onto this list to be read later. | |
6075 | Return just the first event now. */ | |
24597608 RS |
6076 | Vunread_command_events |
6077 | = nconc2 (XCONS (value)->cdr, Vunread_command_events); | |
663258f2 JB |
6078 | value = XCONS (value)->car; |
6079 | } | |
1c90c381 | 6080 | else if (NILP (value)) |
dcc408a0 | 6081 | value = Qt; |
6569cc8d JB |
6082 | if (used_mouse_menu) |
6083 | *used_mouse_menu = 1; | |
7d6de002 RS |
6084 | return value; |
6085 | } | |
1f5b1641 | 6086 | #endif /* HAVE_MENUS */ |
8150596a RS |
6087 | return Qnil ; |
6088 | } | |
6089 | ||
68e0de82 RS |
6090 | /* Buffer in use so far for the minibuf prompts for menu keymaps. |
6091 | We make this bigger when necessary, and never free it. */ | |
6092 | static char *read_char_minibuf_menu_text; | |
6093 | /* Size of that buffer. */ | |
6094 | static int read_char_minibuf_menu_width; | |
6095 | ||
8150596a | 6096 | static Lisp_Object |
24597608 | 6097 | read_char_minibuf_menu_prompt (commandflag, nmaps, maps) |
8150596a RS |
6098 | int commandflag ; |
6099 | int nmaps; | |
6100 | Lisp_Object *maps; | |
6101 | { | |
6102 | int mapno; | |
6103 | register Lisp_Object name; | |
6104 | int nlength; | |
6105 | int width = FRAME_WIDTH (selected_frame) - 4; | |
8150596a | 6106 | int idx = -1; |
9fdbfdf8 | 6107 | int nobindings = 1; |
8150596a | 6108 | Lisp_Object rest, vector; |
68e0de82 | 6109 | char *menu; |
8150596a RS |
6110 | |
6111 | if (! menu_prompting) | |
6112 | return Qnil; | |
6113 | ||
68e0de82 RS |
6114 | /* Make sure we have a big enough buffer for the menu text. */ |
6115 | if (read_char_minibuf_menu_text == 0) | |
6116 | { | |
6117 | read_char_minibuf_menu_width = width + 4; | |
6118 | read_char_minibuf_menu_text = (char *) xmalloc (width + 4); | |
6119 | } | |
6120 | else if (width + 4 > read_char_minibuf_menu_width) | |
6121 | { | |
6122 | read_char_minibuf_menu_width = width + 4; | |
6123 | read_char_minibuf_menu_text | |
6124 | = (char *) xrealloc (read_char_minibuf_menu_text, width + 4); | |
6125 | } | |
6126 | menu = read_char_minibuf_menu_text; | |
6127 | ||
8150596a RS |
6128 | /* Get the menu name from the first map that has one (a prompt string). */ |
6129 | for (mapno = 0; mapno < nmaps; mapno++) | |
6130 | { | |
6131 | name = map_prompt (maps[mapno]); | |
6132 | if (!NILP (name)) | |
6133 | break; | |
6134 | } | |
6135 | ||
6136 | /* If we don't have any menus, just read a character normally. */ | |
6137 | if (mapno >= nmaps) | |
6138 | return Qnil; | |
284f4730 JB |
6139 | |
6140 | /* Prompt string always starts with map's prompt, and a space. */ | |
6141 | strcpy (menu, XSTRING (name)->data); | |
fc932ac6 | 6142 | nlength = STRING_BYTES (XSTRING (name)); |
7d6de002 | 6143 | menu[nlength++] = ':'; |
284f4730 JB |
6144 | menu[nlength++] = ' '; |
6145 | menu[nlength] = 0; | |
6146 | ||
7d6de002 RS |
6147 | /* Start prompting at start of first map. */ |
6148 | mapno = 0; | |
6149 | rest = maps[mapno]; | |
284f4730 JB |
6150 | |
6151 | /* Present the documented bindings, a line at a time. */ | |
6152 | while (1) | |
6153 | { | |
6154 | int notfirst = 0; | |
6155 | int i = nlength; | |
6156 | Lisp_Object obj; | |
6157 | int ch; | |
8066f1a1 | 6158 | Lisp_Object orig_defn_macro; |
284f4730 | 6159 | |
284f4730 | 6160 | /* Loop over elements of map. */ |
7d6de002 | 6161 | while (i < width) |
284f4730 | 6162 | { |
fd3613d7 | 6163 | Lisp_Object elt; |
284f4730 | 6164 | |
7d6de002 RS |
6165 | /* If reached end of map, start at beginning of next map. */ |
6166 | if (NILP (rest)) | |
6167 | { | |
6168 | mapno++; | |
6169 | /* At end of last map, wrap around to first map if just starting, | |
6170 | or end this line if already have something on it. */ | |
6171 | if (mapno == nmaps) | |
284f4730 | 6172 | { |
8150596a | 6173 | mapno = 0; |
40932d1a | 6174 | if (notfirst || nobindings) break; |
284f4730 | 6175 | } |
7d6de002 | 6176 | rest = maps[mapno]; |
284f4730 | 6177 | } |
7d6de002 RS |
6178 | |
6179 | /* Look at the next element of the map. */ | |
6180 | if (idx >= 0) | |
6181 | elt = XVECTOR (vector)->contents[idx]; | |
284f4730 | 6182 | else |
7d6de002 RS |
6183 | elt = Fcar_safe (rest); |
6184 | ||
8c18cbfb | 6185 | if (idx < 0 && VECTORP (elt)) |
284f4730 | 6186 | { |
7d6de002 RS |
6187 | /* If we found a dense table in the keymap, |
6188 | advanced past it, but start scanning its contents. */ | |
6189 | rest = Fcdr_safe (rest); | |
6190 | vector = elt; | |
6191 | idx = 0; | |
284f4730 | 6192 | } |
7d6de002 RS |
6193 | else |
6194 | { | |
6195 | /* An ordinary element. */ | |
fd3613d7 | 6196 | Lisp_Object event, tem; |
0a2ea221 KH |
6197 | |
6198 | if (idx < 0) | |
6199 | { | |
fd3613d7 RS |
6200 | event = Fcar_safe (elt); /* alist */ |
6201 | elt = Fcdr_safe (elt); | |
0a2ea221 | 6202 | } |
8150596a | 6203 | else |
7d6de002 | 6204 | { |
fd3613d7 | 6205 | XSETINT (event, idx); /* vector */ |
0a2ea221 KH |
6206 | } |
6207 | ||
6208 | /* Ignore the element if it has no prompt string. */ | |
fd3613d7 | 6209 | if (INTEGERP (event) && parse_menu_item (elt, 0, -1)) |
0a2ea221 KH |
6210 | { |
6211 | /* 1 if the char to type matches the string. */ | |
6212 | int char_matches; | |
6213 | Lisp_Object upcased_event, downcased_event; | |
6214 | Lisp_Object desc; | |
fd3613d7 RS |
6215 | Lisp_Object s |
6216 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; | |
0a2ea221 KH |
6217 | |
6218 | upcased_event = Fupcase (event); | |
6219 | downcased_event = Fdowncase (event); | |
6220 | char_matches = (XINT (upcased_event) == XSTRING (s)->data[0] | |
6221 | || XINT (downcased_event) == XSTRING (s)->data[0]); | |
6222 | if (! char_matches) | |
6223 | desc = Fsingle_key_description (event); | |
6224 | ||
fd3613d7 RS |
6225 | tem |
6226 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ]; | |
6227 | if (!NILP (tem)) | |
6228 | /* Insert equivalent keybinding. */ | |
6229 | s = concat2 (s, tem); | |
6230 | ||
6231 | tem | |
6232 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE]; | |
6233 | if (EQ (tem, QCradio) || EQ (tem, QCtoggle)) | |
6234 | { | |
6235 | /* Insert button prefix. */ | |
6236 | Lisp_Object selected | |
6237 | = XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]; | |
6238 | if (EQ (tem, QCradio)) | |
6239 | tem = build_string (NILP (selected) ? "(*) " : "( ) "); | |
6240 | else | |
6241 | tem = build_string (NILP (selected) ? "[X] " : "[ ] "); | |
6242 | s = concat2 (tem, s); | |
6243 | } | |
6244 | ||
6245 | ||
0a2ea221 KH |
6246 | /* If we have room for the prompt string, add it to this line. |
6247 | If this is the first on the line, always add it. */ | |
6248 | if ((XSTRING (s)->size + i + 2 | |
6249 | + (char_matches ? 0 : XSTRING (desc)->size + 3)) | |
6250 | < width | |
6251 | || !notfirst) | |
6252 | { | |
6253 | int thiswidth; | |
6254 | ||
6255 | /* Punctuate between strings. */ | |
6256 | if (notfirst) | |
6257 | { | |
6258 | strcpy (menu + i, ", "); | |
6259 | i += 2; | |
6260 | } | |
6261 | notfirst = 1; | |
6262 | nobindings = 0 ; | |
284f4730 | 6263 | |
0a2ea221 KH |
6264 | /* If the char to type doesn't match the string's |
6265 | first char, explicitly show what char to type. */ | |
6266 | if (! char_matches) | |
6267 | { | |
6268 | /* Add as much of string as fits. */ | |
6269 | thiswidth = XSTRING (desc)->size; | |
6270 | if (thiswidth + i > width) | |
6271 | thiswidth = width - i; | |
6272 | bcopy (XSTRING (desc)->data, menu + i, thiswidth); | |
6273 | i += thiswidth; | |
6274 | strcpy (menu + i, " = "); | |
6275 | i += 3; | |
6276 | } | |
6277 | ||
6278 | /* Add as much of string as fits. */ | |
6279 | thiswidth = XSTRING (s)->size; | |
6280 | if (thiswidth + i > width) | |
6281 | thiswidth = width - i; | |
6282 | bcopy (XSTRING (s)->data, menu + i, thiswidth); | |
6283 | i += thiswidth; | |
6284 | menu[i] = 0; | |
6285 | } | |
6286 | else | |
7d6de002 | 6287 | { |
0a2ea221 KH |
6288 | /* If this element does not fit, end the line now, |
6289 | and save the element for the next line. */ | |
6290 | strcpy (menu + i, "..."); | |
6291 | break; | |
7d6de002 | 6292 | } |
7d6de002 RS |
6293 | } |
6294 | ||
6295 | /* Move past this element. */ | |
8150596a | 6296 | if (idx >= 0 && idx + 1 >= XVECTOR (vector)->size) |
7d6de002 RS |
6297 | /* Handle reaching end of dense table. */ |
6298 | idx = -1; | |
6299 | if (idx >= 0) | |
6300 | idx++; | |
6301 | else | |
6302 | rest = Fcdr_safe (rest); | |
6303 | } | |
284f4730 JB |
6304 | } |
6305 | ||
6306 | /* Prompt with that and read response. */ | |
301738ed RS |
6307 | message2_nolog (menu, strlen (menu), |
6308 | ! NILP (current_buffer->enable_multibyte_characters)); | |
8150596a | 6309 | |
df0f2ba1 | 6310 | /* Make believe its not a keyboard macro in case the help char |
8150596a RS |
6311 | is pressed. Help characters are not recorded because menu prompting |
6312 | is not used on replay. | |
6313 | */ | |
c5fdd383 KH |
6314 | orig_defn_macro = current_kboard->defining_kbd_macro; |
6315 | current_kboard->defining_kbd_macro = Qnil; | |
3cb81011 KH |
6316 | do |
6317 | obj = read_char (commandflag, 0, 0, Qnil, 0); | |
8c18cbfb | 6318 | while (BUFFERP (obj)); |
c5fdd383 | 6319 | current_kboard->defining_kbd_macro = orig_defn_macro; |
284f4730 | 6320 | |
8c18cbfb | 6321 | if (!INTEGERP (obj)) |
284f4730 JB |
6322 | return obj; |
6323 | else | |
6324 | ch = XINT (obj); | |
6325 | ||
f4255cd1 | 6326 | if (! EQ (obj, menu_prompt_more_char) |
8c18cbfb | 6327 | && (!INTEGERP (menu_prompt_more_char) |
f4255cd1 | 6328 | || ! EQ (obj, make_number (Ctl (XINT (menu_prompt_more_char)))))) |
8150596a | 6329 | { |
c5fdd383 | 6330 | if (!NILP (current_kboard->defining_kbd_macro)) |
8066f1a1 | 6331 | store_kbd_macro_char (obj); |
8150596a RS |
6332 | return obj; |
6333 | } | |
6334 | /* Help char - go round again */ | |
284f4730 JB |
6335 | } |
6336 | } | |
284f4730 JB |
6337 | \f |
6338 | /* Reading key sequences. */ | |
6339 | ||
6340 | /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings | |
6341 | in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a | |
6342 | keymap, or nil otherwise. Return the index of the first keymap in | |
6343 | which KEY has any binding, or NMAPS if no map has a binding. | |
6344 | ||
6345 | If KEY is a meta ASCII character, treat it like meta-prefix-char | |
6346 | followed by the corresponding non-meta character. Keymaps in | |
6347 | CURRENT with non-prefix bindings for meta-prefix-char become nil in | |
6348 | NEXT. | |
6349 | ||
88cb0656 JB |
6350 | If KEY has no bindings in any of the CURRENT maps, NEXT is left |
6351 | unmodified. | |
6352 | ||
569871d2 | 6353 | NEXT may be the same array as CURRENT. */ |
284f4730 JB |
6354 | |
6355 | static int | |
4e50f26a | 6356 | follow_key (key, nmaps, current, defs, next) |
284f4730 JB |
6357 | Lisp_Object key; |
6358 | Lisp_Object *current, *defs, *next; | |
6359 | int nmaps; | |
6360 | { | |
6361 | int i, first_binding; | |
569871d2 | 6362 | int did_meta = 0; |
284f4730 JB |
6363 | |
6364 | /* If KEY is a meta ASCII character, treat it like meta-prefix-char | |
569871d2 RS |
6365 | followed by the corresponding non-meta character. |
6366 | Put the results into DEFS, since we are going to alter that anyway. | |
6367 | Do not alter CURRENT or NEXT. */ | |
8c18cbfb | 6368 | if (INTEGERP (key) && (XINT (key) & CHAR_META)) |
284f4730 JB |
6369 | { |
6370 | for (i = 0; i < nmaps; i++) | |
6371 | if (! NILP (current[i])) | |
6372 | { | |
569871d2 RS |
6373 | Lisp_Object def; |
6374 | def = get_keyelt (access_keymap (current[i], | |
c6a67acd | 6375 | meta_prefix_char, 1, 0), 0); |
284f4730 JB |
6376 | |
6377 | /* Note that since we pass the resulting bindings through | |
6378 | get_keymap_1, non-prefix bindings for meta-prefix-char | |
6379 | disappear. */ | |
569871d2 | 6380 | defs[i] = get_keymap_1 (def, 0, 1); |
284f4730 JB |
6381 | } |
6382 | else | |
569871d2 | 6383 | defs[i] = Qnil; |
284f4730 | 6384 | |
569871d2 | 6385 | did_meta = 1; |
18cd2eeb | 6386 | XSETINT (key, XFASTINT (key) & ~CHAR_META); |
284f4730 JB |
6387 | } |
6388 | ||
6389 | first_binding = nmaps; | |
6390 | for (i = nmaps - 1; i >= 0; i--) | |
6391 | { | |
6392 | if (! NILP (current[i])) | |
6393 | { | |
569871d2 RS |
6394 | Lisp_Object map; |
6395 | if (did_meta) | |
6396 | map = defs[i]; | |
6397 | else | |
6398 | map = current[i]; | |
6399 | ||
c6a67acd | 6400 | defs[i] = get_keyelt (access_keymap (map, key, 1, 0), 0); |
284f4730 JB |
6401 | if (! NILP (defs[i])) |
6402 | first_binding = i; | |
6403 | } | |
6404 | else | |
6405 | defs[i] = Qnil; | |
6406 | } | |
6407 | ||
284f4730 | 6408 | /* Given the set of bindings we've found, produce the next set of maps. */ |
0a7f1fc0 JB |
6409 | if (first_binding < nmaps) |
6410 | for (i = 0; i < nmaps; i++) | |
f4255cd1 | 6411 | next[i] = NILP (defs[i]) ? Qnil : get_keymap_1 (defs[i], 0, 1); |
284f4730 JB |
6412 | |
6413 | return first_binding; | |
6414 | } | |
6415 | ||
df0f2ba1 | 6416 | /* Read a sequence of keys that ends with a non prefix character, |
f4255cd1 JB |
6417 | storing it in KEYBUF, a buffer of size BUFSIZE. |
6418 | Prompt with PROMPT. | |
284f4730 | 6419 | Return the length of the key sequence stored. |
dcc408a0 | 6420 | Return -1 if the user rejected a command menu. |
284f4730 | 6421 | |
f4255cd1 JB |
6422 | Echo starting immediately unless `prompt' is 0. |
6423 | ||
6424 | Where a key sequence ends depends on the currently active keymaps. | |
6425 | These include any minor mode keymaps active in the current buffer, | |
6426 | the current buffer's local map, and the global map. | |
6427 | ||
6428 | If a key sequence has no other bindings, we check Vfunction_key_map | |
6429 | to see if some trailing subsequence might be the beginning of a | |
6430 | function key's sequence. If so, we try to read the whole function | |
6431 | key, and substitute its symbolic name into the key sequence. | |
6432 | ||
fbcd35bd JB |
6433 | We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and |
6434 | `double-' events into similar click events, if that would make them | |
6435 | bound. We try to turn `triple-' events first into `double-' events, | |
6436 | then into clicks. | |
f4255cd1 JB |
6437 | |
6438 | If we get a mouse click in a mode line, vertical divider, or other | |
6439 | non-text area, we treat the click as if it were prefixed by the | |
6440 | symbol denoting that area - `mode-line', `vertical-line', or | |
6441 | whatever. | |
6442 | ||
6443 | If the sequence starts with a mouse click, we read the key sequence | |
6444 | with respect to the buffer clicked on, not the current buffer. | |
284f4730 | 6445 | |
f4255cd1 JB |
6446 | If the user switches frames in the midst of a key sequence, we put |
6447 | off the switch-frame event until later; the next call to | |
f571ae0d RS |
6448 | read_char will return it. |
6449 | ||
6450 | If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer | |
6451 | from the selected window's buffer. */ | |
48e416d4 | 6452 | |
284f4730 | 6453 | static int |
ce98e608 | 6454 | read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last, |
f571ae0d | 6455 | can_return_switch_frame, fix_current_buffer) |
284f4730 JB |
6456 | Lisp_Object *keybuf; |
6457 | int bufsize; | |
84d91fda | 6458 | Lisp_Object prompt; |
309b0fc8 | 6459 | int dont_downcase_last; |
ce98e608 | 6460 | int can_return_switch_frame; |
f571ae0d | 6461 | int fix_current_buffer; |
284f4730 | 6462 | { |
f4255cd1 JB |
6463 | int count = specpdl_ptr - specpdl; |
6464 | ||
284f4730 JB |
6465 | /* How many keys there are in the current key sequence. */ |
6466 | int t; | |
6467 | ||
284f4730 JB |
6468 | /* The length of the echo buffer when we started reading, and |
6469 | the length of this_command_keys when we started reading. */ | |
6470 | int echo_start; | |
f4255cd1 | 6471 | int keys_start; |
284f4730 JB |
6472 | |
6473 | /* The number of keymaps we're scanning right now, and the number of | |
6474 | keymaps we have allocated space for. */ | |
6475 | int nmaps; | |
6476 | int nmaps_allocated = 0; | |
6477 | ||
284f4730 JB |
6478 | /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in |
6479 | the current keymaps. */ | |
6480 | Lisp_Object *defs; | |
6481 | ||
f4255cd1 JB |
6482 | /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] |
6483 | in the current keymaps, or nil where it is not a prefix. */ | |
6484 | Lisp_Object *submaps; | |
6485 | ||
e0dff5f6 RS |
6486 | /* The local map to start out with at start of key sequence. */ |
6487 | Lisp_Object orig_local_map; | |
6488 | ||
6489 | /* 1 if we have already considered switching to the local-map property | |
6490 | of the place where a mouse click occurred. */ | |
6491 | int localized_local_map = 0; | |
6492 | ||
f4255cd1 JB |
6493 | /* The index in defs[] of the first keymap that has a binding for |
6494 | this key sequence. In other words, the lowest i such that | |
6495 | defs[i] is non-nil. */ | |
284f4730 JB |
6496 | int first_binding; |
6497 | ||
f4255cd1 | 6498 | /* If t < mock_input, then KEYBUF[t] should be read as the next |
253598e4 JB |
6499 | input key. |
6500 | ||
6501 | We use this to recover after recognizing a function key. Once we | |
6502 | realize that a suffix of the current key sequence is actually a | |
6503 | function key's escape sequence, we replace the suffix with the | |
6504 | function key's binding from Vfunction_key_map. Now keybuf | |
f4255cd1 JB |
6505 | contains a new and different key sequence, so the echo area, |
6506 | this_command_keys, and the submaps and defs arrays are wrong. In | |
6507 | this situation, we set mock_input to t, set t to 0, and jump to | |
6508 | restart_sequence; the loop will read keys from keybuf up until | |
6509 | mock_input, thus rebuilding the state; and then it will resume | |
6510 | reading characters from the keyboard. */ | |
284f4730 JB |
6511 | int mock_input = 0; |
6512 | ||
253598e4 | 6513 | /* If the sequence is unbound in submaps[], then |
f4255cd1 JB |
6514 | keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map, |
6515 | and fkey_map is its binding. | |
253598e4 | 6516 | |
f4255cd1 JB |
6517 | These might be > t, indicating that all function key scanning |
6518 | should hold off until t reaches them. We do this when we've just | |
6519 | recognized a function key, to avoid searching for the function | |
6520 | key's again in Vfunction_key_map. */ | |
284f4730 | 6521 | int fkey_start = 0, fkey_end = 0; |
4efda7dd | 6522 | Lisp_Object fkey_map; |
284f4730 | 6523 | |
a612e298 RS |
6524 | /* Likewise, for key_translation_map. */ |
6525 | int keytran_start = 0, keytran_end = 0; | |
6526 | Lisp_Object keytran_map; | |
6527 | ||
cd21b839 JB |
6528 | /* If we receive a ``switch-frame'' event in the middle of a key sequence, |
6529 | we put it off for later. While we're reading, we keep the event here. */ | |
4efda7dd | 6530 | Lisp_Object delayed_switch_frame; |
cd21b839 | 6531 | |
51763820 BF |
6532 | /* See the comment below... */ |
6533 | #if defined (GOBBLE_FIRST_EVENT) | |
4efda7dd | 6534 | Lisp_Object first_event; |
51763820 | 6535 | #endif |
4efda7dd | 6536 | |
309b0fc8 RS |
6537 | Lisp_Object original_uppercase; |
6538 | int original_uppercase_position = -1; | |
6539 | ||
bc536d84 | 6540 | /* Gets around Microsoft compiler limitations. */ |
309b0fc8 | 6541 | int dummyflag = 0; |
bc536d84 | 6542 | |
3b9189f8 RS |
6543 | struct buffer *starting_buffer; |
6544 | ||
e9bf89a0 RS |
6545 | /* Nonzero if we seem to have got the beginning of a binding |
6546 | in function_key_map. */ | |
6547 | int function_key_possible = 0; | |
00a78037 | 6548 | int key_translation_possible = 0; |
e9bf89a0 | 6549 | |
3fe8e9a2 RS |
6550 | /* Save the status of key translation before each step, |
6551 | so that we can restore this after downcasing. */ | |
6552 | Lisp_Object prev_fkey_map; | |
3fdfceb3 RS |
6553 | int prev_fkey_start; |
6554 | int prev_fkey_end; | |
3fe8e9a2 RS |
6555 | |
6556 | Lisp_Object prev_keytran_map; | |
3fdfceb3 RS |
6557 | int prev_keytran_start; |
6558 | int prev_keytran_end; | |
3fe8e9a2 | 6559 | |
4efda7dd RS |
6560 | int junk; |
6561 | ||
6562 | last_nonmenu_event = Qnil; | |
6563 | ||
6564 | delayed_switch_frame = Qnil; | |
6565 | fkey_map = Vfunction_key_map; | |
a612e298 | 6566 | keytran_map = Vkey_translation_map; |
f4255cd1 | 6567 | |
a612e298 | 6568 | /* If there is no function-key-map, turn off function key scanning. */ |
f4255cd1 JB |
6569 | if (NILP (Fkeymapp (Vfunction_key_map))) |
6570 | fkey_start = fkey_end = bufsize + 1; | |
6571 | ||
a612e298 RS |
6572 | /* If there is no key-translation-map, turn off scanning. */ |
6573 | if (NILP (Fkeymapp (Vkey_translation_map))) | |
6574 | keytran_start = keytran_end = bufsize + 1; | |
6575 | ||
284f4730 JB |
6576 | if (INTERACTIVE) |
6577 | { | |
84d91fda RS |
6578 | if (!NILP (prompt)) |
6579 | echo_prompt (XSTRING (prompt)->data); | |
a98ea3f9 | 6580 | else if (cursor_in_echo_area && echo_keystrokes) |
284f4730 JB |
6581 | /* This doesn't put in a dash if the echo buffer is empty, so |
6582 | you don't always see a dash hanging out in the minibuffer. */ | |
6583 | echo_dash (); | |
284f4730 JB |
6584 | } |
6585 | ||
f4255cd1 JB |
6586 | /* Record the initial state of the echo area and this_command_keys; |
6587 | we will need to restore them if we replay a key sequence. */ | |
0a7f1fc0 | 6588 | if (INTERACTIVE) |
df0f2ba1 | 6589 | echo_start = echo_length (); |
f4255cd1 | 6590 | keys_start = this_command_key_count; |
6321824f | 6591 | this_single_command_key_start = keys_start; |
0a7f1fc0 | 6592 | |
51763820 BF |
6593 | #if defined (GOBBLE_FIRST_EVENT) |
6594 | /* This doesn't quite work, because some of the things that read_char | |
6595 | does cannot safely be bypassed. It seems too risky to try to make | |
df0f2ba1 | 6596 | this work right. */ |
51763820 | 6597 | |
4efda7dd RS |
6598 | /* Read the first char of the sequence specially, before setting |
6599 | up any keymaps, in case a filter runs and switches buffers on us. */ | |
84d91fda | 6600 | first_event = read_char (NILP (prompt), 0, submaps, last_nonmenu_event, |
4efda7dd | 6601 | &junk); |
51763820 | 6602 | #endif /* GOBBLE_FIRST_EVENT */ |
4efda7dd | 6603 | |
e0dff5f6 RS |
6604 | orig_local_map = get_local_map (PT, current_buffer); |
6605 | ||
7b4aedb9 JB |
6606 | /* We jump here when the key sequence has been thoroughly changed, and |
6607 | we need to rescan it starting from the beginning. When we jump here, | |
6608 | keybuf[0..mock_input] holds the sequence we should reread. */ | |
07d2b8de | 6609 | replay_sequence: |
7b4aedb9 | 6610 | |
3b9189f8 | 6611 | starting_buffer = current_buffer; |
e9bf89a0 | 6612 | function_key_possible = 0; |
00a78037 | 6613 | key_translation_possible = 0; |
3b9189f8 | 6614 | |
f4255cd1 | 6615 | /* Build our list of keymaps. |
07d2b8de JB |
6616 | If we recognize a function key and replace its escape sequence in |
6617 | keybuf with its symbol, or if the sequence starts with a mouse | |
6618 | click and we need to switch buffers, we jump back here to rebuild | |
6619 | the initial keymaps from the current buffer. */ | |
df0f2ba1 | 6620 | { |
284f4730 JB |
6621 | Lisp_Object *maps; |
6622 | ||
217258d5 KH |
6623 | if (!NILP (current_kboard->Voverriding_terminal_local_map) |
6624 | || !NILP (Voverriding_local_map)) | |
284f4730 | 6625 | { |
217258d5 | 6626 | if (3 > nmaps_allocated) |
9dd3131c | 6627 | { |
217258d5 KH |
6628 | submaps = (Lisp_Object *) alloca (3 * sizeof (submaps[0])); |
6629 | defs = (Lisp_Object *) alloca (3 * sizeof (defs[0])); | |
6630 | nmaps_allocated = 3; | |
9dd3131c | 6631 | } |
217258d5 KH |
6632 | nmaps = 0; |
6633 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
6634 | submaps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
6635 | if (!NILP (Voverriding_local_map)) | |
6636 | submaps[nmaps++] = Voverriding_local_map; | |
284f4730 | 6637 | } |
9dd3131c RS |
6638 | else |
6639 | { | |
217258d5 KH |
6640 | nmaps = current_minor_maps (0, &maps); |
6641 | if (nmaps + 2 > nmaps_allocated) | |
9dd3131c | 6642 | { |
217258d5 KH |
6643 | submaps = (Lisp_Object *) alloca ((nmaps+2) * sizeof (submaps[0])); |
6644 | defs = (Lisp_Object *) alloca ((nmaps+2) * sizeof (defs[0])); | |
6645 | nmaps_allocated = nmaps + 2; | |
9dd3131c | 6646 | } |
217258d5 | 6647 | bcopy (maps, submaps, nmaps * sizeof (submaps[0])); |
497ba7a1 | 6648 | #ifdef USE_TEXT_PROPERTIES |
217258d5 | 6649 | submaps[nmaps++] = orig_local_map; |
497ba7a1 | 6650 | #else |
217258d5 | 6651 | submaps[nmaps++] = current_buffer->keymap; |
497ba7a1 | 6652 | #endif |
9dd3131c | 6653 | } |
217258d5 | 6654 | submaps[nmaps++] = current_global_map; |
284f4730 JB |
6655 | } |
6656 | ||
6657 | /* Find an accurate initial value for first_binding. */ | |
6658 | for (first_binding = 0; first_binding < nmaps; first_binding++) | |
253598e4 | 6659 | if (! NILP (submaps[first_binding])) |
284f4730 JB |
6660 | break; |
6661 | ||
3b9189f8 | 6662 | /* Start from the beginning in keybuf. */ |
f4255cd1 JB |
6663 | t = 0; |
6664 | ||
6665 | /* These are no-ops the first time through, but if we restart, they | |
6666 | revert the echo area and this_command_keys to their original state. */ | |
6667 | this_command_key_count = keys_start; | |
df0f2ba1 | 6668 | if (INTERACTIVE && t < mock_input) |
f4255cd1 JB |
6669 | echo_truncate (echo_start); |
6670 | ||
cca310da JB |
6671 | /* If the best binding for the current key sequence is a keymap, or |
6672 | we may be looking at a function key's escape sequence, keep on | |
6673 | reading. */ | |
253598e4 | 6674 | while ((first_binding < nmaps && ! NILP (submaps[first_binding])) |
cca310da JB |
6675 | || (first_binding >= nmaps |
6676 | && fkey_start < t | |
6677 | /* mock input is never part of a function key's sequence. */ | |
a612e298 | 6678 | && mock_input <= fkey_start) |
0d882d52 KH |
6679 | || (first_binding >= nmaps |
6680 | && keytran_start < t && key_translation_possible) | |
e9bf89a0 RS |
6681 | /* Don't return in the middle of a possible function key sequence, |
6682 | if the only bindings we found were via case conversion. | |
6683 | Thus, if ESC O a has a function-key-map translation | |
6684 | and ESC o has a binding, don't return after ESC O, | |
6685 | so that we can translate ESC O plus the next character. */ | |
4e50f26a | 6686 | ) |
284f4730 JB |
6687 | { |
6688 | Lisp_Object key; | |
7d6de002 | 6689 | int used_mouse_menu = 0; |
284f4730 | 6690 | |
7b4aedb9 JB |
6691 | /* Where the last real key started. If we need to throw away a |
6692 | key that has expanded into more than one element of keybuf | |
6693 | (say, a mouse click on the mode line which is being treated | |
6694 | as [mode-line (mouse-...)], then we backtrack to this point | |
6695 | of keybuf. */ | |
6696 | int last_real_key_start; | |
6697 | ||
0a7f1fc0 JB |
6698 | /* These variables are analogous to echo_start and keys_start; |
6699 | while those allow us to restart the entire key sequence, | |
6700 | echo_local_start and keys_local_start allow us to throw away | |
6701 | just one key. */ | |
f4255cd1 JB |
6702 | int echo_local_start, keys_local_start, local_first_binding; |
6703 | ||
284f4730 | 6704 | if (t >= bufsize) |
3fe8e9a2 | 6705 | error ("Key sequence too long"); |
284f4730 | 6706 | |
f4255cd1 JB |
6707 | if (INTERACTIVE) |
6708 | echo_local_start = echo_length (); | |
6709 | keys_local_start = this_command_key_count; | |
6710 | local_first_binding = first_binding; | |
df0f2ba1 | 6711 | |
f4255cd1 | 6712 | replay_key: |
0a7f1fc0 | 6713 | /* These are no-ops, unless we throw away a keystroke below and |
f4255cd1 JB |
6714 | jumped back up to replay_key; in that case, these restore the |
6715 | variables to their original state, allowing us to replay the | |
0a7f1fc0 | 6716 | loop. */ |
40932d1a | 6717 | if (INTERACTIVE && t < mock_input) |
f4255cd1 | 6718 | echo_truncate (echo_local_start); |
0a7f1fc0 JB |
6719 | this_command_key_count = keys_local_start; |
6720 | first_binding = local_first_binding; | |
6721 | ||
7e85b935 RS |
6722 | /* By default, assume each event is "real". */ |
6723 | last_real_key_start = t; | |
6724 | ||
f4255cd1 | 6725 | /* Does mock_input indicate that we are re-reading a key sequence? */ |
284f4730 JB |
6726 | if (t < mock_input) |
6727 | { | |
6728 | key = keybuf[t]; | |
6729 | add_command_key (key); | |
a98ea3f9 RS |
6730 | if (echo_keystrokes) |
6731 | echo_char (key); | |
284f4730 | 6732 | } |
253598e4 JB |
6733 | |
6734 | /* If not, we should actually read a character. */ | |
284f4730 JB |
6735 | else |
6736 | { | |
a6d53864 RS |
6737 | struct buffer *buf = current_buffer; |
6738 | ||
beecf6a1 | 6739 | { |
c5fdd383 KH |
6740 | #ifdef MULTI_KBOARD |
6741 | KBOARD *interrupted_kboard = current_kboard; | |
df0f2ba1 | 6742 | struct frame *interrupted_frame = selected_frame; |
c5fdd383 | 6743 | if (setjmp (wrong_kboard_jmpbuf)) |
beecf6a1 | 6744 | { |
5798cf15 KH |
6745 | if (!NILP (delayed_switch_frame)) |
6746 | { | |
c5fdd383 | 6747 | interrupted_kboard->kbd_queue |
5798cf15 | 6748 | = Fcons (delayed_switch_frame, |
c5fdd383 | 6749 | interrupted_kboard->kbd_queue); |
5798cf15 KH |
6750 | delayed_switch_frame = Qnil; |
6751 | } | |
beecf6a1 | 6752 | while (t > 0) |
c5fdd383 KH |
6753 | interrupted_kboard->kbd_queue |
6754 | = Fcons (keybuf[--t], interrupted_kboard->kbd_queue); | |
5798cf15 KH |
6755 | |
6756 | /* If the side queue is non-empty, ensure it begins with a | |
6757 | switch-frame, so we'll replay it in the right context. */ | |
c5fdd383 KH |
6758 | if (CONSP (interrupted_kboard->kbd_queue) |
6759 | && (key = XCONS (interrupted_kboard->kbd_queue)->car, | |
5798cf15 KH |
6760 | !(EVENT_HAS_PARAMETERS (key) |
6761 | && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key)), | |
6762 | Qswitch_frame)))) | |
df0f2ba1 KH |
6763 | { |
6764 | Lisp_Object frame; | |
6765 | XSETFRAME (frame, interrupted_frame); | |
c5fdd383 | 6766 | interrupted_kboard->kbd_queue |
df0f2ba1 | 6767 | = Fcons (make_lispy_switch_frame (frame), |
c5fdd383 | 6768 | interrupted_kboard->kbd_queue); |
df0f2ba1 | 6769 | } |
beecf6a1 | 6770 | mock_input = 0; |
a6e0153c | 6771 | orig_local_map = get_local_map (PT, current_buffer); |
beecf6a1 KH |
6772 | goto replay_sequence; |
6773 | } | |
bded54dd | 6774 | #endif |
beecf6a1 KH |
6775 | key = read_char (NILP (prompt), nmaps, submaps, last_nonmenu_event, |
6776 | &used_mouse_menu); | |
6777 | } | |
284f4730 | 6778 | |
dcc408a0 RS |
6779 | /* read_char returns t when it shows a menu and the user rejects it. |
6780 | Just return -1. */ | |
6781 | if (EQ (key, Qt)) | |
6782 | return -1; | |
6783 | ||
f4255cd1 | 6784 | /* read_char returns -1 at the end of a macro. |
284f4730 JB |
6785 | Emacs 18 handles this by returning immediately with a |
6786 | zero, so that's what we'll do. */ | |
8c18cbfb | 6787 | if (INTEGERP (key) && XINT (key) == -1) |
cd21b839 | 6788 | { |
f4255cd1 | 6789 | t = 0; |
bc536d84 RS |
6790 | /* The Microsoft C compiler can't handle the goto that |
6791 | would go here. */ | |
309b0fc8 | 6792 | dummyflag = 1; |
bc536d84 | 6793 | break; |
cd21b839 | 6794 | } |
df0f2ba1 | 6795 | |
3cb81011 KH |
6796 | /* If the current buffer has been changed from under us, the |
6797 | keymap may have changed, so replay the sequence. */ | |
8c18cbfb | 6798 | if (BUFFERP (key)) |
3cb81011 KH |
6799 | { |
6800 | mock_input = t; | |
f571ae0d RS |
6801 | /* Reset the current buffer from the selected window |
6802 | in case something changed the former and not the latter. | |
6803 | This is to be more consistent with the behavior | |
6804 | of the command_loop_1. */ | |
6805 | if (fix_current_buffer) | |
6806 | if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
6807 | Fset_buffer (XWINDOW (selected_window)->buffer); | |
6808 | ||
a6e0153c | 6809 | orig_local_map = get_local_map (PT, current_buffer); |
3cb81011 KH |
6810 | goto replay_sequence; |
6811 | } | |
6812 | ||
3b9189f8 RS |
6813 | /* If we have a quit that was typed in another frame, and |
6814 | quit_throw_to_read_char switched buffers, | |
6815 | replay to get the right keymap. */ | |
9343ab07 | 6816 | if (XINT (key) == quit_char && current_buffer != starting_buffer) |
3b9189f8 RS |
6817 | { |
6818 | keybuf[t++] = key; | |
6819 | mock_input = t; | |
6820 | Vquit_flag = Qnil; | |
a6e0153c | 6821 | orig_local_map = get_local_map (PT, current_buffer); |
3b9189f8 RS |
6822 | goto replay_sequence; |
6823 | } | |
3cb81011 | 6824 | |
284f4730 | 6825 | Vquit_flag = Qnil; |
7e85b935 | 6826 | } |
284f4730 | 6827 | |
df0f2ba1 | 6828 | /* Clicks in non-text areas get prefixed by the symbol |
7e85b935 RS |
6829 | in their CHAR-ADDRESS field. For example, a click on |
6830 | the mode line is prefixed by the symbol `mode-line'. | |
6831 | ||
6832 | Furthermore, key sequences beginning with mouse clicks | |
6833 | are read using the keymaps of the buffer clicked on, not | |
6834 | the current buffer. So we may have to switch the buffer | |
6835 | here. | |
6836 | ||
6837 | When we turn one event into two events, we must make sure | |
6838 | that neither of the two looks like the original--so that, | |
6839 | if we replay the events, they won't be expanded again. | |
6840 | If not for this, such reexpansion could happen either here | |
6841 | or when user programs play with this-command-keys. */ | |
6842 | if (EVENT_HAS_PARAMETERS (key)) | |
6843 | { | |
9b8eb840 | 6844 | Lisp_Object kind; |
cca310da | 6845 | |
9b8eb840 | 6846 | kind = EVENT_HEAD_KIND (EVENT_HEAD (key)); |
7e85b935 | 6847 | if (EQ (kind, Qmouse_click)) |
0a7f1fc0 | 6848 | { |
9b8eb840 | 6849 | Lisp_Object window, posn; |
f4255cd1 | 6850 | |
9b8eb840 KH |
6851 | window = POSN_WINDOW (EVENT_START (key)); |
6852 | posn = POSN_BUFFER_POSN (EVENT_START (key)); | |
8c18cbfb | 6853 | if (CONSP (posn)) |
0a7f1fc0 | 6854 | { |
7e85b935 RS |
6855 | /* We're looking at the second event of a |
6856 | sequence which we expanded before. Set | |
6857 | last_real_key_start appropriately. */ | |
6858 | if (t > 0) | |
6859 | last_real_key_start = t - 1; | |
cd21b839 | 6860 | } |
7e85b935 RS |
6861 | |
6862 | /* Key sequences beginning with mouse clicks are | |
6863 | read using the keymaps in the buffer clicked on, | |
6864 | not the current buffer. If we're at the | |
6865 | beginning of a key sequence, switch buffers. */ | |
6866 | if (last_real_key_start == 0 | |
8c18cbfb KH |
6867 | && WINDOWP (window) |
6868 | && BUFFERP (XWINDOW (window)->buffer) | |
7e85b935 | 6869 | && XBUFFER (XWINDOW (window)->buffer) != current_buffer) |
cd21b839 | 6870 | { |
7e85b935 RS |
6871 | keybuf[t] = key; |
6872 | mock_input = t + 1; | |
6873 | ||
6874 | /* Arrange to go back to the original buffer once we're | |
6875 | done reading the key sequence. Note that we can't | |
6876 | use save_excursion_{save,restore} here, because they | |
6877 | save point as well as the current buffer; we don't | |
6878 | want to save point, because redisplay may change it, | |
6879 | to accommodate a Fset_window_start or something. We | |
6880 | don't want to do this at the top of the function, | |
6881 | because we may get input from a subprocess which | |
6882 | wants to change the selected window and stuff (say, | |
6883 | emacsclient). */ | |
6884 | record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
6885 | ||
6886 | set_buffer_internal (XBUFFER (XWINDOW (window)->buffer)); | |
e0dff5f6 | 6887 | orig_local_map = get_local_map (PT, current_buffer); |
7e85b935 | 6888 | goto replay_sequence; |
0a7f1fc0 | 6889 | } |
e0dff5f6 RS |
6890 | /* For a mouse click, get the local text-property keymap |
6891 | of the place clicked on, rather than point. */ | |
6892 | if (last_real_key_start == 0 && CONSP (XCONS (key)->cdr) | |
6893 | && ! localized_local_map) | |
5ec75a55 | 6894 | { |
e0dff5f6 RS |
6895 | Lisp_Object map_here, start, pos; |
6896 | ||
6897 | localized_local_map = 1; | |
6898 | start = EVENT_START (key); | |
6899 | if (CONSP (start) && CONSP (XCONS (start)->cdr)) | |
6900 | { | |
6901 | pos = POSN_BUFFER_POSN (start); | |
b78ce8fb RS |
6902 | if (INTEGERP (pos) |
6903 | && XINT (pos) >= BEG && XINT (pos) <= Z) | |
e0dff5f6 RS |
6904 | { |
6905 | map_here = get_local_map (XINT (pos), current_buffer); | |
6906 | if (!EQ (map_here, orig_local_map)) | |
6907 | { | |
6908 | orig_local_map = map_here; | |
6909 | keybuf[t] = key; | |
6910 | mock_input = t + 1; | |
5ec75a55 | 6911 | |
e0dff5f6 RS |
6912 | goto replay_sequence; |
6913 | } | |
6914 | } | |
6915 | } | |
6916 | } | |
6917 | ||
6918 | /* Expand mode-line and scroll-bar events into two events: | |
6919 | use posn as a fake prefix key. */ | |
6920 | if (SYMBOLP (posn)) | |
6921 | { | |
7e85b935 | 6922 | if (t + 1 >= bufsize) |
3fe8e9a2 | 6923 | error ("Key sequence too long"); |
7e85b935 RS |
6924 | keybuf[t] = posn; |
6925 | keybuf[t+1] = key; | |
6926 | mock_input = t + 2; | |
6927 | ||
6928 | /* Zap the position in key, so we know that we've | |
6929 | expanded it, and don't try to do so again. */ | |
6930 | POSN_BUFFER_POSN (EVENT_START (key)) | |
6931 | = Fcons (posn, Qnil); | |
6932 | goto replay_key; | |
5ec75a55 | 6933 | } |
0a7f1fc0 | 6934 | } |
7e85b935 | 6935 | else if (EQ (kind, Qswitch_frame)) |
a6d53864 | 6936 | { |
ce98e608 KH |
6937 | /* If we're at the beginning of a key sequence, and the caller |
6938 | says it's okay, go ahead and return this event. If we're | |
6939 | in the midst of a key sequence, delay it until the end. */ | |
6940 | if (t > 0 || !can_return_switch_frame) | |
7e85b935 RS |
6941 | { |
6942 | delayed_switch_frame = key; | |
6943 | goto replay_key; | |
6944 | } | |
6945 | } | |
7a80a6f6 RS |
6946 | else if (CONSP (XCONS (key)->cdr) |
6947 | && CONSP (EVENT_START (key)) | |
6948 | && CONSP (XCONS (EVENT_START (key))->cdr)) | |
7e85b935 | 6949 | { |
9b8eb840 | 6950 | Lisp_Object posn; |
7e85b935 | 6951 | |
9b8eb840 | 6952 | posn = POSN_BUFFER_POSN (EVENT_START (key)); |
7e85b935 RS |
6953 | /* Handle menu-bar events: |
6954 | insert the dummy prefix event `menu-bar'. */ | |
6955 | if (EQ (posn, Qmenu_bar)) | |
6956 | { | |
6957 | if (t + 1 >= bufsize) | |
3fe8e9a2 | 6958 | error ("Key sequence too long"); |
7e85b935 RS |
6959 | keybuf[t] = posn; |
6960 | keybuf[t+1] = key; | |
6961 | ||
6962 | /* Zap the position in key, so we know that we've | |
6963 | expanded it, and don't try to do so again. */ | |
6964 | POSN_BUFFER_POSN (EVENT_START (key)) | |
6965 | = Fcons (posn, Qnil); | |
6966 | ||
6967 | mock_input = t + 2; | |
6968 | goto replay_sequence; | |
6969 | } | |
8c18cbfb | 6970 | else if (CONSP (posn)) |
7e85b935 RS |
6971 | { |
6972 | /* We're looking at the second event of a | |
6973 | sequence which we expanded before. Set | |
6974 | last_real_key_start appropriately. */ | |
6975 | if (last_real_key_start == t && t > 0) | |
6976 | last_real_key_start = t - 1; | |
6977 | } | |
a6d53864 | 6978 | } |
284f4730 | 6979 | } |
f4255cd1 JB |
6980 | |
6981 | /* We have finally decided that KEY is something we might want | |
6982 | to look up. */ | |
284f4730 JB |
6983 | first_binding = (follow_key (key, |
6984 | nmaps - first_binding, | |
253598e4 | 6985 | submaps + first_binding, |
284f4730 | 6986 | defs + first_binding, |
4e50f26a | 6987 | submaps + first_binding) |
284f4730 | 6988 | + first_binding); |
0a7f1fc0 | 6989 | |
f4255cd1 | 6990 | /* If KEY wasn't bound, we'll try some fallbacks. */ |
0a7f1fc0 JB |
6991 | if (first_binding >= nmaps) |
6992 | { | |
9b8eb840 | 6993 | Lisp_Object head; |
0a7f1fc0 | 6994 | |
9b8eb840 | 6995 | head = EVENT_HEAD (key); |
24736fbc | 6996 | if (help_char_p (head) && t > 0) |
7e85b935 RS |
6997 | { |
6998 | read_key_sequence_cmd = Vprefix_help_command; | |
6999 | keybuf[t++] = key; | |
7000 | last_nonmenu_event = key; | |
bc536d84 RS |
7001 | /* The Microsoft C compiler can't handle the goto that |
7002 | would go here. */ | |
309b0fc8 | 7003 | dummyflag = 1; |
0d882d52 | 7004 | break; |
7e85b935 RS |
7005 | } |
7006 | ||
8c18cbfb | 7007 | if (SYMBOLP (head)) |
0a7f1fc0 | 7008 | { |
9b8eb840 KH |
7009 | Lisp_Object breakdown; |
7010 | int modifiers; | |
0a7f1fc0 | 7011 | |
9b8eb840 KH |
7012 | breakdown = parse_modifiers (head); |
7013 | modifiers = XINT (XCONS (XCONS (breakdown)->cdr)->car); | |
559f9d04 RS |
7014 | /* Attempt to reduce an unbound mouse event to a simpler |
7015 | event that is bound: | |
7016 | Drags reduce to clicks. | |
7017 | Double-clicks reduce to clicks. | |
7018 | Triple-clicks reduce to double-clicks, then to clicks. | |
7019 | Down-clicks are eliminated. | |
7020 | Double-downs reduce to downs, then are eliminated. | |
7021 | Triple-downs reduce to double-downs, then to downs, | |
7022 | then are eliminated. */ | |
7023 | if (modifiers & (down_modifier | drag_modifier | |
7024 | | double_modifier | triple_modifier)) | |
0a7f1fc0 | 7025 | { |
559f9d04 RS |
7026 | while (modifiers & (down_modifier | drag_modifier |
7027 | | double_modifier | triple_modifier)) | |
fbcd35bd JB |
7028 | { |
7029 | Lisp_Object new_head, new_click; | |
7030 | if (modifiers & triple_modifier) | |
7031 | modifiers ^= (double_modifier | triple_modifier); | |
bc536d84 RS |
7032 | else if (modifiers & double_modifier) |
7033 | modifiers &= ~double_modifier; | |
7034 | else if (modifiers & drag_modifier) | |
7035 | modifiers &= ~drag_modifier; | |
559f9d04 RS |
7036 | else |
7037 | { | |
7038 | /* Dispose of this `down' event by simply jumping | |
7039 | back to replay_key, to get another event. | |
7040 | ||
7041 | Note that if this event came from mock input, | |
7042 | then just jumping back to replay_key will just | |
7043 | hand it to us again. So we have to wipe out any | |
7044 | mock input. | |
7045 | ||
7046 | We could delete keybuf[t] and shift everything | |
7047 | after that to the left by one spot, but we'd also | |
7048 | have to fix up any variable that points into | |
7049 | keybuf, and shifting isn't really necessary | |
7050 | anyway. | |
7051 | ||
7052 | Adding prefixes for non-textual mouse clicks | |
7053 | creates two characters of mock input, and both | |
7054 | must be thrown away. If we're only looking at | |
7055 | the prefix now, we can just jump back to | |
7056 | replay_key. On the other hand, if we've already | |
7057 | processed the prefix, and now the actual click | |
7058 | itself is giving us trouble, then we've lost the | |
7059 | state of the keymaps we want to backtrack to, and | |
7060 | we need to replay the whole sequence to rebuild | |
7061 | it. | |
7062 | ||
7063 | Beyond that, only function key expansion could | |
7064 | create more than two keys, but that should never | |
7065 | generate mouse events, so it's okay to zero | |
7066 | mock_input in that case too. | |
7067 | ||
7068 | Isn't this just the most wonderful code ever? */ | |
7069 | if (t == last_real_key_start) | |
7070 | { | |
7071 | mock_input = 0; | |
7072 | goto replay_key; | |
7073 | } | |
7074 | else | |
7075 | { | |
7076 | mock_input = last_real_key_start; | |
7077 | goto replay_sequence; | |
7078 | } | |
7079 | } | |
7080 | ||
27203ead RS |
7081 | new_head |
7082 | = apply_modifiers (modifiers, XCONS (breakdown)->car); | |
7083 | new_click | |
7084 | = Fcons (new_head, Fcons (EVENT_START (key), Qnil)); | |
fbcd35bd JB |
7085 | |
7086 | /* Look for a binding for this new key. follow_key | |
7087 | promises that it didn't munge submaps the | |
7088 | last time we called it, since key was unbound. */ | |
27203ead RS |
7089 | first_binding |
7090 | = (follow_key (new_click, | |
7091 | nmaps - local_first_binding, | |
7092 | submaps + local_first_binding, | |
7093 | defs + local_first_binding, | |
4e50f26a | 7094 | submaps + local_first_binding) |
27203ead | 7095 | + local_first_binding); |
fbcd35bd JB |
7096 | |
7097 | /* If that click is bound, go for it. */ | |
7098 | if (first_binding < nmaps) | |
7099 | { | |
7100 | key = new_click; | |
7101 | break; | |
7102 | } | |
7103 | /* Otherwise, we'll leave key set to the drag event. */ | |
7104 | } | |
0a7f1fc0 JB |
7105 | } |
7106 | } | |
7107 | } | |
7108 | ||
284f4730 | 7109 | keybuf[t++] = key; |
7d6de002 RS |
7110 | /* Normally, last_nonmenu_event gets the previous key we read. |
7111 | But when a mouse popup menu is being used, | |
7112 | we don't update last_nonmenu_event; it continues to hold the mouse | |
7113 | event that preceded the first level of menu. */ | |
7114 | if (!used_mouse_menu) | |
7115 | last_nonmenu_event = key; | |
284f4730 | 7116 | |
6321824f RS |
7117 | /* Record what part of this_command_keys is the current key sequence. */ |
7118 | this_single_command_key_start = this_command_key_count - t; | |
7119 | ||
3fe8e9a2 RS |
7120 | prev_fkey_map = fkey_map; |
7121 | prev_fkey_start = fkey_start; | |
7122 | prev_fkey_end = fkey_end; | |
7123 | ||
7124 | prev_keytran_map = keytran_map; | |
7125 | prev_keytran_start = keytran_start; | |
7126 | prev_keytran_end = keytran_end; | |
7127 | ||
284f4730 | 7128 | /* If the sequence is unbound, see if we can hang a function key |
253598e4 JB |
7129 | off the end of it. We only want to scan real keyboard input |
7130 | for function key sequences, so if mock_input says that we're | |
f4255cd1 | 7131 | re-reading old events, don't examine it. */ |
4e50f26a | 7132 | if (first_binding >= nmaps |
253598e4 | 7133 | && t >= mock_input) |
284f4730 JB |
7134 | { |
7135 | Lisp_Object fkey_next; | |
7136 | ||
e9bf89a0 RS |
7137 | /* Continue scan from fkey_end until we find a bound suffix. |
7138 | If we fail, increment fkey_start | |
7139 | and start fkey_end from there. */ | |
284f4730 JB |
7140 | while (fkey_end < t) |
7141 | { | |
f4255cd1 JB |
7142 | Lisp_Object key; |
7143 | ||
7144 | key = keybuf[fkey_end++]; | |
067ffa38 JB |
7145 | /* Look up meta-characters by prefixing them |
7146 | with meta_prefix_char. I hate this. */ | |
8c18cbfb | 7147 | if (INTEGERP (key) && XINT (key) & meta_modifier) |
f4255cd1 | 7148 | { |
e74fbc70 RS |
7149 | fkey_next |
7150 | = get_keymap_1 | |
f4255cd1 | 7151 | (get_keyelt |
c6a67acd | 7152 | (access_keymap (fkey_map, meta_prefix_char, 1, 0), 0), |
f4255cd1 | 7153 | 0, 1); |
bb9e9bed | 7154 | XSETFASTINT (key, XFASTINT (key) & ~meta_modifier); |
f4255cd1 | 7155 | } |
067ffa38 JB |
7156 | else |
7157 | fkey_next = fkey_map; | |
7158 | ||
e74fbc70 | 7159 | fkey_next |
c6a67acd | 7160 | = get_keyelt (access_keymap (fkey_next, key, 1, 0), 0); |
067ffa38 | 7161 | |
7a80a6f6 RS |
7162 | #if 0 /* I didn't turn this on, because it might cause trouble |
7163 | for the mapping of return into C-m and tab into C-i. */ | |
7164 | /* Optionally don't map function keys into other things. | |
7165 | This enables the user to redefine kp- keys easily. */ | |
7166 | if (SYMBOLP (key) && !NILP (Vinhibit_function_key_mapping)) | |
7167 | fkey_next = Qnil; | |
7168 | #endif | |
7169 | ||
1abe6abe RS |
7170 | /* If the function key map gives a function, not an |
7171 | array, then call the function with no args and use | |
7172 | its value instead. */ | |
7173 | if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next)) | |
7174 | && fkey_end == t) | |
7175 | { | |
7176 | struct gcpro gcpro1, gcpro2, gcpro3; | |
7177 | Lisp_Object tem; | |
7178 | tem = fkey_next; | |
7179 | ||
7180 | GCPRO3 (fkey_map, keytran_map, delayed_switch_frame); | |
84d91fda | 7181 | fkey_next = call1 (fkey_next, prompt); |
1abe6abe RS |
7182 | UNGCPRO; |
7183 | /* If the function returned something invalid, | |
7184 | barf--don't ignore it. | |
df0f2ba1 | 7185 | (To ignore it safely, we would need to gcpro a bunch of |
1abe6abe RS |
7186 | other variables.) */ |
7187 | if (! (VECTORP (fkey_next) || STRINGP (fkey_next))) | |
6321824f | 7188 | error ("Function in key-translation-map returns invalid key sequence"); |
1abe6abe RS |
7189 | } |
7190 | ||
e9bf89a0 RS |
7191 | function_key_possible = ! NILP (fkey_next); |
7192 | ||
85bc5181 | 7193 | /* If keybuf[fkey_start..fkey_end] is bound in the |
a764a753 | 7194 | function key map and it's a suffix of the current |
85bc5181 | 7195 | sequence (i.e. fkey_end == t), replace it with |
a764a753 | 7196 | the binding and restart with fkey_start at the end. */ |
f5ea6163 | 7197 | if ((VECTORP (fkey_next) || STRINGP (fkey_next)) |
284f4730 JB |
7198 | && fkey_end == t) |
7199 | { | |
2e864a76 | 7200 | int len = XFASTINT (Flength (fkey_next)); |
f5ea6163 JB |
7201 | |
7202 | t = fkey_start + len; | |
284f4730 | 7203 | if (t >= bufsize) |
3fe8e9a2 | 7204 | error ("Key sequence too long"); |
284f4730 | 7205 | |
f5ea6163 JB |
7206 | if (VECTORP (fkey_next)) |
7207 | bcopy (XVECTOR (fkey_next)->contents, | |
7208 | keybuf + fkey_start, | |
7209 | (t - fkey_start) * sizeof (keybuf[0])); | |
7210 | else if (STRINGP (fkey_next)) | |
7211 | { | |
7212 | int i; | |
7213 | ||
7214 | for (i = 0; i < len; i++) | |
bb9e9bed KH |
7215 | XSETFASTINT (keybuf[fkey_start + i], |
7216 | XSTRING (fkey_next)->data[i]); | |
f5ea6163 | 7217 | } |
df0f2ba1 | 7218 | |
284f4730 JB |
7219 | mock_input = t; |
7220 | fkey_start = fkey_end = t; | |
32e6d806 | 7221 | fkey_map = Vfunction_key_map; |
284f4730 | 7222 | |
00a78037 RS |
7223 | /* Do pass the results through key-translation-map. */ |
7224 | keytran_start = keytran_end = 0; | |
7225 | keytran_map = Vkey_translation_map; | |
7226 | ||
f4255cd1 | 7227 | goto replay_sequence; |
284f4730 | 7228 | } |
df0f2ba1 | 7229 | |
f4255cd1 | 7230 | fkey_map = get_keymap_1 (fkey_next, 0, 1); |
284f4730 | 7231 | |
df0f2ba1 | 7232 | /* If we no longer have a bound suffix, try a new positions for |
a764a753 | 7233 | fkey_start. */ |
284f4730 JB |
7234 | if (NILP (fkey_map)) |
7235 | { | |
7236 | fkey_end = ++fkey_start; | |
7237 | fkey_map = Vfunction_key_map; | |
e9bf89a0 | 7238 | function_key_possible = 0; |
284f4730 JB |
7239 | } |
7240 | } | |
7241 | } | |
a612e298 RS |
7242 | |
7243 | /* Look for this sequence in key-translation-map. */ | |
7244 | { | |
7245 | Lisp_Object keytran_next; | |
7246 | ||
7247 | /* Scan from keytran_end until we find a bound suffix. */ | |
7248 | while (keytran_end < t) | |
7249 | { | |
7250 | Lisp_Object key; | |
7251 | ||
7252 | key = keybuf[keytran_end++]; | |
7253 | /* Look up meta-characters by prefixing them | |
7254 | with meta_prefix_char. I hate this. */ | |
8c18cbfb | 7255 | if (INTEGERP (key) && XINT (key) & meta_modifier) |
a612e298 RS |
7256 | { |
7257 | keytran_next | |
7258 | = get_keymap_1 | |
7259 | (get_keyelt | |
c6a67acd | 7260 | (access_keymap (keytran_map, meta_prefix_char, 1, 0), 0), |
a612e298 | 7261 | 0, 1); |
bb9e9bed | 7262 | XSETFASTINT (key, XFASTINT (key) & ~meta_modifier); |
a612e298 RS |
7263 | } |
7264 | else | |
7265 | keytran_next = keytran_map; | |
7266 | ||
7267 | keytran_next | |
c6a67acd | 7268 | = get_keyelt (access_keymap (keytran_next, key, 1, 0), 0); |
a612e298 | 7269 | |
1abe6abe RS |
7270 | /* If the key translation map gives a function, not an |
7271 | array, then call the function with no args and use | |
7272 | its value instead. */ | |
7273 | if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next)) | |
7274 | && keytran_end == t) | |
7275 | { | |
7276 | struct gcpro gcpro1, gcpro2, gcpro3; | |
7277 | Lisp_Object tem; | |
7278 | tem = keytran_next; | |
7279 | ||
40932d1a | 7280 | GCPRO3 (fkey_map, keytran_map, delayed_switch_frame); |
84d91fda | 7281 | keytran_next = call1 (keytran_next, prompt); |
1abe6abe RS |
7282 | UNGCPRO; |
7283 | /* If the function returned something invalid, | |
7284 | barf--don't ignore it. | |
df0f2ba1 | 7285 | (To ignore it safely, we would need to gcpro a bunch of |
1abe6abe RS |
7286 | other variables.) */ |
7287 | if (! (VECTORP (keytran_next) || STRINGP (keytran_next))) | |
40932d1a | 7288 | error ("Function in key-translation-map returns invalid key sequence"); |
1abe6abe RS |
7289 | } |
7290 | ||
00a78037 RS |
7291 | key_translation_possible = ! NILP (keytran_next); |
7292 | ||
a612e298 | 7293 | /* If keybuf[keytran_start..keytran_end] is bound in the |
1abe6abe | 7294 | key translation map and it's a suffix of the current |
a612e298 RS |
7295 | sequence (i.e. keytran_end == t), replace it with |
7296 | the binding and restart with keytran_start at the end. */ | |
7297 | if ((VECTORP (keytran_next) || STRINGP (keytran_next)) | |
7298 | && keytran_end == t) | |
7299 | { | |
2e864a76 | 7300 | int len = XFASTINT (Flength (keytran_next)); |
a612e298 RS |
7301 | |
7302 | t = keytran_start + len; | |
7303 | if (t >= bufsize) | |
3fe8e9a2 | 7304 | error ("Key sequence too long"); |
a612e298 RS |
7305 | |
7306 | if (VECTORP (keytran_next)) | |
7307 | bcopy (XVECTOR (keytran_next)->contents, | |
7308 | keybuf + keytran_start, | |
7309 | (t - keytran_start) * sizeof (keybuf[0])); | |
7310 | else if (STRINGP (keytran_next)) | |
7311 | { | |
7312 | int i; | |
7313 | ||
7314 | for (i = 0; i < len; i++) | |
bb9e9bed KH |
7315 | XSETFASTINT (keybuf[keytran_start + i], |
7316 | XSTRING (keytran_next)->data[i]); | |
a612e298 RS |
7317 | } |
7318 | ||
7319 | mock_input = t; | |
7320 | keytran_start = keytran_end = t; | |
7321 | keytran_map = Vkey_translation_map; | |
7322 | ||
00a78037 RS |
7323 | /* Don't pass the results of key-translation-map |
7324 | through function-key-map. */ | |
7325 | fkey_start = fkey_end = t; | |
7326 | fkey_map = Vkey_translation_map; | |
7327 | ||
a612e298 RS |
7328 | goto replay_sequence; |
7329 | } | |
7330 | ||
7331 | keytran_map = get_keymap_1 (keytran_next, 0, 1); | |
7332 | ||
df0f2ba1 | 7333 | /* If we no longer have a bound suffix, try a new positions for |
a612e298 RS |
7334 | keytran_start. */ |
7335 | if (NILP (keytran_map)) | |
7336 | { | |
7337 | keytran_end = ++keytran_start; | |
7338 | keytran_map = Vkey_translation_map; | |
00a78037 | 7339 | key_translation_possible = 0; |
a612e298 RS |
7340 | } |
7341 | } | |
7342 | } | |
4e50f26a RS |
7343 | |
7344 | /* If KEY is not defined in any of the keymaps, | |
7345 | and cannot be part of a function key or translation, | |
7346 | and is an upper case letter | |
7347 | use the corresponding lower-case letter instead. */ | |
7348 | if (first_binding == nmaps && ! function_key_possible | |
00a78037 | 7349 | && ! key_translation_possible |
8c18cbfb | 7350 | && INTEGERP (key) |
4e50f26a | 7351 | && ((((XINT (key) & 0x3ffff) |
301738ed | 7352 | < XCHAR_TABLE (current_buffer->downcase_table)->size) |
4e50f26a RS |
7353 | && UPPERCASEP (XINT (key) & 0x3ffff)) |
7354 | || (XINT (key) & shift_modifier))) | |
7355 | { | |
569871d2 | 7356 | Lisp_Object new_key; |
569871d2 | 7357 | |
309b0fc8 RS |
7358 | original_uppercase = key; |
7359 | original_uppercase_position = t - 1; | |
7360 | ||
831f35a2 | 7361 | if (XINT (key) & shift_modifier) |
569871d2 | 7362 | XSETINT (new_key, XINT (key) & ~shift_modifier); |
4e50f26a | 7363 | else |
569871d2 RS |
7364 | XSETINT (new_key, (DOWNCASE (XINT (key) & 0x3ffff) |
7365 | | (XINT (key) & ~0x3ffff))); | |
7366 | ||
3fe8e9a2 RS |
7367 | /* We have to do this unconditionally, regardless of whether |
7368 | the lower-case char is defined in the keymaps, because they | |
7369 | might get translated through function-key-map. */ | |
7370 | keybuf[t - 1] = new_key; | |
7371 | mock_input = t; | |
7372 | ||
7373 | fkey_map = prev_fkey_map; | |
7374 | fkey_start = prev_fkey_start; | |
7375 | fkey_end = prev_fkey_end; | |
7376 | ||
7377 | keytran_map = prev_keytran_map; | |
7378 | keytran_start = prev_keytran_start; | |
7379 | keytran_end = prev_keytran_end; | |
7380 | ||
7381 | goto replay_sequence; | |
4e50f26a | 7382 | } |
ef8fd672 RS |
7383 | /* If KEY is not defined in any of the keymaps, |
7384 | and cannot be part of a function key or translation, | |
7385 | and is a shifted function key, | |
7386 | use the corresponding unshifted function key instead. */ | |
7387 | if (first_binding == nmaps && ! function_key_possible | |
7388 | && ! key_translation_possible | |
7389 | && SYMBOLP (key)) | |
7390 | { | |
7391 | Lisp_Object breakdown; | |
7392 | int modifiers; | |
7393 | ||
7394 | breakdown = parse_modifiers (key); | |
7395 | modifiers = XINT (XCONS (XCONS (breakdown)->cdr)->car); | |
7396 | if (modifiers & shift_modifier) | |
7397 | { | |
569871d2 | 7398 | Lisp_Object new_key; |
3fe8e9a2 RS |
7399 | |
7400 | original_uppercase = key; | |
7401 | original_uppercase_position = t - 1; | |
ef8fd672 | 7402 | |
569871d2 RS |
7403 | modifiers &= ~shift_modifier; |
7404 | new_key = apply_modifiers (modifiers, | |
7405 | XCONS (breakdown)->car); | |
7406 | ||
3fe8e9a2 RS |
7407 | keybuf[t - 1] = new_key; |
7408 | mock_input = t; | |
7409 | ||
7410 | fkey_map = prev_fkey_map; | |
7411 | fkey_start = prev_fkey_start; | |
7412 | fkey_end = prev_fkey_end; | |
7413 | ||
7414 | keytran_map = prev_keytran_map; | |
7415 | keytran_start = prev_keytran_start; | |
7416 | keytran_end = prev_keytran_end; | |
7417 | ||
7418 | goto replay_sequence; | |
ef8fd672 RS |
7419 | } |
7420 | } | |
284f4730 JB |
7421 | } |
7422 | ||
309b0fc8 | 7423 | if (!dummyflag) |
bc536d84 RS |
7424 | read_key_sequence_cmd = (first_binding < nmaps |
7425 | ? defs[first_binding] | |
7426 | : Qnil); | |
284f4730 | 7427 | |
cd21b839 | 7428 | unread_switch_frame = delayed_switch_frame; |
f4255cd1 | 7429 | unbind_to (count, Qnil); |
07f76a14 | 7430 | |
3fe8e9a2 RS |
7431 | /* Don't downcase the last character if the caller says don't. |
7432 | Don't downcase it if the result is undefined, either. */ | |
7433 | if ((dont_downcase_last || first_binding >= nmaps) | |
7434 | && t - 1 == original_uppercase_position) | |
309b0fc8 RS |
7435 | keybuf[t - 1] = original_uppercase; |
7436 | ||
07f76a14 JB |
7437 | /* Occasionally we fabricate events, perhaps by expanding something |
7438 | according to function-key-map, or by adding a prefix symbol to a | |
7439 | mouse click in the scroll bar or modeline. In this cases, return | |
7440 | the entire generated key sequence, even if we hit an unbound | |
7441 | prefix or a definition before the end. This means that you will | |
7442 | be able to push back the event properly, and also means that | |
7443 | read-key-sequence will always return a logical unit. | |
7444 | ||
7445 | Better ideas? */ | |
cca310da JB |
7446 | for (; t < mock_input; t++) |
7447 | { | |
a98ea3f9 RS |
7448 | if (echo_keystrokes) |
7449 | echo_char (keybuf[t]); | |
cca310da JB |
7450 | add_command_key (keybuf[t]); |
7451 | } | |
07f76a14 | 7452 | |
284f4730 JB |
7453 | return t; |
7454 | } | |
7455 | ||
a612e298 RS |
7456 | #if 0 /* This doc string is too long for some compilers. |
7457 | This commented-out definition serves for DOC. */ | |
ce98e608 | 7458 | DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 4, 0, |
284f4730 JB |
7459 | "Read a sequence of keystrokes and return as a string or vector.\n\ |
7460 | The sequence is sufficient to specify a non-prefix command in the\n\ | |
7461 | current local and global maps.\n\ | |
7462 | \n\ | |
c0a58692 RS |
7463 | First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\ |
7464 | Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\ | |
7465 | as a continuation of the previous key.\n\ | |
284f4730 | 7466 | \n\ |
309b0fc8 RS |
7467 | The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\ |
7468 | convert the last event to lower case. (Normally any upper case event\n\ | |
7469 | is converted to lower case if the original event is undefined and the lower\n\ | |
7470 | case equivalent is defined.) A non-nil value is appropriate for reading\n\ | |
7471 | a key sequence to be defined.\n\ | |
7472 | \n\ | |
cb5df6ae JB |
7473 | A C-g typed while in this function is treated like any other character,\n\ |
7474 | and `quit-flag' is not set.\n\ | |
7475 | \n\ | |
7476 | If the key sequence starts with a mouse click, then the sequence is read\n\ | |
7477 | using the keymaps of the buffer of the window clicked in, not the buffer\n\ | |
7478 | of the selected window as normal.\n\ | |
ede41463 | 7479 | ""\n\ |
cb5df6ae JB |
7480 | `read-key-sequence' drops unbound button-down events, since you normally\n\ |
7481 | only care about the click or drag events which follow them. If a drag\n\ | |
fbcd35bd JB |
7482 | or multi-click event is unbound, but the corresponding click event would\n\ |
7483 | be bound, `read-key-sequence' turns the event into a click event at the\n\ | |
cb5df6ae | 7484 | drag's starting position. This means that you don't have to distinguish\n\ |
fbcd35bd | 7485 | between click and drag, double, or triple events unless you want to.\n\ |
cb5df6ae JB |
7486 | \n\ |
7487 | `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\ | |
3c370943 JB |
7488 | lines separating windows, and scroll bars with imaginary keys\n\ |
7489 | `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\ | |
cb5df6ae | 7490 | \n\ |
ce98e608 KH |
7491 | Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\ |
7492 | function will process a switch-frame event if the user switches frames\n\ | |
7493 | before typing anything. If the user switches frames in the middle of a\n\ | |
7494 | key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\ | |
7495 | is nil, then the event will be put off until after the current key sequence.\n\ | |
cb5df6ae JB |
7496 | \n\ |
7497 | `read-key-sequence' checks `function-key-map' for function key\n\ | |
7498 | sequences, where they wouldn't conflict with ordinary bindings. See\n\ | |
4bb994d1 | 7499 | `function-key-map' for more details.") |
11e08aab | 7500 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame) |
a612e298 RS |
7501 | #endif |
7502 | ||
ce98e608 | 7503 | DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 4, 0, |
a612e298 | 7504 | 0) |
ce98e608 | 7505 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame) |
309b0fc8 | 7506 | Lisp_Object prompt, continue_echo, dont_downcase_last; |
ce98e608 | 7507 | Lisp_Object can_return_switch_frame; |
284f4730 JB |
7508 | { |
7509 | Lisp_Object keybuf[30]; | |
7510 | register int i; | |
7511 | struct gcpro gcpro1, gcpro2; | |
7512 | ||
7513 | if (!NILP (prompt)) | |
7514 | CHECK_STRING (prompt, 0); | |
7515 | QUIT; | |
7516 | ||
7517 | bzero (keybuf, sizeof keybuf); | |
7518 | GCPRO1 (keybuf[0]); | |
7519 | gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); | |
7520 | ||
daa37602 | 7521 | if (NILP (continue_echo)) |
6321824f RS |
7522 | { |
7523 | this_command_key_count = 0; | |
7524 | this_single_command_key_start = 0; | |
7525 | } | |
c0a58692 | 7526 | |
309b0fc8 | 7527 | i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), |
ce98e608 | 7528 | prompt, ! NILP (dont_downcase_last), |
f571ae0d | 7529 | ! NILP (can_return_switch_frame), 0); |
284f4730 | 7530 | |
dcc408a0 RS |
7531 | if (i == -1) |
7532 | { | |
7533 | Vquit_flag = Qt; | |
7534 | QUIT; | |
7535 | } | |
284f4730 | 7536 | UNGCPRO; |
86e5706b | 7537 | return make_event_array (i, keybuf); |
284f4730 | 7538 | } |
e39da3d7 RS |
7539 | |
7540 | DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector, | |
7541 | Sread_key_sequence_vector, 1, 4, 0, | |
7542 | "Like `read-key-sequence' but always return a vector.") | |
7543 | (prompt, continue_echo, dont_downcase_last, can_return_switch_frame) | |
7544 | Lisp_Object prompt, continue_echo, dont_downcase_last; | |
7545 | Lisp_Object can_return_switch_frame; | |
7546 | { | |
7547 | Lisp_Object keybuf[30]; | |
7548 | register int i; | |
7549 | struct gcpro gcpro1, gcpro2; | |
7550 | ||
7551 | if (!NILP (prompt)) | |
7552 | CHECK_STRING (prompt, 0); | |
7553 | QUIT; | |
7554 | ||
7555 | bzero (keybuf, sizeof keybuf); | |
7556 | GCPRO1 (keybuf[0]); | |
7557 | gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); | |
7558 | ||
7559 | if (NILP (continue_echo)) | |
7560 | { | |
7561 | this_command_key_count = 0; | |
7562 | this_single_command_key_start = 0; | |
7563 | } | |
7564 | ||
7565 | i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), | |
7566 | prompt, ! NILP (dont_downcase_last), | |
7567 | ! NILP (can_return_switch_frame), 0); | |
7568 | ||
7569 | if (i == -1) | |
7570 | { | |
7571 | Vquit_flag = Qt; | |
7572 | QUIT; | |
7573 | } | |
7574 | UNGCPRO; | |
7575 | return Fvector (i, keybuf); | |
7576 | } | |
284f4730 | 7577 | \f |
158f7532 | 7578 | DEFUN ("command-execute", Fcommand_execute, Scommand_execute, 1, 4, 0, |
284f4730 JB |
7579 | "Execute CMD as an editor command.\n\ |
7580 | CMD must be a symbol that satisfies the `commandp' predicate.\n\ | |
7581 | Optional second arg RECORD-FLAG non-nil\n\ | |
7582 | means unconditionally put this command in `command-history'.\n\ | |
aaf2ead7 RS |
7583 | Otherwise, that is done only if an arg is read using the minibuffer.\n\ |
7584 | The argument KEYS specifies the value to use instead of (this-command-keys)\n\ | |
6321824f | 7585 | when reading the arguments; if it is nil, (this-command-keys) is used.\n\ |
158f7532 RS |
7586 | The argument SPECIAL, if non-nil, means that this command is executing\n\ |
7587 | a special event, so ignore the prefix argument and don't clear it.") | |
7588 | (cmd, record_flag, keys, special) | |
7589 | Lisp_Object cmd, record_flag, keys, special; | |
284f4730 JB |
7590 | { |
7591 | register Lisp_Object final; | |
7592 | register Lisp_Object tem; | |
7593 | Lisp_Object prefixarg; | |
7594 | struct backtrace backtrace; | |
7595 | extern int debug_on_next_call; | |
7596 | ||
284f4730 JB |
7597 | debug_on_next_call = 0; |
7598 | ||
158f7532 RS |
7599 | if (NILP (special)) |
7600 | { | |
7601 | prefixarg = current_kboard->Vprefix_arg; | |
7602 | Vcurrent_prefix_arg = prefixarg; | |
7603 | current_kboard->Vprefix_arg = Qnil; | |
7604 | } | |
7605 | else | |
7606 | prefixarg = Qnil; | |
7607 | ||
8c18cbfb | 7608 | if (SYMBOLP (cmd)) |
284f4730 JB |
7609 | { |
7610 | tem = Fget (cmd, Qdisabled); | |
88ce066e | 7611 | if (!NILP (tem) && !NILP (Vrun_hooks)) |
b78ce8fb RS |
7612 | { |
7613 | tem = Fsymbol_value (Qdisabled_command_hook); | |
7614 | if (!NILP (tem)) | |
7615 | return call1 (Vrun_hooks, Qdisabled_command_hook); | |
7616 | } | |
284f4730 JB |
7617 | } |
7618 | ||
01e26217 | 7619 | while (1) |
284f4730 | 7620 | { |
ffd56f97 | 7621 | final = Findirect_function (cmd); |
284f4730 JB |
7622 | |
7623 | if (CONSP (final) && (tem = Fcar (final), EQ (tem, Qautoload))) | |
b516a185 RS |
7624 | { |
7625 | struct gcpro gcpro1, gcpro2; | |
7626 | ||
7627 | GCPRO2 (cmd, prefixarg); | |
7628 | do_autoload (final, cmd); | |
7629 | UNGCPRO; | |
7630 | } | |
284f4730 JB |
7631 | else |
7632 | break; | |
7633 | } | |
7634 | ||
8c18cbfb | 7635 | if (STRINGP (final) || VECTORP (final)) |
284f4730 JB |
7636 | { |
7637 | /* If requested, place the macro in the command history. For | |
7638 | other sorts of commands, call-interactively takes care of | |
7639 | this. */ | |
e57d8fd8 | 7640 | if (!NILP (record_flag)) |
f4385381 RS |
7641 | { |
7642 | Vcommand_history | |
7643 | = Fcons (Fcons (Qexecute_kbd_macro, | |
7644 | Fcons (final, Fcons (prefixarg, Qnil))), | |
7645 | Vcommand_history); | |
7646 | ||
7647 | /* Don't keep command history around forever. */ | |
7648 | if (NUMBERP (Vhistory_length) && XINT (Vhistory_length) > 0) | |
7649 | { | |
7650 | tem = Fnthcdr (Vhistory_length, Vcommand_history); | |
7651 | if (CONSP (tem)) | |
7652 | XCONS (tem)->cdr = Qnil; | |
7653 | } | |
7654 | } | |
284f4730 JB |
7655 | |
7656 | return Fexecute_kbd_macro (final, prefixarg); | |
7657 | } | |
f4385381 | 7658 | |
8c18cbfb | 7659 | if (CONSP (final) || SUBRP (final) || COMPILEDP (final)) |
284f4730 JB |
7660 | { |
7661 | backtrace.next = backtrace_list; | |
7662 | backtrace_list = &backtrace; | |
7663 | backtrace.function = &Qcall_interactively; | |
7664 | backtrace.args = &cmd; | |
7665 | backtrace.nargs = 1; | |
7666 | backtrace.evalargs = 0; | |
7667 | ||
e57d8fd8 | 7668 | tem = Fcall_interactively (cmd, record_flag, keys); |
284f4730 JB |
7669 | |
7670 | backtrace_list = backtrace.next; | |
7671 | return tem; | |
7672 | } | |
7673 | return Qnil; | |
7674 | } | |
7675 | \f | |
284f4730 JB |
7676 | DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_command, |
7677 | 1, 1, "P", | |
7678 | "Read function name, then read its arguments and call it.") | |
7679 | (prefixarg) | |
7680 | Lisp_Object prefixarg; | |
7681 | { | |
7682 | Lisp_Object function; | |
7683 | char buf[40]; | |
7684 | Lisp_Object saved_keys; | |
5434fce6 | 7685 | Lisp_Object bindings, value; |
214360e9 | 7686 | struct gcpro gcpro1, gcpro2; |
284f4730 | 7687 | |
b0f2a7bf KH |
7688 | saved_keys = Fvector (this_command_key_count, |
7689 | XVECTOR (this_command_keys)->contents); | |
284f4730 | 7690 | buf[0] = 0; |
fde7aff8 | 7691 | GCPRO2 (saved_keys, prefixarg); |
284f4730 JB |
7692 | |
7693 | if (EQ (prefixarg, Qminus)) | |
7694 | strcpy (buf, "- "); | |
7695 | else if (CONSP (prefixarg) && XINT (XCONS (prefixarg)->car) == 4) | |
7696 | strcpy (buf, "C-u "); | |
8c18cbfb | 7697 | else if (CONSP (prefixarg) && INTEGERP (XCONS (prefixarg)->car)) |
5d5b907f RS |
7698 | { |
7699 | if (sizeof (int) == sizeof (EMACS_INT)) | |
7700 | sprintf (buf, "%d ", XINT (XCONS (prefixarg)->car)); | |
7701 | else if (sizeof (long) == sizeof (EMACS_INT)) | |
7702 | sprintf (buf, "%ld ", XINT (XCONS (prefixarg)->car)); | |
7703 | else | |
7704 | abort (); | |
7705 | } | |
8c18cbfb | 7706 | else if (INTEGERP (prefixarg)) |
5d5b907f RS |
7707 | { |
7708 | if (sizeof (int) == sizeof (EMACS_INT)) | |
7709 | sprintf (buf, "%d ", XINT (prefixarg)); | |
7710 | else if (sizeof (long) == sizeof (EMACS_INT)) | |
7711 | sprintf (buf, "%ld ", XINT (prefixarg)); | |
7712 | else | |
7713 | abort (); | |
7714 | } | |
284f4730 JB |
7715 | |
7716 | /* This isn't strictly correct if execute-extended-command | |
7717 | is bound to anything else. Perhaps it should use | |
7718 | this_command_keys? */ | |
7719 | strcat (buf, "M-x "); | |
7720 | ||
7721 | /* Prompt with buf, and then read a string, completing from and | |
7722 | restricting to the set of all defined commands. Don't provide | |
51763820 | 7723 | any initial input. Save the command read on the extended-command |
03b4122a | 7724 | history list. */ |
284f4730 JB |
7725 | function = Fcompleting_read (build_string (buf), |
7726 | Vobarray, Qcommandp, | |
4328577a KH |
7727 | Qt, Qnil, Qextended_command_history, Qnil, |
7728 | Qnil); | |
284f4730 | 7729 | |
1f5b1641 RS |
7730 | if (STRINGP (function) && XSTRING (function)->size == 0) |
7731 | error ("No command name given"); | |
7732 | ||
1113d9db JB |
7733 | /* Set this_command_keys to the concatenation of saved_keys and |
7734 | function, followed by a RET. */ | |
284f4730 | 7735 | { |
1113d9db | 7736 | struct Lisp_String *str; |
b0f2a7bf | 7737 | Lisp_Object *keys; |
284f4730 | 7738 | int i; |
284f4730 | 7739 | |
1113d9db | 7740 | this_command_key_count = 0; |
6321824f | 7741 | this_single_command_key_start = 0; |
1113d9db | 7742 | |
b0f2a7bf KH |
7743 | keys = XVECTOR (saved_keys)->contents; |
7744 | for (i = 0; i < XVECTOR (saved_keys)->size; i++) | |
7745 | add_command_key (keys[i]); | |
1113d9db JB |
7746 | |
7747 | str = XSTRING (function); | |
7748 | for (i = 0; i < str->size; i++) | |
301738ed | 7749 | add_command_key (Faref (function, make_number (i))); |
1113d9db | 7750 | |
301738ed | 7751 | add_command_key (make_number ('\015')); |
284f4730 JB |
7752 | } |
7753 | ||
7754 | UNGCPRO; | |
7755 | ||
0a7f1fc0 | 7756 | function = Fintern (function, Qnil); |
d8bcf58e | 7757 | current_kboard->Vprefix_arg = prefixarg; |
284f4730 JB |
7758 | this_command = function; |
7759 | ||
6526ab49 RS |
7760 | /* If enabled, show which key runs this command. */ |
7761 | if (!NILP (Vsuggest_key_bindings) | |
71012575 | 7762 | && NILP (Vexecuting_macro) |
6526ab49 | 7763 | && SYMBOLP (function)) |
5434fce6 RS |
7764 | bindings = Fwhere_is_internal (function, Voverriding_local_map, |
7765 | Qt, Qnil); | |
7766 | else | |
7767 | bindings = Qnil; | |
6526ab49 | 7768 | |
5434fce6 RS |
7769 | value = Qnil; |
7770 | GCPRO2 (bindings, value); | |
7771 | value = Fcommand_execute (function, Qt, Qnil, Qnil); | |
6526ab49 | 7772 | |
5434fce6 | 7773 | /* If the command has a key binding, print it now. */ |
3ababa60 | 7774 | if (!NILP (bindings) |
ee112567 KH |
7775 | && ! (VECTORP (bindings) && EQ (Faref (bindings, make_number (0)), |
7776 | Qmouse_movement))) | |
5434fce6 RS |
7777 | { |
7778 | /* But first wait, and skip the message if there is input. */ | |
7779 | if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings) | |
7780 | ? Vsuggest_key_bindings : make_number (2)), | |
303b5b3f RS |
7781 | Qnil, Qnil)) |
7782 | && ! CONSP (Vunread_command_events)) | |
6526ab49 | 7783 | { |
5434fce6 RS |
7784 | Lisp_Object binding; |
7785 | char *newmessage; | |
7786 | char *oldmessage = echo_area_glyphs; | |
7787 | int oldmessage_len = echo_area_glyphs_length; | |
30c6e062 | 7788 | int oldmultibyte = message_enable_multibyte; |
5434fce6 RS |
7789 | |
7790 | binding = Fkey_description (bindings); | |
7791 | ||
7792 | newmessage | |
7793 | = (char *) alloca (XSYMBOL (function)->name->size | |
fc932ac6 | 7794 | + STRING_BYTES (XSTRING (binding)) |
5434fce6 | 7795 | + 100); |
3ababa60 | 7796 | sprintf (newmessage, "You can run the command `%s' with %s", |
6526ab49 | 7797 | XSYMBOL (function)->name->data, |
5434fce6 | 7798 | XSTRING (binding)->data); |
301738ed RS |
7799 | message2_nolog (newmessage, |
7800 | strlen (newmessage), | |
7801 | STRING_MULTIBYTE (binding)); | |
5434fce6 RS |
7802 | if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings) |
7803 | ? Vsuggest_key_bindings : make_number (2)), | |
7804 | Qnil, Qnil))) | |
a59b172a | 7805 | message2_nolog (oldmessage, oldmessage_len, oldmultibyte); |
6526ab49 RS |
7806 | } |
7807 | } | |
7808 | ||
5434fce6 | 7809 | RETURN_UNGCPRO (value); |
284f4730 | 7810 | } |
6526ab49 RS |
7811 | |
7812 | /* Find the set of keymaps now active. | |
7813 | Store into *MAPS_P a vector holding the various maps | |
7814 | and return the number of them. The vector was malloc'd | |
7815 | and the caller should free it. */ | |
7816 | ||
7817 | int | |
7818 | current_active_maps (maps_p) | |
7819 | Lisp_Object **maps_p; | |
7820 | { | |
7821 | Lisp_Object *tmaps, *maps; | |
7822 | int nmaps; | |
7823 | ||
7824 | /* Should overriding-terminal-local-map and overriding-local-map apply? */ | |
7825 | if (!NILP (Voverriding_local_map_menu_flag)) | |
7826 | { | |
7827 | /* Yes, use them (if non-nil) as well as the global map. */ | |
7828 | maps = (Lisp_Object *) xmalloc (3 * sizeof (maps[0])); | |
7829 | nmaps = 0; | |
7830 | if (!NILP (current_kboard->Voverriding_terminal_local_map)) | |
7831 | maps[nmaps++] = current_kboard->Voverriding_terminal_local_map; | |
7832 | if (!NILP (Voverriding_local_map)) | |
7833 | maps[nmaps++] = Voverriding_local_map; | |
7834 | } | |
7835 | else | |
7836 | { | |
7837 | /* No, so use major and minor mode keymaps. */ | |
7838 | nmaps = current_minor_maps (NULL, &tmaps); | |
7839 | maps = (Lisp_Object *) xmalloc ((nmaps + 2) * sizeof (maps[0])); | |
7840 | bcopy (tmaps, maps, nmaps * sizeof (maps[0])); | |
7841 | #ifdef USE_TEXT_PROPERTIES | |
7842 | maps[nmaps++] = get_local_map (PT, current_buffer); | |
7843 | #else | |
7844 | maps[nmaps++] = current_buffer->keymap; | |
7845 | #endif | |
7846 | } | |
7847 | maps[nmaps++] = current_global_map; | |
7848 | ||
7849 | *maps_p = maps; | |
7850 | return nmaps; | |
7851 | } | |
284f4730 | 7852 | \f |
d9d4c147 | 7853 | /* Return nonzero if input events are pending. */ |
284f4730 | 7854 | |
dfcf069d | 7855 | int |
284f4730 JB |
7856 | detect_input_pending () |
7857 | { | |
7858 | if (!input_pending) | |
d9d4c147 KH |
7859 | get_input_pending (&input_pending, 0); |
7860 | ||
7861 | return input_pending; | |
7862 | } | |
7863 | ||
b1878f45 | 7864 | /* Return nonzero if input events are pending, and run any pending timers. */ |
d9d4c147 | 7865 | |
dfcf069d | 7866 | int |
87dd9b9b RS |
7867 | detect_input_pending_run_timers (do_display) |
7868 | int do_display; | |
d9d4c147 | 7869 | { |
87dd9b9b RS |
7870 | int old_timers_run = timers_run; |
7871 | ||
d9d4c147 KH |
7872 | if (!input_pending) |
7873 | get_input_pending (&input_pending, 1); | |
284f4730 | 7874 | |
87dd9b9b RS |
7875 | if (old_timers_run != timers_run && do_display) |
7876 | redisplay_preserve_echo_area (); | |
7877 | ||
284f4730 JB |
7878 | return input_pending; |
7879 | } | |
7880 | ||
ffd56f97 JB |
7881 | /* This is called in some cases before a possible quit. |
7882 | It cases the next call to detect_input_pending to recompute input_pending. | |
7883 | So calling this function unnecessarily can't do any harm. */ | |
07a59269 KH |
7884 | |
7885 | void | |
ffd56f97 JB |
7886 | clear_input_pending () |
7887 | { | |
7888 | input_pending = 0; | |
7889 | } | |
7890 | ||
b1878f45 RS |
7891 | /* Return nonzero if there are pending requeued events. |
7892 | This isn't used yet. The hope is to make wait_reading_process_input | |
7893 | call it, and return return if it runs Lisp code that unreads something. | |
7894 | The problem is, kbd_buffer_get_event needs to be fixed to know what | |
7895 | to do in that case. It isn't trivial. */ | |
7896 | ||
dfcf069d | 7897 | int |
b1878f45 RS |
7898 | requeued_events_pending_p () |
7899 | { | |
7900 | return (!NILP (Vunread_command_events) || unread_command_char != -1); | |
7901 | } | |
7902 | ||
7903 | ||
284f4730 JB |
7904 | DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0, |
7905 | "T if command input is currently available with no waiting.\n\ | |
7906 | Actually, the value is nil only if we can be sure that no input is available.") | |
7907 | () | |
7908 | { | |
24597608 | 7909 | if (!NILP (Vunread_command_events) || unread_command_char != -1) |
284f4730 JB |
7910 | return (Qt); |
7911 | ||
d9d4c147 KH |
7912 | get_input_pending (&input_pending, 1); |
7913 | return input_pending > 0 ? Qt : Qnil; | |
284f4730 JB |
7914 | } |
7915 | ||
7916 | DEFUN ("recent-keys", Frecent_keys, Srecent_keys, 0, 0, 0, | |
22d7cb89 | 7917 | "Return vector of last 100 events, not counting those from keyboard macros.") |
284f4730 JB |
7918 | () |
7919 | { | |
5160df46 | 7920 | Lisp_Object *keys = XVECTOR (recent_keys)->contents; |
284f4730 JB |
7921 | Lisp_Object val; |
7922 | ||
7923 | if (total_keys < NUM_RECENT_KEYS) | |
5160df46 | 7924 | return Fvector (total_keys, keys); |
284f4730 JB |
7925 | else |
7926 | { | |
5160df46 JB |
7927 | val = Fvector (NUM_RECENT_KEYS, keys); |
7928 | bcopy (keys + recent_keys_index, | |
284f4730 JB |
7929 | XVECTOR (val)->contents, |
7930 | (NUM_RECENT_KEYS - recent_keys_index) * sizeof (Lisp_Object)); | |
5160df46 | 7931 | bcopy (keys, |
284f4730 JB |
7932 | XVECTOR (val)->contents + NUM_RECENT_KEYS - recent_keys_index, |
7933 | recent_keys_index * sizeof (Lisp_Object)); | |
7934 | return val; | |
7935 | } | |
7936 | } | |
7937 | ||
7938 | DEFUN ("this-command-keys", Fthis_command_keys, Sthis_command_keys, 0, 0, 0, | |
e5f920d7 RS |
7939 | "Return the key sequence that invoked this command.\n\ |
7940 | The value is a string or a vector.") | |
284f4730 JB |
7941 | () |
7942 | { | |
86e5706b RS |
7943 | return make_event_array (this_command_key_count, |
7944 | XVECTOR (this_command_keys)->contents); | |
284f4730 JB |
7945 | } |
7946 | ||
e39da3d7 RS |
7947 | DEFUN ("this-command-keys-vector", Fthis_command_keys_vector, Sthis_command_keys_vector, 0, 0, 0, |
7948 | "Return the key sequence that invoked this command, as a vector.") | |
7949 | () | |
7950 | { | |
7951 | return Fvector (this_command_key_count, | |
7952 | XVECTOR (this_command_keys)->contents); | |
7953 | } | |
7954 | ||
6321824f RS |
7955 | DEFUN ("this-single-command-keys", Fthis_single_command_keys, |
7956 | Sthis_single_command_keys, 0, 0, 0, | |
7957 | "Return the key sequence that invoked this command.\n\ | |
7958 | Unlike `this-command-keys', this function's value\n\ | |
7959 | does not include prefix arguments.\n\ | |
e39da3d7 | 7960 | The value is always a vector.") |
6321824f RS |
7961 | () |
7962 | { | |
e39da3d7 RS |
7963 | return Fvector (this_command_key_count |
7964 | - this_single_command_key_start, | |
7965 | (XVECTOR (this_command_keys)->contents | |
7966 | + this_single_command_key_start)); | |
6321824f RS |
7967 | } |
7968 | ||
71918b75 RS |
7969 | DEFUN ("reset-this-command-lengths", Freset_this_command_lengths, |
7970 | Sreset_this_command_lengths, 0, 0, 0, | |
7971 | "Used for complicated reasons in `universal-argument-other-key'.\n\ | |
7972 | \n\ | |
7973 | `universal-argument-other-key' rereads the event just typed.\n\ | |
7974 | It then gets translated through `function-key-map'.\n\ | |
7975 | The translated event gets included in the echo area and in\n\ | |
7976 | the value of `this-command-keys' in addition to the raw original event.\n\ | |
7977 | That is not right.\n\ | |
7978 | \n\ | |
7979 | Calling this function directs the translated event to replace\n\ | |
7980 | the original event, so that only one version of the event actually\n\ | |
7981 | appears in the echo area and in the value of `this-command-keys.'.") | |
7982 | () | |
7983 | { | |
7984 | before_command_restore_flag = 1; | |
7985 | before_command_key_count_1 = before_command_key_count; | |
7986 | before_command_echo_length_1 = before_command_echo_length; | |
7987 | } | |
7988 | ||
284f4730 JB |
7989 | DEFUN ("recursion-depth", Frecursion_depth, Srecursion_depth, 0, 0, 0, |
7990 | "Return the current depth in recursive edits.") | |
7991 | () | |
7992 | { | |
7993 | Lisp_Object temp; | |
bb9e9bed | 7994 | XSETFASTINT (temp, command_loop_level + minibuf_level); |
284f4730 JB |
7995 | return temp; |
7996 | } | |
7997 | ||
7998 | DEFUN ("open-dribble-file", Fopen_dribble_file, Sopen_dribble_file, 1, 1, | |
7999 | "FOpen dribble file: ", | |
9b2471df RS |
8000 | "Start writing all keyboard characters to a dribble file called FILE.\n\ |
8001 | If FILE is nil, close any open dribble file.") | |
284f4730 JB |
8002 | (file) |
8003 | Lisp_Object file; | |
8004 | { | |
6cb52def | 8005 | if (dribble) |
284f4730 | 8006 | { |
6cb52def KH |
8007 | fclose (dribble); |
8008 | dribble = 0; | |
284f4730 | 8009 | } |
6cb52def | 8010 | if (!NILP (file)) |
284f4730 JB |
8011 | { |
8012 | file = Fexpand_file_name (file, Qnil); | |
8013 | dribble = fopen (XSTRING (file)->data, "w"); | |
ab6ca1de KH |
8014 | if (dribble == 0) |
8015 | report_file_error ("Opening dribble", Fcons (file, Qnil)); | |
284f4730 JB |
8016 | } |
8017 | return Qnil; | |
8018 | } | |
8019 | ||
8020 | DEFUN ("discard-input", Fdiscard_input, Sdiscard_input, 0, 0, 0, | |
8021 | "Discard the contents of the terminal input buffer.\n\ | |
8022 | Also cancel any kbd macro being defined.") | |
8023 | () | |
8024 | { | |
c5fdd383 | 8025 | current_kboard->defining_kbd_macro = Qnil; |
284f4730 JB |
8026 | update_mode_lines++; |
8027 | ||
24597608 | 8028 | Vunread_command_events = Qnil; |
86e5706b | 8029 | unread_command_char = -1; |
284f4730 JB |
8030 | |
8031 | discard_tty_input (); | |
8032 | ||
ff0b5f4c JB |
8033 | /* Without the cast, GCC complains that this assignment loses the |
8034 | volatile qualifier of kbd_store_ptr. Is there anything wrong | |
8035 | with that? */ | |
beecf6a1 KH |
8036 | kbd_fetch_ptr = (struct input_event *) kbd_store_ptr; |
8037 | Ffillarray (kbd_buffer_frame_or_window, Qnil); | |
284f4730 JB |
8038 | input_pending = 0; |
8039 | ||
8040 | return Qnil; | |
8041 | } | |
8042 | \f | |
8043 | DEFUN ("suspend-emacs", Fsuspend_emacs, Ssuspend_emacs, 0, 1, "", | |
8044 | "Stop Emacs and return to superior process. You can resume later.\n\ | |
8026024c KH |
8045 | If `cannot-suspend' is non-nil, or if the system doesn't support job\n\ |
8046 | control, run a subshell instead.\n\n\ | |
284f4730 | 8047 | If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\ |
b7d2ebbf RS |
8048 | to be read as terminal input by Emacs's parent, after suspension.\n\ |
8049 | \n\ | |
bbdc2092 RS |
8050 | Before suspending, run the normal hook `suspend-hook'.\n\ |
8051 | After resumption run the normal hook `suspend-resume-hook'.\n\ | |
284f4730 JB |
8052 | \n\ |
8053 | Some operating systems cannot stop the Emacs process and resume it later.\n\ | |
b7d2ebbf | 8054 | On such systems, Emacs starts a subshell instead of suspending.") |
284f4730 JB |
8055 | (stuffstring) |
8056 | Lisp_Object stuffstring; | |
8057 | { | |
3a69360c | 8058 | Lisp_Object tem; |
284f4730 JB |
8059 | int count = specpdl_ptr - specpdl; |
8060 | int old_height, old_width; | |
8061 | int width, height; | |
b7d2ebbf | 8062 | struct gcpro gcpro1, gcpro2; |
284f4730 JB |
8063 | |
8064 | if (!NILP (stuffstring)) | |
8065 | CHECK_STRING (stuffstring, 0); | |
284f4730 | 8066 | |
1e95ed28 JB |
8067 | /* Run the functions in suspend-hook. */ |
8068 | if (!NILP (Vrun_hooks)) | |
8069 | call1 (Vrun_hooks, intern ("suspend-hook")); | |
284f4730 | 8070 | |
b7d2ebbf | 8071 | GCPRO1 (stuffstring); |
ff11dfa1 | 8072 | get_frame_size (&old_width, &old_height); |
284f4730 JB |
8073 | reset_sys_modes (); |
8074 | /* sys_suspend can get an error if it tries to fork a subshell | |
8075 | and the system resources aren't available for that. */ | |
91a0da02 | 8076 | record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes, |
d52a7a92 | 8077 | Qnil); |
284f4730 | 8078 | stuff_buffered_input (stuffstring); |
8026024c KH |
8079 | if (cannot_suspend) |
8080 | sys_subshell (); | |
8081 | else | |
8082 | sys_suspend (); | |
284f4730 JB |
8083 | unbind_to (count, Qnil); |
8084 | ||
8085 | /* Check if terminal/window size has changed. | |
8086 | Note that this is not useful when we are running directly | |
8087 | with a window system; but suspend should be disabled in that case. */ | |
ff11dfa1 | 8088 | get_frame_size (&width, &height); |
284f4730 | 8089 | if (width != old_width || height != old_height) |
f5ea6163 | 8090 | change_frame_size (selected_frame, height, width, 0, 0); |
284f4730 | 8091 | |
1e95ed28 | 8092 | /* Run suspend-resume-hook. */ |
284f4730 JB |
8093 | if (!NILP (Vrun_hooks)) |
8094 | call1 (Vrun_hooks, intern ("suspend-resume-hook")); | |
df0f2ba1 | 8095 | |
284f4730 JB |
8096 | UNGCPRO; |
8097 | return Qnil; | |
8098 | } | |
8099 | ||
8100 | /* If STUFFSTRING is a string, stuff its contents as pending terminal input. | |
eb8c3be9 | 8101 | Then in any case stuff anything Emacs has read ahead and not used. */ |
284f4730 | 8102 | |
07a59269 | 8103 | void |
284f4730 JB |
8104 | stuff_buffered_input (stuffstring) |
8105 | Lisp_Object stuffstring; | |
8106 | { | |
284f4730 | 8107 | /* stuff_char works only in BSD, versions 4.2 and up. */ |
6df54671 | 8108 | #ifdef BSD_SYSTEM |
284f4730 | 8109 | #ifndef BSD4_1 |
612b78ef | 8110 | register unsigned char *p; |
612b78ef | 8111 | |
8c18cbfb | 8112 | if (STRINGP (stuffstring)) |
284f4730 JB |
8113 | { |
8114 | register int count; | |
8115 | ||
8116 | p = XSTRING (stuffstring)->data; | |
fc932ac6 | 8117 | count = STRING_BYTES (XSTRING (stuffstring)); |
284f4730 JB |
8118 | while (count-- > 0) |
8119 | stuff_char (*p++); | |
8120 | stuff_char ('\n'); | |
8121 | } | |
8122 | /* Anything we have read ahead, put back for the shell to read. */ | |
beecf6a1 | 8123 | /* ?? What should this do when we have multiple keyboards?? |
c5fdd383 | 8124 | Should we ignore anything that was typed in at the "wrong" kboard? */ |
beecf6a1 | 8125 | for (; kbd_fetch_ptr != kbd_store_ptr; kbd_fetch_ptr++) |
284f4730 | 8126 | { |
beecf6a1 KH |
8127 | if (kbd_fetch_ptr == kbd_buffer + KBD_BUFFER_SIZE) |
8128 | kbd_fetch_ptr = kbd_buffer; | |
8129 | if (kbd_fetch_ptr->kind == ascii_keystroke) | |
8130 | stuff_char (kbd_fetch_ptr->code); | |
8131 | kbd_fetch_ptr->kind = no_event; | |
8132 | (XVECTOR (kbd_buffer_frame_or_window)->contents[kbd_fetch_ptr | |
8133 | - kbd_buffer] | |
7b4aedb9 | 8134 | = Qnil); |
284f4730 JB |
8135 | } |
8136 | input_pending = 0; | |
8137 | #endif | |
6df54671 | 8138 | #endif /* BSD_SYSTEM and not BSD4_1 */ |
284f4730 JB |
8139 | } |
8140 | \f | |
dfcf069d | 8141 | void |
ffd56f97 JB |
8142 | set_waiting_for_input (time_to_clear) |
8143 | EMACS_TIME *time_to_clear; | |
284f4730 | 8144 | { |
ffd56f97 | 8145 | input_available_clear_time = time_to_clear; |
284f4730 JB |
8146 | |
8147 | /* Tell interrupt_signal to throw back to read_char, */ | |
8148 | waiting_for_input = 1; | |
8149 | ||
8150 | /* If interrupt_signal was called before and buffered a C-g, | |
8151 | make it run again now, to avoid timing error. */ | |
8152 | if (!NILP (Vquit_flag)) | |
8153 | quit_throw_to_read_char (); | |
284f4730 JB |
8154 | } |
8155 | ||
07a59269 | 8156 | void |
284f4730 JB |
8157 | clear_waiting_for_input () |
8158 | { | |
8159 | /* Tell interrupt_signal not to throw back to read_char, */ | |
8160 | waiting_for_input = 0; | |
ffd56f97 | 8161 | input_available_clear_time = 0; |
284f4730 JB |
8162 | } |
8163 | ||
8164 | /* This routine is called at interrupt level in response to C-G. | |
8165 | If interrupt_input, this is the handler for SIGINT. | |
8166 | Otherwise, it is called from kbd_buffer_store_event, | |
8167 | in handling SIGIO or SIGTINT. | |
8168 | ||
8169 | If `waiting_for_input' is non zero, then unless `echoing' is nonzero, | |
8170 | immediately throw back to read_char. | |
8171 | ||
8172 | Otherwise it sets the Lisp variable quit-flag not-nil. | |
8173 | This causes eval to throw, when it gets a chance. | |
8174 | If quit-flag is already non-nil, it stops the job right away. */ | |
8175 | ||
8176 | SIGTYPE | |
91c049d4 RS |
8177 | interrupt_signal (signalnum) /* If we don't have an argument, */ |
8178 | int signalnum; /* some compilers complain in signal calls. */ | |
284f4730 JB |
8179 | { |
8180 | char c; | |
8181 | /* Must preserve main program's value of errno. */ | |
8182 | int old_errno = errno; | |
284f4730 | 8183 | |
5970a8cb | 8184 | #if defined (USG) && !defined (POSIX_SIGNALS) |
7a80a6f6 RS |
8185 | if (!read_socket_hook && NILP (Vwindow_system)) |
8186 | { | |
8187 | /* USG systems forget handlers when they are used; | |
8188 | must reestablish each time */ | |
8189 | signal (SIGINT, interrupt_signal); | |
8190 | signal (SIGQUIT, interrupt_signal); | |
8191 | } | |
284f4730 JB |
8192 | #endif /* USG */ |
8193 | ||
8194 | cancel_echoing (); | |
8195 | ||
31e4e97b EZ |
8196 | if (!NILP (Vquit_flag) |
8197 | && (FRAME_TERMCAP_P (selected_frame) || FRAME_MSDOS_P (selected_frame))) | |
284f4730 | 8198 | { |
31e4e97b EZ |
8199 | /* If SIGINT isn't blocked, don't let us be interrupted by |
8200 | another SIGINT, it might be harmful due to non-reentrancy | |
8201 | in I/O functions. */ | |
8202 | sigblock (sigmask (SIGINT)); | |
8203 | ||
284f4730 JB |
8204 | fflush (stdout); |
8205 | reset_sys_modes (); | |
31e4e97b | 8206 | |
284f4730 JB |
8207 | #ifdef SIGTSTP /* Support possible in later USG versions */ |
8208 | /* | |
8209 | * On systems which can suspend the current process and return to the original | |
8210 | * shell, this command causes the user to end up back at the shell. | |
8211 | * The "Auto-save" and "Abort" questions are not asked until | |
8212 | * the user elects to return to emacs, at which point he can save the current | |
8213 | * job and either dump core or continue. | |
8214 | */ | |
8215 | sys_suspend (); | |
8216 | #else | |
8217 | #ifdef VMS | |
8218 | if (sys_suspend () == -1) | |
8219 | { | |
8220 | printf ("Not running as a subprocess;\n"); | |
8221 | printf ("you can continue or abort.\n"); | |
8222 | } | |
8223 | #else /* not VMS */ | |
8224 | /* Perhaps should really fork an inferior shell? | |
8225 | But that would not provide any way to get back | |
8226 | to the original shell, ever. */ | |
8227 | printf ("No support for stopping a process on this operating system;\n"); | |
8228 | printf ("you can continue or abort.\n"); | |
8229 | #endif /* not VMS */ | |
8230 | #endif /* not SIGTSTP */ | |
80e4aa30 RS |
8231 | #ifdef MSDOS |
8232 | /* We must remain inside the screen area when the internal terminal | |
8233 | is used. Note that [Enter] is not echoed by dos. */ | |
8234 | cursor_to (0, 0); | |
8235 | #endif | |
118d6ca9 RS |
8236 | /* It doesn't work to autosave while GC is in progress; |
8237 | the code used for auto-saving doesn't cope with the mark bit. */ | |
8238 | if (!gc_in_progress) | |
9fd7d808 | 8239 | { |
118d6ca9 RS |
8240 | printf ("Auto-save? (y or n) "); |
8241 | fflush (stdout); | |
8242 | if (((c = getchar ()) & ~040) == 'Y') | |
8243 | { | |
8244 | Fdo_auto_save (Qt, Qnil); | |
80e4aa30 | 8245 | #ifdef MSDOS |
118d6ca9 | 8246 | printf ("\r\nAuto-save done"); |
80e4aa30 | 8247 | #else /* not MSDOS */ |
118d6ca9 | 8248 | printf ("Auto-save done\n"); |
80e4aa30 | 8249 | #endif /* not MSDOS */ |
118d6ca9 RS |
8250 | } |
8251 | while (c != '\n') c = getchar (); | |
9fd7d808 | 8252 | } |
118d6ca9 RS |
8253 | else |
8254 | { | |
8255 | /* During GC, it must be safe to reenable quitting again. */ | |
8256 | Vinhibit_quit = Qnil; | |
8257 | #ifdef MSDOS | |
8258 | printf ("\r\n"); | |
8259 | #endif /* not MSDOS */ | |
8260 | printf ("Garbage collection in progress; cannot auto-save now\r\n"); | |
8261 | printf ("but will instead do a real quit after garbage collection ends\r\n"); | |
8262 | fflush (stdout); | |
8263 | } | |
8264 | ||
80e4aa30 RS |
8265 | #ifdef MSDOS |
8266 | printf ("\r\nAbort? (y or n) "); | |
8267 | #else /* not MSDOS */ | |
284f4730 JB |
8268 | #ifdef VMS |
8269 | printf ("Abort (and enter debugger)? (y or n) "); | |
8270 | #else /* not VMS */ | |
8271 | printf ("Abort (and dump core)? (y or n) "); | |
8272 | #endif /* not VMS */ | |
80e4aa30 | 8273 | #endif /* not MSDOS */ |
284f4730 JB |
8274 | fflush (stdout); |
8275 | if (((c = getchar ()) & ~040) == 'Y') | |
8276 | abort (); | |
8277 | while (c != '\n') c = getchar (); | |
80e4aa30 RS |
8278 | #ifdef MSDOS |
8279 | printf ("\r\nContinuing...\r\n"); | |
8280 | #else /* not MSDOS */ | |
284f4730 | 8281 | printf ("Continuing...\n"); |
80e4aa30 | 8282 | #endif /* not MSDOS */ |
284f4730 JB |
8283 | fflush (stdout); |
8284 | init_sys_modes (); | |
31e4e97b | 8285 | sigfree (); |
284f4730 JB |
8286 | } |
8287 | else | |
8288 | { | |
8289 | /* If executing a function that wants to be interrupted out of | |
8290 | and the user has not deferred quitting by binding `inhibit-quit' | |
8291 | then quit right away. */ | |
8292 | if (immediate_quit && NILP (Vinhibit_quit)) | |
8293 | { | |
e39da3d7 RS |
8294 | struct gl_state_s saved; |
8295 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
8296 | ||
284f4730 JB |
8297 | immediate_quit = 0; |
8298 | sigfree (); | |
e39da3d7 RS |
8299 | saved = gl_state; |
8300 | GCPRO4 (saved.object, saved.global_code, | |
8301 | saved.current_syntax_table, saved.old_prop); | |
284f4730 | 8302 | Fsignal (Qquit, Qnil); |
e39da3d7 RS |
8303 | gl_state = saved; |
8304 | UNGCPRO; | |
284f4730 JB |
8305 | } |
8306 | else | |
8307 | /* Else request quit when it's safe */ | |
8308 | Vquit_flag = Qt; | |
8309 | } | |
8310 | ||
8311 | if (waiting_for_input && !echoing) | |
8312 | quit_throw_to_read_char (); | |
8313 | ||
8314 | errno = old_errno; | |
8315 | } | |
8316 | ||
8317 | /* Handle a C-g by making read_char return C-g. */ | |
8318 | ||
07a59269 | 8319 | void |
284f4730 JB |
8320 | quit_throw_to_read_char () |
8321 | { | |
8322 | quit_error_check (); | |
8323 | sigfree (); | |
8324 | /* Prevent another signal from doing this before we finish. */ | |
f76475ad | 8325 | clear_waiting_for_input (); |
284f4730 JB |
8326 | input_pending = 0; |
8327 | ||
24597608 | 8328 | Vunread_command_events = Qnil; |
86e5706b | 8329 | unread_command_char = -1; |
284f4730 | 8330 | |
087feab3 RS |
8331 | #if 0 /* Currently, sit_for is called from read_char without turning |
8332 | off polling. And that can call set_waiting_for_input. | |
8333 | It seems to be harmless. */ | |
e6b01c14 JB |
8334 | #ifdef POLL_FOR_INPUT |
8335 | /* May be > 1 if in recursive minibuffer. */ | |
8336 | if (poll_suppress_count == 0) | |
8337 | abort (); | |
8338 | #endif | |
087feab3 | 8339 | #endif |
4c52b668 KH |
8340 | if (FRAMEP (internal_last_event_frame) |
8341 | && XFRAME (internal_last_event_frame) != selected_frame) | |
719191cf RS |
8342 | do_switch_frame (make_lispy_switch_frame (internal_last_event_frame), |
8343 | Qnil, 0); | |
e6b01c14 | 8344 | |
284f4730 JB |
8345 | _longjmp (getcjmp, 1); |
8346 | } | |
8347 | \f | |
8348 | DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, | |
8349 | "Set mode of reading keyboard input.\n\ | |
464f8898 RS |
8350 | First arg INTERRUPT non-nil means use input interrupts;\n\ |
8351 | nil means use CBREAK mode.\n\ | |
8352 | Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\ | |
284f4730 | 8353 | (no effect except in CBREAK mode).\n\ |
b04904fb RS |
8354 | Third arg META t means accept 8-bit input (for a Meta key).\n\ |
8355 | META nil means ignore the top bit, on the assumption it is parity.\n\ | |
8356 | Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\ | |
a8ee7ef9 RS |
8357 | Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\ |
8358 | See also `current-input-mode'.") | |
284f4730 JB |
8359 | (interrupt, flow, meta, quit) |
8360 | Lisp_Object interrupt, flow, meta, quit; | |
8361 | { | |
8362 | if (!NILP (quit) | |
8c18cbfb | 8363 | && (!INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400)) |
34f04431 RS |
8364 | error ("set-input-mode: QUIT must be an ASCII character"); |
8365 | ||
8366 | #ifdef POLL_FOR_INPUT | |
8367 | stop_polling (); | |
8368 | #endif | |
284f4730 | 8369 | |
07de30b9 | 8370 | #ifndef DOS_NT |
2ee250ec | 8371 | /* this causes startup screen to be restored and messes with the mouse */ |
284f4730 | 8372 | reset_sys_modes (); |
2ee250ec RS |
8373 | #endif |
8374 | ||
284f4730 JB |
8375 | #ifdef SIGIO |
8376 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
284f4730 | 8377 | if (read_socket_hook) |
9a0f60bb KH |
8378 | { |
8379 | /* When using X, don't give the user a real choice, | |
8380 | because we haven't implemented the mechanisms to support it. */ | |
8381 | #ifdef NO_SOCK_SIGIO | |
8382 | interrupt_input = 0; | |
8383 | #else /* not NO_SOCK_SIGIO */ | |
8384 | interrupt_input = 1; | |
284f4730 | 8385 | #endif /* NO_SOCK_SIGIO */ |
9a0f60bb KH |
8386 | } |
8387 | else | |
284f4730 JB |
8388 | interrupt_input = !NILP (interrupt); |
8389 | #else /* not SIGIO */ | |
8390 | interrupt_input = 0; | |
8391 | #endif /* not SIGIO */ | |
9a0f60bb | 8392 | |
284f4730 JB |
8393 | /* Our VMS input only works by interrupts, as of now. */ |
8394 | #ifdef VMS | |
8395 | interrupt_input = 1; | |
8396 | #endif | |
9a0f60bb | 8397 | |
284f4730 | 8398 | flow_control = !NILP (flow); |
b04904fb RS |
8399 | if (NILP (meta)) |
8400 | meta_key = 0; | |
8401 | else if (EQ (meta, Qt)) | |
8402 | meta_key = 1; | |
8403 | else | |
8404 | meta_key = 2; | |
284f4730 JB |
8405 | if (!NILP (quit)) |
8406 | /* Don't let this value be out of range. */ | |
8407 | quit_char = XINT (quit) & (meta_key ? 0377 : 0177); | |
8408 | ||
07de30b9 | 8409 | #ifndef DOS_NT |
284f4730 | 8410 | init_sys_modes (); |
2ee250ec | 8411 | #endif |
34f04431 RS |
8412 | |
8413 | #ifdef POLL_FOR_INPUT | |
8414 | poll_suppress_count = 1; | |
8415 | start_polling (); | |
8416 | #endif | |
284f4730 JB |
8417 | return Qnil; |
8418 | } | |
80645119 JB |
8419 | |
8420 | DEFUN ("current-input-mode", Fcurrent_input_mode, Scurrent_input_mode, 0, 0, 0, | |
8421 | "Return information about the way Emacs currently reads keyboard input.\n\ | |
8422 | The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\ | |
8423 | INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\ | |
8424 | nil, Emacs is using CBREAK mode.\n\ | |
8425 | FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\ | |
8426 | terminal; this does not apply if Emacs uses interrupt-driven input.\n\ | |
a8ee7ef9 RS |
8427 | META is t if accepting 8-bit input with 8th bit as Meta flag.\n\ |
8428 | META nil means ignoring the top bit, on the assumption it is parity.\n\ | |
8429 | META is neither t nor nil if accepting 8-bit input and using\n\ | |
8430 | all 8 bits as the character code.\n\ | |
80645119 JB |
8431 | QUIT is the character Emacs currently uses to quit.\n\ |
8432 | The elements of this list correspond to the arguments of\n\ | |
a8ee7ef9 | 8433 | `set-input-mode'.") |
80645119 JB |
8434 | () |
8435 | { | |
8436 | Lisp_Object val[4]; | |
8437 | ||
8438 | val[0] = interrupt_input ? Qt : Qnil; | |
8439 | val[1] = flow_control ? Qt : Qnil; | |
a8ee7ef9 | 8440 | val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil; |
bb9e9bed | 8441 | XSETFASTINT (val[3], quit_char); |
80645119 | 8442 | |
bf673a7a | 8443 | return Flist (sizeof (val) / sizeof (val[0]), val); |
80645119 JB |
8444 | } |
8445 | ||
284f4730 | 8446 | \f |
6c6083a9 | 8447 | /* |
c5fdd383 | 8448 | * Set up a new kboard object with reasonable initial values. |
6c6083a9 KH |
8449 | */ |
8450 | void | |
c5fdd383 KH |
8451 | init_kboard (kb) |
8452 | KBOARD *kb; | |
6c6083a9 | 8453 | { |
217258d5 | 8454 | kb->Voverriding_terminal_local_map = Qnil; |
6c7178b9 | 8455 | kb->Vlast_command = Qnil; |
75045dcb | 8456 | kb->Vreal_last_command = Qnil; |
d8bcf58e | 8457 | kb->Vprefix_arg = Qnil; |
75045dcb | 8458 | kb->Vlast_prefix_arg = Qnil; |
c5fdd383 KH |
8459 | kb->kbd_queue = Qnil; |
8460 | kb->kbd_queue_has_data = 0; | |
8461 | kb->immediate_echo = 0; | |
8462 | kb->echoptr = kb->echobuf; | |
8463 | kb->echo_after_prompt = -1; | |
8464 | kb->kbd_macro_buffer = 0; | |
8465 | kb->kbd_macro_bufsize = 0; | |
8466 | kb->defining_kbd_macro = Qnil; | |
8467 | kb->Vlast_kbd_macro = Qnil; | |
8468 | kb->reference_count = 0; | |
7c97ffdc | 8469 | kb->Vsystem_key_alist = Qnil; |
142e6c73 | 8470 | kb->system_key_syms = Qnil; |
9ba47203 | 8471 | kb->Vdefault_minibuffer_frame = Qnil; |
6c6083a9 KH |
8472 | } |
8473 | ||
8474 | /* | |
c5fdd383 | 8475 | * Destroy the contents of a kboard object, but not the object itself. |
8e6208c5 | 8476 | * We use this just before deleting it, or if we're going to initialize |
6c6083a9 KH |
8477 | * it a second time. |
8478 | */ | |
e50b8090 | 8479 | static void |
c5fdd383 KH |
8480 | wipe_kboard (kb) |
8481 | KBOARD *kb; | |
6c6083a9 | 8482 | { |
c5fdd383 KH |
8483 | if (kb->kbd_macro_buffer) |
8484 | xfree (kb->kbd_macro_buffer); | |
6c6083a9 KH |
8485 | } |
8486 | ||
e50b8090 KH |
8487 | #ifdef MULTI_KBOARD |
8488 | void | |
8489 | delete_kboard (kb) | |
8490 | KBOARD *kb; | |
8491 | { | |
8492 | KBOARD **kbp; | |
8493 | for (kbp = &all_kboards; *kbp != kb; kbp = &(*kbp)->next_kboard) | |
8494 | if (*kbp == NULL) | |
8495 | abort (); | |
8496 | *kbp = kb->next_kboard; | |
8497 | wipe_kboard (kb); | |
8498 | xfree (kb); | |
8499 | } | |
8500 | #endif | |
8501 | ||
dfcf069d | 8502 | void |
284f4730 JB |
8503 | init_keyboard () |
8504 | { | |
284f4730 JB |
8505 | /* This is correct before outermost invocation of the editor loop */ |
8506 | command_loop_level = -1; | |
8507 | immediate_quit = 0; | |
8508 | quit_char = Ctl ('g'); | |
24597608 | 8509 | Vunread_command_events = Qnil; |
86e5706b | 8510 | unread_command_char = -1; |
87dd9b9b | 8511 | EMACS_SET_SECS_USECS (timer_idleness_start_time, -1, -1); |
284f4730 | 8512 | total_keys = 0; |
9deb415a | 8513 | recent_keys_index = 0; |
beecf6a1 KH |
8514 | kbd_fetch_ptr = kbd_buffer; |
8515 | kbd_store_ptr = kbd_buffer; | |
8516 | kbd_buffer_frame_or_window | |
8517 | = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil); | |
2eb6bfbe | 8518 | #ifdef HAVE_MOUSE |
a9d77f1f | 8519 | do_mouse_tracking = Qnil; |
2eb6bfbe | 8520 | #endif |
284f4730 JB |
8521 | input_pending = 0; |
8522 | ||
4c52b668 KH |
8523 | /* This means that command_loop_1 won't try to select anything the first |
8524 | time through. */ | |
8525 | internal_last_event_frame = Qnil; | |
8526 | Vlast_event_frame = internal_last_event_frame; | |
4c52b668 | 8527 | |
c5fdd383 | 8528 | #ifdef MULTI_KBOARD |
aaca43a1 | 8529 | current_kboard = initial_kboard; |
6c6083a9 | 8530 | #endif |
aaca43a1 | 8531 | wipe_kboard (current_kboard); |
c5fdd383 | 8532 | init_kboard (current_kboard); |
07d2b8de | 8533 | |
beecf6a1 KH |
8534 | if (initialized) |
8535 | Ffillarray (kbd_buffer_frame_or_window, Qnil); | |
8536 | ||
8537 | kbd_buffer_frame_or_window | |
8538 | = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil); | |
7a80a6f6 | 8539 | if (!noninteractive && !read_socket_hook && NILP (Vwindow_system)) |
284f4730 JB |
8540 | { |
8541 | signal (SIGINT, interrupt_signal); | |
cb5df6ae | 8542 | #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) |
284f4730 JB |
8543 | /* For systems with SysV TERMIO, C-g is set up for both SIGINT and |
8544 | SIGQUIT and we can't tell which one it will give us. */ | |
8545 | signal (SIGQUIT, interrupt_signal); | |
8546 | #endif /* HAVE_TERMIO */ | |
7a80a6f6 | 8547 | } |
284f4730 JB |
8548 | /* Note SIGIO has been undef'd if FIONREAD is missing. */ |
8549 | #ifdef SIGIO | |
7a80a6f6 RS |
8550 | if (!noninteractive) |
8551 | signal (SIGIO, input_available_signal); | |
8ea0a720 | 8552 | #endif /* SIGIO */ |
284f4730 JB |
8553 | |
8554 | /* Use interrupt input by default, if it works and noninterrupt input | |
8555 | has deficiencies. */ | |
8556 | ||
8557 | #ifdef INTERRUPT_INPUT | |
8558 | interrupt_input = 1; | |
8559 | #else | |
8560 | interrupt_input = 0; | |
8561 | #endif | |
8562 | ||
8563 | /* Our VMS input only works by interrupts, as of now. */ | |
8564 | #ifdef VMS | |
8565 | interrupt_input = 1; | |
8566 | #endif | |
8567 | ||
8568 | sigfree (); | |
8569 | dribble = 0; | |
8570 | ||
8571 | if (keyboard_init_hook) | |
8572 | (*keyboard_init_hook) (); | |
8573 | ||
8574 | #ifdef POLL_FOR_INPUT | |
8575 | poll_suppress_count = 1; | |
8576 | start_polling (); | |
8577 | #endif | |
8578 | } | |
8579 | ||
df0f2ba1 | 8580 | /* This type's only use is in syms_of_keyboard, to initialize the |
284f4730 JB |
8581 | event header symbols and put properties on them. */ |
8582 | struct event_head { | |
8583 | Lisp_Object *var; | |
8584 | char *name; | |
8585 | Lisp_Object *kind; | |
8586 | }; | |
8587 | ||
8588 | struct event_head head_table[] = { | |
7b4aedb9 | 8589 | &Qmouse_movement, "mouse-movement", &Qmouse_movement, |
3c370943 | 8590 | &Qscroll_bar_movement, "scroll-bar-movement", &Qmouse_movement, |
7b4aedb9 | 8591 | &Qswitch_frame, "switch-frame", &Qswitch_frame, |
bbdc2092 | 8592 | &Qdelete_frame, "delete-frame", &Qdelete_frame, |
af17bd2b KH |
8593 | &Qiconify_frame, "iconify-frame", &Qiconify_frame, |
8594 | &Qmake_frame_visible, "make-frame-visible", &Qmake_frame_visible, | |
284f4730 JB |
8595 | }; |
8596 | ||
dfcf069d | 8597 | void |
284f4730 JB |
8598 | syms_of_keyboard () |
8599 | { | |
e8886a1d RS |
8600 | staticpro (&item_properties); |
8601 | item_properties = Qnil; | |
8602 | ||
d925fb39 RS |
8603 | Qtimer_event_handler = intern ("timer-event-handler"); |
8604 | staticpro (&Qtimer_event_handler); | |
8605 | ||
2e894dab RS |
8606 | Qdisabled_command_hook = intern ("disabled-command-hook"); |
8607 | staticpro (&Qdisabled_command_hook); | |
8608 | ||
284f4730 JB |
8609 | Qself_insert_command = intern ("self-insert-command"); |
8610 | staticpro (&Qself_insert_command); | |
8611 | ||
8612 | Qforward_char = intern ("forward-char"); | |
8613 | staticpro (&Qforward_char); | |
8614 | ||
8615 | Qbackward_char = intern ("backward-char"); | |
8616 | staticpro (&Qbackward_char); | |
8617 | ||
8618 | Qdisabled = intern ("disabled"); | |
8619 | staticpro (&Qdisabled); | |
8620 | ||
e58aa385 RS |
8621 | Qundefined = intern ("undefined"); |
8622 | staticpro (&Qundefined); | |
8623 | ||
86e5706b RS |
8624 | Qpre_command_hook = intern ("pre-command-hook"); |
8625 | staticpro (&Qpre_command_hook); | |
8626 | ||
8627 | Qpost_command_hook = intern ("post-command-hook"); | |
8628 | staticpro (&Qpost_command_hook); | |
8629 | ||
59aadc81 RS |
8630 | Qpost_command_idle_hook = intern ("post-command-idle-hook"); |
8631 | staticpro (&Qpost_command_idle_hook); | |
8632 | ||
3ef14e46 RS |
8633 | Qdeferred_action_function = intern ("deferred-action-function"); |
8634 | staticpro (&Qdeferred_action_function); | |
8635 | ||
40932d1a RS |
8636 | Qcommand_hook_internal = intern ("command-hook-internal"); |
8637 | staticpro (&Qcommand_hook_internal); | |
8638 | ||
284f4730 JB |
8639 | Qfunction_key = intern ("function-key"); |
8640 | staticpro (&Qfunction_key); | |
13b5e56c | 8641 | Qmouse_click = intern ("mouse-click"); |
284f4730 | 8642 | staticpro (&Qmouse_click); |
07de30b9 GV |
8643 | #ifdef WINDOWSNT |
8644 | Qmouse_wheel = intern ("mouse-wheel"); | |
8645 | staticpro (&Qmouse_wheel); | |
8646 | #endif | |
a24dc617 RS |
8647 | Qdrag_n_drop = intern ("drag-n-drop"); |
8648 | staticpro (&Qdrag_n_drop); | |
284f4730 | 8649 | |
598a9fa7 JB |
8650 | Qmenu_enable = intern ("menu-enable"); |
8651 | staticpro (&Qmenu_enable); | |
e8886a1d RS |
8652 | Qmenu_alias = intern ("menu-alias"); |
8653 | staticpro (&Qmenu_alias); | |
8654 | QCenable = intern (":enable"); | |
8655 | staticpro (&QCenable); | |
8656 | QCvisible = intern (":visible"); | |
8657 | staticpro (&QCvisible); | |
8658 | QCfilter = intern (":filter"); | |
8659 | staticpro (&QCfilter); | |
8660 | QCbutton = intern (":button"); | |
8661 | staticpro (&QCbutton); | |
74c1de23 RS |
8662 | QCkeys = intern (":keys"); |
8663 | staticpro (&QCkeys); | |
8664 | QCkey_sequence = intern (":key-sequence"); | |
8665 | staticpro (&QCkey_sequence); | |
e8886a1d RS |
8666 | QCtoggle = intern (":toggle"); |
8667 | staticpro (&QCtoggle); | |
8668 | QCradio = intern (":radio"); | |
8669 | staticpro (&QCradio); | |
598a9fa7 | 8670 | |
284f4730 JB |
8671 | Qmode_line = intern ("mode-line"); |
8672 | staticpro (&Qmode_line); | |
e5d77022 JB |
8673 | Qvertical_line = intern ("vertical-line"); |
8674 | staticpro (&Qvertical_line); | |
3c370943 JB |
8675 | Qvertical_scroll_bar = intern ("vertical-scroll-bar"); |
8676 | staticpro (&Qvertical_scroll_bar); | |
5ec75a55 RS |
8677 | Qmenu_bar = intern ("menu-bar"); |
8678 | staticpro (&Qmenu_bar); | |
4bb994d1 JB |
8679 | |
8680 | Qabove_handle = intern ("above-handle"); | |
8681 | staticpro (&Qabove_handle); | |
8682 | Qhandle = intern ("handle"); | |
8683 | staticpro (&Qhandle); | |
8684 | Qbelow_handle = intern ("below-handle"); | |
8685 | staticpro (&Qbelow_handle); | |
db08707d RS |
8686 | Qup = intern ("up"); |
8687 | staticpro (&Qup); | |
8688 | Qdown = intern ("down"); | |
8689 | staticpro (&Qdown); | |
284f4730 | 8690 | |
cd21b839 | 8691 | Qevent_kind = intern ("event-kind"); |
284f4730 | 8692 | staticpro (&Qevent_kind); |
88cb0656 JB |
8693 | Qevent_symbol_elements = intern ("event-symbol-elements"); |
8694 | staticpro (&Qevent_symbol_elements); | |
0a7f1fc0 JB |
8695 | Qevent_symbol_element_mask = intern ("event-symbol-element-mask"); |
8696 | staticpro (&Qevent_symbol_element_mask); | |
8697 | Qmodifier_cache = intern ("modifier-cache"); | |
8698 | staticpro (&Qmodifier_cache); | |
284f4730 | 8699 | |
48e416d4 RS |
8700 | Qrecompute_lucid_menubar = intern ("recompute-lucid-menubar"); |
8701 | staticpro (&Qrecompute_lucid_menubar); | |
8702 | Qactivate_menubar_hook = intern ("activate-menubar-hook"); | |
8703 | staticpro (&Qactivate_menubar_hook); | |
8704 | ||
f4eef8b4 RS |
8705 | Qpolling_period = intern ("polling-period"); |
8706 | staticpro (&Qpolling_period); | |
8707 | ||
284f4730 JB |
8708 | { |
8709 | struct event_head *p; | |
8710 | ||
8711 | for (p = head_table; | |
8712 | p < head_table + (sizeof (head_table) / sizeof (head_table[0])); | |
8713 | p++) | |
8714 | { | |
8715 | *p->var = intern (p->name); | |
8716 | staticpro (p->var); | |
8717 | Fput (*p->var, Qevent_kind, *p->kind); | |
88cb0656 | 8718 | Fput (*p->var, Qevent_symbol_elements, Fcons (*p->var, Qnil)); |
284f4730 JB |
8719 | } |
8720 | } | |
8721 | ||
7b4aedb9 JB |
8722 | button_down_location = Fmake_vector (make_number (NUM_MOUSE_BUTTONS), Qnil); |
8723 | staticpro (&button_down_location); | |
88cb0656 JB |
8724 | |
8725 | { | |
8726 | int i; | |
8727 | int len = sizeof (modifier_names) / sizeof (modifier_names[0]); | |
8728 | ||
8729 | modifier_symbols = Fmake_vector (make_number (len), Qnil); | |
8730 | for (i = 0; i < len; i++) | |
86e5706b RS |
8731 | if (modifier_names[i]) |
8732 | XVECTOR (modifier_symbols)->contents[i] = intern (modifier_names[i]); | |
88cb0656 JB |
8733 | staticpro (&modifier_symbols); |
8734 | } | |
8735 | ||
9deb415a JB |
8736 | recent_keys = Fmake_vector (make_number (NUM_RECENT_KEYS), Qnil); |
8737 | staticpro (&recent_keys); | |
8738 | ||
6569cc8d | 8739 | this_command_keys = Fmake_vector (make_number (40), Qnil); |
715d9345 | 8740 | staticpro (&this_command_keys); |
6569cc8d | 8741 | |
03b4122a BF |
8742 | Qextended_command_history = intern ("extended-command-history"); |
8743 | Fset (Qextended_command_history, Qnil); | |
8744 | staticpro (&Qextended_command_history); | |
8745 | ||
beecf6a1 KH |
8746 | kbd_buffer_frame_or_window |
8747 | = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil); | |
8748 | staticpro (&kbd_buffer_frame_or_window); | |
8749 | ||
24597608 RS |
8750 | accent_key_syms = Qnil; |
8751 | staticpro (&accent_key_syms); | |
8752 | ||
284f4730 JB |
8753 | func_key_syms = Qnil; |
8754 | staticpro (&func_key_syms); | |
8755 | ||
8756 | mouse_syms = Qnil; | |
8757 | staticpro (&mouse_syms); | |
8758 | ||
07de30b9 GV |
8759 | #ifdef WINDOWSNT |
8760 | mouse_wheel_syms = Qnil; | |
8761 | staticpro (&mouse_wheel_syms); | |
a24dc617 RS |
8762 | |
8763 | drag_n_drop_syms = Qnil; | |
8764 | staticpro (&drag_n_drop_syms); | |
07de30b9 GV |
8765 | #endif |
8766 | ||
cd21b839 JB |
8767 | unread_switch_frame = Qnil; |
8768 | staticpro (&unread_switch_frame); | |
8769 | ||
fe412364 EN |
8770 | internal_last_event_frame = Qnil; |
8771 | staticpro (&internal_last_event_frame); | |
8772 | ||
8773 | read_key_sequence_cmd = Qnil; | |
8774 | staticpro (&read_key_sequence_cmd); | |
8775 | ||
a1706c30 | 8776 | defsubr (&Sevent_convert_list); |
284f4730 | 8777 | defsubr (&Sread_key_sequence); |
e39da3d7 | 8778 | defsubr (&Sread_key_sequence_vector); |
284f4730 | 8779 | defsubr (&Srecursive_edit); |
2eb6bfbe | 8780 | #ifdef HAVE_MOUSE |
284f4730 | 8781 | defsubr (&Strack_mouse); |
2eb6bfbe | 8782 | #endif |
284f4730 JB |
8783 | defsubr (&Sinput_pending_p); |
8784 | defsubr (&Scommand_execute); | |
8785 | defsubr (&Srecent_keys); | |
8786 | defsubr (&Sthis_command_keys); | |
e39da3d7 | 8787 | defsubr (&Sthis_command_keys_vector); |
6321824f | 8788 | defsubr (&Sthis_single_command_keys); |
71918b75 | 8789 | defsubr (&Sreset_this_command_lengths); |
284f4730 JB |
8790 | defsubr (&Ssuspend_emacs); |
8791 | defsubr (&Sabort_recursive_edit); | |
8792 | defsubr (&Sexit_recursive_edit); | |
8793 | defsubr (&Srecursion_depth); | |
8794 | defsubr (&Stop_level); | |
8795 | defsubr (&Sdiscard_input); | |
8796 | defsubr (&Sopen_dribble_file); | |
8797 | defsubr (&Sset_input_mode); | |
80645119 | 8798 | defsubr (&Scurrent_input_mode); |
284f4730 JB |
8799 | defsubr (&Sexecute_extended_command); |
8800 | ||
284f4730 | 8801 | DEFVAR_LISP ("last-command-char", &last_command_char, |
86e5706b RS |
8802 | "Last input event that was part of a command."); |
8803 | ||
186cf719 | 8804 | DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char, |
86e5706b | 8805 | "Last input event that was part of a command."); |
284f4730 | 8806 | |
7d6de002 | 8807 | DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event, |
86e5706b | 8808 | "Last input event in a command, except for mouse menu events.\n\ |
7d6de002 RS |
8809 | Mouse menus give back keys that don't look like mouse events;\n\ |
8810 | this variable holds the actual mouse event that led to the menu,\n\ | |
8811 | so that you can determine whether the command was run by mouse or not."); | |
8812 | ||
284f4730 | 8813 | DEFVAR_LISP ("last-input-char", &last_input_char, |
86e5706b RS |
8814 | "Last input event."); |
8815 | ||
186cf719 | 8816 | DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char, |
86e5706b | 8817 | "Last input event."); |
284f4730 | 8818 | |
24597608 | 8819 | DEFVAR_LISP ("unread-command-events", &Vunread_command_events, |
1c07d0a6 | 8820 | "List of objects to be read as next command input events."); |
284f4730 | 8821 | |
86e5706b RS |
8822 | DEFVAR_INT ("unread-command-char", &unread_command_char, |
8823 | "If not -1, an object to be read as next command input event."); | |
8824 | ||
284f4730 JB |
8825 | DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char, |
8826 | "Meta-prefix character code. Meta-foo as command input\n\ | |
8827 | turns into this character followed by foo."); | |
18cd2eeb | 8828 | XSETINT (meta_prefix_char, 033); |
284f4730 | 8829 | |
6c7178b9 | 8830 | DEFVAR_KBOARD ("last-command", Vlast_command, |
284f4730 JB |
8831 | "The last command executed. Normally a symbol with a function definition,\n\ |
8832 | but can be whatever was found in the keymap, or whatever the variable\n\ | |
18f29056 RS |
8833 | `this-command' was set to by that command.\n\ |
8834 | \n\ | |
8835 | The value `mode-exit' is special; it means that the previous command\n\ | |
8836 | read an event that told it to exit, and it did so and unread that event.\n\ | |
8837 | In other words, the present command is the event that made the previous\n\ | |
8838 | command exit.\n\ | |
8839 | \n\ | |
8840 | The value `kill-region' is special; it means that the previous command\n\ | |
8841 | was a kill command."); | |
284f4730 | 8842 | |
75045dcb RS |
8843 | DEFVAR_KBOARD ("real-last-command", Vreal_last_command, |
8844 | "Same as `last-command', but never altered by Lisp code."); | |
8845 | ||
284f4730 JB |
8846 | DEFVAR_LISP ("this-command", &this_command, |
8847 | "The command now being executed.\n\ | |
8848 | The command can set this variable; whatever is put here\n\ | |
8849 | will be in `last-command' during the following command."); | |
8850 | this_command = Qnil; | |
8851 | ||
8852 | DEFVAR_INT ("auto-save-interval", &auto_save_interval, | |
8853 | "*Number of keyboard input characters between auto-saves.\n\ | |
8854 | Zero means disable autosaving due to number of characters typed."); | |
8855 | auto_save_interval = 300; | |
8856 | ||
8857 | DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout, | |
8858 | "*Number of seconds idle time before auto-save.\n\ | |
06ef7355 RS |
8859 | Zero or nil means disable auto-saving due to idleness.\n\ |
8860 | After auto-saving due to this many seconds of idle time,\n\ | |
84447c71 | 8861 | Emacs also does a garbage collection if that seems to be warranted."); |
bb9e9bed | 8862 | XSETFASTINT (Vauto_save_timeout, 30); |
284f4730 JB |
8863 | |
8864 | DEFVAR_INT ("echo-keystrokes", &echo_keystrokes, | |
8865 | "*Nonzero means echo unfinished commands after this many seconds of pause."); | |
8866 | echo_keystrokes = 1; | |
8867 | ||
8868 | DEFVAR_INT ("polling-period", &polling_period, | |
8869 | "*Interval between polling for input during Lisp execution.\n\ | |
8870 | The reason for polling is to make C-g work to stop a running program.\n\ | |
8871 | Polling is needed only when using X windows and SIGIO does not work.\n\ | |
8872 | Polling is automatically disabled in all other cases."); | |
8873 | polling_period = 2; | |
df0f2ba1 | 8874 | |
564dc952 | 8875 | DEFVAR_LISP ("double-click-time", &Vdouble_click_time, |
fbcd35bd | 8876 | "*Maximum time between mouse clicks to make a double-click.\n\ |
564dc952 JB |
8877 | Measured in milliseconds. nil means disable double-click recognition;\n\ |
8878 | t means double-clicks have no time limit and are detected\n\ | |
fbcd35bd | 8879 | by position only."); |
aab06933 | 8880 | Vdouble_click_time = make_number (500); |
fbcd35bd | 8881 | |
03361bcc RS |
8882 | DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus, |
8883 | "*Non-nil means inhibit local map menu bar menus."); | |
8884 | inhibit_local_menu_bar_menus = 0; | |
8885 | ||
284f4730 | 8886 | DEFVAR_INT ("num-input-keys", &num_input_keys, |
c43b1734 | 8887 | "Number of complete key sequences read as input so far.\n\ |
58ce35fb KH |
8888 | This includes key sequences read from keyboard macros.\n\ |
8889 | The number is effectively the number of interactive command invocations."); | |
284f4730 JB |
8890 | num_input_keys = 0; |
8891 | ||
c43b1734 RS |
8892 | DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events, |
8893 | "Number of input events read from the keyboard so far.\n\ | |
8894 | This does not include events generated by keyboard macros."); | |
8895 | num_nonmacro_input_events = 0; | |
fa90970d | 8896 | |
4c52b668 KH |
8897 | DEFVAR_LISP ("last-event-frame", &Vlast_event_frame, |
8898 | "The frame in which the most recently read event occurred.\n\ | |
8899 | If the last event came from a keyboard macro, this is set to `macro'."); | |
8900 | Vlast_event_frame = Qnil; | |
8901 | ||
fa90970d RS |
8902 | /* This variable is set up in sysdep.c. */ |
8903 | DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char, | |
8904 | "The ERASE character as set by the user with stty."); | |
8905 | ||
7e85b935 | 8906 | DEFVAR_LISP ("help-char", &Vhelp_char, |
284f4730 JB |
8907 | "Character to recognize as meaning Help.\n\ |
8908 | When it is read, do `(eval help-form)', and display result if it's a string.\n\ | |
8909 | If the value of `help-form' is nil, this char can be read normally."); | |
18cd2eeb | 8910 | XSETINT (Vhelp_char, Ctl ('H')); |
284f4730 | 8911 | |
ecb7cb34 KH |
8912 | DEFVAR_LISP ("help-event-list", &Vhelp_event_list, |
8913 | "List of input events to recognize as meaning Help.\n\ | |
8914 | These work just like the value of `help-char' (see that)."); | |
8915 | Vhelp_event_list = Qnil; | |
8916 | ||
284f4730 | 8917 | DEFVAR_LISP ("help-form", &Vhelp_form, |
7e85b935 | 8918 | "Form to execute when character `help-char' is read.\n\ |
284f4730 JB |
8919 | If the form returns a string, that string is displayed.\n\ |
8920 | If `help-form' is nil, the help char is not recognized."); | |
8921 | Vhelp_form = Qnil; | |
8922 | ||
7e85b935 RS |
8923 | DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command, |
8924 | "Command to run when `help-char' character follows a prefix key.\n\ | |
8925 | This command is used only when there is no actual binding\n\ | |
8926 | for that character after that prefix key."); | |
8927 | Vprefix_help_command = Qnil; | |
8928 | ||
284f4730 JB |
8929 | DEFVAR_LISP ("top-level", &Vtop_level, |
8930 | "Form to evaluate when Emacs starts up.\n\ | |
8931 | Useful to set before you dump a modified Emacs."); | |
8932 | Vtop_level = Qnil; | |
8933 | ||
8934 | DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table, | |
f9414d62 | 8935 | "Translate table for keyboard input, or nil.\n\ |
284f4730 | 8936 | Each character is looked up in this string and the contents used instead.\n\ |
f9414d62 RS |
8937 | The value may be a string, a vector, or a char-table.\n\ |
8938 | If it is a string or vector of length N,\n\ | |
8939 | character codes N and up are untranslated.\n\ | |
8940 | In a vector or a char-table, an element which is nil means \"no translation\"."); | |
284f4730 JB |
8941 | Vkeyboard_translate_table = Qnil; |
8942 | ||
8026024c KH |
8943 | DEFVAR_BOOL ("cannot-suspend", &cannot_suspend, |
8944 | "Non-nil means to always spawn a subshell instead of suspending,\n\ | |
8945 | even if the operating system has support for stopping a process."); | |
8946 | cannot_suspend = 0; | |
8947 | ||
284f4730 | 8948 | DEFVAR_BOOL ("menu-prompting", &menu_prompting, |
7d6de002 | 8949 | "Non-nil means prompt with menus when appropriate.\n\ |
284f4730 | 8950 | This is done when reading from a keymap that has a prompt string,\n\ |
7d6de002 RS |
8951 | for elements that have prompt strings.\n\ |
8952 | The menu is displayed on the screen\n\ | |
8953 | if X menus were enabled at configuration\n\ | |
8954 | time and the previous event was a mouse click prefix key.\n\ | |
8955 | Otherwise, menu prompting uses the echo area."); | |
284f4730 JB |
8956 | menu_prompting = 1; |
8957 | ||
8958 | DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char, | |
8959 | "Character to see next line of menu prompt.\n\ | |
8960 | Type this character while in a menu prompt to rotate around the lines of it."); | |
18cd2eeb | 8961 | XSETINT (menu_prompt_more_char, ' '); |
9fa4395d RS |
8962 | |
8963 | DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers, | |
8964 | "A mask of additional modifier keys to use with every keyboard character.\n\ | |
ad163903 JB |
8965 | Emacs applies the modifiers of the character stored here to each keyboard\n\ |
8966 | character it reads. For example, after evaluating the expression\n\ | |
9d9f56dd | 8967 | (setq extra-keyboard-modifiers ?\\C-x)\n\ |
80645119 JB |
8968 | all input characters will have the control modifier applied to them.\n\ |
8969 | \n\ | |
9d9f56dd | 8970 | Note that the character ?\\C-@, equivalent to the integer zero, does\n\ |
80645119 | 8971 | not count as a control character; rather, it counts as a character\n\ |
27203ead | 8972 | with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\ |
80645119 | 8973 | cancels any modification."); |
9fa4395d | 8974 | extra_keyboard_modifiers = 0; |
86e5706b RS |
8975 | |
8976 | DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark, | |
8977 | "If an editing command sets this to t, deactivate the mark afterward.\n\ | |
8978 | The command loop sets this to nil before each command,\n\ | |
8979 | and tests the value when the command returns.\n\ | |
8980 | Buffer modification stores t in this variable."); | |
8981 | Vdeactivate_mark = Qnil; | |
8982 | ||
b0f2a7bf KH |
8983 | DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal, |
8984 | "Temporary storage of pre-command-hook or post-command-hook."); | |
8985 | Vcommand_hook_internal = Qnil; | |
8986 | ||
86e5706b | 8987 | DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook, |
a1fd42c0 | 8988 | "Normal hook run before each command is executed.\n\ |
59aadc81 | 8989 | Errors running the hook are caught and ignored."); |
86e5706b RS |
8990 | Vpre_command_hook = Qnil; |
8991 | ||
8992 | DEFVAR_LISP ("post-command-hook", &Vpost_command_hook, | |
a1fd42c0 | 8993 | "Normal hook run after each command is executed.\n\ |
59aadc81 | 8994 | Errors running the hook are caught and ignored."); |
86e5706b | 8995 | Vpost_command_hook = Qnil; |
48e416d4 | 8996 | |
59aadc81 RS |
8997 | DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook, |
8998 | "Normal hook run after each command is executed, if idle.\n\ | |
d4d62e8d RS |
8999 | Errors running the hook are caught and ignored.\n\ |
9000 | This feature is obsolete; use idle timers instead. See `etc/NEWS'."); | |
59aadc81 RS |
9001 | Vpost_command_idle_hook = Qnil; |
9002 | ||
9003 | DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay, | |
7051b69b | 9004 | "Delay time before running `post-command-idle-hook'.\n\ |
59aadc81 RS |
9005 | This is measured in microseconds."); |
9006 | post_command_idle_delay = 100000; | |
9007 | ||
cdb9d665 RS |
9008 | #if 0 |
9009 | DEFVAR_LISP ("echo-area-clear-hook", ..., | |
9010 | "Normal hook run when clearing the echo area."); | |
9011 | #endif | |
9012 | Qecho_area_clear_hook = intern ("echo-area-clear-hook"); | |
9013 | XSYMBOL (Qecho_area_clear_hook)->value = Qnil; | |
9014 | ||
48e416d4 RS |
9015 | DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag, |
9016 | "t means menu bar, specified Lucid style, needs to be recomputed."); | |
9017 | Vlucid_menu_bar_dirty_flag = Qnil; | |
a73c5e29 | 9018 | |
9f9c0e27 RS |
9019 | DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items, |
9020 | "List of menu bar items to move to the end of the menu bar.\n\ | |
a612e298 | 9021 | The elements of the list are event types that may have menu bar bindings."); |
9f9c0e27 | 9022 | Vmenu_bar_final_items = Qnil; |
e9bf89a0 | 9023 | |
217258d5 KH |
9024 | DEFVAR_KBOARD ("overriding-terminal-local-map", |
9025 | Voverriding_terminal_local_map, | |
779b34df | 9026 | "Per-terminal keymap that overrides all other local keymaps.\n\ |
217258d5 | 9027 | If this variable is non-nil, it is used as a keymap instead of the\n\ |
779b34df RS |
9028 | buffer's local map, and the minor mode keymaps and text property keymaps.\n\ |
9029 | This variable is intended to let commands such as `universal-argumemnt'\n\ | |
9030 | set up a different keymap for reading the next command."); | |
217258d5 | 9031 | |
9dd3131c RS |
9032 | DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map, |
9033 | "Keymap that overrides all other local keymaps.\n\ | |
9034 | If this variable is non-nil, it is used as a keymap instead of the\n\ | |
9035 | buffer's local map, and the minor mode keymaps and text property keymaps."); | |
9036 | Voverriding_local_map = Qnil; | |
9037 | ||
d0a49716 RS |
9038 | DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag, |
9039 | "Non-nil means `overriding-local-map' applies to the menu bar.\n\ | |
9040 | Otherwise, the menu bar continues to reflect the buffer's local map\n\ | |
9041 | and the minor mode maps regardless of `overriding-local-map'."); | |
9042 | Voverriding_local_map_menu_flag = Qnil; | |
9043 | ||
7f07d5ca RS |
9044 | DEFVAR_LISP ("special-event-map", &Vspecial_event_map, |
9045 | "Keymap defining bindings for special events to execute at low level."); | |
9046 | Vspecial_event_map = Fcons (intern ("keymap"), Qnil); | |
9047 | ||
71edead1 | 9048 | DEFVAR_LISP ("track-mouse", &do_mouse_tracking, |
a53c7666 | 9049 | "*Non-nil means generate motion events for mouse motion."); |
80e4aa30 | 9050 | |
7c97ffdc | 9051 | DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist, |
270a208f | 9052 | "Alist of system-specific X windows key symbols.\n\ |
80e4aa30 | 9053 | Each element should have the form (N . SYMBOL) where N is the\n\ |
270a208f | 9054 | numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\ |
80e4aa30 | 9055 | and SYMBOL is its name."); |
8a792f3a RS |
9056 | |
9057 | DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list, | |
9058 | "List of deferred actions to be performed at a later time.\n\ | |
9059 | The precise format isn't relevant here; we just check whether it is nil."); | |
9060 | Vdeferred_action_list = Qnil; | |
9061 | ||
9062 | DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function, | |
9063 | "Function to call to handle deferred actions, after each command.\n\ | |
9064 | This function is called with no arguments after each command\n\ | |
9065 | whenever `deferred-action-list' is non-nil."); | |
9066 | Vdeferred_action_function = Qnil; | |
6526ab49 RS |
9067 | |
9068 | DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings, | |
ac52ebd5 | 9069 | "*Non-nil means show the equivalent key-binding when M-x command has one.\n\ |
6526ab49 RS |
9070 | The value can be a length of time to show the message for.\n\ |
9071 | If the value is non-nil and not a number, we wait 2 seconds."); | |
9072 | Vsuggest_key_bindings = Qt; | |
8bb1c042 | 9073 | |
c04cbc3b | 9074 | DEFVAR_LISP ("timer-list", &Vtimer_list, |
d9d4c147 | 9075 | "List of active absolute time timers in order of increasing time"); |
c04cbc3b | 9076 | Vtimer_list = Qnil; |
d9d4c147 KH |
9077 | |
9078 | DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list, | |
9079 | "List of active idle-time timers in order of increasing time"); | |
9080 | Vtimer_idle_list = Qnil; | |
284f4730 JB |
9081 | } |
9082 | ||
dfcf069d | 9083 | void |
284f4730 JB |
9084 | keys_of_keyboard () |
9085 | { | |
9086 | initial_define_key (global_map, Ctl ('Z'), "suspend-emacs"); | |
9087 | initial_define_key (control_x_map, Ctl ('Z'), "suspend-emacs"); | |
9088 | initial_define_key (meta_map, Ctl ('C'), "exit-recursive-edit"); | |
9089 | initial_define_key (global_map, Ctl (']'), "abort-recursive-edit"); | |
9090 | initial_define_key (meta_map, 'x', "execute-extended-command"); | |
7f07d5ca RS |
9091 | |
9092 | initial_define_lispy_key (Vspecial_event_map, "delete-frame", | |
9093 | "handle-delete-frame"); | |
9094 | initial_define_lispy_key (Vspecial_event_map, "iconify-frame", | |
9095 | "ignore-event"); | |
9096 | initial_define_lispy_key (Vspecial_event_map, "make-frame-visible", | |
9097 | "ignore-event"); | |
284f4730 | 9098 | } |