comparison src/indent.c @ 40720:db9254d9c5d0

(current_column_1, Fmove_to_column): Separate the code for display-table glyphs from the code buffer text, to fix bugs in the former.
author Richard M. Stallman <rms@gnu.org>
date Sun, 04 Nov 2001 23:26:52 +0000
parents cdfd4d09b79a
children 4846599d4eef
comparison
equal deleted inserted replaced
40719:fe4f4f041e44 40720:db9254d9c5d0
524 524
525 /* Scan forward to the target position. */ 525 /* Scan forward to the target position. */
526 while (scan < opoint) 526 while (scan < opoint)
527 { 527 {
528 int c; 528 int c;
529 EMACS_INT i, n;
530 Lisp_Object charvec;
531 529
532 /* Occasionally we may need to skip invisible text. */ 530 /* Occasionally we may need to skip invisible text. */
533 while (scan == next_boundary) 531 while (scan == next_boundary)
534 { 532 {
535 int old_scan = scan; 533 int old_scan = scan;
562 560
563 if (dp != 0 561 if (dp != 0
564 && ! (multibyte && BASE_LEADING_CODE_P (c)) 562 && ! (multibyte && BASE_LEADING_CODE_P (c))
565 && VECTORP (DISP_CHAR_VECTOR (dp, c))) 563 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
566 { 564 {
565 Lisp_Object charvec;
566 EMACS_INT i, n;
567
568 /* This character is displayed using a vector of glyphs.
569 Update the column based on those glyphs. */
570
567 charvec = DISP_CHAR_VECTOR (dp, c); 571 charvec = DISP_CHAR_VECTOR (dp, c);
568 n = ASIZE (charvec); 572 n = ASIZE (charvec);
569 } 573
570 else 574 for (i = 0; i < n; i++)
571 {
572 charvec = Qnil;
573 n = 1;
574 }
575
576 for (i = n - 1; i >= 0; --i)
577 {
578 if (VECTORP (charvec))
579 { 575 {
580 /* This should be handled the same as 576 /* This should be handled the same as
581 next_element_from_display_vector does it. */ 577 next_element_from_display_vector does it. */
582 Lisp_Object entry = AREF (charvec, i); 578 Lisp_Object entry;
583 579 entry = AREF (charvec, i);
580
584 if (INTEGERP (entry) 581 if (INTEGERP (entry)
585 && GLYPH_CHAR_VALID_P (XFASTINT (entry))) 582 && GLYPH_CHAR_VALID_P (XFASTINT (entry)))
586 c = FAST_GLYPH_CHAR (XFASTINT (entry)); 583 c = FAST_GLYPH_CHAR (XFASTINT (entry));
587 else 584 else
588 c = ' '; 585 c = ' ';
589 } 586
590 587 if (c == '\n')
588 goto endloop;
589 if (c == '\r' && EQ (current_buffer->selective_display, Qt))
590 goto endloop;
591 if (c == '\t')
592 {
593 int prev_col = col;
594 col += tab_width;
595 col = col / tab_width * tab_width;
596 }
597 else
598 ++col;
599 }
600 }
601 else
602 {
603 /* The display table says nothing for this character.
604 Display it as itself. */
605
591 if (c == '\n') 606 if (c == '\n')
592 goto endloop; 607 goto endloop;
593 if (c == '\r' && EQ (current_buffer->selective_display, Qt)) 608 if (c == '\r' && EQ (current_buffer->selective_display, Qt))
594 goto endloop; 609 goto endloop;
595 scan++;
596 scan_byte++;
597 if (c == '\t') 610 if (c == '\t')
598 { 611 {
599 int prev_col = col; 612 int prev_col = col;
600 col += tab_width; 613 col += tab_width;
601 col = col / tab_width * tab_width; 614 col = col / tab_width * tab_width;
609 ptr = BYTE_POS_ADDR (scan_byte); 622 ptr = BYTE_POS_ADDR (scan_byte);
610 MULTIBYTE_BYTES_WIDTH (ptr, dp); 623 MULTIBYTE_BYTES_WIDTH (ptr, dp);
611 scan_byte += bytes; 624 scan_byte += bytes;
612 col += width; 625 col += width;
613 } 626 }
614 else if (VECTORP (charvec))
615 ++col;
616 else if (ctl_arrow && (c < 040 || c == 0177)) 627 else if (ctl_arrow && (c < 040 || c == 0177))
617 col += 2; 628 col += 2;
618 else if (c < 040 || c >= 0177) 629 else if (c < 040 || c >= 0177)
619 col += 4; 630 col += 4;
620 else 631 else
621 col++; 632 col++;
622 } 633 }
634 scan++;
635 scan_byte++;
636
623 } 637 }
624 endloop: 638 endloop:
625 639
626 last_known_column = col; 640 last_known_column = col;
627 last_known_column_point = PT; 641 last_known_column_point = PT;
945 col = 0; 959 col = 0;
946 } 960 }
947 961
948 while (pos < end) 962 while (pos < end)
949 { 963 {
950 Lisp_Object charvec;
951 EMACS_INT i, n;
952
953 while (pos == next_boundary) 964 while (pos == next_boundary)
954 { 965 {
955 int prev = pos; 966 int prev = pos;
956 pos = skip_invisible (pos, &next_boundary, end, Qnil); 967 pos = skip_invisible (pos, &next_boundary, end, Qnil);
957 if (pos != prev) 968 if (pos != prev)
980 } 991 }
981 } 992 }
982 993
983 c = FETCH_BYTE (pos_byte); 994 c = FETCH_BYTE (pos_byte);
984 995
996 /* See if there is a display table and it relates
997 to this character. */
998
985 if (dp != 0 999 if (dp != 0
986 && ! (multibyte && BASE_LEADING_CODE_P (c)) 1000 && ! (multibyte && BASE_LEADING_CODE_P (c))
987 && VECTORP (DISP_CHAR_VECTOR (dp, c))) 1001 && VECTORP (DISP_CHAR_VECTOR (dp, c)))
988 { 1002 {
1003 Lisp_Object charvec;
1004 EMACS_INT i, n;
1005
1006 /* This character is displayed using a vector of glyphs.
1007 Update the position based on those glyphs. */
1008
989 charvec = DISP_CHAR_VECTOR (dp, c); 1009 charvec = DISP_CHAR_VECTOR (dp, c);
990 n = ASIZE (charvec); 1010 n = ASIZE (charvec);
991 } 1011
992 else 1012 for (i = 0; i < n; i++)
993 {
994 charvec = Qnil;
995 n = 1;
996 }
997
998 for (i = n - 1; i >= 0; --i)
999 {
1000 if (VECTORP (charvec))
1001 { 1013 {
1002 /* This should be handled the same as 1014 /* This should be handled the same as
1003 next_element_from_display_vector does it. */ 1015 next_element_from_display_vector does it. */
1004 Lisp_Object entry = AREF (charvec, i); 1016
1005 1017 Lisp_Object entry;
1018 entry = AREF (charvec, i);
1019
1006 if (INTEGERP (entry) 1020 if (INTEGERP (entry)
1007 && GLYPH_CHAR_VALID_P (XFASTINT (entry))) 1021 && GLYPH_CHAR_VALID_P (XFASTINT (entry)))
1008 c = FAST_GLYPH_CHAR (XFASTINT (entry)); 1022 c = FAST_GLYPH_CHAR (XFASTINT (entry));
1009 else 1023 else
1010 c = ' '; 1024 c = ' ';
1011 } 1025
1012 1026 if (c == '\n')
1013 1027 goto endloop;
1028 if (c == '\r' && EQ (current_buffer->selective_display, Qt))
1029 goto endloop;
1030 if (c == '\t')
1031 {
1032 prev_col = col;
1033 col += tab_width;
1034 col = col / tab_width * tab_width;
1035 }
1036 else
1037 ++col;
1038 }
1039 }
1040 else
1041 {
1042 /* The display table doesn't affect this character;
1043 it displays as itself. */
1044
1014 if (c == '\n') 1045 if (c == '\n')
1015 goto endloop; 1046 goto endloop;
1016 if (c == '\r' && EQ (current_buffer->selective_display, Qt)) 1047 if (c == '\r' && EQ (current_buffer->selective_display, Qt))
1017 goto endloop; 1048 goto endloop;
1018 pos++;
1019 pos_byte++;
1020 if (c == '\t') 1049 if (c == '\t')
1021 { 1050 {
1022 prev_col = col; 1051 prev_col = col;
1023 col += tab_width; 1052 col += tab_width;
1024 col = col / tab_width * tab_width; 1053 col = col / tab_width * tab_width;
1025 } 1054 }
1026 else if (VECTORP (charvec))
1027 ++col;
1028 else if (ctl_arrow && (c < 040 || c == 0177)) 1055 else if (ctl_arrow && (c < 040 || c == 0177))
1029 col += 2; 1056 col += 2;
1030 else if (c < 040 || c == 0177) 1057 else if (c < 040 || c == 0177)
1031 col += 4; 1058 col += 4;
1032 else if (c < 0177) 1059 else if (c < 0177)
1035 { 1062 {
1036 /* Start of multi-byte form. */ 1063 /* Start of multi-byte form. */
1037 unsigned char *ptr; 1064 unsigned char *ptr;
1038 int bytes, width, wide_column; 1065 int bytes, width, wide_column;
1039 1066
1040 pos_byte--;
1041 ptr = BYTE_POS_ADDR (pos_byte); 1067 ptr = BYTE_POS_ADDR (pos_byte);
1042 MULTIBYTE_BYTES_WIDTH (ptr, dp); 1068 MULTIBYTE_BYTES_WIDTH (ptr, dp);
1043 pos_byte += bytes; 1069 pos_byte += bytes - 1;
1044 col += width; 1070 col += width;
1045 } 1071 }
1046 else 1072 else
1047 col += 4; 1073 col += 4;
1048 } 1074 }
1075
1076 pos++;
1077 pos_byte++;
1049 } 1078 }
1050 endloop: 1079 endloop:
1051 1080
1052 SET_PT_BOTH (pos, pos_byte); 1081 SET_PT_BOTH (pos, pos_byte);
1053 1082