To: vim-dev@vim.org Subject: Patch 6.1.469 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.469 Problem: 'listchars' cannot contain multi-byte characters. Solution: Handle multi-byte UTF-8 list characters. (Matthew Samsonoff) Files: src/message.c, src/option.c, src/screen.c *** ../vim61.468/src/message.c Wed Mar 26 22:26:31 2003 --- src/message.c Wed Apr 16 21:08:46 2003 *************** *** 984,990 **** --- 984,994 ---- int c; int attr; { + #ifdef FEAT_MBYTE + char_u buf[MB_MAXBYTES + 1]; + #else char_u buf[4]; + #endif if (IS_SPECIAL(c)) { *************** *** 995,1002 **** --- 999,1010 ---- } else { + #ifdef FEAT_MBYTE + buf[(*mb_char2bytes)(c, buf)] = NUL; + #else buf[0] = c; buf[1] = NUL; + #endif } msg_puts_attr(buf, attr); } *** ../vim61.468/src/option.c Thu Apr 10 22:58:43 2003 --- src/option.c Wed Apr 9 20:48:41 2003 *************** *** 5432,5438 **** char_u **varp; { int round, i, len, entries; ! char_u *p; struct charstab { int *cp; --- 5432,5439 ---- char_u **varp; { int round, i, len, entries; ! char_u *p, *s; ! int c1, c2 = 0; struct charstab { int *cp; *************** *** 5499,5516 **** && p[len] == ':' && p[len + 1] != NUL) { if (tab[i].cp == &lcs_tab2) ! ++len; ! if (p[len + 1] != NUL ! && (p[len + 2] == ',' || p[len + 2] == NUL)) { if (round) { - *(tab[i].cp) = p[len + 1]; if (tab[i].cp == &lcs_tab2) ! lcs_tab1 = p[len]; } ! p += len + 2; break; } } --- 5500,5535 ---- && p[len] == ':' && p[len + 1] != NUL) { + s = p + len + 1; + #ifdef FEAT_MBYTE + c1 = mb_ptr2char_adv(&s); + #else + c1 = *s++; + #endif if (tab[i].cp == &lcs_tab2) ! { ! if (*s == NUL) ! continue; ! #ifdef FEAT_MBYTE ! c2 = mb_ptr2char_adv(&s); ! #else ! c2 = *s++; ! #endif ! } ! if (*s == ',' || *s == NUL) { if (round) { if (tab[i].cp == &lcs_tab2) ! { ! lcs_tab1 = c1; ! lcs_tab2 = c2; ! } ! else ! *(tab[i].cp) = c1; ! } ! p = s; break; } } *** ../vim61.468/src/screen.c Tue Apr 8 23:05:36 2003 --- src/screen.c Wed Apr 16 21:20:48 2003 *************** *** 2197,2203 **** { #ifdef FEAT_MBYTE if (enc_utf8) ! ScreenLinesUC[off + col] = 0; #endif ScreenLines[off + col++] = fill_fold; } --- 2197,2212 ---- { #ifdef FEAT_MBYTE if (enc_utf8) ! { ! if (fill_fold >= 0x80) ! { ! ScreenLinesUC[off + col] = fill_fold; ! ScreenLinesC1[off + col] = 0; ! ScreenLinesC2[off + col] = 0; ! } ! else ! ScreenLinesUC[off + col] = 0; ! } #endif ScreenLines[off + col++] = fill_fold; } *************** *** 3170,3176 **** { c = c_extra; #ifdef FEAT_MBYTE ! mb_c = c; /* doesn't handle multi-byte! */ #endif } else --- 3179,3192 ---- { c = c_extra; #ifdef FEAT_MBYTE ! mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ ! if (enc_utf8 && (*mb_char2len)(c) > 1) ! { ! mb_utf8 = TRUE; ! u8c_c1 = u8c_c2 = 0; ! } ! else ! mb_utf8 = FALSE; #endif } else *************** *** 3438,3443 **** --- 3454,3469 ---- extra_attr = hl_attr(HLF_8); saved_attr2 = char_attr; /* save current attr */ } + #ifdef FEAT_MBYTE + mb_c = c; + if (enc_utf8 && (*mb_char2len)(c) > 1) + { + mb_utf8 = TRUE; + u8c_c1 = u8c_c2 = 0; + } + else + mb_utf8 = FALSE; + #endif } } *************** *** 3456,3461 **** --- 3482,3490 ---- /* tab amount depends on current column */ n_extra = (int)wp->w_buffer->b_p_ts - vcol % (int)wp->w_buffer->b_p_ts - 1; + #ifdef FEAT_MBYTE + mb_utf8 = FALSE; /* don't draw as UTF-8 */ + #endif if (wp->w_p_list) { c = lcs_tab1; *************** *** 3463,3477 **** n_attr = n_extra + 1; extra_attr = hl_attr(HLF_8); saved_attr2 = char_attr; /* save current attr */ } else { c_extra = ' '; c = ' '; } - #ifdef FEAT_MBYTE - mb_utf8 = FALSE; /* don't draw as UTF-8 */ - #endif } else if (c == NUL && wp->w_p_list && lcs_eol_one > 0) { --- 3492,3511 ---- n_attr = n_extra + 1; extra_attr = hl_attr(HLF_8); saved_attr2 = char_attr; /* save current attr */ + #ifdef FEAT_MBYTE + mb_c = c; + if (enc_utf8 && (*mb_char2len)(c) > 1) + { + mb_utf8 = TRUE; + u8c_c1 = u8c_c2 = 0; + } + #endif } else { c_extra = ' '; c = ' '; } } else if (c == NUL && wp->w_p_list && lcs_eol_one > 0) { *************** *** 3514,3520 **** n_attr = 1; } #ifdef FEAT_MBYTE ! mb_utf8 = FALSE; /* don't draw as UTF-8 */ #endif } else if (c != NUL) --- 3548,3561 ---- n_attr = 1; } #ifdef FEAT_MBYTE ! mb_c = c; ! if (enc_utf8 && (*mb_char2len)(c) > 1) ! { ! mb_utf8 = TRUE; ! u8c_c1 = u8c_c2 = 0; ! } ! else ! mb_utf8 = FALSE; /* don't draw as UTF-8 */ #endif } else if (c != NUL) *************** *** 3649,3655 **** c = lcs_prec; lcs_prec_todo = NUL; #ifdef FEAT_MBYTE ! mb_utf8 = FALSE; /* don't draw as UTF-8 */ #endif if ((area_attr == 0 || char_attr != area_attr) && (search_attr == 0 || char_attr != search_attr)) --- 3690,3703 ---- c = lcs_prec; lcs_prec_todo = NUL; #ifdef FEAT_MBYTE ! mb_c = c; ! if (enc_utf8 && (*mb_char2len)(c) > 1) ! { ! mb_utf8 = TRUE; ! u8c_c1 = u8c_c2 = 0; ! } ! else ! mb_utf8 = FALSE; /* don't draw as UTF-8 */ #endif if ((area_attr == 0 || char_attr != area_attr) && (search_attr == 0 || char_attr != search_attr)) *************** *** 3757,3762 **** --- 3805,3820 ---- { c = lcs_ext; char_attr = hl_attr(HLF_AT); + #ifdef FEAT_MBYTE + mb_c = c; + if (enc_utf8 && (*mb_char2len)(c) > 1) + { + mb_utf8 = TRUE; + u8c_c1 = u8c_c2 = 0; + } + else + mb_utf8 = FALSE; + #endif } /* *************** *** 4379,4391 **** int c; c = fillchar_vsep(&hl); ! if (ScreenLines[off_to] != c || ScreenAttrs[off_to] != hl) { ScreenLines[off_to] = c; ScreenAttrs[off_to] = hl; # ifdef FEAT_MBYTE if (enc_utf8) ! ScreenLinesUC[off_to] = 0; # endif screen_char(off_to, row, col + coloff); } --- 4437,4463 ---- int c; c = fillchar_vsep(&hl); ! if (ScreenLines[off_to] != c ! # ifdef FEAT_MBYTE ! || (enc_utf8 ! && ScreenLinesUC[off_to] != (c >= 0x80 ? c : 0)) ! # endif ! || ScreenAttrs[off_to] != hl) { ScreenLines[off_to] = c; ScreenAttrs[off_to] = hl; # ifdef FEAT_MBYTE if (enc_utf8) ! { ! if (c >= 0x80) ! { ! ScreenLinesUC[off_to] = c; ! ScreenLinesC1[off_to] = 0; ! ScreenLinesC2[off_to] = 0; ! } ! else ! ScreenLinesUC[off_to] = 0; ! } # endif screen_char(off_to, row, col + coloff); } *************** *** 5134,5140 **** --- 5206,5216 ---- while (width < maxwidth && len < sizeof(buf) - 1) { + #ifdef FEAT_MBYTE + len += (*mb_char2bytes)(fillchar, buf + len); + #else buf[len++] = fillchar; + #endif ++width; } buf[len] = NUL; *************** *** 5167,5173 **** /* * Output a single character directly to the screen and update ScreenLines. - * Not for multi-byte chars! */ void screen_putchar(c, row, col, attr) --- 5243,5248 ---- *************** *** 5175,5187 **** int row, col; int attr; { char_u buf[2]; ! { ! buf[0] = c; ! buf[1] = NUL; ! screen_puts(buf, row, col, attr); ! } } /* --- 5250,5266 ---- int row, col; int attr; { + #ifdef FEAT_MBYTE + char_u buf[MB_MAXBYTES + 1]; + + buf[(*mb_char2bytes)(c, buf)] = NUL; + #else char_u buf[2]; ! buf[0] = c; ! buf[1] = NUL; ! #endif ! screen_puts(buf, row, col, attr); } /* *************** *** 5956,5962 **** * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' * with character 'c1' in first column followed by 'c2' in the other columns. * Use attributes 'attr'. - * Cannot handle multi-byte characters, c1 and c2 must be < 0x80! */ void screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) --- 6035,6040 ---- *************** *** 6054,6060 **** c = c1; for (col = start_col; col < end_col; ++col) { ! if (ScreenLines[off] != c || ScreenAttrs[off] != attr #if defined(FEAT_GUI) || defined(UNIX) || force_next #endif --- 6132,6142 ---- c = c1; for (col = start_col; col < end_col; ++col) { ! if (ScreenLines[off] != c ! #ifdef FEAT_MBYTE ! || (enc_utf8 && ScreenLinesUC[off] != (c >= 0x80 ? c : 0)) ! #endif ! || ScreenAttrs[off] != attr #if defined(FEAT_GUI) || defined(UNIX) || force_next #endif *************** *** 6088,6094 **** ScreenLines[off] = c; #ifdef FEAT_MBYTE if (enc_utf8) ! ScreenLinesUC[off] = 0; #endif ScreenAttrs[off] = attr; if (!did_delete || c != ' ') --- 6170,6185 ---- ScreenLines[off] = c; #ifdef FEAT_MBYTE if (enc_utf8) ! { ! if (c >= 0x80) ! { ! ScreenLinesUC[off] = c; ! ScreenLinesC1[off] = 0; ! ScreenLinesC2[off] = 0; ! } ! else ! ScreenLinesUC[off] = 0; ! } #endif ScreenAttrs[off] = attr; if (!did_delete || c != ' ') *************** *** 8051,8057 **** */ i = (int)STRLEN(buffer); get_rel_pos(wp, buffer + i + 1); ! o = vim_strsize(buffer + i + 1); #ifdef FEAT_WINDOWS if (wp->w_status_height == 0) /* can't use last char of screen */ #endif --- 8142,8148 ---- */ i = (int)STRLEN(buffer); get_rel_pos(wp, buffer + i + 1); ! o = i + vim_strsize(buffer + i + 1); #ifdef FEAT_WINDOWS if (wp->w_status_height == 0) /* can't use last char of screen */ #endif *************** *** 8065,8074 **** * half for the filename. */ if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) this_ru_col = (WITH_WIDTH(width) + 1) / 2; ! if (this_ru_col + i + o < WITH_WIDTH(width)) { ! while (this_ru_col + i + o < WITH_WIDTH(width)) ! buffer[i++] = fillchar; get_rel_pos(wp, buffer + i); } /* Truncate at window boundary. */ --- 8156,8173 ---- * half for the filename. */ if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) this_ru_col = (WITH_WIDTH(width) + 1) / 2; ! if (this_ru_col + o < WITH_WIDTH(width)) { ! while (this_ru_col + o < WITH_WIDTH(width)) ! { ! #ifdef FEAT_MBYTE ! if (has_mbyte) ! i += (*mb_char2bytes)(fillchar, buffer + i); ! else ! #endif ! buffer[i++] = fillchar; ! ++o; ! } get_rel_pos(wp, buffer + i); } /* Truncate at window boundary. */ *** ../vim61.468/src/version.c Wed Apr 16 21:02:21 2003 --- src/version.c Wed Apr 16 21:12:23 2003 *************** *** 613,614 **** --- 613,616 ---- { /* Add new patch number below this line */ + /**/ + 469, /**/ -- Engineers are widely recognized as superior marriage material: intelligent, dependable, employed, honest, and handy around the house. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///