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