0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2017-03-26 13:50:09 +02:00
parent 1572e30607
commit c96272e30e
7 changed files with 32 additions and 8 deletions

View File

@@ -11746,7 +11746,7 @@ f_synIDattr(typval_T *argvars UNUSED, typval_T *rettv)
break; break;
case 'n': /* name */ case 'n': /* name */
p = get_highlight_name(NULL, id - 1); p = get_highlight_name_ext(NULL, id - 1, FALSE);
break; break;
case 'r': /* reverse */ case 'r': /* reverse */

View File

@@ -7962,7 +7962,7 @@ sign_list_defined(sign_T *sp)
if (sp->sn_line_hl > 0) if (sp->sn_line_hl > 0)
{ {
MSG_PUTS(" linehl="); 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) if (p == NULL)
MSG_PUTS("NONE"); MSG_PUTS("NONE");
else else
@@ -7971,7 +7971,7 @@ sign_list_defined(sign_T *sp)
if (sp->sn_text_hl > 0) if (sp->sn_text_hl > 0)
{ {
MSG_PUTS(" texthl="); 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) if (p == NULL)
MSG_PUTS("NONE"); MSG_PUTS("NONE");
else else

View File

@@ -52,5 +52,6 @@ void highlight_gui_started(void);
int highlight_changed(void); int highlight_changed(void);
void set_context_in_highlight_cmd(expand_T *xp, char_u *arg); 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(expand_T *xp, int idx);
char_u *get_highlight_name_ext(expand_T *xp, int idx, int skip_cleared);
void free_highlight_fonts(void); void free_highlight_fonts(void);
/* vim: set ft=c : */ /* vim: set ft=c : */

View File

@@ -9949,17 +9949,27 @@ highlight_list_two(int cnt, int attr)
|| defined(FEAT_SIGNS) || defined(PROTO) || defined(FEAT_SIGNS) || defined(PROTO)
/* /*
* Function given to ExpandGeneric() to obtain the list of group names. * Function given to ExpandGeneric() to obtain the list of group names.
* Also used for synIDattr() function.
*/ */
char_u * char_u *
get_highlight_name(expand_T *xp UNUSED, int idx) 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) if (idx < 0)
return NULL; return NULL;
/* Items are never removed from the table, skip the ones that were cleared.
*/ /* Items are never removed from the table, skip the ones that were
while (idx < highlight_ga.ga_len && HL_TABLE()[idx].sg_cleared) * cleared. */
++idx; if (skip_cleared && idx < highlight_ga.ga_len && HL_TABLE()[idx].sg_cleared)
return (char_u *)"";
#ifdef FEAT_CMDL_COMPL #ifdef FEAT_CMDL_COMPL
if (idx == highlight_ga.ga_len && include_none != 0) if (idx == highlight_ga.ga_len && include_none != 0)

View File

@@ -71,6 +71,14 @@ func Test_highlight_completion()
call assert_equal('"hi default', getreg(':')) call assert_equal('"hi default', getreg(':'))
call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
call assert_equal('"hi clear', getreg(':')) 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 endfunc
func Test_expr_completion() func Test_expr_completion()

View File

@@ -326,13 +326,16 @@ func Test_syn_clear()
syntax keyword Bar tar syntax keyword Bar tar
call assert_match('Foo', execute('syntax')) call assert_match('Foo', execute('syntax'))
call assert_match('Bar', execute('syntax')) call assert_match('Bar', execute('syntax'))
call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
syn clear Foo syn clear Foo
call assert_notmatch('Foo', execute('syntax')) call assert_notmatch('Foo', execute('syntax'))
call assert_match('Bar', execute('syntax')) call assert_match('Bar', execute('syntax'))
call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
syn clear Foo Bar syn clear Foo Bar
call assert_notmatch('Foo', execute('syntax')) call assert_notmatch('Foo', execute('syntax'))
call assert_notmatch('Bar', execute('syntax')) call assert_notmatch('Bar', execute('syntax'))
hi clear Foo hi clear Foo
call assert_equal('Foo', synIDattr(hlID("Foo"), "name"))
hi clear Bar hi clear Bar
endfunc endfunc

View File

@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
513,
/**/ /**/
512, 512,
/**/ /**/