summaryrefslogtreecommitdiffstats
path: root/src/autocmd.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-08-01 14:52:32 +0200
committerBram Moolenaar <Bram@vim.org>2021-08-01 14:52:32 +0200
commit73b8b0ae3acac220e823076f8ca1c14524ed96dd (patch)
tree0b9157946ccfc3a56e621e7e271c97207817a801 /src/autocmd.c
parent6db660bed9ed5063f8c6e0fadeef32d44bbd017d (diff)
patch 8.2.3268: cannot use a block with :autocmd like with :commandv8.2.3268
Problem: Cannot use a block with :autocmd like with :command. Solution: Add support for a {} block after :autocmd. (closes #8620)
Diffstat (limited to 'src/autocmd.c')
-rw-r--r--src/autocmd.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index 4c12e729e0..83e990df01 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -258,7 +258,7 @@ static int au_need_clean = FALSE; // need to delete marked patterns
static char_u *event_nr2name(event_T event);
static int au_get_grouparg(char_u **argp);
-static int do_autocmd_event(event_T event, char_u *pat, int once, int nested, char_u *cmd, int forceit, int group);
+static int do_autocmd_event(event_T event, char_u *pat, int once, int nested, char_u *cmd, int forceit, int group, int flags);
static int apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, int force, int group, buf_T *buf, exarg_T *eap);
static void auto_next_pat(AutoPatCmd *apc, int stop_at_last);
static int au_find_group(char_u *name);
@@ -615,7 +615,7 @@ free_all_autocmds(void)
for (current_augroup = -1; current_augroup < augroups.ga_len;
++current_augroup)
- do_autocmd((char_u *)"", TRUE);
+ do_autocmd(NULL, (char_u *)"", TRUE);
for (i = 0; i < augroups.ga_len; ++i)
{
@@ -823,20 +823,23 @@ au_event_restore(char_u *old_ei)
* :autocmd * *.c show all autocommands for *.c files.
*
* Mostly a {group} argument can optionally appear before <event>.
+ * "eap" can be NULL.
*/
void
-do_autocmd(char_u *arg_in, int forceit)
+do_autocmd(exarg_T *eap, char_u *arg_in, int forceit)
{
char_u *arg = arg_in;
char_u *pat;
char_u *envpat = NULL;
char_u *cmd;
+ int cmd_need_free = FALSE;
event_T event;
- int need_free = FALSE;
+ char_u *tofree = NULL;
int nested = FALSE;
int once = FALSE;
int group;
int i;
+ int flags = 0;
if (*arg == '|')
{
@@ -935,10 +938,14 @@ do_autocmd(char_u *arg_in, int forceit)
*/
if (*cmd != NUL)
{
+ if (eap != NULL)
+ // Read a {} block if it follows.
+ cmd = may_get_cmd_block(eap, cmd, &tofree, &flags);
+
cmd = expand_sfile(cmd);
if (cmd == NULL) // some error
return;
- need_free = TRUE;
+ cmd_need_free = TRUE;
}
}
@@ -962,19 +969,20 @@ do_autocmd(char_u *arg_in, int forceit)
for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
event = (event_T)((int)event + 1))
if (do_autocmd_event(event, pat,
- once, nested, cmd, forceit, group) == FAIL)
+ once, nested, cmd, forceit, group, flags) == FAIL)
break;
}
else
{
while (*arg && *arg != '|' && !VIM_ISWHITE(*arg))
if (do_autocmd_event(event_name2nr(arg, &arg), pat,
- once, nested, cmd, forceit, group) == FAIL)
+ once, nested, cmd, forceit, group, flags) == FAIL)
break;
}
- if (need_free)
+ if (cmd_need_free)
vim_free(cmd);
+ vim_free(tofree);
vim_free(envpat);
}
@@ -1024,7 +1032,8 @@ do_autocmd_event(
int nested,
char_u *cmd,
int forceit,
- int group)
+ int group,
+ int flags)
{
AutoPat *ap;
AutoPat **prev_ap;
@@ -1251,6 +1260,8 @@ do_autocmd_event(
return FAIL;
ac->cmd = vim_strsave(cmd);
ac->script_ctx = current_sctx;
+ if (flags & UC_VIM9)
+ ac->script_ctx.sc_version = SCRIPT_VERSION_VIM9;
#ifdef FEAT_EVAL
ac->script_ctx.sc_lnum += SOURCING_LNUM;
#endif