vim-patch:8.2.4749: <script> is not expanded in autocmd context

Problem:    <script> is not expanded in autocmd context.
Solution:   Add the context to the pattern struct. (closes vim/vim#10144)
            Rename AutoPatCmd to AutoPatCmd_T.
eca7c60d68

Omit AutoPatCmd -> AutoPatCmd_T rename as it is inconsistent.
Use `.sn_name` instead of `->sn_name` as v8.2.0154 hasn't been ported.
Omit acp_script_stx(), use member directly.
This commit is contained in:
zeertzjq
2022-08-23 12:20:37 +08:00
parent 7afc17dec1
commit d0b9fe2d5a
4 changed files with 65 additions and 39 deletions

View File

@@ -1811,16 +1811,15 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force
char *tail = path_tail(fname);
// Find first autocommand that matches
AutoPatCmd patcmd;
patcmd.curpat = first_autopat[(int)event];
patcmd.nextcmd = NULL;
patcmd.group = group;
patcmd.fname = fname;
patcmd.sfname = sfname;
patcmd.tail = tail;
patcmd.event = event;
patcmd.arg_bufnr = autocmd_bufnr;
patcmd.next = NULL;
AutoPatCmd patcmd = {
.curpat = first_autopat[(int)event],
.group = group,
.fname = fname,
.sfname = sfname,
.tail = tail,
.event = event,
.arg_bufnr = autocmd_bufnr,
};
auto_next_pat(&patcmd, false);
// found one, start executing the autocommands
@@ -1984,9 +1983,12 @@ void auto_next_pat(AutoPatCmd *apc, int stop_at_last)
AutoPat *ap;
AutoCmd *cp;
char *s;
char **const sourcing_namep = &SOURCING_NAME;
XFREE_CLEAR(*sourcing_namep);
estack_T *const entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1;
// Clear the exestack entry for this ETYPE_AUCMD entry.
XFREE_CLEAR(entry->es_name);
entry->es_info.aucmd = NULL;
for (ap = apc->curpat; ap != NULL && !got_int; ap = ap->next) {
apc->curpat = NULL;
@@ -2011,14 +2013,18 @@ void auto_next_pat(AutoPatCmd *apc, int stop_at_last)
const size_t sourcing_name_len
= (STRLEN(s) + strlen(name) + (size_t)ap->patlen + 1);
*sourcing_namep = xmalloc(sourcing_name_len);
snprintf(*sourcing_namep, sourcing_name_len, s, name, ap->pat);
char *const namep = xmalloc(sourcing_name_len);
snprintf(namep, sourcing_name_len, s, name, ap->pat);
if (p_verbose >= 8) {
verbose_enter();
smsg(_("Executing %s"), *sourcing_namep);
smsg(_("Executing %s"), namep);
verbose_leave();
}
// Update the exestack entry for this autocmd.
entry->es_name = namep;
entry->es_info.aucmd = apc;
apc->curpat = ap;
apc->nextcmd = ap->cmds;
// mark last command
@@ -2150,6 +2156,7 @@ char *getnextac(int c, void *cookie, int indent, bool do_concat)
// lua code, so that it works properly
autocmd_nested = ac->nested;
current_sctx = ac->script_ctx;
acp->script_ctx = current_sctx;
if (ac->exec.type == CALLABLE_CB) {
if (call_autocmd_callback(ac, acp)) {