]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.0.0513: getting name of cleared highlight group is wrong v8.0.0513
authorBram Moolenaar <Bram@vim.org>
Sun, 26 Mar 2017 11:50:09 +0000 (13:50 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 26 Mar 2017 11:50:09 +0000 (13:50 +0200)
Problem:    Getting name of cleared highlight group is wrong. (Matt Wozniski)
Solution:   Only skip over cleared names for completion. (closes #1592)
            Also fix that a cleared group causes duplicate completions.

src/evalfunc.c
src/ex_cmds.c
src/proto/syntax.pro
src/syntax.c
src/testdir/test_cmdline.vim
src/testdir/test_syntax.vim
src/version.c

index 8869810dfac50f81353e5cba086bac39c76f2338..42773e1b8d920911fc4ac6141b7b6a6b70ad4d71 100644 (file)
@@ -11746,7 +11746,7 @@ f_synIDattr(typval_T *argvars UNUSED, typval_T *rettv)
                break;
 
        case 'n':                                       /* name */
-               p = get_highlight_name(NULL, id - 1);
+               p = get_highlight_name_ext(NULL, id - 1, FALSE);
                break;
 
        case 'r':                                       /* reverse */
index 0c4dffbc66fe400874ccdb2b76c73ec93e4276e4..6940e55277ad69849faab537b92163f83e998aeb 100644 (file)
@@ -7962,7 +7962,7 @@ sign_list_defined(sign_T *sp)
     if (sp->sn_line_hl > 0)
     {
        MSG_PUTS(" linehl=");
-       p = get_highlight_name(NULL, sp->sn_line_hl - 1);
+       p = get_highlight_name_ext(NULL, sp->sn_line_hl - 1, FALSE);
        if (p == NULL)
            MSG_PUTS("NONE");
        else
@@ -7971,7 +7971,7 @@ sign_list_defined(sign_T *sp)
     if (sp->sn_text_hl > 0)
     {
        MSG_PUTS(" texthl=");
-       p = get_highlight_name(NULL, sp->sn_text_hl - 1);
+       p = get_highlight_name_ext(NULL, sp->sn_text_hl - 1, FALSE);
        if (p == NULL)
            MSG_PUTS("NONE");
        else
index 64235b00bccf0cd0c9a0d9d36f7ee28774b26b57..aae187fe6859340261492febdd657afc0d1f309d 100644 (file)
@@ -52,5 +52,6 @@ void highlight_gui_started(void);
 int highlight_changed(void);
 void set_context_in_highlight_cmd(expand_T *xp, char_u *arg);
 char_u *get_highlight_name(expand_T *xp, int idx);
+char_u *get_highlight_name_ext(expand_T *xp, int idx, int skip_cleared);
 void free_highlight_fonts(void);
 /* vim: set ft=c : */
index a8942e797c3596e72b20475e1ad6c6bfc8e4ab10..42a0bdc3f956be5396f88892408fbfd8b477f9ac 100644 (file)
@@ -9949,17 +9949,27 @@ highlight_list_two(int cnt, int attr)
     || defined(FEAT_SIGNS) || defined(PROTO)
 /*
  * Function given to ExpandGeneric() to obtain the list of group names.
- * Also used for synIDattr() function.
  */
     char_u *
 get_highlight_name(expand_T *xp UNUSED, int idx)
+{
+    return get_highlight_name_ext(xp, idx, TRUE);
+}
+
+/*
+ * Obtain a highlight group name.
+ * When "skip_cleared" is TRUE don't return a cleared entry.
+ */
+    char_u *
+get_highlight_name_ext(expand_T *xp UNUSED, int idx, int skip_cleared)
 {
     if (idx < 0)
        return NULL;
-    /* Items are never removed from the table, skip the ones that were cleared.
-     */
-    while (idx < highlight_ga.ga_len && HL_TABLE()[idx].sg_cleared)
-       ++idx;
+
+    /* Items are never removed from the table, skip the ones that were
+     * cleared. */
+    if (skip_cleared && idx < highlight_ga.ga_len && HL_TABLE()[idx].sg_cleared)
+       return (char_u *)"";
 
 #ifdef FEAT_CMDL_COMPL
     if (idx == highlight_ga.ga_len && include_none != 0)
index 98a4337780fe715c2842faf0727b35c38e58eb17..77c91704923ee0235b033e7030b2d68dd48731ed 100644 (file)
@@ -71,6 +71,14 @@ func Test_highlight_completion()
   call assert_equal('"hi default', getreg(':'))
   call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
   call assert_equal('"hi clear', getreg(':'))
+
+  " A cleared group does not show up in completions.
+  hi Anders ctermfg=green
+  call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
+  hi clear Aardig
+  call assert_equal(['Anders'], getcompletion('A', 'highlight'))
+  hi clear Anders
+  call assert_equal([], getcompletion('A', 'highlight'))
 endfunc
 
 func Test_expr_completion()
index 8a00f992f2ddda3d78ca3aaf85e6180cdb6df158..9ebe3f13e8b93cbd1aee58e5d020ea4e93b10969 100644 (file)
@@ -326,13 +326,16 @@ func Test_syn_clear()
   syntax keyword Bar tar
   call assert_match('Foo', execute('syntax'))
   call assert_match('Bar', execute('syntax'))
+  call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
   syn clear Foo
   call assert_notmatch('Foo', execute('syntax'))
   call assert_match('Bar', execute('syntax'))
+  call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
   syn clear Foo Bar
   call assert_notmatch('Foo', execute('syntax'))
   call assert_notmatch('Bar', execute('syntax'))
   hi clear Foo
+  call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
   hi clear Bar
 endfunc
 
index 3ebe8a6f9d13a0b7529beef9752a496742f4e16b..28f3c59d11353e7202dda8263df815308b45010c 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    513,
 /**/
     512,
 /**/