Mercurial > vim
changeset 36281:d37f8260fdce draft v9.1.0771
patch 9.1.0771: completion attribute hl_group is confusing
Commit: https://github.com/vim/vim/commit/0fe17f8ffbd2588ecd2bf42dced556897bc64f89
Author: glepnir <glephunter@gmail.com>
Date: Tue Oct 8 22:26:44 2024 +0200
patch 9.1.0771: completion attribute hl_group is confusing
Problem: Currently completion attribute hl_group is combined with
all items, which is redundant and confusing with kind_hlgroup
Solution: Renamed to abbr_hlgroup and combine it only with the abbr item
(glepnir).
closes: #15818
Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 08 Oct 2024 22:45:04 +0200 |
parents | 4cc90683b8cb |
children | eabb9dc03fb0 |
files | runtime/doc/insert.txt src/cmdexpand.c src/insexpand.c src/popupmenu.c src/structs.h src/testdir/dumps/Test_pum_highlights_12.dump src/testdir/dumps/Test_pum_highlights_13.dump src/testdir/dumps/Test_pum_highlights_14.dump src/testdir/dumps/Test_pum_highlights_16.dump src/testdir/test_popup.vim src/version.c |
diffstat | 11 files changed, 66 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/doc/insert.txt +++ b/runtime/doc/insert.txt @@ -1183,12 +1183,12 @@ items: user_data custom data which is associated with the item and available in |v:completed_item|; it can be any type; defaults to an empty string - hl_group an additional highlight group whose attributes are + abbr_hlgroup an additional highlight group whose attributes are combined with |hl-PmenuSel| and |hl-Pmenu| or |hl-PmenuMatchSel| and |hl-PmenuMatch| highlight attributes in the popup menu to apply cterm and gui properties (with higher priority) like strikethrough - to the completion items + to the completion items abbreviation kind_hlgroup an additional highlight group specifically for setting the highlight attributes of the completion kind. When this field is present, it will override the
--- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -360,7 +360,8 @@ cmdline_pum_create( compl_match_array[i].pum_info = NULL; compl_match_array[i].pum_extra = NULL; compl_match_array[i].pum_kind = NULL; - compl_match_array[i].pum_user_hlattr = -1; + compl_match_array[i].pum_user_abbr_hlattr = -1; + compl_match_array[i].pum_user_kind_hlattr = -1; } // Compute the popup menu starting column
--- a/src/insexpand.c +++ b/src/insexpand.c @@ -100,13 +100,14 @@ struct compl_S #ifdef FEAT_EVAL typval_T cp_user_data; #endif - char_u *cp_fname; // file containing the match, allocated when - // cp_flags has CP_FREE_FNAME - int cp_flags; // CP_ values - int cp_number; // sequence number - int cp_score; // fuzzy match score - int cp_user_hlattr; // highlight attribute to combine with - int cp_user_kind_hlattr; // highlight attribute for kind + char_u *cp_fname; // file containing the match, allocated when + // cp_flags has CP_FREE_FNAME + int cp_flags; // CP_ values + int cp_number; // sequence number + int cp_score; // fuzzy match score + int cp_user_abbr_hlattr; // highlight attribute to combine with + // for abbr. + int cp_user_kind_hlattr; // highlight attribute for kind }; // values for cp_flags @@ -772,7 +773,7 @@ ins_compl_add( int cdir, int flags_arg, int adup, // accept duplicate match - int user_hlattr, + int user_abbr_hlattr, int user_kind_hlattr) { compl_T *match; @@ -837,7 +838,7 @@ ins_compl_add( else match->cp_fname = NULL; match->cp_flags = flags; - match->cp_user_hlattr = user_hlattr; + match->cp_user_abbr_hlattr = user_abbr_hlattr; match->cp_user_kind_hlattr = user_kind_hlattr; if (cptext != NULL) @@ -1335,7 +1336,7 @@ ins_compl_build_pum(void) compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND]; compl_match_array[i].pum_info = compl->cp_text[CPT_INFO]; compl_match_array[i].pum_score = compl->cp_score; - compl_match_array[i].pum_user_hlattr = compl->cp_user_hlattr; + compl_match_array[i].pum_user_abbr_hlattr = compl->cp_user_abbr_hlattr; compl_match_array[i].pum_user_kind_hlattr = compl->cp_user_kind_hlattr; if (compl->cp_text[CPT_MENU] != NULL) compl_match_array[i++].pum_extra = @@ -2863,9 +2864,9 @@ ins_compl_add_tv(typval_T *tv, int dir, char_u *(cptext[CPT_COUNT]); typval_T user_data; int status; - char_u *user_hlname; + char_u *user_abbr_hlname; + int user_abbr_hlattr = -1; char_u *user_kind_hlname; - int user_hlattr = -1; int user_kind_hlattr = -1; user_data.v_type = VAR_UNKNOWN; @@ -2877,8 +2878,8 @@ ins_compl_add_tv(typval_T *tv, int dir, cptext[CPT_KIND] = dict_get_string(tv->vval.v_dict, "kind", FALSE); cptext[CPT_INFO] = dict_get_string(tv->vval.v_dict, "info", FALSE); - user_hlname = dict_get_string(tv->vval.v_dict, "hl_group", FALSE); - user_hlattr = get_user_highlight_attr(user_hlname); + user_abbr_hlname = dict_get_string(tv->vval.v_dict, "abbr_hlgroup", FALSE); + user_abbr_hlattr = get_user_highlight_attr(user_abbr_hlname); user_kind_hlname = dict_get_string(tv->vval.v_dict, "kind_hlgroup", FALSE); user_kind_hlattr = get_user_highlight_attr(user_kind_hlname); @@ -2906,7 +2907,8 @@ ins_compl_add_tv(typval_T *tv, int dir, return FAIL; } status = ins_compl_add(word, -1, NULL, cptext, - &user_data, dir, flags, dup, user_hlattr, user_kind_hlattr); + &user_data, dir, flags, dup, + user_abbr_hlattr, user_kind_hlattr); if (status != OK) clear_tv(&user_data); return status;
--- a/src/popupmenu.c +++ b/src/popupmenu.c @@ -586,6 +586,8 @@ pum_redraw(void) pum_extra_width }; int basic_width; // first item width int last_isabbr = FALSE; + int user_abbr_hlattr, user_kind_hlattr; + int orig_attr = -1; hlf_T hlfsNorm[3]; hlf_T hlfsSel[3]; @@ -660,10 +662,13 @@ pum_redraw(void) item_type = order[j]; hlf = hlfs[item_type]; attr = highlight_attr[hlf]; - if (pum_array[idx].pum_user_hlattr > 0) - attr = hl_combine_attr(attr, pum_array[idx].pum_user_hlattr); - if (item_type == CPT_KIND && pum_array[idx].pum_user_kind_hlattr > 0) - attr = hl_combine_attr(attr, pum_array[idx].pum_user_kind_hlattr); + orig_attr = attr; + user_abbr_hlattr = pum_array[idx].pum_user_abbr_hlattr; + user_kind_hlattr = pum_array[idx].pum_user_kind_hlattr; + if (item_type == CPT_ABBR && user_abbr_hlattr > 0) + attr = hl_combine_attr(attr, user_abbr_hlattr); + if (item_type == CPT_KIND && user_kind_hlattr > 0) + attr = hl_combine_attr(attr, user_kind_hlattr); width = 0; s = NULL; p = pum_get_item(idx, item_type); @@ -678,7 +683,7 @@ pum_redraw(void) // Display the text that fits or comes before a Tab. // First convert it to printable characters. char_u *st; - int *attrs; + int *attrs = NULL; int saved = *p; if (saved != NUL) @@ -687,9 +692,9 @@ pum_redraw(void) if (saved != NUL) *p = saved; - int user_hlattr = pum_array[idx].pum_user_hlattr; - attrs = pum_compute_text_attrs(st, hlf, user_hlattr); - + if (item_type == CPT_ABBR) + attrs = pum_compute_text_attrs(st, hlf, + user_abbr_hlattr); #ifdef FEAT_RIGHTLEFT if (pum_rl) { @@ -771,7 +776,11 @@ pum_redraw(void) col += width; } - vim_free(attrs); + if (attrs != NULL) + { + vim_free(attrs); + attrs = NULL; + } if (*p != TAB) break; @@ -781,13 +790,14 @@ pum_redraw(void) if (pum_rl) { screen_puts_len((char_u *)" ", 2, row, col - 1, - attr); + orig_attr); col -= 2; } else #endif { - screen_puts_len((char_u *)" ", 2, row, col, attr); + screen_puts_len((char_u *)" ", 2, row, col, + orig_attr); col += 2; } totwidth += 2; @@ -823,7 +833,7 @@ pum_redraw(void) #endif { screen_fill(row, row + 1, col, pum_col + basic_width + n, - ' ', ' ', attr); + ' ', ' ', orig_attr); col = pum_col + basic_width + n; } totwidth = basic_width + n;
--- a/src/structs.h +++ b/src/structs.h @@ -4468,14 +4468,14 @@ typedef struct */ typedef struct { - char_u *pum_text; // main menu text - char_u *pum_kind; // extra kind text (may be truncated) - char_u *pum_extra; // extra menu text (may be truncated) - char_u *pum_info; // extra info - int pum_score; // fuzzy match score - int pum_idx; // index of item before sorting by score - int pum_user_hlattr; // highlight attribute to combine with - int pum_user_kind_hlattr; // highlight attribute for kind + char_u *pum_text; // main menu text + char_u *pum_kind; // extra kind text (may be truncated) + char_u *pum_extra; // extra menu text (may be truncated) + char_u *pum_info; // extra info + int pum_score; // fuzzy match score + int pum_idx; // index of item before sorting by score + int pum_user_abbr_hlattr; // highlight attribute to combine with + int pum_user_kind_hlattr; // highlight attribute for kind } pumitem_T; /* @@ -5086,4 +5086,3 @@ typedef struct #define KEYVALUE_ENTRY(k, v) \ {(k), (v), STRLEN_LITERAL(v)} -
--- a/src/testdir/dumps/Test_pum_highlights_12.dump +++ b/src/testdir/dumps/Test_pum_highlights_12.dump @@ -1,7 +1,7 @@ |a+0&#ffffff0|w|o|r|d|1> @68 -|a+0#ff404010#e0e0e08|w|o|r|d|1| |W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52 +|a+0#ff404010#e0e0e08|w|o|r|d|1| +0#0000001&|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 -|你*0#ff404010#ffd7ff255|好| +&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52 +|你*0#ff404010#ffd7ff255|好| +0#0000001&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52 |~| @73 |~| @73 |~| @73
--- a/src/testdir/dumps/Test_pum_highlights_13.dump +++ b/src/testdir/dumps/Test_pum_highlights_13.dump @@ -1,7 +1,7 @@ |a+0&#ffffff0|w|o|r|d|1> @68 -|a+8#ff404010#e0e0e08|w|o+0&&|r|d|1| |W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52 +|a+8#ff404010#e0e0e08|w|o+0&&|r|d|1| +0#0000001&|W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52 |a+8#0000e05#ffd7ff255|w|o+0#0000001&|r|d|2| |W| |e|x|t|r|a| |t|e|x|t| |2| | +0#4040ff13#ffffff0@52 -|你*0#ff404010#ffd7ff255|好| +&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52 +|你*0#ff404010#ffd7ff255|好| +0#0000001&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52 |~| @73 |~| @73 |~| @73
--- a/src/testdir/dumps/Test_pum_highlights_14.dump +++ b/src/testdir/dumps/Test_pum_highlights_14.dump @@ -1,7 +1,7 @@ |a+0&#ffffff0|w|o|r|d|2> @68 -|a+8#ff404010#ffd7ff255|w|o+0&&|r|d|1| |W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52 +|a+8#ff404010#ffd7ff255|w|o+0&&|r|d|1| +0#0000001&|W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52 |a+8#00e0e07#e0e0e08|w|o+0#0000001&|r|d|2| |W| |e|x|t|r|a| |t|e|x|t| |2| | +0#4040ff13#ffffff0@52 -|你*0#ff404010#ffd7ff255|好| +&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52 +|你*0#ff404010#ffd7ff255|好| +0#0000001&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52 |~| @73 |~| @73 |~| @73
--- a/src/testdir/dumps/Test_pum_highlights_16.dump +++ b/src/testdir/dumps/Test_pum_highlights_16.dump @@ -1,7 +1,7 @@ |a+0&#ffffff0|w|o|r|d|1> @68 -|a+0#ff404010#e0e0e08|w|o|r|d|1| |v+0#ffff4012&|a|r|i|a|b|l|e| |e+0#ff404010&|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@45 -|a+0#0000001#ffd7ff255|w|o|r|d|2| |f+0#4040ff13&|u|n|c|t|i|o|n| |e+0#0000001&|x|t|r|a| |t|e|x|t| |2| | +0#4040ff13#ffffff0@45 -|你*0#0000001#ffd7ff255|好| +&@2|c+0#40ff4011&|l|a|s@1| @3|e+0#0000001&|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@45 +|a+0#ff404010#e0e0e08|w|o|r|d|1| +0#0000001&|v+0#ffff4012&|a|r|i|a|b|l|e| +0#0000001&|e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@45 +|a+0#0000001#ffd7ff255|w|o|r|d|2| |f+0#4040ff13&|u|n|c|t|i|o|n| +0#0000001&|e|x|t|r|a| |t|e|x|t| |2| | +0#4040ff13#ffffff0@45 +|你*0#0000001#ffd7ff255|好| +&@2|c+0#40ff4011&|l|a|s@1| +0#0000001&@3|e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@45 |~| @73 |~| @73 |~| @73
--- a/src/testdir/test_popup.vim +++ b/src/testdir/test_popup.vim @@ -1504,7 +1504,7 @@ func Test_pum_highlights_match() call StopVimInTerminal(buf) endfunc -func Test_pum_user_hl_group() +func Test_pum_user_abbr_hlgroup() CheckScreendump let lines =<< trim END func CompleteFunc( findstart, base ) @@ -1513,9 +1513,9 @@ func Test_pum_user_hl_group() endif return { \ 'words': [ - \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'hl_group': 'StrikeFake' }, + \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' }, \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', }, - \ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'hl_group': 'StrikeFake' }, + \ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' }, \]} endfunc set completeopt=menu @@ -1557,7 +1557,7 @@ func Test_pum_user_kind_hlgroup() endif return { \ 'words': [ - \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'variable', 'kind_hlgroup': 'KindVar', 'hl_group': 'StrikeFake' }, + \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'variable', 'kind_hlgroup': 'KindVar', 'abbr_hlgroup': 'StrikeFake' }, \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'function', 'kind_hlgroup': 'KindFunc' }, \ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'class', 'kind_hlgroup': 'KindClass' }, \]}