From c96272e30e2b81e5e0c8418f09d9db4e2fcd5d73 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 26 Mar 2017 13:50:09 +0200 Subject: [PATCH 1/2] 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. --- src/evalfunc.c | 2 +- src/ex_cmds.c | 4 ++-- src/proto/syntax.pro | 1 + src/syntax.c | 20 +++++++++++++++----- src/testdir/test_cmdline.vim | 8 ++++++++ src/testdir/test_syntax.vim | 3 +++ src/version.c | 2 ++ 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/evalfunc.c b/src/evalfunc.c index 8869810dfa..42773e1b8d 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -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 */ diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 0c4dffbc66..6940e55277 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -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 diff --git a/src/proto/syntax.pro b/src/proto/syntax.pro index 64235b00bc..aae187fe68 100644 --- a/src/proto/syntax.pro +++ b/src/proto/syntax.pro @@ -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 : */ diff --git a/src/syntax.c b/src/syntax.c index a8942e797c..42a0bdc3f9 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -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) diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim index 98a4337780..77c9170492 100644 --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -71,6 +71,14 @@ func Test_highlight_completion() call assert_equal('"hi default', getreg(':')) call feedkeys(":hi c\\\"\", '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() diff --git a/src/testdir/test_syntax.vim b/src/testdir/test_syntax.vim index 8a00f992f2..9ebe3f13e8 100644 --- a/src/testdir/test_syntax.vim +++ b/src/testdir/test_syntax.vim @@ -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 diff --git a/src/version.c b/src/version.c index 3ebe8a6f9d..28f3c59d11 100644 --- a/src/version.c +++ b/src/version.c @@ -764,6 +764,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 513, /**/ 512, /**/ From 980128c369451450743bdb90a67588fa72ec4b07 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 26 Mar 2017 21:46:28 +0200 Subject: [PATCH 2/2] patch 8.0.0514: script for creating cmdidxs can be improved Problem: Script for creating cmdidxs can be improved. Solution: Count skipped lines instead of collecting the lines. Add "const". (Dominique Pelle, closes #1594) --- src/create_cmdidxs.pl | 11 ++++++----- src/ex_docmd.c | 2 +- src/version.c | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/create_cmdidxs.pl b/src/create_cmdidxs.pl index ff8dcc3f4b..d39ac1614a 100644 --- a/src/create_cmdidxs.pl +++ b/src/create_cmdidxs.pl @@ -9,15 +9,17 @@ # Script should be run every time new Ex commands are added in Vim, # from the src/vim directory, since it reads commands from "ex_cmds.h". +use strict; + # Find the list of Vim commands from cmdnames[] table in ex_cmds.h my @cmds; -my @skipped; +my $skipped_cmds; open(IN, "< ex_cmds.h") or die "can't open ex_cmds.h: $!\n"; while () { if (/^EX\(CMD_\S*,\s*"([a-z][^"]*)"/) { - push (@cmds, $1); + push @cmds, $1; } elsif (/^EX\(CMD_/) { - push (@skipped, $1); + ++$skipped_cmds; } } @@ -68,7 +70,6 @@ for my $c1 ('a' .. 'z') { } print "};\n", "\n", - "static int command_count = ", $#cmds + $#skipped + 2 , ";\n", + "static const int command_count = ", scalar(@cmds) + $skipped_cmds, ";\n", "\n", "/* End of automatically generated code by create_cmdidxs.pl */\n"; - diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 9782557c13..8755f0549b 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -566,7 +566,7 @@ static const unsigned char cmdidxs2[26][26] = /* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } }; -static int command_count = 539; +static const int command_count = 539; /* End of automatically generated code by create_cmdidxs.pl */ diff --git a/src/version.c b/src/version.c index 28f3c59d11..79c97f9b96 100644 --- a/src/version.c +++ b/src/version.c @@ -764,6 +764,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 514, /**/ 513, /**/