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