• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision6650e3dff8d41726db215e754176bf701d54e0a1 (tree)
Time2019-09-10 05:15:04
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.1.2019: 'cursorline' always highlights the whole line

Commit: https://github.com/vim/vim/commit/410e98a70bc00ea4bed51e55a8fe20e56a72c087
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 9 22:05:49 2019 +0200

patch 8.1.2019: 'cursorline' always highlights the whole line
Problem: 'cursorline' always highlights the whole line.
Solution: Add 'cursorlineopt' to specify what is highlighted.
(closes #4693)

Change Summary

Incremental Difference

diff -r 4b4c49dee5e6 -r 6650e3dff8d4 runtime/doc/options.txt
--- a/runtime/doc/options.txt Mon Sep 09 20:15:04 2019 +0200
+++ b/runtime/doc/options.txt Mon Sep 09 22:15:04 2019 +0200
@@ -2461,13 +2461,26 @@
24612461 local to window
24622462 {not available when compiled without the |+syntax|
24632463 feature}
2464- Highlight the screen line of the cursor with CursorLine
2465- |hl-CursorLine|. Useful to easily spot the cursor. Will make screen
2466- redrawing slower.
2464+ Highlight the text line of the cursor with CursorLine |hl-CursorLine|.
2465+ Useful to easily spot the cursor. Will make screen redrawing slower.
24672466 When Visual mode is active the highlighting isn't used to make it
24682467 easier to see the selected text.
24692468
24702469
2470+ *'cursorlineopt'* *'culopt'*
2471+'cursorlineopt' 'culopt' string (default: "both")
2472+ local to window
2473+ {not in Vi}
2474+ {not available when compiled without the |+syntax|
2475+ feature}
2476+ Settings for how 'cursorline' is displayed. Valid values:
2477+ "line" Highlight the text line of the cursor with
2478+ CursorLine |hl-CursorLine|.
2479+ "number" Highlight the line number of the cursor with
2480+ CursorLineNr |hl-CursorLineNr|.
2481+ "both" Highlight as both "line" and "number" are set.
2482+
2483+
24712484 *'debug'*
24722485 'debug' string (default "")
24732486 global
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 runtime/doc/quickref.txt
--- a/runtime/doc/quickref.txt Mon Sep 09 20:15:04 2019 +0200
+++ b/runtime/doc/quickref.txt Mon Sep 09 22:15:04 2019 +0200
@@ -670,6 +670,7 @@
670670 'cursorbind' 'crb' move cursor in window as it moves in other windows
671671 'cursorcolumn' 'cuc' highlight the screen column of the cursor
672672 'cursorline' 'cul' highlight the screen line of the cursor
673+'cursorlineopt' 'culopt' settings for 'cursorline'
673674 'debug' set to "msg" to see all error messages
674675 'define' 'def' pattern to be used to find a macro definition
675676 'delcombine' 'deco' delete combining characters on their own
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 runtime/doc/syntax.txt
--- a/runtime/doc/syntax.txt Mon Sep 09 20:15:04 2019 +0200
+++ b/runtime/doc/syntax.txt Mon Sep 09 22:15:04 2019 +0200
@@ -5042,7 +5042,8 @@
50425042 LineNr Line number for ":number" and ":#" commands, and when 'number'
50435043 or 'relativenumber' option is set.
50445044 *hl-CursorLineNr*
5045-CursorLineNr Like LineNr when 'cursorline' or 'relativenumber' is set for
5045+CursorLineNr Like LineNr when 'cursorline' is set and 'cursorlineopt' is
5046+ set to "number" or "both", or 'relativenumber' is set, for
50465047 the cursor line.
50475048 *hl-MatchParen*
50485049 MatchParen The character under the cursor or just before it, if it
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 runtime/optwin.vim
--- a/runtime/optwin.vim Mon Sep 09 20:15:04 2019 +0200
+++ b/runtime/optwin.vim Mon Sep 09 22:15:04 2019 +0200
@@ -429,6 +429,9 @@
429429 call append("$", "cursorline\thighlight the screen line of the cursor")
430430 call append("$", "\t(local to window)")
431431 call <SID>BinOptionL("cul")
432+ call append("$", "cursorlineopt\tspecifies which area 'cursorline' highlights")
433+ call append("$", "\t(local to window)")
434+ call <SID>OptionL("culopt")
432435 call append("$", "colorcolumn\tcolumns to highlight")
433436 call append("$", "\t(local to window)")
434437 call <SID>OptionL("cc")
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 src/option.c
--- a/src/option.c Mon Sep 09 20:15:04 2019 +0200
+++ b/src/option.c Mon Sep 09 22:15:04 2019 +0200
@@ -238,6 +238,7 @@
238238 #ifdef FEAT_SYN_HL
239239 # define PV_CUC OPT_WIN(WV_CUC)
240240 # define PV_CUL OPT_WIN(WV_CUL)
241+# define PV_CULOPT OPT_WIN(WV_CULOPT)
241242 # define PV_CC OPT_WIN(WV_CC)
242243 #endif
243244 #ifdef FEAT_STL_OPT
@@ -993,6 +994,13 @@
993994 (char_u *)NULL, PV_NONE,
994995 #endif
995996 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
997+ {"cursorlineopt", "culopt", P_STRING|P_VI_DEF|P_RWIN,
998+#ifdef FEAT_SYN_HL
999+ (char_u *)VAR_WIN, PV_CULOPT,
1000+#else
1001+ (char_u *)NULL, PV_NONE,
1002+#endif
1003+ {(char_u *)"both", (char_u *)0L} SCTX_INIT},
9961004 {"debug", NULL, P_STRING|P_VI_DEF,
9971005 (char_u *)&p_debug, PV_NONE,
9981006 {(char_u *)"", (char_u *)0L} SCTX_INIT},
@@ -3228,6 +3236,9 @@
32283236 #if defined(MSWIN) && defined(FEAT_TERMINAL)
32293237 static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
32303238 #endif
3239+#ifdef FEAT_SYN_HL
3240+static char *(p_culopt_values[]) = {"line", "number", "both", NULL};
3241+#endif
32313242
32323243 static void set_options_default(int opt_flags);
32333244 static void set_string_default_esc(char *name, char_u *val, int escape);
@@ -6326,6 +6337,15 @@
63266337 }
63276338
63286339 #ifdef FEAT_SYN_HL
6340+ /* 'cursorlineopt' */
6341+ else if (varp == &curwin->w_p_culopt
6342+ || gvarp == &curwin->w_allbuf_opt.wo_culopt)
6343+ {
6344+ if (**varp == NUL
6345+ || check_opt_strings(*varp, p_culopt_values, FALSE) != OK)
6346+ errmsg = e_invarg;
6347+ }
6348+
63296349 /* 'colorcolumn' */
63306350 else if (varp == &curwin->w_p_cc)
63316351 errmsg = check_colorcolumn(curwin);
@@ -10775,6 +10795,7 @@
1077510795 #ifdef FEAT_SYN_HL
1077610796 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
1077710797 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
10798+ case PV_CULOPT: return (char_u *)&(curwin->w_p_culopt);
1077810799 case PV_CC: return (char_u *)&(curwin->w_p_cc);
1077910800 #endif
1078010801 #ifdef FEAT_DIFF
@@ -11012,6 +11033,7 @@
1101211033 #ifdef FEAT_SYN_HL
1101311034 to->wo_cuc = from->wo_cuc;
1101411035 to->wo_cul = from->wo_cul;
11036+ to->wo_culopt = vim_strsave(from->wo_culopt);
1101511037 to->wo_cc = vim_strsave(from->wo_cc);
1101611038 #endif
1101711039 #ifdef FEAT_DIFF
@@ -11087,6 +11109,7 @@
1108711109 check_string_option(&wop->wo_stl);
1108811110 #endif
1108911111 #ifdef FEAT_SYN_HL
11112+ check_string_option(&wop->wo_culopt);
1109011113 check_string_option(&wop->wo_cc);
1109111114 #endif
1109211115 #ifdef FEAT_CONCEAL
@@ -11132,6 +11155,7 @@
1113211155 clear_string_option(&wop->wo_stl);
1113311156 #endif
1113411157 #ifdef FEAT_SYN_HL
11158+ clear_string_option(&wop->wo_culopt);
1113511159 clear_string_option(&wop->wo_cc);
1113611160 #endif
1113711161 #ifdef FEAT_CONCEAL
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 src/option.h
--- a/src/option.h Mon Sep 09 20:15:04 2019 +0200
+++ b/src/option.h Mon Sep 09 22:15:04 2019 +0200
@@ -1161,6 +1161,7 @@
11611161 #ifdef FEAT_SYN_HL
11621162 , WV_CUC
11631163 , WV_CUL
1164+ , WV_CULOPT
11641165 , WV_CC
11651166 #endif
11661167 #ifdef FEAT_STL_OPT
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 src/screen.c
--- a/src/screen.c Mon Sep 09 20:15:04 2019 +0200
+++ b/src/screen.c Mon Sep 09 22:15:04 2019 +0200
@@ -3817,7 +3817,7 @@
38173817 {
38183818 // Do not show the cursor line when Visual mode is active, because it's
38193819 // not clear what is selected then. Do update w_last_cursorline.
3820- if (!(wp == curwin && VIsual_active))
3820+ if (!(wp == curwin && VIsual_active) && *wp->w_p_culopt != 'n')
38213821 {
38223822 line_attr = HL_ATTR(HLF_CUL);
38233823 area_highlighting = TRUE;
@@ -4021,6 +4021,7 @@
40214021 * TODO: Can we use CursorLine instead of CursorLineNr
40224022 * when CursorLineNr isn't set? */
40234023 if ((wp->w_p_cul || wp->w_p_rnu)
4024+ && *wp->w_p_culopt != 'l'
40244025 && lnum == wp->w_cursor.lnum)
40254026 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
40264027 #endif
@@ -4055,7 +4056,8 @@
40554056 {
40564057 char_attr = HL_ATTR(diff_hlf);
40574058 # ifdef FEAT_SYN_HL
4058- if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
4059+ if (wp->w_p_cul && lnum == wp->w_cursor.lnum
4060+ && *wp->w_p_culopt != 'n')
40594061 char_attr = hl_combine_attr(char_attr,
40604062 HL_ATTR(HLF_CUL));
40614063 # endif
@@ -4117,7 +4119,8 @@
41174119 tocol += n_extra;
41184120 #ifdef FEAT_SYN_HL
41194121 /* combine 'showbreak' with 'cursorline' */
4120- if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
4122+ if (wp->w_p_cul && lnum == wp->w_cursor.lnum
4123+ && *wp->w_p_culopt != 'n')
41214124 char_attr = hl_combine_attr(char_attr,
41224125 HL_ATTR(HLF_CUL));
41234126 #endif
@@ -4212,7 +4215,8 @@
42124215 && n_extra == 0)
42134216 diff_hlf = HLF_CHD; /* changed line */
42144217 line_attr = HL_ATTR(diff_hlf);
4215- if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
4218+ if (wp->w_p_cul && lnum == wp->w_cursor.lnum
4219+ && *wp->w_p_culopt != 'n')
42164220 line_attr = hl_combine_attr(line_attr, HL_ATTR(HLF_CUL));
42174221 }
42184222 #endif
@@ -5180,7 +5184,8 @@
51805184 if (vi_attr == 0 || char_attr != vi_attr)
51815185 {
51825186 char_attr = HL_ATTR(diff_hlf);
5183- if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
5187+ if (wp->w_p_cul && lnum == wp->w_cursor.lnum
5188+ && *wp->w_p_culopt != 'n')
51845189 char_attr = hl_combine_attr(char_attr,
51855190 HL_ATTR(HLF_CUL));
51865191 }
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 src/structs.h
--- a/src/structs.h Mon Sep 09 20:15:04 2019 +0200
+++ b/src/structs.h Mon Sep 09 22:15:04 2019 +0200
@@ -249,6 +249,8 @@
249249 # define w_p_cuc w_onebuf_opt.wo_cuc // 'cursorcolumn'
250250 int wo_cul;
251251 # define w_p_cul w_onebuf_opt.wo_cul // 'cursorline'
252+ char_u *wo_culopt;
253+# define w_p_culopt w_onebuf_opt.wo_culopt // 'cursorlineopt'
252254 char_u *wo_cc;
253255 # define w_p_cc w_onebuf_opt.wo_cc // 'colorcolumn'
254256 #endif
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 src/testdir/Make_all.mak
--- a/src/testdir/Make_all.mak Mon Sep 09 20:15:04 2019 +0200
+++ b/src/testdir/Make_all.mak Mon Sep 09 22:15:04 2019 +0200
@@ -92,6 +92,7 @@
9292 test_crypt \
9393 test_cscope \
9494 test_cursor_func \
95+ test_cursorline \
9596 test_curswant \
9697 test_debugger \
9798 test_delete \
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 src/testdir/gen_opt_test.vim
--- a/src/testdir/gen_opt_test.vim Mon Sep 09 20:15:04 2019 +0200
+++ b/src/testdir/gen_opt_test.vim Mon Sep 09 22:15:04 2019 +0200
@@ -82,6 +82,7 @@
8282 \ 'completeslash': [['', 'slash', 'backslash'], ['xxx']],
8383 \ 'cryptmethod': [['', 'zip'], ['xxx']],
8484 \ 'cscopequickfix': [['', 's-', 's-,c+,e0'], ['xxx', 's,g,d']],
85+ \ 'cursorlineopt': [['both', 'line', 'number'], ['', 'xxx', 'line,number']],
8586 \ 'debug': [['', 'msg', 'msg', 'beep'], ['xxx']],
8687 \ 'diffopt': [['', 'filler', 'icase,iwhite'], ['xxx', 'algorithm:xxx', 'algorithm:']],
8788 \ 'display': [['', 'lastline', 'lastline,uhex'], ['xxx']],
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 src/testdir/test_alot.vim
--- a/src/testdir/test_alot.vim Mon Sep 09 20:15:04 2019 +0200
+++ b/src/testdir/test_alot.vim Mon Sep 09 22:15:04 2019 +0200
@@ -9,6 +9,7 @@
99 source test_changedtick.vim
1010 source test_compiler.vim
1111 source test_cursor_func.vim
12+source test_cursorline.vim
1213 source test_delete.vim
1314 source test_ex_equal.vim
1415 source test_ex_undo.vim
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 src/testdir/test_cursorline.vim
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testdir/test_cursorline.vim Mon Sep 09 22:15:04 2019 +0200
@@ -0,0 +1,108 @@
1+" Test for cursorline and cursorlineopt
2+"
3+source view_util.vim
4+source check.vim
5+
6+function! s:screen_attr(lnum) abort
7+ return map(range(1, 8), 'screenattr(a:lnum, v:val)')
8+endfunction
9+
10+function! s:test_windows(h, w) abort
11+ call NewWindow(a:h, a:w)
12+endfunction
13+
14+function! s:close_windows() abort
15+ call CloseWindow()
16+endfunction
17+
18+function! s:new_hi() abort
19+ redir => save_hi
20+ silent! hi CursorLineNr
21+ redir END
22+ let save_hi = join(split(substitute(save_hi, '\s*xxx\s*', ' ', ''), "\n"), '')
23+ exe 'hi' save_hi 'ctermbg=0 guibg=Black'
24+ return save_hi
25+endfunction
26+
27+func Test_cursorline_highlight1()
28+ let save_hi = s:new_hi()
29+ try
30+ call s:test_windows(10, 20)
31+ call setline(1, repeat(['aaaa'], 10))
32+ redraw
33+ let attr01 = s:screen_attr(1)
34+ call assert_equal(repeat([attr01[0]], 8), attr01)
35+
36+ setl number numberwidth=4
37+ redraw
38+ let attr11 = s:screen_attr(1)
39+ call assert_equal(repeat([attr11[0]], 4), attr11[0:3])
40+ call assert_equal(repeat([attr11[4]], 4), attr11[4:7])
41+ call assert_notequal(attr11[0], attr11[4])
42+
43+ setl cursorline
44+ redraw
45+ let attr21 = s:screen_attr(1)
46+ let attr22 = s:screen_attr(2)
47+ call assert_equal(repeat([attr21[0]], 4), attr21[0:3])
48+ call assert_equal(repeat([attr21[4]], 4), attr21[4:7])
49+ call assert_equal(attr11, attr22)
50+ call assert_notequal(attr22, attr21)
51+
52+ setl nocursorline relativenumber
53+ redraw
54+ let attr31 = s:screen_attr(1)
55+ call assert_equal(attr21[0:3], attr31[0:3])
56+ call assert_equal(attr11[4:7], attr31[4:7])
57+
58+ call s:close_windows()
59+ finally
60+ exe 'hi' save_hi
61+ endtry
62+endfunc
63+
64+func Test_cursorline_highlight2()
65+ CheckOption cursorlineopt
66+
67+ let save_hi = s:new_hi()
68+ try
69+ call s:test_windows(10, 20)
70+ call setline(1, repeat(['aaaa'], 10))
71+ redraw
72+ let attr0 = s:screen_attr(1)
73+ call assert_equal(repeat([attr0[0]], 8), attr0)
74+
75+ setl number
76+ redraw
77+ let attr1 = s:screen_attr(1)
78+ call assert_notequal(attr0[0:3], attr1[0:3])
79+ call assert_equal(attr0[0:3], attr1[4:7])
80+
81+ setl cursorline cursorlineopt=both
82+ redraw
83+ let attr2 = s:screen_attr(1)
84+ call assert_notequal(attr1[0:3], attr2[0:3])
85+ call assert_notequal(attr1[4:7], attr2[4:7])
86+
87+ setl cursorlineopt=line
88+ redraw
89+ let attr3 = s:screen_attr(1)
90+ call assert_equal(attr1[0:3], attr3[0:3])
91+ call assert_equal(attr2[4:7], attr3[4:7])
92+
93+ setl cursorlineopt=number
94+ redraw
95+ let attr4 = s:screen_attr(1)
96+ call assert_equal(attr2[0:3], attr4[0:3])
97+ call assert_equal(attr1[4:7], attr4[4:7])
98+
99+ setl nonumber
100+ redraw
101+ let attr5 = s:screen_attr(1)
102+ call assert_equal(attr0, attr5)
103+
104+ call s:close_windows()
105+ finally
106+ exe 'hi' save_hi
107+ endtry
108+endfunc
diff -r 4b4c49dee5e6 -r 6650e3dff8d4 src/version.c
--- a/src/version.c Mon Sep 09 20:15:04 2019 +0200
+++ b/src/version.c Mon Sep 09 22:15:04 2019 +0200
@@ -758,6 +758,8 @@
758758 static int included_patches[] =
759759 { /* Add new patch number below this line */
760760 /**/
761+ 2019,
762+/**/
761763 2018,
762764 /**/
763765 2017,
Show on old repository browser