To: vim_dev@googlegroups.com Subject: Patch 8.1.2019 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2019 Problem: 'cursorline' always highlights the whole line. Solution: Add 'cursorlineopt' to specify what is highlighted. (closes #4693) Files: runtime/doc/options.txt, runtime/doc/quickref.txt, runtime/doc/syntax.txt, runtime/optwin.vim, src/option.c, src/option.h, src/screen.c, src/structs.h, src/testdir/Make_all.mak, src/testdir/gen_opt_test.vim, src/testdir/test_alot.vim, src/testdir/test_cursorline.vim *** ../vim-8.1.2018/runtime/doc/options.txt 2019-08-21 14:36:29.399376050 +0200 --- runtime/doc/options.txt 2019-09-09 21:54:03.095871648 +0200 *************** *** 2459,2471 **** local to window {not available when compiled without the |+syntax| feature} ! Highlight the screen line of the cursor with CursorLine ! |hl-CursorLine|. Useful to easily spot the cursor. Will make screen ! redrawing slower. When Visual mode is active the highlighting isn't used to make it easier to see the selected text. *'debug'* 'debug' string (default "") global --- 2461,2486 ---- local to window {not available when compiled without the |+syntax| feature} ! Highlight the text line of the cursor with CursorLine |hl-CursorLine|. ! Useful to easily spot the cursor. Will make screen redrawing slower. When Visual mode is active the highlighting isn't used to make it easier to see the selected text. + *'cursorlineopt'* *'culopt'* + 'cursorlineopt' 'culopt' string (default: "both") + local to window + {not in Vi} + {not available when compiled without the |+syntax| + feature} + Settings for how 'cursorline' is displayed. Valid values: + "line" Highlight the text line of the cursor with + CursorLine |hl-CursorLine|. + "number" Highlight the line number of the cursor with + CursorLineNr |hl-CursorLineNr|. + "both" Highlight as both "line" and "number" are set. + + *'debug'* 'debug' string (default "") global *** ../vim-8.1.2018/runtime/doc/quickref.txt 2019-08-20 21:11:43.176949148 +0200 --- runtime/doc/quickref.txt 2019-09-09 21:51:20.664167332 +0200 *************** *** 670,675 **** --- 670,676 ---- 'cursorbind' 'crb' move cursor in window as it moves in other windows 'cursorcolumn' 'cuc' highlight the screen column of the cursor 'cursorline' 'cul' highlight the screen line of the cursor + 'cursorlineopt' 'culopt' settings for 'cursorline' 'debug' set to "msg" to see all error messages 'define' 'def' pattern to be used to find a macro definition 'delcombine' 'deco' delete combining characters on their own *************** *** 800,805 **** --- 801,807 ---- 'menuitems' 'mis' maximum number of items in a menu 'mkspellmem' 'msm' memory used before |:mkspell| compresses the tree 'modeline' 'ml' recognize modelines at start or end of file + 'modelineexpr' 'mle' allow setting expression options from a modeline 'modelines' 'mls' number of lines checked for modelines 'modifiable' 'ma' changes to the text are not possible 'modified' 'mod' buffer has been modified *** ../vim-8.1.2018/runtime/doc/syntax.txt 2019-05-09 19:26:34.132388790 +0200 --- runtime/doc/syntax.txt 2019-09-09 21:51:20.668167325 +0200 *************** *** 5042,5048 **** LineNr Line number for ":number" and ":#" commands, and when 'number' or 'relativenumber' option is set. *hl-CursorLineNr* ! CursorLineNr Like LineNr when 'cursorline' or 'relativenumber' is set for the cursor line. *hl-MatchParen* MatchParen The character under the cursor or just before it, if it --- 5042,5049 ---- LineNr Line number for ":number" and ":#" commands, and when 'number' or 'relativenumber' option is set. *hl-CursorLineNr* ! CursorLineNr Like LineNr when 'cursorline' is set and 'cursorlineopt' is ! set to "number" or "both", or 'relativenumber' is set, for the cursor line. *hl-MatchParen* MatchParen The character under the cursor or just before it, if it *** ../vim-8.1.2018/runtime/optwin.vim 2019-08-20 21:11:43.176949148 +0200 --- runtime/optwin.vim 2019-09-09 21:51:20.668167325 +0200 *************** *** 429,434 **** --- 429,437 ---- call append("$", "cursorline\thighlight the screen line of the cursor") call append("$", "\t(local to window)") call BinOptionL("cul") + call append("$", "cursorlineopt\tspecifies which area 'cursorline' highlights") + call append("$", "\t(local to window)") + call OptionL("culopt") call append("$", "colorcolumn\tcolumns to highlight") call append("$", "\t(local to window)") call OptionL("cc") *************** *** 997,1002 **** --- 1000,1007 ---- call append("$", "modeline\tenable using settings from modelines when reading a file") call append("$", "\t(local to buffer)") call BinOptionL("ml") + call append("$", "modelineexpr\tallow setting expression options from a modeline") + call BinOptionG("mle", &mle) call append("$", "modelines\tnumber of lines to check for modelines") call append("$", " \tset mls=" . &mls) call append("$", "binary\tbinary file editing") *************** *** 1178,1183 **** --- 1183,1190 ---- if has("win32") call append("$", "shellslash\tuse forward slashes in file names; for Unix-like shells") call BinOptionG("ssl", &ssl) + call append("$", "completeslash\tspecifies slash/backslash used for completion") + call OptionG("csl", &csl) endif endif *** ../vim-8.1.2018/src/option.c 2019-09-02 22:31:08.010296361 +0200 --- src/option.c 2019-09-09 21:51:20.668167325 +0200 *************** *** 238,243 **** --- 238,244 ---- #ifdef FEAT_SYN_HL # define PV_CUC OPT_WIN(WV_CUC) # define PV_CUL OPT_WIN(WV_CUL) + # define PV_CULOPT OPT_WIN(WV_CULOPT) # define PV_CC OPT_WIN(WV_CC) #endif #ifdef FEAT_STL_OPT *************** *** 993,998 **** --- 994,1006 ---- (char_u *)NULL, PV_NONE, #endif {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, + {"cursorlineopt", "culopt", P_STRING|P_VI_DEF|P_RWIN, + #ifdef FEAT_SYN_HL + (char_u *)VAR_WIN, PV_CULOPT, + #else + (char_u *)NULL, PV_NONE, + #endif + {(char_u *)"both", (char_u *)0L} SCTX_INIT}, {"debug", NULL, P_STRING|P_VI_DEF, (char_u *)&p_debug, PV_NONE, {(char_u *)"", (char_u *)0L} SCTX_INIT}, *************** *** 3228,3233 **** --- 3236,3244 ---- #if defined(MSWIN) && defined(FEAT_TERMINAL) static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL}; #endif + #ifdef FEAT_SYN_HL + static char *(p_culopt_values[]) = {"line", "number", "both", NULL}; + #endif static void set_options_default(int opt_flags); static void set_string_default_esc(char *name, char_u *val, int escape); *************** *** 6326,6331 **** --- 6337,6351 ---- } #ifdef FEAT_SYN_HL + /* 'cursorlineopt' */ + else if (varp == &curwin->w_p_culopt + || gvarp == &curwin->w_allbuf_opt.wo_culopt) + { + if (**varp == NUL + || check_opt_strings(*varp, p_culopt_values, FALSE) != OK) + errmsg = e_invarg; + } + /* 'colorcolumn' */ else if (varp == &curwin->w_p_cc) errmsg = check_colorcolumn(curwin); *************** *** 10775,10780 **** --- 10795,10801 ---- #ifdef FEAT_SYN_HL case PV_CUC: return (char_u *)&(curwin->w_p_cuc); case PV_CUL: return (char_u *)&(curwin->w_p_cul); + case PV_CULOPT: return (char_u *)&(curwin->w_p_culopt); case PV_CC: return (char_u *)&(curwin->w_p_cc); #endif #ifdef FEAT_DIFF *************** *** 11012,11017 **** --- 11033,11039 ---- #ifdef FEAT_SYN_HL to->wo_cuc = from->wo_cuc; to->wo_cul = from->wo_cul; + to->wo_culopt = vim_strsave(from->wo_culopt); to->wo_cc = vim_strsave(from->wo_cc); #endif #ifdef FEAT_DIFF *************** *** 11087,11092 **** --- 11109,11115 ---- check_string_option(&wop->wo_stl); #endif #ifdef FEAT_SYN_HL + check_string_option(&wop->wo_culopt); check_string_option(&wop->wo_cc); #endif #ifdef FEAT_CONCEAL *************** *** 11132,11137 **** --- 11155,11161 ---- clear_string_option(&wop->wo_stl); #endif #ifdef FEAT_SYN_HL + clear_string_option(&wop->wo_culopt); clear_string_option(&wop->wo_cc); #endif #ifdef FEAT_CONCEAL *** ../vim-8.1.2018/src/option.h 2019-08-21 14:36:29.395376065 +0200 --- src/option.h 2019-09-09 21:51:20.668167325 +0200 *************** *** 1161,1166 **** --- 1161,1167 ---- #ifdef FEAT_SYN_HL , WV_CUC , WV_CUL + , WV_CULOPT , WV_CC #endif #ifdef FEAT_STL_OPT *** ../vim-8.1.2018/src/screen.c 2019-09-02 22:31:08.014296345 +0200 --- src/screen.c 2019-09-09 21:51:20.668167325 +0200 *************** *** 3817,3823 **** { // Do not show the cursor line when Visual mode is active, because it's // not clear what is selected then. Do update w_last_cursorline. ! if (!(wp == curwin && VIsual_active)) { line_attr = HL_ATTR(HLF_CUL); area_highlighting = TRUE; --- 3817,3823 ---- { // Do not show the cursor line when Visual mode is active, because it's // not clear what is selected then. Do update w_last_cursorline. ! if (!(wp == curwin && VIsual_active) && *wp->w_p_culopt != 'n') { line_attr = HL_ATTR(HLF_CUL); area_highlighting = TRUE; *************** *** 4021,4026 **** --- 4021,4027 ---- * TODO: Can we use CursorLine instead of CursorLineNr * when CursorLineNr isn't set? */ if ((wp->w_p_cul || wp->w_p_rnu) + && *wp->w_p_culopt != 'l' && lnum == wp->w_cursor.lnum) char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN)); #endif *************** *** 4055,4061 **** { char_attr = HL_ATTR(diff_hlf); # ifdef FEAT_SYN_HL ! if (wp->w_p_cul && lnum == wp->w_cursor.lnum) char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUL)); # endif --- 4056,4063 ---- { char_attr = HL_ATTR(diff_hlf); # ifdef FEAT_SYN_HL ! if (wp->w_p_cul && lnum == wp->w_cursor.lnum ! && *wp->w_p_culopt != 'n') char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUL)); # endif *************** *** 4117,4123 **** tocol += n_extra; #ifdef FEAT_SYN_HL /* combine 'showbreak' with 'cursorline' */ ! if (wp->w_p_cul && lnum == wp->w_cursor.lnum) char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUL)); #endif --- 4119,4126 ---- tocol += n_extra; #ifdef FEAT_SYN_HL /* combine 'showbreak' with 'cursorline' */ ! if (wp->w_p_cul && lnum == wp->w_cursor.lnum ! && *wp->w_p_culopt != 'n') char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUL)); #endif *************** *** 4212,4218 **** && n_extra == 0) diff_hlf = HLF_CHD; /* changed line */ line_attr = HL_ATTR(diff_hlf); ! if (wp->w_p_cul && lnum == wp->w_cursor.lnum) line_attr = hl_combine_attr(line_attr, HL_ATTR(HLF_CUL)); } #endif --- 4215,4222 ---- && n_extra == 0) diff_hlf = HLF_CHD; /* changed line */ line_attr = HL_ATTR(diff_hlf); ! if (wp->w_p_cul && lnum == wp->w_cursor.lnum ! && *wp->w_p_culopt != 'n') line_attr = hl_combine_attr(line_attr, HL_ATTR(HLF_CUL)); } #endif *************** *** 5180,5186 **** if (vi_attr == 0 || char_attr != vi_attr) { char_attr = HL_ATTR(diff_hlf); ! if (wp->w_p_cul && lnum == wp->w_cursor.lnum) char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUL)); } --- 5184,5191 ---- if (vi_attr == 0 || char_attr != vi_attr) { char_attr = HL_ATTR(diff_hlf); ! if (wp->w_p_cul && lnum == wp->w_cursor.lnum ! && *wp->w_p_culopt != 'n') char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUL)); } *** ../vim-8.1.2018/src/structs.h 2019-09-08 17:11:39.350869449 +0200 --- src/structs.h 2019-09-09 21:51:20.668167325 +0200 *************** *** 249,254 **** --- 249,256 ---- # define w_p_cuc w_onebuf_opt.wo_cuc // 'cursorcolumn' int wo_cul; # define w_p_cul w_onebuf_opt.wo_cul // 'cursorline' + char_u *wo_culopt; + # define w_p_culopt w_onebuf_opt.wo_culopt // 'cursorlineopt' char_u *wo_cc; # define w_p_cc w_onebuf_opt.wo_cc // 'colorcolumn' #endif *** ../vim-8.1.2018/src/testdir/Make_all.mak 2019-08-25 23:07:34.883383627 +0200 --- src/testdir/Make_all.mak 2019-09-09 21:51:20.672167318 +0200 *************** *** 92,97 **** --- 92,98 ---- test_crypt \ test_cscope \ test_cursor_func \ + test_cursorline \ test_curswant \ test_debugger \ test_delete \ *** ../vim-8.1.2018/src/testdir/gen_opt_test.vim 2019-08-21 15:13:24.565040301 +0200 --- src/testdir/gen_opt_test.vim 2019-09-09 21:51:20.672167318 +0200 *************** *** 82,87 **** --- 82,88 ---- \ 'completeslash': [['', 'slash', 'backslash'], ['xxx']], \ 'cryptmethod': [['', 'zip'], ['xxx']], \ 'cscopequickfix': [['', 's-', 's-,c+,e0'], ['xxx', 's,g,d']], + \ 'cursorlineopt': [['both', 'line', 'number'], ['', 'xxx', 'line,number']], \ 'debug': [['', 'msg', 'msg', 'beep'], ['xxx']], \ 'diffopt': [['', 'filler', 'icase,iwhite'], ['xxx', 'algorithm:xxx', 'algorithm:']], \ 'display': [['', 'lastline', 'lastline,uhex'], ['xxx']], *** ../vim-8.1.2018/src/testdir/test_alot.vim 2019-08-12 14:37:01.194209466 +0200 --- src/testdir/test_alot.vim 2019-09-09 21:51:20.672167318 +0200 *************** *** 9,14 **** --- 9,15 ---- source test_changedtick.vim source test_compiler.vim source test_cursor_func.vim + source test_cursorline.vim source test_delete.vim source test_ex_equal.vim source test_ex_undo.vim *** ../vim-8.1.2018/src/testdir/test_cursorline.vim 2019-09-09 22:03:07.058870810 +0200 --- src/testdir/test_cursorline.vim 2019-09-09 21:58:41.475360952 +0200 *************** *** 0 **** --- 1,108 ---- + " Test for cursorline and cursorlineopt + " + source view_util.vim + source check.vim + + function! s:screen_attr(lnum) abort + return map(range(1, 8), 'screenattr(a:lnum, v:val)') + endfunction + + function! s:test_windows(h, w) abort + call NewWindow(a:h, a:w) + endfunction + + function! s:close_windows() abort + call CloseWindow() + endfunction + + function! s:new_hi() abort + redir => save_hi + silent! hi CursorLineNr + redir END + let save_hi = join(split(substitute(save_hi, '\s*xxx\s*', ' ', ''), "\n"), '') + exe 'hi' save_hi 'ctermbg=0 guibg=Black' + return save_hi + endfunction + + func Test_cursorline_highlight1() + let save_hi = s:new_hi() + try + call s:test_windows(10, 20) + call setline(1, repeat(['aaaa'], 10)) + redraw + let attr01 = s:screen_attr(1) + call assert_equal(repeat([attr01[0]], 8), attr01) + + setl number numberwidth=4 + redraw + let attr11 = s:screen_attr(1) + call assert_equal(repeat([attr11[0]], 4), attr11[0:3]) + call assert_equal(repeat([attr11[4]], 4), attr11[4:7]) + call assert_notequal(attr11[0], attr11[4]) + + setl cursorline + redraw + let attr21 = s:screen_attr(1) + let attr22 = s:screen_attr(2) + call assert_equal(repeat([attr21[0]], 4), attr21[0:3]) + call assert_equal(repeat([attr21[4]], 4), attr21[4:7]) + call assert_equal(attr11, attr22) + call assert_notequal(attr22, attr21) + + setl nocursorline relativenumber + redraw + let attr31 = s:screen_attr(1) + call assert_equal(attr21[0:3], attr31[0:3]) + call assert_equal(attr11[4:7], attr31[4:7]) + + call s:close_windows() + finally + exe 'hi' save_hi + endtry + endfunc + + func Test_cursorline_highlight2() + CheckOption cursorlineopt + + let save_hi = s:new_hi() + try + call s:test_windows(10, 20) + call setline(1, repeat(['aaaa'], 10)) + redraw + let attr0 = s:screen_attr(1) + call assert_equal(repeat([attr0[0]], 8), attr0) + + setl number + redraw + let attr1 = s:screen_attr(1) + call assert_notequal(attr0[0:3], attr1[0:3]) + call assert_equal(attr0[0:3], attr1[4:7]) + + setl cursorline cursorlineopt=both + redraw + let attr2 = s:screen_attr(1) + call assert_notequal(attr1[0:3], attr2[0:3]) + call assert_notequal(attr1[4:7], attr2[4:7]) + + setl cursorlineopt=line + redraw + let attr3 = s:screen_attr(1) + call assert_equal(attr1[0:3], attr3[0:3]) + call assert_equal(attr2[4:7], attr3[4:7]) + + setl cursorlineopt=number + redraw + let attr4 = s:screen_attr(1) + call assert_equal(attr2[0:3], attr4[0:3]) + call assert_equal(attr1[4:7], attr4[4:7]) + + setl nonumber + redraw + let attr5 = s:screen_attr(1) + call assert_equal(attr0, attr5) + + call s:close_windows() + finally + exe 'hi' save_hi + endtry + endfunc *** ../vim-8.1.2018/src/version.c 2019-09-09 20:04:04.738340561 +0200 --- src/version.c 2019-09-09 22:02:46.922908068 +0200 *************** *** 759,760 **** --- 759,762 ---- { /* Add new patch number below this line */ + /**/ + 2019, /**/ -- Get a life? What is the URL where it can be downloaded? /// 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 ///