summaryrefslogtreecommitdiff
path: root/src/usercmd.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-07-27 21:17:32 +0200
committerBram Moolenaar <Bram@vim.org>2021-07-27 21:17:32 +0200
commit5d7c2df536c17db4a9c61e0760bdcf78d0db7330 (patch)
tree74a24ee4dec7bed9866c328da2bf3ac00460ef77 /src/usercmd.c
parent53ba05b09075f14227f9be831a22ed16f7cc26b2 (diff)
downloadvim-git-5d7c2df536c17db4a9c61e0760bdcf78d0db7330.tar.gz
patch 8.2.3228: cannot use a simple block for the :command argumentv8.2.3228
Problem: Cannot use a simple block for the :command argument. (Maarten Tournoij) Solution: Recognize a simple {} block. (issue #8623)
Diffstat (limited to 'src/usercmd.c')
-rw-r--r--src/usercmd.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/usercmd.c b/src/usercmd.c
index 42b9014f3..09e7b26b3 100644
--- a/src/usercmd.c
+++ b/src/usercmd.c
@@ -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);
+ }
}
/*