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