vim-patch:8.0.0198

Problem:    Some syntax arguments take effect even after "if 0". (Taylor
            Venable)
Solution:   Properly skip the syntax statements.  Make "syn case" and "syn
            conceal" report the current state.  Fix that "syn clear" didn't
            reset the conceal flag.  Add tests for :syntax skipping properly.

de318c5c35
This commit is contained in:
dvejmz 2017-10-21 16:48:47 +01:00
parent a8ad6b4d51
commit b58c17f8df
2 changed files with 185 additions and 22 deletions

View File

@ -3019,12 +3019,19 @@ static void syn_cmd_conceal(exarg_T *eap, int syncing)
return; return;
next = skiptowhite(arg); next = skiptowhite(arg);
if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2) if (*arg == NUL) {
if (curwin->w_s->b_syn_conceal) {
MSG(_("syn conceal on"));
} else {
MSG(_("syn conceal off"));
}
} else if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2) {
curwin->w_s->b_syn_conceal = TRUE; curwin->w_s->b_syn_conceal = TRUE;
else if (STRNICMP(arg, "off", 3) == 0 && next - arg == 3) } else if (STRNICMP(arg, "off", 3) == 0 && next - arg == 3) {
curwin->w_s->b_syn_conceal = FALSE; curwin->w_s->b_syn_conceal = FALSE;
else } else {
EMSG2(_("E390: Illegal argument: %s"), arg); EMSG2(_("E390: Illegal argument: %s"), arg);
}
} }
/* /*
@ -3040,12 +3047,19 @@ static void syn_cmd_case(exarg_T *eap, int syncing)
return; return;
next = skiptowhite(arg); next = skiptowhite(arg);
if (STRNICMP(arg, "match", 5) == 0 && next - arg == 5) if (*arg == NUL) {
if (curwin->w_s->b_syn_ic) {
MSG(_("syntax case ignore"));
} else {
MSG(_("syntax case match"));
}
} else if (STRNICMP(arg, "match", 5) == 0 && next - arg == 5) {
curwin->w_s->b_syn_ic = FALSE; curwin->w_s->b_syn_ic = FALSE;
else if (STRNICMP(arg, "ignore", 6) == 0 && next - arg == 6) } else if (STRNICMP(arg, "ignore", 6) == 0 && next - arg == 6) {
curwin->w_s->b_syn_ic = TRUE; curwin->w_s->b_syn_ic = TRUE;
else } else {
EMSG2(_("E390: Illegal argument: %s"), arg); EMSG2(_("E390: Illegal argument: %s"), arg);
}
} }
/* /*
@ -3061,7 +3075,15 @@ static void syn_cmd_spell(exarg_T *eap, int syncing)
return; return;
next = skiptowhite(arg); next = skiptowhite(arg);
if (STRNICMP(arg, "toplevel", 8) == 0 && next - arg == 8) { if (*arg == NUL) {
if (curwin->w_s->b_syn_spell == SYNSPL_TOP) {
MSG(_("syntax spell toplevel"));
} else if (curwin->w_s->b_syn_spell == SYNSPL_NOTOP) {
MSG(_("syntax spell notoplevel"));
} else {
MSG(_("syntax spell default"));
}
} else if (STRNICMP(arg, "toplevel", 8) == 0 && next - arg == 8) {
curwin->w_s->b_syn_spell = SYNSPL_TOP; curwin->w_s->b_syn_spell = SYNSPL_TOP;
} else if (STRNICMP(arg, "notoplevel", 10) == 0 && next - arg == 10) { } else if (STRNICMP(arg, "notoplevel", 10) == 0 && next - arg == 10) {
curwin->w_s->b_syn_spell = SYNSPL_NOTOP; curwin->w_s->b_syn_spell = SYNSPL_NOTOP;
@ -3125,6 +3147,7 @@ void syntax_clear(synblock_T *block)
block->b_syn_ic = FALSE; /* Use case, by default */ block->b_syn_ic = FALSE; /* Use case, by default */
block->b_syn_spell = SYNSPL_DEFAULT; /* default spell checking */ block->b_syn_spell = SYNSPL_DEFAULT; /* default spell checking */
block->b_syn_containedin = FALSE; block->b_syn_containedin = FALSE;
block->b_syn_conceal = FALSE;
/* free the keywords */ /* free the keywords */
clear_keywtab(&block->b_keywtab); clear_keywtab(&block->b_keywtab);
@ -4004,7 +4027,8 @@ static char_u *
get_syn_options ( get_syn_options (
char_u *arg, /* next argument to be checked */ char_u *arg, /* next argument to be checked */
syn_opt_arg_T *opt, /* various things */ syn_opt_arg_T *opt, /* various things */
int *conceal_char int *conceal_char,
int skip /* TRUE if skipping over command */
) )
{ {
char_u *gname_start, *gname; char_u *gname_start, *gname;
@ -4080,13 +4104,13 @@ get_syn_options (
EMSG(_("E395: contains argument not accepted here")); EMSG(_("E395: contains argument not accepted here"));
return NULL; return NULL;
} }
if (get_id_list(&arg, 8, &opt->cont_list) == FAIL) if (get_id_list(&arg, 8, &opt->cont_list, skip) == FAIL)
return NULL; return NULL;
} else if (flagtab[fidx].argtype == 2) { } else if (flagtab[fidx].argtype == 2) {
if (get_id_list(&arg, 11, &opt->cont_in_list) == FAIL) if (get_id_list(&arg, 11, &opt->cont_in_list, skip) == FAIL)
return NULL; return NULL;
} else if (flagtab[fidx].argtype == 3) { } else if (flagtab[fidx].argtype == 3) {
if (get_id_list(&arg, 9, &opt->next_list) == FAIL) if (get_id_list(&arg, 9, &opt->next_list, skip) == FAIL)
return NULL; return NULL;
} else if (flagtab[fidx].argtype == 11 && arg[5] == '=') { } else if (flagtab[fidx].argtype == 11 && arg[5] == '=') {
/* cchar=? */ /* cchar=? */
@ -4257,7 +4281,11 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
rest = get_group_name(arg, &group_name_end); rest = get_group_name(arg, &group_name_end);
if (rest != NULL) { if (rest != NULL) {
syn_id = syn_check_group(arg, (int)(group_name_end - arg)); if (eap->skip) {
syn_id = -1;
} else {
syn_id = syn_check_group(arg, (int)(group_name_end - arg));
}
if (syn_id != 0) { if (syn_id != 0) {
// Allocate a buffer, for removing backslashes in the keyword. // Allocate a buffer, for removing backslashes in the keyword.
keyword_copy = xmalloc(STRLEN(rest) + 1); keyword_copy = xmalloc(STRLEN(rest) + 1);
@ -4276,7 +4304,7 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
cnt = 0; cnt = 0;
p = keyword_copy; p = keyword_copy;
for (; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) { for (; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) {
rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
if (rest == NULL || ends_excmd(*rest)) { if (rest == NULL || ends_excmd(*rest)) {
break; break;
} }
@ -4375,7 +4403,7 @@ syn_cmd_match (
syn_opt_arg.cont_list = NULL; syn_opt_arg.cont_list = NULL;
syn_opt_arg.cont_in_list = NULL; syn_opt_arg.cont_in_list = NULL;
syn_opt_arg.next_list = NULL; syn_opt_arg.next_list = NULL;
rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
/* get the pattern. */ /* get the pattern. */
init_syn_patterns(); init_syn_patterns();
@ -4385,7 +4413,7 @@ syn_cmd_match (
syn_opt_arg.flags |= HL_HAS_EOL; syn_opt_arg.flags |= HL_HAS_EOL;
/* Get options after the pattern */ /* Get options after the pattern */
rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
if (rest != NULL) { /* all arguments are valid */ if (rest != NULL) { /* all arguments are valid */
/* /*
@ -4502,7 +4530,7 @@ syn_cmd_region (
*/ */
while (rest != NULL && !ends_excmd(*rest)) { while (rest != NULL && !ends_excmd(*rest)) {
/* Check for option arguments */ /* Check for option arguments */
rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip);
if (rest == NULL || ends_excmd(*rest)) if (rest == NULL || ends_excmd(*rest))
break; break;
@ -4926,12 +4954,14 @@ static void syn_cmd_cluster(exarg_T *eap, int syncing)
break; break;
clstr_list = NULL; clstr_list = NULL;
if (get_id_list(&rest, opt_len, &clstr_list) == FAIL) { if (get_id_list(&rest, opt_len, &clstr_list, eap->skip) == FAIL) {
EMSG2(_(e_invarg2), rest); EMSG2(_(e_invarg2), rest);
break; break;
} }
syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list, if (scl_id >= 0) {
&clstr_list, list_op); syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list,
&clstr_list, list_op);
}
got_clstr = TRUE; got_clstr = TRUE;
} }
@ -5181,8 +5211,9 @@ static int
get_id_list ( get_id_list (
char_u **arg, char_u **arg,
int keylen, /* length of keyword */ int keylen, /* length of keyword */
short **list /* where to store the resulting list, if not short **list, /* where to store the resulting list, if not
NULL, the list is silently skipped! */ NULL, the list is silently skipped! */
int skip
) )
{ {
char_u *p = NULL; char_u *p = NULL;
@ -5251,7 +5282,9 @@ get_id_list (
id = SYNID_CONTAINED; id = SYNID_CONTAINED;
id += current_syn_inc_tag; id += current_syn_inc_tag;
} else if (name[1] == '@') { } else if (name[1] == '@') {
id = syn_check_cluster(name + 2, (int)(end - p - 1)); if (!skip) {
id = syn_check_cluster(name + 2, (int)(end - p - 1));
}
} else { } else {
/* /*
* Handle full group name. * Handle full group name.

View File

@ -157,4 +157,134 @@ func Test_syntax_completion()
call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_match('^"syn match Boolean Character ', @:) call assert_match('^"syn match Boolean Character ', @:)
endfunc endfunc
func Test_syntax_arg_skipped()
syn clear
syntax case ignore
if 0
syntax case match
endif
call assert_match('case ignore', execute('syntax case'))
syn keyword Foo foo
call assert_match('Foo', execute('syntax'))
syn clear
call assert_match('case match', execute('syntax case'))
call assert_notmatch('Foo', execute('syntax'))
if has('conceal')
syn clear
syntax conceal on
if 0
syntax conceal off
endif
call assert_match('conceal on', execute('syntax conceal'))
syn clear
call assert_match('conceal off', execute('syntax conceal'))
endif
syntax region Tar start=/</ end=/>/
if 0
syntax region NotTest start=/</ end=/>/ contains=@Spell
endif
call assert_match('Tar', execute('syntax'))
call assert_notmatch('NotTest', execute('syntax'))
call assert_notmatch('Spell', execute('syntax'))
hi Foo ctermfg=blue
let a = execute('hi Foo')
if 0
syntax rest
endif
call assert_equal(a, execute('hi Foo'))
set ft=tags
syn off
if 0
syntax enable
endif
call assert_match('No Syntax items defined', execute('syntax'))
syntax enable
call assert_match('tagComment', execute('syntax'))
set ft=
syn clear
if 0
syntax include @Spell nothing
endif
call assert_notmatch('Spell', execute('syntax'))
syn clear
syn iskeyword 48-57,$,_
call assert_match('48-57,$,_', execute('syntax iskeyword'))
if 0
syn clear
syn iskeyword clear
endif
call assert_match('48-57,$,_', execute('syntax iskeyword'))
syn iskeyword clear
call assert_match('not set', execute('syntax iskeyword'))
syn iskeyword 48-57,$,_
syn clear
call assert_match('not set', execute('syntax iskeyword'))
syn clear
syn keyword Foo foo
if 0
syn keyword NotAdded bar
endif
call assert_match('Foo', execute('syntax'))
call assert_notmatch('NotAdded', execute('highlight'))
syn clear
syn keyword Foo foo
call assert_match('Foo', execute('syntax'))
call assert_match('Foo', execute('syntax list'))
call assert_notmatch('Foo', execute('if 0 | syntax | endif'))
call assert_notmatch('Foo', execute('if 0 | syntax list | endif'))
syn clear
syn match Fopi /asdf/
if 0
syn match Fopx /asdf/
endif
call assert_match('Fopi', execute('syntax'))
call assert_notmatch('Fopx', execute('syntax'))
syn clear
syn spell toplevel
call assert_match('spell toplevel', execute('syntax spell'))
if 0
syn spell notoplevel
endif
call assert_match('spell toplevel', execute('syntax spell'))
syn spell notoplevel
call assert_match('spell notoplevel', execute('syntax spell'))
syn spell default
call assert_match('spell default', execute('syntax spell'))
syn clear
if 0
syntax cluster Spell
endif
call assert_notmatch('Spell', execute('syntax'))
syn clear
syn keyword Foo foo
syn sync ccomment
syn sync maxlines=5
if 0
syn sync maxlines=11
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
if 0
syn sync ccomment
endif
call assert_notmatch('on C-style comments', execute('syntax sync'))
syn clear
endfunc