Skip to content

Commit efae76a

Browse files
committed
patch 8.1.2229: cannot color number column above/below cursor differently
Problem: Cannot color number column above/below cursor differently. Solution: Add LineNrAbove and LineNrBelow. (Shaun Brady, closes #624)
1 parent 38ba4dc commit efae76a

File tree

11 files changed

+102
-3
lines changed

11 files changed

+102
-3
lines changed

runtime/doc/options.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,6 +3923,7 @@ A jump table for the options with a short description can be found at |Q_op|.
39233923
"8:SpecialKey,~:EndOfBuffer,@:NonText,
39243924
d:Directory,e:ErrorMsg,i:IncSearch,
39253925
l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,
3926+
a:LineNrAbove,b:LineNrBelow,
39263927
N:CursorLineNr,r:Question,s:StatusLine,
39273928
S:StatusLineNC,c:VertSplit,t:Title,
39283929
v:Visual,V:VisualNOS,w:WarningMsg,
@@ -3954,6 +3955,10 @@ A jump table for the options with a short description can be found at |Q_op|.
39543955
|hl-ModeMsg| M Mode (e.g., "-- INSERT --")
39553956
|hl-LineNr| n line number for ":number" and ":#" commands, and
39563957
when 'number' or 'relativenumber' option is set.
3958+
|hl-LineNrAbove| a line number above the cursor for when the
3959+
'relativenumber' option is set.
3960+
|hl-LineNrBelow| b line number below the cursor for when the
3961+
'relativenumber' option is set.
39573962
|hl-CursorLineNr| N like n for when 'cursorline' or 'relativenumber' is
39583963
set.
39593964
|hl-Question| r |hit-enter| prompt and yes/no questions

runtime/doc/syntax.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5071,6 +5071,12 @@ IncSearch 'incsearch' highlighting; also used for the text replaced with
50715071
*hl-LineNr*
50725072
LineNr Line number for ":number" and ":#" commands, and when 'number'
50735073
or 'relativenumber' option is set.
5074+
*hl-LineNrAbove*
5075+
LineNrAbove Line number for when the 'relativenumber'
5076+
option is set, above the cursor line.
5077+
*hl-LineNrBelow*
5078+
LineNrBelow Line number for when the 'relativenumber'
5079+
option is set, below the cursor line.
50745080
*hl-CursorLineNr*
50755081
CursorLineNr Like LineNr when 'cursorline' is set and 'cursorlineopt' is
50765082
set to "number" or "both", or 'relativenumber' is set, for

src/drawline.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,16 @@ win_line(
11271127
|| wp->w_p_culopt_flags & CULOPT_LINE))
11281128
char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
11291129
#endif
1130+
if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1131+
&& HL_ATTR(HLF_LNA) != 0)
1132+
// Use LineNrAbove
1133+
char_attr = hl_combine_attr(wcr_attr,
1134+
HL_ATTR(HLF_LNA));
1135+
if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1136+
&& HL_ATTR(HLF_LNB) != 0)
1137+
// Use LineNrBelow
1138+
char_attr = hl_combine_attr(wcr_attr,
1139+
HL_ATTR(HLF_LNB));
11301140
}
11311141
}
11321142
}

src/optiondefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ struct vimoption
289289
# define ISP_LATIN1 (char_u *)"@,161-255"
290290
#endif
291291

292-
# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
292+
# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,a:LineNrAbove,b:LineNrBelow,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
293293

294294
// Default python version for pyx* commands
295295
#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| +0#ff404010#ffffff0@1|4| |1+0#0000000&|0|6| @42
2+
| +0#ff404010&@1|3| |1+0#0000000&|0|7| @42
3+
| +0#ff404010&@1|2| |1+0#0000000&|0|8| @42
4+
| +0#ff404010&@1|1| |1+0#0000000&|0|9| @42
5+
|1+0#ff404010&@2| >1+0#0000000&@1|0| @42
6+
| +0#ff404010&@1|1| |1+0#0000000&@2| @42
7+
| +0#ff404010&@1|2| |1+0#0000000&@1|2| @42
8+
| +0#ff404010&@1|3| |1+0#0000000&@1|3| @42
9+
| +0#ff404010&@1|4| |1+0#0000000&@1|4| @42
10+
@32|1@2|,|1| @8|5@1|%|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| +0#4040ff13#ffffff0@1|4| |1+0#0000000&|0|6| @42
2+
| +0#4040ff13&@1|3| |1+0#0000000&|0|7| @42
3+
| +0#4040ff13&@1|2| |1+0#0000000&|0|8| @42
4+
| +0#4040ff13&@1|1| |1+0#0000000&|0|9| @42
5+
|1+0#ff404010&@2| >1+0#0000000&@1|0| @42
6+
| +0#ff404010&@1|1| |1+0#0000000&@2| @42
7+
| +0#ff404010&@1|2| |1+0#0000000&@1|2| @42
8+
| +0#ff404010&@1|3| |1+0#0000000&@1|3| @42
9+
| +0#ff404010&@1|4| |1+0#0000000&@1|4| @42
10+
|:|h|i| |L|i|n|e|N|r|A|b|o|v|e| |c|t|e|r|m|f|g|=|b|l|u|e| @3|1@2|,|1| @8|5@1|%|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| +0#4040ff13#ffffff0@1|4| |1+0#0000000&|0|6| @42
2+
| +0#4040ff13&@1|3| |1+0#0000000&|0|7| @42
3+
| +0#4040ff13&@1|2| |1+0#0000000&|0|8| @42
4+
| +0#4040ff13&@1|1| |1+0#0000000&|0|9| @42
5+
|1+0#ff404010&@2| >1+0#0000000&@1|0| @42
6+
| +0#40ff4011&@1|1| |1+0#0000000&@2| @42
7+
| +0#40ff4011&@1|2| |1+0#0000000&@1|2| @42
8+
| +0#40ff4011&@1|3| |1+0#0000000&@1|3| @42
9+
| +0#40ff4011&@1|4| |1+0#0000000&@1|4| @42
10+
|:|h|i| |L|i|n|e|N|r|B|e|l|o|w| |c|t|e|r|m|f|g|=|g|r|e@1|n| @2|1@2|,|1| @8|5@1|%|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| +0#ff404010#ffffff0@1|4| |1+0#0000000&|0|6| @42
2+
| +0#ff404010&@1|3| |1+0#0000000&|0|7| @42
3+
| +0#ff404010&@1|2| |1+0#0000000&|0|8| @42
4+
| +0#ff404010&@1|1| |1+0#0000000&|0|9| @42
5+
|1+0#ff404010&@2| >1+0#0000000&@1|0| @42
6+
| +0#40ff4011&@1|1| |1+0#0000000&@2| @42
7+
| +0#40ff4011&@1|2| |1+0#0000000&@1|2| @42
8+
| +0#40ff4011&@1|3| |1+0#0000000&@1|3| @42
9+
| +0#40ff4011&@1|4| |1+0#0000000&@1|4| @42
10+
|:|h|i| |c|l|e|a|r| |L|i|n|e|N|r|A|b|o|v|e| @10|1@2|,|1| @8|5@1|%|

src/testdir/test_number.vim

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
" Test for 'number' and 'relativenumber'
22

3+
source check.vim
34
source view_util.vim
45

6+
source screendump.vim
7+
58
func s:screen_lines(start, end) abort
69
return ScreenLines([a:start, a:end], 8)
710
endfunc
@@ -263,3 +266,34 @@ func Test_relativenumber_uninitialised()
263266
redraw
264267
bwipe!
265268
endfunc
269+
270+
func Test_relativenumber_colors()
271+
CheckScreendump
272+
273+
let lines =<< trim [CODE]
274+
call setline(1, range(200))
275+
111
276+
set number relativenumber
277+
hi LineNr ctermfg=red
278+
[CODE]
279+
call writefile(lines, 'XTest_relnr')
280+
281+
" Check that the balloon shows up after a mouse move
282+
let buf = RunVimInTerminal('-S XTest_relnr', {'rows': 10, 'cols': 50})
283+
call term_wait(buf, 100)
284+
" Default colors
285+
call VerifyScreenDump(buf, 'Test_relnr_colors_1', {})
286+
287+
call term_sendkeys(buf, ":hi LineNrAbove ctermfg=blue\<CR>")
288+
call VerifyScreenDump(buf, 'Test_relnr_colors_2', {})
289+
290+
call term_sendkeys(buf, ":hi LineNrBelow ctermfg=green\<CR>")
291+
call VerifyScreenDump(buf, 'Test_relnr_colors_3', {})
292+
293+
call term_sendkeys(buf, ":hi clear LineNrAbove\<CR>")
294+
call VerifyScreenDump(buf, 'Test_relnr_colors_4', {})
295+
296+
" clean up
297+
call StopVimInTerminal(buf)
298+
call delete('XTest_relnr')
299+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2229,
744746
/**/
745747
2228,
746748
/**/

0 commit comments

Comments
 (0)