aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/keyboard.c176
1 files changed, 128 insertions, 48 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index 3c5ebbb9b8d..4bad07131d6 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -317,7 +317,10 @@ int last_auto_save;
317/* The command being executed by the command loop. 317/* The command being executed by the command loop.
318 Commands may set this, and the value set will be copied into 318 Commands may set this, and the value set will be copied into
319 current_kboard->Vlast_command instead of the actual command. */ 319 current_kboard->Vlast_command instead of the actual command. */
320Lisp_Object this_command; 320Lisp_Object Vthis_command;
321
322/* This is like Vthis_command, except that commands never set it. */
323Lisp_Object real_this_command;
321 324
322/* The value of point when the last command was executed. */ 325/* The value of point when the last command was executed. */
323int last_point_position; 326int last_point_position;
@@ -368,6 +371,10 @@ extern Lisp_Object Vkey_translation_map;
368Lisp_Object Vinput_method_function; 371Lisp_Object Vinput_method_function;
369Lisp_Object Qinput_method_function; 372Lisp_Object Qinput_method_function;
370 373
374/* When we call Vinput_method_function,
375 this holds the echo area message that was just erased. */
376Lisp_Object Vinput_method_previous_message;
377
371/* Non-nil means deactivate the mark at end of this command. */ 378/* Non-nil means deactivate the mark at end of this command. */
372Lisp_Object Vdeactivate_mark; 379Lisp_Object Vdeactivate_mark;
373 380
@@ -396,6 +403,9 @@ Lisp_Object Vdeferred_action_list;
396Lisp_Object Vdeferred_action_function; 403Lisp_Object Vdeferred_action_function;
397Lisp_Object Qdeferred_action_function; 404Lisp_Object Qdeferred_action_function;
398 405
406Lisp_Object Qinput_method_exit_on_first_char;
407Lisp_Object Qinput_method_use_echo_area;
408
399/* File in which we write all commands we read. */ 409/* File in which we write all commands we read. */
400FILE *dribble; 410FILE *dribble;
401 411
@@ -1185,8 +1195,8 @@ command_loop_1 ()
1185 } 1195 }
1186 1196
1187 /* Do this after running Vpost_command_hook, for consistency. */ 1197 /* Do this after running Vpost_command_hook, for consistency. */
1188 current_kboard->Vlast_command = this_command; 1198 current_kboard->Vlast_command = Vthis_command;
1189 current_kboard->Vreal_last_command = this_command; 1199 current_kboard->Vreal_last_command = real_this_command;
1190 1200
1191 while (1) 1201 while (1)
1192 { 1202 {
@@ -1253,7 +1263,8 @@ command_loop_1 ()
1253 before_command_key_count = this_command_key_count; 1263 before_command_key_count = this_command_key_count;
1254 before_command_echo_length = echo_length (); 1264 before_command_echo_length = echo_length ();
1255 1265
1256 this_command = Qnil; 1266 Vthis_command = Qnil;
1267 real_this_command = Qnil;
1257 1268
1258 /* Read next key sequence; i gets its length. */ 1269 /* Read next key sequence; i gets its length. */
1259 i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0], 1270 i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0],
@@ -1318,13 +1329,14 @@ command_loop_1 ()
1318 1329
1319 /* Execute the command. */ 1330 /* Execute the command. */
1320 1331
1321 this_command = cmd; 1332 Vthis_command = cmd;
1333 real_this_command = cmd;
1322 /* Note that the value cell will never directly contain nil 1334 /* Note that the value cell will never directly contain nil
1323 if the symbol is a local variable. */ 1335 if the symbol is a local variable. */
1324 if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks)) 1336 if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks))
1325 safe_run_hooks (Qpre_command_hook); 1337 safe_run_hooks (Qpre_command_hook);
1326 1338
1327 if (NILP (this_command)) 1339 if (NILP (Vthis_command))
1328 { 1340 {
1329 /* nil means key is undefined. */ 1341 /* nil means key is undefined. */
1330 bitch_at_user (); 1342 bitch_at_user ();
@@ -1341,7 +1353,7 @@ command_loop_1 ()
1341 1353
1342 /* Recognize some common commands in common situations and 1354 /* Recognize some common commands in common situations and
1343 do them directly. */ 1355 do them directly. */
1344 if (EQ (this_command, Qforward_char) && PT < ZV) 1356 if (EQ (Vthis_command, Qforward_char) && PT < ZV)
1345 { 1357 {
1346 struct Lisp_Char_Table *dp 1358 struct Lisp_Char_Table *dp
1347 = window_display_table (XWINDOW (selected_window)); 1359 = window_display_table (XWINDOW (selected_window));
@@ -1370,7 +1382,7 @@ command_loop_1 ()
1370 no_redisplay = direct_output_forward_char (1); 1382 no_redisplay = direct_output_forward_char (1);
1371 goto directly_done; 1383 goto directly_done;
1372 } 1384 }
1373 else if (EQ (this_command, Qbackward_char) && PT > BEGV) 1385 else if (EQ (Vthis_command, Qbackward_char) && PT > BEGV)
1374 { 1386 {
1375 struct Lisp_Char_Table *dp 1387 struct Lisp_Char_Table *dp
1376 = window_display_table (XWINDOW (selected_window)); 1388 = window_display_table (XWINDOW (selected_window));
@@ -1396,7 +1408,7 @@ command_loop_1 ()
1396 no_redisplay = direct_output_forward_char (-1); 1408 no_redisplay = direct_output_forward_char (-1);
1397 goto directly_done; 1409 goto directly_done;
1398 } 1410 }
1399 else if (EQ (this_command, Qself_insert_command) 1411 else if (EQ (Vthis_command, Qself_insert_command)
1400 /* Try this optimization only on ascii keystrokes. */ 1412 /* Try this optimization only on ascii keystrokes. */
1401 && INTEGERP (last_command_char)) 1413 && INTEGERP (last_command_char))
1402 { 1414 {
@@ -1480,7 +1492,7 @@ command_loop_1 ()
1480 nonundocount = 0; 1492 nonundocount = 0;
1481 if (NILP (current_kboard->Vprefix_arg)) 1493 if (NILP (current_kboard->Vprefix_arg))
1482 Fundo_boundary (); 1494 Fundo_boundary ();
1483 Fcommand_execute (this_command, Qnil, Qnil, Qnil); 1495 Fcommand_execute (Vthis_command, Qnil, Qnil, Qnil);
1484 } 1496 }
1485 directly_done: ; 1497 directly_done: ;
1486 current_kboard->Vlast_prefix_arg = Vcurrent_prefix_arg; 1498 current_kboard->Vlast_prefix_arg = Vcurrent_prefix_arg;
@@ -1518,8 +1530,8 @@ command_loop_1 ()
1518 then the above doesn't apply. */ 1530 then the above doesn't apply. */
1519 if (NILP (current_kboard->Vprefix_arg) || CONSP (last_command_char)) 1531 if (NILP (current_kboard->Vprefix_arg) || CONSP (last_command_char))
1520 { 1532 {
1521 current_kboard->Vlast_command = this_command; 1533 current_kboard->Vlast_command = Vthis_command;
1522 current_kboard->Vreal_last_command = this_command; 1534 current_kboard->Vreal_last_command = real_this_command;
1523 cancel_echoing (); 1535 cancel_echoing ();
1524 this_command_key_count = 0; 1536 this_command_key_count = 0;
1525 this_single_command_key_start = 0; 1537 this_single_command_key_start = 0;
@@ -1788,17 +1800,19 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
1788 jmp_buf save_jump; 1800 jmp_buf save_jump;
1789 int key_already_recorded = 0; 1801 int key_already_recorded = 0;
1790 Lisp_Object tem, save; 1802 Lisp_Object tem, save;
1803 Lisp_Object echo_area_message;
1791 Lisp_Object also_record; 1804 Lisp_Object also_record;
1792 int reread; 1805 int reread;
1793 struct gcpro gcpro1; 1806 struct gcpro gcpro1, gcpro2;
1794 1807
1795 also_record = Qnil; 1808 also_record = Qnil;
1796 1809
1797 before_command_key_count = this_command_key_count; 1810 before_command_key_count = this_command_key_count;
1798 before_command_echo_length = echo_length (); 1811 before_command_echo_length = echo_length ();
1799 c = Qnil; 1812 c = Qnil;
1813 echo_area_message = Qnil;
1800 1814
1801 GCPRO1 (c); 1815 GCPRO2 (c, echo_area_message);
1802 1816
1803 retry: 1817 retry:
1804 1818
@@ -2274,11 +2288,6 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
2274 goto retry; 2288 goto retry;
2275 } 2289 }
2276 2290
2277 /* Wipe the echo area. */
2278 if (echo_area_glyphs)
2279 safe_run_hooks (Qecho_area_clear_hook);
2280 echo_area_glyphs = 0;
2281
2282 /* Handle things that only apply to characters. */ 2291 /* Handle things that only apply to characters. */
2283 if (INTEGERP (c)) 2292 if (INTEGERP (c))
2284 { 2293 {
@@ -2331,27 +2340,53 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
2331 if (! NILP (also_record)) 2340 if (! NILP (also_record))
2332 record_char (also_record); 2341 record_char (also_record);
2333 2342
2343 /* Wipe the echo area.
2344 But first, if we are about to use an input method,
2345 save the echo area contents for it to refer to. */
2346 if (INTEGERP (c)
2347 && ! NILP (Vinput_method_function)
2348 && (unsigned) XINT (c) >= ' '
2349 && (unsigned) XINT (c) < 127)
2350 Vinput_method_previous_message = echo_area_message = Fcurrent_message ();
2351
2352 /* Now wipe the echo area. */
2353 if (echo_area_glyphs)
2354 safe_run_hooks (Qecho_area_clear_hook);
2355 echo_area_glyphs = 0;
2356
2334 reread_for_input_method: 2357 reread_for_input_method:
2335 from_macro: 2358 from_macro:
2336 /* Pass this to the input method, if appropriate. */ 2359 /* Pass this to the input method, if appropriate. */
2337 if (INTEGERP (c)) 2360 if (INTEGERP (c)
2338 { 2361 && ! NILP (Vinput_method_function)
2339 /* If this is a printing character, run the input method. */ 2362 && (unsigned) XINT (c) >= ' '
2340 if (! NILP (Vinput_method_function) 2363 && (unsigned) XINT (c) < 127)
2341 && (unsigned) XINT (c) >= ' ' 2364 {
2342 && (unsigned) XINT (c) < 127) 2365 Lisp_Object keys;
2366 int key_count = this_command_key_count - 1;
2367 int saved = current_kboard->immediate_echo;
2368 struct gcpro gcpro1;
2369
2370 keys = Fcopy_sequence (this_command_keys);
2371 GCPRO1 (keys);
2372 tem = call1 (Vinput_method_function, c);
2373 UNGCPRO;
2374 current_kboard->immediate_echo = saved;
2375 /* The input method can return no events. */
2376 if (! CONSP (tem))
2343 { 2377 {
2344 int saved = current_kboard->immediate_echo; 2378 /* Bring back the previous message, if any. */
2345 tem = call1 (Vinput_method_function, c); 2379 if (! NILP (Vinput_method_previous_message))
2346 current_kboard->immediate_echo = saved; 2380 message_with_string ("%s", echo_area_message, 0);
2347 /* The input method can return no events. */ 2381 this_command_keys = keys;
2348 if (! CONSP (tem)) 2382 this_command_key_count = key_count;
2349 goto retry; 2383 cancel_echoing ();
2350 /* It returned one event or more. */ 2384 goto retry;
2351 c = XCONS (tem)->car;
2352 Vunread_post_input_method_events
2353 = nconc2 (XCONS (tem)->cdr, Vunread_post_input_method_events);
2354 } 2385 }
2386 /* It returned one event or more. */
2387 c = XCONS (tem)->car;
2388 Vunread_post_input_method_events
2389 = nconc2 (XCONS (tem)->cdr, Vunread_post_input_method_events);
2355 } 2390 }
2356 2391
2357 reread_first: 2392 reread_first:
@@ -7611,24 +7646,36 @@ is nil, then the event will be put off until after the current key sequence.\n\
7611\n\ 7646\n\
7612`read-key-sequence' checks `function-key-map' for function key\n\ 7647`read-key-sequence' checks `function-key-map' for function key\n\
7613sequences, where they wouldn't conflict with ordinary bindings. See\n\ 7648sequences, where they wouldn't conflict with ordinary bindings. See\n\
7614`function-key-map' for more details.") 7649`function-key-map' for more details.\n\
7650\n\
7651The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
7652that this key sequence is being read by something that will\n\
7653read commands one after another. It should be nil if the caller\n\
7654will read just one key sequence.")
7615 (prompt, continue_echo, dont_downcase_last, can_return_switch_frame) 7655 (prompt, continue_echo, dont_downcase_last, can_return_switch_frame)
7616#endif 7656#endif
7617 7657
7618DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 4, 0, 7658DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0,
7619 0) 7659 0)
7620 (prompt, continue_echo, dont_downcase_last, can_return_switch_frame) 7660 (prompt, continue_echo, dont_downcase_last, can_return_switch_frame,
7661 command_loop)
7621 Lisp_Object prompt, continue_echo, dont_downcase_last; 7662 Lisp_Object prompt, continue_echo, dont_downcase_last;
7622 Lisp_Object can_return_switch_frame; 7663 Lisp_Object can_return_switch_frame, command_loop;
7623{ 7664{
7624 Lisp_Object keybuf[30]; 7665 Lisp_Object keybuf[30];
7625 register int i; 7666 register int i;
7626 struct gcpro gcpro1, gcpro2; 7667 struct gcpro gcpro1, gcpro2;
7668 int count = specpdl_ptr - specpdl;
7627 7669
7628 if (!NILP (prompt)) 7670 if (!NILP (prompt))
7629 CHECK_STRING (prompt, 0); 7671 CHECK_STRING (prompt, 0);
7630 QUIT; 7672 QUIT;
7631 7673
7674 specbind (Qinput_method_exit_on_first_char,
7675 (NILP (command_loop) ? Qt : Qnil));
7676 specbind (Qinput_method_use_echo_area,
7677 (NILP (command_loop) ? Qt : Qnil));
7678
7632 bzero (keybuf, sizeof keybuf); 7679 bzero (keybuf, sizeof keybuf);
7633 GCPRO1 (keybuf[0]); 7680 GCPRO1 (keybuf[0]);
7634 gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); 7681 gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0]));
@@ -7649,24 +7696,31 @@ DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 4, 0,
7649 QUIT; 7696 QUIT;
7650 } 7697 }
7651 UNGCPRO; 7698 UNGCPRO;
7652 return make_event_array (i, keybuf); 7699 return unbind_to (count, make_event_array (i, keybuf));
7653} 7700}
7654 7701
7655DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector, 7702DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector,
7656 Sread_key_sequence_vector, 1, 4, 0, 7703 Sread_key_sequence_vector, 1, 5, 0,
7657 "Like `read-key-sequence' but always return a vector.") 7704 "Like `read-key-sequence' but always return a vector.")
7658 (prompt, continue_echo, dont_downcase_last, can_return_switch_frame) 7705 (prompt, continue_echo, dont_downcase_last, can_return_switch_frame,
7706 command_loop)
7659 Lisp_Object prompt, continue_echo, dont_downcase_last; 7707 Lisp_Object prompt, continue_echo, dont_downcase_last;
7660 Lisp_Object can_return_switch_frame; 7708 Lisp_Object can_return_switch_frame, command_loop;
7661{ 7709{
7662 Lisp_Object keybuf[30]; 7710 Lisp_Object keybuf[30];
7663 register int i; 7711 register int i;
7664 struct gcpro gcpro1, gcpro2; 7712 struct gcpro gcpro1, gcpro2;
7713 int count = specpdl_ptr - specpdl;
7665 7714
7666 if (!NILP (prompt)) 7715 if (!NILP (prompt))
7667 CHECK_STRING (prompt, 0); 7716 CHECK_STRING (prompt, 0);
7668 QUIT; 7717 QUIT;
7669 7718
7719 specbind (Qinput_method_exit_on_first_char,
7720 (NILP (command_loop) ? Qt : Qnil));
7721 specbind (Qinput_method_use_echo_area,
7722 (NILP (command_loop) ? Qt : Qnil));
7723
7670 bzero (keybuf, sizeof keybuf); 7724 bzero (keybuf, sizeof keybuf);
7671 GCPRO1 (keybuf[0]); 7725 GCPRO1 (keybuf[0]);
7672 gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0])); 7726 gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0]));
@@ -7687,7 +7741,7 @@ DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector,
7687 QUIT; 7741 QUIT;
7688 } 7742 }
7689 UNGCPRO; 7743 UNGCPRO;
7690 return Fvector (i, keybuf); 7744 return unbind_to (count, Fvector (i, keybuf));
7691} 7745}
7692 7746
7693DEFUN ("command-execute", Fcommand_execute, Scommand_execute, 1, 4, 0, 7747DEFUN ("command-execute", Fcommand_execute, Scommand_execute, 1, 4, 0,
@@ -7870,7 +7924,8 @@ DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_
7870 7924
7871 function = Fintern (function, Qnil); 7925 function = Fintern (function, Qnil);
7872 current_kboard->Vprefix_arg = prefixarg; 7926 current_kboard->Vprefix_arg = prefixarg;
7873 this_command = function; 7927 Vthis_command = function;
7928 real_this_command = function;
7874 7929
7875 /* If enabled, show which key runs this command. */ 7930 /* If enabled, show which key runs this command. */
7876 if (!NILP (Vsuggest_key_bindings) 7931 if (!NILP (Vsuggest_key_bindings)
@@ -8736,6 +8791,9 @@ syms_of_keyboard ()
8736 staticpro (&item_properties); 8791 staticpro (&item_properties);
8737 item_properties = Qnil; 8792 item_properties = Qnil;
8738 8793
8794 staticpro (&real_this_command);
8795 real_this_command = Qnil;
8796
8739 Qtimer_event_handler = intern ("timer-event-handler"); 8797 Qtimer_event_handler = intern ("timer-event-handler");
8740 staticpro (&Qtimer_event_handler); 8798 staticpro (&Qtimer_event_handler);
8741 8799
@@ -8844,6 +8902,14 @@ syms_of_keyboard ()
8844 Qinput_method_function = intern ("input-method-function"); 8902 Qinput_method_function = intern ("input-method-function");
8845 staticpro (&Qinput_method_function); 8903 staticpro (&Qinput_method_function);
8846 8904
8905 Qinput_method_exit_on_first_char = intern ("input-method-exit-on-first-char");
8906 staticpro (&Qinput_method_exit_on_first_char);
8907 Qinput_method_use_echo_area = intern ("input-method-use-echo-area");
8908 staticpro (&Qinput_method_use_echo_area);
8909
8910 Fset (Qinput_method_exit_on_first_char, Qnil);
8911 Fset (Qinput_method_use_echo_area, Qnil);
8912
8847 { 8913 {
8848 struct event_head *p; 8914 struct event_head *p;
8849 8915
@@ -9000,11 +9066,11 @@ was a kill command.");
9000 DEFVAR_KBOARD ("real-last-command", Vreal_last_command, 9066 DEFVAR_KBOARD ("real-last-command", Vreal_last_command,
9001 "Same as `last-command', but never altered by Lisp code."); 9067 "Same as `last-command', but never altered by Lisp code.");
9002 9068
9003 DEFVAR_LISP ("this-command", &this_command, 9069 DEFVAR_LISP ("this-command", &Vthis_command,
9004 "The command now being executed.\n\ 9070 "The command now being executed.\n\
9005The command can set this variable; whatever is put here\n\ 9071The command can set this variable; whatever is put here\n\
9006will be in `last-command' during the following command."); 9072will be in `last-command' during the following command.");
9007 this_command = Qnil; 9073 Vthis_command = Qnil;
9008 9074
9009 DEFVAR_INT ("auto-save-interval", &auto_save_interval, 9075 DEFVAR_INT ("auto-save-interval", &auto_save_interval,
9010 "*Number of keyboard input characters between auto-saves.\n\ 9076 "*Number of keyboard input characters between auto-saves.\n\
@@ -9247,8 +9313,22 @@ so it will not be called recursively.\n\
9247The function should return a list of zero or more events\n\ 9313The function should return a list of zero or more events\n\
9248to be used as input. If it wants to put back some events\n\ 9314to be used as input. If it wants to put back some events\n\
9249to be reconsidered, separately, by the input method,\n\ 9315to be reconsidered, separately, by the input method,\n\
9250it can add them to the beginning of `unread-command-events'."); 9316it can add them to the beginning of `unread-command-events'.\n\
9317\n\
9318The input method function can find in `input-method-previous-method'\n\
9319the previous echo area message.\n\
9320\n\
9321The input method function should refer to the variables\n\
9322`input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
9323for guidance on what to do.");
9251 Vinput_method_function = Qnil; 9324 Vinput_method_function = Qnil;
9325
9326 DEFVAR_LISP ("input-method-previous-message",
9327 &Vinput_method_previous_message,
9328 "When `input-mehod-function' is called, hold the previous echo area message.\n\
9329This variable exists because `read-event' clears the echo area\n\
9330before running the input method. It is nil if there was no message.");
9331 Vinput_method_previous_message = Qnil;
9252} 9332}
9253 9333
9254void 9334void