1
0
forked from aniani/vim

patch 8.2.3228: cannot use a simple block for the :command argument

Problem:    Cannot use a simple block for the :command argument. (Maarten
            Tournoij)
Solution:   Recognize a simple {} block. (issue #8623)
This commit is contained in:
Bram Moolenaar
2021-07-27 21:17:32 +02:00
parent 53ba05b090
commit 5d7c2df536
6 changed files with 84 additions and 14 deletions

View File

@@ -115,6 +115,7 @@ static struct
};
#define UC_BUFFER 1 // -buffer: local to current buffer
#define UC_VIM9 2 // {} argument: Vim9 syntax.
/*
* Search for a user command that matches "eap->cmd".
@@ -872,10 +873,10 @@ uc_add_command(
replace_termcodes(rep, &rep_buf, 0, NULL);
if (rep_buf == NULL)
{
// Can't replace termcodes - try using the string as is
// can't replace termcodes - try using the string as is
rep_buf = vim_strsave(rep);
// Give up if out of memory
// give up if out of memory
if (rep_buf == NULL)
return FAIL;
}
@@ -955,6 +956,8 @@ uc_add_command(
cmd->uc_def = def;
cmd->uc_compl = compl;
cmd->uc_script_ctx = current_sctx;
if (flags & UC_VIM9)
cmd->uc_script_ctx.sc_version = SCRIPT_VERSION_VIM9;
#ifdef FEAT_EVAL
cmd->uc_script_ctx.sc_lnum += SOURCING_LNUM;
cmd->uc_compl_arg = compl_arg;
@@ -1037,8 +1040,46 @@ ex_command(exarg_T *eap)
(char_u *)_(e_complete_used_without_nargs), TRUE, TRUE);
}
else
{
char_u *tofree = NULL;
if (*p == '{' && ends_excmd2(eap->arg, skipwhite(p + 1))
&& eap->getline != NULL)
{
garray_T ga;
char_u *line = NULL;
ga_init2(&ga, sizeof(char_u *), 10);
if (ga_add_string(&ga, p) == FAIL)
return;
// Read lines between '{' and '}'. Does not support nesting or
// here-doc constructs.
//
for (;;)
{
vim_free(line);
if ((line = eap->getline(':', eap->cookie,
0, GETLINE_CONCAT_CONTBAR)) == NULL)
{
emsg(_(e_missing_rcurly));
break;
}
if (ga_add_string(&ga, line) == FAIL)
break;
if (*skipwhite(line) == '}')
break;
}
vim_free(line);
p = tofree = ga_concat_strings(&ga, "\n");
ga_clear_strings(&ga);
flags |= UC_VIM9;
}
uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg,
addr_type_arg, eap->forceit);
vim_free(tofree);
}
}
/*