Mercurial > vim
diff src/scriptfile.c @ 28449:80ed5ad30d28 v8.2.4749
patch 8.2.4749: <script> is not expanded in autocmd context
Commit: https://github.com/vim/vim/commit/eca7c60d68e63001dbe3c8e5d240b0895e607fc3
Author: LemonBoy <thatlemon@gmail.com>
Date: Thu Apr 14 15:39:43 2022 +0100
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 https://github.com/vim/vim/issues/10144)
Rename AutoPatCmd to AutoPatCmd_T.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 14 Apr 2022 16:45:02 +0200 |
parents | 6f753a8125f0 |
children | 4dcccb2673fe |
line wrap: on
line diff
--- 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;