mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Problem: Vim9: # comment not recognized after :vim9script. Solution: Check script type. Make comment after ":echo" work. And in several other places.
This commit is contained in:
@@ -6061,7 +6061,7 @@ ex_echo(exarg_T *eap)
|
|||||||
|
|
||||||
if (eap->skip)
|
if (eap->skip)
|
||||||
++emsg_skip;
|
++emsg_skip;
|
||||||
while (*arg != NUL && *arg != '|' && *arg != '\n' && !got_int)
|
while ((!ends_excmd2(eap->cmd, arg) || *arg == '"') && !got_int)
|
||||||
{
|
{
|
||||||
// If eval1() causes an error message the text from the command may
|
// If eval1() causes an error message the text from the command may
|
||||||
// still need to be cleared. E.g., "echo 22,44".
|
// still need to be cleared. E.g., "echo 22,44".
|
||||||
|
@@ -1835,7 +1835,10 @@ do_one_cmd(
|
|||||||
* If we find a '|' or '\n' we set ea.nextcmd.
|
* If we find a '|' or '\n' we set ea.nextcmd.
|
||||||
*/
|
*/
|
||||||
if (*ea.cmd == NUL || *ea.cmd == '"'
|
if (*ea.cmd == NUL || *ea.cmd == '"'
|
||||||
|| (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL)
|
#ifdef FEAT_EVAL
|
||||||
|
|| (*ea.cmd == '#' && !starts_with_colon && in_vim9script())
|
||||||
|
#endif
|
||||||
|
|| (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* strange vi behaviour:
|
* strange vi behaviour:
|
||||||
@@ -4761,12 +4764,31 @@ ex_blast(exarg_T *eap)
|
|||||||
do_cmdline_cmd(eap->do_ecmd_cmd);
|
do_cmdline_cmd(eap->do_ecmd_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if "c" ends an Ex command.
|
||||||
|
* In Vim9 script does not check for white space before #.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
ends_excmd(int c)
|
ends_excmd(int c)
|
||||||
{
|
{
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
if (c == '#')
|
if (c == '#')
|
||||||
// TODO: should check for preceding white space
|
return in_vim9script();
|
||||||
|
#endif
|
||||||
|
return (c == NUL || c == '|' || c == '"' || c == '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Like ends_excmd() but checks that a # in Vim9 script either has "cmd" equal
|
||||||
|
* to "cmd_start" or has a white space character before it.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ends_excmd2(char_u *cmd_start, char_u *cmd)
|
||||||
|
{
|
||||||
|
int c = *cmd;
|
||||||
|
|
||||||
|
#ifdef FEAT_EVAL
|
||||||
|
if (c == '#' && (cmd == cmd_start || VIM_ISWHITE(cmd[-1])))
|
||||||
return in_vim9script();
|
return in_vim9script();
|
||||||
#endif
|
#endif
|
||||||
return (c == NUL || c == '|' || c == '"' || c == '\n');
|
return (c == NUL || c == '|' || c == '"' || c == '\n');
|
||||||
|
@@ -19,6 +19,7 @@ void separate_nextcmd(exarg_T *eap);
|
|||||||
char_u *skip_cmd_arg(char_u *p, int rembs);
|
char_u *skip_cmd_arg(char_u *p, int rembs);
|
||||||
int get_bad_opt(char_u *p, exarg_T *eap);
|
int get_bad_opt(char_u *p, exarg_T *eap);
|
||||||
int ends_excmd(int c);
|
int ends_excmd(int c);
|
||||||
|
int ends_excmd2(char_u *before, char_u *cmd);
|
||||||
char_u *find_nextcmd(char_u *p);
|
char_u *find_nextcmd(char_u *p);
|
||||||
char_u *check_nextcmd(char_u *p);
|
char_u *check_nextcmd(char_u *p);
|
||||||
char_u *get_command_name(expand_T *xp, int idx);
|
char_u *get_command_name(expand_T *xp, int idx);
|
||||||
|
@@ -10,11 +10,17 @@ func CheckDefFailure(lines, error)
|
|||||||
call delete('Xdef')
|
call delete('Xdef')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func CheckScriptFailure(lines, error)
|
def CheckScriptFailure(lines: list<string>, error: string)
|
||||||
call writefile(a:lines, 'Xdef')
|
writefile(lines, 'Xdef')
|
||||||
call assert_fails('so Xdef', a:error, a:lines)
|
assert_fails('so Xdef', error, lines)
|
||||||
call delete('Xdef')
|
delete('Xdef')
|
||||||
endfunc
|
enddef
|
||||||
|
|
||||||
|
def CheckScriptSuccess(lines: list<string>)
|
||||||
|
writefile(lines, 'Xdef')
|
||||||
|
so Xdef
|
||||||
|
delete('Xdef')
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_syntax()
|
def Test_syntax()
|
||||||
let var = 234
|
let var = 234
|
||||||
@@ -269,15 +275,15 @@ enddef
|
|||||||
|
|
||||||
def Test_try_catch()
|
def Test_try_catch()
|
||||||
let l = []
|
let l = []
|
||||||
try
|
try # comment
|
||||||
add(l, '1')
|
add(l, '1')
|
||||||
throw 'wrong'
|
throw 'wrong'
|
||||||
add(l, '2')
|
add(l, '2')
|
||||||
catch
|
catch # comment
|
||||||
add(l, v:exception)
|
add(l, v:exception)
|
||||||
finally
|
finally # comment
|
||||||
add(l, '3')
|
add(l, '3')
|
||||||
endtry
|
endtry # comment
|
||||||
assert_equal(['1', 'wrong', '3'], l)
|
assert_equal(['1', 'wrong', '3'], l)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
@@ -1003,6 +1009,58 @@ def Test_automatic_line_continuation()
|
|||||||
)
|
)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_vim9_comment()
|
||||||
|
CheckScriptSuccess([
|
||||||
|
'vim9script',
|
||||||
|
'# something',
|
||||||
|
])
|
||||||
|
CheckScriptFailure([
|
||||||
|
'vim9script',
|
||||||
|
':# something',
|
||||||
|
], 'E488:')
|
||||||
|
CheckScriptFailure([
|
||||||
|
'# something',
|
||||||
|
], 'E488:')
|
||||||
|
CheckScriptFailure([
|
||||||
|
':# something',
|
||||||
|
], 'E488:')
|
||||||
|
|
||||||
|
CheckScriptSuccess([
|
||||||
|
'vim9script',
|
||||||
|
'echo "yes" # something',
|
||||||
|
])
|
||||||
|
CheckScriptFailure([
|
||||||
|
'vim9script',
|
||||||
|
'echo "yes"# something',
|
||||||
|
], 'E121:')
|
||||||
|
CheckScriptFailure([
|
||||||
|
'vim9script',
|
||||||
|
'echo# something',
|
||||||
|
], 'E121:')
|
||||||
|
CheckScriptFailure([
|
||||||
|
'echo "yes" # something',
|
||||||
|
], 'E121:')
|
||||||
|
|
||||||
|
CheckDefFailure([
|
||||||
|
'try# comment',
|
||||||
|
'echo "yes"',
|
||||||
|
'catch',
|
||||||
|
'endtry',
|
||||||
|
], 'E488:')
|
||||||
|
CheckDefFailure([
|
||||||
|
'try',
|
||||||
|
'echo "yes"',
|
||||||
|
'catch# comment',
|
||||||
|
'endtry',
|
||||||
|
], 'E488:')
|
||||||
|
CheckDefFailure([
|
||||||
|
'try',
|
||||||
|
'echo "yes"',
|
||||||
|
'catch',
|
||||||
|
'endtry# comment',
|
||||||
|
], 'E488:')
|
||||||
|
enddef
|
||||||
|
|
||||||
" Keep this last, it messes up highlighting.
|
" Keep this last, it messes up highlighting.
|
||||||
def Test_substitute_cmd()
|
def Test_substitute_cmd()
|
||||||
new
|
new
|
||||||
|
@@ -746,6 +746,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 */
|
||||||
|
/**/
|
||||||
|
585,
|
||||||
/**/
|
/**/
|
||||||
584,
|
584,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -108,6 +108,7 @@ typedef struct {
|
|||||||
struct cctx_S {
|
struct cctx_S {
|
||||||
ufunc_T *ctx_ufunc; // current function
|
ufunc_T *ctx_ufunc; // current function
|
||||||
int ctx_lnum; // line number in current function
|
int ctx_lnum; // line number in current function
|
||||||
|
char_u *ctx_line_start; // start of current line or NULL
|
||||||
garray_T ctx_instr; // generated instructions
|
garray_T ctx_instr; // generated instructions
|
||||||
|
|
||||||
garray_T ctx_locals; // currently visible local variables
|
garray_T ctx_locals; // currently visible local variables
|
||||||
@@ -2055,14 +2056,18 @@ free_imported(cctx_T *cctx)
|
|||||||
static char_u *
|
static char_u *
|
||||||
next_line_from_context(cctx_T *cctx)
|
next_line_from_context(cctx_T *cctx)
|
||||||
{
|
{
|
||||||
char_u *line = NULL;
|
char_u *line;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
++cctx->ctx_lnum;
|
++cctx->ctx_lnum;
|
||||||
if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len)
|
if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len)
|
||||||
|
{
|
||||||
|
line = NULL;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
|
line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
|
||||||
|
cctx->ctx_line_start = line;
|
||||||
SOURCING_LNUM = cctx->ctx_ufunc->uf_script_ctx.sc_lnum
|
SOURCING_LNUM = cctx->ctx_ufunc->uf_script_ctx.sc_lnum
|
||||||
+ cctx->ctx_lnum + 1;
|
+ cctx->ctx_lnum + 1;
|
||||||
} while (line == NULL || *skipwhite(line) == NUL);
|
} while (line == NULL || *skipwhite(line) == NUL);
|
||||||
@@ -5448,7 +5453,7 @@ compile_catch(char_u *arg, cctx_T *cctx UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
p = skipwhite(arg);
|
p = skipwhite(arg);
|
||||||
if (ends_excmd(*p))
|
if (ends_excmd2(arg, p))
|
||||||
{
|
{
|
||||||
scope->se_u.se_try.ts_caught_all = TRUE;
|
scope->se_u.se_try.ts_caught_all = TRUE;
|
||||||
scope->se_u.se_try.ts_catch_label = 0;
|
scope->se_u.se_try.ts_catch_label = 0;
|
||||||
@@ -5782,7 +5787,9 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
|
|||||||
if (line != NULL && *line == '|')
|
if (line != NULL && *line == '|')
|
||||||
// the line continues after a '|'
|
// the line continues after a '|'
|
||||||
++line;
|
++line;
|
||||||
else if (line != NULL && *line != NUL)
|
else if (line != NULL && *line != NUL
|
||||||
|
&& !(*line == '#' && (line == cctx.ctx_line_start
|
||||||
|
|| VIM_ISWHITE(line[-1]))))
|
||||||
{
|
{
|
||||||
semsg(_("E488: Trailing characters: %s"), line);
|
semsg(_("E488: Trailing characters: %s"), line);
|
||||||
goto erret;
|
goto erret;
|
||||||
|
Reference in New Issue
Block a user