mirror of
https://github.com/neovim/neovim.git
synced 2025-10-10 03:46:31 +00:00
vim-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.
d61e8aaae5
This commit is contained in:
@@ -52,6 +52,7 @@ static bool did_syntax_onoff = false;
|
||||
struct hl_group {
|
||||
char_u *sg_name; ///< highlight group name
|
||||
char_u *sg_name_u; ///< uppercase of sg_name
|
||||
int sg_cleared; ///< "hi clear" was used
|
||||
int sg_attr; ///< Screen attr @see ATTR_ENTRY
|
||||
int sg_link; ///< link to this highlight group ID
|
||||
int sg_set; ///< combination of flags in \ref SG_SET
|
||||
@@ -6490,6 +6491,7 @@ void do_highlight(const char *line, const bool forceit, const bool init)
|
||||
HL_TABLE()[from_id - 1].sg_set |= SG_LINK;
|
||||
HL_TABLE()[from_id - 1].sg_link = to_id;
|
||||
HL_TABLE()[from_id - 1].sg_scriptID = current_SID;
|
||||
HL_TABLE()[from_id - 1].sg_cleared = false;
|
||||
redraw_all_later(SOME_VALID);
|
||||
}
|
||||
}
|
||||
@@ -6872,6 +6874,7 @@ void do_highlight(const char *line, const bool forceit, const bool init)
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
HL_TABLE()[idx].sg_cleared = false;
|
||||
|
||||
// When highlighting has been given for a group, don't link it.
|
||||
if (!init || !(HL_TABLE()[idx].sg_set & SG_LINK)) {
|
||||
@@ -6953,6 +6956,8 @@ static int hl_has_settings(int idx, int check_link)
|
||||
*/
|
||||
static void highlight_clear(int idx)
|
||||
{
|
||||
HL_TABLE()[idx].sg_cleared = true;
|
||||
|
||||
HL_TABLE()[idx].sg_attr = 0;
|
||||
HL_TABLE()[idx].sg_cterm = 0;
|
||||
HL_TABLE()[idx].sg_cterm_bold = FALSE;
|
||||
@@ -7763,10 +7768,20 @@ const char *get_highlight_name(expand_T *const xp, const int idx)
|
||||
} else if (idx == highlight_ga.ga_len + include_none + include_default + 1
|
||||
&& include_link != 0) {
|
||||
return "clear";
|
||||
} else if (idx < 0 || idx >= highlight_ga.ga_len) {
|
||||
} else if (idx < 0) {
|
||||
return NULL;
|
||||
}
|
||||
return (const char *)HL_TABLE()[idx].sg_name;
|
||||
|
||||
/* Items are never removed from the table, skip the ones that were cleared.
|
||||
*/
|
||||
int current_idx = idx;
|
||||
while (current_idx < highlight_ga.ga_len && HL_TABLE()[current_idx].sg_cleared) {
|
||||
++current_idx;
|
||||
}
|
||||
if (current_idx >= highlight_ga.ga_len) {
|
||||
return NULL;
|
||||
}
|
||||
return (const char *)HL_TABLE()[current_idx].sg_name;
|
||||
}
|
||||
|
||||
color_name_table_T color_name_table[] = {
|
||||
|
@@ -152,6 +152,12 @@ func Test_syntax_completion()
|
||||
call feedkeys(":syn sync \<C-A>\<C-B>\"\<CR>", 'tx')
|
||||
call assert_equal('"syn sync ccomment clear fromstart linebreaks= linecont lines= match maxlines= minlines= region', @:)
|
||||
|
||||
" Check that clearing "Aap" avoids it showing up before Boolean.
|
||||
hi Aap ctermfg=blue
|
||||
call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx')
|
||||
call assert_match('^"syn list Aap Boolean Character ', @:)
|
||||
hi clear Aap
|
||||
|
||||
call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx')
|
||||
call assert_match('^"syn list Boolean Character ', @:)
|
||||
|
||||
@@ -188,11 +194,11 @@ func Test_syntax_arg_skipped()
|
||||
syntax conceal off
|
||||
call assert_match('conceal off', execute('syntax conceal'))
|
||||
|
||||
syntax region Tar start=/</ end=/>/
|
||||
syntax region Bar start=/</ end=/>/
|
||||
if 0
|
||||
syntax region NotTest start=/</ end=/>/ contains=@Spell
|
||||
endif
|
||||
call assert_match('Tar', execute('syntax'))
|
||||
call assert_match('Bar', execute('syntax'))
|
||||
call assert_notmatch('NotTest', execute('syntax'))
|
||||
call assert_notmatch('Spell', execute('syntax'))
|
||||
|
||||
@@ -202,6 +208,8 @@ func Test_syntax_arg_skipped()
|
||||
syntax rest
|
||||
endif
|
||||
call assert_equal(a, execute('hi Foo'))
|
||||
hi clear Bar
|
||||
hi clear Foo
|
||||
|
||||
set ft=tags
|
||||
syn off
|
||||
@@ -283,8 +291,7 @@ func Test_syntax_arg_skipped()
|
||||
endif
|
||||
call assert_match('on C-style comments', execute('syntax sync'))
|
||||
call assert_match('maximal 5 lines', execute('syntax sync'))
|
||||
syn clear
|
||||
syn keyword Foo foo
|
||||
syn sync clear
|
||||
if 0
|
||||
syn sync ccomment
|
||||
endif
|
||||
@@ -292,3 +299,33 @@ func Test_syntax_arg_skipped()
|
||||
|
||||
syn clear
|
||||
endfunc
|
||||
|
||||
func Test_invalid_arg()
|
||||
call assert_fails('syntax case asdf', 'E390:')
|
||||
call assert_fails('syntax conceal asdf', 'E390:')
|
||||
call assert_fails('syntax spell asdf', 'E390:')
|
||||
endfunc
|
||||
|
||||
func Test_syn_sync()
|
||||
syntax region HereGroup start=/this/ end=/that/
|
||||
syntax sync match SyncHere grouphere HereGroup "pattern"
|
||||
call assert_match('SyncHere', execute('syntax sync'))
|
||||
syn sync clear
|
||||
call assert_notmatch('SyncHere', execute('syntax sync'))
|
||||
syn clear
|
||||
endfunc
|
||||
|
||||
func Test_syn_clear()
|
||||
syntax keyword Foo foo
|
||||
syntax keyword Bar tar
|
||||
call assert_match('Foo', execute('syntax'))
|
||||
call assert_match('Bar', execute('syntax'))
|
||||
syn clear Foo
|
||||
call assert_notmatch('Foo', execute('syntax'))
|
||||
call assert_match('Bar', execute('syntax'))
|
||||
syn clear Foo Bar
|
||||
call assert_notmatch('Foo', execute('syntax'))
|
||||
call assert_notmatch('Bar', execute('syntax'))
|
||||
hi clear Foo
|
||||
hi clear Bar
|
||||
endfunc
|
||||
|
Reference in New Issue
Block a user