diff options
author | LemonBoy <thatlemon@gmail.com> | 2022-04-14 15:39:43 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-04-14 15:39:43 +0100 |
commit | eca7c60d68e63001dbe3c8e5d240b0895e607fc3 (patch) | |
tree | 04384f6cf892f06286cc7176f80af901cd72be40 /src/scriptfile.c | |
parent | 8944551534b311a2d25acf6e8db235c6d906256c (diff) | |
download | vim-git-eca7c60d68e63001dbe3c8e5d240b0895e607fc3.tar.gz |
patch 8.2.4749: <script> is not expanded in autocmd contextv8.2.4749
Problem: <script> is not expanded in autocmd context.
Solution: Add the context to the pattern struct. (closes #10144)
Rename AutoPatCmd to AutoPatCmd_T.
Diffstat (limited to 'src/scriptfile.c')
-rw-r--r-- | src/scriptfile.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/scriptfile.c b/src/scriptfile.c index 2a1f84a50..3dfb1c43c 100644 --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -157,27 +157,36 @@ estack_sfile(estack_arg_T which UNUSED) return NULL; } - // If evaluated in a function return the path of the script where the - // function is defined, at script level the current script path is returned + // If evaluated in a function or autocommand, return the path of the script + // where it is defined, at script level the current script path is returned // instead. if (which == ESTACK_SCRIPT) { - if (entry->es_type == ETYPE_UFUNC) + entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; + // Walk the stack backwards, starting from the current frame. + for (idx = exestack.ga_len - 1; idx >= 0; --idx, --entry) { - sctx_T *def_ctx = &entry->es_info.ufunc->uf_script_ctx; + if (entry->es_type == ETYPE_UFUNC) + { + sctx_T *def_ctx = &entry->es_info.ufunc->uf_script_ctx; - if (def_ctx->sc_sid > 0) - return vim_strsave(SCRIPT_ITEM(def_ctx->sc_sid)->sn_name); - } - else if (exestack.ga_len > 0) - { - // Walk the stack backwards, starting from the current frame. - for (idx = exestack.ga_len - 1; idx; --idx) + if (def_ctx->sc_sid > 0) + return vim_strsave(SCRIPT_ITEM(def_ctx->sc_sid)->sn_name); + else + return NULL; + } + else if (entry->es_type == ETYPE_AUCMD) { - entry = ((estack_T *)exestack.ga_data) + idx; + sctx_T *def_ctx = acp_script_ctx(entry->es_info.aucmd); - if (entry->es_type == ETYPE_SCRIPT) - return vim_strsave(entry->es_name); + if (def_ctx->sc_sid > 0) + return vim_strsave(SCRIPT_ITEM(def_ctx->sc_sid)->sn_name); + else + return NULL; + } + else if (entry->es_type == ETYPE_SCRIPT) + { + return vim_strsave(entry->es_name); } } return NULL; |