Mercurial > emacs
annotate src/keyboard.c @ 1118:a43d53261506
* frame.c (choose_minibuf_frame): abort if the selected frame has
nil in its minibuffer_window slot; this shouldn't happen any more.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sun, 13 Sep 1992 12:29:01 +0000 |
parents | f3a7122a68e1 |
children | 5d315d54b8b4 |
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; | |
765 | 1590 /* Do the redirection specified by the focus_frame |
727 | 1591 member now, before we return this event. */ |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
1592 kbd_fetch_ptr->frame |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
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 |
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1595 #ifdef MULTI_FRAME |
765 | 1596 XSET (Vlast_event_frame, Lisp_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
|
1597 #endif |
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
1598 |
708 | 1599 last_event_timestamp = kbd_fetch_ptr->timestamp; |
518 | 1600 obj = make_lispy_event (kbd_fetch_ptr); |
1601 kbd_fetch_ptr->kind = no_event; | |
1602 kbd_fetch_ptr++; | |
1603 if (XTYPE (obj) == Lisp_Int) | |
1604 XSET (obj, Lisp_Int, XINT (obj) & (meta_key ? 0377 : 0177)); | |
1605 } | |
1606 else if (do_mouse_tracking && mouse_moved) | |
1607 { | |
765 | 1608 FRAME_PTR frame; |
732 | 1609 Lisp_Object x, y; |
1610 unsigned long time; | |
518 | 1611 |
765 | 1612 (*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
|
1613 #ifdef MULTI_FRAME |
765 | 1614 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
|
1615 #endif |
765 | 1616 |
1617 obj = make_lispy_movement (frame, x, y, time); | |
518 | 1618 } |
1619 else | |
1620 /* We were promised by the above while loop that there was | |
1621 something for us to read! */ | |
1622 abort (); | |
1623 | |
1624 input_pending = readable_events (); | |
1625 | |
1626 return (obj); | |
1627 } | |
1628 | |
1629 /* Caches for modify_event_symbol. */ | |
1630 static Lisp_Object func_key_syms; | |
1631 static Lisp_Object mouse_syms; | |
1632 | |
1633 /* You'll notice that this table is arranged to be conveniently | |
1634 indexed by X Windows keysym values. */ | |
1635 static char *lispy_function_keys[] = | |
1636 { | |
1637 /* X Keysym value */ | |
1638 | |
1639 "home", /* 0xff50 */ /* IsCursorKey */ | |
1640 "left", | |
1641 "up", | |
1642 "right", | |
1643 "down", | |
1644 "prior", | |
1645 "next", | |
1646 "end", | |
1647 "begin", | |
1648 0, /* 0xff59 */ | |
1649 0, 0, 0, 0, 0, 0, | |
1650 "select", /* 0xff60 */ /* IsMiscFunctionKey */ | |
1651 "print", | |
1652 "execute", | |
1653 "insert", | |
1654 0, /* 0xff64 */ | |
1655 "undo", | |
1656 "redo", | |
1657 "menu", | |
1658 "find", | |
1659 "cancel", | |
1660 "help", | |
1661 "break", /* 0xff6b */ | |
1662 | |
1663 /* Here are some keys found mostly on HP keyboards. The X event | |
1664 handling code will strip bit 29, which flags vendor-specific | |
1665 keysyms. */ | |
1666 "reset", /* 0x1000ff6c */ | |
1667 "system", | |
1668 "user", | |
1669 "clearline", | |
1670 "insertline", | |
1671 "deleteline", | |
1672 "insertchar", | |
1673 "deletechar", | |
1674 "backtab", | |
1675 "kp_backtab", /* 0x1000ff75 */ | |
1676 0, /* 0xff76 */ | |
1677 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff7f */ | |
1678 "kp-space", /* 0xff80 */ /* IsKeypadKey */ | |
1679 0, 0, 0, 0, 0, 0, 0, 0, | |
1680 "kp-tab", /* 0xff89 */ | |
1681 0, 0, 0, | |
1682 "kp-enter", /* 0xff8d */ | |
1683 0, 0, 0, | |
1684 "kp-f1", /* 0xff91 */ | |
1685 "kp-f2", | |
1686 "kp-f3", | |
1687 "kp-f4", | |
1688 0, /* 0xff95 */ | |
1689 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
1690 "kp-multiply", /* 0xffaa */ | |
1691 "kp-add", | |
1692 "kp-separator", | |
1693 "kp-subtract", | |
1694 "kp-decimal", | |
1695 "kp-divide", /* 0xffaf */ | |
1696 "kp-0", /* 0xffb0 */ | |
1697 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9", | |
1698 0, /* 0xffba */ | |
1699 0, 0, | |
1700 "kp-equal", /* 0xffbd */ | |
1701 "f1", /* 0xffbe */ /* IsFunctionKey */ | |
1702 "f2", "f3", "f4", | |
1703 "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12", | |
1704 "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", | |
1705 "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28", | |
1706 "f29", "f30", "f31", "f32", "f33", "f34", "f35" /* 0xffe0 */ | |
1707 }; | |
1708 | |
1709 static char *lispy_mouse_names[] = | |
1710 { | |
1711 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5" | |
1712 }; | |
1713 | |
1714 /* Given a struct input_event, build the lisp event which represents | |
1715 it. If EVENT is 0, build a mouse movement event from the mouse | |
1716 movement buffer, which should have a movement event in it. */ | |
1717 | |
1718 static Lisp_Object | |
1719 make_lispy_event (event) | |
1720 struct input_event *event; | |
1721 { | |
1722 #ifdef SWITCH_ENUM_BUG | |
1723 switch ((int) event->kind) | |
1724 #else | |
1725 switch (event->kind) | |
1726 #endif | |
1727 { | |
1728 | |
1729 /* A simple keystroke. */ | |
1730 case ascii_keystroke: | |
1731 return event->code; | |
1732 break; | |
1733 | |
1734 /* A function key. The symbol may need to have modifier prefixes | |
1735 tacked onto it. */ | |
1736 case non_ascii_keystroke: | |
1737 return modify_event_symbol (XFASTINT (event->code), event->modifiers, | |
1738 Qfunction_key, | |
1739 lispy_function_keys, &func_key_syms, | |
1740 (sizeof (lispy_function_keys) | |
1741 / sizeof (lispy_function_keys[0]))); | |
1742 break; | |
1743 | |
1744 /* A mouse click - build a list of the relevant information. */ | |
1745 case mouse_click: | |
1746 { | |
1747 int part; | |
1748 Lisp_Object window = | |
765 | 1749 window_from_coordinates (event->frame, |
518 | 1750 XINT (event->x), XINT (event->y), |
1751 &part); | |
1752 Lisp_Object posn; | |
1753 | |
1754 if (XTYPE (window) != Lisp_Window) | |
1755 posn = Qnil; | |
1756 else | |
1757 { | |
1758 XSETINT (event->x, (XINT (event->x) | |
1759 - XINT (XWINDOW (window)->left))); | |
1760 XSETINT (event->y, (XINT (event->y) | |
1761 - XINT (XWINDOW (window)->top))); | |
1762 | |
1763 if (part == 1) | |
1764 posn = Qmode_line; | |
1765 else if (part == 2) | |
732 | 1766 posn = Qvertical_line; |
518 | 1767 else |
1768 XSET (posn, Lisp_Int, | |
1769 buffer_posn_from_coords (XWINDOW (window), | |
1770 XINT (event->x), | |
1771 XINT (event->y))); | |
1772 } | |
1773 | |
1774 return Fcons (modify_event_symbol (XFASTINT (event->code) - 1, | |
1775 event->modifiers, | |
1776 Qmouse_click, | |
1777 lispy_mouse_names, &mouse_syms, | |
1778 (sizeof (lispy_mouse_names) | |
1779 / sizeof (lispy_mouse_names[0]))), | |
1780 Fcons (window, | |
1781 Fcons (posn, | |
1782 Fcons (Fcons (event->x, event->y), | |
708 | 1783 Fcons (make_number |
1784 (event->timestamp), | |
518 | 1785 Qnil))))); |
1786 } | |
1787 | |
1788 /* A scrollbar click. Build a list containing the relevant | |
1789 information. */ | |
1790 case scrollbar_click: | |
1791 { | |
1792 Lisp_Object button | |
1793 = modify_event_symbol (XFASTINT (event->code) - 1, | |
1794 event->modifiers, | |
1795 Qmouse_click, | |
1796 lispy_mouse_names, &mouse_syms, | |
1797 (sizeof (lispy_mouse_names) | |
1798 / sizeof (lispy_mouse_names[0]))); | |
1799 return Fcons (event->part, | |
765 | 1800 Fcons (FRAME_SELECTED_WINDOW (event->frame), |
518 | 1801 Fcons (button, |
1802 Fcons (Fcons (event->x, event->y), | |
708 | 1803 Fcons (make_number |
1804 (event->timestamp), | |
518 | 1805 Qnil))))); |
1806 } | |
1807 | |
1808 /* The 'kind' field of the event is something we don't recognize. */ | |
1809 default: | |
1810 abort(); | |
1811 } | |
1812 } | |
1813 | |
1814 static Lisp_Object | |
765 | 1815 make_lispy_movement (frame, x, y, time) |
1816 FRAME_PTR frame; | |
518 | 1817 Lisp_Object x, y; |
732 | 1818 unsigned long time; |
518 | 1819 { |
1820 Lisp_Object window; | |
1821 int ix, iy; | |
1822 Lisp_Object posn; | |
1823 int part; | |
1824 | |
1825 ix = XINT (x); | |
1826 iy = XINT (y); | |
765 | 1827 window = (frame |
1828 ? window_from_coordinates (frame, ix, iy, &part) | |
518 | 1829 : Qnil); |
1830 if (XTYPE (window) != Lisp_Window) | |
1831 posn = Qnil; | |
1832 else | |
1833 { | |
1834 ix -= XINT (XWINDOW (window)->left); | |
1835 iy -= XINT (XWINDOW (window)->top); | |
1836 if (part == 1) | |
1837 posn = Qmode_line; | |
1838 else if (part == 2) | |
732 | 1839 posn = Qvertical_line; |
518 | 1840 else |
1841 XSET (posn, Lisp_Int, buffer_posn_from_coords (XWINDOW (window), | |
1842 ix, iy)); | |
1843 } | |
1844 | |
1845 XSETINT (x, ix); | |
1846 XSETINT (y, iy); | |
1847 return Fcons (Qmouse_movement, | |
1848 Fcons (window, | |
1849 Fcons (posn, | |
1850 Fcons (Fcons (x, y), | |
732 | 1851 Fcons (make_number (time), Qnil))))); |
518 | 1852 } |
1853 | |
1854 | |
1855 | |
1856 /* Place the written representation of MODIFIERS in BUF, '\0'-terminated, | |
1857 and return its length. */ | |
1858 | |
1859 static int | |
1860 format_modifiers (modifiers, buf) | |
1861 int modifiers; | |
1862 char *buf; | |
1863 { | |
1864 char *p = buf; | |
1865 | |
708 | 1866 if (modifiers & ctrl_modifier) { *p++ = 'C'; *p++ = '-'; } |
518 | 1867 if (modifiers & meta_modifier) { *p++ = 'M'; *p++ = '-'; } |
1868 if (modifiers & shift_modifier) { *p++ = 'S'; *p++ = '-'; } | |
1869 if (modifiers & up_modifier) { *p++ = 'U'; *p++ = '-'; } | |
1870 *p = '\0'; | |
1871 | |
1872 return p - buf; | |
1873 } | |
1874 | |
1875 | |
1876 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc), | |
1877 return a symbol with the modifiers placed in the canonical order. | |
1878 | |
1879 Fdefine_key calls this to make sure that (for example) C-M-foo | |
1880 and M-C-foo end up being equivalent in the keymap. */ | |
1881 | |
1882 Lisp_Object | |
1883 reorder_modifiers (symbol) | |
1884 Lisp_Object symbol; | |
1885 { | |
1886 struct Lisp_String *name; | |
1887 int i; | |
1888 int modifiers; | |
1889 int not_canonical; | |
1890 | |
1891 CHECK_SYMBOL (symbol, 1); | |
1892 | |
1893 modifiers = 0; | |
1894 name = XSYMBOL (symbol)->name; | |
1895 | |
1896 /* Special case for things with only one modifier, which is | |
1897 (hopefully) the vast majority of cases. */ | |
1898 if (! (name->size >= 4 && name->data[1] == '-' && name->data[3] == '-')) | |
1899 return symbol; | |
1900 | |
1901 for (i = 0; i + 1 < name->size && name->data[i + 1] == '-'; i += 2) | |
1902 switch (name->data[i]) | |
1903 { | |
1904 case 'M': | |
1905 not_canonical |= (modifiers & (meta_modifier|ctrl_modifier | |
1906 |shift_modifier|up_modifier)); | |
1907 modifiers |= meta_modifier; | |
1908 break; | |
1909 | |
1910 case 'C': | |
1911 not_canonical |= (modifiers & | |
1912 (ctrl_modifier|shift_modifier|up_modifier)); | |
1913 modifiers |= ctrl_modifier; | |
1914 break; | |
1915 | |
1916 case 'S': | |
1917 not_canonical |= (modifiers & (shift_modifier|up_modifier)); | |
1918 modifiers |= shift_modifier; | |
1919 break; | |
1920 | |
1921 case 'U': | |
1922 not_canonical |= (modifiers & (up_modifier)); | |
1923 modifiers |= up_modifier; | |
1924 break; | |
1925 | |
1926 default: | |
1927 goto no_more_modifiers; | |
1928 } | |
1929 no_more_modifiers: | |
1930 | |
1931 if (!not_canonical) | |
1932 return symbol; | |
1933 | |
1934 /* The modifiers were out of order, so find a new symbol with the | |
1935 mods in order. Since the symbol name could contain nulls, we can't | |
1936 use intern here; we have to use Fintern, which expects a genuine | |
1937 Lisp_String, and keeps a reference to it. */ | |
1938 { | |
1939 char *new_mods = (char *) alloca (sizeof ("C-M-S-U-")); | |
1940 int len = format_modifiers (modifiers, new_mods); | |
1941 Lisp_Object new_name = make_uninit_string (len + name->size - i); | |
1942 | |
1943 bcopy (new_mods, XSTRING (new_name)->data, len); | |
1944 bcopy (name->data + i, XSTRING (new_name)->data + len, name->size - i); | |
1945 | |
1946 return Fintern (new_name, Qnil); | |
1947 } | |
1948 } | |
1949 | |
1950 | |
1951 /* For handling events, we often want to produce a symbol whose name | |
1952 is a series of modifier key prefixes ("M-", "C-", etcetera) attached | |
1953 to some base, like the name of a function key or mouse button. | |
1954 modify_event_symbol produces symbols of this sort. | |
1955 | |
1956 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i] | |
1957 is the name of the i'th symbol. TABLE_SIZE is the number of elements | |
1958 in the table. | |
1959 | |
1960 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will | |
1961 persist between calls to modify_event_symbol that it can use to | |
1962 store a cache of the symbols it's generated for this NAME_TABLE | |
1963 before. | |
1964 | |
1965 SYMBOL_NUM is the number of the base name we want from NAME_TABLE. | |
1966 | |
1967 MODIFIERS is a set of modifier bits (as given in struct input_events) | |
1968 whose prefixes should be applied to the symbol name. | |
1969 | |
1970 SYMBOL_KIND is the value to be placed in the event_kind property of | |
1971 the returned symbol. */ | |
1972 | |
1973 static Lisp_Object | |
1974 modify_event_symbol (symbol_num, modifiers, symbol_kind, name_table, | |
1975 symbol_table, table_size) | |
1976 int symbol_num; | |
1977 unsigned modifiers; | |
1978 Lisp_Object symbol_kind; | |
1979 char **name_table; | |
1980 Lisp_Object *symbol_table; | |
1981 int table_size; | |
1982 { | |
1983 Lisp_Object *slot, *unmodified_slot; | |
1984 | |
1985 /* Is this a request for a valid symbol? */ | |
1986 if (symbol_num < 0 || symbol_num >= table_size | |
1987 || modifiers >= NUM_MODIFIER_COMBOS) | |
1988 abort (); | |
1989 | |
1990 /* If *symbol_table is not a vector of the appropriate size, | |
1991 set it to one. */ | |
1992 if (XTYPE (*symbol_table) != Lisp_Vector | |
1993 || XVECTOR (*symbol_table)->size != table_size) | |
1994 *symbol_table = Fmake_vector (make_number (table_size), Qnil); | |
1995 | |
1996 unmodified_slot = slot = & XVECTOR (*symbol_table)->contents[symbol_num]; | |
1997 | |
1998 /* If there are modifier keys, there had better be a vector in | |
1999 this symbol's position of the symbol_table. */ | |
2000 if (modifiers != 0) | |
2001 { | |
2002 Lisp_Object slot_contents = *slot; | |
2003 | |
2004 /* If there isn't the right sort of vector there, put one in. */ | |
2005 if (XTYPE (slot_contents) != Lisp_Vector | |
2006 || XVECTOR (slot_contents)->size != NUM_MODIFIER_COMBOS) | |
2007 { | |
2008 *slot = Fmake_vector (make_number (NUM_MODIFIER_COMBOS), Qnil); | |
2009 | |
2010 /* Make sure that the vector has an entry for the unmodified | |
2011 symbol, so we can put it on the event_unmodified property. */ | |
2012 if (! NILP (slot_contents)) | |
2013 XVECTOR (*slot)->contents[0] = slot_contents; | |
2014 else | |
2015 XVECTOR (*slot)->contents[0] = intern (name_table [symbol_num]); | |
2016 } | |
2017 } | |
2018 | |
2019 /* If this entry has been filled in with a modified symbol vector, | |
2020 point to the appropriate slot within that. */ | |
2021 if (XTYPE (*slot) == Lisp_Vector) | |
2022 { | |
2023 unmodified_slot = & XVECTOR (*slot)->contents[0]; | |
2024 slot = & XVECTOR (*slot)->contents[modifiers]; | |
2025 } | |
2026 | |
2027 /* Make sure we have an unmodified version of the symbol in its | |
2028 proper place? */ | |
2029 if (NILP (*unmodified_slot)) | |
2030 { | |
2031 *unmodified_slot = intern (name_table [symbol_num]); | |
2032 Fput (*unmodified_slot, Qevent_kind, symbol_kind); | |
2033 Fput (*unmodified_slot, Qevent_unmodified, *unmodified_slot); | |
2034 } | |
2035 | |
2036 /* Have we already created a symbol for this combination of modifiers? */ | |
2037 if (NILP (*slot)) | |
2038 { | |
2039 /* No, let's create one. */ | |
2040 char *modified_name | |
2041 = (char *) alloca (sizeof ("C-M-S-U-") | |
2042 + strlen (name_table [symbol_num])); | |
2043 | |
2044 strcpy (modified_name + format_modifiers (modifiers, modified_name), | |
2045 name_table [symbol_num]); | |
2046 | |
2047 *slot = intern (modified_name); | |
2048 Fput (*slot, Qevent_kind, symbol_kind); | |
2049 Fput (*slot, Qevent_unmodified, *unmodified_slot); | |
2050 } | |
2051 | |
2052 return *slot; | |
2053 } | |
2054 | |
2055 DEFUN ("mouse-click-p", Fmouse_click_p, Smouse_click_p, 1, 1, 0, | |
2056 "Return non-nil iff OBJECT is a representation of a mouse event.\n\ | |
2057 A mouse event is a list of five elements whose car is a symbol of the\n\ | |
2058 form <MODIFIERS>mouse-<DIGIT>. I hope this is a temporary hack.") | |
2059 (object) | |
2060 Lisp_Object object; | |
2061 { | |
2062 if (EVENT_HAS_PARAMETERS (object) | |
2063 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (object)), | |
2064 Qmouse_click)) | |
2065 return Qt; | |
2066 else | |
2067 return Qnil; | |
2068 } | |
2069 | |
2070 /* Store into *addr a value nonzero if terminal input chars are available. | |
2071 Serves the purpose of ioctl (0, FIONREAD, addr) | |
2072 but works even if FIONREAD does not exist. | |
2073 (In fact, this may actually read some input.) */ | |
2074 | |
2075 static void | |
2076 get_input_pending (addr) | |
2077 int *addr; | |
2078 { | |
2079 /* First of all, have we already counted some input? */ | |
2080 *addr = !NILP (Vquit_flag) || readable_events (); | |
2081 | |
2082 /* If input is being read as it arrives, and we have none, there is none. */ | |
2083 if (*addr > 0 || (interrupt_input && ! interrupts_deferred)) | |
2084 return; | |
2085 | |
2086 /* Try to read some input and see how much we get. */ | |
2087 gobble_input (0); | |
2088 *addr = !NILP (Vquit_flag) || readable_events (); | |
2089 } | |
2090 | |
2091 /* Interface to read_avail_input, blocking SIGIO if necessary. */ | |
2092 | |
2093 int | |
2094 gobble_input (expected) | |
2095 int expected; | |
2096 { | |
2097 #ifndef VMS | |
2098 #ifdef SIGIO | |
2099 if (interrupt_input) | |
2100 { | |
624 | 2101 SIGMASKTYPE mask; |
638 | 2102 mask = sigblockx (SIGIO); |
518 | 2103 read_avail_input (expected); |
638 | 2104 sigsetmask (mask); |
518 | 2105 } |
2106 else | |
2107 #endif | |
2108 read_avail_input (expected); | |
2109 #endif | |
2110 } | |
2111 | |
2112 #ifndef VMS | |
2113 | |
2114 /* Read any terminal input already buffered up by the system | |
2115 into the kbd_buffer, but do not wait. | |
2116 | |
2117 EXPECTED should be nonzero if the caller knows there is some input. | |
2118 | |
2119 Except on VMS, all input is read by this function. | |
2120 If interrupt_input is nonzero, this function MUST be called | |
2121 only when SIGIO is blocked. | |
2122 | |
2123 Returns the number of keyboard chars read, or -1 meaning | |
2124 this is a bad time to try to read input. */ | |
2125 | |
2126 static int | |
2127 read_avail_input (expected) | |
2128 int expected; | |
2129 { | |
2130 struct input_event buf[KBD_BUFFER_SIZE]; | |
2131 register int i; | |
2132 int nread; | |
2133 | |
2134 if (read_socket_hook) | |
2135 /* No need for FIONREAD or fcntl; just say don't wait. */ | |
2136 nread = (*read_socket_hook) (0, buf, KBD_BUFFER_SIZE, expected, expected); | |
2137 else | |
2138 { | |
2139 unsigned char cbuf[KBD_BUFFER_SIZE]; | |
2140 | |
2141 #ifdef FIONREAD | |
2142 /* Find out how much input is available. */ | |
2143 if (ioctl (0, FIONREAD, &nread) < 0) | |
2144 /* Formerly simply reported no input, but that sometimes led to | |
2145 a failure of Emacs to terminate. | |
2146 SIGHUP seems appropriate if we can't reach the terminal. */ | |
2147 kill (getpid (), SIGHUP); | |
2148 if (nread == 0) | |
2149 return 0; | |
2150 if (nread > sizeof cbuf) | |
2151 nread = sizeof cbuf; | |
2152 #else /* no FIONREAD */ | |
2153 #ifdef USG | |
2154 /* Read some input if available, but don't wait. */ | |
2155 nread = sizeof cbuf; | |
2156 fcntl (fileno (stdin), F_SETFL, O_NDELAY); | |
2157 #else | |
2158 you lose; | |
2159 #endif | |
2160 #endif | |
2161 | |
2162 /* Now read; for one reason or another, this will not block. */ | |
2163 while (1) | |
2164 { | |
2165 nread = read (fileno (stdin), cbuf, nread); | |
2166 #ifdef AIX | |
2167 /* The kernel sometimes fails to deliver SIGHUP for ptys. | |
2168 This looks incorrect, but it isn't, because _BSD causes | |
2169 O_NDELAY to be defined in fcntl.h as O_NONBLOCK, | |
2170 and that causes a value other than 0 when there is no input. */ | |
2171 if (nread == 0) | |
2172 kill (SIGHUP, 0); | |
2173 #endif | |
2174 /* Retry the read if it is interrupted. */ | |
2175 if (nread >= 0 | |
2176 || ! (errno == EAGAIN || errno == EFAULT | |
2177 #ifdef EBADSLT | |
2178 || errno == EBADSLT | |
2179 #endif | |
2180 )) | |
2181 break; | |
2182 } | |
2183 | |
2184 #ifndef FIONREAD | |
2185 #ifdef USG | |
2186 fcntl (fileno (stdin), F_SETFL, 0); | |
2187 #endif /* USG */ | |
2188 #endif /* no FIONREAD */ | |
2189 for (i = 0; i < nread; i++) | |
2190 { | |
2191 buf[i].kind = ascii_keystroke; | |
2192 XSET (buf[i].code, Lisp_Int, cbuf[i]); | |
765 | 2193 buf[i].frame = selected_frame; |
518 | 2194 } |
2195 } | |
2196 | |
2197 /* Scan the chars for C-g and store them in kbd_buffer. */ | |
2198 for (i = 0; i < nread; i++) | |
2199 { | |
2200 kbd_buffer_store_event (&buf[i]); | |
2201 /* Don't look at input that follows a C-g too closely. | |
2202 This reduces lossage due to autorepeat on C-g. */ | |
2203 if (buf[i].kind == ascii_keystroke | |
2204 && XINT(buf[i].code) == quit_char) | |
2205 break; | |
2206 } | |
2207 | |
2208 return nread; | |
2209 } | |
2210 #endif /* not VMS */ | |
2211 | |
2212 #ifdef SIGIO /* for entire page */ | |
2213 /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
2214 | |
2215 input_available_signal (signo) | |
2216 int signo; | |
2217 { | |
2218 /* Must preserve main program's value of errno. */ | |
2219 int old_errno = errno; | |
2220 #ifdef BSD4_1 | |
2221 extern int select_alarmed; | |
2222 #endif | |
2223 | |
2224 #ifdef USG | |
2225 /* USG systems forget handlers when they are used; | |
2226 must reestablish each time */ | |
2227 signal (signo, input_available_signal); | |
2228 #endif /* USG */ | |
2229 | |
2230 #ifdef BSD4_1 | |
2231 sigisheld (SIGIO); | |
2232 #endif | |
2233 | |
648 | 2234 if (input_available_clear_time) |
2235 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); | |
518 | 2236 |
2237 while (1) | |
2238 { | |
2239 int nread; | |
2240 nread = read_avail_input (1); | |
2241 /* -1 means it's not ok to read the input now. | |
2242 UNBLOCK_INPUT will read it later; now, avoid infinite loop. | |
2243 0 means there was no keyboard input available. */ | |
2244 if (nread <= 0) | |
2245 break; | |
2246 | |
2247 #ifdef BSD4_1 | |
2248 select_alarmed = 1; /* Force the select emulator back to life */ | |
2249 #endif | |
2250 } | |
2251 | |
2252 #ifdef BSD4_1 | |
2253 sigfree (); | |
2254 #endif | |
2255 errno = old_errno; | |
2256 } | |
2257 #endif /* SIGIO */ | |
2258 | |
2259 /* Return the prompt-string of a sparse keymap. | |
2260 This is the first element which is a string. | |
2261 Return nil if there is none. */ | |
2262 | |
2263 Lisp_Object | |
2264 map_prompt (map) | |
2265 Lisp_Object map; | |
2266 { | |
2267 while (CONSP (map)) | |
2268 { | |
2269 register Lisp_Object tem; | |
2270 tem = Fcar (map); | |
2271 if (XTYPE (tem) == Lisp_String) | |
2272 return tem; | |
2273 map = Fcdr (map); | |
2274 } | |
2275 return Qnil; | |
2276 } | |
2277 | |
2278 static int echo_flag; | |
2279 static int echo_now; | |
2280 | |
2281 /* 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
|
2282 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
|
2283 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2284 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
|
2285 the first event of a key sequence. |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2286 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2287 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
|
2288 Otherwise we store 0 there. |
518 | 2289 |
2290 The prompting is done based on the prompt-string of the map | |
2291 and the strings associated with various map elements. */ | |
2292 | |
2293 Lisp_Object | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2294 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
|
2295 int nmaps; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2296 Lisp_Object *maps; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2297 Lisp_Object prev_event; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2298 int *used_mouse_menu; |
518 | 2299 { |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2300 int mapno; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2301 register Lisp_Object name; |
518 | 2302 int nlength; |
765 | 2303 int width = FRAME_WIDTH (selected_frame) - 4; |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2304 char *menu = (char *) alloca (width + 4); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2305 int idx = -1; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2306 Lisp_Object rest, vector; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2307 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2308 *used_mouse_menu = 0; |
518 | 2309 |
2310 /* Use local over global Menu maps */ | |
2311 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2312 if (! menu_prompting) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2313 return Qnil; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2314 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2315 /* 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
|
2316 for (mapno = 0; mapno < nmaps; mapno++) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2317 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2318 name = map_prompt (maps[mapno]); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2319 if (!NILP (name)) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2320 break; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2321 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2322 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2323 /* If we don't have any menus, just read a character normally. */ |
518 | 2324 if (NILP (name)) |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2325 return Qnil; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2326 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2327 #ifdef HAVE_X_MENU |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2328 /* 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
|
2329 use a real menu for mouse selection. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2330 if (XTYPE (prev_event) == Lisp_Cons) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2331 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2332 /* Display the menu and get the selection. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2333 Lisp_Object *realmaps |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2334 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2335 Lisp_Object value; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2336 int nmaps1 = 0; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2337 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2338 /* Use the maps that are not nil. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2339 for (mapno = 0; mapno < nmaps; mapno++) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2340 if (!NILP (maps[mapno])) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2341 realmaps[nmaps1++] = maps[mapno]; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2342 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2343 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
|
2344 if (NILP (value)) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2345 XSET (value, Lisp_Int, quit_char); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2346 *used_mouse_menu = 1; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2347 return value; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2348 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2349 #endif /* HAVE_X_MENU */ |
518 | 2350 |
2351 /* Prompt string always starts with map's prompt, and a space. */ | |
2352 strcpy (menu, XSTRING (name)->data); | |
2353 nlength = XSTRING (name)->size; | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2354 menu[nlength++] = ':'; |
518 | 2355 menu[nlength++] = ' '; |
2356 menu[nlength] = 0; | |
2357 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2358 /* Start prompting at start of first map. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2359 mapno = 0; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2360 rest = maps[mapno]; |
518 | 2361 |
2362 /* Present the documented bindings, a line at a time. */ | |
2363 while (1) | |
2364 { | |
2365 int notfirst = 0; | |
2366 int i = nlength; | |
2367 Lisp_Object obj; | |
2368 int ch; | |
2369 | |
2370 /* Loop over elements of map. */ | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2371 while (i < width) |
518 | 2372 { |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2373 Lisp_Object s, elt; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2374 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2375 /* 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
|
2376 if (NILP (rest)) |
518 | 2377 { |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2378 mapno++; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2379 /* 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
|
2380 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
|
2381 if (mapno == nmaps) |
518 | 2382 { |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2383 if (notfirst) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2384 break; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2385 else |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2386 mapno = 0; |
518 | 2387 } |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2388 rest = maps[mapno]; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2389 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2390 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2391 /* Look at the next element of the map. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2392 if (idx >= 0) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2393 elt = XVECTOR (vector)->contents[idx]; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2394 else |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2395 elt = Fcar_safe (rest); |
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 (idx < 0 && XTYPE (elt) == Lisp_Vector) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2398 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2399 /* 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
|
2400 advanced past it, but start scanning its contents. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2401 rest = Fcdr_safe (rest); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2402 vector = elt; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2403 idx = 0; |
518 | 2404 } |
2405 else | |
2406 { | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2407 /* An ordinary element. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2408 s = Fcar_safe (Fcdr_safe (elt)); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2409 if (XTYPE (s) != Lisp_String) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2410 /* 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
|
2411 ; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2412 /* 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
|
2413 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
|
2414 else if (XSTRING (s)->size + i < width |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2415 || !notfirst) |
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 int thiswidth; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2418 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2419 /* Punctuate between strings. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2420 if (notfirst) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2421 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2422 strcpy (menu + i, ", "); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2423 i += 2; |
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 notfirst = 1; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2426 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2427 /* Add as much of string as fits. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2428 thiswidth = XSTRING (s)->size; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2429 if (thiswidth + i > width) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2430 thiswidth = width - i; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2431 bcopy (XSTRING (s)->data, menu + i, thiswidth); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2432 i += thiswidth; |
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 else |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2435 { |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2436 /* 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
|
2437 and save the element for the next line. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2438 strcpy (menu + i, "..."); |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2439 break; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2440 } |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2441 |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2442 /* Move past this element. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2443 if (idx >= 0 && idx + 1 >= XVECTOR (rest)->size) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2444 /* Handle reaching end of dense table. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2445 idx = -1; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2446 if (idx >= 0) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2447 idx++; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2448 else |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2449 rest = Fcdr_safe (rest); |
518 | 2450 } |
2451 } | |
2452 | |
2453 /* Prompt with that and read response. */ | |
2454 message1 (menu); | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2455 obj = read_char (1, 0, 0, Qnil, 0); |
518 | 2456 |
2457 if (XTYPE (obj) != Lisp_Int) | |
2458 return obj; | |
2459 else | |
2460 ch = XINT (obj); | |
2461 | |
2462 if (obj != menu_prompt_more_char | |
2463 && (XTYPE (menu_prompt_more_char) != Lisp_Int | |
2464 || obj != make_number (Ctl (XINT (menu_prompt_more_char))))) | |
2465 return obj; | |
2466 } | |
2467 } | |
2468 | |
2469 /* Reading key sequences. */ | |
2470 | |
2471 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings | |
2472 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a | |
2473 keymap, or nil otherwise. Return the index of the first keymap in | |
2474 which KEY has any binding, or NMAPS if no map has a binding. | |
2475 | |
2476 If KEY is a meta ASCII character, treat it like meta-prefix-char | |
2477 followed by the corresponding non-meta character. Keymaps in | |
2478 CURRENT with non-prefix bindings for meta-prefix-char become nil in | |
2479 NEXT. | |
2480 | |
2481 When KEY is not defined in any of the keymaps, if it is an upper | |
2482 case letter and there are bindings for the corresponding lower-case | |
2483 letter, return the bindings for the lower-case letter. | |
2484 | |
2485 NEXT may == CURRENT. */ | |
2486 | |
2487 static int | |
2488 follow_key (key, nmaps, current, defs, next) | |
2489 Lisp_Object key; | |
2490 Lisp_Object *current, *defs, *next; | |
2491 int nmaps; | |
2492 { | |
2493 int i, first_binding; | |
2494 | |
2495 /* If KEY is a meta ASCII character, treat it like meta-prefix-char | |
2496 followed by the corresponding non-meta character. */ | |
2497 if (XTYPE (key) == Lisp_Int | |
2498 && XINT (key) >= 0200) | |
2499 { | |
2500 for (i = 0; i < nmaps; i++) | |
2501 if (! NILP (current[i])) | |
2502 { | |
2503 next[i] = get_keyelt (access_keymap (current[i], | |
2504 meta_prefix_char)); | |
2505 | |
2506 /* Note that since we pass the resulting bindings through | |
2507 get_keymap_1, non-prefix bindings for meta-prefix-char | |
2508 disappear. */ | |
2509 next[i] = get_keymap_1 (next[i], 0); | |
2510 } | |
2511 else | |
2512 next[i] = Qnil; | |
2513 | |
2514 current = next; | |
2515 XSET (key, Lisp_Int, XFASTINT (key) & 0177); | |
2516 } | |
2517 | |
2518 first_binding = nmaps; | |
2519 for (i = nmaps - 1; i >= 0; i--) | |
2520 { | |
2521 if (! NILP (current[i])) | |
2522 { | |
2523 defs[i] = get_keyelt (access_keymap (current[i], key)); | |
2524 if (! NILP (defs[i])) | |
2525 first_binding = i; | |
2526 } | |
2527 else | |
2528 defs[i] = Qnil; | |
2529 } | |
2530 | |
2531 /* When KEY is not defined in any of the keymaps, if it is an upper | |
2532 case letter and there are bindings for the corresponding | |
2533 lower-case letter, return the bindings for the lower-case letter. */ | |
2534 if (first_binding == nmaps | |
2535 && XTYPE (key) == Lisp_Int | |
2536 && UPPERCASEP (XINT (key))) | |
2537 { | |
2538 XSETINT (key, DOWNCASE (XINT (key))); | |
2539 | |
2540 first_binding = nmaps; | |
2541 for (i = nmaps - 1; i >= 0; i--) | |
2542 { | |
2543 if (! NILP (current[i])) | |
2544 { | |
2545 defs[i] = get_keyelt (access_keymap (current[i], key)); | |
2546 if (! NILP (defs[i])) | |
2547 first_binding = i; | |
2548 } | |
2549 else | |
2550 defs[i] = Qnil; | |
2551 } | |
2552 } | |
2553 | |
2554 /* Given the set of bindings we've found, produce the next set of maps. */ | |
2555 for (i = 0; i < nmaps; i++) | |
2556 next[i] = NILP (defs[i]) ? Qnil : get_keymap_1 (defs[i], 0); | |
2557 | |
2558 return first_binding; | |
2559 } | |
2560 | |
2561 /* Read a sequence of keys that ends with a non prefix character | |
2562 according to the keymaps in KEYMAPS[0..nmaps-1]. Keymaps appearing | |
2563 earlier in KEYMAPS take precidence over those appearing later. | |
2564 | |
2565 Store the sequence in KEYBUF, a buffer of size BUFSIZE. Prompt | |
2566 with PROMPT. Echo starting immediately unless `prompt' is 0. | |
2567 Return the length of the key sequence stored. | |
2568 | |
765 | 2569 If the user switches frames in the midst of a key sequence, we |
518 | 2570 throw away any prefix we have read so far, and start afresh. For |
2571 mouse clicks, we look up the click in the keymap of the buffer | |
2572 clicked on, throwing away any prefix if it is not the same buffer | |
2573 we used to be reading from. */ | |
2574 | |
2575 static int | |
2576 read_key_sequence (keybuf, bufsize, prompt) | |
2577 Lisp_Object *keybuf; | |
2578 int bufsize; | |
2579 Lisp_Object prompt; | |
2580 { | |
2581 /* How many keys there are in the current key sequence. */ | |
2582 int t; | |
2583 | |
2584 /* The buffer that the most recently read event was typed at. This | |
2585 helps us read mouse clicks according to the buffer clicked in, | |
765 | 2586 and notice when the mouse has moved from one frame to another. */ |
518 | 2587 struct buffer *last_event_buffer = current_buffer; |
2588 | |
2589 /* The length of the echo buffer when we started reading, and | |
2590 the length of this_command_keys when we started reading. */ | |
2591 int echo_start; | |
2592 int keys_start = this_command_key_count; | |
2593 | |
2594 /* The number of keymaps we're scanning right now, and the number of | |
2595 keymaps we have allocated space for. */ | |
2596 int nmaps; | |
2597 int nmaps_allocated = 0; | |
2598 | |
899 | 2599 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1] |
518 | 2600 in the current keymaps, or nil where it is not a prefix. */ |
899 | 2601 Lisp_Object *submaps; |
518 | 2602 |
2603 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in | |
2604 the current keymaps. */ | |
2605 Lisp_Object *defs; | |
2606 | |
899 | 2607 /* The index of the first keymap that has a binding for this key |
2608 sequence. In other words, the lowest i such that defs[i] is | |
2609 non-nil.*/ | |
518 | 2610 int first_binding; |
2611 | |
2612 /* If mock_input > t, then KEYBUF[t] should be read as the next | |
899 | 2613 input key. |
2614 | |
2615 We use this to recover after recognizing a function key. Once we | |
2616 realize that a suffix of the current key sequence is actually a | |
2617 function key's escape sequence, we replace the suffix with the | |
2618 function key's binding from Vfunction_key_map. Now keybuf | |
2619 contains a new and different key sequence, so the echo area and | |
2620 the submaps and defs arrays are wrong. In this situation, we set | |
2621 mock_input to t, set t to 0, and jump to restart; the loop will | |
2622 read keys from keybuf up until mock_input, which rebuilds the | |
2623 state, and then it will resume reading characters from the keyboard. */ | |
518 | 2624 int mock_input = 0; |
2625 | |
899 | 2626 /* If the sequence is unbound in submaps[], then |
2627 keymap[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map, | |
2628 and fkey_map is its binding. If mock_input is in use, these | |
2629 might be > t, indicating that all function key scanning should | |
518 | 2630 hold off until t reaches them. */ |
899 | 2631 |
518 | 2632 int fkey_start = 0, fkey_end = 0; |
2633 Lisp_Object fkey_map = Vfunction_key_map; | |
2634 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2635 last_nonmenu_event = Qnil; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2636 |
518 | 2637 if (INTERACTIVE) |
2638 { | |
2639 if (prompt) | |
2640 echo_prompt (prompt); | |
2641 else if (cursor_in_echo_area) | |
2642 /* This doesn't put in a dash if the echo buffer is empty, so | |
2643 you don't always see a dash hanging out in the minibuffer. */ | |
2644 echo_dash (); | |
2645 echo_start = echo_length (); | |
2646 } | |
2647 | |
899 | 2648 /* If there is no function key map, turn off function key scanning. */ |
518 | 2649 if (NILP (Fkeymapp (Vfunction_key_map))) |
2650 fkey_start = fkey_end = bufsize + 1; | |
2651 | |
2652 restart: | |
2653 t = 0; | |
2654 this_command_key_count = keys_start; | |
2655 | |
2656 { | |
2657 Lisp_Object *maps; | |
2658 | |
2659 nmaps = current_minor_maps (0, &maps) + 2; | |
2660 if (nmaps > nmaps_allocated) | |
2661 { | |
899 | 2662 submaps = (Lisp_Object *) alloca (nmaps * sizeof (submaps[0])); |
518 | 2663 defs = (Lisp_Object *) alloca (nmaps * sizeof (defs[0])); |
2664 nmaps_allocated = nmaps; | |
2665 } | |
899 | 2666 bcopy (maps, submaps, (nmaps - 2) * sizeof (submaps[0])); |
2667 submaps[nmaps-2] = last_event_buffer->keymap; | |
2668 submaps[nmaps-1] = global_map; | |
518 | 2669 } |
2670 | |
2671 /* Find an accurate initial value for first_binding. */ | |
2672 for (first_binding = 0; first_binding < nmaps; first_binding++) | |
899 | 2673 if (! NILP (submaps[first_binding])) |
518 | 2674 break; |
2675 | |
899 | 2676 while ((first_binding < nmaps && ! NILP (submaps[first_binding])) |
518 | 2677 || (first_binding >= nmaps && fkey_start < t)) |
2678 { | |
2679 Lisp_Object key; | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2680 int used_mouse_menu = 0; |
518 | 2681 |
2682 if (t >= bufsize) | |
2683 error ("key sequence too long"); | |
2684 | |
899 | 2685 /* Are we re-reading a key sequence, as indicated by mock_input? */ |
518 | 2686 if (t < mock_input) |
2687 { | |
2688 key = keybuf[t]; | |
2689 add_command_key (key); | |
2690 echo_char (key); | |
2691 } | |
899 | 2692 |
2693 /* If not, we should actually read a character. */ | |
518 | 2694 else |
2695 { | |
2696 struct buffer *buf; | |
2697 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2698 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
|
2699 &used_mouse_menu); |
518 | 2700 |
2701 /* The above routines return -1 at the end of a macro. | |
2702 Emacs 18 handles this by returning immediately with a | |
2703 zero, so that's what we'll do. */ | |
2704 if (XTYPE (key) == Lisp_Int && XINT (key) < 0) | |
2705 return 0; | |
2706 | |
2707 Vquit_flag = Qnil; | |
2708 | |
765 | 2709 #ifdef MULTI_FRAME |
518 | 2710 /* 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
|
2711 if (used_mouse_menu) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2712 /* 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
|
2713 buf = last_event_buffer; |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2714 else if (XTYPE (key) == Lisp_Int || XTYPE (key) == Lisp_Symbol) |
518 | 2715 buf = (XBUFFER |
2716 (XWINDOW | |
765 | 2717 (FRAME_SELECTED_WINDOW |
2718 (XFRAME (Vlast_event_frame)))->buffer)); | |
518 | 2719 else if (EVENT_HAS_PARAMETERS (key)) |
2720 { | |
2721 Lisp_Object window = EVENT_WINDOW (key); | |
2722 | |
2723 if (NILP (window)) | |
2724 abort (); | |
2725 | |
2726 buf = XBUFFER (XWINDOW (window)->buffer); | |
2727 } | |
2728 else | |
2729 abort (); | |
2730 | |
2731 /* If this event came to a different buffer than the one | |
2732 we're currently in, switch buffers and start a new key | |
2733 sequence, starting with key. */ | |
2734 if (buf != last_event_buffer) | |
2735 { | |
2736 last_event_buffer = buf; | |
765 | 2737 Fselect_frame (Vlast_event_frame, Qnil); |
518 | 2738 |
2739 /* Arrange to read key as the next event. */ | |
2740 keybuf[0] = key; | |
2741 mock_input = 1; | |
2742 | |
2743 /* Truncate the key sequence in the echo area. */ | |
2744 if (INTERACTIVE) | |
2745 echo_truncate (echo_start); | |
2746 | |
2747 goto restart; | |
2748 } | |
732 | 2749 #endif |
518 | 2750 } |
2751 | |
2752 first_binding = (follow_key (key, | |
2753 nmaps - first_binding, | |
899 | 2754 submaps + first_binding, |
518 | 2755 defs + first_binding, |
899 | 2756 submaps + first_binding) |
518 | 2757 + first_binding); |
2758 keybuf[t++] = key; | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2759 /* 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
|
2760 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
|
2761 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
|
2762 event that preceded the first level of menu. */ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2763 if (!used_mouse_menu) |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
2764 last_nonmenu_event = key; |
518 | 2765 |
2766 /* If the sequence is unbound, see if we can hang a function key | |
899 | 2767 off the end of it. We only want to scan real keyboard input |
2768 for function key sequences, so if mock_input says that we're | |
2769 re-scanning after expanding a function key, don't examine it. */ | |
518 | 2770 if (first_binding >= nmaps |
899 | 2771 && t >= mock_input) |
518 | 2772 { |
2773 Lisp_Object fkey_next; | |
2774 | |
2775 /* Scan from fkey_end until we find a bound suffix. */ | |
2776 while (fkey_end < t) | |
2777 { | |
853 | 2778 /* Look up meta-characters by prefixing them |
2779 with meta_prefix_char. I hate this. */ | |
899 | 2780 if (keybuf[fkey_end] & 0x80) |
853 | 2781 fkey_next = |
2782 get_keymap_1 (get_keyelt | |
2783 (access_keymap (fkey_map, meta_prefix_char)), | |
2784 0); | |
2785 else | |
2786 fkey_next = fkey_map; | |
2787 | |
518 | 2788 fkey_next = |
853 | 2789 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
|
2790 (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
|
2791 |
c4dcdc9aed70
Clear the eighth bit of the character from the key sequence, NOT the
Jim Blandy <jimb@redhat.com>
parents:
899
diff
changeset
|
2792 /* If keybuf[fkey_start..fkey_end] is bound in the |
547 | 2793 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
|
2794 sequence (i.e. fkey_end == t), replace it with |
547 | 2795 the binding and restart with fkey_start at the end. */ |
518 | 2796 if (XTYPE (fkey_next) == Lisp_Vector |
2797 && fkey_end == t) | |
2798 { | |
2799 t = fkey_start + XVECTOR (fkey_next)->size; | |
2800 if (t >= bufsize) | |
2801 error ("key sequence too long"); | |
2802 | |
2803 bcopy (XVECTOR (fkey_next)->contents, | |
2804 keybuf + fkey_start, | |
2805 (t - fkey_start) * sizeof (keybuf[0])); | |
2806 | |
2807 mock_input = t; | |
2808 fkey_start = fkey_end = t; | |
2809 | |
2810 /* Truncate the key sequence in the echo area. */ | |
2811 if (INTERACTIVE) | |
2812 echo_truncate (echo_start); | |
2813 | |
2814 goto restart; | |
2815 } | |
2816 | |
2817 fkey_map = get_keymap_1 (fkey_next, 0); | |
2818 | |
547 | 2819 /* If we no longer have a bound suffix, try a new positions for |
2820 fkey_start. */ | |
518 | 2821 if (NILP (fkey_map)) |
2822 { | |
2823 fkey_end = ++fkey_start; | |
2824 fkey_map = Vfunction_key_map; | |
2825 } | |
2826 } | |
2827 } | |
2828 } | |
2829 | |
2830 read_key_sequence_cmd = (first_binding < nmaps | |
2831 ? defs[first_binding] | |
2832 : Qnil); | |
2833 | |
2834 return t; | |
2835 } | |
2836 | |
691
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
2837 DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 2, 0, |
518 | 2838 "Read a sequence of keystrokes and return as a string or vector.\n\ |
2839 The sequence is sufficient to specify a non-prefix command in the\n\ | |
2840 current local and global maps.\n\ | |
2841 \n\ | |
691
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
2842 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
|
2843 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
|
2844 as a continuation of the previous key.\n\ |
518 | 2845 \n\ |
765 | 2846 If Emacs is running on multiple frames, switching between frames in\n\ |
518 | 2847 the midst of a keystroke will toss any prefix typed so far. A C-g\n\ |
2848 typed while in this function is treated like any other character, and\n\ | |
2849 `quit-flag' is not set.") | |
691
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
2850 (prompt, continue_echo) |
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
2851 Lisp_Object prompt, continue_echo; |
518 | 2852 { |
2853 Lisp_Object keybuf[30]; | |
2854 register int i; | |
2855 struct gcpro gcpro1, gcpro2; | |
2856 | |
2857 if (!NILP (prompt)) | |
2858 CHECK_STRING (prompt, 0); | |
2859 QUIT; | |
2860 | |
2861 bzero (keybuf, sizeof keybuf); | |
2862 GCPRO1 (keybuf[0]); | |
2863 gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); | |
2864 | |
727 | 2865 if (NILP (continue_echo)) |
691
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
2866 this_command_key_count = 0; |
cae8c3ef1677
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
2867 |
518 | 2868 i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])), |
2869 NILP (prompt) ? 0 : XSTRING (prompt)->data); | |
2870 | |
2871 UNGCPRO; | |
2872 return make_array (i, keybuf); | |
2873 } | |
2874 | |
2875 DEFUN ("command-execute", Fcommand_execute, Scommand_execute, 1, 2, 0, | |
2876 "Execute CMD as an editor command.\n\ | |
2877 CMD must be a symbol that satisfies the `commandp' predicate.\n\ | |
2878 Optional second arg RECORD-FLAG non-nil\n\ | |
2879 means unconditionally put this command in `command-history'.\n\ | |
2880 Otherwise, that is done only if an arg is read using the minibuffer.") | |
2881 (cmd, record) | |
2882 Lisp_Object cmd, record; | |
2883 { | |
2884 register Lisp_Object final; | |
2885 register Lisp_Object tem; | |
2886 Lisp_Object prefixarg; | |
2887 struct backtrace backtrace; | |
2888 extern int debug_on_next_call; | |
2889 | |
2890 prefixarg = Vprefix_arg, Vprefix_arg = Qnil; | |
2891 Vcurrent_prefix_arg = prefixarg; | |
2892 debug_on_next_call = 0; | |
2893 | |
2894 if (XTYPE (cmd) == Lisp_Symbol) | |
2895 { | |
2896 tem = Fget (cmd, Qdisabled); | |
2897 if (!NILP (tem)) | |
2898 return call1 (Vrun_hooks, Vdisabled_command_hook); | |
2899 } | |
2900 | |
2901 while (1) | |
2902 { | |
648 | 2903 final = Findirect_function (cmd); |
518 | 2904 |
2905 if (CONSP (final) && (tem = Fcar (final), EQ (tem, Qautoload))) | |
2906 do_autoload (final, cmd); | |
2907 else | |
2908 break; | |
2909 } | |
2910 | |
2911 if (XTYPE (final) == Lisp_String | |
2912 || XTYPE (final) == Lisp_Vector) | |
2913 { | |
2914 /* If requested, place the macro in the command history. For | |
2915 other sorts of commands, call-interactively takes care of | |
2916 this. */ | |
2917 if (!NILP (record)) | |
2918 Vcommand_history | |
2919 = Fcons (Fcons (Qexecute_kbd_macro, | |
2920 Fcons (final, Fcons (prefixarg, Qnil))), | |
2921 Vcommand_history); | |
2922 | |
2923 return Fexecute_kbd_macro (final, prefixarg); | |
2924 } | |
2925 if (CONSP (final) || XTYPE (final) == Lisp_Subr | |
2926 || XTYPE (final) == Lisp_Compiled) | |
2927 { | |
2928 backtrace.next = backtrace_list; | |
2929 backtrace_list = &backtrace; | |
2930 backtrace.function = &Qcall_interactively; | |
2931 backtrace.args = &cmd; | |
2932 backtrace.nargs = 1; | |
2933 backtrace.evalargs = 0; | |
2934 | |
2935 tem = Fcall_interactively (cmd, record); | |
2936 | |
2937 backtrace_list = backtrace.next; | |
2938 return tem; | |
2939 } | |
2940 return Qnil; | |
2941 } | |
2942 | |
2943 DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_command, | |
2944 1, 1, "P", | |
2945 "Read function name, then read its arguments and call it.") | |
2946 (prefixarg) | |
2947 Lisp_Object prefixarg; | |
2948 { | |
2949 Lisp_Object function; | |
2950 char buf[40]; | |
2951 Lisp_Object saved_keys; | |
2952 struct gcpro gcpro1; | |
2953 | |
2954 saved_keys = Fthis_command_keys (); | |
2955 buf[0] = 0; | |
2956 GCPRO1 (saved_keys); | |
2957 | |
2958 if (EQ (prefixarg, Qminus)) | |
2959 strcpy (buf, "- "); | |
2960 else if (CONSP (prefixarg) && XINT (XCONS (prefixarg)->car) == 4) | |
2961 strcpy (buf, "C-u "); | |
2962 else if (CONSP (prefixarg) && XTYPE (XCONS (prefixarg)->car) == Lisp_Int) | |
2963 sprintf (buf, "%d ", XINT (XCONS (prefixarg)->car)); | |
2964 else if (XTYPE (prefixarg) == Lisp_Int) | |
2965 sprintf (buf, "%d ", XINT (prefixarg)); | |
2966 | |
2967 /* This isn't strictly correct if execute-extended-command | |
2968 is bound to anything else. Perhaps it should use | |
2969 this_command_keys? */ | |
2970 strcat (buf, "M-x "); | |
2971 | |
2972 /* Prompt with buf, and then read a string, completing from and | |
2973 restricting to the set of all defined commands. Don't provide | |
2974 any initial input. The last Qnil says not to perform a | |
2975 peculiar hack on the initial input. */ | |
2976 function = Fcompleting_read (build_string (buf), | |
2977 Vobarray, Qcommandp, | |
2978 Qt, Qnil, Qnil); | |
2979 | |
708 | 2980 /* Set this_command_keys to the concatenation of saved_keys and |
2981 function, followed by a RET. */ | |
518 | 2982 { |
708 | 2983 struct Lisp_String *str; |
518 | 2984 int i; |
2985 Lisp_Object tem; | |
2986 | |
708 | 2987 this_command_key_count = 0; |
2988 | |
2989 str = XSTRING (saved_keys); | |
2990 for (i = 0; i < str->size; i++) | |
518 | 2991 { |
708 | 2992 XFASTINT (tem) = str->data[i]; |
518 | 2993 add_command_key (tem); |
2994 } | |
708 | 2995 |
2996 str = XSTRING (function); | |
2997 for (i = 0; i < str->size; i++) | |
2998 { | |
2999 XFASTINT (tem) = str->data[i]; | |
3000 add_command_key (tem); | |
3001 } | |
3002 | |
3003 XFASTINT (tem) = '\015'; | |
3004 add_command_key (tem); | |
518 | 3005 } |
3006 | |
3007 UNGCPRO; | |
3008 | |
3009 function = Fintern (function, Vobarray); | |
3010 Vprefix_arg = prefixarg; | |
3011 this_command = function; | |
3012 | |
3013 return Fcommand_execute (function, Qt); | |
3014 } | |
3015 | |
3016 | |
3017 detect_input_pending () | |
3018 { | |
3019 if (!input_pending) | |
3020 get_input_pending (&input_pending); | |
3021 | |
3022 return input_pending; | |
3023 } | |
3024 | |
648 | 3025 /* This is called in some cases before a possible quit. |
3026 It cases the next call to detect_input_pending to recompute input_pending. | |
3027 So calling this function unnecessarily can't do any harm. */ | |
3028 clear_input_pending () | |
3029 { | |
3030 input_pending = 0; | |
3031 } | |
3032 | |
518 | 3033 DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0, |
3034 "T if command input is currently available with no waiting.\n\ | |
3035 Actually, the value is nil only if we can be sure that no input is available.") | |
3036 () | |
3037 { | |
3038 if (!NILP (unread_command_char)) | |
3039 return (Qt); | |
3040 | |
3041 return detect_input_pending () ? Qt : Qnil; | |
3042 } | |
3043 | |
3044 DEFUN ("recent-keys", Frecent_keys, Srecent_keys, 0, 0, 0, | |
727 | 3045 "Return vector of last 100 chars read from terminal.") |
518 | 3046 () |
3047 { | |
3048 Lisp_Object val; | |
3049 | |
3050 if (total_keys < NUM_RECENT_KEYS) | |
3051 return Fvector (total_keys, recent_keys); | |
3052 else | |
3053 { | |
3054 val = Fvector (NUM_RECENT_KEYS, recent_keys); | |
3055 bcopy (recent_keys + recent_keys_index, | |
3056 XVECTOR (val)->contents, | |
3057 (NUM_RECENT_KEYS - recent_keys_index) * sizeof (Lisp_Object)); | |
3058 bcopy (recent_keys, | |
3059 XVECTOR (val)->contents + NUM_RECENT_KEYS - recent_keys_index, | |
3060 recent_keys_index * sizeof (Lisp_Object)); | |
3061 return val; | |
3062 } | |
3063 } | |
3064 | |
3065 DEFUN ("this-command-keys", Fthis_command_keys, Sthis_command_keys, 0, 0, 0, | |
3066 "Return string of the keystrokes that invoked this command.") | |
3067 () | |
3068 { | |
3069 return make_array (this_command_key_count, this_command_keys); | |
3070 } | |
3071 | |
3072 DEFUN ("recursion-depth", Frecursion_depth, Srecursion_depth, 0, 0, 0, | |
3073 "Return the current depth in recursive edits.") | |
3074 () | |
3075 { | |
3076 Lisp_Object temp; | |
3077 XFASTINT (temp) = command_loop_level + minibuf_level; | |
3078 return temp; | |
3079 } | |
3080 | |
3081 DEFUN ("open-dribble-file", Fopen_dribble_file, Sopen_dribble_file, 1, 1, | |
3082 "FOpen dribble file: ", | |
3083 "Start writing all keyboard characters to FILE.") | |
3084 (file) | |
3085 Lisp_Object file; | |
3086 { | |
3087 if (NILP (file)) | |
3088 { | |
3089 fclose (dribble); | |
3090 dribble = 0; | |
3091 } | |
3092 else | |
3093 { | |
3094 file = Fexpand_file_name (file, Qnil); | |
3095 dribble = fopen (XSTRING (file)->data, "w"); | |
3096 } | |
3097 return Qnil; | |
3098 } | |
3099 | |
3100 DEFUN ("discard-input", Fdiscard_input, Sdiscard_input, 0, 0, 0, | |
3101 "Discard the contents of the terminal input buffer.\n\ | |
3102 Also cancel any kbd macro being defined.") | |
3103 () | |
3104 { | |
3105 defining_kbd_macro = 0; | |
3106 update_mode_lines++; | |
3107 | |
3108 unread_command_char = Qnil; | |
3109 | |
3110 discard_tty_input (); | |
3111 | |
3112 kbd_fetch_ptr = kbd_store_ptr; | |
3113 input_pending = 0; | |
3114 | |
3115 return Qnil; | |
3116 } | |
3117 | |
3118 DEFUN ("suspend-emacs", Fsuspend_emacs, Ssuspend_emacs, 0, 1, "", | |
3119 "Stop Emacs and return to superior process. You can resume later.\n\ | |
3120 On systems that don't have job control, run a subshell instead.\n\n\ | |
3121 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\ | |
3122 to be read as terminal input by Emacs's superior shell.\n\ | |
3123 Before suspending, if `suspend-hook' is bound and value is non-nil\n\ | |
3124 call the value as a function of no args. Don't suspend if it returns non-nil.\n\ | |
3125 Otherwise, suspend normally and after resumption call\n\ | |
3126 `suspend-resume-hook' if that is bound and non-nil.\n\ | |
3127 \n\ | |
3128 Some operating systems cannot stop the Emacs process and resume it later.\n\ | |
3129 On such systems, Emacs will start a subshell and wait for it to exit.") | |
3130 (stuffstring) | |
3131 Lisp_Object stuffstring; | |
3132 { | |
3133 register Lisp_Object tem; | |
3134 int count = specpdl_ptr - specpdl; | |
3135 int old_height, old_width; | |
3136 int width, height; | |
3137 struct gcpro gcpro1; | |
3138 extern init_sys_modes (); | |
3139 | |
3140 if (!NILP (stuffstring)) | |
3141 CHECK_STRING (stuffstring, 0); | |
3142 GCPRO1 (stuffstring); | |
3143 | |
3144 /* Call value of suspend-hook | |
3145 if it is bound and value is non-nil. */ | |
3146 if (!NILP (Vrun_hooks)) | |
3147 { | |
3148 tem = call1 (Vrun_hooks, intern ("suspend-hook")); | |
3149 if (!EQ (tem, Qnil)) return Qnil; | |
3150 } | |
3151 | |
765 | 3152 get_frame_size (&old_width, &old_height); |
518 | 3153 reset_sys_modes (); |
3154 /* sys_suspend can get an error if it tries to fork a subshell | |
3155 and the system resources aren't available for that. */ | |
3156 record_unwind_protect (init_sys_modes, 0); | |
3157 stuff_buffered_input (stuffstring); | |
3158 sys_suspend (); | |
3159 unbind_to (count, Qnil); | |
3160 | |
3161 /* Check if terminal/window size has changed. | |
3162 Note that this is not useful when we are running directly | |
3163 with a window system; but suspend should be disabled in that case. */ | |
765 | 3164 get_frame_size (&width, &height); |
518 | 3165 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
|
3166 change_frame_size (0, height, width, 0, 0); |
518 | 3167 |
3168 /* Call value of suspend-resume-hook | |
3169 if it is bound and value is non-nil. */ | |
3170 if (!NILP (Vrun_hooks)) | |
3171 call1 (Vrun_hooks, intern ("suspend-resume-hook")); | |
3172 | |
3173 UNGCPRO; | |
3174 return Qnil; | |
3175 } | |
3176 | |
3177 /* If STUFFSTRING is a string, stuff its contents as pending terminal input. | |
3178 Then in any case stuff anthing Emacs has read ahead and not used. */ | |
3179 | |
3180 stuff_buffered_input (stuffstring) | |
3181 Lisp_Object stuffstring; | |
3182 { | |
3183 register unsigned char *p; | |
3184 | |
3185 /* stuff_char works only in BSD, versions 4.2 and up. */ | |
3186 #ifdef BSD | |
3187 #ifndef BSD4_1 | |
3188 if (XTYPE (stuffstring) == Lisp_String) | |
3189 { | |
3190 register int count; | |
3191 | |
3192 p = XSTRING (stuffstring)->data; | |
3193 count = XSTRING (stuffstring)->size; | |
3194 while (count-- > 0) | |
3195 stuff_char (*p++); | |
3196 stuff_char ('\n'); | |
3197 } | |
3198 /* Anything we have read ahead, put back for the shell to read. */ | |
3199 while (kbd_fetch_ptr != kbd_store_ptr) | |
3200 { | |
3201 if (kbd_fetch_ptr == kbd_buffer + KBD_BUFFER_SIZE) | |
3202 kbd_fetch_ptr = kbd_buffer; | |
3203 if (kbd_fetch_ptr->kind == ascii_keystroke) | |
3204 stuff_char (XINT (kbd_fetch_ptr->code)); | |
3205 kbd_fetch_ptr++; | |
3206 } | |
3207 input_pending = 0; | |
3208 #endif | |
3209 #endif /* BSD and not BSD4_1 */ | |
3210 } | |
3211 | |
648 | 3212 set_waiting_for_input (time_to_clear) |
3213 EMACS_TIME *time_to_clear; | |
518 | 3214 { |
648 | 3215 input_available_clear_time = time_to_clear; |
518 | 3216 |
3217 /* Tell interrupt_signal to throw back to read_char, */ | |
3218 waiting_for_input = 1; | |
3219 | |
3220 /* If interrupt_signal was called before and buffered a C-g, | |
3221 make it run again now, to avoid timing error. */ | |
3222 if (!NILP (Vquit_flag)) | |
3223 quit_throw_to_read_char (); | |
3224 | |
3225 /* If alarm has gone off already, echo now. */ | |
3226 if (echo_flag) | |
3227 { | |
3228 echo (); | |
3229 echo_flag = 0; | |
3230 } | |
3231 } | |
3232 | |
3233 clear_waiting_for_input () | |
3234 { | |
3235 /* Tell interrupt_signal not to throw back to read_char, */ | |
3236 waiting_for_input = 0; | |
648 | 3237 input_available_clear_time = 0; |
518 | 3238 } |
3239 | |
3240 /* This routine is called at interrupt level in response to C-G. | |
3241 If interrupt_input, this is the handler for SIGINT. | |
3242 Otherwise, it is called from kbd_buffer_store_event, | |
3243 in handling SIGIO or SIGTINT. | |
3244 | |
3245 If `waiting_for_input' is non zero, then unless `echoing' is nonzero, | |
3246 immediately throw back to read_char. | |
3247 | |
3248 Otherwise it sets the Lisp variable quit-flag not-nil. | |
3249 This causes eval to throw, when it gets a chance. | |
3250 If quit-flag is already non-nil, it stops the job right away. */ | |
3251 | |
3252 SIGTYPE | |
3253 interrupt_signal () | |
3254 { | |
3255 char c; | |
3256 /* Must preserve main program's value of errno. */ | |
3257 int old_errno = errno; | |
3258 extern Lisp_Object Vwindow_system; | |
3259 | |
3260 #ifdef USG | |
3261 /* USG systems forget handlers when they are used; | |
3262 must reestablish each time */ | |
3263 signal (SIGINT, interrupt_signal); | |
3264 signal (SIGQUIT, interrupt_signal); | |
3265 #endif /* USG */ | |
3266 | |
3267 cancel_echoing (); | |
3268 | |
966
eb74884fc95a
* keyboard.c (Fsuspend_emacs): Call change_frame_size with the
Jim Blandy <jimb@redhat.com>
parents:
939
diff
changeset
|
3269 if (!NILP (Vquit_flag) && FRAME_TERMCAP_P (selected_frame)) |
518 | 3270 { |
3271 fflush (stdout); | |
3272 reset_sys_modes (); | |
3273 sigfree (); | |
3274 #ifdef SIGTSTP /* Support possible in later USG versions */ | |
3275 /* | |
3276 * On systems which can suspend the current process and return to the original | |
3277 * shell, this command causes the user to end up back at the shell. | |
3278 * The "Auto-save" and "Abort" questions are not asked until | |
3279 * the user elects to return to emacs, at which point he can save the current | |
3280 * job and either dump core or continue. | |
3281 */ | |
3282 sys_suspend (); | |
3283 #else | |
3284 #ifdef VMS | |
3285 if (sys_suspend () == -1) | |
3286 { | |
3287 printf ("Not running as a subprocess;\n"); | |
3288 printf ("you can continue or abort.\n"); | |
3289 } | |
3290 #else /* not VMS */ | |
3291 /* Perhaps should really fork an inferior shell? | |
3292 But that would not provide any way to get back | |
3293 to the original shell, ever. */ | |
3294 printf ("No support for stopping a process on this operating system;\n"); | |
3295 printf ("you can continue or abort.\n"); | |
3296 #endif /* not VMS */ | |
3297 #endif /* not SIGTSTP */ | |
3298 printf ("Auto-save? (y or n) "); | |
3299 fflush (stdout); | |
3300 if (((c = getchar ()) & ~040) == 'Y') | |
3301 Fdo_auto_save (Qnil, Qnil); | |
3302 while (c != '\n') c = getchar (); | |
3303 #ifdef VMS | |
3304 printf ("Abort (and enter debugger)? (y or n) "); | |
3305 #else /* not VMS */ | |
3306 printf ("Abort (and dump core)? (y or n) "); | |
3307 #endif /* not VMS */ | |
3308 fflush (stdout); | |
3309 if (((c = getchar ()) & ~040) == 'Y') | |
3310 abort (); | |
3311 while (c != '\n') c = getchar (); | |
3312 printf ("Continuing...\n"); | |
3313 fflush (stdout); | |
3314 init_sys_modes (); | |
3315 } | |
3316 else | |
3317 { | |
3318 /* If executing a function that wants to be interrupted out of | |
3319 and the user has not deferred quitting by binding `inhibit-quit' | |
3320 then quit right away. */ | |
3321 if (immediate_quit && NILP (Vinhibit_quit)) | |
3322 { | |
3323 immediate_quit = 0; | |
3324 sigfree (); | |
3325 Fsignal (Qquit, Qnil); | |
3326 } | |
3327 else | |
3328 /* Else request quit when it's safe */ | |
3329 Vquit_flag = Qt; | |
3330 } | |
3331 | |
3332 if (waiting_for_input && !echoing) | |
3333 quit_throw_to_read_char (); | |
3334 | |
3335 errno = old_errno; | |
3336 } | |
3337 | |
3338 /* Handle a C-g by making read_char return C-g. */ | |
3339 | |
3340 quit_throw_to_read_char () | |
3341 { | |
3342 quit_error_check (); | |
3343 sigfree (); | |
3344 /* Prevent another signal from doing this before we finish. */ | |
650 | 3345 clear_waiting_for_input (); |
518 | 3346 input_pending = 0; |
3347 | |
3348 unread_command_char = Qnil; | |
3349 | |
3350 _longjmp (getcjmp, 1); | |
3351 } | |
3352 | |
3353 DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, | |
3354 "Set mode of reading keyboard input.\n\ | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
691
diff
changeset
|
3355 First arg INTERRUPT non-nil means use input interrupts;\n\ |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
691
diff
changeset
|
3356 nil means use CBREAK mode.\n\ |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
691
diff
changeset
|
3357 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\ |
518 | 3358 (no effect except in CBREAK mode).\n\ |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
691
diff
changeset
|
3359 Third arg META non-nil means accept 8-bit input (for a Meta key).\n\ |
518 | 3360 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
|
3361 Optional fourth arg QUIT if non-nil specifies character to use for quitting.") |
518 | 3362 (interrupt, flow, meta, quit) |
3363 Lisp_Object interrupt, flow, meta, quit; | |
3364 { | |
3365 if (!NILP (quit) | |
3366 && (XTYPE (quit) != Lisp_Int | |
3367 || XINT (quit) < 0 || XINT (quit) > 0400)) | |
3368 error ("set-input-mode: QUIT must be an ASCII character."); | |
3369 | |
3370 reset_sys_modes (); | |
3371 #ifdef SIGIO | |
3372 /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
3373 #ifdef NO_SOCK_SIGIO | |
3374 if (read_socket_hook) | |
3375 interrupt_input = 0; /* No interrupts if reading from a socket. */ | |
3376 else | |
3377 #endif /* NO_SOCK_SIGIO */ | |
3378 interrupt_input = !NILP (interrupt); | |
3379 #else /* not SIGIO */ | |
3380 interrupt_input = 0; | |
3381 #endif /* not SIGIO */ | |
3382 /* Our VMS input only works by interrupts, as of now. */ | |
3383 #ifdef VMS | |
3384 interrupt_input = 1; | |
3385 #endif | |
3386 flow_control = !NILP (flow); | |
3387 meta_key = !NILP (meta); | |
3388 if (!NILP (quit)) | |
3389 /* Don't let this value be out of range. */ | |
3390 quit_char = XINT (quit) & (meta_key ? 0377 : 0177); | |
3391 | |
3392 init_sys_modes (); | |
3393 return Qnil; | |
3394 } | |
3395 | |
3396 init_keyboard () | |
3397 { | |
3398 this_command_keys_size = 40; | |
3399 this_command_keys = | |
3400 (Lisp_Object *) xmalloc (this_command_keys_size * sizeof (Lisp_Object)); | |
3401 | |
3402 /* This is correct before outermost invocation of the editor loop */ | |
3403 command_loop_level = -1; | |
3404 immediate_quit = 0; | |
3405 quit_char = Ctl ('g'); | |
3406 unread_command_char = Qnil; | |
3407 recent_keys_index = 0; | |
3408 total_keys = 0; | |
3409 kbd_fetch_ptr = kbd_buffer; | |
3410 kbd_store_ptr = kbd_buffer; | |
3411 do_mouse_tracking = 0; | |
3412 input_pending = 0; | |
3413 | |
3414 if (!noninteractive) | |
3415 { | |
3416 signal (SIGINT, interrupt_signal); | |
3417 #ifdef HAVE_TERMIO | |
3418 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and | |
3419 SIGQUIT and we can't tell which one it will give us. */ | |
3420 signal (SIGQUIT, interrupt_signal); | |
3421 #endif /* HAVE_TERMIO */ | |
3422 /* Note SIGIO has been undef'd if FIONREAD is missing. */ | |
3423 #ifdef SIGIO | |
3424 signal (SIGIO, input_available_signal); | |
1008
f1df63f98e5c
* keyboard.c (init_keyboard): Changed "#endif SIGIO" to
Jim Blandy <jimb@redhat.com>
parents:
985
diff
changeset
|
3425 #endif /* SIGIO */ |
518 | 3426 } |
3427 | |
3428 /* Use interrupt input by default, if it works and noninterrupt input | |
3429 has deficiencies. */ | |
3430 | |
3431 #ifdef INTERRUPT_INPUT | |
3432 interrupt_input = 1; | |
3433 #else | |
3434 interrupt_input = 0; | |
3435 #endif | |
3436 | |
3437 /* Our VMS input only works by interrupts, as of now. */ | |
3438 #ifdef VMS | |
3439 interrupt_input = 1; | |
3440 #endif | |
3441 | |
3442 sigfree (); | |
3443 dribble = 0; | |
3444 | |
3445 if (keyboard_init_hook) | |
3446 (*keyboard_init_hook) (); | |
3447 | |
3448 #ifdef POLL_FOR_INPUT | |
3449 poll_suppress_count = 1; | |
3450 start_polling (); | |
3451 #endif | |
3452 } | |
3453 | |
3454 /* This type's only use is in syms_of_keyboard, to initialize the | |
3455 event header symbols and put properties on them. */ | |
3456 struct event_head { | |
3457 Lisp_Object *var; | |
3458 char *name; | |
3459 Lisp_Object *kind; | |
3460 }; | |
3461 | |
3462 struct event_head head_table[] = { | |
3463 &Qmouse_movement, "mouse-movement", &Qmouse_movement, | |
3464 &Qvscrollbar_part, "vscrollbar-part", &Qscrollbar_click, | |
3465 &Qvslider_part, "vslider-part", &Qscrollbar_click, | |
3466 &Qvthumbup_part, "vthumbup-part", &Qscrollbar_click, | |
3467 &Qvthumbdown_part, "vthumbdown-part", &Qscrollbar_click, | |
3468 &Qhscrollbar_part, "hscrollbar-part", &Qscrollbar_click, | |
3469 &Qhslider_part, "hslider-part", &Qscrollbar_click, | |
3470 &Qhthumbleft_part, "hthumbleft-part", &Qscrollbar_click, | |
3471 &Qhthumbright_part,"hthumbright-part", &Qscrollbar_click | |
3472 }; | |
3473 | |
3474 syms_of_keyboard () | |
3475 { | |
3476 Qself_insert_command = intern ("self-insert-command"); | |
3477 staticpro (&Qself_insert_command); | |
3478 | |
3479 Qforward_char = intern ("forward-char"); | |
3480 staticpro (&Qforward_char); | |
3481 | |
3482 Qbackward_char = intern ("backward-char"); | |
3483 staticpro (&Qbackward_char); | |
3484 | |
3485 Qdisabled = intern ("disabled"); | |
3486 staticpro (&Qdisabled); | |
3487 | |
3488 Qfunction_key = intern ("function-key"); | |
3489 staticpro (&Qfunction_key); | |
3490 Qmouse_movement = intern ("mouse-click"); | |
3491 staticpro (&Qmouse_click); | |
3492 Qmouse_movement = intern ("scrollbar-click"); | |
3493 staticpro (&Qmouse_movement); | |
3494 | |
3495 Qmode_line = intern ("mode-line"); | |
3496 staticpro (&Qmode_line); | |
732 | 3497 Qvertical_line = intern ("vertical-line"); |
3498 staticpro (&Qvertical_line); | |
518 | 3499 |
3500 Qevent_kind = intern ("event-type"); | |
3501 staticpro (&Qevent_kind); | |
3502 Qevent_unmodified = intern ("event-unmodified"); | |
3503 staticpro (&Qevent_unmodified); | |
3504 | |
3505 { | |
3506 struct event_head *p; | |
3507 | |
3508 for (p = head_table; | |
3509 p < head_table + (sizeof (head_table) / sizeof (head_table[0])); | |
3510 p++) | |
3511 { | |
3512 *p->var = intern (p->name); | |
3513 staticpro (p->var); | |
3514 Fput (*p->var, Qevent_kind, *p->kind); | |
3515 Fput (*p->var, Qevent_unmodified, *p->var); | |
3516 } | |
3517 } | |
3518 | |
3519 func_key_syms = Qnil; | |
3520 staticpro (&func_key_syms); | |
3521 | |
3522 mouse_syms = Qnil; | |
3523 staticpro (&mouse_syms); | |
3524 | |
3525 defsubr (&Sread_key_sequence); | |
3526 defsubr (&Srecursive_edit); | |
3527 defsubr (&Strack_mouse); | |
3528 defsubr (&Smouse_click_p); | |
3529 defsubr (&Sinput_pending_p); | |
3530 defsubr (&Scommand_execute); | |
3531 defsubr (&Srecent_keys); | |
3532 defsubr (&Sthis_command_keys); | |
3533 defsubr (&Ssuspend_emacs); | |
3534 defsubr (&Sabort_recursive_edit); | |
3535 defsubr (&Sexit_recursive_edit); | |
3536 defsubr (&Srecursion_depth); | |
3537 defsubr (&Stop_level); | |
3538 defsubr (&Sdiscard_input); | |
3539 defsubr (&Sopen_dribble_file); | |
3540 defsubr (&Sset_input_mode); | |
3541 defsubr (&Sexecute_extended_command); | |
3542 | |
3543 DEFVAR_LISP ("disabled-command-hook", &Vdisabled_command_hook, | |
3544 "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
|
3545 \(has a non-nil `disabled' property)."); |
518 | 3546 |
3547 DEFVAR_LISP ("last-command-char", &last_command_char, | |
3548 "Last terminal input key that was part of a command."); | |
3549 | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3550 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event, |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3551 "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
|
3552 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
|
3553 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
|
3554 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
|
3555 |
518 | 3556 DEFVAR_LISP ("last-input-char", &last_input_char, |
3557 "Last terminal input key."); | |
3558 | |
3559 DEFVAR_LISP ("unread-command-char", &unread_command_char, | |
3560 "Object to be read as next input from input stream, or nil if none."); | |
3561 | |
3562 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char, | |
3563 "Meta-prefix character code. Meta-foo as command input\n\ | |
3564 turns into this character followed by foo."); | |
3565 XSET (meta_prefix_char, Lisp_Int, 033); | |
3566 | |
3567 DEFVAR_LISP ("last-command", &last_command, | |
3568 "The last command executed. Normally a symbol with a function definition,\n\ | |
3569 but can be whatever was found in the keymap, or whatever the variable\n\ | |
3570 `this-command' was set to by that command."); | |
3571 last_command = Qnil; | |
3572 | |
3573 DEFVAR_LISP ("this-command", &this_command, | |
3574 "The command now being executed.\n\ | |
3575 The command can set this variable; whatever is put here\n\ | |
3576 will be in `last-command' during the following command."); | |
3577 this_command = Qnil; | |
3578 | |
3579 DEFVAR_INT ("auto-save-interval", &auto_save_interval, | |
3580 "*Number of keyboard input characters between auto-saves.\n\ | |
3581 Zero means disable autosaving due to number of characters typed."); | |
3582 auto_save_interval = 300; | |
3583 | |
3584 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout, | |
3585 "*Number of seconds idle time before auto-save.\n\ | |
687
e2b747dd6a6e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
682
diff
changeset
|
3586 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
|
3587 After auto-saving due to this many seconds of idle time,\n\ |
701 | 3588 Emacs also does a garbage collection if that seems to be warranted."); |
518 | 3589 XFASTINT (Vauto_save_timeout) = 30; |
3590 | |
3591 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes, | |
3592 "*Nonzero means echo unfinished commands after this many seconds of pause."); | |
3593 echo_keystrokes = 1; | |
3594 | |
3595 DEFVAR_INT ("polling-period", &polling_period, | |
3596 "*Interval between polling for input during Lisp execution.\n\ | |
3597 The reason for polling is to make C-g work to stop a running program.\n\ | |
3598 Polling is needed only when using X windows and SIGIO does not work.\n\ | |
3599 Polling is automatically disabled in all other cases."); | |
3600 polling_period = 2; | |
3601 | |
3602 DEFVAR_INT ("num-input-keys", &num_input_keys, | |
3603 "*Number of complete keys read from the keyboard so far."); | |
3604 num_input_keys = 0; | |
3605 | |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
3606 #ifdef MULTI_FRAME |
765 | 3607 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame, |
3608 "*The frame in which the most recently read event occurred."); | |
3609 Vlast_event_frame = Qnil; | |
985
952aa214a3d0
* keyboard.c (Fexecute_mouse_event): dyked-out function deleted.
Jim Blandy <jimb@redhat.com>
parents:
966
diff
changeset
|
3610 #endif |
518 | 3611 |
3612 DEFVAR_LISP ("help-char", &help_char, | |
3613 "Character to recognize as meaning Help.\n\ | |
3614 When it is read, do `(eval help-form)', and display result if it's a string.\n\ | |
3615 If the value of `help-form' is nil, this char can be read normally."); | |
3616 XSET (help_char, Lisp_Int, Ctl ('H')); | |
3617 | |
3618 DEFVAR_LISP ("help-form", &Vhelp_form, | |
3619 "Form to execute when character help-char is read.\n\ | |
3620 If the form returns a string, that string is displayed.\n\ | |
3621 If `help-form' is nil, the help char is not recognized."); | |
3622 Vhelp_form = Qnil; | |
3623 | |
3624 DEFVAR_LISP ("top-level", &Vtop_level, | |
3625 "Form to evaluate when Emacs starts up.\n\ | |
3626 Useful to set before you dump a modified Emacs."); | |
3627 Vtop_level = Qnil; | |
3628 | |
3629 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table, | |
3630 "String used as translate table for keyboard input, or nil.\n\ | |
3631 Each character is looked up in this string and the contents used instead.\n\ | |
3632 If string is of length N, character codes N and up are untranslated."); | |
3633 Vkeyboard_translate_table = Qnil; | |
3634 | |
3635 DEFVAR_BOOL ("menu-prompting", &menu_prompting, | |
1083
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3636 "Non-nil means prompt with menus when appropriate.\n\ |
518 | 3637 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
|
3638 for elements that have prompt strings.\n\ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3639 The menu is displayed on the screen\n\ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3640 if X menus were enabled at configuration\n\ |
cbbbe0a96ecc
(last_nonmenu_event): New var.
Richard M. Stallman <rms@gnu.org>
parents:
1046
diff
changeset
|
3641 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
|
3642 Otherwise, menu prompting uses the echo area."); |
518 | 3643 menu_prompting = 1; |
3644 | |
3645 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char, | |
3646 "Character to see next line of menu prompt.\n\ | |
3647 Type this character while in a menu prompt to rotate around the lines of it."); | |
3648 XSET (menu_prompt_more_char, Lisp_Int, ' '); | |
3649 } | |
3650 | |
3651 keys_of_keyboard () | |
3652 { | |
3653 initial_define_key (global_map, Ctl ('Z'), "suspend-emacs"); | |
3654 initial_define_key (control_x_map, Ctl ('Z'), "suspend-emacs"); | |
3655 initial_define_key (meta_map, Ctl ('C'), "exit-recursive-edit"); | |
3656 initial_define_key (global_map, Ctl (']'), "abort-recursive-edit"); | |
3657 initial_define_key (meta_map, 'x', "execute-extended-command"); | |
3658 } |