Skip to content

Commit 6a7c774

Browse files
mg979brammool
authored andcommitted
patch 9.0.1397: highlight for popupmenu kind and extra cannot be set
Problem: Highlight for popupmenu kind and extra cannot be set. Solution: Add PmenuKind, PmenuKindSel, PmenuExtra and PmenuExtraSel highlight groups and use them. (Gianmaria Bajo, closes #12114)
1 parent be19d78 commit 6a7c774

File tree

10 files changed

+152
-16
lines changed

10 files changed

+152
-16
lines changed

runtime/doc/options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4198,6 +4198,8 @@ A jump table for the options with a short description can be found at |Q_op|.
41984198
T:DiffText,>:SignColumn,-:Conceal,
41994199
B:SpellBad,P:SpellCap,R:SpellRare,
42004200
L:SpellLocal,+:Pmenu,=:PmenuSel,
4201+
[:PmenuKind,]:PmenuKindSel,
4202+
{:PmenuExtra,}:PmenuExtraSel,
42014203
x:PmenuSbar,X:PmenuThumb,*:TabLine,
42024204
#:TabLineSel,_:TabLineFill,!:CursorColumn,
42034205
.:CursorLine,o:ColorColumn,q:QuickFixLine,
@@ -4254,6 +4256,10 @@ A jump table for the options with a short description can be found at |Q_op|.
42544256
|hl-SpellLocal| L word from other region |spell|
42554257
|hl-Pmenu| + popup menu normal line
42564258
|hl-PmenuSel| = popup menu selected line
4259+
|hl-PmenuKind| [ popup menu "kind" normal line
4260+
|hl-PmenuKindSel| ] popup menu "kind" selected line
4261+
|hl-PmenuExtra| { popup menu "kind" normal line
4262+
|hl-PmenuExtraSel| } popup menu "kind" selected line
42574263
|hl-PmenuSbar| x popup menu scrollbar
42584264
|hl-PmenuThumb| X popup menu scrollbar thumb
42594265

runtime/doc/syntax.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5452,6 +5452,14 @@ Normal Normal text.
54525452
Pmenu Popup menu: Normal item.
54535453
*hl-PmenuSel*
54545454
PmenuSel Popup menu: Selected item.
5455+
*hl-PmenuKind*
5456+
PmenuKind Popup menu: Normal item "kind".
5457+
*hl-PmenuKindSel*
5458+
PmenuKindSel Popup menu: Selected item "kind".
5459+
*hl-PmenuExtra*
5460+
PmenuExtra Popup menu: Normal item "extra text".
5461+
*hl-PmenuExtraSel*
5462+
PmenuExtraSel Popup menu: Selected item "extra text".
54555463
*hl-PmenuSbar*
54565464
PmenuSbar Popup menu: Scrollbar.
54575465
*hl-PmenuThumb*

src/highlight.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ static char *(highlight_init_both[]) = {
164164
"default link CursorLineSign SignColumn",
165165
"default link CursorLineFold FoldColumn",
166166
"default link CurSearch Search",
167+
"default link PmenuKind Pmenu",
168+
"default link PmenuKindSel PmenuSel",
169+
"default link PmenuExtra Pmenu",
170+
"default link PmenuExtraSel PmenuSel",
167171
CENT("Normal cterm=NONE", "Normal gui=NONE"),
168172
NULL
169173
};

src/optiondefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ struct vimoption
294294
# define ISP_LATIN1 (char_u *)"@,161-255"
295295
#endif
296296

297-
# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,y:CurSearch,m:MoreMsg,M:ModeMsg,n:LineNr,a:LineNrAbove,b:LineNrBelow,N:CursorLineNr,G:CursorLineSign,O:CursorLineFold,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"
297+
# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,y:CurSearch,m:MoreMsg,M:ModeMsg,n:LineNr,a:LineNrAbove,b:LineNrBelow,N:CursorLineNr,G:CursorLineSign,O:CursorLineFold,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,[:PmenuKind,]:PmenuKindSel,{:PmenuExtra,}:PmenuExtraSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
298298

299299
// Default python version for pyx* commands
300300
#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)

src/popupmenu.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,10 @@ pum_redraw(void)
420420
{
421421
int row = pum_row;
422422
int col;
423-
int attr_norm = highlight_attr[HLF_PNI];
424-
int attr_select = highlight_attr[HLF_PSI];
425423
int attr_scroll = highlight_attr[HLF_PSB];
426424
int attr_thumb = highlight_attr[HLF_PST];
427425
int attr;
426+
int *attrs; // array used for highlights
428427
int i;
429428
int idx;
430429
char_u *s;
@@ -435,6 +434,11 @@ pum_redraw(void)
435434
int round;
436435
int n;
437436

437+
int *ha = highlight_attr;
438+
// "word" "kind" "extra text"
439+
int attrsNorm[3] = { ha[HLF_PNI], ha[HLF_PNK], ha[HLF_PNX] };
440+
int attrsSel[3] = { ha[HLF_PSI], ha[HLF_PSK], ha[HLF_PSX] };
441+
438442
if (call_update_screen)
439443
{
440444
call_update_screen = FALSE;
@@ -468,7 +472,8 @@ pum_redraw(void)
468472
for (i = 0; i < pum_height; ++i)
469473
{
470474
idx = i + pum_first;
471-
attr = (idx == pum_selected) ? attr_select : attr_norm;
475+
attrs = (idx == pum_selected) ? attrsSel : attrsNorm;
476+
attr = attrs[0]; // start with "word" highlight
472477

473478
// prepend a space if there is room
474479
#ifdef FEAT_RIGHTLEFT
@@ -483,18 +488,22 @@ pum_redraw(void)
483488
screen_putchar(' ', row, pum_col - 1, attr);
484489

485490
// Display each entry, use two spaces for a Tab.
486-
// Do this 3 times: For the main text, kind and extra info
491+
// Do this 3 times:
492+
// 0 - main text
493+
// 1 - kind
494+
// 2 - extra info
487495
col = pum_col;
488496
totwidth = 0;
489-
for (round = 1; round <= 3; ++round)
497+
for (round = 0; round < 3; ++round)
490498
{
499+
attr = attrs[round];
491500
width = 0;
492501
s = NULL;
493502
switch (round)
494503
{
495-
case 1: p = pum_array[idx].pum_text; break;
496-
case 2: p = pum_array[idx].pum_kind; break;
497-
case 3: p = pum_array[idx].pum_extra; break;
504+
case 0: p = pum_array[idx].pum_text; break;
505+
case 1: p = pum_array[idx].pum_kind; break;
506+
case 2: p = pum_array[idx].pum_extra; break;
498507
}
499508
if (p != NULL)
500509
for ( ; ; MB_PTR_ADV(p))
@@ -607,15 +616,15 @@ pum_redraw(void)
607616
width += w;
608617
}
609618

610-
if (round > 1)
619+
if (round > 0)
611620
n = pum_kind_width + 1;
612621
else
613622
n = 1;
614623

615624
// Stop when there is nothing more to display.
616-
if (round == 3
617-
|| (round == 2 && pum_array[idx].pum_extra == NULL)
618-
|| (round == 1 && pum_array[idx].pum_kind == NULL
625+
if (round == 2
626+
|| (round == 1 && pum_array[idx].pum_extra == NULL)
627+
|| (round == 0 && pum_array[idx].pum_kind == NULL
619628
&& pum_array[idx].pum_extra == NULL)
620629
|| pum_base_width + n >= pum_width)
621630
break;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
|a+0&#ffffff0|w|o|r|d|1> @68
2+
|a+0#0000001#e0e0e08|w|o|r|d|1| |W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52
3+
|a+0#0000001#ffd7ff255|w|o|r|d|2| |W| |e|x|t|r|a| |t|e|x|t| |2| | +0#4040ff13#ffffff0@52
4+
|a+0#0000001#ffd7ff255|w|o|r|d|3| |W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|~| @73
11+
|~| @73
12+
|~| @73
13+
|~| @73
14+
|~| @73
15+
|~| @73
16+
|~| @73
17+
|~| @73
18+
|~| @73
19+
|~| @73
20+
|-+2#0000000&@1| |U|s|e|r| |d|e|f|i|n|e|d| |c|o|m|p|l|e|t|i|o|n| |(|^|U|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@26
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
|a+0&#ffffff0|w|o|r|d|1> @68
2+
|a+0#0000001#e0e0e08|w|o|r|d|1| |W+0#e000002&| |e+0#0000001&|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52
3+
|a+0#0000001#ffd7ff255|w|o|r|d|2| |W+0#e000002&| |e+0#767676255&|x|t|r|a| |t|e|x|t| |2| | +0#4040ff13#ffffff0@52
4+
|a+0#0000001#ffd7ff255|w|o|r|d|3| |W+0#e000002&| |e+0#767676255&|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|~| @73
11+
|~| @73
12+
|~| @73
13+
|~| @73
14+
|~| @73
15+
|~| @73
16+
|~| @73
17+
|~| @73
18+
|~| @73
19+
|~| @73
20+
|-+2#0000000&@1| |U|s|e|r| |d|e|f|i|n|e|d| |c|o|m|p|l|e|t|i|o|n| |(|^|U|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@26

src/testdir/test_popup.vim

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,4 +1250,66 @@ func Test_pum_scrollbar()
12501250
call StopVimInTerminal(buf)
12511251
endfunc
12521252

1253+
" Test default highlight groups for popup menu
1254+
func Test_pum_highlights_default()
1255+
CheckScreendump
1256+
let lines =<< trim END
1257+
func CompleteFunc( findstart, base )
1258+
if a:findstart
1259+
return 0
1260+
endif
1261+
return {
1262+
\ 'words': [
1263+
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
1264+
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
1265+
\ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
1266+
\]}
1267+
endfunc
1268+
set completeopt=menu
1269+
set completefunc=CompleteFunc
1270+
END
1271+
call writefile(lines, 'Xscript', 'D')
1272+
let buf = RunVimInTerminal('-S Xscript', {})
1273+
call TermWait(buf)
1274+
call term_sendkeys(buf, "iaw\<C-X>\<C-u>")
1275+
call TermWait(buf, 50)
1276+
call VerifyScreenDump(buf, 'Test_pum_highlights_01', {})
1277+
call term_sendkeys(buf, "\<C-E>\<Esc>u")
1278+
call TermWait(buf)
1279+
call StopVimInTerminal(buf)
1280+
endfunc
1281+
1282+
" Test custom highlight groups for popup menu
1283+
func Test_pum_highlights_custom()
1284+
CheckScreendump
1285+
let lines =<< trim END
1286+
func CompleteFunc( findstart, base )
1287+
if a:findstart
1288+
return 0
1289+
endif
1290+
return {
1291+
\ 'words': [
1292+
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
1293+
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
1294+
\ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
1295+
\]}
1296+
endfunc
1297+
set completeopt=menu
1298+
set completefunc=CompleteFunc
1299+
hi PmenuKind ctermfg=1 ctermbg=225
1300+
hi PmenuKindSel ctermfg=1 ctermbg=7
1301+
hi PmenuExtra ctermfg=243 ctermbg=225
1302+
hi PmenuExtraSel ctermfg=0 ctermbg=7
1303+
END
1304+
call writefile(lines, 'Xscript', 'D')
1305+
let buf = RunVimInTerminal('-S Xscript', {})
1306+
call TermWait(buf)
1307+
call term_sendkeys(buf, "iaw\<C-X>\<C-u>")
1308+
call TermWait(buf, 50)
1309+
call VerifyScreenDump(buf, 'Test_pum_highlights_02', {})
1310+
call term_sendkeys(buf, "\<C-E>\<Esc>u")
1311+
call TermWait(buf)
1312+
call StopVimInTerminal(buf)
1313+
endfunc
1314+
12531315
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1397,
698700
/**/
699701
1396,
700702
/**/

src/vim.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,8 +1418,8 @@ typedef enum auto_event event_T;
14181418

14191419
/*
14201420
* Values for index in highlight_attr[].
1421-
* When making changes, also update HL_FLAGS below! And update the default
1422-
* value of 'highlight' in option.c.
1421+
* When making changes, also update HL_FLAGS below!
1422+
* And update the default value of 'highlight': HIGHLIGHT_INIT in optiondefs.h
14231423
*/
14241424
typedef enum
14251425
{
@@ -1465,6 +1465,10 @@ typedef enum
14651465
, HLF_SPL // SpellLocal
14661466
, HLF_PNI // popup menu normal item
14671467
, HLF_PSI // popup menu selected item
1468+
, HLF_PNK // popup menu normal item "kind"
1469+
, HLF_PSK // popup menu selected item "kind"
1470+
, HLF_PNX // popup menu normal item "menu" (extra text)
1471+
, HLF_PSX // popup menu selected item "menu" (extra text)
14681472
, HLF_PSB // popup menu scrollbar
14691473
, HLF_PST // popup menu scrollbar thumb
14701474
, HLF_TP // tabpage line
@@ -1485,7 +1489,8 @@ typedef enum
14851489
'n', 'a', 'b', 'N', 'G', 'O', 'r', 's', 'S', 'c', 't', 'v', 'V', \
14861490
'w', 'W', 'f', 'F', 'A', 'C', 'D', 'T', '-', '>', \
14871491
'B', 'P', 'R', 'L', \
1488-
'+', '=', 'x', 'X', '*', '#', '_', '!', '.', 'o', 'q', \
1492+
'+', '=', '[', ']', '{', '}', 'x', 'X', \
1493+
'*', '#', '_', '!', '.', 'o', 'q', \
14891494
'z', 'Z'}
14901495

14911496
/*

0 commit comments

Comments
 (0)