From 0b03713d1b30252f99e4192a5f46e62ca933e5cf Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Thu, 5 Sep 2002 22:53:47 +0000 Subject: [PATCH] (current_column_1, Fmove_to_column): Separate the code for display-table glyphs from the code for buffer text, to fix bugs in the former. --- src/indent.c | 123 +++++++++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 52 deletions(-) diff --git a/src/indent.c b/src/indent.c index 33a6c5b63db..fb397b6053f 100644 --- a/src/indent.c +++ b/src/indent.c @@ -513,7 +513,7 @@ current_column_1 () /* Start the scan at the beginning of this line with column number 0. */ register int col = 0; int scan, scan_byte; - int next_boundary, next_boundary_byte; + int next_boundary; int opoint = PT, opoint_byte = PT_BYTE; scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1); @@ -521,7 +521,6 @@ current_column_1 () scan = PT, scan_byte = PT_BYTE; SET_PT_BOTH (opoint, opoint_byte); next_boundary = scan; - next_boundary_byte = scan_byte; if (tab_width <= 0 || tab_width > 1000) tab_width = 8; @@ -529,8 +528,6 @@ current_column_1 () while (scan < opoint) { int c; - EMACS_INT i, n; - Lisp_Object charvec; /* Occasionally we may need to skip invisible text. */ while (scan == next_boundary) @@ -543,7 +540,6 @@ current_column_1 () goto endloop; if (scan != old_scan) scan_byte = CHAR_TO_BYTE (scan); - next_boundary_byte = CHAR_TO_BYTE (next_boundary); } /* Check composition sequence. */ @@ -567,39 +563,52 @@ current_column_1 () && ! (multibyte && BASE_LEADING_CODE_P (c)) && VECTORP (DISP_CHAR_VECTOR (dp, c))) { + Lisp_Object charvec; + EMACS_INT i, n; + + /* This character is displayed using a vector of glyphs. + Update the column based on those glyphs. */ + charvec = DISP_CHAR_VECTOR (dp, c); n = ASIZE (charvec); - } - else - { - charvec = Qnil; - n = 1; - } - for (i = n - 1; i >= 0; --i) - { - if (VECTORP (charvec)) + for (i = 0; i < n; i++) { /* This should be handled the same as next_element_from_display_vector does it. */ - Lisp_Object entry = AREF (charvec, i); - + Lisp_Object entry; + entry = AREF (charvec, i); + if (INTEGERP (entry) && GLYPH_CHAR_VALID_P (XFASTINT (entry))) c = FAST_GLYPH_CHAR (XFASTINT (entry)); else c = ' '; + + if (c == '\n') + goto endloop; + if (c == '\r' && EQ (current_buffer->selective_display, Qt)) + goto endloop; + if (c == '\t') + { + col += tab_width; + col = col / tab_width * tab_width; + } + else + ++col; } - + } + else + { + /* The display table says nothing for this character. + Display it as itself. */ + if (c == '\n') goto endloop; if (c == '\r' && EQ (current_buffer->selective_display, Qt)) goto endloop; - scan++; - scan_byte++; if (c == '\t') { - int prev_col = col; col += tab_width; col = col / tab_width * tab_width; } @@ -607,15 +616,15 @@ current_column_1 () { unsigned char *ptr; int bytes, width, wide_column; - - scan_byte--; + ptr = BYTE_POS_ADDR (scan_byte); MULTIBYTE_BYTES_WIDTH (ptr, dp); scan_byte += bytes; + /* Subtract one to compensate for the increment + that is going to happen below. */ + scan_byte--; col += width; } - else if (VECTORP (charvec)) - ++col; else if (ctl_arrow && (c < 040 || c == 0177)) col += 2; else if (c < 040 || c >= 0177) @@ -623,6 +632,9 @@ current_column_1 () else col++; } + scan++; + scan_byte++; + } endloop: @@ -923,8 +935,7 @@ The return value is the current column.") int prev_col = 0; int c = 0; int next_boundary; - - int pos_byte, end_byte, next_boundary_byte; + int pos_byte; if (tab_width <= 0 || tab_width > 1000) tab_width = 8; CHECK_NATNUM (column, 0); @@ -933,9 +944,7 @@ The return value is the current column.") pos = PT; pos_byte = PT_BYTE; end = ZV; - end_byte = ZV_BYTE; next_boundary = pos; - next_boundary_byte = PT_BYTE; /* If we're starting past the desired column, back up to beginning of line and scan from there. */ @@ -949,16 +958,12 @@ The return value is the current column.") while (pos < end) { - Lisp_Object charvec; - EMACS_INT i, n; - while (pos == next_boundary) { int prev = pos; pos = skip_invisible (pos, &next_boundary, end, Qnil); if (pos != prev) pos_byte = CHAR_TO_BYTE (pos); - next_boundary_byte = CHAR_TO_BYTE (next_boundary); if (pos >= end) goto endloop; } @@ -984,49 +989,61 @@ The return value is the current column.") c = FETCH_BYTE (pos_byte); + /* See if there is a display table and it relates + to this character. */ + if (dp != 0 && ! (multibyte && BASE_LEADING_CODE_P (c)) && VECTORP (DISP_CHAR_VECTOR (dp, c))) { + Lisp_Object charvec; + EMACS_INT i, n; + charvec = DISP_CHAR_VECTOR (dp, c); n = ASIZE (charvec); - } - else - { - charvec = Qnil; - n = 1; - } - - for (i = n - 1; i >= 0; --i) - { - if (VECTORP (charvec)) + for (i = 0; i < n; i++) { /* This should be handled the same as next_element_from_display_vector does it. */ - Lisp_Object entry = AREF (charvec, i); - + + Lisp_Object entry; + entry = AREF (charvec, i); + if (INTEGERP (entry) && GLYPH_CHAR_VALID_P (XFASTINT (entry))) c = FAST_GLYPH_CHAR (XFASTINT (entry)); else c = ' '; + + if (c == '\n') + goto endloop; + if (c == '\r' && EQ (current_buffer->selective_display, Qt)) + goto endloop; + if (c == '\t') + { + prev_col = col; + col += tab_width; + col = col / tab_width * tab_width; + } + else + ++col; } + } + else + { + /* The display table doesn't affect this character; + it displays as itself. */ - if (c == '\n') goto endloop; if (c == '\r' && EQ (current_buffer->selective_display, Qt)) goto endloop; - pos++; - pos_byte++; if (c == '\t') { prev_col = col; col += tab_width; col = col / tab_width * tab_width; } - else if (VECTORP (charvec)) - ++col; else if (ctl_arrow && (c < 040 || c == 0177)) col += 2; else if (c < 040 || c == 0177) @@ -1039,15 +1056,17 @@ The return value is the current column.") unsigned char *ptr; int bytes, width, wide_column; - pos_byte--; ptr = BYTE_POS_ADDR (pos_byte); MULTIBYTE_BYTES_WIDTH (ptr, dp); - pos_byte += bytes; + pos_byte += bytes - 1; col += width; } else col += 4; } + + pos++; + pos_byte++; } endloop: @@ -1071,7 +1090,7 @@ The return value is the current column.") goal_pt_byte = PT_BYTE; Findent_to (make_number (col), Qnil); SET_PT_BOTH (goal_pt, goal_pt_byte); - + /* Set the last_known... vars consistently. */ col = goal; } -- 2.39.2