To: vim_dev@googlegroups.com Subject: Patch 8.1.2281 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2281 Problem: 'showbreak' cannot be set for one window. Solution: Make 'showbreak' global-local. Files: src/optiondefs.h, src/option.c, src/option.h, src/proto/option.pro, src/structs.h, src/charset.c, src/drawline.c, src/edit.c, src/move.c, src/normal.c, src/ops.c, src/optionstr.c, src/testdir/test_highlight.vim, src/testdir/test_breakindent.vim, runtime/doc/options.txt *** ../vim-8.1.2280/src/optiondefs.h 2019-11-05 21:09:18.629946582 +0100 --- src/optiondefs.h 2019-11-09 22:52:44.013325499 +0100 *************** *** 209,214 **** --- 209,217 ---- # define PV_CULOPT OPT_WIN(WV_CULOPT) # define PV_CC OPT_WIN(WV_CC) #endif + #ifdef FEAT_LINEBREAK + # define PV_SBR OPT_BOTH(OPT_WIN(WV_SBR)) + #endif #ifdef FEAT_STL_OPT # define PV_STL OPT_BOTH(OPT_WIN(WV_STL)) #endif *************** *** 2282,2288 **** {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL, #ifdef FEAT_LINEBREAK ! (char_u *)&p_sbr, PV_NONE, #else (char_u *)NULL, PV_NONE, #endif --- 2285,2291 ---- {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL, #ifdef FEAT_LINEBREAK ! (char_u *)&p_sbr, PV_SBR, #else (char_u *)NULL, PV_NONE, #endif *** ../vim-8.1.2280/src/option.c 2019-11-02 22:54:37.405188813 +0100 --- src/option.c 2019-11-09 23:09:00.565199580 +0100 *************** *** 5167,5172 **** --- 5167,5177 ---- clear_string_option(&buf->b_p_cm); break; #endif + #ifdef FEAT_LINEBREAK + case PV_SBR: + clear_string_option(&((win_T *)from)->w_p_sbr); + break; + #endif #ifdef FEAT_STL_OPT case PV_STL: clear_string_option(&((win_T *)from)->w_p_stl); *************** *** 5229,5234 **** --- 5234,5242 ---- #if defined(FEAT_CRYPT) case PV_CM: return (char_u *)&(curbuf->b_p_cm); #endif + #ifdef FEAT_LINEBREAK + case PV_SBR: return (char_u *)&(curwin->w_p_sbr); + #endif #ifdef FEAT_STL_OPT case PV_STL: return (char_u *)&(curwin->w_p_stl); #endif *************** *** 5315,5320 **** --- 5323,5332 ---- case PV_CM: return *curbuf->b_p_cm != NUL ? (char_u *)&(curbuf->b_p_cm) : p->var; #endif + #ifdef FEAT_LINEBREAK + case PV_SBR: return *curwin->w_p_sbr != NUL + ? (char_u *)&(curwin->w_p_sbr) : p->var; + #endif #ifdef FEAT_STL_OPT case PV_STL: return *curwin->w_p_stl != NUL ? (char_u *)&(curwin->w_p_stl) : p->var; *************** *** 5581,5586 **** --- 5593,5601 ---- to->wo_rl = from->wo_rl; to->wo_rlc = vim_strsave(from->wo_rlc); #endif + #ifdef FEAT_LINEBREAK + to->wo_sbr = vim_strsave(from->wo_sbr); + #endif #ifdef FEAT_STL_OPT to->wo_stl = vim_strsave(from->wo_stl); #endif *************** *** 5682,5687 **** --- 5697,5705 ---- #ifdef FEAT_RIGHTLEFT check_string_option(&wop->wo_rlc); #endif + #ifdef FEAT_LINEBREAK + check_string_option(&wop->wo_sbr); + #endif #ifdef FEAT_STL_OPT check_string_option(&wop->wo_stl); #endif *************** *** 5728,5733 **** --- 5746,5754 ---- #ifdef FEAT_RIGHTLEFT clear_string_option(&wop->wo_rlc); #endif + #ifdef FEAT_LINEBREAK + clear_string_option(&wop->wo_sbr); + #endif #ifdef FEAT_STL_OPT clear_string_option(&wop->wo_stl); #endif *************** *** 7257,7262 **** --- 7278,7298 ---- return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags; } + #if defined(FEAT_LINEBREAK) || defined(PROTO) + /* + * Get the local or global value of 'showbreak'. + */ + char_u * + get_showbreak_value(win_T *win) + { + if (win->w_p_sbr == NULL || *win->w_p_sbr == NUL) + return p_sbr; + if (STRCMP(win->w_p_sbr, "NONE") == 0) + return empty_option; + return win->w_p_sbr; + } + #endif + #if defined(FEAT_SIGNS) || defined(PROTO) /* * Return TRUE when window "wp" has a column to draw signs in. *** ../vim-8.1.2280/src/option.h 2019-11-05 21:09:18.629946582 +0100 --- src/option.h 2019-11-09 22:53:21.169157313 +0100 *************** *** 1271,1276 **** --- 1271,1279 ---- , WV_CULOPT , WV_CC #endif + #ifdef FEAT_LINEBREAK + , WV_SBR + #endif #ifdef FEAT_STL_OPT , WV_STL #endif *** ../vim-8.1.2280/src/proto/option.pro 2019-09-25 20:37:22.073343455 +0200 --- src/proto/option.pro 2019-11-09 22:54:36.632820156 +0100 *************** *** 80,85 **** --- 80,86 ---- void find_mps_values(int *initc, int *findc, int *backwards, int switchit); int briopt_check(win_T *wp); unsigned int get_bkc_value(buf_T *buf); + char_u *get_showbreak_value(win_T *win); int signcolumn_on(win_T *wp); dict_T *get_winbuf_options(int bufopt); int fill_culopt_flags(char_u *val, win_T *wp); *** ../vim-8.1.2280/src/structs.h 2019-11-09 22:28:08.183680610 +0100 --- src/structs.h 2019-11-09 22:48:51.298419319 +0100 *************** *** 254,259 **** --- 254,263 ---- char_u *wo_cc; # define w_p_cc w_onebuf_opt.wo_cc // 'colorcolumn' #endif + #ifdef FEAT_LINEBREAK + char_u *wo_sbr; + #define w_p_sbr w_onebuf_opt.wo_sbr // 'showbreak' + #endif #ifdef FEAT_STL_OPT char_u *wo_stl; #define w_p_stl w_onebuf_opt.wo_stl // 'statusline' *** ../vim-8.1.2280/src/charset.c 2019-09-15 14:49:49.149286479 +0200 --- src/charset.c 2019-11-09 22:56:43.908262960 +0100 *************** *** 936,942 **** colnr_T col) { #ifdef FEAT_LINEBREAK ! if (!curwin->w_p_lbr && *p_sbr == NUL && !curwin->w_p_bri) { #endif if (curwin->w_p_wrap) --- 936,943 ---- colnr_T col) { #ifdef FEAT_LINEBREAK ! if (!curwin->w_p_lbr && *get_showbreak_value(curwin) == NUL ! && !curwin->w_p_bri) { #endif if (curwin->w_p_wrap) *************** *** 991,1001 **** char_u *ps; int tab_corr = (*s == TAB); int n; /* * No 'linebreak', 'showbreak' and 'breakindent': return quickly. */ ! if (!wp->w_p_lbr && !wp->w_p_bri && *p_sbr == NUL) #endif { if (wp->w_p_wrap) --- 992,1003 ---- char_u *ps; int tab_corr = (*s == TAB); int n; + char_u *sbr; /* * No 'linebreak', 'showbreak' and 'breakindent': return quickly. */ ! if (!wp->w_p_lbr && !wp->w_p_bri && *get_showbreak_value(wp) == NUL) #endif { if (wp->w_p_wrap) *************** *** 1069,1075 **** * Set *headp to the size of what we add. */ added = 0; ! if ((*p_sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && col != 0) { colnr_T sbrlen = 0; int numberwidth = win_col_off(wp); --- 1071,1078 ---- * Set *headp to the size of what we add. */ added = 0; ! sbr = get_showbreak_value(wp); ! if ((*sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && col != 0) { colnr_T sbrlen = 0; int numberwidth = win_col_off(wp); *************** *** 1082,1090 **** numberextra = wp->w_width - (numberextra - win_col_off2(wp)); if (col >= numberextra && numberextra > 0) col %= numberextra; ! if (*p_sbr != NUL) { ! sbrlen = (colnr_T)MB_CHARLEN(p_sbr); if (col >= sbrlen) col -= sbrlen; } --- 1085,1093 ---- numberextra = wp->w_width - (numberextra - win_col_off2(wp)); if (col >= numberextra && numberextra > 0) col %= numberextra; ! if (*sbr != NUL) { ! sbrlen = (colnr_T)MB_CHARLEN(sbr); if (col >= sbrlen) col -= sbrlen; } *************** *** 1098,1104 **** if (col == 0 || col + size + sbrlen > (colnr_T)wp->w_width) { added = 0; ! if (*p_sbr != NUL) { if (size + sbrlen + numberwidth > (colnr_T)wp->w_width) { --- 1101,1107 ---- if (col == 0 || col + size + sbrlen > (colnr_T)wp->w_width) { added = 0; ! if (*sbr != NUL) { if (size + sbrlen + numberwidth > (colnr_T)wp->w_width) { *************** *** 1109,1121 **** if (width <= 0) width = (colnr_T)1; ! added += ((size - prev_width) / width) * vim_strsize(p_sbr); if ((size - prev_width) % width) // wrapped, add another length of 'sbr' ! added += vim_strsize(p_sbr); } else ! added += vim_strsize(p_sbr); } if (wp->w_p_bri) added += get_breakindent_win(wp, line); --- 1112,1124 ---- if (width <= 0) width = (colnr_T)1; ! added += ((size - prev_width) / width) * vim_strsize(sbr); if ((size - prev_width) % width) // wrapped, add another length of 'sbr' ! added += vim_strsize(sbr); } else ! added += vim_strsize(sbr); } if (wp->w_p_bri) added += get_breakindent_win(wp, line); *************** *** 1242,1248 **** */ if ((!wp->w_p_list || lcs_tab1 != NUL) #ifdef FEAT_LINEBREAK ! && !wp->w_p_lbr && *p_sbr == NUL && !wp->w_p_bri #endif ) { --- 1245,1251 ---- */ if ((!wp->w_p_list || lcs_tab1 != NUL) #ifdef FEAT_LINEBREAK ! && !wp->w_p_lbr && *get_showbreak_value(wp) == NUL && !wp->w_p_bri #endif ) { *** ../vim-8.1.2280/src/drawline.c 2019-11-09 21:28:06.526103024 +0100 --- src/drawline.c 2019-11-09 22:58:05.379912640 +0100 *************** *** 1141,1147 **** #ifdef FEAT_LINEBREAK if (wp->w_p_brisbr && draw_state == WL_BRI - 1 ! && n_extra == 0 && *p_sbr != NUL) // draw indent after showbreak value draw_state = WL_BRI; else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0) --- 1141,1147 ---- #ifdef FEAT_LINEBREAK if (wp->w_p_brisbr && draw_state == WL_BRI - 1 ! && n_extra == 0 && *get_showbreak_value(wp) != NUL) // draw indent after showbreak value draw_state = WL_BRI; else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0) *************** *** 1187,1192 **** --- 1187,1194 ---- #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) if (draw_state == WL_SBR - 1 && n_extra == 0) { + char_u *sbr; + draw_state = WL_SBR; # ifdef FEAT_DIFF if (filler_todo > 0) *************** *** 1212,1227 **** } # endif # ifdef FEAT_LINEBREAK ! if (*p_sbr != NUL && need_showbreak) { // Draw 'showbreak' at the start of each broken line. ! p_extra = p_sbr; c_extra = NUL; c_final = NUL; ! n_extra = (int)STRLEN(p_sbr); char_attr = HL_ATTR(HLF_AT); need_showbreak = FALSE; ! vcol_sbr = vcol + MB_CHARLEN(p_sbr); // Correct end of highlighted area for 'showbreak', // required when 'linebreak' is also set. if (tocol == vcol) --- 1214,1230 ---- } # endif # ifdef FEAT_LINEBREAK ! sbr = get_showbreak_value(wp); ! if (*sbr != NUL && need_showbreak) { // Draw 'showbreak' at the start of each broken line. ! p_extra = sbr; c_extra = NUL; c_final = NUL; ! n_extra = (int)STRLEN(sbr); char_attr = HL_ATTR(HLF_AT); need_showbreak = FALSE; ! vcol_sbr = vcol + MB_CHARLEN(sbr); // Correct end of highlighted area for 'showbreak', // required when 'linebreak' is also set. if (tocol == vcol) *************** *** 2011,2020 **** int tab_len = 0; long vcol_adjusted = vcol; // removed showbreak length #ifdef FEAT_LINEBREAK // only adjust the tab_len, when at the first column // after the showbreak value was drawn ! if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) ! vcol_adjusted = vcol - MB_CHARLEN(p_sbr); #endif // tab amount depends on current column #ifdef FEAT_VARTABS --- 2014,2025 ---- int tab_len = 0; long vcol_adjusted = vcol; // removed showbreak length #ifdef FEAT_LINEBREAK + char_u *sbr = get_showbreak_value(wp); + // only adjust the tab_len, when at the first column // after the showbreak value was drawn ! if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) ! vcol_adjusted = vcol - MB_CHARLEN(sbr); #endif // tab amount depends on current column #ifdef FEAT_VARTABS *** ../vim-8.1.2280/src/edit.c 2019-11-06 13:59:12.934333184 +0100 --- src/edit.c 2019-11-09 22:58:18.007858714 +0100 *************** *** 3238,3244 **** /* getviscol() is slow, skip it when 'showbreak' is empty, * 'breakindent' is not set and there are no multi-byte * characters */ ! if ((*p_sbr == NUL && !curwin->w_p_bri && !has_mbyte) || getviscol() < v) break; ++width; --- 3238,3244 ---- /* getviscol() is slow, skip it when 'showbreak' is empty, * 'breakindent' is not set and there are no multi-byte * characters */ ! if ((*get_showbreak_value(curwin) == NUL && !curwin->w_p_bri && !has_mbyte) || getviscol() < v) break; ++width; *** ../vim-8.1.2280/src/move.c 2019-10-27 21:39:04.707620926 +0100 --- src/move.c 2019-11-09 22:59:04.819659622 +0100 *************** *** 988,993 **** --- 988,995 ---- /* long line wrapping, adjust curwin->w_wrow */ if (curwin->w_wcol >= curwin->w_width) { + char_u *sbr; + /* this same formula is used in validate_cursor_col() */ n = (curwin->w_wcol - curwin->w_width) / width + 1; curwin->w_wcol -= n * width; *************** *** 997,1004 **** /* When cursor wraps to first char of next line in Insert * mode, the 'showbreak' string isn't shown, backup to first * column */ ! if (*p_sbr && *ml_get_cursor() == NUL ! && curwin->w_wcol == (int)vim_strsize(p_sbr)) curwin->w_wcol = 0; #endif } --- 999,1007 ---- /* When cursor wraps to first char of next line in Insert * mode, the 'showbreak' string isn't shown, backup to first * column */ ! sbr = get_showbreak_value(curwin); ! if (*sbr && *ml_get_cursor() == NUL ! && curwin->w_wcol == (int)vim_strsize(sbr)) curwin->w_wcol = 0; #endif } *** ../vim-8.1.2280/src/normal.c 2019-10-31 19:55:47.516275360 +0100 --- src/normal.c 2019-11-09 23:00:34.915279562 +0100 *************** *** 1768,1780 **** --- 1768,1783 ---- { # ifdef FEAT_LINEBREAK char_u *saved_sbr = p_sbr; + char_u *saved_w_sbr = curwin->w_p_sbr; /* Make 'sbr' empty for a moment to get the correct size. */ p_sbr = empty_option; + curwin->w_p_sbr = empty_option; # endif getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol); # ifdef FEAT_LINEBREAK p_sbr = saved_sbr; + curwin->w_p_sbr = saved_w_sbr; # endif sprintf((char *)showcmd_buf, "%ldx%ld", lines, (long)(rightcol - leftcol + 1)); *************** *** 2577,2584 **** validate_virtcol(); virtcol = curwin->w_virtcol; #if defined(FEAT_LINEBREAK) ! if (virtcol > (colnr_T)width1 && *p_sbr != NUL) ! virtcol -= vim_strsize(p_sbr); #endif if (virtcol > curwin->w_curswant --- 2580,2587 ---- validate_virtcol(); virtcol = curwin->w_virtcol; #if defined(FEAT_LINEBREAK) ! if (virtcol > (colnr_T)width1 && *get_showbreak_value(curwin) != NUL) ! virtcol -= vim_strsize(get_showbreak_value(curwin)); #endif if (virtcol > curwin->w_curswant *** ../vim-8.1.2280/src/ops.c 2019-10-31 03:21:21.121403678 +0100 --- src/ops.c 2019-11-09 23:01:07.467143169 +0100 *************** *** 3636,3644 **** --- 3636,3646 ---- { #ifdef FEAT_LINEBREAK char_u * saved_sbr = p_sbr; + char_u * saved_w_sbr = curwin->w_p_sbr; /* Make 'sbr' empty for a moment to get the correct size. */ p_sbr = empty_option; + curwin->w_p_sbr = empty_option; #endif oparg.is_VIsual = 1; oparg.block_mode = TRUE; *************** *** 3647,3652 **** --- 3649,3655 ---- &oparg.start_vcol, &oparg.end_vcol); #ifdef FEAT_LINEBREAK p_sbr = saved_sbr; + curwin->w_p_sbr = saved_w_sbr; #endif if (curwin->w_curswant == MAXCOL) oparg.end_vcol = MAXCOL; *** ../vim-8.1.2280/src/optionstr.c 2019-10-20 18:17:08.367431701 +0200 --- src/optionstr.c 2019-11-09 23:03:42.134500761 +0100 *************** *** 1440,1451 **** #ifdef FEAT_LINEBREAK // 'showbreak' ! else if (varp == &p_sbr) { ! for (s = p_sbr; *s; ) { if (ptr2cells(s) != 1) ! errmsg = N_("E595: contains unprintable or wide character"); MB_PTR_ADV(s); } } --- 1440,1451 ---- #ifdef FEAT_LINEBREAK // 'showbreak' ! else if (gvarp == &p_sbr) { ! for (s = *varp; *s; ) { if (ptr2cells(s) != 1) ! errmsg = N_("E595: 'showbreak' contains unprintable or wide character"); MB_PTR_ADV(s); } } *** ../vim-8.1.2280/src/testdir/test_highlight.vim 2019-09-25 20:37:22.073343455 +0200 --- src/testdir/test_highlight.vim 2019-11-09 23:13:29.740113870 +0100 *************** *** 425,430 **** --- 425,431 ---- let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() call NewWindow('topleft 5', 10) + set showbreak=xxx setlocal breakindent breakindentopt=min:0,shift:1 showbreak=> call setline(1, ' ' . repeat('a', 9) . 'bcd') call matchadd('Search', '\n') *************** *** 482,487 **** --- 483,489 ---- call CloseWindow() set showbreak= + setlocal showbreak= exe hiCursorLine endfunc *** ../vim-8.1.2280/src/testdir/test_breakindent.vim 2019-11-03 15:46:40.614538718 +0100 --- src/testdir/test_breakindent.vim 2019-11-09 23:16:46.395327990 +0100 *************** *** 62,68 **** func Test_breakindent02() " simple breakindent test with showbreak set ! call s:test_windows('setl briopt=min:0 sbr=>>') let lines = s:screen_lines(line('.'),8) let expect = [ \ " abcd", --- 62,69 ---- func Test_breakindent02() " simple breakindent test with showbreak set ! set sbr=>> ! call s:test_windows('setl briopt=min:0 sbr=') let lines = s:screen_lines(line('.'),8) let expect = [ \ " abcd", *************** *** 122,128 **** func Test_breakindent04() " breakindent set with min width 18 ! call s:test_windows('setl sbr= briopt=min:18') let lines = s:screen_lines(line('.'),8) let expect = [ \ " abcd", --- 123,130 ---- func Test_breakindent04() " breakindent set with min width 18 ! set sbr=<<< ! call s:test_windows('setl sbr=NONE briopt=min:18') let lines = s:screen_lines(line('.'),8) let expect = [ \ " abcd", *************** *** 132,137 **** --- 134,140 ---- call s:compare_lines(expect, lines) " clean up call s:close_windows('set sbr=') + set sbr= endfunc func Test_breakindent04_vartabs() *** ../vim-8.1.2280/runtime/doc/options.txt 2019-11-05 21:09:18.625946594 +0100 --- runtime/doc/options.txt 2019-11-09 22:43:20.648155607 +0100 *************** *** 6748,6754 **** *'showbreak'* *'sbr'* *E595* 'showbreak' 'sbr' string (default "") ! global {not available when compiled without the |+linebreak| feature} String to put at the start of lines that have been wrapped. Useful --- 6753,6759 ---- *'showbreak'* *'sbr'* *E595* 'showbreak' 'sbr' string (default "") ! global or local to window |global-local| {not available when compiled without the |+linebreak| feature} String to put at the start of lines that have been wrapped. Useful *************** *** 6765,6771 **** Note that tabs after the showbreak will be displayed differently. If you want the 'showbreak' to appear in between line numbers, add the "n" flag to 'cpoptions'. ! *'showcmd'* *'sc'* *'noshowcmd'* *'nosc'* 'showcmd' 'sc' boolean (Vim default: on, off for Unix, Vi default: off, set in |defaults.vim|) --- 6770,6779 ---- Note that tabs after the showbreak will be displayed differently. If you want the 'showbreak' to appear in between line numbers, add the "n" flag to 'cpoptions'. ! A window-local value overrules a global value. If the global value is ! set and you want no value in the current window use NONE: > ! :setlocal showbreak=NONE ! < *'showcmd'* *'sc'* *'noshowcmd'* *'nosc'* 'showcmd' 'sc' boolean (Vim default: on, off for Unix, Vi default: off, set in |defaults.vim|) *** ../vim-8.1.2280/src/version.c 2019-11-09 22:28:08.183680610 +0100 --- src/version.c 2019-11-09 23:21:37.762523622 +0100 *************** *** 743,744 **** --- 743,746 ---- { /* Add new patch number below this line */ + /**/ + 2281, /**/ -- "I can't complain, but sometimes I still do." (Joe Walsh) /// 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 ///