Skip to content

Commit c96272e

Browse files
committed
patch 8.0.0513: getting name of cleared highlight group is wrong
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.
1 parent 1572e30 commit c96272e

7 files changed

Lines changed: 32 additions & 8 deletions

File tree

src/evalfunc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11746,7 +11746,7 @@ f_synIDattr(typval_T *argvars UNUSED, typval_T *rettv)
1174611746
break;
1174711747

1174811748
case 'n': /* name */
11749-
p = get_highlight_name(NULL, id - 1);
11749+
p = get_highlight_name_ext(NULL, id - 1, FALSE);
1175011750
break;
1175111751

1175211752
case 'r': /* reverse */

src/ex_cmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7962,7 +7962,7 @@ sign_list_defined(sign_T *sp)
79627962
if (sp->sn_line_hl > 0)
79637963
{
79647964
MSG_PUTS(" linehl=");
7965-
p = get_highlight_name(NULL, sp->sn_line_hl - 1);
7965+
p = get_highlight_name_ext(NULL, sp->sn_line_hl - 1, FALSE);
79667966
if (p == NULL)
79677967
MSG_PUTS("NONE");
79687968
else
@@ -7971,7 +7971,7 @@ sign_list_defined(sign_T *sp)
79717971
if (sp->sn_text_hl > 0)
79727972
{
79737973
MSG_PUTS(" texthl=");
7974-
p = get_highlight_name(NULL, sp->sn_text_hl - 1);
7974+
p = get_highlight_name_ext(NULL, sp->sn_text_hl - 1, FALSE);
79757975
if (p == NULL)
79767976
MSG_PUTS("NONE");
79777977
else

src/proto/syntax.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ void highlight_gui_started(void);
5252
int highlight_changed(void);
5353
void set_context_in_highlight_cmd(expand_T *xp, char_u *arg);
5454
char_u *get_highlight_name(expand_T *xp, int idx);
55+
char_u *get_highlight_name_ext(expand_T *xp, int idx, int skip_cleared);
5556
void free_highlight_fonts(void);
5657
/* vim: set ft=c : */

src/syntax.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9949,17 +9949,27 @@ highlight_list_two(int cnt, int attr)
99499949
|| defined(FEAT_SIGNS) || defined(PROTO)
99509950
/*
99519951
* Function given to ExpandGeneric() to obtain the list of group names.
9952-
* Also used for synIDattr() function.
99539952
*/
99549953
char_u *
99559954
get_highlight_name(expand_T *xp UNUSED, int idx)
9955+
{
9956+
return get_highlight_name_ext(xp, idx, TRUE);
9957+
}
9958+
9959+
/*
9960+
* Obtain a highlight group name.
9961+
* When "skip_cleared" is TRUE don't return a cleared entry.
9962+
*/
9963+
char_u *
9964+
get_highlight_name_ext(expand_T *xp UNUSED, int idx, int skip_cleared)
99569965
{
99579966
if (idx < 0)
99589967
return NULL;
9959-
/* Items are never removed from the table, skip the ones that were cleared.
9960-
*/
9961-
while (idx < highlight_ga.ga_len && HL_TABLE()[idx].sg_cleared)
9962-
++idx;
9968+
9969+
/* Items are never removed from the table, skip the ones that were
9970+
* cleared. */
9971+
if (skip_cleared && idx < highlight_ga.ga_len && HL_TABLE()[idx].sg_cleared)
9972+
return (char_u *)"";
99639973

99649974
#ifdef FEAT_CMDL_COMPL
99659975
if (idx == highlight_ga.ga_len && include_none != 0)

src/testdir/test_cmdline.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ func Test_highlight_completion()
7171
call assert_equal('"hi default', getreg(':'))
7272
call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
7373
call assert_equal('"hi clear', getreg(':'))
74+
75+
" A cleared group does not show up in completions.
76+
hi Anders ctermfg=green
77+
call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight'))
78+
hi clear Aardig
79+
call assert_equal(['Anders'], getcompletion('A', 'highlight'))
80+
hi clear Anders
81+
call assert_equal([], getcompletion('A', 'highlight'))
7482
endfunc
7583

7684
func Test_expr_completion()

src/testdir/test_syntax.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,16 @@ func Test_syn_clear()
326326
syntax keyword Bar tar
327327
call assert_match('Foo', execute('syntax'))
328328
call assert_match('Bar', execute('syntax'))
329+
call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
329330
syn clear Foo
330331
call assert_notmatch('Foo', execute('syntax'))
331332
call assert_match('Bar', execute('syntax'))
333+
call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
332334
syn clear Foo Bar
333335
call assert_notmatch('Foo', execute('syntax'))
334336
call assert_notmatch('Bar', execute('syntax'))
335337
hi clear Foo
338+
call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
336339
hi clear Bar
337340
endfunc
338341

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
513,
767769
/**/
768770
512,
769771
/**/

0 commit comments

Comments
 (0)