Skip to content

Commit d61e8aa

Browse files
committed
patch 8.0.0201: completion of highlight groups includes cleared names
Problem: When completing a group name for a highlight or syntax command cleared groups are included. Solution: Skip groups that have been cleared.
1 parent 58f60ca commit d61e8aa

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

src/syntax.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct hl_group
2222
{
2323
char_u *sg_name; /* highlight group name */
2424
char_u *sg_name_u; /* uppercase of sg_name */
25+
int sg_cleared; /* "hi clear" was used */
2526
/* for normal terminals */
2627
int sg_term; /* "term=" highlighting attributes */
2728
char_u *sg_start; /* terminal string for start highl */
@@ -7327,6 +7328,7 @@ do_highlight(
73277328
#ifdef FEAT_EVAL
73287329
HL_TABLE()[from_id - 1].sg_scriptID = current_SID;
73297330
#endif
7331+
HL_TABLE()[from_id - 1].sg_cleared = FALSE;
73307332
redraw_all_later(SOME_VALID);
73317333
}
73327334
}
@@ -8034,6 +8036,7 @@ do_highlight(
80348036
error = TRUE;
80358037
break;
80368038
}
8039+
HL_TABLE()[idx].sg_cleared = FALSE;
80378040

80388041
/*
80398042
* When highlighting has been given for a group, don't link it.
@@ -8171,6 +8174,8 @@ hl_has_settings(int idx, int check_link)
81718174
static void
81728175
highlight_clear(int idx)
81738176
{
8177+
HL_TABLE()[idx].sg_cleared = TRUE;
8178+
81748179
HL_TABLE()[idx].sg_term = 0;
81758180
vim_free(HL_TABLE()[idx].sg_start);
81768181
HL_TABLE()[idx].sg_start = NULL;
@@ -9958,7 +9963,13 @@ get_highlight_name(expand_T *xp UNUSED, int idx)
99589963
&& include_link != 0)
99599964
return (char_u *)"clear";
99609965
#endif
9961-
if (idx < 0 || idx >= highlight_ga.ga_len)
9966+
if (idx < 0)
9967+
return NULL;
9968+
/* Items are never removed from the table, skip the ones that were cleared.
9969+
*/
9970+
while (idx < highlight_ga.ga_len && HL_TABLE()[idx].sg_cleared)
9971+
++idx;
9972+
if (idx >= highlight_ga.ga_len)
99629973
return NULL;
99639974
return HL_TABLE()[idx].sg_name;
99649975
}

src/testdir/test_syntax.vim

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ func Test_syntax_completion()
156156
call feedkeys(":syn sync \<C-A>\<C-B>\"\<CR>", 'tx')
157157
call assert_equal('"syn sync ccomment clear fromstart linebreaks= linecont lines= match maxlines= minlines= region', @:)
158158

159+
" Check that clearing "Aap" avoids it showing up before Boolean.
160+
hi Aap ctermfg=blue
161+
call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx')
162+
call assert_match('^"syn list Aap Boolean Character ', @:)
163+
hi clear Aap
164+
159165
call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx')
160166
call assert_match('^"syn list Boolean Character ', @:)
161167

@@ -192,11 +198,11 @@ func Test_syntax_arg_skipped()
192198
call assert_match('conceal off', execute('syntax conceal'))
193199
endif
194200

195-
syntax region Tar start=/</ end=/>/
201+
syntax region Bar start=/</ end=/>/
196202
if 0
197203
syntax region NotTest start=/</ end=/>/ contains=@Spell
198204
endif
199-
call assert_match('Tar', execute('syntax'))
205+
call assert_match('Bar', execute('syntax'))
200206
call assert_notmatch('NotTest', execute('syntax'))
201207
call assert_notmatch('Spell', execute('syntax'))
202208

@@ -206,6 +212,8 @@ func Test_syntax_arg_skipped()
206212
syntax rest
207213
endif
208214
call assert_equal(a, execute('hi Foo'))
215+
hi clear Bar
216+
hi clear Foo
209217

210218
set ft=tags
211219
syn off
@@ -298,7 +306,9 @@ endfunc
298306

299307
func Test_invalid_arg()
300308
call assert_fails('syntax case asdf', 'E390:')
301-
call assert_fails('syntax conceal asdf', 'E390:')
309+
if has('conceal')
310+
call assert_fails('syntax conceal asdf', 'E390:')
311+
endif
302312
call assert_fails('syntax spell asdf', 'E390:')
303313
endfunc
304314

@@ -313,13 +323,15 @@ endfunc
313323

314324
func Test_syn_clear()
315325
syntax keyword Foo foo
316-
syntax keyword Tar tar
326+
syntax keyword Bar tar
317327
call assert_match('Foo', execute('syntax'))
318-
call assert_match('Tar', execute('syntax'))
328+
call assert_match('Bar', execute('syntax'))
319329
syn clear Foo
320330
call assert_notmatch('Foo', execute('syntax'))
321-
call assert_match('Tar', execute('syntax'))
322-
syn clear Foo Tar
331+
call assert_match('Bar', execute('syntax'))
332+
syn clear Foo Bar
323333
call assert_notmatch('Foo', execute('syntax'))
324-
call assert_notmatch('Tar', execute('syntax'))
334+
call assert_notmatch('Bar', execute('syntax'))
335+
hi clear Foo
336+
hi clear Bar
325337
endfunc

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+
201,
767769
/**/
768770
200,
769771
/**/

0 commit comments

Comments
 (0)