To: vim_dev@googlegroups.com Subject: Patch 8.2.2569 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2569 Problem: 'fillchars' "stl" and "stlnc" items must be single byte. Solution: Accept multi-byte characters. (Christian Wellenbrock, Yegappan Lakshmanan, closes #7927) Files: runtime/doc/options.txt, src/buffer.c, src/macros.h, src/screen.c, src/testdir/test_fold.vim, src/testdir/test_statusline.vim *** ../vim-8.2.2568/runtime/doc/options.txt 2021-02-17 13:14:03.684013291 +0100 --- runtime/doc/options.txt 2021-03-04 21:44:47.130487489 +0100 *************** *** 3258,3264 **** < This is similar to the default, except that these characters will also be used when there is highlighting. ! for "stl" and "stlnc" only single-byte values are supported. The highlighting used for these items: item highlight group ~ --- 3262,3269 ---- < This is similar to the default, except that these characters will also be used when there is highlighting. ! For "stl" and "stlnc" single-byte and multibyte characters are ! supported. But double-width characters are not supported. The highlighting used for these items: item highlight group ~ *** ../vim-8.2.2568/src/buffer.c 2021-02-15 20:37:58.453374547 +0100 --- src/buffer.c 2021-03-04 21:44:52.486476128 +0100 *************** *** 4157,4165 **** if (fillchar == 0) fillchar = ' '; - // Can't handle a multi-byte fill character yet. - else if (mb_char2len(fillchar) > 1) - fillchar = '-'; // The cursor in windows other than the current one isn't always // up-to-date, esp. because of autocommands and timers. --- 4157,4162 ---- *************** *** 4335,4341 **** // Fill up space left over by half a double-wide char. while (++l < stl_items[stl_groupitem[groupdepth]].stl_minwid) ! *p++ = fillchar; // correct the start of the items for the truncation for (l = stl_groupitem[groupdepth] + 1; l < curitem; l++) --- 4332,4338 ---- // Fill up space left over by half a double-wide char. while (++l < stl_items[stl_groupitem[groupdepth]].stl_minwid) ! MB_CHAR2BYTES(fillchar, p); // correct the start of the items for the truncation for (l = stl_groupitem[groupdepth] + 1; l < curitem; l++) *************** *** 4354,4373 **** // fill by appending characters n = 0 - n; while (l++ < n && p + 1 < out + outlen) ! *p++ = fillchar; } else { // fill by inserting characters ! mch_memmove(t + n - l, t, (size_t)(p - t)); ! l = n - l; if (p + l >= out + outlen) l = (long)((out + outlen) - p - 1); p += l; for (n = stl_groupitem[groupdepth] + 1; n < curitem; n++) stl_items[n].stl_start += l; for ( ; l > 0; l--) ! *t++ = fillchar; } } continue; --- 4351,4370 ---- // fill by appending characters n = 0 - n; while (l++ < n && p + 1 < out + outlen) ! MB_CHAR2BYTES(fillchar, p); } else { // fill by inserting characters ! l = (n - l) * MB_CHAR2LEN(fillchar); ! mch_memmove(t + l, t, (size_t)(p - t)); if (p + l >= out + outlen) l = (long)((out + outlen) - p - 1); p += l; for (n = stl_groupitem[groupdepth] + 1; n < curitem; n++) stl_items[n].stl_start += l; for ( ; l > 0; l--) ! MB_CHAR2BYTES(fillchar, t); } } continue; *************** *** 4746,4768 **** if (l + 1 == minwid && fillchar == '-' && VIM_ISDIGIT(*t)) *p++ = ' '; else ! *p++ = fillchar; } minwid = 0; } else minwid *= -1; ! while (*t && p + 1 < out + outlen) { - *p++ = *t++; // Change a space by fillchar, unless fillchar is '-' and a // digit follows. ! if (fillable && p[-1] == ' ' ! && (!VIM_ISDIGIT(*t) || fillchar != '-')) ! p[-1] = fillchar; } for (; l < minwid && p + 1 < out + outlen; l++) ! *p++ = fillchar; } else if (num >= 0) { --- 4743,4766 ---- if (l + 1 == minwid && fillchar == '-' && VIM_ISDIGIT(*t)) *p++ = ' '; else ! MB_CHAR2BYTES(fillchar, p); } minwid = 0; } else minwid *= -1; ! for (; *t && p + 1 < out + outlen; t++) { // Change a space by fillchar, unless fillchar is '-' and a // digit follows. ! if (fillable && *t == ' ' ! && (!VIM_ISDIGIT(*(t + 1)) || fillchar != '-')) ! MB_CHAR2BYTES(fillchar, p); ! else ! *p++ = *t; } for (; l < minwid && p + 1 < out + outlen; l++) ! MB_CHAR2BYTES(fillchar, p); } else if (num >= 0) { *************** *** 4865,4871 **** } // Fill up for half a double-wide character. while (++width < maxwidth) ! *s++ = fillchar; } else s = out + maxwidth - 1; --- 4863,4869 ---- } // Fill up for half a double-wide character. while (++width < maxwidth) ! MB_CHAR2BYTES(fillchar, s); } else s = out + maxwidth - 1; *************** *** 4897,4903 **** while (++width < maxwidth) { s = s + STRLEN(s); ! *s++ = fillchar; *s = NUL; } --- 4895,4901 ---- while (++width < maxwidth) { s = s + STRLEN(s); ! MB_CHAR2BYTES(fillchar, s); *s = NUL; } *************** *** 4920,4931 **** break; if (l < itemcnt) { ! p = stl_items[l].stl_start + maxwidth - width; STRMOVE(p, stl_items[l].stl_start); ! for (s = stl_items[l].stl_start; s < p; s++) ! *s = fillchar; for (l++; l < itemcnt; l++) ! stl_items[l].stl_start += maxwidth - width; width = maxwidth; } } --- 4918,4930 ---- break; if (l < itemcnt) { ! int middlelength = (maxwidth - width) * MB_CHAR2LEN(fillchar); ! p = stl_items[l].stl_start + middlelength; STRMOVE(p, stl_items[l].stl_start); ! for (s = stl_items[l].stl_start; s < p;) ! MB_CHAR2BYTES(fillchar, s); for (l++; l < itemcnt; l++) ! stl_items[l].stl_start += middlelength; width = maxwidth; } } *** ../vim-8.2.2568/src/macros.h 2021-03-03 13:25:59.535913158 +0100 --- src/macros.h 2021-03-04 21:49:46.925845060 +0100 *************** *** 252,257 **** --- 252,258 ---- #define MB_CHARLEN(p) (has_mbyte ? mb_charlen(p) : (int)STRLEN(p)) #define MB_CHAR2LEN(c) (has_mbyte ? mb_char2len(c) : 1) #define PTR2CHAR(p) (has_mbyte ? mb_ptr2char(p) : (int)*(p)) + #define MB_CHAR2BYTES(c, b) do { if (has_mbyte) (b) += (*mb_char2bytes)((c), (b)); else *(b)++ = (c); } while(0) #ifdef FEAT_AUTOCHDIR # define DO_AUTOCHDIR do { if (p_acd) do_autochdir(); } while (0) *** ../vim-8.2.2568/src/screen.c 2021-03-03 13:25:59.535913158 +0100 --- src/screen.c 2021-03-04 21:44:52.486476128 +0100 *************** *** 266,272 **** empty = (fdc == 1) ? 0 : 1; // If the column is too narrow, we start at the lowest level that ! // fits and use numbers to indicated the depth. first_level = level - fdc - closed + 1 + empty; if (first_level < 1) first_level = 1; --- 266,272 ---- empty = (fdc == 1) ? 0 : 1; // If the column is too narrow, we start at the lowest level that ! // fits and use numbers to indicate the depth. first_level = level - fdc - closed + 1 + empty; if (first_level < 1) first_level = 1; *** ../vim-8.2.2568/src/testdir/test_fold.vim 2021-03-03 13:25:59.535913158 +0100 --- src/testdir/test_fold.vim 2021-03-04 21:44:52.486476128 +0100 *************** *** 987,993 **** \ a:fs .. 'six ', \ ], ScreenLines([1, 6], 7)) ! setlocal foldcolumn& endfunc func Test_foldcolumn_multibyte_char() --- 987,1052 ---- \ a:fs .. 'six ', \ ], ScreenLines([1, 6], 7)) ! " Enable number and sign columns and place some signs ! setlocal fdc=3 ! setlocal number ! setlocal signcolumn=auto ! sign define S1 text=-> ! sign place 10 line=3 name=S1 ! call assert_equal([ ! \ a:fo .. ' 1 one ', ! \ a:fs .. a:fo .. ' 2 two ', ! \ '2' .. a:fo .. ' -> 3 three', ! \ '23 4 four ', ! \ a:fs .. a:fs .. ' 5 five ', ! \ a:fs .. ' 6 six ' ! \ ], ScreenLines([1, 6], 14)) ! ! " Test with 'rightleft' ! if has('rightleft') ! setlocal rightleft ! let lines = ScreenLines([1, 6], winwidth(0)) ! call assert_equal('o 1 ' .. a:fo, ! \ strcharpart(lines[0], strchars(lines[0]) - 10, 10)) ! call assert_equal('t 2 ' .. a:fo .. a:fs, ! \ strcharpart(lines[1], strchars(lines[1]) - 10, 10)) ! call assert_equal('t 3 >- ' .. a:fo .. '2', ! \ strcharpart(lines[2], strchars(lines[2]) - 10, 10)) ! call assert_equal('f 4 32', ! \ strcharpart(lines[3], strchars(lines[3]) - 10, 10)) ! call assert_equal('f 5 ' .. a:fs .. a:fs, ! \ strcharpart(lines[4], strchars(lines[4]) - 10, 10)) ! call assert_equal('s 6 ' .. a:fs, ! \ strcharpart(lines[5], strchars(lines[5]) - 10, 10)) ! setlocal norightleft ! endif ! ! sign unplace * ! sign undefine S1 ! setlocal number& signcolumn& ! ! " Add a test with more than 9 folds (and then delete some folds) ! normal zE ! for i in range(1, 10) ! normal zfGzo ! endfor ! normal zR ! call assert_equal([ ! \ a:fo .. a:fo .. ' one ', ! \ '9> two ' ! \ ], ScreenLines([1, 2], 7)) ! normal 1Gzd ! call assert_equal([ ! \ a:fo .. a:fo .. ' one ', ! \ '89 two ' ! \ ], ScreenLines([1, 2], 7)) ! normal 1Gzdzdzdzdzdzdzd ! call assert_equal([ ! \ a:fo .. a:fo .. ' one ', ! \ a:fs .. a:fs .. ' two ' ! \ ], ScreenLines([1, 2], 7)) ! ! setlocal foldcolumn& number& signcolumn& endfunc func Test_foldcolumn_multibyte_char() *** ../vim-8.2.2568/src/testdir/test_statusline.vim 2020-10-26 21:05:23.905469139 +0100 --- src/testdir/test_statusline.vim 2021-03-04 21:44:52.486476128 +0100 *************** *** 464,468 **** --- 464,483 ---- set ls& stl& endfunc + " Test using a multibyte character for 'stl' and 'stlnc' items in 'fillchars' + " with a custom 'statusline' + func Test_statusline_mbyte_fillchar() + only + set laststatus=2 + set fillchars=vert:\|,fold:-,stl:━,stlnc:═ + set statusline=a%=b + call assert_match('^a\+━\+b$', s:get_statusline()) + vnew + call assert_match('^a\+━\+b━a\+═\+b$', s:get_statusline()) + wincmd w + call assert_match('^a\+═\+b═a\+━\+b$', s:get_statusline()) + set statusline& fillchars& laststatus& + %bw! + endfunc " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.2568/src/version.c 2021-03-04 21:35:02.283692552 +0100 --- src/version.c 2021-03-04 21:55:09.701312552 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2569, /**/ -- Did Adam and Eve have navels? /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///