0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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)
This commit is contained in:
Gianmaria Bajo
2023-03-10 16:35:53 +00:00
committed by Bram Moolenaar
parent be19d78c3d
commit 6a7c774920
10 changed files with 152 additions and 16 deletions

View File

@@ -4198,6 +4198,8 @@ A jump table for the options with a short description can be found at |Q_op|.
T:DiffText,>:SignColumn,-:Conceal, T:DiffText,>:SignColumn,-:Conceal,
B:SpellBad,P:SpellCap,R:SpellRare, B:SpellBad,P:SpellCap,R:SpellRare,
L:SpellLocal,+:Pmenu,=:PmenuSel, L:SpellLocal,+:Pmenu,=:PmenuSel,
[:PmenuKind,]:PmenuKindSel,
{:PmenuExtra,}:PmenuExtraSel,
x:PmenuSbar,X:PmenuThumb,*:TabLine, x:PmenuSbar,X:PmenuThumb,*:TabLine,
#:TabLineSel,_:TabLineFill,!:CursorColumn, #:TabLineSel,_:TabLineFill,!:CursorColumn,
.:CursorLine,o:ColorColumn,q:QuickFixLine, .: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|.
|hl-SpellLocal| L word from other region |spell| |hl-SpellLocal| L word from other region |spell|
|hl-Pmenu| + popup menu normal line |hl-Pmenu| + popup menu normal line
|hl-PmenuSel| = popup menu selected line |hl-PmenuSel| = popup menu selected line
|hl-PmenuKind| [ popup menu "kind" normal line
|hl-PmenuKindSel| ] popup menu "kind" selected line
|hl-PmenuExtra| { popup menu "kind" normal line
|hl-PmenuExtraSel| } popup menu "kind" selected line
|hl-PmenuSbar| x popup menu scrollbar |hl-PmenuSbar| x popup menu scrollbar
|hl-PmenuThumb| X popup menu scrollbar thumb |hl-PmenuThumb| X popup menu scrollbar thumb

View File

@@ -5452,6 +5452,14 @@ Normal Normal text.
Pmenu Popup menu: Normal item. Pmenu Popup menu: Normal item.
*hl-PmenuSel* *hl-PmenuSel*
PmenuSel Popup menu: Selected item. PmenuSel Popup menu: Selected item.
*hl-PmenuKind*
PmenuKind Popup menu: Normal item "kind".
*hl-PmenuKindSel*
PmenuKindSel Popup menu: Selected item "kind".
*hl-PmenuExtra*
PmenuExtra Popup menu: Normal item "extra text".
*hl-PmenuExtraSel*
PmenuExtraSel Popup menu: Selected item "extra text".
*hl-PmenuSbar* *hl-PmenuSbar*
PmenuSbar Popup menu: Scrollbar. PmenuSbar Popup menu: Scrollbar.
*hl-PmenuThumb* *hl-PmenuThumb*

View File

@@ -164,6 +164,10 @@ static char *(highlight_init_both[]) = {
"default link CursorLineSign SignColumn", "default link CursorLineSign SignColumn",
"default link CursorLineFold FoldColumn", "default link CursorLineFold FoldColumn",
"default link CurSearch Search", "default link CurSearch Search",
"default link PmenuKind Pmenu",
"default link PmenuKindSel PmenuSel",
"default link PmenuExtra Pmenu",
"default link PmenuExtraSel PmenuSel",
CENT("Normal cterm=NONE", "Normal gui=NONE"), CENT("Normal cterm=NONE", "Normal gui=NONE"),
NULL NULL
}; };

View File

@@ -294,7 +294,7 @@ struct vimoption
# define ISP_LATIN1 (char_u *)"@,161-255" # define ISP_LATIN1 (char_u *)"@,161-255"
#endif #endif
# 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" # 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"
// Default python version for pyx* commands // Default python version for pyx* commands
#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)

View File

@@ -420,11 +420,10 @@ pum_redraw(void)
{ {
int row = pum_row; int row = pum_row;
int col; int col;
int attr_norm = highlight_attr[HLF_PNI];
int attr_select = highlight_attr[HLF_PSI];
int attr_scroll = highlight_attr[HLF_PSB]; int attr_scroll = highlight_attr[HLF_PSB];
int attr_thumb = highlight_attr[HLF_PST]; int attr_thumb = highlight_attr[HLF_PST];
int attr; int attr;
int *attrs; // array used for highlights
int i; int i;
int idx; int idx;
char_u *s; char_u *s;
@@ -435,6 +434,11 @@ pum_redraw(void)
int round; int round;
int n; int n;
int *ha = highlight_attr;
// "word" "kind" "extra text"
int attrsNorm[3] = { ha[HLF_PNI], ha[HLF_PNK], ha[HLF_PNX] };
int attrsSel[3] = { ha[HLF_PSI], ha[HLF_PSK], ha[HLF_PSX] };
if (call_update_screen) if (call_update_screen)
{ {
call_update_screen = FALSE; call_update_screen = FALSE;
@@ -468,7 +472,8 @@ pum_redraw(void)
for (i = 0; i < pum_height; ++i) for (i = 0; i < pum_height; ++i)
{ {
idx = i + pum_first; idx = i + pum_first;
attr = (idx == pum_selected) ? attr_select : attr_norm; attrs = (idx == pum_selected) ? attrsSel : attrsNorm;
attr = attrs[0]; // start with "word" highlight
// prepend a space if there is room // prepend a space if there is room
#ifdef FEAT_RIGHTLEFT #ifdef FEAT_RIGHTLEFT
@@ -483,18 +488,22 @@ pum_redraw(void)
screen_putchar(' ', row, pum_col - 1, attr); screen_putchar(' ', row, pum_col - 1, attr);
// Display each entry, use two spaces for a Tab. // Display each entry, use two spaces for a Tab.
// Do this 3 times: For the main text, kind and extra info // Do this 3 times:
// 0 - main text
// 1 - kind
// 2 - extra info
col = pum_col; col = pum_col;
totwidth = 0; totwidth = 0;
for (round = 1; round <= 3; ++round) for (round = 0; round < 3; ++round)
{ {
attr = attrs[round];
width = 0; width = 0;
s = NULL; s = NULL;
switch (round) switch (round)
{ {
case 1: p = pum_array[idx].pum_text; break; case 0: p = pum_array[idx].pum_text; break;
case 2: p = pum_array[idx].pum_kind; break; case 1: p = pum_array[idx].pum_kind; break;
case 3: p = pum_array[idx].pum_extra; break; case 2: p = pum_array[idx].pum_extra; break;
} }
if (p != NULL) if (p != NULL)
for ( ; ; MB_PTR_ADV(p)) for ( ; ; MB_PTR_ADV(p))
@@ -607,15 +616,15 @@ pum_redraw(void)
width += w; width += w;
} }
if (round > 1) if (round > 0)
n = pum_kind_width + 1; n = pum_kind_width + 1;
else else
n = 1; n = 1;
// Stop when there is nothing more to display. // Stop when there is nothing more to display.
if (round == 3 if (round == 2
|| (round == 2 && pum_array[idx].pum_extra == NULL) || (round == 1 && pum_array[idx].pum_extra == NULL)
|| (round == 1 && pum_array[idx].pum_kind == NULL || (round == 0 && pum_array[idx].pum_kind == NULL
&& pum_array[idx].pum_extra == NULL) && pum_array[idx].pum_extra == NULL)
|| pum_base_width + n >= pum_width) || pum_base_width + n >= pum_width)
break; break;

View File

@@ -0,0 +1,20 @@
|a+0&#ffffff0|w|o|r|d|1> @68
|a+0#0000001#e0e0e08|w|o|r|d|1| |W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52
|a+0#0000001#ffd7ff255|w|o|r|d|2| |W| |e|x|t|r|a| |t|e|x|t| |2| | +0#4040ff13#ffffff0@52
|a+0#0000001#ffd7ff255|w|o|r|d|3| |W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+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

View File

@@ -0,0 +1,20 @@
|a+0&#ffffff0|w|o|r|d|1> @68
|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
|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
|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
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+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

View File

@@ -1250,4 +1250,66 @@ func Test_pum_scrollbar()
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
endfunc endfunc
" Test default highlight groups for popup menu
func Test_pum_highlights_default()
CheckScreendump
let lines =<< trim END
func CompleteFunc( findstart, base )
if a:findstart
return 0
endif
return {
\ 'words': [
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
\ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
\]}
endfunc
set completeopt=menu
set completefunc=CompleteFunc
END
call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {})
call TermWait(buf)
call term_sendkeys(buf, "iaw\<C-X>\<C-u>")
call TermWait(buf, 50)
call VerifyScreenDump(buf, 'Test_pum_highlights_01', {})
call term_sendkeys(buf, "\<C-E>\<Esc>u")
call TermWait(buf)
call StopVimInTerminal(buf)
endfunc
" Test custom highlight groups for popup menu
func Test_pum_highlights_custom()
CheckScreendump
let lines =<< trim END
func CompleteFunc( findstart, base )
if a:findstart
return 0
endif
return {
\ 'words': [
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
\ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
\]}
endfunc
set completeopt=menu
set completefunc=CompleteFunc
hi PmenuKind ctermfg=1 ctermbg=225
hi PmenuKindSel ctermfg=1 ctermbg=7
hi PmenuExtra ctermfg=243 ctermbg=225
hi PmenuExtraSel ctermfg=0 ctermbg=7
END
call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {})
call TermWait(buf)
call term_sendkeys(buf, "iaw\<C-X>\<C-u>")
call TermWait(buf, 50)
call VerifyScreenDump(buf, 'Test_pum_highlights_02', {})
call term_sendkeys(buf, "\<C-E>\<Esc>u")
call TermWait(buf)
call StopVimInTerminal(buf)
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1397,
/**/ /**/
1396, 1396,
/**/ /**/

View File

@@ -1418,8 +1418,8 @@ typedef enum auto_event event_T;
/* /*
* Values for index in highlight_attr[]. * Values for index in highlight_attr[].
* When making changes, also update HL_FLAGS below! And update the default * When making changes, also update HL_FLAGS below!
* value of 'highlight' in option.c. * And update the default value of 'highlight': HIGHLIGHT_INIT in optiondefs.h
*/ */
typedef enum typedef enum
{ {
@@ -1465,6 +1465,10 @@ typedef enum
, HLF_SPL // SpellLocal , HLF_SPL // SpellLocal
, HLF_PNI // popup menu normal item , HLF_PNI // popup menu normal item
, HLF_PSI // popup menu selected item , HLF_PSI // popup menu selected item
, HLF_PNK // popup menu normal item "kind"
, HLF_PSK // popup menu selected item "kind"
, HLF_PNX // popup menu normal item "menu" (extra text)
, HLF_PSX // popup menu selected item "menu" (extra text)
, HLF_PSB // popup menu scrollbar , HLF_PSB // popup menu scrollbar
, HLF_PST // popup menu scrollbar thumb , HLF_PST // popup menu scrollbar thumb
, HLF_TP // tabpage line , HLF_TP // tabpage line
@@ -1485,7 +1489,8 @@ typedef enum
'n', 'a', 'b', 'N', 'G', 'O', 'r', 's', 'S', 'c', 't', 'v', 'V', \ 'n', 'a', 'b', 'N', 'G', 'O', 'r', 's', 'S', 'c', 't', 'v', 'V', \
'w', 'W', 'f', 'F', 'A', 'C', 'D', 'T', '-', '>', \ 'w', 'W', 'f', 'F', 'A', 'C', 'D', 'T', '-', '>', \
'B', 'P', 'R', 'L', \ 'B', 'P', 'R', 'L', \
'+', '=', 'x', 'X', '*', '#', '_', '!', '.', 'o', 'q', \ '+', '=', '[', ']', '{', '}', 'x', 'X', \
'*', '#', '_', '!', '.', 'o', 'q', \
'z', 'Z'} 'z', 'Z'}
/* /*