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