Skip to content

Commit 0fe17f8

Browse files
glepnirchrisbra
authored andcommitted
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>
1 parent 0407d62 commit 0fe17f8

11 files changed

Lines changed: 66 additions & 52 deletions

runtime/doc/insert.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,12 +1183,12 @@ items:
11831183
user_data custom data which is associated with the item and
11841184
available in |v:completed_item|; it can be any type;
11851185
defaults to an empty string
1186-
hl_group an additional highlight group whose attributes are
1186+
abbr_hlgroup an additional highlight group whose attributes are
11871187
combined with |hl-PmenuSel| and |hl-Pmenu| or
11881188
|hl-PmenuMatchSel| and |hl-PmenuMatch| highlight
11891189
attributes in the popup menu to apply cterm and gui
11901190
properties (with higher priority) like strikethrough
1191-
to the completion items
1191+
to the completion items abbreviation
11921192
kind_hlgroup an additional highlight group specifically for setting
11931193
the highlight attributes of the completion kind. When
11941194
this field is present, it will override the

src/cmdexpand.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ cmdline_pum_create(
360360
compl_match_array[i].pum_info = NULL;
361361
compl_match_array[i].pum_extra = NULL;
362362
compl_match_array[i].pum_kind = NULL;
363-
compl_match_array[i].pum_user_hlattr = -1;
363+
compl_match_array[i].pum_user_abbr_hlattr = -1;
364+
compl_match_array[i].pum_user_kind_hlattr = -1;
364365
}
365366

366367
// Compute the popup menu starting column

src/insexpand.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ struct compl_S
100100
#ifdef FEAT_EVAL
101101
typval_T cp_user_data;
102102
#endif
103-
char_u *cp_fname; // file containing the match, allocated when
104-
// cp_flags has CP_FREE_FNAME
105-
int cp_flags; // CP_ values
106-
int cp_number; // sequence number
107-
int cp_score; // fuzzy match score
108-
int cp_user_hlattr; // highlight attribute to combine with
109-
int cp_user_kind_hlattr; // highlight attribute for kind
103+
char_u *cp_fname; // file containing the match, allocated when
104+
// cp_flags has CP_FREE_FNAME
105+
int cp_flags; // CP_ values
106+
int cp_number; // sequence number
107+
int cp_score; // fuzzy match score
108+
int cp_user_abbr_hlattr; // highlight attribute to combine with
109+
// for abbr.
110+
int cp_user_kind_hlattr; // highlight attribute for kind
110111
};
111112

112113
// values for cp_flags
@@ -772,7 +773,7 @@ ins_compl_add(
772773
int cdir,
773774
int flags_arg,
774775
int adup, // accept duplicate match
775-
int user_hlattr,
776+
int user_abbr_hlattr,
776777
int user_kind_hlattr)
777778
{
778779
compl_T *match;
@@ -837,7 +838,7 @@ ins_compl_add(
837838
else
838839
match->cp_fname = NULL;
839840
match->cp_flags = flags;
840-
match->cp_user_hlattr = user_hlattr;
841+
match->cp_user_abbr_hlattr = user_abbr_hlattr;
841842
match->cp_user_kind_hlattr = user_kind_hlattr;
842843

843844
if (cptext != NULL)
@@ -1335,7 +1336,7 @@ ins_compl_build_pum(void)
13351336
compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND];
13361337
compl_match_array[i].pum_info = compl->cp_text[CPT_INFO];
13371338
compl_match_array[i].pum_score = compl->cp_score;
1338-
compl_match_array[i].pum_user_hlattr = compl->cp_user_hlattr;
1339+
compl_match_array[i].pum_user_abbr_hlattr = compl->cp_user_abbr_hlattr;
13391340
compl_match_array[i].pum_user_kind_hlattr = compl->cp_user_kind_hlattr;
13401341
if (compl->cp_text[CPT_MENU] != NULL)
13411342
compl_match_array[i++].pum_extra =
@@ -2863,9 +2864,9 @@ ins_compl_add_tv(typval_T *tv, int dir, int fast)
28632864
char_u *(cptext[CPT_COUNT]);
28642865
typval_T user_data;
28652866
int status;
2866-
char_u *user_hlname;
2867+
char_u *user_abbr_hlname;
2868+
int user_abbr_hlattr = -1;
28672869
char_u *user_kind_hlname;
2868-
int user_hlattr = -1;
28692870
int user_kind_hlattr = -1;
28702871

28712872
user_data.v_type = VAR_UNKNOWN;
@@ -2877,8 +2878,8 @@ ins_compl_add_tv(typval_T *tv, int dir, int fast)
28772878
cptext[CPT_KIND] = dict_get_string(tv->vval.v_dict, "kind", FALSE);
28782879
cptext[CPT_INFO] = dict_get_string(tv->vval.v_dict, "info", FALSE);
28792880

2880-
user_hlname = dict_get_string(tv->vval.v_dict, "hl_group", FALSE);
2881-
user_hlattr = get_user_highlight_attr(user_hlname);
2881+
user_abbr_hlname = dict_get_string(tv->vval.v_dict, "abbr_hlgroup", FALSE);
2882+
user_abbr_hlattr = get_user_highlight_attr(user_abbr_hlname);
28822883

28832884
user_kind_hlname = dict_get_string(tv->vval.v_dict, "kind_hlgroup", FALSE);
28842885
user_kind_hlattr = get_user_highlight_attr(user_kind_hlname);
@@ -2906,7 +2907,8 @@ ins_compl_add_tv(typval_T *tv, int dir, int fast)
29062907
return FAIL;
29072908
}
29082909
status = ins_compl_add(word, -1, NULL, cptext,
2909-
&user_data, dir, flags, dup, user_hlattr, user_kind_hlattr);
2910+
&user_data, dir, flags, dup,
2911+
user_abbr_hlattr, user_kind_hlattr);
29102912
if (status != OK)
29112913
clear_tv(&user_data);
29122914
return status;

src/popupmenu.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ pum_redraw(void)
586586
pum_extra_width };
587587
int basic_width; // first item width
588588
int last_isabbr = FALSE;
589+
int user_abbr_hlattr, user_kind_hlattr;
590+
int orig_attr = -1;
589591

590592
hlf_T hlfsNorm[3];
591593
hlf_T hlfsSel[3];
@@ -660,10 +662,13 @@ pum_redraw(void)
660662
item_type = order[j];
661663
hlf = hlfs[item_type];
662664
attr = highlight_attr[hlf];
663-
if (pum_array[idx].pum_user_hlattr > 0)
664-
attr = hl_combine_attr(attr, pum_array[idx].pum_user_hlattr);
665-
if (item_type == CPT_KIND && pum_array[idx].pum_user_kind_hlattr > 0)
666-
attr = hl_combine_attr(attr, pum_array[idx].pum_user_kind_hlattr);
665+
orig_attr = attr;
666+
user_abbr_hlattr = pum_array[idx].pum_user_abbr_hlattr;
667+
user_kind_hlattr = pum_array[idx].pum_user_kind_hlattr;
668+
if (item_type == CPT_ABBR && user_abbr_hlattr > 0)
669+
attr = hl_combine_attr(attr, user_abbr_hlattr);
670+
if (item_type == CPT_KIND && user_kind_hlattr > 0)
671+
attr = hl_combine_attr(attr, user_kind_hlattr);
667672
width = 0;
668673
s = NULL;
669674
p = pum_get_item(idx, item_type);
@@ -678,7 +683,7 @@ pum_redraw(void)
678683
// Display the text that fits or comes before a Tab.
679684
// First convert it to printable characters.
680685
char_u *st;
681-
int *attrs;
686+
int *attrs = NULL;
682687
int saved = *p;
683688

684689
if (saved != NUL)
@@ -687,9 +692,9 @@ pum_redraw(void)
687692
if (saved != NUL)
688693
*p = saved;
689694

690-
int user_hlattr = pum_array[idx].pum_user_hlattr;
691-
attrs = pum_compute_text_attrs(st, hlf, user_hlattr);
692-
695+
if (item_type == CPT_ABBR)
696+
attrs = pum_compute_text_attrs(st, hlf,
697+
user_abbr_hlattr);
693698
#ifdef FEAT_RIGHTLEFT
694699
if (pum_rl)
695700
{
@@ -771,7 +776,11 @@ pum_redraw(void)
771776
col += width;
772777
}
773778

774-
vim_free(attrs);
779+
if (attrs != NULL)
780+
{
781+
vim_free(attrs);
782+
attrs = NULL;
783+
}
775784

776785
if (*p != TAB)
777786
break;
@@ -781,13 +790,14 @@ pum_redraw(void)
781790
if (pum_rl)
782791
{
783792
screen_puts_len((char_u *)" ", 2, row, col - 1,
784-
attr);
793+
orig_attr);
785794
col -= 2;
786795
}
787796
else
788797
#endif
789798
{
790-
screen_puts_len((char_u *)" ", 2, row, col, attr);
799+
screen_puts_len((char_u *)" ", 2, row, col,
800+
orig_attr);
791801
col += 2;
792802
}
793803
totwidth += 2;
@@ -823,7 +833,7 @@ pum_redraw(void)
823833
#endif
824834
{
825835
screen_fill(row, row + 1, col, pum_col + basic_width + n,
826-
' ', ' ', attr);
836+
' ', ' ', orig_attr);
827837
col = pum_col + basic_width + n;
828838
}
829839
totwidth = basic_width + n;

src/structs.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,14 +4468,14 @@ typedef struct
44684468
*/
44694469
typedef struct
44704470
{
4471-
char_u *pum_text; // main menu text
4472-
char_u *pum_kind; // extra kind text (may be truncated)
4473-
char_u *pum_extra; // extra menu text (may be truncated)
4474-
char_u *pum_info; // extra info
4475-
int pum_score; // fuzzy match score
4476-
int pum_idx; // index of item before sorting by score
4477-
int pum_user_hlattr; // highlight attribute to combine with
4478-
int pum_user_kind_hlattr; // highlight attribute for kind
4471+
char_u *pum_text; // main menu text
4472+
char_u *pum_kind; // extra kind text (may be truncated)
4473+
char_u *pum_extra; // extra menu text (may be truncated)
4474+
char_u *pum_info; // extra info
4475+
int pum_score; // fuzzy match score
4476+
int pum_idx; // index of item before sorting by score
4477+
int pum_user_abbr_hlattr; // highlight attribute to combine with
4478+
int pum_user_kind_hlattr; // highlight attribute for kind
44794479
} pumitem_T;
44804480

44814481
/*
@@ -5086,4 +5086,3 @@ typedef struct
50865086

50875087
#define KEYVALUE_ENTRY(k, v) \
50885088
{(k), (v), STRLEN_LITERAL(v)}
5089-

src/testdir/dumps/Test_pum_highlights_12.dump

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
|a+0&#ffffff0|w|o|r|d|1> @68
2-
|a+0#ff404010#e0e0e08|w|o|r|d|1| |W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52
2+
|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
33
|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-
|你*0#ff404010#ffd7ff255|好| +&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
4+
|你*0#ff404010#ffd7ff255|好| +0#0000001&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
55
|~| @73
66
|~| @73
77
|~| @73

src/testdir/dumps/Test_pum_highlights_13.dump

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
|a+0&#ffffff0|w|o|r|d|1> @68
2-
|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
2+
|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
33
|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
4-
|你*0#ff404010#ffd7ff255|好| +&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
4+
|你*0#ff404010#ffd7ff255|好| +0#0000001&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
55
|~| @73
66
|~| @73
77
|~| @73

src/testdir/dumps/Test_pum_highlights_14.dump

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
|a+0&#ffffff0|w|o|r|d|2> @68
2-
|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
2+
|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
33
|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
4-
|你*0#ff404010#ffd7ff255|好| +&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
4+
|你*0#ff404010#ffd7ff255|好| +0#0000001&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
55
|~| @73
66
|~| @73
77
|~| @73

src/testdir/dumps/Test_pum_highlights_16.dump

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
|a+0&#ffffff0|w|o|r|d|1> @68
2-
|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
3-
|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
4-
|你*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
2+
|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
3+
|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
4+
|你*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
55
|~| @73
66
|~| @73
77
|~| @73

src/testdir/test_popup.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ func Test_pum_highlights_match()
15041504
call StopVimInTerminal(buf)
15051505
endfunc
15061506

1507-
func Test_pum_user_hl_group()
1507+
func Test_pum_user_abbr_hlgroup()
15081508
CheckScreendump
15091509
let lines =<< trim END
15101510
func CompleteFunc( findstart, base )
@@ -1513,9 +1513,9 @@ func Test_pum_user_hl_group()
15131513
endif
15141514
return {
15151515
\ 'words': [
1516-
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'hl_group': 'StrikeFake' },
1516+
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' },
15171517
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
1518-
\ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'hl_group': 'StrikeFake' },
1518+
\ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'abbr_hlgroup': 'StrikeFake' },
15191519
\]}
15201520
endfunc
15211521
set completeopt=menu
@@ -1557,7 +1557,7 @@ func Test_pum_user_kind_hlgroup()
15571557
endif
15581558
return {
15591559
\ 'words': [
1560-
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'variable', 'kind_hlgroup': 'KindVar', 'hl_group': 'StrikeFake' },
1560+
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'variable', 'kind_hlgroup': 'KindVar', 'abbr_hlgroup': 'StrikeFake' },
15611561
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'function', 'kind_hlgroup': 'KindFunc' },
15621562
\ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'class', 'kind_hlgroup': 'KindClass' },
15631563
\]}

0 commit comments

Comments
 (0)