# HG changeset patch # User Bram Moolenaar # Date 1587415504 -7200 # Node ID 513c62184ed817b770d2c31926dfb7381319e415 # Parent bd021eb62e73f1f6bc0762477e0f64d98b004875 patch 8.2.0613: Vim9: no check for space before #comment Commit: https://github.com/vim/vim/commit/1966c248814d5195edcd1208ed0e51e664a61283 Author: Bram Moolenaar Date: Mon Apr 20 22:42:32 2020 +0200 patch 8.2.0613: Vim9: no check for space before #comment Problem: Vim9: no check for space before #comment. Solution: Add space checks. diff --git a/runtime/lang/menu_de_de.latin1.vim b/runtime/lang/menu_de_de.latin1.vim --- a/runtime/lang/menu_de_de.latin1.vim +++ b/runtime/lang/menu_de_de.latin1.vim @@ -188,7 +188,7 @@ menutrans Set\ '&filetype'\ too Auch\ menutrans &Off &Aus menutrans &Manual &Manuell menutrans A&utomatic A&utomatisch -menutrans on/off\ for\ &This\ file An/Aus (diese\ &Datei) +menutrans on/off\ for\ &This\ file An/Aus\ (diese\ &Datei) menutrans Co&lor\ test Test\ der\ Farben menutrans &Highlight\ test Test\ der\ Un&terstreichungen menutrans &Convert\ to\ HTML Konvertieren\ nach\ &HTML diff --git a/src/highlight.c b/src/highlight.c --- a/src/highlight.c +++ b/src/highlight.c @@ -694,7 +694,7 @@ do_highlight( /* * ":highlight {group-name}": list highlighting for one group. */ - if (!doclear && !dolink && ends_excmd(*linep)) + if (!doclear && !dolink && ends_excmd2(line, linep)) { id = syn_namen2id(line, (int)(name_end - line)); if (id == 0) @@ -720,14 +720,14 @@ do_highlight( to_start = skipwhite(from_end); to_end = skiptowhite(to_start); - if (ends_excmd(*from_start) || ends_excmd(*to_start)) + if (ends_excmd2(line, from_start) || ends_excmd2(line, to_start)) { semsg(_("E412: Not enough arguments: \":highlight link %s\""), from_start); return; } - if (!ends_excmd(*skipwhite(to_end))) + if (!ends_excmd2(line, skipwhite(to_end))) { semsg(_("E413: Too many arguments: \":highlight link %s\""), from_start); return; @@ -781,8 +781,7 @@ do_highlight( /* * ":highlight clear [group]" command. */ - line = linep; - if (ends_excmd(*line)) + if (ends_excmd2(line, linep)) { #ifdef FEAT_GUI // First, we do not destroy the old values, but allocate the new @@ -826,7 +825,7 @@ do_highlight( // It is now Ok to clear out the old data. #endif #ifdef FEAT_EVAL - do_unlet((char_u *)"colors_name", TRUE); + do_unlet((char_u *)"g:colors_name", TRUE); #endif restore_cterm_colors(); @@ -845,6 +844,7 @@ do_highlight( redraw_later_clear(); return; } + line = linep; name_end = skiptowhite(line); linep = skipwhite(name_end); } @@ -888,7 +888,7 @@ do_highlight( } if (!doclear) - while (!ends_excmd(*linep)) + while (!ends_excmd2(line, linep)) { key_start = linep; if (*linep == '=') @@ -4946,10 +4946,11 @@ ex_match(exarg_T *eap) if (!eap->skip) match_delete(curwin, id, FALSE); - if (ends_excmd(*eap->arg)) + if (ends_excmd2(eap->cmd, eap->arg)) end = eap->arg; else if ((STRNICMP(eap->arg, "none", 4) == 0 - && (VIM_ISWHITE(eap->arg[4]) || ends_excmd(eap->arg[4])))) + && (VIM_ISWHITE(eap->arg[4]) + || ends_excmd2(eap->arg, eap->arg + 4)))) end = eap->arg + 4; else { @@ -4967,7 +4968,7 @@ ex_match(exarg_T *eap) end = skip_regexp(p + 1, *p, TRUE); if (!eap->skip) { - if (*end != NUL && !ends_excmd(*skipwhite(end + 1))) + if (*end != NUL && !ends_excmd2(end, skipwhite(end + 1))) { vim_free(g); eap->errmsg = e_trailing; diff --git a/src/menu.c b/src/menu.c --- a/src/menu.c +++ b/src/menu.c @@ -2680,7 +2680,7 @@ ex_menutranslate(exarg_T *eap UNUSED) /* * ":menutrans clear": clear all translations. */ - if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) + if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd2(arg, skipwhite(arg + 5))) { tp = (menutrans_T *)menutrans_ga.ga_data; for (i = 0; i < menutrans_ga.ga_len; ++i) @@ -2703,7 +2703,9 @@ ex_menutranslate(exarg_T *eap UNUSED) to = skipwhite(arg); *arg = NUL; arg = menu_skip_part(to); - if (arg == to) + if (arg == to || ends_excmd2(eap->arg, from) + || ends_excmd2(eap->arg, to) + || !ends_excmd2(eap->arg, skipwhite(arg))) emsg(_(e_invarg)); else { diff --git a/src/syntax.c b/src/syntax.c --- a/src/syntax.c +++ b/src/syntax.c @@ -3632,7 +3632,7 @@ syn_cmd_clear(exarg_T *eap, int syncing) if (curwin->w_s->b_syn_topgrp != 0) return; - if (ends_excmd(*arg)) + if (ends_excmd2(eap->cmd, arg)) { /* * No argument: Clear all syntax items. @@ -3652,7 +3652,7 @@ syn_cmd_clear(exarg_T *eap, int syncing) /* * Clear the group IDs that are in the argument. */ - while (!ends_excmd(*arg)) + while (!ends_excmd2(eap->cmd, arg)) { arg_end = skiptowhite(arg); if (*arg == '@') @@ -3843,7 +3843,7 @@ syn_cmd_list( } else msg_puts_title(_("\n--- Syntax items ---")); - if (ends_excmd(*arg)) + if (ends_excmd2(eap->cmd, arg)) { /* * No argument: List all group IDs and all syntax clusters. @@ -3858,7 +3858,7 @@ syn_cmd_list( /* * List the group IDs and syntax clusters that are in the argument. */ - while (!ends_excmd(*arg) && !got_int) + while (!ends_excmd2(eap->cmd, arg) && !got_int) { arg_end = skiptowhite(arg); if (*arg == '@') @@ -4463,11 +4463,12 @@ get_group_name( */ static char_u * get_syn_options( - char_u *arg, // next argument to be checked + char_u *start, // next argument to be checked syn_opt_arg_T *opt, // various things int *conceal_char UNUSED, int skip) // TRUE if skipping over command { + char_u *arg = start; char_u *gname_start, *gname; int syn_id; int len; @@ -4528,7 +4529,7 @@ get_syn_options( if (p[i] == NUL && (VIM_ISWHITE(arg[len]) || (flagtab[fidx].argtype > 0 ? arg[len] == '=' - : ends_excmd(arg[len])))) + : ends_excmd2(start, arg + len)))) { if (opt->keyword && (flagtab[fidx].flags == HL_DISPLAY @@ -4790,11 +4791,12 @@ syn_cmd_keyword(exarg_T *eap, int syncin */ cnt = 0; p = keyword_copy; - for ( ; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) + for ( ; rest != NULL && !ends_excmd2(eap->arg, rest); + rest = skipwhite(rest)) { rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); - if (rest == NULL || ends_excmd(*rest)) + if (rest == NULL || ends_excmd2(eap->arg, rest)) break; // Copy the keyword, removing backslashes, and add a NUL. while (*rest != NUL && !VIM_ISWHITE(*rest)) @@ -4892,6 +4894,7 @@ syn_cmd_match( syn_opt_arg_T syn_opt_arg; int sync_idx = 0; int conceal_char = NUL; + int orig_called_emsg = called_emsg; // Isolate the group name, check for validity rest = get_group_name(arg, &group_name_end); @@ -4922,7 +4925,7 @@ syn_cmd_match( * Check for trailing command and illegal trailing arguments. */ eap->nextcmd = check_nextcmd(rest); - if (!ends_excmd(*rest) || eap->skip) + if (!ends_excmd2(eap->cmd, rest) || eap->skip) rest = NULL; else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL && (syn_id = syn_check_group(arg, @@ -4974,7 +4977,7 @@ syn_cmd_match( vim_free(syn_opt_arg.cont_in_list); vim_free(syn_opt_arg.next_list); - if (rest == NULL) + if (rest == NULL && called_emsg == orig_called_emsg) semsg(_(e_invarg2), arg); } @@ -5037,11 +5040,11 @@ syn_cmd_region( /* * get the options, patterns and matchgroup. */ - while (rest != NULL && !ends_excmd(*rest)) + while (rest != NULL && !ends_excmd2(eap->cmd, rest)) { // Check for option arguments rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); - if (rest == NULL || ends_excmd(*rest)) + if (rest == NULL || ends_excmd2(eap->cmd, rest)) break; // must be a pattern or matchgroup then @@ -5570,7 +5573,7 @@ syn_cmd_cluster(exarg_T *eap, int syncin if (!got_clstr) emsg(_("E400: No cluster specified")); - if (rest == NULL || !ends_excmd(*rest)) + if (rest == NULL || !ends_excmd2(eap->cmd, rest)) semsg(_(e_invarg2), arg); } @@ -5680,7 +5683,7 @@ get_syn_pattern(char_u *arg, synpat_T *c } } while (idx >= 0); - if (!ends_excmd(*end) && !VIM_ISWHITE(*end)) + if (!ends_excmd2(arg, end) && !VIM_ISWHITE(*end)) { semsg(_("E402: Garbage after pattern: %s"), arg); return NULL; @@ -5703,13 +5706,13 @@ syn_cmd_sync(exarg_T *eap, int syncing U long n; char_u *cpo_save; - if (ends_excmd(*arg_start)) + if (ends_excmd2(eap->cmd, arg_start)) { syn_cmd_list(eap, TRUE); return; } - while (!ends_excmd(*arg_start)) + while (!ends_excmd2(eap->cmd, arg_start)) { arg_end = skiptowhite(arg_start); next_arg = skipwhite(arg_end); @@ -5719,7 +5722,7 @@ syn_cmd_sync(exarg_T *eap, int syncing U { if (!eap->skip) curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; - if (!ends_excmd(*next_arg)) + if (!ends_excmd2(eap->cmd, next_arg)) { arg_end = skiptowhite(next_arg); if (!eap->skip) @@ -5888,7 +5891,7 @@ get_id_list( break; } p = skipwhite(p + 1); - if (ends_excmd(*p)) + if (ends_excmd2(*arg, p)) { semsg(_("E406: Empty argument: %s"), *arg); break; @@ -5898,7 +5901,7 @@ get_id_list( * parse the arguments after "contains" */ count = 0; - while (!ends_excmd(*p)) + while (!ends_excmd2(*arg, p)) { for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end) ; diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -1210,6 +1210,176 @@ def Test_vim9_comment() 'vim9script', 'hi# comment', ], 'E416:') + CheckScriptSuccess([ + 'vim9script', + 'hi Search # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'hi Search# comment', + ], 'E416:') + CheckScriptSuccess([ + 'vim9script', + 'hi link This Search # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'hi link This That# comment', + ], 'E413:') + CheckScriptSuccess([ + 'vim9script', + 'hi clear This # comment', + 'hi clear # comment', + ]) + " not tested, because it doesn't give an error but a warning: + " hi clear This# comment', + CheckScriptFailure([ + 'vim9script', + 'hi clear# comment', + ], 'E416:') + + CheckScriptSuccess([ + 'vim9script', + 'hi Group term=bold', + 'match Group /todo/ # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'hi Group term=bold', + 'match Group /todo/# comment', + ], 'E488:') + CheckScriptSuccess([ + 'vim9script', + 'match # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'match# comment', + ], 'E475:') + CheckScriptSuccess([ + 'vim9script', + 'match none # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'match none# comment', + ], 'E475:') + + CheckScriptSuccess([ + 'vim9script', + 'menutrans clear # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'menutrans clear# comment text', + ], 'E474:') + + CheckScriptSuccess([ + 'vim9script', + 'syntax clear # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax clear# comment text', + ], 'E28:') + CheckScriptSuccess([ + 'vim9script', + 'syntax keyword Word some', + 'syntax clear Word # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax keyword Word some', + 'syntax clear Word# comment text', + ], 'E28:') + + CheckScriptSuccess([ + 'vim9script', + 'syntax list # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax list# comment text', + ], 'E28:') + + CheckScriptSuccess([ + 'vim9script', + 'syntax match Word /pat/ oneline # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax match Word /pat/ oneline# comment', + ], 'E475:') + + CheckScriptSuccess([ + 'vim9script', + 'syntax keyword Word word # comm[ent', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax keyword Word word# comm[ent', + ], 'E789:') + + CheckScriptSuccess([ + 'vim9script', + 'syntax match Word /pat/ # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax match Word /pat/# comment', + ], 'E402:') + + CheckScriptSuccess([ + 'vim9script', + 'syntax match Word /pat/ contains=Something # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax match Word /pat/ contains=Something# comment', + ], 'E475:') + CheckScriptFailure([ + 'vim9script', + 'syntax match Word /pat/ contains= # comment', + ], 'E406:') + CheckScriptFailure([ + 'vim9script', + 'syntax match Word /pat/ contains=# comment', + ], 'E475:') + + CheckScriptSuccess([ + 'vim9script', + 'syntax region Word start=/pat/ end=/pat/ # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax region Word start=/pat/ end=/pat/# comment', + ], 'E475:') + + CheckScriptSuccess([ + 'vim9script', + 'syntax sync # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax sync# comment', + ], 'E404:') + CheckScriptSuccess([ + 'vim9script', + 'syntax sync ccomment # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax sync ccomment# comment', + ], 'E404:') + + CheckScriptSuccess([ + 'vim9script', + 'syntax cluster Some contains=Word # comment', + ]) + CheckScriptFailure([ + 'vim9script', + 'syntax cluster Some contains=Word# comment', + ], 'E475:') enddef def Test_vim9_comment_gui() diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 613, +/**/ 612, /**/ 611,