aboutsummaryrefslogtreecommitdiffstats
path: root/src/keyboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keyboard.c')
-rw-r--r--src/keyboard.c128
1 files changed, 80 insertions, 48 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index 025c8a3f85c..08b352c3c3a 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -238,6 +238,9 @@ static int inhibit_local_menu_bar_menus;
238/* Nonzero means C-g should cause immediate error-signal. */ 238/* Nonzero means C-g should cause immediate error-signal. */
239int immediate_quit; 239int immediate_quit;
240 240
241/* The user's hook function for outputting an error message. */
242Lisp_Object Vcommand_error_function;
243
241/* The user's ERASE setting. */ 244/* The user's ERASE setting. */
242Lisp_Object Vtty_erase_char; 245Lisp_Object Vtty_erase_char;
243 246
@@ -682,8 +685,6 @@ static void timer_start_idle P_ ((void));
682static void timer_stop_idle P_ ((void)); 685static void timer_stop_idle P_ ((void));
683static void timer_resume_idle P_ ((void)); 686static void timer_resume_idle P_ ((void));
684 687
685Lisp_Object read_char P_ ((int, int, Lisp_Object *, Lisp_Object, int *));
686
687/* Nonzero means don't try to suspend even if the operating system seems 688/* Nonzero means don't try to suspend even if the operating system seems
688 to support it. */ 689 to support it. */
689static int cannot_suspend; 690static int cannot_suspend;
@@ -990,7 +991,7 @@ recursive_edit_1 ()
990 /* Handle throw from read_minibuf when using minibuffer 991 /* Handle throw from read_minibuf when using minibuffer
991 while it's active but we're in another window. */ 992 while it's active but we're in another window. */
992 if (STRINGP (val)) 993 if (STRINGP (val))
993 Fsignal (Qerror, Fcons (val, Qnil)); 994 xsignal1 (Qerror, val);
994 995
995 return unbind_to (count, Qnil); 996 return unbind_to (count, Qnil);
996} 997}
@@ -1185,11 +1186,12 @@ temporarily_switch_to_single_kboard (f)
1185 { 1186 {
1186 if (f != NULL && FRAME_KBOARD (f) != current_kboard) 1187 if (f != NULL && FRAME_KBOARD (f) != current_kboard)
1187 /* We can not switch keyboards while in single_kboard mode. 1188 /* We can not switch keyboards while in single_kboard mode.
1188 This can legally happen when Lisp code calls 1189 In rare cases, Lisp code may call `recursive-edit' (or
1189 `recursive-edit' (or `read-minibuffer' or `y-or-n-p') after 1190 `read-minibuffer' or `y-or-n-p') after it switched to a
1190 it switched to a locked frame. This kind of situation is 1191 locked frame. For example, this is likely to happen
1191 likely to happen when server.el connects to a new 1192 when server.el connects to a new terminal while Emacs is in
1192 terminal. */ 1193 single_kboard mode. It is best to throw an error instead
1194 of presenting the user with a frozen screen. */
1193 error ("Terminal %d is locked, cannot read from it", 1195 error ("Terminal %d is locked, cannot read from it",
1194 FRAME_TERMINAL (f)->id); 1196 FRAME_TERMINAL (f)->id);
1195 else 1197 else
@@ -1304,48 +1306,43 @@ cmd_error_internal (data, context)
1304 Lisp_Object data; 1306 Lisp_Object data;
1305 char *context; 1307 char *context;
1306{ 1308{
1307 Lisp_Object stream;
1308 int kill_emacs_p = 0;
1309 struct frame *sf = SELECTED_FRAME (); 1309 struct frame *sf = SELECTED_FRAME ();
1310 1310
1311 /* The immediate context is not interesting for Quits,
1312 since they are asyncronous. */
1313 if (EQ (XCAR (data), Qquit))
1314 Vsignaling_function = Qnil;
1315
1311 Vquit_flag = Qnil; 1316 Vquit_flag = Qnil;
1312 Vinhibit_quit = Qt; 1317 Vinhibit_quit = Qt;
1313 clear_message (1, 0);
1314 1318
1319 /* Use user's specified output function if any. */
1320 if (!NILP (Vcommand_error_function))
1321 call3 (Vcommand_error_function, data,
1322 build_string (context ? context : ""),
1323 Vsignaling_function);
1315 /* If the window system or terminal frame hasn't been initialized 1324 /* If the window system or terminal frame hasn't been initialized
1316 yet, or we're not interactive, it's best to dump this message out 1325 yet, or we're not interactive, write the message to stderr and exit. */
1317 to stderr and exit. */ 1326 else if (!sf->glyphs_initialized_p
1318 if (!sf->glyphs_initialized_p 1327 || FRAME_INITIAL_P (sf)
1319 || FRAME_INITIAL_P (sf) 1328 || noninteractive)
1320 || noninteractive) 1329 {
1321 { 1330 print_error_message (data, Qexternal_debugging_output,
1322 stream = Qexternal_debugging_output; 1331 context, Vsignaling_function);
1323 kill_emacs_p = 1; 1332 Fterpri (Qexternal_debugging_output);
1333 Fkill_emacs (make_number (-1));
1324 } 1334 }
1325 else 1335 else
1326 { 1336 {
1337 clear_message (1, 0);
1327 Fdiscard_input (); 1338 Fdiscard_input ();
1328 message_log_maybe_newline (); 1339 message_log_maybe_newline ();
1329 bitch_at_user (); 1340 bitch_at_user ();
1330 stream = Qt;
1331 }
1332
1333 /* The immediate context is not interesting for Quits,
1334 since they are asyncronous. */
1335 if (EQ (XCAR (data), Qquit))
1336 Vsignaling_function = Qnil;
1337 1341
1338 print_error_message (data, stream, context, Vsignaling_function); 1342 print_error_message (data, Qt, context, Vsignaling_function);
1343 }
1339 1344
1340 Vsignaling_function = Qnil; 1345 Vsignaling_function = Qnil;
1341
1342 /* If the window system or terminal frame hasn't been initialized
1343 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1344 if (kill_emacs_p)
1345 {
1346 Fterpri (stream);
1347 Fkill_emacs (make_number (-1));
1348 }
1349} 1346}
1350 1347
1351Lisp_Object command_loop_1 (); 1348Lisp_Object command_loop_1 ();
@@ -2470,15 +2467,20 @@ do { if (polling_stopped_here) start_polling (); \
2470 Value is -2 when we find input on another keyboard. A second call 2467 Value is -2 when we find input on another keyboard. A second call
2471 to read_char will read it. 2468 to read_char will read it.
2472 2469
2470 If END_TIME is non-null, it is a pointer to an EMACS_TIME
2471 specifying the maximum time to wait until. If no input arrives by
2472 that time, stop waiting and return nil.
2473
2473 Value is t if we showed a menu and the user rejected it. */ 2474 Value is t if we showed a menu and the user rejected it. */
2474 2475
2475Lisp_Object 2476Lisp_Object
2476read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu) 2477read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2477 int commandflag; 2478 int commandflag;
2478 int nmaps; 2479 int nmaps;
2479 Lisp_Object *maps; 2480 Lisp_Object *maps;
2480 Lisp_Object prev_event; 2481 Lisp_Object prev_event;
2481 int *used_mouse_menu; 2482 int *used_mouse_menu;
2483 EMACS_TIME *end_time;
2482{ 2484{
2483 volatile Lisp_Object c; 2485 volatile Lisp_Object c;
2484 int count; 2486 int count;
@@ -2764,6 +2766,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
2764 start echoing if enough time elapses. */ 2766 start echoing if enough time elapses. */
2765 2767
2766 if (minibuf_level == 0 2768 if (minibuf_level == 0
2769 && !end_time
2767 && !current_kboard->immediate_echo 2770 && !current_kboard->immediate_echo
2768 && this_command_key_count > 0 2771 && this_command_key_count > 0
2769 && ! noninteractive 2772 && ! noninteractive
@@ -2959,11 +2962,19 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
2959 { 2962 {
2960 KBOARD *kb; 2963 KBOARD *kb;
2961 2964
2965 if (end_time)
2966 {
2967 EMACS_TIME now;
2968 EMACS_GET_TIME (now);
2969 if (EMACS_TIME_GE (now, *end_time))
2970 goto exit;
2971 }
2972
2962 /* Actually read a character, waiting if necessary. */ 2973 /* Actually read a character, waiting if necessary. */
2963 save_getcjmp (save_jump); 2974 save_getcjmp (save_jump);
2964 restore_getcjmp (local_getcjmp); 2975 restore_getcjmp (local_getcjmp);
2965 timer_start_idle (); 2976 timer_start_idle ();
2966 c = kbd_buffer_get_event (&kb, used_mouse_menu); 2977 c = kbd_buffer_get_event (&kb, used_mouse_menu, end_time);
2967 restore_getcjmp (save_jump); 2978 restore_getcjmp (save_jump);
2968 2979
2969#ifdef MULTI_KBOARD 2980#ifdef MULTI_KBOARD
@@ -3307,7 +3318,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
3307 3318
3308 cancel_echoing (); 3319 cancel_echoing ();
3309 do 3320 do
3310 c = read_char (0, 0, 0, Qnil, 0); 3321 c = read_char (0, 0, 0, Qnil, 0, NULL);
3311 while (BUFFERP (c)); 3322 while (BUFFERP (c));
3312 /* Remove the help from the frame */ 3323 /* Remove the help from the frame */
3313 unbind_to (count, Qnil); 3324 unbind_to (count, Qnil);
@@ -3317,7 +3328,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
3317 { 3328 {
3318 cancel_echoing (); 3329 cancel_echoing ();
3319 do 3330 do
3320 c = read_char (0, 0, 0, Qnil, 0); 3331 c = read_char (0, 0, 0, Qnil, 0, NULL);
3321 while (BUFFERP (c)); 3332 while (BUFFERP (c));
3322 } 3333 }
3323 } 3334 }
@@ -3994,9 +4005,10 @@ clear_event (event)
3994 We always read and discard one event. */ 4005 We always read and discard one event. */
3995 4006
3996static Lisp_Object 4007static Lisp_Object
3997kbd_buffer_get_event (kbp, used_mouse_menu) 4008kbd_buffer_get_event (kbp, used_mouse_menu, end_time)
3998 KBOARD **kbp; 4009 KBOARD **kbp;
3999 int *used_mouse_menu; 4010 int *used_mouse_menu;
4011 EMACS_TIME *end_time;
4000{ 4012{
4001 register int c; 4013 register int c;
4002 Lisp_Object obj; 4014 Lisp_Object obj;
@@ -4040,13 +4052,24 @@ kbd_buffer_get_event (kbp, used_mouse_menu)
4040 if (!NILP (do_mouse_tracking) && some_mouse_moved ()) 4052 if (!NILP (do_mouse_tracking) && some_mouse_moved ())
4041 break; 4053 break;
4042#endif 4054#endif
4043 { 4055 if (end_time)
4056 {
4057 EMACS_TIME duration;
4058 EMACS_GET_TIME (duration);
4059 EMACS_SUB_TIME (duration, *end_time, duration);
4060 if (EMACS_TIME_NEG_P (duration))
4061 return Qnil;
4062 else
4063 wait_reading_process_output (EMACS_SECS (duration),
4064 EMACS_USECS (duration),
4065 -1, 1, Qnil, NULL, 0);
4066 }
4067 else
4044 wait_reading_process_output (0, 0, -1, 1, Qnil, NULL, 0); 4068 wait_reading_process_output (0, 0, -1, 1, Qnil, NULL, 0);
4045 4069
4046 if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr) 4070 if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr)
4047 /* Pass 1 for EXPECT since we just waited to have input. */ 4071 /* Pass 1 for EXPECT since we just waited to have input. */
4048 read_avail_input (1); 4072 read_avail_input (1);
4049 }
4050#endif /* not VMS */ 4073#endif /* not VMS */
4051 } 4074 }
4052 4075
@@ -8469,7 +8492,7 @@ read_char_minibuf_menu_prompt (commandflag, nmaps, maps)
8469 orig_defn_macro = current_kboard->defining_kbd_macro; 8492 orig_defn_macro = current_kboard->defining_kbd_macro;
8470 current_kboard->defining_kbd_macro = Qnil; 8493 current_kboard->defining_kbd_macro = Qnil;
8471 do 8494 do
8472 obj = read_char (commandflag, 0, 0, Qt, 0); 8495 obj = read_char (commandflag, 0, 0, Qt, 0, NULL);
8473 while (BUFFERP (obj)); 8496 while (BUFFERP (obj));
8474 current_kboard->defining_kbd_macro = orig_defn_macro; 8497 current_kboard->defining_kbd_macro = orig_defn_macro;
8475 8498
@@ -8839,7 +8862,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
8839 /* Read the first char of the sequence specially, before setting 8862 /* Read the first char of the sequence specially, before setting
8840 up any keymaps, in case a filter runs and switches buffers on us. */ 8863 up any keymaps, in case a filter runs and switches buffers on us. */
8841 first_event = read_char (NILP (prompt), 0, submaps, last_nonmenu_event, 8864 first_event = read_char (NILP (prompt), 0, submaps, last_nonmenu_event,
8842 &junk); 8865 &junk, NULL);
8843#endif /* GOBBLE_FIRST_EVENT */ 8866#endif /* GOBBLE_FIRST_EVENT */
8844 8867
8845 orig_local_map = get_local_map (PT, current_buffer, Qlocal_map); 8868 orig_local_map = get_local_map (PT, current_buffer, Qlocal_map);
@@ -9018,7 +9041,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9018#endif 9041#endif
9019 key = read_char (NILP (prompt), nmaps, 9042 key = read_char (NILP (prompt), nmaps,
9020 (Lisp_Object *) submaps, last_nonmenu_event, 9043 (Lisp_Object *) submaps, last_nonmenu_event,
9021 &used_mouse_menu); 9044 &used_mouse_menu, NULL);
9022#ifdef MULTI_KBOARD 9045#ifdef MULTI_KBOARD
9023 if (INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */ 9046 if (INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */
9024 { 9047 {
@@ -11948,6 +11971,15 @@ The value of that variable is passed to `quit-flag' and later causes a
11948peculiar kind of quitting. */); 11971peculiar kind of quitting. */);
11949 Vthrow_on_input = Qnil; 11972 Vthrow_on_input = Qnil;
11950 11973
11974 DEFVAR_LISP ("command-error-function", &Vcommand_error_function,
11975 doc: /* If non-nil, function to output error messages.
11976The arguments are the error data, a list of the form
11977 (SIGNALED-CONDITIONS . SIGNAL-DATA)
11978such as just as `condition-case' would bind its variable to,
11979the context (a string which normally goes at the start of the message),
11980and the Lisp function within which the error was signaled. */);
11981 Vcommand_error_function = Qnil;
11982
11951 DEFVAR_LISP ("enable-disabled-menus-and-buttons", 11983 DEFVAR_LISP ("enable-disabled-menus-and-buttons",
11952 &Venable_disabled_menus_and_buttons, 11984 &Venable_disabled_menus_and_buttons,
11953 doc: /* If non-nil, don't ignore events produced by disabled menu items and tool-bar. 11985 doc: /* If non-nil, don't ignore events produced by disabled menu items and tool-bar.