aboutsummaryrefslogtreecommitdiffstats
path: root/src/keyboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keyboard.c')
-rw-r--r--src/keyboard.c1048
1 files changed, 757 insertions, 291 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index bda07473ccf..3404c60a93a 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -23,13 +23,13 @@ Boston, MA 02110-1301, USA. */
23#include <config.h> 23#include <config.h>
24#include <signal.h> 24#include <signal.h>
25#include <stdio.h> 25#include <stdio.h>
26#include "lisp.h"
26#include "termchar.h" 27#include "termchar.h"
27#include "termopts.h" 28#include "termopts.h"
28#include "lisp.h" 29#include "frame.h"
29#include "termhooks.h" 30#include "termhooks.h"
30#include "macros.h" 31#include "macros.h"
31#include "keyboard.h" 32#include "keyboard.h"
32#include "frame.h"
33#include "window.h" 33#include "window.h"
34#include "commands.h" 34#include "commands.h"
35#include "buffer.h" 35#include "buffer.h"
@@ -59,7 +59,6 @@ Boston, MA 02110-1301, USA. */
59#endif /* not MSDOS */ 59#endif /* not MSDOS */
60 60
61#include "syssignal.h" 61#include "syssignal.h"
62#include "systty.h"
63 62
64#include <sys/types.h> 63#include <sys/types.h>
65#ifdef HAVE_UNISTD_H 64#ifdef HAVE_UNISTD_H
@@ -97,9 +96,6 @@ volatile int interrupt_input_blocked;
97int interrupt_input_pending; 96int interrupt_input_pending;
98 97
99 98
100/* File descriptor to use for input. */
101extern int input_fd;
102
103#ifdef HAVE_WINDOW_SYSTEM 99#ifdef HAVE_WINDOW_SYSTEM
104/* Make all keyboard buffers much bigger when using X windows. */ 100/* Make all keyboard buffers much bigger when using X windows. */
105#ifdef MAC_OS8 101#ifdef MAC_OS8
@@ -425,16 +421,6 @@ Lisp_Object Vecho_keystrokes;
425/* Form to evaluate (if non-nil) when Emacs is started. */ 421/* Form to evaluate (if non-nil) when Emacs is started. */
426Lisp_Object Vtop_level; 422Lisp_Object Vtop_level;
427 423
428/* User-supplied table to translate input characters. */
429Lisp_Object Vkeyboard_translate_table;
430
431/* Keymap mapping ASCII function key sequences onto their preferred forms. */
432extern Lisp_Object Vfunction_key_map;
433
434/* Another keymap that maps key sequences into key sequences.
435 This one takes precedence over ordinary definitions. */
436extern Lisp_Object Vkey_translation_map;
437
438/* If non-nil, this implements the current input method. */ 424/* If non-nil, this implements the current input method. */
439Lisp_Object Vinput_method_function; 425Lisp_Object Vinput_method_function;
440Lisp_Object Qinput_method_function; 426Lisp_Object Qinput_method_function;
@@ -458,6 +444,12 @@ Lisp_Object Qpre_command_hook, Vpre_command_hook;
458Lisp_Object Qpost_command_hook, Vpost_command_hook; 444Lisp_Object Qpost_command_hook, Vpost_command_hook;
459Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal; 445Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal;
460 446
447/* Parent keymap of terminal-local function-key-map instances. */
448Lisp_Object Vfunction_key_map;
449
450/* Parent keymap of terminal-local key-translation-map instances. */
451Lisp_Object Vkey_translation_map;
452
461/* List of deferred actions to be performed at a later time. 453/* List of deferred actions to be performed at a later time.
462 The precise format isn't relevant here; we just check whether it is nil. */ 454 The precise format isn't relevant here; we just check whether it is nil. */
463Lisp_Object Vdeferred_action_list; 455Lisp_Object Vdeferred_action_list;
@@ -475,11 +467,6 @@ FILE *dribble;
475/* Nonzero if input is available. */ 467/* Nonzero if input is available. */
476int input_pending; 468int input_pending;
477 469
478/* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
479 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
480
481int meta_key;
482
483extern char *pending_malloc_warning; 470extern char *pending_malloc_warning;
484 471
485/* Circular buffer for pre-read keyboard input. */ 472/* Circular buffer for pre-read keyboard input. */
@@ -609,9 +596,6 @@ int interrupt_input;
609/* Nonzero while interrupts are temporarily deferred during redisplay. */ 596/* Nonzero while interrupts are temporarily deferred during redisplay. */
610int interrupts_deferred; 597int interrupts_deferred;
611 598
612/* Nonzero means use ^S/^Q for flow control. */
613int flow_control;
614
615/* Allow m- file to inhibit use of FIONREAD. */ 599/* Allow m- file to inhibit use of FIONREAD. */
616#ifdef BROKEN_FIONREAD 600#ifdef BROKEN_FIONREAD
617#undef FIONREAD 601#undef FIONREAD
@@ -694,8 +678,9 @@ static void save_getcjmp ();
694static void restore_getcjmp P_ ((jmp_buf)); 678static void restore_getcjmp P_ ((jmp_buf));
695static Lisp_Object apply_modifiers P_ ((int, Lisp_Object)); 679static Lisp_Object apply_modifiers P_ ((int, Lisp_Object));
696static void clear_event P_ ((struct input_event *)); 680static void clear_event P_ ((struct input_event *));
697static void any_kboard_state P_ ((void)); 681static Lisp_Object restore_kboard_configuration P_ ((Lisp_Object));
698static SIGTYPE interrupt_signal P_ ((int signalnum)); 682static SIGTYPE interrupt_signal P_ ((int signalnum));
683static void handle_interrupt P_ ((void));
699static void timer_start_idle P_ ((void)); 684static void timer_start_idle P_ ((void));
700static void timer_stop_idle P_ ((void)); 685static void timer_stop_idle P_ ((void));
701static void timer_resume_idle P_ ((void)); 686static void timer_resume_idle P_ ((void));
@@ -1061,24 +1046,20 @@ This function is called by the editor initialization to begin editing. */)
1061 like it is done in the splash screen display, we have to 1046 like it is done in the splash screen display, we have to
1062 make sure that we restore single_kboard as command_loop_1 1047 make sure that we restore single_kboard as command_loop_1
1063 would have done if it were left normally. */ 1048 would have done if it were left normally. */
1064 record_unwind_protect (recursive_edit_unwind, 1049 if (command_loop_level > 0)
1065 Fcons (buffer, single_kboard ? Qt : Qnil)); 1050 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
1051 record_unwind_protect (recursive_edit_unwind, buffer);
1066 1052
1067 recursive_edit_1 (); 1053 recursive_edit_1 ();
1068 return unbind_to (count, Qnil); 1054 return unbind_to (count, Qnil);
1069} 1055}
1070 1056
1071Lisp_Object 1057Lisp_Object
1072recursive_edit_unwind (info) 1058recursive_edit_unwind (buffer)
1073 Lisp_Object info; 1059 Lisp_Object buffer;
1074{ 1060{
1075 if (BUFFERP (XCAR (info))) 1061 if (BUFFERP (buffer))
1076 Fset_buffer (XCAR (info)); 1062 Fset_buffer (buffer);
1077
1078 if (NILP (XCDR (info)))
1079 any_kboard_state ();
1080 else
1081 single_kboard_state ();
1082 1063
1083 command_loop_level--; 1064 command_loop_level--;
1084 update_mode_lines = 1; 1065 update_mode_lines = 1;
@@ -1086,6 +1067,8 @@ recursive_edit_unwind (info)
1086} 1067}
1087 1068
1088 1069
1070#if 0 /* These two functions are now replaced with
1071 temporarily_switch_to_single_kboard. */
1089static void 1072static void
1090any_kboard_state () 1073any_kboard_state ()
1091{ 1074{
@@ -1116,6 +1099,7 @@ single_kboard_state ()
1116 single_kboard = 1; 1099 single_kboard = 1;
1117#endif 1100#endif
1118} 1101}
1102#endif
1119 1103
1120/* If we're in single_kboard state for kboard KBOARD, 1104/* If we're in single_kboard state for kboard KBOARD,
1121 get out of it. */ 1105 get out of it. */
@@ -1143,8 +1127,8 @@ struct kboard_stack
1143static struct kboard_stack *kboard_stack; 1127static struct kboard_stack *kboard_stack;
1144 1128
1145void 1129void
1146push_frame_kboard (f) 1130push_kboard (k)
1147 FRAME_PTR f; 1131 struct kboard *k;
1148{ 1132{
1149#ifdef MULTI_KBOARD 1133#ifdef MULTI_KBOARD
1150 struct kboard_stack *p 1134 struct kboard_stack *p
@@ -1154,20 +1138,107 @@ push_frame_kboard (f)
1154 p->kboard = current_kboard; 1138 p->kboard = current_kboard;
1155 kboard_stack = p; 1139 kboard_stack = p;
1156 1140
1157 current_kboard = FRAME_KBOARD (f); 1141 current_kboard = k;
1158#endif 1142#endif
1159} 1143}
1160 1144
1161void 1145void
1162pop_frame_kboard () 1146pop_kboard ()
1163{ 1147{
1164#ifdef MULTI_KBOARD 1148#ifdef MULTI_KBOARD
1149 struct terminal *t;
1165 struct kboard_stack *p = kboard_stack; 1150 struct kboard_stack *p = kboard_stack;
1166 current_kboard = p->kboard; 1151 int found = 0;
1152 for (t = terminal_list; t; t = t->next_terminal)
1153 {
1154 if (t->kboard == p->kboard)
1155 {
1156 current_kboard = p->kboard;
1157 found = 1;
1158 break;
1159 }
1160 }
1161 if (!found)
1162 {
1163 /* The terminal we remembered has been deleted. */
1164 current_kboard = FRAME_KBOARD (SELECTED_FRAME ());
1165 single_kboard = 0;
1166 }
1167 kboard_stack = p->next; 1167 kboard_stack = p->next;
1168 xfree (p); 1168 xfree (p);
1169#endif 1169#endif
1170} 1170}
1171
1172/* Switch to single_kboard mode, making current_kboard the only KBOARD
1173 from which further input is accepted. If F is non-nil, set its
1174 KBOARD as the current keyboard.
1175
1176 This function uses record_unwind_protect to return to the previous
1177 state later.
1178
1179 If Emacs is already in single_kboard mode, and F's keyboard is
1180 locked, then this function will throw an errow. */
1181
1182void
1183temporarily_switch_to_single_kboard (f)
1184 struct frame *f;
1185{
1186#ifdef MULTI_KBOARD
1187 int was_locked = single_kboard;
1188 if (was_locked)
1189 {
1190 if (f != NULL && FRAME_KBOARD (f) != current_kboard)
1191 /* We can not switch keyboards while in single_kboard mode.
1192 In rare cases, Lisp code may call `recursive-edit' (or
1193 `read-minibuffer' or `y-or-n-p') after it switched to a
1194 locked frame. For example, this is likely to happen
1195 when server.el connects to a new terminal while Emacs is in
1196 single_kboard mode. It is best to throw an error instead
1197 of presenting the user with a frozen screen. */
1198 error ("Terminal %d is locked, cannot read from it",
1199 FRAME_TERMINAL (f)->id);
1200 else
1201 /* This call is unnecessary, but helps
1202 `restore_kboard_configuration' discover if somebody changed
1203 `current_kboard' behind our back. */
1204 push_kboard (current_kboard);
1205 }
1206 else if (f != NULL)
1207 current_kboard = FRAME_KBOARD (f);
1208 single_kboard = 1;
1209 record_unwind_protect (restore_kboard_configuration,
1210 (was_locked ? Qt : Qnil));
1211#endif
1212}
1213
1214#if 0 /* This function is not needed anymore. */
1215void
1216record_single_kboard_state ()
1217{
1218 if (single_kboard)
1219 push_kboard (current_kboard);
1220 record_unwind_protect (restore_kboard_configuration,
1221 (single_kboard ? Qt : Qnil));
1222}
1223#endif
1224
1225static Lisp_Object
1226restore_kboard_configuration (was_locked)
1227 Lisp_Object was_locked;
1228{
1229 if (NILP (was_locked))
1230 single_kboard = 0;
1231 else
1232 {
1233 struct kboard *prev = current_kboard;
1234 single_kboard = 1;
1235 pop_kboard ();
1236 /* The pop should not change the kboard. */
1237 if (single_kboard && current_kboard != prev)
1238 abort ();
1239 }
1240 return Qnil;
1241}
1171 1242
1172/* Handle errors that are not handled at inner levels 1243/* Handle errors that are not handled at inner levels
1173 by printing an error message and returning to the editor command loop. */ 1244 by printing an error message and returning to the editor command loop. */
@@ -1215,10 +1286,12 @@ cmd_error (data)
1215 Vquit_flag = Qnil; 1286 Vquit_flag = Qnil;
1216 1287
1217 Vinhibit_quit = Qnil; 1288 Vinhibit_quit = Qnil;
1289#if 0 /* This shouldn't be necessary anymore. --lorentey */
1218#ifdef MULTI_KBOARD 1290#ifdef MULTI_KBOARD
1219 if (command_loop_level == 0 && minibuf_level == 0) 1291 if (command_loop_level == 0 && minibuf_level == 0)
1220 any_kboard_state (); 1292 any_kboard_state ();
1221#endif 1293#endif
1294#endif
1222 1295
1223 return make_number (0); 1296 return make_number (0);
1224} 1297}
@@ -1254,11 +1327,7 @@ cmd_error_internal (data, context)
1254 /* If the window system or terminal frame hasn't been initialized 1327 /* If the window system or terminal frame hasn't been initialized
1255 yet, or we're not interactive, write the message to stderr and exit. */ 1328 yet, or we're not interactive, write the message to stderr and exit. */
1256 else if (!sf->glyphs_initialized_p 1329 else if (!sf->glyphs_initialized_p
1257 /* This is the case of the frame dumped with Emacs, when we're 1330 || FRAME_INITIAL_P (sf)
1258 running under a window system. */
1259 || (!NILP (Vwindow_system)
1260 && !inhibit_window_system
1261 && FRAME_TERMCAP_P (sf))
1262 || noninteractive) 1331 || noninteractive)
1263 { 1332 {
1264 print_error_message (data, Qexternal_debugging_output, 1333 print_error_message (data, Qexternal_debugging_output,
@@ -1301,10 +1370,12 @@ command_loop ()
1301 while (1) 1370 while (1)
1302 { 1371 {
1303 internal_catch (Qtop_level, top_level_1, Qnil); 1372 internal_catch (Qtop_level, top_level_1, Qnil);
1304 /* Reset single_kboard in case top-level set it while 1373#if 0 /* This shouldn't be necessary anymore. --lorentey */
1305 evaluating an -f option, or we are stuck there for some 1374 /* Reset single_kboard in case top-level set it while
1306 other reason. */ 1375 evaluating an -f option, or we are stuck there for some
1307 any_kboard_state (); 1376 other reason. */
1377 any_kboard_state ();
1378#endif
1308 internal_catch (Qtop_level, command_loop_2, Qnil); 1379 internal_catch (Qtop_level, command_loop_2, Qnil);
1309 executing_kbd_macro = Qnil; 1380 executing_kbd_macro = Qnil;
1310 1381
@@ -1499,10 +1570,12 @@ command_loop_1 ()
1499 int no_direct; 1570 int no_direct;
1500 int prev_modiff = 0; 1571 int prev_modiff = 0;
1501 struct buffer *prev_buffer = NULL; 1572 struct buffer *prev_buffer = NULL;
1573#if 0 /* This shouldn't be necessary anymore. --lorentey */
1502#ifdef MULTI_KBOARD 1574#ifdef MULTI_KBOARD
1503 int was_locked = single_kboard; 1575 int was_locked = single_kboard;
1504#endif 1576#endif
1505 int already_adjusted; 1577#endif
1578 int already_adjusted = 0;
1506 1579
1507 current_kboard->Vprefix_arg = Qnil; 1580 current_kboard->Vprefix_arg = Qnil;
1508 current_kboard->Vlast_prefix_arg = Qnil; 1581 current_kboard->Vlast_prefix_arg = Qnil;
@@ -1961,10 +2034,11 @@ command_loop_1 ()
1961 if (!NILP (current_kboard->defining_kbd_macro) 2034 if (!NILP (current_kboard->defining_kbd_macro)
1962 && NILP (current_kboard->Vprefix_arg)) 2035 && NILP (current_kboard->Vprefix_arg))
1963 finalize_kbd_macro_chars (); 2036 finalize_kbd_macro_chars ();
1964 2037#if 0 /* This shouldn't be necessary anymore. --lorentey */
1965#ifdef MULTI_KBOARD 2038#ifdef MULTI_KBOARD
1966 if (!was_locked) 2039 if (!was_locked)
1967 any_kboard_state (); 2040 any_kboard_state ();
2041#endif
1968#endif 2042#endif
1969 } 2043 }
1970} 2044}
@@ -2203,7 +2277,10 @@ void
2203start_polling () 2277start_polling ()
2204{ 2278{
2205#ifdef POLL_FOR_INPUT 2279#ifdef POLL_FOR_INPUT
2206 if (read_socket_hook && !interrupt_input) 2280 /* XXX This condition was (read_socket_hook && !interrupt_input),
2281 but read_socket_hook is not global anymore. Let's pretend that
2282 it's always set. */
2283 if (!interrupt_input)
2207 { 2284 {
2208 /* Turn alarm handling on unconditionally. It might have 2285 /* Turn alarm handling on unconditionally. It might have
2209 been turned off in process.c. */ 2286 been turned off in process.c. */
@@ -2237,7 +2314,10 @@ int
2237input_polling_used () 2314input_polling_used ()
2238{ 2315{
2239#ifdef POLL_FOR_INPUT 2316#ifdef POLL_FOR_INPUT
2240 return read_socket_hook && !interrupt_input; 2317 /* XXX This condition was (read_socket_hook && !interrupt_input),
2318 but read_socket_hook is not global anymore. Let's pretend that
2319 it's always set. */
2320 return !interrupt_input;
2241#else 2321#else
2242 return 0; 2322 return 0;
2243#endif 2323#endif
@@ -2249,7 +2329,10 @@ void
2249stop_polling () 2329stop_polling ()
2250{ 2330{
2251#ifdef POLL_FOR_INPUT 2331#ifdef POLL_FOR_INPUT
2252 if (read_socket_hook && !interrupt_input) 2332 /* XXX This condition was (read_socket_hook && !interrupt_input),
2333 but read_socket_hook is not global anymore. Let's pretend that
2334 it's always set. */
2335 if (!interrupt_input)
2253 ++poll_suppress_count; 2336 ++poll_suppress_count;
2254#endif 2337#endif
2255} 2338}
@@ -2461,10 +2544,6 @@ read_char_help_form_unwind (arg)
2461 return Qnil; 2544 return Qnil;
2462} 2545}
2463 2546
2464#ifdef MULTI_KBOARD
2465static jmp_buf wrong_kboard_jmpbuf;
2466#endif
2467
2468#define STOP_POLLING \ 2547#define STOP_POLLING \
2469do { if (! polling_stopped_here) stop_polling (); \ 2548do { if (! polling_stopped_here) stop_polling (); \
2470 polling_stopped_here = 1; } while (0) 2549 polling_stopped_here = 1; } while (0)
@@ -2491,6 +2570,9 @@ do { if (polling_stopped_here) start_polling (); \
2491 if we used a mouse menu to read the input, or zero otherwise. If 2570 if we used a mouse menu to read the input, or zero otherwise. If
2492 USED_MOUSE_MENU is null, we don't dereference it. 2571 USED_MOUSE_MENU is null, we don't dereference it.
2493 2572
2573 Value is -2 when we find input on another keyboard. A second call
2574 to read_char will read it.
2575
2494 If END_TIME is non-null, it is a pointer to an EMACS_TIME 2576 If END_TIME is non-null, it is a pointer to an EMACS_TIME
2495 specifying the maximum time to wait until. If no input arrives by 2577 specifying the maximum time to wait until. If no input arrives by
2496 that time, stop waiting and return nil. 2578 that time, stop waiting and return nil.
@@ -2517,6 +2599,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2517 volatile int reread; 2599 volatile int reread;
2518 struct gcpro gcpro1, gcpro2; 2600 struct gcpro gcpro1, gcpro2;
2519 int polling_stopped_here = 0; 2601 int polling_stopped_here = 0;
2602 struct kboard *orig_kboard = current_kboard;
2520 2603
2521 also_record = Qnil; 2604 also_record = Qnil;
2522 2605
@@ -2731,6 +2814,10 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2731 && !detect_input_pending_run_timers (0)) 2814 && !detect_input_pending_run_timers (0))
2732 { 2815 {
2733 c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps); 2816 c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps);
2817
2818 if (INTEGERP (c) && XINT (c) == -2)
2819 return c; /* wrong_kboard_jmpbuf */
2820
2734 if (! NILP (c)) 2821 if (! NILP (c))
2735 { 2822 {
2736 key_already_recorded = 1; 2823 key_already_recorded = 1;
@@ -2747,6 +2834,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2747 jmpcount = SPECPDL_INDEX (); 2834 jmpcount = SPECPDL_INDEX ();
2748 if (_setjmp (local_getcjmp)) 2835 if (_setjmp (local_getcjmp))
2749 { 2836 {
2837 /* Handle quits while reading the keyboard. */
2750 /* We must have saved the outer value of getcjmp here, 2838 /* We must have saved the outer value of getcjmp here,
2751 so restore it now. */ 2839 so restore it now. */
2752 restore_getcjmp (save_jump); 2840 restore_getcjmp (save_jump);
@@ -2784,7 +2872,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2784 /* This is going to exit from read_char 2872 /* This is going to exit from read_char
2785 so we had better get rid of this frame's stuff. */ 2873 so we had better get rid of this frame's stuff. */
2786 UNGCPRO; 2874 UNGCPRO;
2787 longjmp (wrong_kboard_jmpbuf, 1); 2875 return make_number (-2); /* wrong_kboard_jmpbuf */
2788 } 2876 }
2789 } 2877 }
2790#endif 2878#endif
@@ -2921,6 +3009,19 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2921 } 3009 }
2922 } 3010 }
2923 3011
3012 /* Notify the caller if an autosave hook, or a timer, sentinel or
3013 filter in the sit_for calls above have changed the current
3014 kboard. This could happen if they use the minibuffer or start a
3015 recursive edit, like the fancy splash screen in server.el's
3016 filter. If this longjmp wasn't here, read_key_sequence would
3017 interpret the next key sequence using the wrong translation
3018 tables and function keymaps. */
3019 if (NILP (c) && current_kboard != orig_kboard)
3020 {
3021 UNGCPRO;
3022 return make_number (-2); /* wrong_kboard_jmpbuf */
3023 }
3024
2924 /* If this has become non-nil here, it has been set by a timer 3025 /* If this has become non-nil here, it has been set by a timer
2925 or sentinel or filter. */ 3026 or sentinel or filter. */
2926 if (CONSP (Vunread_command_events)) 3027 if (CONSP (Vunread_command_events))
@@ -2969,7 +3070,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2969 /* This is going to exit from read_char 3070 /* This is going to exit from read_char
2970 so we had better get rid of this frame's stuff. */ 3071 so we had better get rid of this frame's stuff. */
2971 UNGCPRO; 3072 UNGCPRO;
2972 longjmp (wrong_kboard_jmpbuf, 1); 3073 return make_number (-2); /* wrong_kboard_jmpbuf */
2973 } 3074 }
2974 } 3075 }
2975#endif 3076#endif
@@ -3025,7 +3126,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3025 /* This is going to exit from read_char 3126 /* This is going to exit from read_char
3026 so we had better get rid of this frame's stuff. */ 3127 so we had better get rid of this frame's stuff. */
3027 UNGCPRO; 3128 UNGCPRO;
3028 longjmp (wrong_kboard_jmpbuf, 1); 3129 return make_number (-2);
3029 } 3130 }
3030#endif 3131#endif
3031 } 3132 }
@@ -3080,8 +3181,12 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3080 3181
3081 if (!NILP (tem)) 3182 if (!NILP (tem))
3082 { 3183 {
3184#if 0 /* This shouldn't be necessary anymore. --lorentey */
3083 int was_locked = single_kboard; 3185 int was_locked = single_kboard;
3084 3186 int count = SPECPDL_INDEX ();
3187 record_single_kboard_state ();
3188#endif
3189
3085 last_input_char = c; 3190 last_input_char = c;
3086 Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt); 3191 Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt);
3087 3192
@@ -3092,9 +3197,12 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3092 example banishing the mouse under mouse-avoidance-mode. */ 3197 example banishing the mouse under mouse-avoidance-mode. */
3093 timer_resume_idle (); 3198 timer_resume_idle ();
3094 3199
3200#if 0 /* This shouldn't be necessary anymore. --lorentey */
3095 /* Resume allowing input from any kboard, if that was true before. */ 3201 /* Resume allowing input from any kboard, if that was true before. */
3096 if (!was_locked) 3202 if (!was_locked)
3097 any_kboard_state (); 3203 any_kboard_state ();
3204 unbind_to (count, Qnil);
3205#endif
3098 3206
3099 goto retry; 3207 goto retry;
3100 } 3208 }
@@ -3106,15 +3214,15 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3106 if (XINT (c) == -1) 3214 if (XINT (c) == -1)
3107 goto exit; 3215 goto exit;
3108 3216
3109 if ((STRINGP (Vkeyboard_translate_table) 3217 if ((STRINGP (current_kboard->Vkeyboard_translate_table)
3110 && SCHARS (Vkeyboard_translate_table) > (unsigned) XFASTINT (c)) 3218 && SCHARS (current_kboard->Vkeyboard_translate_table) > (unsigned) XFASTINT (c))
3111 || (VECTORP (Vkeyboard_translate_table) 3219 || (VECTORP (current_kboard->Vkeyboard_translate_table)
3112 && XVECTOR (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) 3220 && XVECTOR (current_kboard->Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c))
3113 || (CHAR_TABLE_P (Vkeyboard_translate_table) 3221 || (CHAR_TABLE_P (current_kboard->Vkeyboard_translate_table)
3114 && CHAR_VALID_P (XINT (c), 0))) 3222 && CHAR_VALID_P (XINT (c), 0)))
3115 { 3223 {
3116 Lisp_Object d; 3224 Lisp_Object d;
3117 d = Faref (Vkeyboard_translate_table, c); 3225 d = Faref (current_kboard->Vkeyboard_translate_table, c);
3118 /* nil in keyboard-translate-table means no translation. */ 3226 /* nil in keyboard-translate-table means no translation. */
3119 if (!NILP (d)) 3227 if (!NILP (d))
3120 c = d; 3228 c = d;
@@ -3734,12 +3842,10 @@ kbd_buffer_store_event_hold (event, hold_quit)
3734 if (c == quit_char) 3842 if (c == quit_char)
3735 { 3843 {
3736#ifdef MULTI_KBOARD 3844#ifdef MULTI_KBOARD
3737 KBOARD *kb; 3845 KBOARD *kb = FRAME_KBOARD (XFRAME (event->frame_or_window));
3738 struct input_event *sp; 3846 struct input_event *sp;
3739 3847
3740 if (single_kboard 3848 if (single_kboard && kb != current_kboard)
3741 && (kb = FRAME_KBOARD (XFRAME (event->frame_or_window)),
3742 kb != current_kboard))
3743 { 3849 {
3744 kb->kbd_queue 3850 kb->kbd_queue
3745 = Fcons (make_lispy_switch_frame (event->frame_or_window), 3851 = Fcons (make_lispy_switch_frame (event->frame_or_window),
@@ -3782,7 +3888,7 @@ kbd_buffer_store_event_hold (event, hold_quit)
3782 } 3888 }
3783 3889
3784 last_event_timestamp = event->timestamp; 3890 last_event_timestamp = event->timestamp;
3785 interrupt_signal (0 /* dummy */); 3891 handle_interrupt ();
3786 return; 3892 return;
3787 } 3893 }
3788 3894
@@ -4261,11 +4367,15 @@ kbd_buffer_get_event (kbp, used_mouse_menu, end_time)
4261 unsigned long time; 4367 unsigned long time;
4262 4368
4263 *kbp = current_kboard; 4369 *kbp = current_kboard;
4264 /* Note that this uses F to determine which display to look at. 4370 /* Note that this uses F to determine which terminal to look at.
4265 If there is no valid info, it does not store anything 4371 If there is no valid info, it does not store anything
4266 so x remains nil. */ 4372 so x remains nil. */
4267 x = Qnil; 4373 x = Qnil;
4268 (*mouse_position_hook) (&f, 0, &bar_window, &part, &x, &y, &time); 4374
4375 /* XXX Can f or mouse_position_hook be NULL here? */
4376 if (f && FRAME_TERMINAL (f)->mouse_position_hook)
4377 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, 0, &bar_window,
4378 &part, &x, &y, &time);
4269 4379
4270 obj = Qnil; 4380 obj = Qnil;
4271 4381
@@ -4562,10 +4672,14 @@ timer_check (do_it_now)
4562 { 4672 {
4563 if (NILP (vector[0])) 4673 if (NILP (vector[0]))
4564 { 4674 {
4565 int was_locked = single_kboard;
4566 int count = SPECPDL_INDEX (); 4675 int count = SPECPDL_INDEX ();
4567 Lisp_Object old_deactivate_mark = Vdeactivate_mark; 4676 Lisp_Object old_deactivate_mark = Vdeactivate_mark;
4568 4677
4678#if 0 /* This shouldn't be necessary anymore. --lorentey */
4679 /* On unbind_to, resume allowing input from any kboard, if that
4680 was true before. */
4681 record_single_kboard_state ();
4682#endif
4569 /* Mark the timer as triggered to prevent problems if the lisp 4683 /* Mark the timer as triggered to prevent problems if the lisp
4570 code fails to reschedule it right. */ 4684 code fails to reschedule it right. */
4571 vector[0] = Qt; 4685 vector[0] = Qt;
@@ -4577,10 +4691,6 @@ timer_check (do_it_now)
4577 timers_run++; 4691 timers_run++;
4578 unbind_to (count, Qnil); 4692 unbind_to (count, Qnil);
4579 4693
4580 /* Resume allowing input from any kboard, if that was true before. */
4581 if (!was_locked)
4582 any_kboard_state ();
4583
4584 /* Since we have handled the event, 4694 /* Since we have handled the event,
4585 we don't need to tell the caller to wake up and do it. */ 4695 we don't need to tell the caller to wake up and do it. */
4586 } 4696 }
@@ -6481,8 +6591,8 @@ modify_event_symbol (symbol_num, modifiers, symbol_kind, name_alist_or_stem,
6481 { 6591 {
6482 int len = SBYTES (name_alist_or_stem); 6592 int len = SBYTES (name_alist_or_stem);
6483 char *buf = (char *) alloca (len + 50); 6593 char *buf = (char *) alloca (len + 50);
6484 sprintf (buf, "%s-%ld", SDATA (name_alist_or_stem), 6594 sprintf (buf, "%s-%ld", SDATA (name_alist_or_stem),
6485 (long) XINT (symbol_int) + 1); 6595 (long) XINT (symbol_int) + 1);
6486 value = intern (buf); 6596 value = intern (buf);
6487 } 6597 }
6488 else if (name_table != 0 && name_table[symbol_num]) 6598 else if (name_table != 0 && name_table[symbol_num])
@@ -6747,7 +6857,10 @@ gobble_input (expected)
6747 } 6857 }
6748 else 6858 else
6749#ifdef POLL_FOR_INPUT 6859#ifdef POLL_FOR_INPUT
6750 if (read_socket_hook && !interrupt_input && poll_suppress_count == 0) 6860 /* XXX This condition was (read_socket_hook && !interrupt_input),
6861 but read_socket_hook is not global anymore. Let's pretend that
6862 it's always set. */
6863 if (!interrupt_input && poll_suppress_count == 0)
6751 { 6864 {
6752 SIGMASKTYPE mask; 6865 SIGMASKTYPE mask;
6753 mask = sigblock (sigmask (SIGALRM)); 6866 mask = sigblock (sigmask (SIGALRM));
@@ -6824,150 +6937,221 @@ static int
6824read_avail_input (expected) 6937read_avail_input (expected)
6825 int expected; 6938 int expected;
6826{ 6939{
6827 register int i;
6828 int nread = 0; 6940 int nread = 0;
6941 int err = 0;
6942 struct terminal *t;
6829 6943
6830 /* Store pending user signal events, if any. */ 6944 /* Store pending user signal events, if any. */
6831 if (store_user_signal_events ()) 6945 if (store_user_signal_events ())
6832 expected = 0; 6946 expected = 0;
6833 6947
6834 if (read_socket_hook) 6948 /* Loop through the available terminals, and call their input hooks. */
6949 t = terminal_list;
6950 while (t)
6835 { 6951 {
6836 int nr; 6952 struct terminal *next = t->next_terminal;
6837 struct input_event hold_quit;
6838 6953
6839 EVENT_INIT (hold_quit); 6954 if (t->read_socket_hook)
6840 hold_quit.kind = NO_EVENT; 6955 {
6956 int nr;
6957 struct input_event hold_quit;
6958
6959 EVENT_INIT (hold_quit);
6960 hold_quit.kind = NO_EVENT;
6961
6962 /* No need for FIONREAD or fcntl; just say don't wait. */
6963 while (nr = (*t->read_socket_hook) (t, expected, &hold_quit), nr > 0)
6964 {
6965 nread += nr;
6966 expected = 0;
6967 }
6968
6969 if (nr == -1) /* Not OK to read input now. */
6970 {
6971 err = 1;
6972 }
6973 else if (nr == -2) /* Non-transient error. */
6974 {
6975 /* The terminal device terminated; it should be closed. */
6976
6977 /* Kill Emacs if this was our last terminal. */
6978 if (!terminal_list->next_terminal)
6979 /* Formerly simply reported no input, but that
6980 sometimes led to a failure of Emacs to terminate.
6981 SIGHUP seems appropriate if we can't reach the
6982 terminal. */
6983 /* ??? Is it really right to send the signal just to
6984 this process rather than to the whole process
6985 group? Perhaps on systems with FIONREAD Emacs is
6986 alone in its group. */
6987 kill (getpid (), SIGHUP);
6988
6989 /* XXX Is calling delete_terminal safe here? It calls Fdelete_frame. */
6990 if (t->delete_terminal_hook)
6991 (*t->delete_terminal_hook) (t);
6992 else
6993 delete_terminal (t);
6994 }
6995
6996 if (hold_quit.kind != NO_EVENT)
6997 kbd_buffer_store_event (&hold_quit);
6998 }
6841 6999
6842 /* No need for FIONREAD or fcntl; just say don't wait. */ 7000 t = next;
6843 while (nr = (*read_socket_hook) (input_fd, expected, &hold_quit), nr > 0)
6844 {
6845 nread += nr;
6846 expected = 0;
6847 }
6848 if (hold_quit.kind != NO_EVENT)
6849 kbd_buffer_store_event (&hold_quit);
6850 } 7001 }
6851 else
6852 {
6853 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
6854 the kbd_buffer can really hold. That may prevent loss
6855 of characters on some systems when input is stuffed at us. */
6856 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
6857 int n_to_read;
6858 7002
6859 /* Determine how many characters we should *try* to read. */ 7003 if (err && !nread)
7004 nread = -1;
7005
7006 return nread;
7007}
7008
7009/* This is the tty way of reading available input.
7010
7011 Note that each terminal device has its own `struct terminal' object,
7012 and so this function is called once for each individual termcap
7013 terminal. The first parameter indicates which terminal to read from. */
7014
7015int
7016tty_read_avail_input (struct terminal *terminal,
7017 int expected,
7018 struct input_event *hold_quit)
7019{
7020 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
7021 the kbd_buffer can really hold. That may prevent loss
7022 of characters on some systems when input is stuffed at us. */
7023 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
7024 int n_to_read, i;
7025 struct tty_display_info *tty = terminal->display_info.tty;
7026 int nread = 0;
7027
7028 if (terminal->deleted) /* Don't read from a deleted terminal. */
7029 return;
7030
7031 if (terminal->type != output_termcap)
7032 abort ();
7033
7034 /* XXX I think the following code should be moved to separate hook
7035 functions in system-dependent files. */
6860#ifdef WINDOWSNT 7036#ifdef WINDOWSNT
6861 return 0; 7037 return 0;
6862#else /* not WINDOWSNT */ 7038#else /* not WINDOWSNT */
6863#ifdef MSDOS 7039#ifdef MSDOS
6864 n_to_read = dos_keysns (); 7040 n_to_read = dos_keysns ();
6865 if (n_to_read == 0) 7041 if (n_to_read == 0)
6866 return 0; 7042 return 0;
7043
7044 cbuf[0] = dos_keyread ();
7045 nread = 1;
7046
6867#else /* not MSDOS */ 7047#else /* not MSDOS */
7048
7049 if (! tty->term_initted) /* In case we get called during bootstrap. */
7050 return 0;
7051
7052 if (! tty->input)
7053 return 0; /* The terminal is suspended. */
7054
7055 /* Determine how many characters we should *try* to read. */
6868#ifdef FIONREAD 7056#ifdef FIONREAD
6869 /* Find out how much input is available. */ 7057 /* Find out how much input is available. */
6870 if (ioctl (input_fd, FIONREAD, &n_to_read) < 0) 7058 if (ioctl (fileno (tty->input), FIONREAD, &n_to_read) < 0)
6871 /* Formerly simply reported no input, but that sometimes led to 7059 {
6872 a failure of Emacs to terminate. 7060 if (! noninteractive)
6873 SIGHUP seems appropriate if we can't reach the terminal. */ 7061 return -2; /* Close this terminal. */
6874 /* ??? Is it really right to send the signal just to this process 7062 else
6875 rather than to the whole process group? 7063 n_to_read = 0;
6876 Perhaps on systems with FIONREAD Emacs is alone in its group. */ 7064 }
6877 { 7065 if (n_to_read == 0)
6878 if (! noninteractive) 7066 return 0;
6879 kill (getpid (), SIGHUP); 7067 if (n_to_read > sizeof cbuf)
6880 else 7068 n_to_read = sizeof cbuf;
6881 n_to_read = 0;
6882 }
6883 if (n_to_read == 0)
6884 return 0;
6885 if (n_to_read > sizeof cbuf)
6886 n_to_read = sizeof cbuf;
6887#else /* no FIONREAD */ 7069#else /* no FIONREAD */
6888#if defined (USG) || defined (DGUX) || defined(CYGWIN) 7070#if defined (USG) || defined (DGUX) || defined(CYGWIN)
6889 /* Read some input if available, but don't wait. */ 7071 /* Read some input if available, but don't wait. */
6890 n_to_read = sizeof cbuf; 7072 n_to_read = sizeof cbuf;
6891 fcntl (input_fd, F_SETFL, O_NDELAY); 7073 fcntl (fileno (tty->input), F_SETFL, O_NDELAY);
6892#else 7074#else
6893 you lose; 7075 you lose;
6894#endif 7076#endif
6895#endif 7077#endif
6896#endif /* not MSDOS */
6897#endif /* not WINDOWSNT */
6898 7078
6899 /* Now read; for one reason or another, this will not block. 7079 /* Now read; for one reason or another, this will not block.
6900 NREAD is set to the number of chars read. */ 7080 NREAD is set to the number of chars read. */
6901 do 7081 do
6902 { 7082 {
6903#ifdef MSDOS 7083 nread = emacs_read (fileno (tty->input), cbuf, n_to_read);
6904 cbuf[0] = dos_keyread (); 7084 /* POSIX infers that processes which are not in the session leader's
6905 nread = 1; 7085 process group won't get SIGHUP's at logout time. BSDI adheres to
6906#else 7086 this part standard and returns -1 from read (0) with errno==EIO
6907 nread = emacs_read (input_fd, cbuf, n_to_read); 7087 when the control tty is taken away.
6908#endif 7088 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6909 /* POSIX infers that processes which are not in the session leader's 7089 if (nread == -1 && errno == EIO)
6910 process group won't get SIGHUP's at logout time. BSDI adheres to 7090 return -2; /* Close this terminal. */
6911 this part standard and returns -1 from read (0) with errno==EIO
6912 when the control tty is taken away.
6913 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6914 if (nread == -1 && errno == EIO)
6915 kill (0, SIGHUP);
6916#if defined (AIX) && (! defined (aix386) && defined (_BSD)) 7091#if defined (AIX) && (! defined (aix386) && defined (_BSD))
6917 /* The kernel sometimes fails to deliver SIGHUP for ptys. 7092 /* The kernel sometimes fails to deliver SIGHUP for ptys.
6918 This looks incorrect, but it isn't, because _BSD causes 7093 This looks incorrect, but it isn't, because _BSD causes
6919 O_NDELAY to be defined in fcntl.h as O_NONBLOCK, 7094 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
6920 and that causes a value other than 0 when there is no input. */ 7095 and that causes a value other than 0 when there is no input. */
6921 if (nread == 0) 7096 if (nread == 0)
6922 kill (0, SIGHUP); 7097 return -2; /* Close this terminal. */
6923#endif 7098#endif
6924 } 7099 }
6925 while ( 7100 while (
6926 /* We used to retry the read if it was interrupted. 7101 /* We used to retry the read if it was interrupted.
6927 But this does the wrong thing when O_NDELAY causes 7102 But this does the wrong thing when O_NDELAY causes
6928 an EAGAIN error. Does anybody know of a situation 7103 an EAGAIN error. Does anybody know of a situation
6929 where a retry is actually needed? */ 7104 where a retry is actually needed? */
6930#if 0 7105#if 0
6931 nread < 0 && (errno == EAGAIN 7106 nread < 0 && (errno == EAGAIN
6932#ifdef EFAULT 7107#ifdef EFAULT
6933 || errno == EFAULT 7108 || errno == EFAULT
6934#endif 7109#endif
6935#ifdef EBADSLT 7110#ifdef EBADSLT
6936 || errno == EBADSLT 7111 || errno == EBADSLT
6937#endif 7112#endif
6938 ) 7113 )
6939#else 7114#else
6940 0 7115 0
6941#endif 7116#endif
6942 ); 7117 );
6943 7118
6944#ifndef FIONREAD 7119#ifndef FIONREAD
6945#if defined (USG) || defined (DGUX) || defined (CYGWIN) 7120#if defined (USG) || defined (DGUX) || defined (CYGWIN)
6946 fcntl (input_fd, F_SETFL, 0); 7121 fcntl (fileno (tty->input), F_SETFL, 0);
6947#endif /* USG or DGUX or CYGWIN */ 7122#endif /* USG or DGUX or CYGWIN */
6948#endif /* no FIONREAD */ 7123#endif /* no FIONREAD */
6949 for (i = 0; i < nread; i++) 7124
6950 { 7125 if (nread <= 0)
6951 struct input_event buf; 7126 return nread;
6952 EVENT_INIT (buf); 7127
6953 buf.kind = ASCII_KEYSTROKE_EVENT; 7128#endif /* not MSDOS */
6954 buf.modifiers = 0; 7129#endif /* not WINDOWSNT */
6955 if (meta_key == 1 && (cbuf[i] & 0x80)) 7130
6956 buf.modifiers = meta_modifier; 7131 for (i = 0; i < nread; i++)
6957 if (meta_key != 2) 7132 {
6958 cbuf[i] &= ~0x80; 7133 struct input_event buf;
6959 7134 EVENT_INIT (buf);
6960 buf.code = cbuf[i]; 7135 buf.kind = ASCII_KEYSTROKE_EVENT;
6961 buf.frame_or_window = selected_frame; 7136 buf.modifiers = 0;
6962 buf.arg = Qnil; 7137 if (tty->meta_key == 1 && (cbuf[i] & 0x80))
6963 7138 buf.modifiers = meta_modifier;
6964 kbd_buffer_store_event (&buf); 7139 if (tty->meta_key != 2)
6965 /* Don't look at input that follows a C-g too closely. 7140 cbuf[i] &= ~0x80;
6966 This reduces lossage due to autorepeat on C-g. */ 7141
6967 if (buf.kind == ASCII_KEYSTROKE_EVENT 7142 buf.code = cbuf[i];
6968 && buf.code == quit_char) 7143 /* Set the frame corresponding to the active tty. Note that the
6969 break; 7144 value of selected_frame is not reliable here, redisplay tends
6970 } 7145 to temporarily change it. */
7146 buf.frame_or_window = tty->top_frame;
7147 buf.arg = Qnil;
7148
7149 kbd_buffer_store_event (&buf);
7150 /* Don't look at input that follows a C-g too closely.
7151 This reduces lossage due to autorepeat on C-g. */
7152 if (buf.kind == ASCII_KEYSTROKE_EVENT
7153 && buf.code == quit_char)
7154 break;
6971 } 7155 }
6972 7156
6973 return nread; 7157 return nread;
@@ -8545,6 +8729,8 @@ read_char_minibuf_menu_prompt (commandflag, nmaps, maps)
8545 8729
8546 if (!INTEGERP (obj)) 8730 if (!INTEGERP (obj))
8547 return obj; 8731 return obj;
8732 else if (XINT (obj) == -2)
8733 return obj;
8548 else 8734 else
8549 ch = XINT (obj); 8735 ch = XINT (obj);
8550 8736
@@ -8891,11 +9077,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
8891 last_nonmenu_event = Qnil; 9077 last_nonmenu_event = Qnil;
8892 9078
8893 delayed_switch_frame = Qnil; 9079 delayed_switch_frame = Qnil;
8894 fkey.map = fkey.parent = Vfunction_key_map; 9080
8895 keytran.map = keytran.parent = Vkey_translation_map;
8896 fkey.start = fkey.end = 0;
8897 keytran.start = keytran.end = 0;
8898
8899 if (INTERACTIVE) 9081 if (INTERACTIVE)
8900 { 9082 {
8901 if (!NILP (prompt)) 9083 if (!NILP (prompt))
@@ -8935,6 +9117,13 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
8935 keybuf[0..mock_input] holds the sequence we should reread. */ 9117 keybuf[0..mock_input] holds the sequence we should reread. */
8936 replay_sequence: 9118 replay_sequence:
8937 9119
9120 /* We may switch keyboards between rescans, so we need to
9121 reinitialize fkey and keytran before each replay. */
9122 fkey.map = fkey.parent = current_kboard->Vlocal_function_key_map;
9123 keytran.map = keytran.parent = current_kboard->Vlocal_key_translation_map;
9124 fkey.start = fkey.end = 0;
9125 keytran.start = keytran.end = 0;
9126
8938 starting_buffer = current_buffer; 9127 starting_buffer = current_buffer;
8939 first_unbound = bufsize + 1; 9128 first_unbound = bufsize + 1;
8940 9129
@@ -9099,8 +9288,28 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9099#ifdef MULTI_KBOARD 9288#ifdef MULTI_KBOARD
9100 KBOARD *interrupted_kboard = current_kboard; 9289 KBOARD *interrupted_kboard = current_kboard;
9101 struct frame *interrupted_frame = SELECTED_FRAME (); 9290 struct frame *interrupted_frame = SELECTED_FRAME ();
9102 if (setjmp (wrong_kboard_jmpbuf)) 9291#endif
9292 key = read_char (NILP (prompt), nmaps,
9293 (Lisp_Object *) submaps, last_nonmenu_event,
9294 &used_mouse_menu, NULL);
9295#ifdef MULTI_KBOARD
9296 if (INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */
9103 { 9297 {
9298 int found = 0;
9299 struct kboard *k;
9300
9301 for (k = all_kboards; k; k = k->next_kboard)
9302 if (k == interrupted_kboard)
9303 found = 1;
9304
9305 if (!found)
9306 {
9307 /* Don't touch interrupted_kboard when it's been
9308 deleted. */
9309 delayed_switch_frame = Qnil;
9310 goto replay_sequence;
9311 }
9312
9104 if (!NILP (delayed_switch_frame)) 9313 if (!NILP (delayed_switch_frame))
9105 { 9314 {
9106 interrupted_kboard->kbd_queue 9315 interrupted_kboard->kbd_queue
@@ -9108,6 +9317,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9108 interrupted_kboard->kbd_queue); 9317 interrupted_kboard->kbd_queue);
9109 delayed_switch_frame = Qnil; 9318 delayed_switch_frame = Qnil;
9110 } 9319 }
9320
9111 while (t > 0) 9321 while (t > 0)
9112 interrupted_kboard->kbd_queue 9322 interrupted_kboard->kbd_queue
9113 = Fcons (keybuf[--t], interrupted_kboard->kbd_queue); 9323 = Fcons (keybuf[--t], interrupted_kboard->kbd_queue);
@@ -9132,9 +9342,6 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9132 goto replay_sequence; 9342 goto replay_sequence;
9133 } 9343 }
9134#endif 9344#endif
9135 key = read_char (NILP (prompt), nmaps,
9136 (Lisp_Object *) submaps, last_nonmenu_event,
9137 &used_mouse_menu, NULL);
9138 } 9345 }
9139 9346
9140 /* read_char returns t when it shows a menu and the user rejects it. 9347 /* read_char returns t when it shows a menu and the user rejects it.
@@ -10246,8 +10453,12 @@ detect_input_pending_run_timers (do_display)
10246 from an idle timer function. The symptom of the bug is that 10453 from an idle timer function. The symptom of the bug is that
10247 the cursor sometimes doesn't become visible until the next X 10454 the cursor sometimes doesn't become visible until the next X
10248 event is processed. --gerd. */ 10455 event is processed. --gerd. */
10249 if (rif) 10456 {
10250 rif->flush_display (NULL); 10457 Lisp_Object tail, frame;
10458 FOR_EACH_FRAME (tail, frame)
10459 if (FRAME_RIF (XFRAME (frame)))
10460 FRAME_RIF (XFRAME (frame))->flush_display (XFRAME (frame));
10461 }
10251 } 10462 }
10252 10463
10253 return input_pending; 10464 return input_pending;
@@ -10499,6 +10710,9 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10499 int width, height; 10710 int width, height;
10500 struct gcpro gcpro1; 10711 struct gcpro gcpro1;
10501 10712
10713 if (tty_list && tty_list->next)
10714 error ("There are other tty frames open; close them before suspending Emacs");
10715
10502 if (!NILP (stuffstring)) 10716 if (!NILP (stuffstring))
10503 CHECK_STRING (stuffstring); 10717 CHECK_STRING (stuffstring);
10504 10718
@@ -10507,11 +10721,11 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10507 call1 (Vrun_hooks, intern ("suspend-hook")); 10721 call1 (Vrun_hooks, intern ("suspend-hook"));
10508 10722
10509 GCPRO1 (stuffstring); 10723 GCPRO1 (stuffstring);
10510 get_frame_size (&old_width, &old_height); 10724 get_tty_size (fileno (CURTTY ()->input), &old_width, &old_height);
10511 reset_sys_modes (); 10725 reset_all_sys_modes ();
10512 /* sys_suspend can get an error if it tries to fork a subshell 10726 /* sys_suspend can get an error if it tries to fork a subshell
10513 and the system resources aren't available for that. */ 10727 and the system resources aren't available for that. */
10514 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes, 10728 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_all_sys_modes,
10515 Qnil); 10729 Qnil);
10516 stuff_buffered_input (stuffstring); 10730 stuff_buffered_input (stuffstring);
10517 if (cannot_suspend) 10731 if (cannot_suspend)
@@ -10523,7 +10737,7 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10523 /* Check if terminal/window size has changed. 10737 /* Check if terminal/window size has changed.
10524 Note that this is not useful when we are running directly 10738 Note that this is not useful when we are running directly
10525 with a window system; but suspend should be disabled in that case. */ 10739 with a window system; but suspend should be disabled in that case. */
10526 get_frame_size (&width, &height); 10740 get_tty_size (fileno (CURTTY ()->input), &width, &height);
10527 if (width != old_width || height != old_height) 10741 if (width != old_width || height != old_height)
10528 change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0); 10742 change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0);
10529 10743
@@ -10583,10 +10797,10 @@ set_waiting_for_input (time_to_clear)
10583{ 10797{
10584 input_available_clear_time = time_to_clear; 10798 input_available_clear_time = time_to_clear;
10585 10799
10586 /* Tell interrupt_signal to throw back to read_char, */ 10800 /* Tell handle_interrupt to throw back to read_char, */
10587 waiting_for_input = 1; 10801 waiting_for_input = 1;
10588 10802
10589 /* If interrupt_signal was called before and buffered a C-g, 10803 /* If handle_interrupt was called before and buffered a C-g,
10590 make it run again now, to avoid timing error. */ 10804 make it run again now, to avoid timing error. */
10591 if (!NILP (Vquit_flag)) 10805 if (!NILP (Vquit_flag))
10592 quit_throw_to_read_char (); 10806 quit_throw_to_read_char ();
@@ -10595,48 +10809,82 @@ set_waiting_for_input (time_to_clear)
10595void 10809void
10596clear_waiting_for_input () 10810clear_waiting_for_input ()
10597{ 10811{
10598 /* Tell interrupt_signal not to throw back to read_char, */ 10812 /* Tell handle_interrupt not to throw back to read_char, */
10599 waiting_for_input = 0; 10813 waiting_for_input = 0;
10600 input_available_clear_time = 0; 10814 input_available_clear_time = 0;
10601} 10815}
10602 10816
10603/* This routine is called at interrupt level in response to C-g. 10817/* The SIGINT handler.
10604
10605 If interrupt_input, this is the handler for SIGINT. Otherwise, it
10606 is called from kbd_buffer_store_event, in handling SIGIO or
10607 SIGTINT.
10608 10818
10609 If `waiting_for_input' is non zero, then unless `echoing' is 10819 If we have a frame on the controlling tty, we assume that the
10610 nonzero, immediately throw back to read_char. 10820 SIGINT was generated by C-g, so we call handle_interrupt.
10611 10821 Otherwise, the handler kills Emacs. */
10612 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
10613 eval to throw, when it gets a chance. If quit-flag is already
10614 non-nil, it stops the job right away. */
10615 10822
10616static SIGTYPE 10823static SIGTYPE
10617interrupt_signal (signalnum) /* If we don't have an argument, */ 10824interrupt_signal (signalnum) /* If we don't have an argument, */
10618 int signalnum; /* some compilers complain in signal calls. */ 10825 int signalnum; /* some compilers complain in signal calls. */
10619{ 10826{
10620 char c;
10621 /* Must preserve main program's value of errno. */ 10827 /* Must preserve main program's value of errno. */
10622 int old_errno = errno; 10828 int old_errno = errno;
10623 struct frame *sf = SELECTED_FRAME (); 10829 struct terminal *terminal;
10624 10830
10625#if defined (USG) && !defined (POSIX_SIGNALS) 10831#if defined (USG) && !defined (POSIX_SIGNALS)
10626 if (!read_socket_hook && NILP (Vwindow_system)) 10832 /* USG systems forget handlers when they are used;
10627 { 10833 must reestablish each time */
10628 /* USG systems forget handlers when they are used; 10834 signal (SIGINT, interrupt_signal);
10629 must reestablish each time */ 10835 signal (SIGQUIT, interrupt_signal);
10630 signal (SIGINT, interrupt_signal);
10631 signal (SIGQUIT, interrupt_signal);
10632 }
10633#endif /* USG */ 10836#endif /* USG */
10634 10837
10635 SIGNAL_THREAD_CHECK (signalnum); 10838 SIGNAL_THREAD_CHECK (signalnum);
10839
10840 /* See if we have an active terminal on our controlling tty. */
10841 terminal = get_named_tty ("/dev/tty");
10842 if (!terminal)
10843 {
10844 /* If there are no frames there, let's pretend that we are a
10845 well-behaving UN*X program and quit. */
10846 Fkill_emacs (Qnil);
10847 }
10848 else
10849 {
10850 /* Otherwise, the SIGINT was probably generated by C-g. */
10851
10852 /* Set internal_last_event_frame to the top frame of the
10853 controlling tty, if we have a frame there. We disable the
10854 interrupt key on secondary ttys, so the SIGINT must have come
10855 from the controlling tty. */
10856 internal_last_event_frame = terminal->display_info.tty->top_frame;
10857
10858 handle_interrupt ();
10859 }
10860
10861 errno = old_errno;
10862}
10863
10864/* This routine is called at interrupt level in response to C-g.
10865
10866 It is called from the SIGINT handler or kbd_buffer_store_event.
10867
10868 If `waiting_for_input' is non zero, then unless `echoing' is
10869 nonzero, immediately throw back to read_char.
10870
10871 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
10872 eval to throw, when it gets a chance. If quit-flag is already
10873 non-nil, it stops the job right away. */
10874
10875static void
10876handle_interrupt ()
10877{
10878 char c;
10879
10636 cancel_echoing (); 10880 cancel_echoing ();
10637 10881
10882 /* XXX This code needs to be revised for multi-tty support. */
10638 if (!NILP (Vquit_flag) 10883 if (!NILP (Vquit_flag)
10639 && (FRAME_TERMCAP_P (sf) || FRAME_MSDOS_P (sf))) 10884#ifndef MSDOS
10885 && get_named_tty ("/dev/tty")
10886#endif
10887 )
10640 { 10888 {
10641 /* If SIGINT isn't blocked, don't let us be interrupted by 10889 /* If SIGINT isn't blocked, don't let us be interrupted by
10642 another SIGINT, it might be harmful due to non-reentrancy 10890 another SIGINT, it might be harmful due to non-reentrancy
@@ -10644,7 +10892,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10644 sigblock (sigmask (SIGINT)); 10892 sigblock (sigmask (SIGINT));
10645 10893
10646 fflush (stdout); 10894 fflush (stdout);
10647 reset_sys_modes (); 10895 reset_all_sys_modes ();
10648 10896
10649#ifdef SIGTSTP /* Support possible in later USG versions */ 10897#ifdef SIGTSTP /* Support possible in later USG versions */
10650/* 10898/*
@@ -10723,7 +10971,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10723 printf ("Continuing...\n"); 10971 printf ("Continuing...\n");
10724#endif /* not MSDOS */ 10972#endif /* not MSDOS */
10725 fflush (stdout); 10973 fflush (stdout);
10726 init_sys_modes (); 10974 init_all_sys_modes ();
10727 sigfree (); 10975 sigfree ();
10728 } 10976 }
10729 else 10977 else
@@ -10751,9 +10999,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10751 } 10999 }
10752 11000
10753 if (waiting_for_input && !echoing) 11001 if (waiting_for_input && !echoing)
10754 quit_throw_to_read_char (); 11002 quit_throw_to_read_char ();
10755
10756 errno = old_errno;
10757} 11003}
10758 11004
10759/* Handle a C-g by making read_char return C-g. */ 11005/* Handle a C-g by making read_char return C-g. */
@@ -10786,75 +11032,202 @@ quit_throw_to_read_char ()
10786 _longjmp (getcjmp, 1); 11032 _longjmp (getcjmp, 1);
10787} 11033}
10788 11034
10789DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, 11035DEFUN ("set-input-interrupt-mode", Fset_input_interrupt_mode, Sset_input_interrupt_mode, 1, 1, 0,
10790 doc: /* Set mode of reading keyboard input. 11036 doc: /* Set interrupt mode of reading keyboard input.
10791First arg INTERRUPT non-nil means use input interrupts; 11037If INTERRUPT is non-nil, Emacs will use input interrupts;
10792 nil means use CBREAK mode. 11038otherwise Emacs uses CBREAK mode.
10793Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal 11039
10794 (no effect except in CBREAK mode).
10795Third arg META t means accept 8-bit input (for a Meta key).
10796 META nil means ignore the top bit, on the assumption it is parity.
10797 Otherwise, accept 8-bit input and don't use the top bit for Meta.
10798Optional fourth arg QUIT if non-nil specifies character to use for quitting.
10799See also `current-input-mode'. */) 11040See also `current-input-mode'. */)
10800 (interrupt, flow, meta, quit) 11041 (interrupt)
10801 Lisp_Object interrupt, flow, meta, quit; 11042 Lisp_Object interrupt;
10802{ 11043{
10803 if (!NILP (quit) 11044 int new_interrupt_input;
10804 && (!INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400))
10805 error ("set-input-mode: QUIT must be an ASCII character");
10806
10807#ifdef POLL_FOR_INPUT
10808 stop_polling ();
10809#endif
10810
10811#ifndef DOS_NT
10812 /* this causes startup screen to be restored and messes with the mouse */
10813 reset_sys_modes ();
10814#endif
10815
10816#ifdef SIGIO 11045#ifdef SIGIO
10817/* Note SIGIO has been undef'd if FIONREAD is missing. */ 11046/* Note SIGIO has been undef'd if FIONREAD is missing. */
10818 if (read_socket_hook) 11047#ifdef HAVE_X_WINDOWS
11048 if (x_display_list != NULL)
10819 { 11049 {
10820 /* When using X, don't give the user a real choice, 11050 /* When using X, don't give the user a real choice,
10821 because we haven't implemented the mechanisms to support it. */ 11051 because we haven't implemented the mechanisms to support it. */
10822#ifdef NO_SOCK_SIGIO 11052#ifdef NO_SOCK_SIGIO
10823 interrupt_input = 0; 11053 new_interrupt_input = 0;
10824#else /* not NO_SOCK_SIGIO */ 11054#else /* not NO_SOCK_SIGIO */
10825 interrupt_input = 1; 11055 new_interrupt_input = 1;
10826#endif /* NO_SOCK_SIGIO */ 11056#endif /* NO_SOCK_SIGIO */
10827 } 11057 }
10828 else 11058 else
10829 interrupt_input = !NILP (interrupt); 11059#endif
11060 new_interrupt_input = !NILP (interrupt);
10830#else /* not SIGIO */ 11061#else /* not SIGIO */
10831 interrupt_input = 0; 11062 new_interrupt_input = 0;
10832#endif /* not SIGIO */ 11063#endif /* not SIGIO */
10833 11064
10834/* Our VMS input only works by interrupts, as of now. */ 11065/* Our VMS input only works by interrupts, as of now. */
10835#ifdef VMS 11066#ifdef VMS
10836 interrupt_input = 1; 11067 new_interrupt_input = 1;
11068#endif
11069
11070 if (new_interrupt_input != interrupt_input)
11071 {
11072#ifdef POLL_FOR_INPUT
11073 stop_polling ();
11074#endif
11075#ifndef DOS_NT
11076 /* this causes startup screen to be restored and messes with the mouse */
11077 reset_all_sys_modes ();
11078#endif
11079 interrupt_input = new_interrupt_input;
11080#ifndef DOS_NT
11081 init_all_sys_modes ();
11082#endif
11083
11084#ifdef POLL_FOR_INPUT
11085 poll_suppress_count = 1;
11086 start_polling ();
11087#endif
11088 }
11089 return Qnil;
11090}
11091
11092DEFUN ("set-output-flow-control", Fset_output_flow_control, Sset_output_flow_control, 1, 2, 0,
11093 doc: /* Enable or disable ^S/^Q flow control for output to TERMINAL.
11094If FLOW is non-nil, flow control is enabled and you cannot use C-s or
11095C-q in key sequences.
11096
11097This setting only has an effect on tty terminals and only when
11098Emacs reads input in CBREAK mode; see `set-input-interrupt-mode'.
11099
11100See also `current-input-mode'. */)
11101 (flow, terminal)
11102 Lisp_Object flow, terminal;
11103{
11104 struct terminal *t = get_terminal (terminal, 1);
11105 struct tty_display_info *tty;
11106 if (t == NULL || t->type != output_termcap)
11107 return Qnil;
11108 tty = t->display_info.tty;
11109
11110 if (tty->flow_control != !NILP (flow))
11111 {
11112#ifndef DOS_NT
11113 /* this causes startup screen to be restored and messes with the mouse */
11114 reset_sys_modes (tty);
10837#endif 11115#endif
10838 11116
10839 flow_control = !NILP (flow); 11117 tty->flow_control = !NILP (flow);
11118
11119#ifndef DOS_NT
11120 init_sys_modes (tty);
11121#endif
11122 }
11123 return Qnil;
11124}
11125
11126DEFUN ("set-input-meta-mode", Fset_input_meta_mode, Sset_input_meta_mode, 1, 2, 0,
11127 doc: /* Enable or disable 8-bit input on TERMINAL.
11128If META is t, Emacs will accept 8-bit input, and interpret the 8th
11129bit as the Meta modifier.
11130
11131If META is nil, Emacs will ignore the top bit, on the assumption it is
11132parity.
11133
11134Otherwise, Emacs will accept and pass through 8-bit input without
11135specially interpreting the top bit.
11136
11137This setting only has an effect on tty terminal devices.
11138
11139Optional parameter TERMINAL specifies the tty terminal device to use.
11140It may be a terminal id, a frame, or nil for the terminal used by the
11141currently selected frame.
11142
11143See also `current-input-mode'. */)
11144 (meta, terminal)
11145 Lisp_Object meta, terminal;
11146{
11147 struct terminal *t = get_terminal (terminal, 1);
11148 struct tty_display_info *tty;
11149 int new_meta;
11150
11151 if (t == NULL || t->type != output_termcap)
11152 return Qnil;
11153 tty = t->display_info.tty;
11154
10840 if (NILP (meta)) 11155 if (NILP (meta))
10841 meta_key = 0; 11156 new_meta = 0;
10842 else if (EQ (meta, Qt)) 11157 else if (EQ (meta, Qt))
10843 meta_key = 1; 11158 new_meta = 1;
10844 else 11159 else
10845 meta_key = 2; 11160 new_meta = 2;
10846 if (!NILP (quit))
10847 /* Don't let this value be out of range. */
10848 quit_char = XINT (quit) & (meta_key ? 0377 : 0177);
10849 11161
11162 if (tty->meta_key != new_meta)
11163 {
10850#ifndef DOS_NT 11164#ifndef DOS_NT
10851 init_sys_modes (); 11165 /* this causes startup screen to be restored and messes with the mouse */
11166 reset_sys_modes (tty);
10852#endif 11167#endif
10853 11168
10854#ifdef POLL_FOR_INPUT 11169 tty->meta_key = new_meta;
10855 poll_suppress_count = 1; 11170
10856 start_polling (); 11171#ifndef DOS_NT
11172 init_sys_modes (tty);
11173#endif
11174 }
11175 return Qnil;
11176}
11177
11178DEFUN ("set-quit-char", Fset_quit_char, Sset_quit_char, 1, 1, 0,
11179 doc: /* Specify character used for quitting.
11180QUIT must be an ASCII character.
11181
11182This function only has an effect on the controlling tty of the Emacs
11183process.
11184
11185See also `current-input-mode'. */)
11186 (quit)
11187 Lisp_Object quit;
11188{
11189 struct terminal *t = get_named_tty ("/dev/tty");
11190 struct tty_display_info *tty;
11191 if (t == NULL || t->type != output_termcap)
11192 return Qnil;
11193 tty = t->display_info.tty;
11194
11195 if (NILP (quit) || !INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400)
11196 error ("QUIT must be an ASCII character");
11197
11198#ifndef DOS_NT
11199 /* this causes startup screen to be restored and messes with the mouse */
11200 reset_sys_modes (tty);
10857#endif 11201#endif
11202
11203 /* Don't let this value be out of range. */
11204 quit_char = XINT (quit) & (tty->meta_key == 0 ? 0177 : 0377);
11205
11206#ifndef DOS_NT
11207 init_sys_modes (tty);
11208#endif
11209
11210 return Qnil;
11211}
11212
11213DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0,
11214 doc: /* Set mode of reading keyboard input.
11215First arg INTERRUPT non-nil means use input interrupts;
11216 nil means use CBREAK mode.
11217Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal
11218 (no effect except in CBREAK mode).
11219Third arg META t means accept 8-bit input (for a Meta key).
11220 META nil means ignore the top bit, on the assumption it is parity.
11221 Otherwise, accept 8-bit input and don't use the top bit for Meta.
11222Optional fourth arg QUIT if non-nil specifies character to use for quitting.
11223See also `current-input-mode'. */)
11224 (interrupt, flow, meta, quit)
11225 Lisp_Object interrupt, flow, meta, quit;
11226{
11227 Fset_input_interrupt_mode (interrupt);
11228 Fset_output_flow_control (flow, Qnil);
11229 Fset_input_meta_mode (meta, Qnil);
11230 Fset_quit_char (quit);
10858 return Qnil; 11231 return Qnil;
10859} 11232}
10860 11233
@@ -10875,10 +11248,21 @@ The elements of this list correspond to the arguments of
10875 () 11248 ()
10876{ 11249{
10877 Lisp_Object val[4]; 11250 Lisp_Object val[4];
11251 struct frame *sf = XFRAME (selected_frame);
10878 11252
10879 val[0] = interrupt_input ? Qt : Qnil; 11253 val[0] = interrupt_input ? Qt : Qnil;
10880 val[1] = flow_control ? Qt : Qnil; 11254 if (FRAME_TERMCAP_P (sf))
10881 val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil; 11255 {
11256 val[1] = FRAME_TTY (sf)->flow_control ? Qt : Qnil;
11257 val[2] = (FRAME_TTY (sf)->meta_key == 2
11258 ? make_number (0)
11259 : (CURTTY ()->meta_key == 1 ? Qt : Qnil));
11260 }
11261 else
11262 {
11263 val[1] = Qnil;
11264 val[2] = Qt;
11265 }
10882 XSETFASTINT (val[3], quit_char); 11266 XSETFASTINT (val[3], quit_char);
10883 11267
10884 return Flist (sizeof (val) / sizeof (val[0]), val); 11268 return Flist (sizeof (val) / sizeof (val[0]), val);
@@ -10970,6 +11354,7 @@ init_kboard (kb)
10970 kb->Voverriding_terminal_local_map = Qnil; 11354 kb->Voverriding_terminal_local_map = Qnil;
10971 kb->Vlast_command = Qnil; 11355 kb->Vlast_command = Qnil;
10972 kb->Vreal_last_command = Qnil; 11356 kb->Vreal_last_command = Qnil;
11357 kb->Vkeyboard_translate_table = Qnil;
10973 kb->Vprefix_arg = Qnil; 11358 kb->Vprefix_arg = Qnil;
10974 kb->Vlast_prefix_arg = Qnil; 11359 kb->Vlast_prefix_arg = Qnil;
10975 kb->kbd_queue = Qnil; 11360 kb->kbd_queue = Qnil;
@@ -10984,6 +11369,10 @@ init_kboard (kb)
10984 kb->reference_count = 0; 11369 kb->reference_count = 0;
10985 kb->Vsystem_key_alist = Qnil; 11370 kb->Vsystem_key_alist = Qnil;
10986 kb->system_key_syms = Qnil; 11371 kb->system_key_syms = Qnil;
11372 kb->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil);
11373 Fset_keymap_parent (kb->Vlocal_function_key_map, Vfunction_key_map);
11374 kb->Vlocal_key_translation_map = Fmake_sparse_keymap (Qnil);
11375 Fset_keymap_parent (kb->Vlocal_key_translation_map, Vkey_translation_map);
10987 kb->Vdefault_minibuffer_frame = Qnil; 11376 kb->Vdefault_minibuffer_frame = Qnil;
10988} 11377}
10989 11378
@@ -11020,7 +11409,8 @@ delete_kboard (kb)
11020 && FRAMEP (selected_frame) 11409 && FRAMEP (selected_frame)
11021 && FRAME_LIVE_P (XFRAME (selected_frame))) 11410 && FRAME_LIVE_P (XFRAME (selected_frame)))
11022 { 11411 {
11023 current_kboard = XFRAME (selected_frame)->kboard; 11412 current_kboard = FRAME_KBOARD (XFRAME (selected_frame));
11413 single_kboard = 0;
11024 if (current_kboard == kb) 11414 if (current_kboard == kb)
11025 abort (); 11415 abort ();
11026 } 11416 }
@@ -11063,8 +11453,14 @@ init_keyboard ()
11063 wipe_kboard (current_kboard); 11453 wipe_kboard (current_kboard);
11064 init_kboard (current_kboard); 11454 init_kboard (current_kboard);
11065 11455
11066 if (!noninteractive && !read_socket_hook && NILP (Vwindow_system)) 11456 if (!noninteractive)
11067 { 11457 {
11458 /* Before multi-tty support, these handlers used to be installed
11459 only if the current session was a tty session. Now an Emacs
11460 session may have multiple display types, so we always handle
11461 SIGINT. There is special code in interrupt_signal to exit
11462 Emacs on SIGINT when there are no termcap frames on the
11463 controlling terminal. */
11068 signal (SIGINT, interrupt_signal); 11464 signal (SIGINT, interrupt_signal);
11069#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) 11465#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
11070 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and 11466 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
@@ -11386,6 +11782,10 @@ syms_of_keyboard ()
11386 defsubr (&Stop_level); 11782 defsubr (&Stop_level);
11387 defsubr (&Sdiscard_input); 11783 defsubr (&Sdiscard_input);
11388 defsubr (&Sopen_dribble_file); 11784 defsubr (&Sopen_dribble_file);
11785 defsubr (&Sset_input_interrupt_mode);
11786 defsubr (&Sset_output_flow_control);
11787 defsubr (&Sset_input_meta_mode);
11788 defsubr (&Sset_quit_char);
11389 defsubr (&Sset_input_mode); 11789 defsubr (&Sset_input_mode);
11390 defsubr (&Scurrent_input_mode); 11790 defsubr (&Scurrent_input_mode);
11391 defsubr (&Sexecute_extended_command); 11791 defsubr (&Sexecute_extended_command);
@@ -11452,7 +11852,10 @@ In other words, the present command is the event that made the previous
11452command exit. 11852command exit.
11453 11853
11454The value `kill-region' is special; it means that the previous command 11854The value `kill-region' is special; it means that the previous command
11455was a kill command. */); 11855was a kill command.
11856
11857`last-command' has a separate binding for each terminal device.
11858See Info node `(elisp)Multiple displays'. */);
11456 11859
11457 DEFVAR_KBOARD ("real-last-command", Vreal_last_command, 11860 DEFVAR_KBOARD ("real-last-command", Vreal_last_command,
11458 doc: /* Same as `last-command', but never altered by Lisp code. */); 11861 doc: /* Same as `last-command', but never altered by Lisp code. */);
@@ -11564,8 +11967,8 @@ for that character after that prefix key. */);
11564Useful to set before you dump a modified Emacs. */); 11967Useful to set before you dump a modified Emacs. */);
11565 Vtop_level = Qnil; 11968 Vtop_level = Qnil;
11566 11969
11567 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table, 11970 DEFVAR_KBOARD ("keyboard-translate-table", Vkeyboard_translate_table,
11568 doc: /* Translate table for keyboard input, or nil. 11971 doc: /* Translate table for local keyboard input, or nil.
11569If non-nil, the value should be a char-table. Each character read 11972If non-nil, the value should be a char-table. Each character read
11570from the keyboard is looked up in this char-table. If the value found 11973from the keyboard is looked up in this char-table. If the value found
11571there is non-nil, then it is used instead of the actual input character. 11974there is non-nil, then it is used instead of the actual input character.
@@ -11575,8 +11978,10 @@ If it is a string or vector of length N, character codes N and up are left
11575untranslated. In a vector, an element which is nil means "no translation". 11978untranslated. In a vector, an element which is nil means "no translation".
11576 11979
11577This is applied to the characters supplied to input methods, not their 11980This is applied to the characters supplied to input methods, not their
11578output. See also `translation-table-for-input'. */); 11981output. See also `translation-table-for-input'.
11579 Vkeyboard_translate_table = Qnil; 11982
11983This variable has a separate binding for each terminal. See Info node
11984`(elisp)Multiple displays'. */);
11580 11985
11581 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend, 11986 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend,
11582 doc: /* Non-nil means to always spawn a subshell instead of suspending. 11987 doc: /* Non-nil means to always spawn a subshell instead of suspending.
@@ -11661,7 +12066,11 @@ buffer's local map, and the minor mode keymaps and text property keymaps.
11661It also replaces `overriding-local-map'. 12066It also replaces `overriding-local-map'.
11662 12067
11663This variable is intended to let commands such as `universal-argument' 12068This variable is intended to let commands such as `universal-argument'
11664set up a different keymap for reading the next command. */); 12069set up a different keymap for reading the next command.
12070
12071`overriding-terminal-local-map' has a separate binding for each
12072terminal device.
12073See Info node `(elisp)Multiple displays'. */);
11665 12074
11666 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map, 12075 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map,
11667 doc: /* Keymap that overrides all other local keymaps. 12076 doc: /* Keymap that overrides all other local keymaps.
@@ -11686,7 +12095,61 @@ and the minor mode maps regardless of `overriding-local-map'. */);
11686 doc: /* Alist of system-specific X windows key symbols. 12095 doc: /* Alist of system-specific X windows key symbols.
11687Each element should have the form (N . SYMBOL) where N is the 12096Each element should have the form (N . SYMBOL) where N is the
11688numeric keysym code (sans the \"system-specific\" bit 1<<28) 12097numeric keysym code (sans the \"system-specific\" bit 1<<28)
11689and SYMBOL is its name. */); 12098and SYMBOL is its name.
12099
12100`system-key-alist' has a separate binding for each terminal device.
12101See Info node `(elisp)Multiple displays'. */);
12102
12103 DEFVAR_KBOARD ("local-function-key-map", Vlocal_function_key_map,
12104 doc: /* Keymap that translates key sequences to key sequences during input.
12105This is used mainly for mapping ASCII function key sequences into
12106real Emacs function key events (symbols).
12107
12108The `read-key-sequence' function replaces any subsequence bound by
12109`local-function-key-map' with its binding. More precisely, when the
12110active keymaps have no binding for the current key sequence but
12111`local-function-key-map' binds a suffix of the sequence to a vector or
12112string, `read-key-sequence' replaces the matching suffix with its
12113binding, and continues with the new sequence.
12114
12115If the binding is a function, it is called with one argument (the prompt)
12116and its return value (a key sequence) is used.
12117
12118The events that come from bindings in `local-function-key-map' are not
12119themselves looked up in `local-function-key-map'.
12120
12121For example, suppose `local-function-key-map' binds `ESC O P' to [f1].
12122Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing
12123`C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix key,
12124typing `ESC O P x' would return [f1 x].
12125
12126`local-function-key-map' has a separate binding for each terminal
12127device. See Info node `(elisp)Multiple displays'. If you need to
12128define a binding on all terminals, change `function-key-map'
12129instead. Initially, `local-function-key-map' is an empty keymap that
12130has `function-key-map' as its parent on all terminal devices. */);
12131
12132 DEFVAR_LISP ("function-key-map", &Vfunction_key_map,
12133 doc: /* The parent keymap of all `local-function-key-map' instances.
12134Function key definitions that apply to all terminal devices should go
12135here. If a mapping is defined in both the current
12136`local-function-key-map' binding and this variable, then the local
12137definition will take precendence. */);
12138 Vfunction_key_map = Fmake_sparse_keymap (Qnil);
12139
12140 DEFVAR_KBOARD ("local-key-translation-map", Vlocal_key_translation_map,
12141 doc: /* Keymap of key translations that can override keymaps.
12142This keymap works like `function-key-map', but comes after that,
12143and its non-prefix bindings override ordinary bindings.
12144
12145`key-translation-map' has a separate binding for each terminal device.
12146(See Info node `(elisp)Multiple displays'.) If you need to set a key
12147translation on all terminals, change `global-key-translation-map' instead. */);
12148
12149 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map,
12150 doc: /* The parent keymap of all `local-key-translation-map' instances.
12151Key translations that apply to all terminal devices should go here. */);
12152 Vkey_translation_map = Fmake_sparse_keymap (Qnil);
11690 12153
11691 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list, 12154 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list,
11692 doc: /* List of deferred actions to be performed at a later time. 12155 doc: /* List of deferred actions to be performed at a later time.
@@ -11855,6 +12318,7 @@ mark_kboards ()
11855 mark_object (kb->Voverriding_terminal_local_map); 12318 mark_object (kb->Voverriding_terminal_local_map);
11856 mark_object (kb->Vlast_command); 12319 mark_object (kb->Vlast_command);
11857 mark_object (kb->Vreal_last_command); 12320 mark_object (kb->Vreal_last_command);
12321 mark_object (kb->Vkeyboard_translate_table);
11858 mark_object (kb->Vprefix_arg); 12322 mark_object (kb->Vprefix_arg);
11859 mark_object (kb->Vlast_prefix_arg); 12323 mark_object (kb->Vlast_prefix_arg);
11860 mark_object (kb->kbd_queue); 12324 mark_object (kb->kbd_queue);
@@ -11862,6 +12326,8 @@ mark_kboards ()
11862 mark_object (kb->Vlast_kbd_macro); 12326 mark_object (kb->Vlast_kbd_macro);
11863 mark_object (kb->Vsystem_key_alist); 12327 mark_object (kb->Vsystem_key_alist);
11864 mark_object (kb->system_key_syms); 12328 mark_object (kb->system_key_syms);
12329 mark_object (kb->Vlocal_function_key_map);
12330 mark_object (kb->Vlocal_key_translation_map);
11865 mark_object (kb->Vdefault_minibuffer_frame); 12331 mark_object (kb->Vdefault_minibuffer_frame);
11866 mark_object (kb->echo_string); 12332 mark_object (kb->echo_string);
11867 } 12333 }