comparison src/keyboard.c @ 43750:38729301823d

(echo_prompt, echo_char, echo_dash, echo_now) (cancel_echoing, echo_length, echo_truncate): Changed to work with new kboard definition. (echo_now): Use message3_nolog instead of message2_nolog.
author Gerd Moellmann <gerd@gnu.org>
date Wed, 06 Mar 2002 15:55:11 +0000
parents f92c4d87863a
children 5f25ad91cf88
comparison
equal deleted inserted replaced
43749:0df5bec3cfdf 43750:38729301823d
704 704
705 void 705 void
706 echo_prompt (str) 706 echo_prompt (str)
707 Lisp_Object str; 707 Lisp_Object str;
708 { 708 {
709 int nbytes = STRING_BYTES (XSTRING (str)); 709 current_kboard->echo_string = str;
710 int multibyte_p = STRING_MULTIBYTE (str); 710 current_kboard->echo_after_prompt = XSTRING (str)->size;
711
712 if (nbytes > ECHOBUFSIZE - 4)
713 {
714 if (multibyte_p)
715 {
716 /* Have to find the last character that fit's into the
717 echo buffer. */
718 unsigned char *p = XSTRING (str)->data;
719 unsigned char *pend = p + ECHOBUFSIZE - 4;
720 int char_len;
721
722 do
723 {
724 PARSE_MULTIBYTE_SEQ (p, pend - p, char_len);
725 p += char_len;
726 }
727 while (p < pend);
728
729 nbytes = p - XSTRING (str)->data - char_len;
730 }
731 else
732 nbytes = ECHOBUFSIZE - 4;
733 }
734
735 nbytes = copy_text (XSTRING (str)->data, current_kboard->echobuf, nbytes,
736 STRING_MULTIBYTE (str), 1);
737 current_kboard->echoptr = current_kboard->echobuf + nbytes;
738 *current_kboard->echoptr = '\0';
739 current_kboard->echo_after_prompt = nbytes;
740
741 echo_now (); 711 echo_now ();
742 } 712 }
743 713
744 /* Add C to the echo string, if echoing is going on. 714 /* Add C to the echo string, if echoing is going on.
745 C can be a character, which is printed prettily ("M-C-x" and all that 715 C can be a character, which is printed prettily ("M-C-x" and all that
749 echo_char (c) 719 echo_char (c)
750 Lisp_Object c; 720 Lisp_Object c;
751 { 721 {
752 if (current_kboard->immediate_echo) 722 if (current_kboard->immediate_echo)
753 { 723 {
754 char *ptr = current_kboard->echoptr; 724 int size = KEY_DESCRIPTION_SIZE + 100;
755 725 char *buffer = (char *) alloca (size);
756 if (ptr != current_kboard->echobuf) 726 char *ptr = buffer;
757 *ptr++ = ' '; 727 Lisp_Object echo_string;
758 728
759 /* If someone has passed us a composite event, use its head symbol. */ 729 /* If someone has passed us a composite event, use its head symbol. */
760 c = EVENT_HEAD (c); 730 c = EVENT_HEAD (c);
761 731
762 if (INTEGERP (c)) 732 if (INTEGERP (c))
763 { 733 {
764 int ch = XINT (c); 734 ptr = push_key_description (XINT (c), ptr, 1);
765
766 if (ptr - current_kboard->echobuf
767 > ECHOBUFSIZE - KEY_DESCRIPTION_SIZE)
768 return;
769
770 ptr = push_key_description (ch, ptr, 1);
771 } 735 }
772 else if (SYMBOLP (c)) 736 else if (SYMBOLP (c))
773 { 737 {
774 struct Lisp_String *name = XSYMBOL (c)->name; 738 struct Lisp_String *name = XSYMBOL (c)->name;
775 if ((ptr - current_kboard->echobuf) + STRING_BYTES (name) + 4 739
776 > ECHOBUFSIZE) 740 if (size - (ptr - buffer) < STRING_BYTES (name))
777 return; 741 {
742 int offset = ptr - buffer;
743 size = max (2 * size, size + STRING_BYTES (name));
744 buffer = (char *) alloca (size);
745 ptr = buffer + offset;
746 }
747
778 ptr += copy_text (name->data, ptr, STRING_BYTES (name), 748 ptr += copy_text (name->data, ptr, STRING_BYTES (name),
779 name->size_byte >= 0, 1); 749 name->size_byte >= 0, 1);
780 } 750 }
781 751
782 if (current_kboard->echoptr == current_kboard->echobuf 752 if ((NILP (current_kboard->echo_string)
753 || XSTRING (current_kboard->echo_string)->size == 0)
783 && help_char_p (c)) 754 && help_char_p (c))
784 { 755 {
785 strcpy (ptr, " (Type ? for further options)"); 756 const char *text = " (Type ? for further options)";
786 ptr += strlen (ptr); 757 int len = strlen (text);
787 } 758
788 759 if (size - (ptr - buffer) < len)
789 *ptr = 0; 760 {
790 current_kboard->echoptr = ptr; 761 int offset = ptr - buffer;
762 size += len;
763 buffer = (char *) alloca (size);
764 ptr = buffer + offset;
765 }
766
767 bcopy (text, ptr, len);
768 ptr += len;
769 }
770
771 echo_string = current_kboard->echo_string;
772
773 /* Replace a dash from echo_dash with a space. */
774 if (STRINGP (echo_string)
775 && (size = STRING_BYTES (XSTRING (echo_string)),
776 (size > 0
777 && XSTRING (echo_string)->data[size - 1] == '-')))
778 XSTRING (echo_string)->data[size - 1] = ' ';
779
780 current_kboard->echo_string
781 = concat2 (echo_string, make_string (buffer, ptr - buffer));
791 782
792 echo_now (); 783 echo_now ();
793 } 784 }
794 } 785 }
795 786
797 empty, so that it serves as a mini-prompt for the very next character. */ 788 empty, so that it serves as a mini-prompt for the very next character. */
798 789
799 void 790 void
800 echo_dash () 791 echo_dash ()
801 { 792 {
793 /* Do nothing if not echoing at all. */
794 if (NILP (current_kboard->echo_string))
795 return;
796
802 if (!current_kboard->immediate_echo 797 if (!current_kboard->immediate_echo
803 && current_kboard->echoptr == current_kboard->echobuf) 798 && XSTRING (current_kboard->echo_string)->size == 0)
804 return; 799 return;
800
805 /* Do nothing if we just printed a prompt. */ 801 /* Do nothing if we just printed a prompt. */
806 if (current_kboard->echo_after_prompt 802 if (current_kboard->echo_after_prompt
807 == current_kboard->echoptr - current_kboard->echobuf) 803 == XSTRING (current_kboard->echo_string)->size)
808 return; 804 return;
809 /* Do nothing if not echoing at all. */ 805
810 if (current_kboard->echoptr == 0)
811 return;
812
813 /* Put a dash at the end of the buffer temporarily, 806 /* Put a dash at the end of the buffer temporarily,
814 but make it go away when the next character is added. */ 807 but make it go away when the next character is added. */
815 current_kboard->echoptr[0] = '-'; 808 current_kboard->echo_string = concat2 (current_kboard->echo_string,
816 current_kboard->echoptr[1] = 0; 809 build_string ("-"));
817
818 echo_now (); 810 echo_now ();
819 } 811 }
820 812
821 /* Display the current echo string, and begin echoing if not already 813 /* Display the current echo string, and begin echoing if not already
822 doing so. */ 814 doing so. */
839 } 831 }
840 echo_dash (); 832 echo_dash ();
841 } 833 }
842 834
843 echoing = 1; 835 echoing = 1;
844 message2_nolog (current_kboard->echobuf, strlen (current_kboard->echobuf), 836 message3_nolog (current_kboard->echo_string,
845 1); 837 STRING_BYTES (XSTRING (current_kboard->echo_string)),
838 STRING_MULTIBYTE (current_kboard->echo_string));
846 echoing = 0; 839 echoing = 0;
847 840
848 /* Record in what buffer we echoed, and from which kboard. */ 841 /* Record in what buffer we echoed, and from which kboard. */
849 echo_message_buffer = echo_area_buffer[0]; 842 echo_message_buffer = echo_area_buffer[0];
850 echo_kboard = current_kboard; 843 echo_kboard = current_kboard;
857 850
858 void 851 void
859 cancel_echoing () 852 cancel_echoing ()
860 { 853 {
861 current_kboard->immediate_echo = 0; 854 current_kboard->immediate_echo = 0;
862 current_kboard->echoptr = current_kboard->echobuf;
863 current_kboard->echo_after_prompt = -1; 855 current_kboard->echo_after_prompt = -1;
856 current_kboard->echo_string = Qnil;
864 ok_to_echo_at_next_pause = NULL; 857 ok_to_echo_at_next_pause = NULL;
865 echo_kboard = NULL; 858 echo_kboard = NULL;
866 echo_message_buffer = Qnil; 859 echo_message_buffer = Qnil;
867 } 860 }
868 861
869 /* Return the length of the current echo string. */ 862 /* Return the length of the current echo string. */
870 863
871 static int 864 static int
872 echo_length () 865 echo_length ()
873 { 866 {
874 return current_kboard->echoptr - current_kboard->echobuf; 867 return (STRINGP (current_kboard->echo_string)
868 ? XSTRING (current_kboard->echo_string)->size
869 : 0);
875 } 870 }
876 871
877 /* Truncate the current echo message to its first LEN chars. 872 /* Truncate the current echo message to its first LEN chars.
878 This and echo_char get used by read_key_sequence when the user 873 This and echo_char get used by read_key_sequence when the user
879 switches frames while entering a key sequence. */ 874 switches frames while entering a key sequence. */
880 875
881 static void 876 static void
882 echo_truncate (len) 877 echo_truncate (nchars)
883 int len; 878 int nchars;
884 { 879 {
885 current_kboard->echobuf[len] = '\0'; 880 if (STRINGP (current_kboard->echo_string))
886 current_kboard->echoptr = current_kboard->echobuf + len; 881 current_kboard->echo_string
887 truncate_echo_area (len); 882 = Fsubstring (current_kboard->echo_string,
883 make_number (0), make_number (nchars));
884 truncate_echo_area (nchars);
888 } 885 }
889 886
890 887
891 /* Functions for manipulating this_command_keys. */ 888 /* Functions for manipulating this_command_keys. */
892 static void 889 static void
10128 kb->Vprefix_arg = Qnil; 10125 kb->Vprefix_arg = Qnil;
10129 kb->Vlast_prefix_arg = Qnil; 10126 kb->Vlast_prefix_arg = Qnil;
10130 kb->kbd_queue = Qnil; 10127 kb->kbd_queue = Qnil;
10131 kb->kbd_queue_has_data = 0; 10128 kb->kbd_queue_has_data = 0;
10132 kb->immediate_echo = 0; 10129 kb->immediate_echo = 0;
10133 kb->echoptr = kb->echobuf; 10130 kb->echo_string = Qnil;
10134 kb->echo_after_prompt = -1; 10131 kb->echo_after_prompt = -1;
10135 kb->kbd_macro_buffer = 0; 10132 kb->kbd_macro_buffer = 0;
10136 kb->kbd_macro_bufsize = 0; 10133 kb->kbd_macro_bufsize = 0;
10137 kb->defining_kbd_macro = Qnil; 10134 kb->defining_kbd_macro = Qnil;
10138 kb->Vlast_kbd_macro = Qnil; 10135 kb->Vlast_kbd_macro = Qnil;