To: vim_dev@googlegroups.com Subject: Patch 9.0.1397 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1397 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) Files: runtime/doc/syntax.txt, runtime/doc/options.txt, src/highlight.c, src/optiondefs.h, src/popupmenu.c, src/vim.h, src/testdir/dumps/Test_pum_highlights_01.dump, src/testdir/dumps/Test_pum_highlights_02.dump, src/testdir/test_popup.vim *** ../vim-9.0.1396/runtime/doc/syntax.txt 2022-06-29 18:39:05.011841452 +0100 --- runtime/doc/syntax.txt 2023-03-10 16:17:32.133608865 +0000 *************** *** 5345,5377 **** *hl-CursorLineNr* CursorLineNr Like LineNr when 'cursorline' is set and 'cursorlineopt' contains "number" or is "both", for the cursor line. - *hl-CursorLineSign* - CursorLineSign Like SignColumn when 'cursorline' is set for the cursor line. *hl-CursorLineFold* CursorLineFold Like FoldColumn when 'cursorline' is set for the cursor line. *hl-MatchParen* MatchParen Character under the cursor or just before it, if it is a paired bracket, and its match. |pi_paren.txt| ! *hl-ModeMsg* ModeMsg 'showmode' message (e.g., "-- INSERT --"). *hl-MoreMsg* MoreMsg |more-prompt| *hl-NonText* ! NonText '@' at the end of the window, characters from 'showbreak' ! and other characters that do not really exist in the text ! (e.g., ">" displayed when a double-wide character doesn't ! fit at the end of the line). *hl-Normal* Normal Normal text. *hl-Pmenu* Pmenu Popup menu: Normal item. *hl-PmenuSel* PmenuSel Popup menu: Selected item. *hl-PmenuSbar* PmenuSbar Popup menu: Scrollbar. *hl-PmenuThumb* PmenuThumb Popup menu: Thumb of the scrollbar. *hl-Question* Question |hit-enter| prompt and yes/no questions. *hl-QuickFixLine* --- 5426,5473 ---- *hl-CursorLineNr* CursorLineNr Like LineNr when 'cursorline' is set and 'cursorlineopt' contains "number" or is "both", for the cursor line. *hl-CursorLineFold* CursorLineFold Like FoldColumn when 'cursorline' is set for the cursor line. + *hl-CursorLineSign* + CursorLineSign Like SignColumn when 'cursorline' is set for the cursor line. *hl-MatchParen* MatchParen Character under the cursor or just before it, if it is a paired bracket, and its match. |pi_paren.txt| ! *hl-MessageWindow* ! MessageWindow Messages popup window used by `:echowindow`. If not defined ! |hl-WarningMsg| is used. *hl-ModeMsg* ModeMsg 'showmode' message (e.g., "-- INSERT --"). *hl-MoreMsg* MoreMsg |more-prompt| *hl-NonText* ! NonText '@' at the end of the window, "<<<" at the start of the window ! for 'smoothscroll', characters from 'showbreak' and other ! characters that do not really exist in the text, such as the ! ">" displayed when a double-wide character doesn't fit at the ! end of the line. *hl-Normal* Normal Normal text. *hl-Pmenu* Pmenu Popup menu: Normal item. *hl-PmenuSel* 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* PmenuSbar Popup menu: Scrollbar. *hl-PmenuThumb* PmenuThumb Popup menu: Thumb of the scrollbar. + *hl-PopupNotification* + PopupNotification + Popup window created with |popup_notification()|. If not + defined |hl-WarningMsg| is used. *hl-Question* Question |hit-enter| prompt and yes/no questions. *hl-QuickFixLine* *** ../vim-9.0.1396/runtime/doc/options.txt 2023-02-11 11:15:19.999085252 +0000 --- runtime/doc/options.txt 2023-03-10 16:28:11.561121426 +0000 *************** *** 4167,4172 **** --- 4198,4205 ---- 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, *************** *** 4223,4228 **** --- 4256,4265 ---- |hl-SpellLocal| L word from other region |spell| |hl-Pmenu| + popup menu normal 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-PmenuThumb| X popup menu scrollbar thumb *** ../vim-9.0.1396/src/highlight.c 2023-02-21 14:27:34.516360384 +0000 --- src/highlight.c 2023-03-10 16:17:32.137608862 +0000 *************** *** 164,169 **** --- 164,173 ---- "default link CursorLineSign SignColumn", "default link CursorLineFold FoldColumn", "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"), NULL }; *** ../vim-9.0.1396/src/optiondefs.h 2023-03-04 19:57:28.342671183 +0000 --- src/optiondefs.h 2023-03-10 16:17:32.137608862 +0000 *************** *** 294,300 **** # define ISP_LATIN1 (char_u *)"@,161-255" #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" // Default python version for pyx* commands #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) --- 294,300 ---- # define ISP_LATIN1 (char_u *)"@,161-255" #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,[: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 #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) *** ../vim-9.0.1396/src/popupmenu.c 2023-02-21 14:27:34.520360383 +0000 --- src/popupmenu.c 2023-03-10 16:23:47.809276268 +0000 *************** *** 420,430 **** { int row = pum_row; 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_thumb = highlight_attr[HLF_PST]; int attr; int i; int idx; char_u *s; --- 420,429 ---- { int row = pum_row; int col; int attr_scroll = highlight_attr[HLF_PSB]; int attr_thumb = highlight_attr[HLF_PST]; int attr; + int *attrs; // array used for highlights int i; int idx; char_u *s; *************** *** 435,440 **** --- 434,444 ---- int round; 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) { call_update_screen = FALSE; *************** *** 468,474 **** for (i = 0; i < pum_height; ++i) { idx = i + pum_first; ! attr = (idx == pum_selected) ? attr_select : attr_norm; // prepend a space if there is room #ifdef FEAT_RIGHTLEFT --- 472,479 ---- for (i = 0; i < pum_height; ++i) { idx = i + pum_first; ! attrs = (idx == pum_selected) ? attrsSel : attrsNorm; ! attr = attrs[0]; // start with "word" highlight // prepend a space if there is room #ifdef FEAT_RIGHTLEFT *************** *** 483,500 **** screen_putchar(' ', row, pum_col - 1, attr); // Display each entry, use two spaces for a Tab. ! // Do this 3 times: For the main text, kind and extra info col = pum_col; totwidth = 0; ! for (round = 1; round <= 3; ++round) { width = 0; s = NULL; switch (round) { ! case 1: p = pum_array[idx].pum_text; break; ! case 2: p = pum_array[idx].pum_kind; break; ! case 3: p = pum_array[idx].pum_extra; break; } if (p != NULL) for ( ; ; MB_PTR_ADV(p)) --- 488,509 ---- screen_putchar(' ', row, pum_col - 1, attr); // Display each entry, use two spaces for a Tab. ! // Do this 3 times: ! // 0 - main text ! // 1 - kind ! // 2 - extra info col = pum_col; totwidth = 0; ! for (round = 0; round < 3; ++round) { + attr = attrs[round]; width = 0; s = NULL; switch (round) { ! case 0: p = pum_array[idx].pum_text; break; ! case 1: p = pum_array[idx].pum_kind; break; ! case 2: p = pum_array[idx].pum_extra; break; } if (p != NULL) for ( ; ; MB_PTR_ADV(p)) *************** *** 607,621 **** width += w; } ! if (round > 1) n = pum_kind_width + 1; else n = 1; // Stop when there is nothing more to display. ! if (round == 3 ! || (round == 2 && pum_array[idx].pum_extra == NULL) ! || (round == 1 && pum_array[idx].pum_kind == NULL && pum_array[idx].pum_extra == NULL) || pum_base_width + n >= pum_width) break; --- 616,630 ---- width += w; } ! if (round > 0) n = pum_kind_width + 1; else n = 1; // Stop when there is nothing more to display. ! if (round == 2 ! || (round == 1 && pum_array[idx].pum_extra == NULL) ! || (round == 0 && pum_array[idx].pum_kind == NULL && pum_array[idx].pum_extra == NULL) || pum_base_width + n >= pum_width) break; *** ../vim-9.0.1396/src/vim.h 2023-02-21 19:55:02.791958055 +0000 --- src/vim.h 2023-03-10 16:17:32.137608862 +0000 *************** *** 1418,1425 **** /* * Values for index in highlight_attr[]. ! * When making changes, also update HL_FLAGS below! And update the default ! * value of 'highlight' in option.c. */ typedef enum { --- 1418,1425 ---- /* * Values for index in highlight_attr[]. ! * When making changes, also update HL_FLAGS below! ! * And update the default value of 'highlight': HIGHLIGHT_INIT in optiondefs.h */ typedef enum { *************** *** 1465,1470 **** --- 1465,1474 ---- , HLF_SPL // SpellLocal , HLF_PNI // popup menu normal 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_PST // popup menu scrollbar thumb , HLF_TP // tabpage line *************** *** 1485,1491 **** 'n', 'a', 'b', 'N', 'G', 'O', 'r', 's', 'S', 'c', 't', 'v', 'V', \ 'w', 'W', 'f', 'F', 'A', 'C', 'D', 'T', '-', '>', \ 'B', 'P', 'R', 'L', \ ! '+', '=', 'x', 'X', '*', '#', '_', '!', '.', 'o', 'q', \ 'z', 'Z'} /* --- 1489,1496 ---- 'n', 'a', 'b', 'N', 'G', 'O', 'r', 's', 'S', 'c', 't', 'v', 'V', \ 'w', 'W', 'f', 'F', 'A', 'C', 'D', 'T', '-', '>', \ 'B', 'P', 'R', 'L', \ ! '+', '=', '[', ']', '{', '}', 'x', 'X', \ ! '*', '#', '_', '!', '.', 'o', 'q', \ 'z', 'Z'} /* *** ../vim-9.0.1396/src/testdir/dumps/Test_pum_highlights_01.dump 2023-03-10 16:32:41.344999847 +0000 --- src/testdir/dumps/Test_pum_highlights_01.dump 2023-03-10 16:17:32.137608862 +0000 *************** *** 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 *** ../vim-9.0.1396/src/testdir/dumps/Test_pum_highlights_02.dump 2023-03-10 16:32:41.348999846 +0000 --- src/testdir/dumps/Test_pum_highlights_02.dump 2023-03-10 16:17:32.137608862 +0000 *************** *** 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 *** ../vim-9.0.1396/src/testdir/test_popup.vim 2023-01-28 19:18:56.733720607 +0000 --- src/testdir/test_popup.vim 2023-03-10 16:17:32.137608862 +0000 *************** *** 1250,1253 **** --- 1250,1315 ---- call StopVimInTerminal(buf) 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\\") + call TermWait(buf, 50) + call VerifyScreenDump(buf, 'Test_pum_highlights_01', {}) + call term_sendkeys(buf, "\\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\\") + call TermWait(buf, 50) + call VerifyScreenDump(buf, 'Test_pum_highlights_02', {}) + call term_sendkeys(buf, "\\u") + call TermWait(buf) + call StopVimInTerminal(buf) + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-9.0.1396/src/version.c 2023-03-09 22:06:45.903407145 +0000 --- src/version.c 2023-03-10 16:19:53.005463292 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1397, /**/ -- Did you hear about the new 3 million dollar West Virginia State Lottery? The winner gets 3 dollars a year for a million years. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///