aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChong Yidong2013-01-06 10:38:04 +0800
committerChong Yidong2013-01-06 10:38:04 +0800
commit56ed110a17fc377f1d0a39eb3f01e4fd03a65709 (patch)
tree829bb687376da76eb07b2983f8cf17ed6b6e327b /src
parent7a2657fa3bedbd977f4e11fe030cb4a210c04ab4 (diff)
downloademacs-56ed110a17fc377f1d0a39eb3f01e4fd03a65709.tar.gz
emacs-56ed110a17fc377f1d0a39eb3f01e4fd03a65709.zip
Fix echoing of replayed keys.
* keyboard.c (echo_add_char): New function, factored out from echo_char. Don't add a space if the previous echo string was empty. (echo_char): Use it. (read_key_sequence): When echoing mock input, ensure that the trailing dash is properly added. Fixes: debbugs:13255
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog9
-rw-r--r--src/keyboard.c146
2 files changed, 87 insertions, 68 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c0c85c15ee9..3b0b295e695 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
12013-01-06 Chong Yidong <cyd@gnu.org>
2
3 * keyboard.c (echo_add_char): New function, factored out from
4 echo_char. Don't add a space if the previous echo string was
5 empty (Bug#13255).
6 (echo_char): Use it.
7 (read_key_sequence): When echoing mock input, ensure that the
8 trailing dash is properly added.
9
12013-01-05 Eli Zaretskii <eliz@gnu.org> 102013-01-05 Eli Zaretskii <eliz@gnu.org>
2 11
3 * xdisp.c (dump_glyph): Align glyph data better. Use "pD" instead 12 * xdisp.c (dump_glyph): Align glyph data better. Use "pD" instead
diff --git a/src/keyboard.c b/src/keyboard.c
index 8edd705135f..bc55eed1f5c 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -497,97 +497,103 @@ kset_system_key_syms (struct kboard *kb, Lisp_Object val)
497} 497}
498 498
499 499
500/* Add C to the echo string, if echoing is going on. 500/* Add C to the echo string, without echoing it immediately. C can be
501 C can be a character, which is printed prettily ("M-C-x" and all that 501 a character, which is pretty-printed, or a symbol, whose name is
502 jazz), or a symbol, whose name is printed. */ 502 printed. */
503 503
504static void 504static void
505echo_char (Lisp_Object c) 505echo_add_char (Lisp_Object c)
506{ 506{
507 if (current_kboard->immediate_echo) 507 int size = KEY_DESCRIPTION_SIZE + 100;
508 { 508 char *buffer = alloca (size);
509 int size = KEY_DESCRIPTION_SIZE + 100; 509 char *ptr = buffer;
510 char *buffer = alloca (size); 510 Lisp_Object echo_string;
511 char *ptr = buffer;
512 Lisp_Object echo_string;
513 511
514 echo_string = KVAR (current_kboard, echo_string); 512 echo_string = KVAR (current_kboard, echo_string);
515 513
516 /* If someone has passed us a composite event, use its head symbol. */ 514 /* If someone has passed us a composite event, use its head symbol. */
517 c = EVENT_HEAD (c); 515 c = EVENT_HEAD (c);
518 516
519 if (INTEGERP (c)) 517 if (INTEGERP (c))
518 ptr = push_key_description (XINT (c), ptr);
519 else if (SYMBOLP (c))
520 {
521 Lisp_Object name = SYMBOL_NAME (c);
522 int nbytes = SBYTES (name);
523
524 if (size - (ptr - buffer) < nbytes)
520 { 525 {
521 ptr = push_key_description (XINT (c), ptr); 526 int offset = ptr - buffer;
527 size = max (2 * size, size + nbytes);
528 buffer = alloca (size);
529 ptr = buffer + offset;
522 } 530 }
523 else if (SYMBOLP (c))
524 {
525 Lisp_Object name = SYMBOL_NAME (c);
526 int nbytes = SBYTES (name);
527 531
528 if (size - (ptr - buffer) < nbytes) 532 ptr += copy_text (SDATA (name), (unsigned char *) ptr, nbytes,
529 { 533 STRING_MULTIBYTE (name), 1);
530 int offset = ptr - buffer; 534 }
531 size = max (2 * size, size + nbytes);
532 buffer = alloca (size);
533 ptr = buffer + offset;
534 }
535 535
536 ptr += copy_text (SDATA (name), (unsigned char *) ptr, nbytes, 536 if ((NILP (echo_string) || SCHARS (echo_string) == 0)
537 STRING_MULTIBYTE (name), 1); 537 && help_char_p (c))
538 } 538 {
539 const char *text = " (Type ? for further options)";
540 int len = strlen (text);
539 541
540 if ((NILP (echo_string) || SCHARS (echo_string) == 0) 542 if (size - (ptr - buffer) < len)
541 && help_char_p (c))
542 { 543 {
543 const char *text = " (Type ? for further options)"; 544 int offset = ptr - buffer;
544 int len = strlen (text); 545 size += len;
545 546 buffer = alloca (size);
546 if (size - (ptr - buffer) < len) 547 ptr = buffer + offset;
547 {
548 int offset = ptr - buffer;
549 size += len;
550 buffer = alloca (size);
551 ptr = buffer + offset;
552 }
553
554 memcpy (ptr, text, len);
555 ptr += len;
556 } 548 }
557 549
558 /* Replace a dash from echo_dash with a space, otherwise 550 memcpy (ptr, text, len);
559 add a space at the end as a separator between keys. */ 551 ptr += len;
560 if (STRINGP (echo_string) 552 }
561 && SCHARS (echo_string) > 1)
562 {
563 Lisp_Object last_char, prev_char, idx;
564 553
565 idx = make_number (SCHARS (echo_string) - 2); 554 /* Replace a dash from echo_dash with a space, otherwise add a space
566 prev_char = Faref (echo_string, idx); 555 at the end as a separator between keys. */
556 if (STRINGP (echo_string) && SCHARS (echo_string) > 1)
557 {
558 Lisp_Object last_char, prev_char, idx;
567 559
568 idx = make_number (SCHARS (echo_string) - 1); 560 idx = make_number (SCHARS (echo_string) - 2);
569 last_char = Faref (echo_string, idx); 561 prev_char = Faref (echo_string, idx);
570 562
571 /* We test PREV_CHAR to make sure this isn't the echoing 563 idx = make_number (SCHARS (echo_string) - 1);
572 of a minus-sign. */ 564 last_char = Faref (echo_string, idx);
573 if (XINT (last_char) == '-' && XINT (prev_char) != ' ') 565
574 Faset (echo_string, idx, make_number (' ')); 566 /* We test PREV_CHAR to make sure this isn't the echoing of a
575 else 567 minus-sign. */
576 echo_string = concat2 (echo_string, build_string (" ")); 568 if (XINT (last_char) == '-' && XINT (prev_char) != ' ')
577 } 569 Faset (echo_string, idx, make_number (' '));
578 else if (STRINGP (echo_string)) 570 else
579 echo_string = concat2 (echo_string, build_string (" ")); 571 echo_string = concat2 (echo_string, build_string (" "));
572 }
573 else if (STRINGP (echo_string) && SCHARS (echo_string) > 0)
574 echo_string = concat2 (echo_string, build_string (" "));
580 575
581 kset_echo_string 576 kset_echo_string
582 (current_kboard, 577 (current_kboard,
583 concat2 (echo_string, make_string (buffer, ptr - buffer))); 578 concat2 (echo_string, make_string (buffer, ptr - buffer)));
579}
580
581/* Add C to the echo string, if echoing is going on. C can be a
582 character or a symbol. */
584 583
584static void
585echo_char (Lisp_Object c)
586{
587 if (current_kboard->immediate_echo)
588 {
589 echo_add_char (c);
585 echo_now (); 590 echo_now ();
586 } 591 }
587} 592}
588 593
589/* Temporarily add a dash to the end of the echo string if it's not 594/* Temporarily add a dash to the end of the echo string if it's not
590 empty, so that it serves as a mini-prompt for the very next character. */ 595 empty, so that it serves as a mini-prompt for the very next
596 character. */
591 597
592static void 598static void
593echo_dash (void) 599echo_dash (void)
@@ -9218,8 +9224,12 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
9218 key = keybuf[t]; 9224 key = keybuf[t];
9219 add_command_key (key); 9225 add_command_key (key);
9220 if ((FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes)) 9226 if ((FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes))
9221 && NILP (Fzerop (Vecho_keystrokes))) 9227 && NILP (Fzerop (Vecho_keystrokes))
9222 echo_char (key); 9228 && current_kboard->immediate_echo)
9229 {
9230 echo_add_char (key);
9231 echo_dash ();
9232 }
9223 } 9233 }
9224 9234
9225 /* If not, we should actually read a character. */ 9235 /* If not, we should actually read a character. */