]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0771: completion attribute hl_group is confusing v9.1.0771
authorglepnir <glephunter@gmail.com>
Tue, 8 Oct 2024 20:26:44 +0000 (22:26 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 8 Oct 2024 20:26:44 +0000 (22:26 +0200)
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>
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

index a954eef0b8df025733d697fc3897e7659874b806..839d17a64d18f5ec9c6a75750441e31d99d5286d 100644 (file)
@@ -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
index c7c42abffa82b6d955419010691af7f799695147..e563d225f967833163263b0d1187f93751c78bd5 100644 (file)
@@ -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
index a774a330996607a052705a90caf248dea31c93b7..eb920a751e8635e72768ec7b2a11f4a494320aec 100644 (file)
@@ -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, int fast)
     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, int fast)
        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, int fast)
        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;
index 437c6e7e190869657f1b5bf5af2f61f9dec7e1b8..90ffe0e34237388e846cb94facc5f49ecdade0ee 100644 (file)
@@ -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;
index 79f415d03b7920e953632dc55af1659f945e24bc..debc7df96b7d1995dbcf3bc8bf34debc453943a6 100644 (file)
@@ -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)}
-
index a0d2b491fba7d964b78fd64415882c3978874cca..c7c20012da2f47577c678d506d740e513f2a0cba 100644 (file)
@@ -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
index 34fde12ba80cf21c68fd3b207b9dc0736706e8f7..96a00eb15dd9d4f74d1bcfdb3b9293489ac6b8dc 100644 (file)
@@ -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
index f35b4cbf015e7658f5c539a33c114ae8243cd778..563ee856a97174ce9d6d32cfcd7e41a28084a61a 100644 (file)
@@ -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
index fe2b68db88d0f96707f355f4df953953c9aa9111..5a8d78737ce62d8ea7c33b0e9f86c48830a2aba8 100644 (file)
@@ -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
index a4f6d02d20955ec9c1a1367bbbb066df82033b70..3c748a4a524a11057c49f764a713a8bdb4b3a22b 100644 (file)
@@ -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'  },
             \]}
index e949908f087665d66278c6050514859b3f265151..67c05f3ea1eaca430e6ad4f1d1e27b516b7b55d1 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    771,
 /**/
     770,
 /**/