Mercurial > emacs
annotate src/keyboard.c @ 1328:c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
areas as if they were prefixed with the symbol denoting the
area clicked on - `mode-line', etcetera.
When we throw away an unbound `down-' event, reset mock_input as
well.
* keyboard.c (Qevent_symbol_element_mask, Qmodifier_cache): Two
new symbols, used to implement caches on event heads. These take
the place of some of the caching that modify_event_symbol used to do.
(parse_modifiers_uncached, apply_modifiers_uncached,
lispy_modifier_list, parse_modifiers, apply_modifiers): New
functions, which replace format_modifiers and reorder_modifiers;
they can be useful elsewhere too.
(reorder_modifiers, modify_event_symbol): Re-implement these in
terms of parse_modifiers and apply_modifiers. modify_event_symbol
now uses a much simpler cache, and takes advantage of the caches
maintained by parse_ and apply_modifiers.
(follow_key): Don't modify NEXT if KEY has no bindings.
(read_key_sequence): Drop unbound `down-' events, and turn unbound
`drag-' events into clicks if that would make them bound. This
benefits from the rewriting of the modifier key handling code.
(syms_of_keyboard): Initialize and intern
Qevent_symbol_element_mask and Qmodifier_cache.
* keyboard.c (echo_prompt): Terminate the echo buffer properly
even when the string is too long to display in the minibuffer.
(echo_truncate): Just return echoptr - echobuf, rather than
calling strlen on echobuf.
* keyboard.c (modifier_names): The modifier is named "control",
not "ctrl".
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sat, 03 Oct 1992 15:37:35 +0000 |
parents | 5f327f1dddd3 |
children | 5845050f9d5c |
rev | line source |
---|---|
518 | 1 /* Keyboard and mouse input; editor command loop. |
586 | 2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1992 Free Software Foundation, Inc. |
518 | 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 | |
8 the Free Software Foundation; either version 1, or (at your option) | |
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 | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 /* Allow config.h to undefine symbols found here. */ | |
21 #include <signal.h> | |
22 | |
23 #include "config.h" | |
24 #include <stdio.h> | |
25 #undef NULL | |
26 #include "termchar.h" | |
27 #include "termopts.h" | |
28 #include "lisp.h" | |
29 #include "termhooks.h" | |
30 #include "macros.h" | |
765 | 31 #include "frame.h" |
518 | 32 #include "window.h" |
33 #include "commands.h" | |
34 #include "buffer.h" | |
35 #include "disptab.h" | |
36 #include "keyboard.h" | |
37 #include <setjmp.h> | |
38 #include <errno.h> | |
39 | |
562 | 40 #ifndef VMS |
41 #include <sys/ioctl.h> | |
42 #endif | |
43 | |
44 #include "syssignal.h" | |
1046
d4b1e5db2b2a
* keyboard.c: Include "systty.h", not "systerm.h".
Jim Blandy <jimb@redhat.com>
parents:
1008
diff
changeset
|
45 #include "systty.h" |
648 | 46 #include "systime.h" |
518 | 47 |
48 extern int errno; | |
49 | |
50 #ifdef HAVE_X_WINDOWS | |
51 extern Lisp_Object Vmouse_grabbed; | |
52 | |
53 /* Make all keyboard buffers much bigger when using X windows. */ | |
54 #define KBD_BUFFER_SIZE 4096 | |
55 #else /* No X-windows, character input */ | |
56 #define KBD_BUFFER_SIZE 256 | |
57 #endif /* No X-windows */ | |
58 | |
59 /* Following definition copied from eval.c */ | |
60 | |
61 struct backtrace | |
62 { | |
63 struct backtrace *next; | |
64 Lisp_Object *function; | |
65 Lisp_Object *args; /* Points to vector of args. */ | |
66 int nargs; /* length of vector. If nargs is UNEVALLED, | |
67 args points to slot holding list of | |
68 unevalled args */ | |
69 char evalargs; | |
70 }; | |
71 | |
72 /* Non-nil disable property on a command means | |
73 do not execute it; call disabled-command-hook's value instead. */ | |
74 Lisp_Object Qdisabled, Vdisabled_command_hook; | |
75 | |
76 #define NUM_RECENT_KEYS (100) | |
77 int recent_keys_index; /* Index for storing next element into recent_keys */ | |
78 int total_keys; /* Total number of elements stored into recent_keys */ | |
1261
60b30565326c
* keyboard.c (recent_keys): Turn this from an array, which is a
Jim Blandy <jimb@redhat.com>
parents:
1239
diff
changeset
|
79 Lisp_Object recent_keys; /* A vector, holding the last 100 keystrokes */ |
518 | 80 |
81 /* Buffer holding the key that invoked the current command. */ | |
82 Lisp_Object *this_command_keys; | |
83 int this_command_key_count; /* Size in use. */ | |
84 int this_command_keys_size; /* Size allocated. */ | |
85 | |
86 extern int minbuf_level; | |
87 | |
88 extern struct backtrace *backtrace_list; | |
89 | |
90 /* Nonzero means do menu prompting. */ | |
91 static int menu_prompting; | |
92 | |
93 /* Character to see next line of menu prompt. */ | |
94 static Lisp_Object menu_prompt_more_char; | |
95 | |
96 /* For longjmp to where kbd input is being done. */ | |
97 static jmp_buf getcjmp; | |
98 | |
99 /* True while doing kbd input. */ | |
100 int waiting_for_input; | |
101 | |
102 /* True while displaying for echoing. Delays C-g throwing. */ | |
103 static int echoing; | |
104 | |
105 /* Nonzero means C-G should cause immediate error-signal. */ | |
106 int immediate_quit; | |
107 | |
108 /* Character to recognize as the help char. */ | |
109 Lisp_Object help_char; | |
110 | |
111 /* Form to execute when help char is typed. */ | |
112 Lisp_Object Vhelp_form; | |
113 | |
114 /* Character that causes a quit. Normally C-g. | |
115 | |
116 If we are running on an ordinary terminal, this must be an ordinary | |
117 ASCII char, since we want to make it our interrupt character. | |
118 | |
119 If we are not running on an ordinary terminal, it still needs to be | |
120 an ordinary ASCII char. This character needs to be recognized in | |
121 the input interrupt handler. At this point, the keystroke is | |
122 represented as a struct input_event, while the desired quit | |
123 character is specified as a lispy event. The mapping from struct | |
124 input_events to lispy events cannot run in an interrupt handler, | |
125 and the reverse mapping is difficult for anything but ASCII | |
126 keystrokes. | |
127 | |
128 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an | |
129 ASCII character. */ | |
130 int quit_char; | |
131 | |
132 extern Lisp_Object current_global_map; | |
133 extern int minibuf_level; | |
134 | |
135 /* Current depth in recursive edits. */ | |
136 int command_loop_level; | |
137 | |
138 /* Total number of times command_loop has read a key sequence. */ | |
139 int num_input_keys; | |
140 | |
141 /* Last input character read as a command. */ | |
142 Lisp_Object last_command_char; | |
143 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
144 /* Last input character read as a command, not counting menus |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
145 reached by the mouse. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
146 Lisp_Object last_nonmenu_event; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
147 |
518 | 148 /* Last input character read for any purpose. */ |
149 Lisp_Object last_input_char; | |
150 | |
151 /* If not Qnil, an object to be read as the next command input. */ | |
152 Lisp_Object unread_command_char; | |
153 | |
154 /* Char to use as prefix when a meta character is typed in. | |
155 This is bound on entry to minibuffer in case ESC is changed there. */ | |
156 | |
157 Lisp_Object meta_prefix_char; | |
158 | |
159 /* Last size recorded for a current buffer which is not a minibuffer. */ | |
160 static int last_non_minibuf_size; | |
161 | |
687
e2b747dd6a6e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
682
diff
changeset
|
162 /* Number of idle seconds before an auto-save and garbage collection. */ |
518 | 163 static Lisp_Object Vauto_save_timeout; |
164 | |
165 /* Total number of times read_char has returned. */ | |
166 int num_input_chars; | |
167 | |
1104
f3a7122a68e1
(num_nonmacro_input_chars): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1097
diff
changeset
|
168 /* Total number of times read_char has returned, outside of macros. */ |
f3a7122a68e1
(num_nonmacro_input_chars): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1097
diff
changeset
|
169 int num_nonmacro_input_chars; |
f3a7122a68e1
(num_nonmacro_input_chars): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1097
diff
changeset
|
170 |
518 | 171 /* Auto-save automatically when this many characters have been typed |
172 since the last time. */ | |
173 | |
174 static int auto_save_interval; | |
175 | |
1104
f3a7122a68e1
(num_nonmacro_input_chars): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1097
diff
changeset
|
176 /* Value of num_nonmacro_input_chars as of last auto save. */ |
518 | 177 |
178 int last_auto_save; | |
179 | |
180 /* Last command executed by the editor command loop, not counting | |
181 commands that set the prefix argument. */ | |
182 | |
183 Lisp_Object last_command; | |
184 | |
185 /* The command being executed by the command loop. | |
186 Commands may set this, and the value set will be copied into last_command | |
187 instead of the actual command. */ | |
188 Lisp_Object this_command; | |
189 | |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
190 #ifdef MULTI_FRAME |
1239
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
191 /* The frame in which the last input event occurred, or Qmacro if the |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
192 last event came from a macro. |
765 | 193 command_loop_1 will select this frame before running the |
518 | 194 command bound to an event sequence, and read_key_sequence will |
195 toss the existing prefix if the user starts typing at a | |
765 | 196 new frame. */ |
197 Lisp_Object Vlast_event_frame; | |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
198 #endif |
518 | 199 |
708 | 200 /* The timestamp of the last input event we received from the X server. |
201 X Windows wants this for selection ownership. */ | |
518 | 202 unsigned long last_event_timestamp; |
203 | |
204 Lisp_Object Qself_insert_command; | |
205 Lisp_Object Qforward_char; | |
206 Lisp_Object Qbackward_char; | |
207 | |
208 /* read_key_sequence stores here the command definition of the | |
209 key sequence that it reads. */ | |
210 Lisp_Object read_key_sequence_cmd; | |
211 | |
212 /* Form to evaluate (if non-nil) when Emacs is started. */ | |
213 Lisp_Object Vtop_level; | |
214 | |
215 /* User-supplied string to translate input characters through. */ | |
216 Lisp_Object Vkeyboard_translate_table; | |
217 | |
218 /* Keymap mapping ASCII function key sequences onto their preferred forms. */ | |
219 extern Lisp_Object Vfunction_key_map; | |
220 | |
221 /* File in which we write all commands we read. */ | |
222 FILE *dribble; | |
223 | |
224 /* Nonzero if input is available. */ | |
225 int input_pending; | |
226 | |
227 /* Nonzero if should obey 0200 bit in input chars as "Meta". */ | |
228 int meta_key; | |
229 | |
230 extern char *pending_malloc_warning; | |
231 | |
232 /* Circular buffer for pre-read keyboard input. */ | |
233 static struct input_event kbd_buffer[KBD_BUFFER_SIZE]; | |
234 | |
235 /* Pointer to next available character in kbd_buffer. | |
236 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty. | |
237 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the | |
238 next available char is in kbd_buffer[0]. */ | |
239 static struct input_event *kbd_fetch_ptr; | |
240 | |
241 /* Pointer to next place to store character in kbd_buffer. This | |
242 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next | |
243 character should go in kbd_buffer[0]. */ | |
244 static struct input_event *kbd_store_ptr; | |
245 | |
246 /* The above pair of variables forms a "queue empty" flag. When we | |
247 enqueue a non-hook event, we increment kbd_write_count. When we | |
248 dequeue a non-hook event, we increment kbd_read_count. We say that | |
249 there is input available iff the two counters are equal. | |
250 | |
251 Why not just have a flag set and cleared by the enqueuing and | |
252 dequeuing functions? Such a flag could be screwed up by interrupts | |
253 at inopportune times. */ | |
254 | |
255 /* If this flag is non-zero, mouse movement events will appear in the | |
256 input stream. If is zero, mouse movement will be ignored. */ | |
257 int do_mouse_tracking; | |
258 | |
259 /* The window system handling code should set this if the mouse has | |
260 moved since the last call to the mouse_position_hook. Calling that | |
261 hook should clear this. Code assumes that if this is set, it can | |
262 call mouse_position_hook to get the promised position, so don't set | |
263 it unless you're prepared to substantiate the claim! */ | |
264 int mouse_moved; | |
265 | |
266 /* True iff there is an event in kbd_buffer, or if mouse tracking is | |
267 enabled and there is a new mouse position in the mouse movement | |
268 buffer. Note that if this is false, that doesn't mean that there | |
269 is readable input; all the events in the queue might be button-up | |
270 events, and do_mouse_tracking might be off. */ | |
271 #define EVENT_QUEUES_EMPTY \ | |
272 ((kbd_fetch_ptr == kbd_store_ptr) && (!do_mouse_tracking || !mouse_moved)) | |
273 | |
274 | |
275 /* Symbols to head events. */ | |
276 Lisp_Object Qmouse_movement; | |
277 | |
278 Lisp_Object Qvscrollbar_part; | |
279 Lisp_Object Qvslider_part; | |
280 Lisp_Object Qvthumbup_part; | |
281 Lisp_Object Qvthumbdown_part; | |
282 | |
283 Lisp_Object Qhscrollbar_part; | |
284 Lisp_Object Qhslider_part; | |
285 Lisp_Object Qhthumbleft_part; | |
286 Lisp_Object Qhthumbright_part; | |
287 | |
288 /* Symbols to denote kinds of events. */ | |
289 Lisp_Object Qfunction_key; | |
290 Lisp_Object Qmouse_click; | |
291 /* Lisp_Object Qmouse_movement; - also an event header */ | |
292 Lisp_Object Qscrollbar_click; | |
293 | |
294 /* Properties of event headers. */ | |
295 Lisp_Object Qevent_kind; | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
296 Lisp_Object Qevent_symbol_elements; |
518 | 297 |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
298 /* An event header symbol HEAD may have a property named |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
299 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
300 BASE is the base, unmodified version of HEAD, and MODIFIERS is the |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
301 mask of modifiers applied to it. If present, this is used to help |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
302 speed up parse_modifiers. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
303 Lisp_Object Qevent_symbol_element_mask; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
304 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
305 /* An unmodified event header BASE may have a property named |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
306 Qmodifier_cache, which is an alist mapping modifier masks onto |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
307 modified versions of BASE. If present, this helps speed up |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
308 apply_modifiers. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
309 Lisp_Object Qmodifier_cache; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
310 |
518 | 311 /* Symbols to use for non-text mouse positions. */ |
312 Lisp_Object Qmode_line; | |
732 | 313 Lisp_Object Qvertical_line; |
518 | 314 |
315 | |
648 | 316 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt |
317 happens. */ | |
318 EMACS_TIME *input_available_clear_time; | |
518 | 319 |
320 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode. | |
321 Default is 1 if INTERRUPT_INPUT is defined. */ | |
322 int interrupt_input; | |
323 | |
324 /* Nonzero while interrupts are temporarily deferred during redisplay. */ | |
325 int interrupts_deferred; | |
326 | |
327 /* nonzero means use ^S/^Q for flow control. */ | |
328 int flow_control; | |
329 | |
330 /* Allow m- file to inhibit use of FIONREAD. */ | |
331 #ifdef BROKEN_FIONREAD | |
332 #undef FIONREAD | |
333 #endif | |
334 | |
335 /* We are unable to use interrupts if FIONREAD is not available, | |
336 so flush SIGIO so we won't try. */ | |
337 #ifndef FIONREAD | |
338 #ifdef SIGIO | |
339 #undef SIGIO | |
340 #endif | |
341 #endif | |
342 | |
343 /* If we support X Windows, and won't get an interrupt when input | |
344 arrives from the server, poll periodically so we can detect C-g. */ | |
345 #ifdef HAVE_X_WINDOWS | |
346 #ifndef SIGIO | |
347 #define POLL_FOR_INPUT | |
348 #endif | |
349 #endif | |
350 | |
351 /* Global variable declarations. */ | |
352 | |
353 /* Function for init_keyboard to call with no args (if nonzero). */ | |
354 void (*keyboard_init_hook) (); | |
355 | |
356 static int read_avail_input (); | |
357 static void get_input_pending (); | |
358 | |
359 /* > 0 if we are to echo keystrokes. */ | |
360 static int echo_keystrokes; | |
361 | |
362 /* Nonzero means echo each character as typed. */ | |
363 static int immediate_echo; | |
364 | |
365 /* The text we're echoing in the modeline - partial key sequences, | |
366 usually. '\0'-terminated. */ | |
367 static char echobuf[100]; | |
368 | |
369 /* Where to append more text to echobuf if we want to. */ | |
370 static char *echoptr; | |
371 | |
372 #define min(a,b) ((a)<(b)?(a):(b)) | |
373 #define max(a,b) ((a)>(b)?(a):(b)) | |
374 | |
375 /* Install the string STR as the beginning of the string of echoing, | |
376 so that it serves as a prompt for the next character. | |
377 Also start echoing. */ | |
378 | |
379 echo_prompt (str) | |
380 char *str; | |
381 { | |
382 int len = strlen (str); | |
383 if (len > sizeof echobuf - 4) | |
384 len = sizeof echobuf - 4; | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
385 bcopy (str, echobuf, len); |
518 | 386 echoptr = echobuf + len; |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
387 *echoptr = '\0'; |
518 | 388 |
389 echo (); | |
390 } | |
391 | |
392 /* Add C to the echo string, if echoing is going on. | |
393 C can be a character, which is printed prettily ("M-C-x" and all that | |
394 jazz), or a symbol, whose name is printed. */ | |
395 | |
396 echo_char (c) | |
397 Lisp_Object c; | |
398 { | |
399 extern char *push_key_description (); | |
400 | |
401 if (immediate_echo) | |
402 { | |
403 char *ptr = echoptr; | |
404 | |
405 if (ptr != echobuf) | |
406 *ptr++ = ' '; | |
407 | |
408 /* If someone has passed us a composite event, use its head symbol. */ | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
409 c = EVENT_HEAD (c); |
518 | 410 |
411 if (XTYPE (c) == Lisp_Int) | |
412 { | |
413 if (ptr - echobuf > sizeof echobuf - 6) | |
414 return; | |
415 | |
416 ptr = push_key_description (c, ptr); | |
417 } | |
418 else if (XTYPE (c) == Lisp_Symbol) | |
419 { | |
420 struct Lisp_String *name = XSYMBOL (c)->name; | |
421 if (((ptr - echobuf) + name->size + 4) > sizeof echobuf) | |
422 return; | |
423 bcopy (name->data, ptr, name->size); | |
424 ptr += name->size; | |
425 } | |
426 | |
427 if (echoptr == echobuf && c == help_char) | |
428 { | |
429 strcpy (ptr, " (Type ? for further options)"); | |
430 ptr += strlen (ptr); | |
431 } | |
432 | |
433 *ptr = 0; | |
434 echoptr = ptr; | |
435 | |
436 echo (); | |
437 } | |
438 } | |
439 | |
440 /* Temporarily add a dash to the end of the echo string if it's not | |
441 empty, so that it serves as a mini-prompt for the very next character. */ | |
442 | |
443 echo_dash () | |
444 { | |
445 if (!immediate_echo && echoptr == echobuf) | |
446 return; | |
447 | |
448 /* Put a dash at the end of the buffer temporarily, | |
449 but make it go away when the next character is added. */ | |
450 echoptr[0] = '-'; | |
451 echoptr[1] = 0; | |
452 | |
453 echo (); | |
454 } | |
455 | |
456 /* Display the current echo string, and begin echoing if not already | |
457 doing so. */ | |
458 | |
459 echo () | |
460 { | |
461 if (!immediate_echo) | |
462 { | |
463 int i; | |
464 immediate_echo = 1; | |
465 | |
466 for (i = 0; i < this_command_key_count; i++) | |
467 echo_char (this_command_keys[i]); | |
468 echo_dash (); | |
469 } | |
470 | |
471 echoing = 1; | |
472 message1 (echobuf); | |
473 echoing = 0; | |
474 | |
475 if (waiting_for_input && !NILP (Vquit_flag)) | |
476 quit_throw_to_read_char (); | |
477 } | |
478 | |
479 /* Turn off echoing, for the start of a new command. */ | |
480 | |
481 cancel_echoing () | |
482 { | |
483 immediate_echo = 0; | |
484 echoptr = echobuf; | |
485 } | |
486 | |
487 /* Return the length of the current echo string. */ | |
488 | |
489 static int | |
490 echo_length () | |
491 { | |
492 return echoptr - echobuf; | |
493 } | |
494 | |
495 /* Truncate the current echo message to its first LEN chars. | |
496 This and echo_char get used by read_key_sequence when the user | |
765 | 497 switches frames while entering a key sequence. */ |
518 | 498 |
499 static void | |
500 echo_truncate (len) | |
501 int len; | |
502 { | |
503 echobuf[len] = '\0'; | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
504 echoptr = echobuf + len; |
518 | 505 } |
506 | |
507 | |
508 /* Functions for manipulating this_command_keys. */ | |
509 static void | |
510 add_command_key (key) | |
511 Lisp_Object key; | |
512 { | |
513 if (this_command_key_count == this_command_keys_size) | |
514 { | |
515 this_command_keys_size *= 2; | |
516 this_command_keys | |
517 = (Lisp_Object *) xrealloc (this_command_keys, | |
518 (this_command_keys_size | |
519 * sizeof (Lisp_Object))); | |
520 } | |
521 this_command_keys[this_command_key_count++] = key; | |
522 } | |
523 | |
524 Lisp_Object | |
525 recursive_edit_1 () | |
526 { | |
527 int count = specpdl_ptr - specpdl; | |
528 Lisp_Object val; | |
529 | |
530 if (command_loop_level > 0) | |
531 { | |
532 specbind (Qstandard_output, Qt); | |
533 specbind (Qstandard_input, Qt); | |
534 } | |
535 | |
536 val = command_loop (); | |
537 if (EQ (val, Qt)) | |
538 Fsignal (Qquit, Qnil); | |
539 | |
540 unbind_to (count); | |
541 return Qnil; | |
542 } | |
543 | |
544 /* When an auto-save happens, record the "time", and don't do again soon. */ | |
545 record_auto_save () | |
546 { | |
1104
f3a7122a68e1
(num_nonmacro_input_chars): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1097
diff
changeset
|
547 last_auto_save = num_nonmacro_input_chars; |
518 | 548 } |
549 | |
550 Lisp_Object recursive_edit_unwind (), command_loop (); | |
551 | |
552 DEFUN ("recursive-edit", Frecursive_edit, Srecursive_edit, 0, 0, "", | |
553 "Invoke the editor command loop recursively.\n\ | |
554 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\ | |
555 that tells this function to return.\n\ | |
556 Alternately, `(throw 'exit t)' makes this function signal an error.\n\ | |
557 This function is called by the editor initialization to begin editing.") | |
558 () | |
559 { | |
560 int count = specpdl_ptr - specpdl; | |
561 Lisp_Object val; | |
562 | |
563 command_loop_level++; | |
564 update_mode_lines = 1; | |
565 | |
566 record_unwind_protect (recursive_edit_unwind, | |
567 (command_loop_level | |
568 && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer)) | |
569 ? Fcurrent_buffer () | |
570 : Qnil); | |
571 recursive_edit_1 (); | |
572 return unbind_to (count, Qnil); | |
573 } | |
574 | |
575 Lisp_Object | |
576 recursive_edit_unwind (buffer) | |
577 Lisp_Object buffer; | |
578 { | |
579 if (!NILP (buffer)) | |
580 Fset_buffer (buffer); | |
581 | |
582 command_loop_level--; | |
583 update_mode_lines = 1; | |
584 return Qnil; | |
585 } | |
586 | |
587 Lisp_Object | |
588 cmd_error (data) | |
589 Lisp_Object data; | |
590 { | |
591 Lisp_Object errmsg, tail, errname, file_error; | |
592 Lisp_Object stream; | |
593 struct gcpro gcpro1; | |
594 int i; | |
595 | |
596 Vquit_flag = Qnil; | |
597 Vinhibit_quit = Qt; | |
598 Vstandard_output = Qt; | |
599 Vstandard_input = Qt; | |
600 Vexecuting_macro = Qnil; | |
601 echo_area_glyphs = 0; | |
602 | |
765 | 603 /* If the window system or terminal frame hasn't been initialized |
518 | 604 yet, or we're not interactive, it's best to dump this message out |
605 to stderr and exit. */ | |
765 | 606 if (! FRAME_MESSAGE_BUF (selected_frame) |
518 | 607 || noninteractive) |
608 stream = Qexternal_debugging_output; | |
609 else | |
610 { | |
611 Fdiscard_input (); | |
612 bitch_at_user (); | |
613 stream = Qt; | |
614 } | |
615 | |
616 errname = Fcar (data); | |
617 | |
618 if (EQ (errname, Qerror)) | |
619 { | |
620 data = Fcdr (data); | |
621 if (!CONSP (data)) data = Qnil; | |
622 errmsg = Fcar (data); | |
623 file_error = Qnil; | |
624 } | |
625 else | |
626 { | |
627 errmsg = Fget (errname, Qerror_message); | |
628 file_error = Fmemq (Qfile_error, | |
629 Fget (errname, Qerror_conditions)); | |
630 } | |
631 | |
632 /* Print an error message including the data items. | |
633 This is done by printing it into a scratch buffer | |
634 and then making a copy of the text in the buffer. */ | |
635 | |
636 if (!CONSP (data)) data = Qnil; | |
637 tail = Fcdr (data); | |
638 GCPRO1 (tail); | |
639 | |
640 /* For file-error, make error message by concatenating | |
641 all the data items. They are all strings. */ | |
642 if (!NILP (file_error) && !NILP (tail)) | |
643 errmsg = XCONS (tail)->car, tail = XCONS (tail)->cdr; | |
644 | |
645 if (XTYPE (errmsg) == Lisp_String) | |
646 Fprinc (errmsg, stream); | |
647 else | |
648 write_string_1 ("peculiar error", -1, stream); | |
649 | |
650 for (i = 0; CONSP (tail); tail = Fcdr (tail), i++) | |
651 { | |
652 write_string_1 (i ? ", " : ": ", 2, stream); | |
653 if (!NILP (file_error)) | |
654 Fprinc (Fcar (tail), stream); | |
655 else | |
656 Fprin1 (Fcar (tail), stream); | |
657 } | |
658 UNGCPRO; | |
659 | |
765 | 660 /* If the window system or terminal frame hasn't been initialized |
518 | 661 yet, or we're in -batch mode, this error should cause Emacs to exit. */ |
765 | 662 if (! FRAME_MESSAGE_BUF (selected_frame) |
518 | 663 || noninteractive) |
664 { | |
665 Fterpri (stream); | |
666 Fkill_emacs (make_number (-1)); | |
667 } | |
668 | |
669 Vquit_flag = Qnil; | |
670 | |
671 Vinhibit_quit = Qnil; | |
672 return make_number (0); | |
673 } | |
674 | |
675 Lisp_Object command_loop_1 (); | |
676 Lisp_Object command_loop_2 (); | |
677 Lisp_Object top_level_1 (); | |
678 | |
679 /* Entry to editor-command-loop. | |
680 This level has the catches for exiting/returning to editor command loop. | |
681 It returns nil to exit recursive edit, t to abort it. */ | |
682 | |
683 Lisp_Object | |
684 command_loop () | |
685 { | |
686 if (command_loop_level > 0 || minibuf_level > 0) | |
687 { | |
688 return internal_catch (Qexit, command_loop_2, Qnil); | |
689 } | |
690 else | |
691 while (1) | |
692 { | |
693 internal_catch (Qtop_level, top_level_1, Qnil); | |
694 internal_catch (Qtop_level, command_loop_2, Qnil); | |
695 | |
696 /* End of file in -batch run causes exit here. */ | |
697 if (noninteractive) | |
698 Fkill_emacs (Qt); | |
699 } | |
700 } | |
701 | |
702 /* Here we catch errors in execution of commands within the | |
703 editing loop, and reenter the editing loop. | |
704 When there is an error, cmd_error runs and returns a non-nil | |
705 value to us. A value of nil means that cmd_loop_1 itself | |
706 returned due to end of file (or end of kbd macro). */ | |
707 | |
708 Lisp_Object | |
709 command_loop_2 () | |
710 { | |
711 register Lisp_Object val; | |
712 | |
713 do | |
714 val = internal_condition_case (command_loop_1, Qerror, cmd_error); | |
715 while (!NILP (val)); | |
716 | |
717 return Qnil; | |
718 } | |
719 | |
720 Lisp_Object | |
721 top_level_2 () | |
722 { | |
723 return Feval (Vtop_level); | |
724 } | |
725 | |
726 Lisp_Object | |
727 top_level_1 () | |
728 { | |
729 /* On entry to the outer level, run the startup file */ | |
730 if (!NILP (Vtop_level)) | |
731 internal_condition_case (top_level_2, Qerror, cmd_error); | |
732 else if (!NILP (Vpurify_flag)) | |
733 message ("Bare impure Emacs (standard Lisp code not loaded)"); | |
734 else | |
735 message ("Bare Emacs (standard Lisp code not loaded)"); | |
736 return Qnil; | |
737 } | |
738 | |
739 DEFUN ("top-level", Ftop_level, Stop_level, 0, 0, "", | |
740 "Exit all recursive editing levels.") | |
741 () | |
742 { | |
743 Fthrow (Qtop_level, Qnil); | |
744 } | |
745 | |
746 DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, "", | |
747 "Exit from the innermost recursive edit or minibuffer.") | |
748 () | |
749 { | |
750 if (command_loop_level > 0 || minibuf_level > 0) | |
751 Fthrow (Qexit, Qnil); | |
752 | |
753 error ("No recursive edit is in progress"); | |
754 } | |
755 | |
756 DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0, 0, "", | |
757 "Abort the command that requested this recursive edit or minibuffer input.") | |
758 () | |
759 { | |
760 if (command_loop_level > 0 || minibuf_level > 0) | |
761 Fthrow (Qexit, Qt); | |
762 | |
763 error ("No recursive edit is in progress"); | |
764 } | |
765 | |
766 /* This is the actual command reading loop, | |
767 sans error-handling encapsulation. */ | |
768 | |
769 Lisp_Object Fcommand_execute (); | |
770 static int read_key_sequence (); | |
771 | |
772 Lisp_Object | |
773 command_loop_1 () | |
774 { | |
775 Lisp_Object cmd; | |
776 int lose; | |
777 int nonundocount; | |
778 Lisp_Object keybuf[30]; | |
779 int i; | |
780 int no_redisplay; | |
781 int no_direct; | |
782 | |
783 Vprefix_arg = Qnil; | |
784 waiting_for_input = 0; | |
785 cancel_echoing (); | |
786 | |
787 /* Don't clear out last_command at the beginning of a macro. */ | |
788 if (XTYPE (Vexecuting_macro) != Lisp_String) | |
789 last_command = Qt; | |
790 | |
791 nonundocount = 0; | |
792 no_redisplay = 0; | |
793 this_command_key_count = 0; | |
794 | |
795 while (1) | |
796 { | |
797 /* Install chars successfully executed in kbd macro. */ | |
798 | |
799 if (defining_kbd_macro && NILP (Vprefix_arg)) | |
800 finalize_kbd_macro_chars (); | |
801 | |
802 /* Make sure the current window's buffer is selected. */ | |
803 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer) | |
804 set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer)); | |
805 | |
806 /* Display any malloc warning that just came out. Use while because | |
807 displaying one warning can cause another. */ | |
808 | |
809 while (pending_malloc_warning) | |
810 display_malloc_warning (); | |
811 | |
812 no_direct = 0; | |
813 | |
814 /* If minibuffer on and echo area in use, | |
815 wait 2 sec and redraw minibufer. */ | |
816 | |
817 if (minibuf_level && echo_area_glyphs) | |
818 { | |
1097
d9efc1c88574
(command_loop_1): Bind inhibit-quit to t when in Fsit_for.
Richard M. Stallman <rms@gnu.org>
parents:
1083
diff
changeset
|
819 /* Bind inhibit-quit to t so that C-g gets read in |
d9efc1c88574
(command_loop_1): Bind inhibit-quit to t when in Fsit_for.
Richard M. Stallman <rms@gnu.org>
parents:
1083
diff
changeset
|
820 rather than quitting back to the minibuffer. */ |
d9efc1c88574
(command_loop_1): Bind inhibit-quit to t when in Fsit_for.
Richard M. Stallman <rms@gnu.org>
parents:
1083
diff
changeset
|
821 int count = specpdl_ptr - specpdl; |
d9efc1c88574
(command_loop_1): Bind inhibit-quit to t when in Fsit_for.
Richard M. Stallman <rms@gnu.org>
parents:
1083
diff
changeset
|
822 specbind (Qinhibit_quit, Qt); |
518 | 823 Fsit_for (make_number (2), Qnil, Qnil); |
1097
d9efc1c88574
(command_loop_1): Bind inhibit-quit to t when in Fsit_for.
Richard M. Stallman <rms@gnu.org>
parents:
1083
diff
changeset
|
824 unbind_to (count); |
d9efc1c88574
(command_loop_1): Bind inhibit-quit to t when in Fsit_for.
Richard M. Stallman <rms@gnu.org>
parents:
1083
diff
changeset
|
825 |
518 | 826 echo_area_glyphs = 0; |
827 no_direct = 1; | |
828 if (!NILP (Vquit_flag)) | |
829 { | |
830 Vquit_flag = Qnil; | |
831 unread_command_char = make_number (quit_char); | |
832 } | |
833 } | |
834 | |
835 #ifdef C_ALLOCA | |
836 alloca (0); /* Cause a garbage collection now */ | |
837 /* Since we can free the most stuff here. */ | |
838 #endif /* C_ALLOCA */ | |
839 | |
840 /* Read next key sequence; i gets its length. */ | |
841 i = read_key_sequence (keybuf, (sizeof keybuf / sizeof (keybuf[0])), 0); | |
842 | |
843 ++num_input_keys; | |
844 | |
765 | 845 #ifdef MULTI_FRAME |
846 /* Select the frame that the key sequence came from. */ | |
847 if (XTYPE (Vlast_event_frame) == Lisp_Frame | |
848 && XFRAME (Vlast_event_frame) != selected_frame) | |
849 Fselect_frame (Vlast_event_frame, Qnil); | |
518 | 850 #endif |
851 | |
852 /* Now we have read a key sequence of length I, | |
853 or else I is 0 and we found end of file. */ | |
854 | |
855 if (i == 0) /* End of file -- happens only in */ | |
856 return Qnil; /* a kbd macro, at the end. */ | |
857 | |
858 last_command_char = keybuf[i - 1]; | |
859 | |
860 cmd = read_key_sequence_cmd; | |
861 if (!NILP (Vexecuting_macro)) | |
862 { | |
863 if (!NILP (Vquit_flag)) | |
864 { | |
865 Vexecuting_macro = Qt; | |
866 QUIT; /* Make some noise. */ | |
867 /* Will return since macro now empty. */ | |
868 } | |
869 } | |
870 | |
871 /* Do redisplay processing after this command except in special | |
872 cases identified below that set no_redisplay to 1. */ | |
873 no_redisplay = 0; | |
874 | |
875 /* Execute the command. */ | |
876 | |
877 if (NILP (cmd)) | |
878 { | |
879 /* nil means key is undefined. */ | |
880 bitch_at_user (); | |
881 defining_kbd_macro = 0; | |
882 update_mode_lines = 1; | |
883 Vprefix_arg = Qnil; | |
884 } | |
885 else | |
886 { | |
887 this_command = cmd; | |
888 if (NILP (Vprefix_arg) && ! no_direct) | |
889 { | |
890 /* Recognize some common commands in common situations and | |
891 do them directly. */ | |
892 if (EQ (cmd, Qforward_char) && point < ZV) | |
893 { | |
894 struct Lisp_Vector *dp | |
895 = window_display_table (XWINDOW (selected_window)); | |
896 lose = FETCH_CHAR (point); | |
897 SET_PT (point + 1); | |
898 if (((dp == 0 && lose >= 040 && lose < 0177) | |
899 || | |
900 (dp && (XTYPE (dp->contents[lose]) != Lisp_String | |
901 || XSTRING (dp->contents[lose])->size == sizeof (GLYPH)))) | |
902 && (XFASTINT (XWINDOW (selected_window)->last_modified) | |
903 >= MODIFF) | |
904 && (XFASTINT (XWINDOW (selected_window)->last_point) | |
905 == point - 1) | |
906 && !windows_or_buffers_changed | |
907 && EQ (current_buffer->selective_display, Qnil) | |
908 && !detect_input_pending () | |
909 && NILP (Vexecuting_macro)) | |
910 no_redisplay = direct_output_forward_char (1); | |
911 goto directly_done; | |
912 } | |
913 else if (EQ (cmd, Qbackward_char) && point > BEGV) | |
914 { | |
915 struct Lisp_Vector *dp | |
916 = window_display_table (XWINDOW (selected_window)); | |
917 SET_PT (point - 1); | |
918 lose = FETCH_CHAR (point); | |
919 if (((dp == 0 && lose >= 040 && lose < 0177) | |
920 || | |
921 (dp && (XTYPE (dp->contents[lose]) != Lisp_String | |
922 || XSTRING (dp->contents[lose])->size == sizeof (GLYPH)))) | |
923 && (XFASTINT (XWINDOW (selected_window)->last_modified) | |
924 >= MODIFF) | |
925 && (XFASTINT (XWINDOW (selected_window)->last_point) | |
926 == point + 1) | |
927 && !windows_or_buffers_changed | |
928 && EQ (current_buffer->selective_display, Qnil) | |
929 && !detect_input_pending () | |
930 && NILP (Vexecuting_macro)) | |
931 no_redisplay = direct_output_forward_char (-1); | |
932 goto directly_done; | |
933 } | |
934 else if (EQ (cmd, Qself_insert_command) | |
935 /* Try this optimization only on ascii keystrokes. */ | |
936 && XTYPE (last_command_char) == Lisp_Int) | |
937 { | |
938 unsigned char c = XINT (last_command_char); | |
939 | |
940 if (NILP (Vexecuting_macro) && | |
941 !EQ (minibuf_window, selected_window)) | |
942 { | |
943 if (!nonundocount || nonundocount >= 20) | |
944 { | |
945 Fundo_boundary (); | |
946 nonundocount = 0; | |
947 } | |
948 nonundocount++; | |
949 } | |
950 lose = (XFASTINT (XWINDOW (selected_window)->last_modified) | |
951 < MODIFF) | |
952 || (XFASTINT (XWINDOW (selected_window)->last_point) | |
953 != point) | |
954 || MODIFF <= current_buffer->save_modified | |
955 || windows_or_buffers_changed | |
956 || !EQ (current_buffer->selective_display, Qnil) | |
957 || detect_input_pending () | |
958 || !NILP (Vexecuting_macro); | |
959 if (internal_self_insert (c, 0)) | |
960 { | |
961 lose = 1; | |
962 nonundocount = 0; | |
963 } | |
964 if (!lose && | |
965 (point == ZV || FETCH_CHAR (point) == '\n')) | |
966 { | |
967 struct Lisp_Vector *dp | |
968 = window_display_table (XWINDOW (selected_window)); | |
969 | |
970 if (dp == 0 || XTYPE (dp->contents[c]) != Lisp_String) | |
971 no_redisplay = direct_output_for_insert (c); | |
972 else if (XSTRING (dp->contents[c])->size | |
973 == sizeof (GLYPH)) | |
974 no_redisplay = | |
975 direct_output_for_insert (*(GLYPH *)XSTRING (dp->contents[c])->data); | |
976 } | |
977 goto directly_done; | |
978 } | |
979 } | |
980 | |
981 /* Here for a command that isn't executed directly */ | |
982 | |
983 nonundocount = 0; | |
984 if (NILP (Vprefix_arg)) | |
985 Fundo_boundary (); | |
986 Fcommand_execute (cmd, Qnil); | |
987 | |
988 } | |
547 | 989 directly_done: ; |
518 | 990 |
991 /* If there is a prefix argument, | |
992 1) We don't want last_command to be ``universal-argument'' | |
993 (that would be dumb), so don't set last_command, | |
994 2) we want to leave echoing on so that the prefix will be | |
995 echoed as part of this key sequence, so don't call | |
996 cancel_echoing, and | |
997 3) we want to leave this_command_key_count non-zero, so that | |
998 read_char will realize that it is re-reading a character, and | |
999 not echo it a second time. */ | |
1000 if (NILP (Vprefix_arg)) | |
1001 { | |
1002 last_command = this_command; | |
1003 cancel_echoing (); | |
1004 this_command_key_count = 0; | |
1005 } | |
1006 } | |
1007 } | |
1008 | |
1009 /* Number of seconds between polling for input. */ | |
1010 int polling_period; | |
1011 | |
1012 /* Nonzero means polling for input is temporarily suppresed. */ | |
1013 int poll_suppress_count; | |
1014 | |
1015 #ifdef POLL_FOR_INPUT | |
1016 int polling_for_input; | |
1017 | |
1018 /* Handle an alarm once each second and read pending input | |
1019 so as to handle a C-g if it comces in. */ | |
1020 | |
1021 SIGTYPE | |
1022 input_poll_signal () | |
1023 { | |
1024 #ifdef HAVE_X_WINDOWS | |
1025 extern int x_input_blocked; | |
1026 if (x_input_blocked == 0) | |
1027 #endif | |
1028 if (!waiting_for_input) | |
1029 read_avail_input (0); | |
1030 signal (SIGALRM, input_poll_signal); | |
1031 alarm (polling_period); | |
1032 } | |
1033 | |
1034 #endif | |
1035 | |
1036 /* Begin signals to poll for input, if they are appropriate. | |
1037 This function is called unconditionally from various places. */ | |
1038 | |
1039 start_polling () | |
1040 { | |
1041 #ifdef POLL_FOR_INPUT | |
1042 if (read_socket_hook) | |
1043 { | |
1044 poll_suppress_count--; | |
1045 if (poll_suppress_count == 0) | |
1046 { | |
1047 signal (SIGALRM, input_poll_signal); | |
1048 polling_for_input = 1; | |
1049 alarm (polling_period); | |
1050 } | |
1051 } | |
1052 #endif | |
1053 } | |
1054 | |
1055 /* Turn off polling. */ | |
1056 | |
1057 stop_polling () | |
1058 { | |
1059 #ifdef POLL_FOR_INPUT | |
1060 if (read_socket_hook) | |
1061 { | |
1062 if (poll_suppress_count == 0) | |
1063 { | |
1064 polling_for_input = 0; | |
1065 alarm (0); | |
1066 } | |
1067 poll_suppress_count++; | |
1068 } | |
1069 #endif | |
1070 } | |
1071 | |
1072 /* Input of single characters from keyboard */ | |
1073 | |
1074 Lisp_Object print_help (); | |
1075 static Lisp_Object kbd_buffer_get_event (); | |
1076 | |
1077 /* read a character from the keyboard; call the redisplay if needed */ | |
1078 /* commandflag 0 means do not do auto-saving, but do do redisplay. | |
1079 -1 means do not do redisplay, but do do autosaving. | |
1080 1 means do both. */ | |
1081 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1082 /* The arguments MAPS and NMAPS are for menu prompting. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1083 MAPS is an array of keymaps; NMAPS is the length of MAPS. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1084 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1085 PREV_EVENT is the previous input event, or nil if we are reading |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1086 the first event of a key sequence. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1087 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1088 If we use a mouse menu to read the input, we store 1 into *USED_MOUSE_MENU. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1089 Otherwise we store 0 there. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1090 |
518 | 1091 Lisp_Object |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1092 read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu) |
518 | 1093 int commandflag; |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1094 int nmaps; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1095 Lisp_Object *maps; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1096 Lisp_Object prev_event; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1097 int *used_mouse_menu; |
518 | 1098 { |
1099 register Lisp_Object c; | |
1100 int count; | |
1101 jmp_buf save_jump; | |
1102 | |
1103 if (!NILP (unread_command_char)) | |
1104 { | |
1105 c = unread_command_char; | |
1106 unread_command_char = Qnil; | |
1107 | |
1108 if (this_command_key_count == 0) | |
1109 goto reread_first; | |
1110 else | |
1111 goto reread; | |
1112 } | |
1113 | |
1114 if (!NILP (Vexecuting_macro)) | |
1115 { | |
1239
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1116 /* We set this to Qmacro; since that's not a frame, nobody will |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1117 try to switch frames on us, and the selected window will |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1118 remain unchanged. |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1119 |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1120 Since this event came from a macro, it would be misleading to |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1121 leave Vlast_event_frame set to whereever the last real event |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1122 came from. Normally, command_loop_1 selects |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1123 Vlast_event_frame after each command is read, but events read |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1124 from a macro should never cause a new frame to be selected. */ |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1125 Vlast_event_frame = Qmacro; |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
1126 |
518 | 1127 if (executing_macro_index >= Flength (Vexecuting_macro)) |
1128 { | |
1129 XSET (c, Lisp_Int, -1); | |
1130 return c; | |
1131 } | |
1132 | |
1133 c = Faref (Vexecuting_macro, make_number (executing_macro_index)); | |
1134 executing_macro_index++; | |
1135 | |
1136 goto from_macro; | |
1137 } | |
1138 | |
1139 /* Save outer setjmp data, in case called recursively. */ | |
650 | 1140 save_getcjmp (save_jump); |
518 | 1141 |
1142 stop_polling (); | |
1143 | |
1144 if (commandflag >= 0 && !input_pending && !detect_input_pending ()) | |
1145 redisplay (); | |
1146 | |
1147 if (_setjmp (getcjmp)) | |
1148 { | |
1149 XSET (c, Lisp_Int, quit_char); | |
765 | 1150 #ifdef MULTI_FRAME |
1151 XSET (Vlast_event_frame, Lisp_Frame, selected_frame); | |
586 | 1152 #endif |
518 | 1153 |
1154 goto non_reread; | |
1155 } | |
1156 | |
1157 /* Message turns off echoing unless more keystrokes turn it on again. */ | |
1158 if (echo_area_glyphs && *echo_area_glyphs && echo_area_glyphs != echobuf) | |
1159 cancel_echoing (); | |
1160 else | |
1161 /* If already echoing, continue. */ | |
1162 echo_dash (); | |
1163 | |
1164 /* If in middle of key sequence and minibuffer not active, | |
1165 start echoing if enough time elapses. */ | |
1166 if (minibuf_level == 0 && !immediate_echo && this_command_key_count > 0 | |
1167 && echo_keystrokes > 0 | |
1168 && (echo_area_glyphs == 0 || *echo_area_glyphs == 0)) | |
1169 { | |
1170 Lisp_Object tem0; | |
1171 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1172 /* After a mouse event, start echoing right away. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1173 This is because we are probably about to display a menu, |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1174 and we don't want to delay before doing so. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1175 if (XTYPE (prev_event) == Lisp_Cons) |
518 | 1176 echo (); |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1177 else |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1178 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1179 tem0 = sit_for (echo_keystrokes, 0, 1, 1); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1180 if (EQ (tem0, Qt)) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1181 echo (); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1182 } |
518 | 1183 } |
1184 | |
1185 /* Maybe auto save due to number of keystrokes or idle time. */ | |
1186 | |
1187 if (commandflag != 0 | |
1188 && auto_save_interval > 0 | |
1104
f3a7122a68e1
(num_nonmacro_input_chars): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1097
diff
changeset
|
1189 && num_nonmacro_input_chars - last_auto_save > max (auto_save_interval, 20) |
518 | 1190 && !detect_input_pending ()) |
1191 { | |
1192 jmp_buf temp; | |
1193 save_getcjmp (temp); | |
1194 Fdo_auto_save (Qnil, Qnil); | |
1195 restore_getcjmp (temp); | |
1196 } | |
1197 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1198 /* Try reading a character via menu prompting. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1199 Try this before the sit-for, because the sit-for |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1200 would do the wrong thing if we are supposed to do |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1201 menu prompting. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1202 c = Qnil; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1203 if (INTERACTIVE && !NILP (prev_event)) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1204 c = read_char_menu_prompt (nmaps, maps, prev_event, used_mouse_menu); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1205 |
518 | 1206 /* Slow down auto saves logarithmically in size of current buffer, |
1207 and garbage collect while we're at it. */ | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1208 if (NILP (c)) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1209 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1210 int delay_level, buffer_size; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1211 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1212 if (! MINI_WINDOW_P (XWINDOW (selected_window))) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1213 last_non_minibuf_size = Z - BEG; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1214 buffer_size = (last_non_minibuf_size >> 8) + 1; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1215 delay_level = 0; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1216 while (buffer_size > 64) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1217 delay_level++, buffer_size -= buffer_size >> 2; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1218 if (delay_level < 4) delay_level = 4; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1219 /* delay_level is 4 for files under around 50k, 7 at 100k, |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1220 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1221 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1222 /* Auto save if enough time goes by without input. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1223 if (commandflag != 0 |
1104
f3a7122a68e1
(num_nonmacro_input_chars): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1097
diff
changeset
|
1224 && num_nonmacro_input_chars > last_auto_save |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1225 && XTYPE (Vauto_save_timeout) == Lisp_Int |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1226 && XINT (Vauto_save_timeout) > 0) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1227 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1228 Lisp_Object tem0; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1229 int delay = delay_level * XFASTINT (Vauto_save_timeout) / 4; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1230 tem0 = sit_for (delay, 0, 1, 1); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1231 if (EQ (tem0, Qt)) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1232 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1233 jmp_buf temp; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1234 save_getcjmp (temp); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1235 Fdo_auto_save (Qnil, Qnil); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1236 restore_getcjmp (temp); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1237 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1238 /* If we have auto-saved and there is still no input |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1239 available, garbage collect if there has been enough |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1240 consing going on to make it worthwhile. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1241 if (!detect_input_pending () |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1242 && consing_since_gc > gc_cons_threshold / 2) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1243 Fgarbage_collect (); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1244 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1245 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1246 } |
518 | 1247 |
1248 /* Actually read a character, waiting if necessary. */ | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1249 if (NILP (c)) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1250 c = kbd_buffer_get_event (); |
518 | 1251 |
1252 if (NILP (c)) | |
1253 abort (); /* Don't think this can happen. */ | |
1254 | |
1255 /* Terminate Emacs in batch mode if at eof. */ | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1256 if (noninteractive && XTYPE (c) == Lisp_Int && XINT (c) < 0) |
518 | 1257 Fkill_emacs (make_number (1)); |
1258 | |
1259 non_reread: | |
1260 | |
650 | 1261 restore_getcjmp (save_jump); |
518 | 1262 |
1263 start_polling (); | |
1264 | |
1265 echo_area_glyphs = 0; | |
1266 | |
1267 /* Handle things that only apply to characters. */ | |
1268 if (XTYPE (c) == Lisp_Int) | |
1269 { | |
1270 /* If kbd_buffer_get_event gave us an EOF, return that. */ | |
1271 if (XINT (c) < 0) | |
1272 return c; | |
1273 | |
1274 /* Strip the high bits, and maybe the meta bit too. */ | |
1275 XSETINT (c, c & (meta_key ? 0377 : 0177)); | |
1276 | |
1277 if (XTYPE (Vkeyboard_translate_table) == Lisp_String | |
1278 && XSTRING (Vkeyboard_translate_table)->size > XINT (c)) | |
1279 XSETINT (c, XSTRING (Vkeyboard_translate_table)->data[c]); | |
1280 } | |
1281 | |
1282 total_keys++; | |
1261
60b30565326c
* keyboard.c (recent_keys): Turn this from an array, which is a
Jim Blandy <jimb@redhat.com>
parents:
1239
diff
changeset
|
1283 XVECTOR (recent_keys)->contents[recent_keys_index] = c; |
60b30565326c
* keyboard.c (recent_keys): Turn this from an array, which is a
Jim Blandy <jimb@redhat.com>
parents:
1239
diff
changeset
|
1284 if (++recent_keys_index >= NUM_RECENT_KEYS) |
518 | 1285 recent_keys_index = 0; |
1286 | |
1287 /* Write c to the dribble file. If c is a lispy event, write | |
1288 the event's symbol to the dribble file, in <brackets>. Bleaugh. | |
1289 If you, dear reader, have a better idea, you've got the source. :-) */ | |
1290 if (dribble) | |
1291 { | |
1292 if (XTYPE (c) == Lisp_Int) | |
1293 putc (c, dribble); | |
1294 else | |
1295 { | |
1296 Lisp_Object dribblee = c; | |
1297 | |
1298 /* If it's a structured event, take the event header. */ | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1299 dribblee = EVENT_HEAD (dribblee); |
518 | 1300 |
1301 if (XTYPE (c) == Lisp_Symbol) | |
1302 { | |
1303 putc ('<', dribble); | |
1304 fwrite (XSYMBOL (c)->name->data, sizeof (char), | |
1305 XSYMBOL (c)->name->size, | |
1306 dribble); | |
1307 putc ('>', dribble); | |
1308 } | |
1309 } | |
1310 | |
1311 fflush (dribble); | |
1312 } | |
1313 | |
1314 store_kbd_macro_char (c); | |
1315 | |
1104
f3a7122a68e1
(num_nonmacro_input_chars): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1097
diff
changeset
|
1316 num_nonmacro_input_chars++; |
f3a7122a68e1
(num_nonmacro_input_chars): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1097
diff
changeset
|
1317 |
518 | 1318 from_macro: |
1319 reread_first: | |
1320 echo_char (c); | |
1321 | |
1322 /* Record this character as part of the current key. */ | |
1323 add_command_key (c); | |
1324 | |
1325 /* Re-reading in the middle of a command */ | |
1326 reread: | |
1327 last_input_char = c; | |
1328 num_input_chars++; | |
1329 | |
1330 /* Process the help character specially if enabled */ | |
1331 if (EQ (c, help_char) && !NILP (Vhelp_form)) | |
1332 { | |
1333 Lisp_Object tem0; | |
1334 count = specpdl_ptr - specpdl; | |
1335 | |
1336 record_unwind_protect (Fset_window_configuration, | |
1337 Fcurrent_window_configuration (Qnil)); | |
1338 | |
1339 tem0 = Feval (Vhelp_form); | |
1340 if (XTYPE (tem0) == Lisp_String) | |
1341 internal_with_output_to_temp_buffer ("*Help*", print_help, tem0); | |
1342 | |
1343 cancel_echoing (); | |
1344 c = read_char (0); | |
765 | 1345 /* Remove the help from the frame */ |
518 | 1346 unbind_to (count, Qnil); |
1347 redisplay (); | |
1348 if (EQ (c, make_number (040))) | |
1349 { | |
1350 cancel_echoing (); | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1351 c = read_char (0, 0, 0, Qnil, 0); |
518 | 1352 } |
1353 } | |
1354 | |
1355 return c; | |
1356 } | |
1357 | |
1358 Lisp_Object | |
1359 print_help (object) | |
1360 Lisp_Object object; | |
1361 { | |
1362 Fprinc (object, Qnil); | |
1363 return Qnil; | |
1364 } | |
1365 | |
1366 /* Copy out or in the info on where C-g should throw to. | |
1367 This is used when running Lisp code from within get_char, | |
1368 in case get_char is called recursively. | |
1369 See read_process_output. */ | |
1370 | |
1371 save_getcjmp (temp) | |
1372 jmp_buf temp; | |
1373 { | |
1374 bcopy (getcjmp, temp, sizeof getcjmp); | |
1375 } | |
1376 | |
1377 restore_getcjmp (temp) | |
1378 jmp_buf temp; | |
1379 { | |
1380 bcopy (temp, getcjmp, sizeof getcjmp); | |
1381 } | |
1382 | |
1383 | |
1384 /* Low level keyboard/mouse input. | |
1385 kbd_buffer_store_event places events in kbd_buffer, and | |
1386 kbd_buffer_get_event retrieves them. | |
1387 mouse_moved indicates when the mouse has moved again, and | |
1388 *mouse_position_hook provides the mouse position. */ | |
1389 | |
1390 /* Set this for debugging, to have a way to get out */ | |
1391 int stop_character; | |
1392 | |
765 | 1393 extern int frame_garbaged; |
518 | 1394 |
1395 /* Return true iff there are any events in the queue that read-char | |
1396 would return. If this returns false, a read-char would block. */ | |
1397 static int | |
1398 readable_events () | |
1399 { | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1400 return ! EVENT_QUEUES_EMPTY; |
518 | 1401 } |
1402 | |
1403 | |
1404 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use | |
1405 of this function. */ | |
1406 static Lisp_Object | |
1407 tracking_off (old_value) | |
1408 Lisp_Object old_value; | |
1409 { | |
1410 if (! XFASTINT (old_value)) | |
1411 { | |
1412 do_mouse_tracking = 0; | |
1413 | |
1414 /* Redisplay may have been preempted because there was input | |
1415 available, and it assumes it will be called again after the | |
1416 input has been processed. If the only input available was | |
1417 the sort that we have just disabled, then we need to call | |
1418 redisplay. */ | |
1419 if (!readable_events ()) | |
1420 { | |
1421 redisplay_preserve_echo_area (); | |
1422 get_input_pending (&input_pending); | |
1423 } | |
1424 } | |
1425 } | |
1426 | |
1427 DEFUN ("track-mouse", Ftrack_mouse, Strack_mouse, 0, UNEVALLED, 0, | |
1428 "Evaluate BODY with mouse movement and button release events enabled.\n\ | |
682
71f59bd24996
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
650
diff
changeset
|
1429 Within a `track-mouse', mouse motion and button releases generate input\n\ |
71f59bd24996
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
650
diff
changeset
|
1430 events that you can read with `read-event'.\n\ |
71f59bd24996
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
650
diff
changeset
|
1431 Normally, these occurrences don't generate events.") |
518 | 1432 (args) |
1433 Lisp_Object args; | |
1434 { | |
1435 int count = specpdl_ptr - specpdl; | |
1436 Lisp_Object val; | |
1437 | |
1438 XSET (val, Lisp_Int, do_mouse_tracking); | |
1439 record_unwind_protect (tracking_off, val); | |
1440 | |
1441 do_mouse_tracking = 1; | |
1442 | |
1443 val = Fprogn (args); | |
1444 return unbind_to (count, val); | |
1445 } | |
1446 | |
1447 /* Store an event obtained at interrupt level into kbd_buffer, fifo */ | |
1448 | |
1449 void | |
1450 kbd_buffer_store_event (event) | |
1451 register struct input_event *event; | |
1452 { | |
1453 if (event->kind == no_event) | |
1454 abort (); | |
1455 | |
1456 if (event->kind == ascii_keystroke) | |
1457 { | |
1458 register int c = XFASTINT (event->code) & 0377; | |
1459 | |
1460 if (c == quit_char | |
1461 || ((c == (0200 | quit_char)) && !meta_key)) | |
1462 { | |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1463 extern SIGTYPE interrupt_signal (); |
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1464 |
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1465 #ifdef MULTI_FRAME |
518 | 1466 /* If this results in a quit_char being returned to Emacs as |
765 | 1467 input, set last-event-frame properly. If this doesn't |
518 | 1468 get returned to Emacs as an event, the next event read |
765 | 1469 will set Vlast_event_frame again, so this is safe to do. */ |
1470 Vlast_event_frame = FRAME_FOCUS_FRAME (event->frame); | |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1471 #endif |
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1472 |
648 | 1473 last_event_timestamp = event->timestamp; |
518 | 1474 interrupt_signal (); |
1475 return; | |
1476 } | |
1477 | |
1478 if (c && c == stop_character) | |
1479 { | |
1480 sys_suspend (); | |
1481 return; | |
1482 } | |
1483 | |
1484 XSET (event->code, Lisp_Int, c); | |
1485 } | |
1486 | |
1487 if (kbd_store_ptr - kbd_buffer == KBD_BUFFER_SIZE) | |
1488 kbd_store_ptr = kbd_buffer; | |
1489 | |
1490 /* Don't let the very last slot in the buffer become full, | |
1491 since that would make the two pointers equal, | |
1492 and that is indistinguishable from an empty buffer. | |
1493 Discard the event if it would fill the last slot. */ | |
1494 if (kbd_fetch_ptr - 1 != kbd_store_ptr) | |
1495 { | |
1496 kbd_store_ptr->kind = event->kind; | |
1497 kbd_store_ptr->code = event->code; | |
1498 kbd_store_ptr->part = event->part; | |
765 | 1499 kbd_store_ptr->frame = event->frame; |
518 | 1500 kbd_store_ptr->modifiers = event->modifiers; |
1501 kbd_store_ptr->x = event->x; | |
1502 kbd_store_ptr->y = event->y; | |
1503 kbd_store_ptr->timestamp = event->timestamp; | |
1504 | |
1505 kbd_store_ptr++; | |
1506 } | |
1507 } | |
1508 | |
1509 static Lisp_Object make_lispy_event (); | |
1510 static Lisp_Object make_lispy_movement (); | |
1511 static Lisp_Object modify_event_symbol (); | |
1512 | |
1513 static Lisp_Object | |
1514 kbd_buffer_get_event () | |
1515 { | |
1516 register int c; | |
1517 Lisp_Object obj; | |
1518 | |
1519 if (noninteractive) | |
1520 { | |
1521 c = getchar (); | |
1522 XSET (obj, Lisp_Int, c); | |
1523 return obj; | |
1524 } | |
1525 | |
1526 /* Wait until there is input available. */ | |
1527 for (;;) | |
1528 { | |
1529 if (!EVENT_QUEUES_EMPTY) | |
1530 break; | |
1531 | |
1532 /* If the quit flag is set, then read_char will return | |
1533 quit_char, so that counts as "available input." */ | |
1534 if (!NILP (Vquit_flag)) | |
1535 quit_throw_to_read_char (); | |
1536 | |
1537 /* One way or another, wait until input is available; then, if | |
1538 interrupt handlers have not read it, read it now. */ | |
1539 | |
1540 #ifdef OLDVMS | |
1541 wait_for_kbd_input (); | |
1542 #else | |
1543 /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
1544 #ifdef SIGIO | |
1545 gobble_input (0); | |
1546 #endif /* SIGIO */ | |
1547 if (EVENT_QUEUES_EMPTY) | |
1548 { | |
650 | 1549 Lisp_Object minus_one; |
1550 | |
1551 XSET (minus_one, Lisp_Int, -1); | |
1552 wait_reading_process_input (0, 0, minus_one, 1); | |
518 | 1553 |
1554 if (!interrupt_input && EVENT_QUEUES_EMPTY) | |
1555 { | |
1556 read_avail_input (0); | |
1557 } | |
1558 } | |
1559 #endif /* not VMS */ | |
1560 } | |
1561 | |
1562 /* At this point, we know that there is a readable event available | |
1563 somewhere. If the event queue is empty, then there must be a | |
1564 mouse movement enabled and available. */ | |
1565 if (kbd_fetch_ptr != kbd_store_ptr) | |
1566 { | |
1567 if (kbd_fetch_ptr == kbd_buffer + KBD_BUFFER_SIZE) | |
1568 kbd_fetch_ptr = kbd_buffer; | |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1569 |
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1570 #ifdef MULTI_FRAME |
1119
5d315d54b8b4
* keyboard.c (kbd_buffer_get_event): When performing the
Jim Blandy <jimb@redhat.com>
parents:
1104
diff
changeset
|
1571 XSET (Vlast_event_frame, Lisp_Frame, |
5d315d54b8b4
* keyboard.c (kbd_buffer_get_event): When performing the
Jim Blandy <jimb@redhat.com>
parents:
1104
diff
changeset
|
1572 XFRAME (FRAME_FOCUS_FRAME (kbd_fetch_ptr->frame))); |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1573 #endif |
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1574 |
708 | 1575 last_event_timestamp = kbd_fetch_ptr->timestamp; |
518 | 1576 obj = make_lispy_event (kbd_fetch_ptr); |
1577 kbd_fetch_ptr->kind = no_event; | |
1578 kbd_fetch_ptr++; | |
1579 if (XTYPE (obj) == Lisp_Int) | |
1580 XSET (obj, Lisp_Int, XINT (obj) & (meta_key ? 0377 : 0177)); | |
1581 } | |
1582 else if (do_mouse_tracking && mouse_moved) | |
1583 { | |
765 | 1584 FRAME_PTR frame; |
732 | 1585 Lisp_Object x, y; |
1586 unsigned long time; | |
518 | 1587 |
765 | 1588 (*mouse_position_hook) (&frame, &x, &y, &time); |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1589 #ifdef MULTI_FRAME |
765 | 1590 XSET (Vlast_event_frame, Lisp_Frame, frame); |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1591 #endif |
765 | 1592 |
1593 obj = make_lispy_movement (frame, x, y, time); | |
518 | 1594 } |
1595 else | |
1596 /* We were promised by the above while loop that there was | |
1597 something for us to read! */ | |
1598 abort (); | |
1599 | |
1600 input_pending = readable_events (); | |
1601 | |
1602 return (obj); | |
1603 } | |
1604 | |
1605 /* Caches for modify_event_symbol. */ | |
1606 static Lisp_Object func_key_syms; | |
1607 static Lisp_Object mouse_syms; | |
1608 | |
1609 /* You'll notice that this table is arranged to be conveniently | |
1610 indexed by X Windows keysym values. */ | |
1611 static char *lispy_function_keys[] = | |
1612 { | |
1613 /* X Keysym value */ | |
1614 | |
1615 "home", /* 0xff50 */ /* IsCursorKey */ | |
1616 "left", | |
1617 "up", | |
1618 "right", | |
1619 "down", | |
1620 "prior", | |
1621 "next", | |
1622 "end", | |
1623 "begin", | |
1624 0, /* 0xff59 */ | |
1625 0, 0, 0, 0, 0, 0, | |
1626 "select", /* 0xff60 */ /* IsMiscFunctionKey */ | |
1627 "print", | |
1628 "execute", | |
1629 "insert", | |
1630 0, /* 0xff64 */ | |
1631 "undo", | |
1632 "redo", | |
1633 "menu", | |
1634 "find", | |
1635 "cancel", | |
1636 "help", | |
1637 "break", /* 0xff6b */ | |
1638 | |
1639 /* Here are some keys found mostly on HP keyboards. The X event | |
1640 handling code will strip bit 29, which flags vendor-specific | |
1641 keysyms. */ | |
1642 "reset", /* 0x1000ff6c */ | |
1643 "system", | |
1644 "user", | |
1645 "clearline", | |
1646 "insertline", | |
1647 "deleteline", | |
1648 "insertchar", | |
1649 "deletechar", | |
1650 "backtab", | |
1651 "kp_backtab", /* 0x1000ff75 */ | |
1652 0, /* 0xff76 */ | |
1653 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff7f */ | |
1654 "kp-space", /* 0xff80 */ /* IsKeypadKey */ | |
1655 0, 0, 0, 0, 0, 0, 0, 0, | |
1656 "kp-tab", /* 0xff89 */ | |
1657 0, 0, 0, | |
1658 "kp-enter", /* 0xff8d */ | |
1659 0, 0, 0, | |
1660 "kp-f1", /* 0xff91 */ | |
1661 "kp-f2", | |
1662 "kp-f3", | |
1663 "kp-f4", | |
1664 0, /* 0xff95 */ | |
1665 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
1666 "kp-multiply", /* 0xffaa */ | |
1667 "kp-add", | |
1668 "kp-separator", | |
1669 "kp-subtract", | |
1670 "kp-decimal", | |
1671 "kp-divide", /* 0xffaf */ | |
1672 "kp-0", /* 0xffb0 */ | |
1673 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9", | |
1674 0, /* 0xffba */ | |
1675 0, 0, | |
1676 "kp-equal", /* 0xffbd */ | |
1677 "f1", /* 0xffbe */ /* IsFunctionKey */ | |
1678 "f2", "f3", "f4", | |
1679 "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12", | |
1680 "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", | |
1681 "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28", | |
1682 "f29", "f30", "f31", "f32", "f33", "f34", "f35" /* 0xffe0 */ | |
1683 }; | |
1684 | |
1685 static char *lispy_mouse_names[] = | |
1686 { | |
1687 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5" | |
1688 }; | |
1689 | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1690 /* make_lispy_event stores the down-going location of the currently |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1691 depressed buttons in button_down_locations. */ |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1692 struct mouse_position { |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1693 Lisp_Object window; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1694 Lisp_Object buffer_pos; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1695 Lisp_Object x, y; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1696 Lisp_Object timestamp; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1697 }; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1698 static struct mouse_position button_down_location[NUM_MOUSE_BUTTONS]; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1699 |
518 | 1700 /* Given a struct input_event, build the lisp event which represents |
1701 it. If EVENT is 0, build a mouse movement event from the mouse | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1702 movement buffer, which should have a movement event in it. |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1703 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1704 Note that events must be passed to this function in the order they |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1705 are received; this function stores the location of button presses |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1706 in order to build drag events when the button is released. */ |
518 | 1707 |
1708 static Lisp_Object | |
1709 make_lispy_event (event) | |
1710 struct input_event *event; | |
1711 { | |
1712 #ifdef SWITCH_ENUM_BUG | |
1713 switch ((int) event->kind) | |
1714 #else | |
1715 switch (event->kind) | |
1716 #endif | |
1717 { | |
1718 /* A simple keystroke. */ | |
1719 case ascii_keystroke: | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1720 return XFASTINT (event->code); |
518 | 1721 break; |
1722 | |
1723 /* A function key. The symbol may need to have modifier prefixes | |
1724 tacked onto it. */ | |
1725 case non_ascii_keystroke: | |
1726 return modify_event_symbol (XFASTINT (event->code), event->modifiers, | |
1727 Qfunction_key, | |
1728 lispy_function_keys, &func_key_syms, | |
1729 (sizeof (lispy_function_keys) | |
1730 / sizeof (lispy_function_keys[0]))); | |
1731 break; | |
1732 | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1733 /* A mouse click. Figure out where it is, decide whether it's |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1734 a press, click or drag, and build the appropriate structure. */ |
518 | 1735 case mouse_click: |
1736 { | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1737 int button = XFASTINT (event->code); |
518 | 1738 int part; |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1739 Lisp_Object window; |
518 | 1740 Lisp_Object posn; |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1741 struct mouse_position *loc; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1742 |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1743 if (button < 0 || button >= NUM_MOUSE_BUTTONS) |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1744 abort (); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1745 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1746 /* Where did this mouse click occur? */ |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1747 window = window_from_coordinates (event->frame, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1748 XINT (event->x), XINT (event->y), |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1749 &part); |
518 | 1750 if (XTYPE (window) != Lisp_Window) |
1751 posn = Qnil; | |
1752 else | |
1753 { | |
1754 XSETINT (event->x, (XINT (event->x) | |
1755 - XINT (XWINDOW (window)->left))); | |
1756 XSETINT (event->y, (XINT (event->y) | |
1757 - XINT (XWINDOW (window)->top))); | |
1758 if (part == 1) | |
1759 posn = Qmode_line; | |
1760 else if (part == 2) | |
732 | 1761 posn = Qvertical_line; |
518 | 1762 else |
1763 XSET (posn, Lisp_Int, | |
1764 buffer_posn_from_coords (XWINDOW (window), | |
1765 XINT (event->x), | |
1766 XINT (event->y))); | |
1767 } | |
1768 | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1769 /* If this is a button press, squirrel away the location, so we |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1770 can decide later whether it was a click or a drag. */ |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1771 loc = button_down_location + button; |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1772 if (event->modifiers & down_modifier) |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1773 { |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1774 loc->window = window; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1775 loc->buffer_pos = posn; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1776 loc->x = event->x; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1777 loc->y = event->y; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1778 loc->timestamp = event->timestamp; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1779 } |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1780 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1781 /* Now we're releasing a button - check the co-ordinates to |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1782 see if this was a click or a drag. */ |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1783 else if (event->modifiers & up_modifier) |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1784 { |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1785 event->modifiers &= ~up_modifier; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1786 event->modifiers |= ((event->x == loc->x && event->y == loc->y) |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1787 ? click_modifier |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1788 : drag_modifier); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1789 } |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1790 else |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1791 /* Every mouse event should either have the down_modifier or |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1792 the up_modifier set. */ |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1793 abort (); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1794 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1795 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1796 /* Build the event. */ |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1797 { |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1798 Lisp_Object head, start, end; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1799 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1800 /* Build the components of the event. */ |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1801 head = modify_event_symbol (button - 1, |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1802 event->modifiers, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1803 Qmouse_click, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1804 lispy_mouse_names, &mouse_syms, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1805 (sizeof (lispy_mouse_names) |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1806 / sizeof (lispy_mouse_names[0]))); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1807 end = Fcons (window, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1808 Fcons (posn, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1809 Fcons (Fcons (event->x, event->y), |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1810 Fcons (make_number (event->timestamp), |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1811 Qnil)))); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1812 if (event->modifiers & drag_modifier) |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1813 start = Fcons (loc->window, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1814 Fcons (loc->buffer_pos, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1815 Fcons (Fcons (loc->x, loc->y), |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1816 Fcons (make_number (loc->timestamp), |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1817 Qnil)))); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1818 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1819 /* Assemble the pieces. */ |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1820 if (event->modifiers & drag_modifier) |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1821 return Fcons (head, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1822 Fcons (start, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1823 Fcons (end, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1824 Qnil))); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1825 else |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1826 return Fcons (head, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1827 Fcons (end, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1828 Qnil)); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1829 } |
518 | 1830 } |
1831 | |
1832 /* A scrollbar click. Build a list containing the relevant | |
1833 information. */ | |
1834 case scrollbar_click: | |
1835 { | |
1836 Lisp_Object button | |
1837 = modify_event_symbol (XFASTINT (event->code) - 1, | |
1838 event->modifiers, | |
1839 Qmouse_click, | |
1840 lispy_mouse_names, &mouse_syms, | |
1841 (sizeof (lispy_mouse_names) | |
1842 / sizeof (lispy_mouse_names[0]))); | |
1843 return Fcons (event->part, | |
765 | 1844 Fcons (FRAME_SELECTED_WINDOW (event->frame), |
518 | 1845 Fcons (button, |
1846 Fcons (Fcons (event->x, event->y), | |
708 | 1847 Fcons (make_number |
1848 (event->timestamp), | |
518 | 1849 Qnil))))); |
1850 } | |
1851 | |
1852 /* The 'kind' field of the event is something we don't recognize. */ | |
1853 default: | |
1854 abort(); | |
1855 } | |
1856 } | |
1857 | |
1858 static Lisp_Object | |
765 | 1859 make_lispy_movement (frame, x, y, time) |
1860 FRAME_PTR frame; | |
518 | 1861 Lisp_Object x, y; |
732 | 1862 unsigned long time; |
518 | 1863 { |
1864 Lisp_Object window; | |
1865 int ix, iy; | |
1866 Lisp_Object posn; | |
1867 int part; | |
1868 | |
1869 ix = XINT (x); | |
1870 iy = XINT (y); | |
765 | 1871 window = (frame |
1872 ? window_from_coordinates (frame, ix, iy, &part) | |
518 | 1873 : Qnil); |
1874 if (XTYPE (window) != Lisp_Window) | |
1875 posn = Qnil; | |
1876 else | |
1877 { | |
1878 ix -= XINT (XWINDOW (window)->left); | |
1879 iy -= XINT (XWINDOW (window)->top); | |
1880 if (part == 1) | |
1881 posn = Qmode_line; | |
1882 else if (part == 2) | |
732 | 1883 posn = Qvertical_line; |
518 | 1884 else |
1885 XSET (posn, Lisp_Int, buffer_posn_from_coords (XWINDOW (window), | |
1886 ix, iy)); | |
1887 } | |
1888 | |
1889 XSETINT (x, ix); | |
1890 XSETINT (y, iy); | |
1891 return Fcons (Qmouse_movement, | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1892 Fcons (Fcons (window, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1893 Fcons (posn, |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1894 Fcons (Fcons (x, y), |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1895 Fcons (make_number (time), |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1896 Qnil)))), |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
1897 Qnil)); |
518 | 1898 } |
1899 | |
1900 | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1901 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1902 /* Manipulating modifiers. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1903 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1904 /* Parse the name of SYMBOL, and return the set of modifiers it contains. |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1905 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1906 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1907 SYMBOL's name of the end of the modifiers; the string from this |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1908 position is the unmodified symbol name. |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1909 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1910 This doesn't use any caches. */ |
518 | 1911 static int |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1912 parse_modifiers_uncached (symbol, modifier_end) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1913 Lisp_Object symbol; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1914 int *modifier_end; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1915 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1916 struct Lisp_String *name; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1917 int i; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1918 int modifiers; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1919 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1920 CHECK_SYMBOL (symbol, 1); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1921 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1922 modifiers = 0; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1923 name = XSYMBOL (symbol)->name; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1924 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1925 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1926 for (i = 0; i+2 <= name->size; ) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1927 switch (name->data[i]) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1928 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1929 #define SINGLE_LETTER_MOD(bit) \ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1930 if (name->data[i+1] != '-') \ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1931 goto no_more_modifiers; \ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1932 modifiers |= bit; \ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1933 i += 2; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1934 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1935 case 'A': |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1936 SINGLE_LETTER_MOD (alt_modifier); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1937 break; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1938 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1939 case 'C': |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1940 SINGLE_LETTER_MOD (ctrl_modifier); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1941 break; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1942 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1943 case 'H': |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1944 SINGLE_LETTER_MOD (hyper_modifier); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1945 break; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1946 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1947 case 'M': |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1948 SINGLE_LETTER_MOD (meta_modifier); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1949 break; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1950 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1951 case 'S': |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1952 SINGLE_LETTER_MOD (shift_modifier); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1953 break; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1954 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1955 case 's': |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1956 if (i + 6 > name->size |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1957 || strncmp (name->data + i, "super-", 6)) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1958 goto no_more_modifiers; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1959 modifiers |= super_modifier; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1960 i += 6; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1961 break; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1962 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1963 case 'd': |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1964 if (i + 5 > name->size) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1965 goto no_more_modifiers; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1966 if (! strncmp (name->data + i, "drag-", 5)) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1967 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1968 modifiers |= drag_modifier; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1969 i += 5; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1970 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1971 else if (! strncmp (name->data + i, "down-", 5)) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1972 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1973 modifiers |= down_modifier; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1974 i += 5; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1975 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1976 else |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1977 goto no_more_modifiers; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1978 break; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1979 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1980 default: |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1981 goto no_more_modifiers; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1982 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1983 #undef SINGLE_LETTER_MOD |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1984 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1985 no_more_modifiers: |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1986 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1987 /* Should we include the `click' modifier? */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1988 if (! (modifiers & (down_modifier | drag_modifier)) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1989 && i + 7 == name->size |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1990 && strncmp (name->data + i, "mouse-", 6) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1991 && '0' <= name->data[i + 6] |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1992 && name->data[i + 6] <= '9') |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1993 modifiers |= click_modifier; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1994 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1995 if (modifier_end) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1996 *modifier_end = i; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1997 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1998 return modifiers; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
1999 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2000 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2001 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2002 /* Return a symbol whose name is the modifier prefixes for MODIFIERS |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2003 prepended to the string BASE[0..BASE_LEN-1]. |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2004 This doesn't use any caches. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2005 static Lisp_Object |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2006 apply_modifiers_uncached (modifiers, base, base_len) |
518 | 2007 int modifiers; |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2008 char *base; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2009 int base_len; |
518 | 2010 { |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2011 /* Since BASE could contain nulls, we can't use intern here; we have |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2012 to use Fintern, which expects a genuine Lisp_String, and keeps a |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2013 reference to it. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2014 char *new_mods = |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2015 (char *) alloca (sizeof ("A-C-H-M-S-super-down-drag-")); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2016 int mod_len; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2017 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2018 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2019 char *p = new_mods; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2020 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2021 /* Only the event queue may use the `up' modifier; it should always |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2022 be turned into a click or drag event before presented to lisp code. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2023 if (modifiers & up_modifier) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2024 abort (); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2025 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2026 if (modifiers & alt_modifier) { *p++ = 'A'; *p++ = '-'; } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2027 if (modifiers & ctrl_modifier) { *p++ = 'C'; *p++ = '-'; } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2028 if (modifiers & hyper_modifier) { *p++ = 'H'; *p++ = '-'; } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2029 if (modifiers & meta_modifier) { *p++ = 'M'; *p++ = '-'; } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2030 if (modifiers & shift_modifier) { *p++ = 'S'; *p++ = '-'; } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2031 if (modifiers & super_modifier) { strcpy (p, "super-"); p += 6; } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2032 if (modifiers & down_modifier) { strcpy (p, "down-"); p += 5; } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2033 if (modifiers & drag_modifier) { strcpy (p, "drag-"); p += 5; } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2034 /* The click modifier is denoted by the absence of other modifiers. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2035 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2036 *p = '\0'; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2037 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2038 mod_len = p - new_mods; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2039 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2040 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2041 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2042 Lisp_Object new_name = make_uninit_string (mod_len + base_len); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2043 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2044 bcopy (new_mods, XSTRING (new_name)->data, mod_len); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2045 bcopy (base, XSTRING (new_name)->data + mod_len, base_len); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2046 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2047 return Fintern (new_name, Qnil); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2048 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2049 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2050 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2051 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2052 static char *modifier_names[] = |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2053 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2054 "up", "alt", "control", "hyper", "meta", "shift", "super", "down", "drag", |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2055 "click" |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2056 }; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2057 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2058 static Lisp_Object modifier_symbols; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2059 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2060 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2061 static Lisp_Object |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2062 lispy_modifier_list (modifiers) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2063 int modifiers; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2064 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2065 Lisp_Object modifier_list; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2066 int i; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2067 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2068 modifier_list = Qnil; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2069 for (i = 0; (1<<i) <= modifiers; i++) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2070 if (modifiers & (1<<i)) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2071 modifier_list = Fcons (XVECTOR (modifier_symbols)->contents[i], |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2072 modifier_list); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2073 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2074 return modifier_list; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2075 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2076 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2077 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2078 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK), |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2079 where UNMODIFIED is the unmodified form of SYMBOL, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2080 MASK is the set of modifiers present in SYMBOL's name. |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2081 This is similar to parse_modifiers_uncached, but uses the cache in |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2082 SYMBOL's Qevent_symbol_element_mask property, and maintains the |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2083 Qevent_symbol_elements property. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2084 static Lisp_Object |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2085 parse_modifiers (symbol) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2086 Lisp_Object symbol; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2087 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2088 Lisp_Object elements = Fget (symbol, Qevent_symbol_element_mask); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2089 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2090 if (CONSP (elements)) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2091 return elements; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2092 else |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2093 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2094 int end; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2095 int modifiers = parse_modifiers_uncached (symbol, &end); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2096 Lisp_Object unmodified |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2097 = Fintern (make_string (XSYMBOL (symbol)->name->data + end, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2098 XSYMBOL (symbol)->name->size - end), |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2099 Qnil); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2100 Lisp_Object mask; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2101 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2102 XFASTINT (mask) = modifiers; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2103 elements = Fcons (unmodified, Fcons (mask, Qnil)); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2104 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2105 /* Cache the parsing results on SYMBOL. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2106 Fput (symbol, Qevent_symbol_element_mask, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2107 elements); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2108 Fput (symbol, Qevent_symbol_elements, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2109 Fcons (unmodified, lispy_modifier_list (modifiers))); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2110 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2111 /* Since we know that SYMBOL is modifiers applied to unmodified, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2112 it would be nice to put that in unmodified's cache. |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2113 But we can't, since we're not sure that parse_modifiers is |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2114 canonical. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2115 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2116 return elements; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2117 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2118 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2119 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2120 /* Apply the modifiers MODIFIERS to the symbol BASE. |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2121 BASE must be unmodified. |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2122 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2123 This is like apply_modifiers_uncached, but uses BASE's |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2124 Qmodifier_cache property, if present. It also builds |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2125 Qevent_symbol_elements properties, since it has that info anyway. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2126 static Lisp_Object |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2127 apply_modifiers (modifiers, base) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2128 int modifiers; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2129 Lisp_Object base; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2130 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2131 Lisp_Object cache, index, entry; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2132 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2133 /* The click modifier never figures into cache indices. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2134 XFASTINT (index) = (modifiers & ~click_modifier); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2135 cache = Fget (base, Qmodifier_cache); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2136 entry = Fassq (index, cache); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2137 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2138 if (CONSP (entry)) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2139 return XCONS (entry)->cdr; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2140 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2141 /* We have to create the symbol ourselves. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2142 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2143 Lisp_Object new_symbol |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2144 = apply_modifiers_uncached (modifiers, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2145 XSYMBOL (base)->name->data, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2146 XSYMBOL (base)->name->size); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2147 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2148 /* Add the new symbol to the base's cache. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2149 Fput (base, Qmodifier_cache, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2150 Fcons (Fcons (index, new_symbol), cache)); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2151 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2152 /* We have the parsing info now for free, so add it to the caches. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2153 XFASTINT (index) = modifiers; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2154 Fput (new_symbol, Qevent_symbol_element_mask, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2155 Fcons (base, Fcons (index, Qnil))); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2156 Fput (new_symbol, Qevent_symbol_elements, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2157 Fcons (base, lispy_modifier_list (modifiers))); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2158 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2159 return new_symbol; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2160 } |
518 | 2161 } |
2162 | |
2163 | |
2164 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc), | |
2165 return a symbol with the modifiers placed in the canonical order. | |
1239
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
2166 Canonical order is alphabetical, except for down and drag, which |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2167 always come last. The 'click' modifier is never written out. |
518 | 2168 |
2169 Fdefine_key calls this to make sure that (for example) C-M-foo | |
2170 and M-C-foo end up being equivalent in the keymap. */ | |
2171 | |
2172 Lisp_Object | |
2173 reorder_modifiers (symbol) | |
2174 Lisp_Object symbol; | |
2175 { | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2176 /* It's hopefully okay to write the code this way, since everything |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2177 will soon be in caches, and no consing will be done at all. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2178 Lisp_Object parsed = parse_modifiers (symbol); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2179 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2180 return apply_modifiers (XCONS (XCONS (parsed)->cdr)->car, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2181 XCONS (parsed)->car); |
518 | 2182 } |
2183 | |
2184 | |
2185 /* For handling events, we often want to produce a symbol whose name | |
2186 is a series of modifier key prefixes ("M-", "C-", etcetera) attached | |
2187 to some base, like the name of a function key or mouse button. | |
2188 modify_event_symbol produces symbols of this sort. | |
2189 | |
2190 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i] | |
2191 is the name of the i'th symbol. TABLE_SIZE is the number of elements | |
2192 in the table. | |
2193 | |
2194 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will | |
2195 persist between calls to modify_event_symbol that it can use to | |
2196 store a cache of the symbols it's generated for this NAME_TABLE | |
2197 before. | |
2198 | |
2199 SYMBOL_NUM is the number of the base name we want from NAME_TABLE. | |
2200 | |
2201 MODIFIERS is a set of modifier bits (as given in struct input_events) | |
2202 whose prefixes should be applied to the symbol name. | |
2203 | |
2204 SYMBOL_KIND is the value to be placed in the event_kind property of | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2205 the returned symbol. |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2206 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2207 The symbols we create are supposed to have an |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2208 `event-symbol-elements' propery, which lists the modifiers present |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2209 in the symbol's name. */ |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2210 |
518 | 2211 static Lisp_Object |
2212 modify_event_symbol (symbol_num, modifiers, symbol_kind, name_table, | |
2213 symbol_table, table_size) | |
2214 int symbol_num; | |
2215 unsigned modifiers; | |
2216 Lisp_Object symbol_kind; | |
2217 char **name_table; | |
2218 Lisp_Object *symbol_table; | |
2219 int table_size; | |
2220 { | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2221 Lisp_Object *slot; |
518 | 2222 |
2223 /* Is this a request for a valid symbol? */ | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2224 if (symbol_num < 0 || symbol_num >= table_size) |
518 | 2225 abort (); |
2226 | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2227 /* If *symbol_table doesn't seem to be initialized properly, fix that. |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2228 *symbol_table should be a lisp vector TABLE_SIZE elements long, |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2229 where the Nth element is the symbol for NAME_TABLE[N]. */ |
518 | 2230 if (XTYPE (*symbol_table) != Lisp_Vector |
2231 || XVECTOR (*symbol_table)->size != table_size) | |
2232 { | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2233 Lisp_Object size; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2234 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2235 XFASTINT (size) = table_size; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2236 *symbol_table = Fmake_vector (size, Qnil); |
518 | 2237 } |
2238 | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2239 slot = & XVECTOR (*symbol_table)->contents[symbol_num]; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2240 |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2241 /* Have we already used this symbol before? */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2242 if (NILP (*slot)) |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2243 { |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2244 /* No; let's create it. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2245 *slot = intern (name_table[symbol_num]); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2246 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2247 /* Fill in the cache entries for this symbol; this also |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2248 builds the Qevent_symbol_elements property, which the user |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2249 cares about. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2250 apply_modifiers (0, *slot); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2251 Fput (*slot, Qevent_kind, symbol_kind); |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2252 } |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2253 |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2254 /* Apply modifiers to that symbol. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2255 return apply_modifiers (modifiers, *slot); |
518 | 2256 } |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2257 |
518 | 2258 |
2259 DEFUN ("mouse-click-p", Fmouse_click_p, Smouse_click_p, 1, 1, 0, | |
2260 "Return non-nil iff OBJECT is a representation of a mouse event.\n\ | |
2261 A mouse event is a list of five elements whose car is a symbol of the\n\ | |
2262 form <MODIFIERS>mouse-<DIGIT>. I hope this is a temporary hack.") | |
2263 (object) | |
2264 Lisp_Object object; | |
2265 { | |
2266 if (EVENT_HAS_PARAMETERS (object) | |
2267 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (object)), | |
2268 Qmouse_click)) | |
2269 return Qt; | |
2270 else | |
2271 return Qnil; | |
2272 } | |
2273 | |
2274 /* Store into *addr a value nonzero if terminal input chars are available. | |
2275 Serves the purpose of ioctl (0, FIONREAD, addr) | |
2276 but works even if FIONREAD does not exist. | |
2277 (In fact, this may actually read some input.) */ | |
2278 | |
2279 static void | |
2280 get_input_pending (addr) | |
2281 int *addr; | |
2282 { | |
2283 /* First of all, have we already counted some input? */ | |
2284 *addr = !NILP (Vquit_flag) || readable_events (); | |
2285 | |
2286 /* If input is being read as it arrives, and we have none, there is none. */ | |
2287 if (*addr > 0 || (interrupt_input && ! interrupts_deferred)) | |
2288 return; | |
2289 | |
2290 /* Try to read some input and see how much we get. */ | |
2291 gobble_input (0); | |
2292 *addr = !NILP (Vquit_flag) || readable_events (); | |
2293 } | |
2294 | |
2295 /* Interface to read_avail_input, blocking SIGIO if necessary. */ | |
2296 | |
2297 int | |
2298 gobble_input (expected) | |
2299 int expected; | |
2300 { | |
2301 #ifndef VMS | |
2302 #ifdef SIGIO | |
2303 if (interrupt_input) | |
2304 { | |
624 | 2305 SIGMASKTYPE mask; |
638 | 2306 mask = sigblockx (SIGIO); |
518 | 2307 read_avail_input (expected); |
638 | 2308 sigsetmask (mask); |
518 | 2309 } |
2310 else | |
2311 #endif | |
2312 read_avail_input (expected); | |
2313 #endif | |
2314 } | |
2315 | |
2316 #ifndef VMS | |
2317 | |
2318 /* Read any terminal input already buffered up by the system | |
2319 into the kbd_buffer, but do not wait. | |
2320 | |
2321 EXPECTED should be nonzero if the caller knows there is some input. | |
2322 | |
2323 Except on VMS, all input is read by this function. | |
2324 If interrupt_input is nonzero, this function MUST be called | |
2325 only when SIGIO is blocked. | |
2326 | |
2327 Returns the number of keyboard chars read, or -1 meaning | |
2328 this is a bad time to try to read input. */ | |
2329 | |
2330 static int | |
2331 read_avail_input (expected) | |
2332 int expected; | |
2333 { | |
2334 struct input_event buf[KBD_BUFFER_SIZE]; | |
2335 register int i; | |
2336 int nread; | |
2337 | |
2338 if (read_socket_hook) | |
2339 /* No need for FIONREAD or fcntl; just say don't wait. */ | |
2340 nread = (*read_socket_hook) (0, buf, KBD_BUFFER_SIZE, expected, expected); | |
2341 else | |
2342 { | |
2343 unsigned char cbuf[KBD_BUFFER_SIZE]; | |
2344 | |
2345 #ifdef FIONREAD | |
2346 /* Find out how much input is available. */ | |
2347 if (ioctl (0, FIONREAD, &nread) < 0) | |
2348 /* Formerly simply reported no input, but that sometimes led to | |
2349 a failure of Emacs to terminate. | |
2350 SIGHUP seems appropriate if we can't reach the terminal. */ | |
2351 kill (getpid (), SIGHUP); | |
2352 if (nread == 0) | |
2353 return 0; | |
2354 if (nread > sizeof cbuf) | |
2355 nread = sizeof cbuf; | |
2356 #else /* no FIONREAD */ | |
2357 #ifdef USG | |
2358 /* Read some input if available, but don't wait. */ | |
2359 nread = sizeof cbuf; | |
2360 fcntl (fileno (stdin), F_SETFL, O_NDELAY); | |
2361 #else | |
2362 you lose; | |
2363 #endif | |
2364 #endif | |
2365 | |
2366 /* Now read; for one reason or another, this will not block. */ | |
2367 while (1) | |
2368 { | |
2369 nread = read (fileno (stdin), cbuf, nread); | |
2370 #ifdef AIX | |
2371 /* The kernel sometimes fails to deliver SIGHUP for ptys. | |
2372 This looks incorrect, but it isn't, because _BSD causes | |
2373 O_NDELAY to be defined in fcntl.h as O_NONBLOCK, | |
2374 and that causes a value other than 0 when there is no input. */ | |
2375 if (nread == 0) | |
2376 kill (SIGHUP, 0); | |
2377 #endif | |
2378 /* Retry the read if it is interrupted. */ | |
2379 if (nread >= 0 | |
2380 || ! (errno == EAGAIN || errno == EFAULT | |
2381 #ifdef EBADSLT | |
2382 || errno == EBADSLT | |
2383 #endif | |
2384 )) | |
2385 break; | |
2386 } | |
2387 | |
2388 #ifndef FIONREAD | |
2389 #ifdef USG | |
2390 fcntl (fileno (stdin), F_SETFL, 0); | |
2391 #endif /* USG */ | |
2392 #endif /* no FIONREAD */ | |
2393 for (i = 0; i < nread; i++) | |
2394 { | |
2395 buf[i].kind = ascii_keystroke; | |
2396 XSET (buf[i].code, Lisp_Int, cbuf[i]); | |
765 | 2397 buf[i].frame = selected_frame; |
518 | 2398 } |
2399 } | |
2400 | |
2401 /* Scan the chars for C-g and store them in kbd_buffer. */ | |
2402 for (i = 0; i < nread; i++) | |
2403 { | |
2404 kbd_buffer_store_event (&buf[i]); | |
2405 /* Don't look at input that follows a C-g too closely. | |
2406 This reduces lossage due to autorepeat on C-g. */ | |
2407 if (buf[i].kind == ascii_keystroke | |
2408 && XINT(buf[i].code) == quit_char) | |
2409 break; | |
2410 } | |
2411 | |
2412 return nread; | |
2413 } | |
2414 #endif /* not VMS */ | |
2415 | |
2416 #ifdef SIGIO /* for entire page */ | |
2417 /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
2418 | |
1119
5d315d54b8b4
* keyboard.c (kbd_buffer_get_event): When performing the
Jim Blandy <jimb@redhat.com>
parents:
1104
diff
changeset
|
2419 SIGTYPE |
518 | 2420 input_available_signal (signo) |
2421 int signo; | |
2422 { | |
2423 /* Must preserve main program's value of errno. */ | |
2424 int old_errno = errno; | |
2425 #ifdef BSD4_1 | |
2426 extern int select_alarmed; | |
2427 #endif | |
2428 | |
2429 #ifdef USG | |
2430 /* USG systems forget handlers when they are used; | |
2431 must reestablish each time */ | |
2432 signal (signo, input_available_signal); | |
2433 #endif /* USG */ | |
2434 | |
2435 #ifdef BSD4_1 | |
2436 sigisheld (SIGIO); | |
2437 #endif | |
2438 | |
648 | 2439 if (input_available_clear_time) |
2440 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); | |
518 | 2441 |
2442 while (1) | |
2443 { | |
2444 int nread; | |
2445 nread = read_avail_input (1); | |
2446 /* -1 means it's not ok to read the input now. | |
2447 UNBLOCK_INPUT will read it later; now, avoid infinite loop. | |
2448 0 means there was no keyboard input available. */ | |
2449 if (nread <= 0) | |
2450 break; | |
2451 | |
2452 #ifdef BSD4_1 | |
2453 select_alarmed = 1; /* Force the select emulator back to life */ | |
2454 #endif | |
2455 } | |
2456 | |
2457 #ifdef BSD4_1 | |
2458 sigfree (); | |
2459 #endif | |
2460 errno = old_errno; | |
2461 } | |
2462 #endif /* SIGIO */ | |
2463 | |
2464 /* Return the prompt-string of a sparse keymap. | |
2465 This is the first element which is a string. | |
2466 Return nil if there is none. */ | |
2467 | |
2468 Lisp_Object | |
2469 map_prompt (map) | |
2470 Lisp_Object map; | |
2471 { | |
2472 while (CONSP (map)) | |
2473 { | |
2474 register Lisp_Object tem; | |
2475 tem = Fcar (map); | |
2476 if (XTYPE (tem) == Lisp_String) | |
2477 return tem; | |
2478 map = Fcdr (map); | |
2479 } | |
2480 return Qnil; | |
2481 } | |
2482 | |
2483 static int echo_flag; | |
2484 static int echo_now; | |
2485 | |
2486 /* Read a character like read_char but optionally prompt based on maps | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2487 in the array MAPS. NMAPS is the length of MAPS. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2488 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2489 PREV_EVENT is the previous input event, or nil if we are reading |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2490 the first event of a key sequence. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2491 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2492 If we use a mouse menu to read the input, we store 1 into *USED_MOUSE_MENU. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2493 Otherwise we store 0 there. |
518 | 2494 |
2495 The prompting is done based on the prompt-string of the map | |
2496 and the strings associated with various map elements. */ | |
2497 | |
2498 Lisp_Object | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2499 read_char_menu_prompt (nmaps, maps, prev_event, used_mouse_menu) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2500 int nmaps; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2501 Lisp_Object *maps; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2502 Lisp_Object prev_event; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2503 int *used_mouse_menu; |
518 | 2504 { |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2505 int mapno; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2506 register Lisp_Object name; |
518 | 2507 int nlength; |
765 | 2508 int width = FRAME_WIDTH (selected_frame) - 4; |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2509 char *menu = (char *) alloca (width + 4); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2510 int idx = -1; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2511 Lisp_Object rest, vector; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2512 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2513 *used_mouse_menu = 0; |
518 | 2514 |
2515 /* Use local over global Menu maps */ | |
2516 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2517 if (! menu_prompting) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2518 return Qnil; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2519 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2520 /* Get the menu name from the first map that has one (a prompt string). */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2521 for (mapno = 0; mapno < nmaps; mapno++) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2522 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2523 name = map_prompt (maps[mapno]); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2524 if (!NILP (name)) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2525 break; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2526 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2527 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2528 /* If we don't have any menus, just read a character normally. */ |
518 | 2529 if (NILP (name)) |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2530 return Qnil; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2531 |
1140
5c36807e445c
(read_char_menu_prompt): Use X menu code if HAVE_X_WINDOWS and not NO_X_MENU.
Richard M. Stallman <rms@gnu.org>
parents:
1119
diff
changeset
|
2532 #ifdef HAVE_X_WINDOW |
5c36807e445c
(read_char_menu_prompt): Use X menu code if HAVE_X_WINDOWS and not NO_X_MENU.
Richard M. Stallman <rms@gnu.org>
parents:
1119
diff
changeset
|
2533 #ifndef NO_X_MENU |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2534 /* If we got to this point via a mouse click, |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2535 use a real menu for mouse selection. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2536 if (XTYPE (prev_event) == Lisp_Cons) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2537 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2538 /* Display the menu and get the selection. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2539 Lisp_Object *realmaps |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2540 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2541 Lisp_Object value; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2542 int nmaps1 = 0; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2543 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2544 /* Use the maps that are not nil. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2545 for (mapno = 0; mapno < nmaps; mapno++) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2546 if (!NILP (maps[mapno])) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2547 realmaps[nmaps1++] = maps[mapno]; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2548 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2549 value = Fx_popup_menu (prev_event, Flist (nmaps1, realmaps)); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2550 if (NILP (value)) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2551 XSET (value, Lisp_Int, quit_char); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2552 *used_mouse_menu = 1; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2553 return value; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2554 } |
1140
5c36807e445c
(read_char_menu_prompt): Use X menu code if HAVE_X_WINDOWS and not NO_X_MENU.
Richard M. Stallman <rms@gnu.org>
parents:
1119
diff
changeset
|
2555 #endif /* not NO_X_MENU */ |
5c36807e445c
(read_char_menu_prompt): Use X menu code if HAVE_X_WINDOWS and not NO_X_MENU.
Richard M. Stallman <rms@gnu.org>
parents:
1119
diff
changeset
|
2556 #endif /* HAVE_X_WINDOW */ |
518 | 2557 |
2558 /* Prompt string always starts with map's prompt, and a space. */ | |
2559 strcpy (menu, XSTRING (name)->data); | |
2560 nlength = XSTRING (name)->size; | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2561 menu[nlength++] = ':'; |
518 | 2562 menu[nlength++] = ' '; |
2563 menu[nlength] = 0; | |
2564 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2565 /* Start prompting at start of first map. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2566 mapno = 0; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2567 rest = maps[mapno]; |
518 | 2568 |
2569 /* Present the documented bindings, a line at a time. */ | |
2570 while (1) | |
2571 { | |
2572 int notfirst = 0; | |
2573 int i = nlength; | |
2574 Lisp_Object obj; | |
2575 int ch; | |
2576 | |
2577 /* Loop over elements of map. */ | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2578 while (i < width) |
518 | 2579 { |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2580 Lisp_Object s, elt; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2581 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2582 /* If reached end of map, start at beginning of next map. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2583 if (NILP (rest)) |
518 | 2584 { |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2585 mapno++; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2586 /* At end of last map, wrap around to first map if just starting, |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2587 or end this line if already have something on it. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2588 if (mapno == nmaps) |
518 | 2589 { |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2590 if (notfirst) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2591 break; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2592 else |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2593 mapno = 0; |
518 | 2594 } |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2595 rest = maps[mapno]; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2596 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2597 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2598 /* Look at the next element of the map. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2599 if (idx >= 0) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2600 elt = XVECTOR (vector)->contents[idx]; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2601 else |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2602 elt = Fcar_safe (rest); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2603 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2604 if (idx < 0 && XTYPE (elt) == Lisp_Vector) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2605 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2606 /* If we found a dense table in the keymap, |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2607 advanced past it, but start scanning its contents. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2608 rest = Fcdr_safe (rest); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2609 vector = elt; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2610 idx = 0; |
518 | 2611 } |
2612 else | |
2613 { | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2614 /* An ordinary element. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2615 s = Fcar_safe (Fcdr_safe (elt)); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2616 if (XTYPE (s) != Lisp_String) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2617 /* Ignore the element if it has no prompt string. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2618 ; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2619 /* If we have room for the prompt string, add it to this line. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2620 If this is the first on the line, always add it. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2621 else if (XSTRING (s)->size + i < width |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2622 || !notfirst) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2623 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2624 int thiswidth; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2625 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2626 /* Punctuate between strings. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2627 if (notfirst) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2628 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2629 strcpy (menu + i, ", "); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2630 i += 2; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2631 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2632 notfirst = 1; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2633 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2634 /* Add as much of string as fits. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2635 thiswidth = XSTRING (s)->size; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2636 if (thiswidth + i > width) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2637 thiswidth = width - i; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2638 bcopy (XSTRING (s)->data, menu + i, thiswidth); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2639 i += thiswidth; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2640 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2641 else |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2642 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2643 /* If this element does not fit, end the line now, |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2644 and save the element for the next line. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2645 strcpy (menu + i, "..."); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2646 break; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2647 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2648 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2649 /* Move past this element. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2650 if (idx >= 0 && idx + 1 >= XVECTOR (rest)->size) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2651 /* Handle reaching end of dense table. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2652 idx = -1; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2653 if (idx >= 0) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2654 idx++; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2655 else |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2656 rest = Fcdr_safe (rest); |
518 | 2657 } |
2658 } | |
2659 | |
2660 /* Prompt with that and read response. */ | |
2661 message1 (menu); | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2662 obj = read_char (1, 0, 0, Qnil, 0); |
518 | 2663 |
2664 if (XTYPE (obj) != Lisp_Int) | |
2665 return obj; | |
2666 else | |
2667 ch = XINT (obj); | |
2668 | |
2669 if (obj != menu_prompt_more_char | |
2670 && (XTYPE (menu_prompt_more_char) != Lisp_Int | |
2671 || obj != make_number (Ctl (XINT (menu_prompt_more_char))))) | |
2672 return obj; | |
2673 } | |
2674 } | |
2675 | |
2676 /* Reading key sequences. */ | |
2677 | |
2678 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings | |
2679 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a | |
2680 keymap, or nil otherwise. Return the index of the first keymap in | |
2681 which KEY has any binding, or NMAPS if no map has a binding. | |
2682 | |
2683 If KEY is a meta ASCII character, treat it like meta-prefix-char | |
2684 followed by the corresponding non-meta character. Keymaps in | |
2685 CURRENT with non-prefix bindings for meta-prefix-char become nil in | |
2686 NEXT. | |
2687 | |
2688 When KEY is not defined in any of the keymaps, if it is an upper | |
2689 case letter and there are bindings for the corresponding lower-case | |
2690 letter, return the bindings for the lower-case letter. | |
2691 | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2692 If KEY has no bindings in any of the CURRENT maps, NEXT is left |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2693 unmodified. |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2694 |
518 | 2695 NEXT may == CURRENT. */ |
2696 | |
2697 static int | |
2698 follow_key (key, nmaps, current, defs, next) | |
2699 Lisp_Object key; | |
2700 Lisp_Object *current, *defs, *next; | |
2701 int nmaps; | |
2702 { | |
2703 int i, first_binding; | |
2704 | |
2705 /* If KEY is a meta ASCII character, treat it like meta-prefix-char | |
2706 followed by the corresponding non-meta character. */ | |
2707 if (XTYPE (key) == Lisp_Int | |
2708 && XINT (key) >= 0200) | |
2709 { | |
2710 for (i = 0; i < nmaps; i++) | |
2711 if (! NILP (current[i])) | |
2712 { | |
2713 next[i] = get_keyelt (access_keymap (current[i], | |
2714 meta_prefix_char)); | |
2715 | |
2716 /* Note that since we pass the resulting bindings through | |
2717 get_keymap_1, non-prefix bindings for meta-prefix-char | |
2718 disappear. */ | |
2719 next[i] = get_keymap_1 (next[i], 0); | |
2720 } | |
2721 else | |
2722 next[i] = Qnil; | |
2723 | |
2724 current = next; | |
2725 XSET (key, Lisp_Int, XFASTINT (key) & 0177); | |
2726 } | |
2727 | |
2728 first_binding = nmaps; | |
2729 for (i = nmaps - 1; i >= 0; i--) | |
2730 { | |
2731 if (! NILP (current[i])) | |
2732 { | |
2733 defs[i] = get_keyelt (access_keymap (current[i], key)); | |
2734 if (! NILP (defs[i])) | |
2735 first_binding = i; | |
2736 } | |
2737 else | |
2738 defs[i] = Qnil; | |
2739 } | |
2740 | |
2741 /* When KEY is not defined in any of the keymaps, if it is an upper | |
2742 case letter and there are bindings for the corresponding | |
2743 lower-case letter, return the bindings for the lower-case letter. */ | |
2744 if (first_binding == nmaps | |
2745 && XTYPE (key) == Lisp_Int | |
2746 && UPPERCASEP (XINT (key))) | |
2747 { | |
2748 XSETINT (key, DOWNCASE (XINT (key))); | |
2749 | |
2750 first_binding = nmaps; | |
2751 for (i = nmaps - 1; i >= 0; i--) | |
2752 { | |
2753 if (! NILP (current[i])) | |
2754 { | |
2755 defs[i] = get_keyelt (access_keymap (current[i], key)); | |
2756 if (! NILP (defs[i])) | |
2757 first_binding = i; | |
2758 } | |
2759 else | |
2760 defs[i] = Qnil; | |
2761 } | |
2762 } | |
2763 | |
2764 /* Given the set of bindings we've found, produce the next set of maps. */ | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2765 if (first_binding < nmaps) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2766 for (i = 0; i < nmaps; i++) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2767 next[i] = NILP (defs[i]) ? Qnil : get_keymap_1 (defs[i], 0); |
518 | 2768 |
2769 return first_binding; | |
2770 } | |
2771 | |
2772 /* Read a sequence of keys that ends with a non prefix character | |
2773 according to the keymaps in KEYMAPS[0..nmaps-1]. Keymaps appearing | |
2774 earlier in KEYMAPS take precidence over those appearing later. | |
2775 | |
2776 Store the sequence in KEYBUF, a buffer of size BUFSIZE. Prompt | |
2777 with PROMPT. Echo starting immediately unless `prompt' is 0. | |
2778 Return the length of the key sequence stored. | |
2779 | |
765 | 2780 If the user switches frames in the midst of a key sequence, we |
518 | 2781 throw away any prefix we have read so far, and start afresh. For |
2782 mouse clicks, we look up the click in the keymap of the buffer | |
2783 clicked on, throwing away any prefix if it is not the same buffer | |
2784 we used to be reading from. */ | |
2785 | |
2786 static int | |
2787 read_key_sequence (keybuf, bufsize, prompt) | |
2788 Lisp_Object *keybuf; | |
2789 int bufsize; | |
2790 Lisp_Object prompt; | |
2791 { | |
2792 /* How many keys there are in the current key sequence. */ | |
2793 int t; | |
2794 | |
2795 /* The buffer that the most recently read event was typed at. This | |
2796 helps us read mouse clicks according to the buffer clicked in, | |
765 | 2797 and notice when the mouse has moved from one frame to another. */ |
518 | 2798 struct buffer *last_event_buffer = current_buffer; |
2799 | |
2800 /* The length of the echo buffer when we started reading, and | |
2801 the length of this_command_keys when we started reading. */ | |
2802 int echo_start; | |
2803 int keys_start = this_command_key_count; | |
2804 | |
2805 /* The number of keymaps we're scanning right now, and the number of | |
2806 keymaps we have allocated space for. */ | |
2807 int nmaps; | |
2808 int nmaps_allocated = 0; | |
2809 | |
899 | 2810 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] |
518 | 2811 in the current keymaps, or nil where it is not a prefix. */ |
899 | 2812 Lisp_Object *submaps; |
518 | 2813 |
2814 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in | |
2815 the current keymaps. */ | |
2816 Lisp_Object *defs; | |
2817 | |
899 | 2818 /* The index of the first keymap that has a binding for this key |
2819 sequence. In other words, the lowest i such that defs[i] is | |
2820 non-nil.*/ | |
518 | 2821 int first_binding; |
2822 | |
2823 /* If mock_input > t, then KEYBUF[t] should be read as the next | |
899 | 2824 input key. |
2825 | |
2826 We use this to recover after recognizing a function key. Once we | |
2827 realize that a suffix of the current key sequence is actually a | |
2828 function key's escape sequence, we replace the suffix with the | |
2829 function key's binding from Vfunction_key_map. Now keybuf | |
2830 contains a new and different key sequence, so the echo area and | |
2831 the submaps and defs arrays are wrong. In this situation, we set | |
2832 mock_input to t, set t to 0, and jump to restart; the loop will | |
2833 read keys from keybuf up until mock_input, which rebuilds the | |
2834 state, and then it will resume reading characters from the keyboard. */ | |
518 | 2835 int mock_input = 0; |
2836 | |
899 | 2837 /* If the sequence is unbound in submaps[], then |
2838 keymap[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map, | |
2839 and fkey_map is its binding. If mock_input is in use, these | |
2840 might be > t, indicating that all function key scanning should | |
518 | 2841 hold off until t reaches them. */ |
899 | 2842 |
518 | 2843 int fkey_start = 0, fkey_end = 0; |
2844 Lisp_Object fkey_map = Vfunction_key_map; | |
2845 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2846 last_nonmenu_event = Qnil; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2847 |
518 | 2848 if (INTERACTIVE) |
2849 { | |
2850 if (prompt) | |
2851 echo_prompt (prompt); | |
2852 else if (cursor_in_echo_area) | |
2853 /* This doesn't put in a dash if the echo buffer is empty, so | |
2854 you don't always see a dash hanging out in the minibuffer. */ | |
2855 echo_dash (); | |
2856 echo_start = echo_length (); | |
2857 } | |
2858 | |
899 | 2859 /* If there is no function key map, turn off function key scanning. */ |
518 | 2860 if (NILP (Fkeymapp (Vfunction_key_map))) |
2861 fkey_start = fkey_end = bufsize + 1; | |
2862 | |
2863 restart: | |
2864 t = 0; | |
2865 this_command_key_count = keys_start; | |
2866 | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2867 /* This is a no-op the first time through, but if we restart, it |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2868 reverts the echo area to its original state. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2869 if (INTERACTIVE) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2870 echo_truncate (echo_start); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2871 |
518 | 2872 { |
2873 Lisp_Object *maps; | |
2874 | |
2875 nmaps = current_minor_maps (0, &maps) + 2; | |
2876 if (nmaps > nmaps_allocated) | |
2877 { | |
899 | 2878 submaps = (Lisp_Object *) alloca (nmaps * sizeof (submaps[0])); |
518 | 2879 defs = (Lisp_Object *) alloca (nmaps * sizeof (defs[0])); |
2880 nmaps_allocated = nmaps; | |
2881 } | |
899 | 2882 bcopy (maps, submaps, (nmaps - 2) * sizeof (submaps[0])); |
2883 submaps[nmaps-2] = last_event_buffer->keymap; | |
2884 submaps[nmaps-1] = global_map; | |
518 | 2885 } |
2886 | |
2887 /* Find an accurate initial value for first_binding. */ | |
2888 for (first_binding = 0; first_binding < nmaps; first_binding++) | |
899 | 2889 if (! NILP (submaps[first_binding])) |
518 | 2890 break; |
2891 | |
899 | 2892 while ((first_binding < nmaps && ! NILP (submaps[first_binding])) |
518 | 2893 || (first_binding >= nmaps && fkey_start < t)) |
2894 { | |
2895 Lisp_Object key; | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2896 int used_mouse_menu = 0; |
518 | 2897 |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2898 /* These variables are analogous to echo_start and keys_start; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2899 while those allow us to restart the entire key sequence, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2900 echo_local_start and keys_local_start allow us to throw away |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2901 just one key. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2902 int echo_local_start = echo_length (); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2903 int keys_local_start = this_command_key_count; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2904 int local_first_binding = first_binding; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2905 |
518 | 2906 if (t >= bufsize) |
2907 error ("key sequence too long"); | |
2908 | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2909 retry_key: |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2910 /* These are no-ops, unless we throw away a keystroke below and |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2911 jumped back up to retry_key; in that case, these restore these |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2912 variables to their original state, allowing us to restart the |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2913 loop. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2914 echo_truncate (echo_local_start); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2915 this_command_key_count = keys_local_start; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2916 first_binding = local_first_binding; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2917 |
899 | 2918 /* Are we re-reading a key sequence, as indicated by mock_input? */ |
518 | 2919 if (t < mock_input) |
2920 { | |
2921 key = keybuf[t]; | |
2922 add_command_key (key); | |
2923 echo_char (key); | |
2924 } | |
899 | 2925 |
2926 /* If not, we should actually read a character. */ | |
518 | 2927 else |
2928 { | |
2929 struct buffer *buf; | |
2930 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2931 key = read_char (!prompt, nmaps, submaps, last_nonmenu_event, |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2932 &used_mouse_menu); |
518 | 2933 |
2934 /* The above routines return -1 at the end of a macro. | |
2935 Emacs 18 handles this by returning immediately with a | |
2936 zero, so that's what we'll do. */ | |
2937 if (XTYPE (key) == Lisp_Int && XINT (key) < 0) | |
2938 return 0; | |
2939 | |
2940 Vquit_flag = Qnil; | |
2941 | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2942 /* Clicks in non-text areas get prefixed by the symbol |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2943 in their CHAR-ADDRESS field. For example, a click on |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2944 the mode line is prefixed by the symbol `mode-line'. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2945 if (EVENT_HAS_PARAMETERS (key) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2946 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key)), Qmouse_click)) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2947 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2948 Lisp_Object posn = POSN_BUFFER_POSN (EVENT_START (key)); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2949 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2950 if (XTYPE (posn) == Lisp_Symbol) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2951 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2952 if (t + 1 >= bufsize) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2953 error ("key sequence too long"); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2954 keybuf[t] = posn; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2955 keybuf[t+1] = key; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2956 mock_input = t + 2; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2957 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2958 goto retry_key; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2959 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2960 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
2961 |
765 | 2962 #ifdef MULTI_FRAME |
518 | 2963 /* What buffer was this event typed/moused at? */ |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2964 if (used_mouse_menu) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2965 /* Never change last_event_buffer for using a menu. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2966 buf = last_event_buffer; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2967 else if (XTYPE (key) == Lisp_Int || XTYPE (key) == Lisp_Symbol) |
1239
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
2968 { |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
2969 buf = ((XTYPE (Vlast_event_frame) == Lisp_Frame) |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
2970 ? (XBUFFER |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
2971 (XWINDOW |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
2972 (FRAME_SELECTED_WINDOW |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
2973 (XFRAME (Vlast_event_frame)))->buffer)) |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
2974 : last_event_buffer); |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
2975 } |
518 | 2976 else if (EVENT_HAS_PARAMETERS (key)) |
2977 { | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
2978 Lisp_Object window = POSN_WINDOW (EVENT_START (key)); |
518 | 2979 |
2980 if (NILP (window)) | |
2981 abort (); | |
2982 | |
2983 buf = XBUFFER (XWINDOW (window)->buffer); | |
2984 } | |
2985 else | |
2986 abort (); | |
2987 | |
2988 /* If this event came to a different buffer than the one | |
2989 we're currently in, switch buffers and start a new key | |
2990 sequence, starting with key. */ | |
2991 if (buf != last_event_buffer) | |
2992 { | |
2993 last_event_buffer = buf; | |
765 | 2994 Fselect_frame (Vlast_event_frame, Qnil); |
518 | 2995 |
2996 /* Arrange to read key as the next event. */ | |
2997 keybuf[0] = key; | |
2998 mock_input = 1; | |
2999 | |
3000 goto restart; | |
3001 } | |
732 | 3002 #endif |
518 | 3003 } |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3004 |
518 | 3005 first_binding = (follow_key (key, |
3006 nmaps - first_binding, | |
899 | 3007 submaps + first_binding, |
518 | 3008 defs + first_binding, |
899 | 3009 submaps + first_binding) |
518 | 3010 + first_binding); |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3011 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3012 /* If this key wasn't bound, we'll try some fallbacks. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3013 if (first_binding >= nmaps) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3014 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3015 Lisp_Object head = EVENT_HEAD (key); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3016 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3017 if (XTYPE (head) == Lisp_Symbol) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3018 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3019 Lisp_Object breakdown = parse_modifiers (head); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3020 Lisp_Object modifiers = |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3021 XINT (XCONS (XCONS (breakdown)->cdr)->car); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3022 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3023 /* We drop unbound `down-' events altogether. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3024 if (modifiers & down_modifier) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3025 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3026 /* Adding prefixes for non-textual mouse clicks creates |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3027 two characters of mock input, and this can't be the |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3028 first, so it's okay to clear mock_input in that case. |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3029 Only function key expansion could create more than |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3030 two keys, but that should never generate mouse events, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3031 so it's okay to nuke mock_input in that case too. |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3032 Isn't this just the most wonderful code ever? */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3033 mock_input = 0; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3034 goto retry_key; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3035 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3036 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3037 /* We turn unbound `drag-' events into `click-' |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3038 events, if the click would be bound. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3039 else if (modifiers & drag_modifier) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3040 { |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3041 Lisp_Object new_head = |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3042 apply_modifiers (modifiers & ~drag_modifier, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3043 XCONS (breakdown)->car); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3044 Lisp_Object new_click = |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3045 Fcons (new_head, Fcons (EVENT_START (key), Qnil)); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3046 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3047 /* Look for a binding for this new key. follow_key |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3048 promises that it didn't munge submaps the |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3049 last time we called it, since key was unbound. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3050 first_binding = |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3051 (follow_key (new_click, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3052 nmaps - local_first_binding, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3053 submaps + local_first_binding, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3054 defs + local_first_binding, |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3055 submaps + local_first_binding) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3056 + local_first_binding); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3057 |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3058 /* If that click is bound, go for it. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3059 if (first_binding < nmaps) |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3060 key = new_click; |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3061 /* Otherwise, we'll leave key set to the drag event. */ |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3062 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3063 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3064 } |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3065 |
518 | 3066 keybuf[t++] = key; |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3067 /* Normally, last_nonmenu_event gets the previous key we read. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3068 But when a mouse popup menu is being used, |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3069 we don't update last_nonmenu_event; it continues to hold the mouse |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3070 event that preceded the first level of menu. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3071 if (!used_mouse_menu) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3072 last_nonmenu_event = key; |
518 | 3073 |
3074 /* If the sequence is unbound, see if we can hang a function key | |
899 | 3075 off the end of it. We only want to scan real keyboard input |
3076 for function key sequences, so if mock_input says that we're | |
3077 re-scanning after expanding a function key, don't examine it. */ | |
518 | 3078 if (first_binding >= nmaps |
899 | 3079 && t >= mock_input) |
518 | 3080 { |
3081 Lisp_Object fkey_next; | |
3082 | |
3083 /* Scan from fkey_end until we find a bound suffix. */ | |
3084 while (fkey_end < t) | |
3085 { | |
853 | 3086 /* Look up meta-characters by prefixing them |
3087 with meta_prefix_char. I hate this. */ | |
899 | 3088 if (keybuf[fkey_end] & 0x80) |
853 | 3089 fkey_next = |
3090 get_keymap_1 (get_keyelt | |
3091 (access_keymap (fkey_map, meta_prefix_char)), | |
3092 0); | |
3093 else | |
3094 fkey_next = fkey_map; | |
3095 | |
518 | 3096 fkey_next = |
853 | 3097 get_keyelt (access_keymap |
939
c4dcdc9aed70
Clear the eighth bit of the character from the key sequence, NOT the
Jim Blandy <jimb@redhat.com>
parents:
899
diff
changeset
|
3098 (fkey_next, keybuf[fkey_end++] & 0x7f)); |
c4dcdc9aed70
Clear the eighth bit of the character from the key sequence, NOT the
Jim Blandy <jimb@redhat.com>
parents:
899
diff
changeset
|
3099 |
c4dcdc9aed70
Clear the eighth bit of the character from the key sequence, NOT the
Jim Blandy <jimb@redhat.com>
parents:
899
diff
changeset
|
3100 /* If keybuf[fkey_start..fkey_end] is bound in the |
547 | 3101 function key map and it's a suffix of the current |
939
c4dcdc9aed70
Clear the eighth bit of the character from the key sequence, NOT the
Jim Blandy <jimb@redhat.com>
parents:
899
diff
changeset
|
3102 sequence (i.e. fkey_end == t), replace it with |
547 | 3103 the binding and restart with fkey_start at the end. */ |
518 | 3104 if (XTYPE (fkey_next) == Lisp_Vector |
3105 && fkey_end == t) | |
3106 { | |
3107 t = fkey_start + XVECTOR (fkey_next)->size; | |
3108 if (t >= bufsize) | |
3109 error ("key sequence too long"); | |
3110 | |
3111 bcopy (XVECTOR (fkey_next)->contents, | |
3112 keybuf + fkey_start, | |
3113 (t - fkey_start) * sizeof (keybuf[0])); | |
3114 | |
3115 mock_input = t; | |
3116 fkey_start = fkey_end = t; | |
3117 | |
3118 goto restart; | |
3119 } | |
3120 | |
3121 fkey_map = get_keymap_1 (fkey_next, 0); | |
3122 | |
547 | 3123 /* If we no longer have a bound suffix, try a new positions for |
3124 fkey_start. */ | |
518 | 3125 if (NILP (fkey_map)) |
3126 { | |
3127 fkey_end = ++fkey_start; | |
3128 fkey_map = Vfunction_key_map; | |
3129 } | |
3130 } | |
3131 } | |
3132 } | |
3133 | |
3134 read_key_sequence_cmd = (first_binding < nmaps | |
3135 ? defs[first_binding] | |
3136 : Qnil); | |
3137 | |
3138 return t; | |
3139 } | |
3140 | |
691
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
3141 DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 2, 0, |
518 | 3142 "Read a sequence of keystrokes and return as a string or vector.\n\ |
3143 The sequence is sufficient to specify a non-prefix command in the\n\ | |
3144 current local and global maps.\n\ | |
3145 \n\ | |
691
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
3146 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\ |
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
3147 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\ |
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
3148 as a continuation of the previous key.\n\ |
518 | 3149 \n\ |
765 | 3150 If Emacs is running on multiple frames, switching between frames in\n\ |
518 | 3151 the midst of a keystroke will toss any prefix typed so far. A C-g\n\ |
3152 typed while in this function is treated like any other character, and\n\ | |
3153 `quit-flag' is not set.") | |
691
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
3154 (prompt, continue_echo) |
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
3155 Lisp_Object prompt, continue_echo; |
518 | 3156 { |
3157 Lisp_Object keybuf[30]; | |
3158 register int i; | |
3159 struct gcpro gcpro1, gcpro2; | |
3160 | |
3161 if (!NILP (prompt)) | |
3162 CHECK_STRING (prompt, 0); | |
3163 QUIT; | |
3164 | |
3165 bzero (keybuf, sizeof keybuf); | |
3166 GCPRO1 (keybuf[0]); | |
3167 gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); | |
3168 | |
727 | 3169 if (NILP (continue_echo)) |
691
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
3170 this_command_key_count = 0; |
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
3171 |
518 | 3172 i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), |
3173 NILP (prompt) ? 0 : XSTRING (prompt)->data); | |
3174 | |
3175 UNGCPRO; | |
3176 return make_array (i, keybuf); | |
3177 } | |
3178 | |
3179 DEFUN ("command-execute", Fcommand_execute, Scommand_execute, 1, 2, 0, | |
3180 "Execute CMD as an editor command.\n\ | |
3181 CMD must be a symbol that satisfies the `commandp' predicate.\n\ | |
3182 Optional second arg RECORD-FLAG non-nil\n\ | |
3183 means unconditionally put this command in `command-history'.\n\ | |
3184 Otherwise, that is done only if an arg is read using the minibuffer.") | |
3185 (cmd, record) | |
3186 Lisp_Object cmd, record; | |
3187 { | |
3188 register Lisp_Object final; | |
3189 register Lisp_Object tem; | |
3190 Lisp_Object prefixarg; | |
3191 struct backtrace backtrace; | |
3192 extern int debug_on_next_call; | |
3193 | |
3194 prefixarg = Vprefix_arg, Vprefix_arg = Qnil; | |
3195 Vcurrent_prefix_arg = prefixarg; | |
3196 debug_on_next_call = 0; | |
3197 | |
3198 if (XTYPE (cmd) == Lisp_Symbol) | |
3199 { | |
3200 tem = Fget (cmd, Qdisabled); | |
3201 if (!NILP (tem)) | |
3202 return call1 (Vrun_hooks, Vdisabled_command_hook); | |
3203 } | |
3204 | |
3205 while (1) | |
3206 { | |
648 | 3207 final = Findirect_function (cmd); |
518 | 3208 |
3209 if (CONSP (final) && (tem = Fcar (final), EQ (tem, Qautoload))) | |
3210 do_autoload (final, cmd); | |
3211 else | |
3212 break; | |
3213 } | |
3214 | |
3215 if (XTYPE (final) == Lisp_String | |
3216 || XTYPE (final) == Lisp_Vector) | |
3217 { | |
3218 /* If requested, place the macro in the command history. For | |
3219 other sorts of commands, call-interactively takes care of | |
3220 this. */ | |
3221 if (!NILP (record)) | |
3222 Vcommand_history | |
3223 = Fcons (Fcons (Qexecute_kbd_macro, | |
3224 Fcons (final, Fcons (prefixarg, Qnil))), | |
3225 Vcommand_history); | |
3226 | |
3227 return Fexecute_kbd_macro (final, prefixarg); | |
3228 } | |
3229 if (CONSP (final) || XTYPE (final) == Lisp_Subr | |
3230 || XTYPE (final) == Lisp_Compiled) | |
3231 { | |
3232 backtrace.next = backtrace_list; | |
3233 backtrace_list = &backtrace; | |
3234 backtrace.function = &Qcall_interactively; | |
3235 backtrace.args = &cmd; | |
3236 backtrace.nargs = 1; | |
3237 backtrace.evalargs = 0; | |
3238 | |
3239 tem = Fcall_interactively (cmd, record); | |
3240 | |
3241 backtrace_list = backtrace.next; | |
3242 return tem; | |
3243 } | |
3244 return Qnil; | |
3245 } | |
3246 | |
3247 DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_command, | |
3248 1, 1, "P", | |
3249 "Read function name, then read its arguments and call it.") | |
3250 (prefixarg) | |
3251 Lisp_Object prefixarg; | |
3252 { | |
3253 Lisp_Object function; | |
3254 char buf[40]; | |
3255 Lisp_Object saved_keys; | |
3256 struct gcpro gcpro1; | |
3257 | |
3258 saved_keys = Fthis_command_keys (); | |
3259 buf[0] = 0; | |
3260 GCPRO1 (saved_keys); | |
3261 | |
3262 if (EQ (prefixarg, Qminus)) | |
3263 strcpy (buf, "- "); | |
3264 else if (CONSP (prefixarg) && XINT (XCONS (prefixarg)->car) == 4) | |
3265 strcpy (buf, "C-u "); | |
3266 else if (CONSP (prefixarg) && XTYPE (XCONS (prefixarg)->car) == Lisp_Int) | |
3267 sprintf (buf, "%d ", XINT (XCONS (prefixarg)->car)); | |
3268 else if (XTYPE (prefixarg) == Lisp_Int) | |
3269 sprintf (buf, "%d ", XINT (prefixarg)); | |
3270 | |
3271 /* This isn't strictly correct if execute-extended-command | |
3272 is bound to anything else. Perhaps it should use | |
3273 this_command_keys? */ | |
3274 strcat (buf, "M-x "); | |
3275 | |
3276 /* Prompt with buf, and then read a string, completing from and | |
3277 restricting to the set of all defined commands. Don't provide | |
3278 any initial input. The last Qnil says not to perform a | |
3279 peculiar hack on the initial input. */ | |
3280 function = Fcompleting_read (build_string (buf), | |
3281 Vobarray, Qcommandp, | |
3282 Qt, Qnil, Qnil); | |
3283 | |
708 | 3284 /* Set this_command_keys to the concatenation of saved_keys and |
3285 function, followed by a RET. */ | |
518 | 3286 { |
708 | 3287 struct Lisp_String *str; |
518 | 3288 int i; |
3289 Lisp_Object tem; | |
3290 | |
708 | 3291 this_command_key_count = 0; |
3292 | |
3293 str = XSTRING (saved_keys); | |
3294 for (i = 0; i < str->size; i++) | |
518 | 3295 { |
708 | 3296 XFASTINT (tem) = str->data[i]; |
518 | 3297 add_command_key (tem); |
3298 } | |
708 | 3299 |
3300 str = XSTRING (function); | |
3301 for (i = 0; i < str->size; i++) | |
3302 { | |
3303 XFASTINT (tem) = str->data[i]; | |
3304 add_command_key (tem); | |
3305 } | |
3306 | |
3307 XFASTINT (tem) = '\015'; | |
3308 add_command_key (tem); | |
518 | 3309 } |
3310 | |
3311 UNGCPRO; | |
3312 | |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3313 function = Fintern (function, Qnil); |
518 | 3314 Vprefix_arg = prefixarg; |
3315 this_command = function; | |
3316 | |
3317 return Fcommand_execute (function, Qt); | |
3318 } | |
3319 | |
3320 | |
3321 detect_input_pending () | |
3322 { | |
3323 if (!input_pending) | |
3324 get_input_pending (&input_pending); | |
3325 | |
3326 return input_pending; | |
3327 } | |
3328 | |
648 | 3329 /* This is called in some cases before a possible quit. |
3330 It cases the next call to detect_input_pending to recompute input_pending. | |
3331 So calling this function unnecessarily can't do any harm. */ | |
3332 clear_input_pending () | |
3333 { | |
3334 input_pending = 0; | |
3335 } | |
3336 | |
518 | 3337 DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0, |
3338 "T if command input is currently available with no waiting.\n\ | |
3339 Actually, the value is nil only if we can be sure that no input is available.") | |
3340 () | |
3341 { | |
3342 if (!NILP (unread_command_char)) | |
3343 return (Qt); | |
3344 | |
3345 return detect_input_pending () ? Qt : Qnil; | |
3346 } | |
3347 | |
3348 DEFUN ("recent-keys", Frecent_keys, Srecent_keys, 0, 0, 0, | |
727 | 3349 "Return vector of last 100 chars read from terminal.") |
518 | 3350 () |
3351 { | |
1261
60b30565326c
* keyboard.c (recent_keys): Turn this from an array, which is a
Jim Blandy <jimb@redhat.com>
parents:
1239
diff
changeset
|
3352 Lisp_Object *keys = XVECTOR (recent_keys)->contents; |
518 | 3353 Lisp_Object val; |
3354 | |
3355 if (total_keys < NUM_RECENT_KEYS) | |
1261
60b30565326c
* keyboard.c (recent_keys): Turn this from an array, which is a
Jim Blandy <jimb@redhat.com>
parents:
1239
diff
changeset
|
3356 return Fvector (total_keys, keys); |
518 | 3357 else |
3358 { | |
1261
60b30565326c
* keyboard.c (recent_keys): Turn this from an array, which is a
Jim Blandy <jimb@redhat.com>
parents:
1239
diff
changeset
|
3359 val = Fvector (NUM_RECENT_KEYS, keys); |
60b30565326c
* keyboard.c (recent_keys): Turn this from an array, which is a
Jim Blandy <jimb@redhat.com>
parents:
1239
diff
changeset
|
3360 bcopy (keys + recent_keys_index, |
518 | 3361 XVECTOR (val)->contents, |
3362 (NUM_RECENT_KEYS - recent_keys_index) * sizeof (Lisp_Object)); | |
1261
60b30565326c
* keyboard.c (recent_keys): Turn this from an array, which is a
Jim Blandy <jimb@redhat.com>
parents:
1239
diff
changeset
|
3363 bcopy (keys, |
518 | 3364 XVECTOR (val)->contents + NUM_RECENT_KEYS - recent_keys_index, |
3365 recent_keys_index * sizeof (Lisp_Object)); | |
3366 return val; | |
3367 } | |
3368 } | |
3369 | |
3370 DEFUN ("this-command-keys", Fthis_command_keys, Sthis_command_keys, 0, 0, 0, | |
3371 "Return string of the keystrokes that invoked this command.") | |
3372 () | |
3373 { | |
3374 return make_array (this_command_key_count, this_command_keys); | |
3375 } | |
3376 | |
3377 DEFUN ("recursion-depth", Frecursion_depth, Srecursion_depth, 0, 0, 0, | |
3378 "Return the current depth in recursive edits.") | |
3379 () | |
3380 { | |
3381 Lisp_Object temp; | |
3382 XFASTINT (temp) = command_loop_level + minibuf_level; | |
3383 return temp; | |
3384 } | |
3385 | |
3386 DEFUN ("open-dribble-file", Fopen_dribble_file, Sopen_dribble_file, 1, 1, | |
3387 "FOpen dribble file: ", | |
3388 "Start writing all keyboard characters to FILE.") | |
3389 (file) | |
3390 Lisp_Object file; | |
3391 { | |
3392 if (NILP (file)) | |
3393 { | |
3394 fclose (dribble); | |
3395 dribble = 0; | |
3396 } | |
3397 else | |
3398 { | |
3399 file = Fexpand_file_name (file, Qnil); | |
3400 dribble = fopen (XSTRING (file)->data, "w"); | |
3401 } | |
3402 return Qnil; | |
3403 } | |
3404 | |
3405 DEFUN ("discard-input", Fdiscard_input, Sdiscard_input, 0, 0, 0, | |
3406 "Discard the contents of the terminal input buffer.\n\ | |
3407 Also cancel any kbd macro being defined.") | |
3408 () | |
3409 { | |
3410 defining_kbd_macro = 0; | |
3411 update_mode_lines++; | |
3412 | |
3413 unread_command_char = Qnil; | |
3414 | |
3415 discard_tty_input (); | |
3416 | |
3417 kbd_fetch_ptr = kbd_store_ptr; | |
3418 input_pending = 0; | |
3419 | |
3420 return Qnil; | |
3421 } | |
3422 | |
3423 DEFUN ("suspend-emacs", Fsuspend_emacs, Ssuspend_emacs, 0, 1, "", | |
3424 "Stop Emacs and return to superior process. You can resume later.\n\ | |
3425 On systems that don't have job control, run a subshell instead.\n\n\ | |
3426 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\ | |
3427 to be read as terminal input by Emacs's superior shell.\n\ | |
3428 Before suspending, if `suspend-hook' is bound and value is non-nil\n\ | |
3429 call the value as a function of no args. Don't suspend if it returns non-nil.\n\ | |
3430 Otherwise, suspend normally and after resumption call\n\ | |
3431 `suspend-resume-hook' if that is bound and non-nil.\n\ | |
3432 \n\ | |
3433 Some operating systems cannot stop the Emacs process and resume it later.\n\ | |
3434 On such systems, Emacs will start a subshell and wait for it to exit.") | |
3435 (stuffstring) | |
3436 Lisp_Object stuffstring; | |
3437 { | |
3438 register Lisp_Object tem; | |
3439 int count = specpdl_ptr - specpdl; | |
3440 int old_height, old_width; | |
3441 int width, height; | |
3442 struct gcpro gcpro1; | |
3443 extern init_sys_modes (); | |
3444 | |
3445 if (!NILP (stuffstring)) | |
3446 CHECK_STRING (stuffstring, 0); | |
3447 GCPRO1 (stuffstring); | |
3448 | |
3449 /* Call value of suspend-hook | |
3450 if it is bound and value is non-nil. */ | |
3451 if (!NILP (Vrun_hooks)) | |
3452 { | |
3453 tem = call1 (Vrun_hooks, intern ("suspend-hook")); | |
3454 if (!EQ (tem, Qnil)) return Qnil; | |
3455 } | |
3456 | |
765 | 3457 get_frame_size (&old_width, &old_height); |
518 | 3458 reset_sys_modes (); |
3459 /* sys_suspend can get an error if it tries to fork a subshell | |
3460 and the system resources aren't available for that. */ | |
3461 record_unwind_protect (init_sys_modes, 0); | |
3462 stuff_buffered_input (stuffstring); | |
3463 sys_suspend (); | |
3464 unbind_to (count, Qnil); | |
3465 | |
3466 /* Check if terminal/window size has changed. | |
3467 Note that this is not useful when we are running directly | |
3468 with a window system; but suspend should be disabled in that case. */ | |
765 | 3469 get_frame_size (&width, &height); |
518 | 3470 if (width != old_width || height != old_height) |
966
eb74884fc95a
* keyboard.c (Fsuspend_emacs): Call change_frame_size with the
Jim Blandy <jimb@redhat.com>
parents:
939
diff
changeset
|
3471 change_frame_size (0, height, width, 0, 0); |
518 | 3472 |
3473 /* Call value of suspend-resume-hook | |
3474 if it is bound and value is non-nil. */ | |
3475 if (!NILP (Vrun_hooks)) | |
3476 call1 (Vrun_hooks, intern ("suspend-resume-hook")); | |
3477 | |
3478 UNGCPRO; | |
3479 return Qnil; | |
3480 } | |
3481 | |
3482 /* If STUFFSTRING is a string, stuff its contents as pending terminal input. | |
3483 Then in any case stuff anthing Emacs has read ahead and not used. */ | |
3484 | |
3485 stuff_buffered_input (stuffstring) | |
3486 Lisp_Object stuffstring; | |
3487 { | |
3488 register unsigned char *p; | |
3489 | |
3490 /* stuff_char works only in BSD, versions 4.2 and up. */ | |
3491 #ifdef BSD | |
3492 #ifndef BSD4_1 | |
3493 if (XTYPE (stuffstring) == Lisp_String) | |
3494 { | |
3495 register int count; | |
3496 | |
3497 p = XSTRING (stuffstring)->data; | |
3498 count = XSTRING (stuffstring)->size; | |
3499 while (count-- > 0) | |
3500 stuff_char (*p++); | |
3501 stuff_char ('\n'); | |
3502 } | |
3503 /* Anything we have read ahead, put back for the shell to read. */ | |
3504 while (kbd_fetch_ptr != kbd_store_ptr) | |
3505 { | |
3506 if (kbd_fetch_ptr == kbd_buffer + KBD_BUFFER_SIZE) | |
3507 kbd_fetch_ptr = kbd_buffer; | |
3508 if (kbd_fetch_ptr->kind == ascii_keystroke) | |
3509 stuff_char (XINT (kbd_fetch_ptr->code)); | |
3510 kbd_fetch_ptr++; | |
3511 } | |
3512 input_pending = 0; | |
3513 #endif | |
3514 #endif /* BSD and not BSD4_1 */ | |
3515 } | |
3516 | |
648 | 3517 set_waiting_for_input (time_to_clear) |
3518 EMACS_TIME *time_to_clear; | |
518 | 3519 { |
648 | 3520 input_available_clear_time = time_to_clear; |
518 | 3521 |
3522 /* Tell interrupt_signal to throw back to read_char, */ | |
3523 waiting_for_input = 1; | |
3524 | |
3525 /* If interrupt_signal was called before and buffered a C-g, | |
3526 make it run again now, to avoid timing error. */ | |
3527 if (!NILP (Vquit_flag)) | |
3528 quit_throw_to_read_char (); | |
3529 | |
3530 /* If alarm has gone off already, echo now. */ | |
3531 if (echo_flag) | |
3532 { | |
3533 echo (); | |
3534 echo_flag = 0; | |
3535 } | |
3536 } | |
3537 | |
3538 clear_waiting_for_input () | |
3539 { | |
3540 /* Tell interrupt_signal not to throw back to read_char, */ | |
3541 waiting_for_input = 0; | |
648 | 3542 input_available_clear_time = 0; |
518 | 3543 } |
3544 | |
3545 /* This routine is called at interrupt level in response to C-G. | |
3546 If interrupt_input, this is the handler for SIGINT. | |
3547 Otherwise, it is called from kbd_buffer_store_event, | |
3548 in handling SIGIO or SIGTINT. | |
3549 | |
3550 If `waiting_for_input' is non zero, then unless `echoing' is nonzero, | |
3551 immediately throw back to read_char. | |
3552 | |
3553 Otherwise it sets the Lisp variable quit-flag not-nil. | |
3554 This causes eval to throw, when it gets a chance. | |
3555 If quit-flag is already non-nil, it stops the job right away. */ | |
3556 | |
3557 SIGTYPE | |
3558 interrupt_signal () | |
3559 { | |
3560 char c; | |
3561 /* Must preserve main program's value of errno. */ | |
3562 int old_errno = errno; | |
3563 extern Lisp_Object Vwindow_system; | |
3564 | |
3565 #ifdef USG | |
3566 /* USG systems forget handlers when they are used; | |
3567 must reestablish each time */ | |
3568 signal (SIGINT, interrupt_signal); | |
3569 signal (SIGQUIT, interrupt_signal); | |
3570 #endif /* USG */ | |
3571 | |
3572 cancel_echoing (); | |
3573 | |
966
eb74884fc95a
* keyboard.c (Fsuspend_emacs): Call change_frame_size with the
Jim Blandy <jimb@redhat.com>
parents:
939
diff
changeset
|
3574 if (!NILP (Vquit_flag) && FRAME_TERMCAP_P (selected_frame)) |
518 | 3575 { |
3576 fflush (stdout); | |
3577 reset_sys_modes (); | |
3578 sigfree (); | |
3579 #ifdef SIGTSTP /* Support possible in later USG versions */ | |
3580 /* | |
3581 * On systems which can suspend the current process and return to the original | |
3582 * shell, this command causes the user to end up back at the shell. | |
3583 * The "Auto-save" and "Abort" questions are not asked until | |
3584 * the user elects to return to emacs, at which point he can save the current | |
3585 * job and either dump core or continue. | |
3586 */ | |
3587 sys_suspend (); | |
3588 #else | |
3589 #ifdef VMS | |
3590 if (sys_suspend () == -1) | |
3591 { | |
3592 printf ("Not running as a subprocess;\n"); | |
3593 printf ("you can continue or abort.\n"); | |
3594 } | |
3595 #else /* not VMS */ | |
3596 /* Perhaps should really fork an inferior shell? | |
3597 But that would not provide any way to get back | |
3598 to the original shell, ever. */ | |
3599 printf ("No support for stopping a process on this operating system;\n"); | |
3600 printf ("you can continue or abort.\n"); | |
3601 #endif /* not VMS */ | |
3602 #endif /* not SIGTSTP */ | |
3603 printf ("Auto-save? (y or n) "); | |
3604 fflush (stdout); | |
3605 if (((c = getchar ()) & ~040) == 'Y') | |
3606 Fdo_auto_save (Qnil, Qnil); | |
3607 while (c != '\n') c = getchar (); | |
3608 #ifdef VMS | |
3609 printf ("Abort (and enter debugger)? (y or n) "); | |
3610 #else /* not VMS */ | |
3611 printf ("Abort (and dump core)? (y or n) "); | |
3612 #endif /* not VMS */ | |
3613 fflush (stdout); | |
3614 if (((c = getchar ()) & ~040) == 'Y') | |
3615 abort (); | |
3616 while (c != '\n') c = getchar (); | |
3617 printf ("Continuing...\n"); | |
3618 fflush (stdout); | |
3619 init_sys_modes (); | |
3620 } | |
3621 else | |
3622 { | |
3623 /* If executing a function that wants to be interrupted out of | |
3624 and the user has not deferred quitting by binding `inhibit-quit' | |
3625 then quit right away. */ | |
3626 if (immediate_quit && NILP (Vinhibit_quit)) | |
3627 { | |
3628 immediate_quit = 0; | |
3629 sigfree (); | |
3630 Fsignal (Qquit, Qnil); | |
3631 } | |
3632 else | |
3633 /* Else request quit when it's safe */ | |
3634 Vquit_flag = Qt; | |
3635 } | |
3636 | |
3637 if (waiting_for_input && !echoing) | |
3638 quit_throw_to_read_char (); | |
3639 | |
3640 errno = old_errno; | |
3641 } | |
3642 | |
3643 /* Handle a C-g by making read_char return C-g. */ | |
3644 | |
3645 quit_throw_to_read_char () | |
3646 { | |
3647 quit_error_check (); | |
3648 sigfree (); | |
3649 /* Prevent another signal from doing this before we finish. */ | |
650 | 3650 clear_waiting_for_input (); |
518 | 3651 input_pending = 0; |
3652 | |
3653 unread_command_char = Qnil; | |
3654 | |
3655 _longjmp (getcjmp, 1); | |
3656 } | |
3657 | |
3658 DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, | |
3659 "Set mode of reading keyboard input.\n\ | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
691
diff
changeset
|
3660 First arg INTERRUPT non-nil means use input interrupts;\n\ |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
691
diff
changeset
|
3661 nil means use CBREAK mode.\n\ |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
691
diff
changeset
|
3662 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\ |
518 | 3663 (no effect except in CBREAK mode).\n\ |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
691
diff
changeset
|
3664 Third arg META non-nil means accept 8-bit input (for a Meta key).\n\ |
518 | 3665 Otherwise, the top bit is ignored, on the assumption it is parity.\n\ |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
691
diff
changeset
|
3666 Optional fourth arg QUIT if non-nil specifies character to use for quitting.") |
518 | 3667 (interrupt, flow, meta, quit) |
3668 Lisp_Object interrupt, flow, meta, quit; | |
3669 { | |
3670 if (!NILP (quit) | |
3671 && (XTYPE (quit) != Lisp_Int | |
3672 || XINT (quit) < 0 || XINT (quit) > 0400)) | |
3673 error ("set-input-mode: QUIT must be an ASCII character."); | |
3674 | |
3675 reset_sys_modes (); | |
3676 #ifdef SIGIO | |
3677 /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
3678 #ifdef NO_SOCK_SIGIO | |
3679 if (read_socket_hook) | |
3680 interrupt_input = 0; /* No interrupts if reading from a socket. */ | |
3681 else | |
3682 #endif /* NO_SOCK_SIGIO */ | |
3683 interrupt_input = !NILP (interrupt); | |
3684 #else /* not SIGIO */ | |
3685 interrupt_input = 0; | |
3686 #endif /* not SIGIO */ | |
3687 /* Our VMS input only works by interrupts, as of now. */ | |
3688 #ifdef VMS | |
3689 interrupt_input = 1; | |
3690 #endif | |
3691 flow_control = !NILP (flow); | |
3692 meta_key = !NILP (meta); | |
3693 if (!NILP (quit)) | |
3694 /* Don't let this value be out of range. */ | |
3695 quit_char = XINT (quit) & (meta_key ? 0377 : 0177); | |
3696 | |
3697 init_sys_modes (); | |
3698 return Qnil; | |
3699 } | |
3700 | |
3701 init_keyboard () | |
3702 { | |
3703 this_command_keys_size = 40; | |
3704 this_command_keys = | |
3705 (Lisp_Object *) xmalloc (this_command_keys_size * sizeof (Lisp_Object)); | |
3706 | |
3707 /* This is correct before outermost invocation of the editor loop */ | |
3708 command_loop_level = -1; | |
3709 immediate_quit = 0; | |
3710 quit_char = Ctl ('g'); | |
3711 unread_command_char = Qnil; | |
3712 total_keys = 0; | |
1262
c9fc221502e4
* keyboard.c: Initialize recent_keys in syms_of_keyboard, not
Jim Blandy <jimb@redhat.com>
parents:
1261
diff
changeset
|
3713 recent_keys_index = 0; |
518 | 3714 kbd_fetch_ptr = kbd_buffer; |
3715 kbd_store_ptr = kbd_buffer; | |
3716 do_mouse_tracking = 0; | |
3717 input_pending = 0; | |
3718 | |
3719 if (!noninteractive) | |
3720 { | |
3721 signal (SIGINT, interrupt_signal); | |
3722 #ifdef HAVE_TERMIO | |
3723 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and | |
3724 SIGQUIT and we can't tell which one it will give us. */ | |
3725 signal (SIGQUIT, interrupt_signal); | |
3726 #endif /* HAVE_TERMIO */ | |
3727 /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
3728 #ifdef SIGIO | |
3729 signal (SIGIO, input_available_signal); | |
1008
f1df63f98e5c
* keyboard.c (init_keyboard): Changed "#endif SIGIO" to
Jim Blandy <jimb@redhat.com>
parents:
985
diff
changeset
|
3730 #endif /* SIGIO */ |
518 | 3731 } |
3732 | |
3733 /* Use interrupt input by default, if it works and noninterrupt input | |
3734 has deficiencies. */ | |
3735 | |
3736 #ifdef INTERRUPT_INPUT | |
3737 interrupt_input = 1; | |
3738 #else | |
3739 interrupt_input = 0; | |
3740 #endif | |
3741 | |
3742 /* Our VMS input only works by interrupts, as of now. */ | |
3743 #ifdef VMS | |
3744 interrupt_input = 1; | |
3745 #endif | |
3746 | |
3747 sigfree (); | |
3748 dribble = 0; | |
3749 | |
3750 if (keyboard_init_hook) | |
3751 (*keyboard_init_hook) (); | |
3752 | |
3753 #ifdef POLL_FOR_INPUT | |
3754 poll_suppress_count = 1; | |
3755 start_polling (); | |
3756 #endif | |
3757 } | |
3758 | |
3759 /* This type's only use is in syms_of_keyboard, to initialize the | |
3760 event header symbols and put properties on them. */ | |
3761 struct event_head { | |
3762 Lisp_Object *var; | |
3763 char *name; | |
3764 Lisp_Object *kind; | |
3765 }; | |
3766 | |
3767 struct event_head head_table[] = { | |
3768 &Qmouse_movement, "mouse-movement", &Qmouse_movement, | |
3769 &Qvscrollbar_part, "vscrollbar-part", &Qscrollbar_click, | |
3770 &Qvslider_part, "vslider-part", &Qscrollbar_click, | |
3771 &Qvthumbup_part, "vthumbup-part", &Qscrollbar_click, | |
3772 &Qvthumbdown_part, "vthumbdown-part", &Qscrollbar_click, | |
3773 &Qhscrollbar_part, "hscrollbar-part", &Qscrollbar_click, | |
3774 &Qhslider_part, "hslider-part", &Qscrollbar_click, | |
3775 &Qhthumbleft_part, "hthumbleft-part", &Qscrollbar_click, | |
3776 &Qhthumbright_part,"hthumbright-part", &Qscrollbar_click | |
3777 }; | |
3778 | |
3779 syms_of_keyboard () | |
3780 { | |
3781 Qself_insert_command = intern ("self-insert-command"); | |
3782 staticpro (&Qself_insert_command); | |
3783 | |
3784 Qforward_char = intern ("forward-char"); | |
3785 staticpro (&Qforward_char); | |
3786 | |
3787 Qbackward_char = intern ("backward-char"); | |
3788 staticpro (&Qbackward_char); | |
3789 | |
3790 Qdisabled = intern ("disabled"); | |
3791 staticpro (&Qdisabled); | |
3792 | |
3793 Qfunction_key = intern ("function-key"); | |
3794 staticpro (&Qfunction_key); | |
1322
5f327f1dddd3
* keyboard.c (modify_event_symbol): Make sure that the unmodified
Jim Blandy <jimb@redhat.com>
parents:
1310
diff
changeset
|
3795 Qmouse_click = intern ("mouse-click"); |
518 | 3796 staticpro (&Qmouse_click); |
3797 Qmouse_movement = intern ("scrollbar-click"); | |
3798 staticpro (&Qmouse_movement); | |
3799 | |
3800 Qmode_line = intern ("mode-line"); | |
3801 staticpro (&Qmode_line); | |
732 | 3802 Qvertical_line = intern ("vertical-line"); |
3803 staticpro (&Qvertical_line); | |
518 | 3804 |
3805 Qevent_kind = intern ("event-type"); | |
3806 staticpro (&Qevent_kind); | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3807 Qevent_symbol_elements = intern ("event-symbol-elements"); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3808 staticpro (&Qevent_symbol_elements); |
1328
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3809 Qevent_symbol_element_mask = intern ("event-symbol-element-mask"); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3810 staticpro (&Qevent_symbol_element_mask); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3811 Qmodifier_cache = intern ("modifier-cache"); |
c4eb3aa71303
* keyboard.c (read_key_sequence): Treat mouse clicks on non-text
Jim Blandy <jimb@redhat.com>
parents:
1322
diff
changeset
|
3812 staticpro (&Qmodifier_cache); |
518 | 3813 |
3814 { | |
3815 struct event_head *p; | |
3816 | |
3817 for (p = head_table; | |
3818 p < head_table + (sizeof (head_table) / sizeof (head_table[0])); | |
3819 p++) | |
3820 { | |
3821 *p->var = intern (p->name); | |
3822 staticpro (p->var); | |
3823 Fput (*p->var, Qevent_kind, *p->kind); | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3824 Fput (*p->var, Qevent_symbol_elements, Fcons (*p->var, Qnil)); |
518 | 3825 } |
3826 } | |
3827 | |
1310
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3828 { |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3829 int i; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3830 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3831 for (i = 0; i < NUM_MOUSE_BUTTONS; i++) |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3832 staticpro (&button_down_location[i].window); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3833 } |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3834 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3835 { |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3836 int i; |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3837 int len = sizeof (modifier_names) / sizeof (modifier_names[0]); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3838 |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3839 modifier_symbols = Fmake_vector (make_number (len), Qnil); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3840 for (i = 0; i < len; i++) |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3841 XVECTOR (modifier_symbols)->contents[i] = intern (modifier_names[i]); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3842 staticpro (&modifier_symbols); |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3843 } |
8db103d11270
* keyboard.c (echo_char, read_char): Apply EVENT_HEAD without first
Jim Blandy <jimb@redhat.com>
parents:
1262
diff
changeset
|
3844 |
1262
c9fc221502e4
* keyboard.c: Initialize recent_keys in syms_of_keyboard, not
Jim Blandy <jimb@redhat.com>
parents:
1261
diff
changeset
|
3845 recent_keys = Fmake_vector (make_number (NUM_RECENT_KEYS), Qnil); |
c9fc221502e4
* keyboard.c: Initialize recent_keys in syms_of_keyboard, not
Jim Blandy <jimb@redhat.com>
parents:
1261
diff
changeset
|
3846 staticpro (&recent_keys); |
c9fc221502e4
* keyboard.c: Initialize recent_keys in syms_of_keyboard, not
Jim Blandy <jimb@redhat.com>
parents:
1261
diff
changeset
|
3847 |
518 | 3848 func_key_syms = Qnil; |
3849 staticpro (&func_key_syms); | |
3850 | |
3851 mouse_syms = Qnil; | |
3852 staticpro (&mouse_syms); | |
3853 | |
3854 defsubr (&Sread_key_sequence); | |
3855 defsubr (&Srecursive_edit); | |
3856 defsubr (&Strack_mouse); | |
3857 defsubr (&Smouse_click_p); | |
3858 defsubr (&Sinput_pending_p); | |
3859 defsubr (&Scommand_execute); | |
3860 defsubr (&Srecent_keys); | |
3861 defsubr (&Sthis_command_keys); | |
3862 defsubr (&Ssuspend_emacs); | |
3863 defsubr (&Sabort_recursive_edit); | |
3864 defsubr (&Sexit_recursive_edit); | |
3865 defsubr (&Srecursion_depth); | |
3866 defsubr (&Stop_level); | |
3867 defsubr (&Sdiscard_input); | |
3868 defsubr (&Sopen_dribble_file); | |
3869 defsubr (&Sset_input_mode); | |
3870 defsubr (&Sexecute_extended_command); | |
3871 | |
3872 DEFVAR_LISP ("disabled-command-hook", &Vdisabled_command_hook, | |
3873 "Value is called instead of any command that is disabled\n\ | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3874 \(has a non-nil `disabled' property)."); |
518 | 3875 |
3876 DEFVAR_LISP ("last-command-char", &last_command_char, | |
3877 "Last terminal input key that was part of a command."); | |
3878 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3879 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event, |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3880 "Last terminal input key in a command, except for mouse menus.\n\ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3881 Mouse menus give back keys that don't look like mouse events;\n\ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3882 this variable holds the actual mouse event that led to the menu,\n\ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3883 so that you can determine whether the command was run by mouse or not."); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3884 |
518 | 3885 DEFVAR_LISP ("last-input-char", &last_input_char, |
3886 "Last terminal input key."); | |
3887 | |
3888 DEFVAR_LISP ("unread-command-char", &unread_command_char, | |
3889 "Object to be read as next input from input stream, or nil if none."); | |
3890 | |
3891 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char, | |
3892 "Meta-prefix character code. Meta-foo as command input\n\ | |
3893 turns into this character followed by foo."); | |
3894 XSET (meta_prefix_char, Lisp_Int, 033); | |
3895 | |
3896 DEFVAR_LISP ("last-command", &last_command, | |
3897 "The last command executed. Normally a symbol with a function definition,\n\ | |
3898 but can be whatever was found in the keymap, or whatever the variable\n\ | |
3899 `this-command' was set to by that command."); | |
3900 last_command = Qnil; | |
3901 | |
3902 DEFVAR_LISP ("this-command", &this_command, | |
3903 "The command now being executed.\n\ | |
3904 The command can set this variable; whatever is put here\n\ | |
3905 will be in `last-command' during the following command."); | |
3906 this_command = Qnil; | |
3907 | |
3908 DEFVAR_INT ("auto-save-interval", &auto_save_interval, | |
3909 "*Number of keyboard input characters between auto-saves.\n\ | |
3910 Zero means disable autosaving due to number of characters typed."); | |
3911 auto_save_interval = 300; | |
3912 | |
3913 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout, | |
3914 "*Number of seconds idle time before auto-save.\n\ | |
687
e2b747dd6a6e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
682
diff
changeset
|
3915 Zero or nil means disable auto-saving due to idleness.\n\ |
e2b747dd6a6e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
682
diff
changeset
|
3916 After auto-saving due to this many seconds of idle time,\n\ |
701 | 3917 Emacs also does a garbage collection if that seems to be warranted."); |
518 | 3918 XFASTINT (Vauto_save_timeout) = 30; |
3919 | |
3920 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes, | |
3921 "*Nonzero means echo unfinished commands after this many seconds of pause."); | |
3922 echo_keystrokes = 1; | |
3923 | |
3924 DEFVAR_INT ("polling-period", &polling_period, | |
3925 "*Interval between polling for input during Lisp execution.\n\ | |
3926 The reason for polling is to make C-g work to stop a running program.\n\ | |
3927 Polling is needed only when using X windows and SIGIO does not work.\n\ | |
3928 Polling is automatically disabled in all other cases."); | |
3929 polling_period = 2; | |
3930 | |
3931 DEFVAR_INT ("num-input-keys", &num_input_keys, | |
3932 "*Number of complete keys read from the keyboard so far."); | |
3933 num_input_keys = 0; | |
3934 | |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
3935 #ifdef MULTI_FRAME |
765 | 3936 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame, |
1239
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
3937 "*The frame in which the most recently read event occurred.\n\ |
52afa4976154
* keyboard.c (read_char): If we're returning an event from a
Jim Blandy <jimb@redhat.com>
parents:
1140
diff
changeset
|
3938 If the last event came from a keyboard macro, this is set to `macro'."); |
765 | 3939 Vlast_event_frame = Qnil; |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
3940 #endif |
518 | 3941 |
3942 DEFVAR_LISP ("help-char", &help_char, | |
3943 "Character to recognize as meaning Help.\n\ | |
3944 When it is read, do `(eval help-form)', and display result if it's a string.\n\ | |
3945 If the value of `help-form' is nil, this char can be read normally."); | |
3946 XSET (help_char, Lisp_Int, Ctl ('H')); | |
3947 | |
3948 DEFVAR_LISP ("help-form", &Vhelp_form, | |
3949 "Form to execute when character help-char is read.\n\ | |
3950 If the form returns a string, that string is displayed.\n\ | |
3951 If `help-form' is nil, the help char is not recognized."); | |
3952 Vhelp_form = Qnil; | |
3953 | |
3954 DEFVAR_LISP ("top-level", &Vtop_level, | |
3955 "Form to evaluate when Emacs starts up.\n\ | |
3956 Useful to set before you dump a modified Emacs."); | |
3957 Vtop_level = Qnil; | |
3958 | |
3959 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table, | |
3960 "String used as translate table for keyboard input, or nil.\n\ | |
3961 Each character is looked up in this string and the contents used instead.\n\ | |
3962 If string is of length N, character codes N and up are untranslated."); | |
3963 Vkeyboard_translate_table = Qnil; | |
3964 | |
3965 DEFVAR_BOOL ("menu-prompting", &menu_prompting, | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3966 "Non-nil means prompt with menus when appropriate.\n\ |
518 | 3967 This is done when reading from a keymap that has a prompt string,\n\ |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3968 for elements that have prompt strings.\n\ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3969 The menu is displayed on the screen\n\ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3970 if X menus were enabled at configuration\n\ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3971 time and the previous event was a mouse click prefix key.\n\ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3972 Otherwise, menu prompting uses the echo area."); |
518 | 3973 menu_prompting = 1; |
3974 | |
3975 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char, | |
3976 "Character to see next line of menu prompt.\n\ | |
3977 Type this character while in a menu prompt to rotate around the lines of it."); | |
3978 XSET (menu_prompt_more_char, Lisp_Int, ' '); | |
3979 } | |
3980 | |
3981 keys_of_keyboard () | |
3982 { | |
3983 initial_define_key (global_map, Ctl ('Z'), "suspend-emacs"); | |
3984 initial_define_key (control_x_map, Ctl ('Z'), "suspend-emacs"); | |
3985 initial_define_key (meta_map, Ctl ('C'), "exit-recursive-edit"); | |
3986 initial_define_key (global_map, Ctl (']'), "abort-recursive-edit"); | |
3987 initial_define_key (meta_map, 'x', "execute-extended-command"); | |
3988 } |