diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-23 12:20:37 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-08-23 17:48:12 +0800 |
commit | d0b9fe2d5a95def67acc83f713b932f3f12dea08 (patch) | |
tree | 3c21b8d776e099c1f55c25a6593ccb3cbf1a9f7a /src/nvim/runtime.c | |
parent | 7afc17dec17bcc40c646b796f05d373e46916dd7 (diff) | |
download | rneovim-d0b9fe2d5a95def67acc83f713b932f3f12dea08.tar.gz rneovim-d0b9fe2d5a95def67acc83f713b932f3f12dea08.tar.bz2 rneovim-d0b9fe2d5a95def67acc83f713b932f3f12dea08.zip |
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.
https://github.com/vim/vim/commit/eca7c60d68e63001dbe3c8e5d240b0895e607fc3
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.
Diffstat (limited to 'src/nvim/runtime.c')
-rw-r--r-- | src/nvim/runtime.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 412b78728e..038aad12a4 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -104,7 +104,7 @@ void estack_pop(void) /// ESTACK_SCRIPT for <script>. char *estack_sfile(estack_arg_T which) { - estack_T *entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; + const estack_T *entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1; if (which == ESTACK_SFILE && entry->es_type != ETYPE_UFUNC) { if (entry->es_name == NULL) { return NULL; @@ -112,22 +112,31 @@ char *estack_sfile(estack_arg_T which) return xstrdup(entry->es_name); } - // 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) { - sctx_T *def_ctx = &entry->es_info.ufunc->uf_script_ctx; - if (def_ctx->sc_sid > 0) { - return xstrdup((char *)(SCRIPT_ITEM(def_ctx->sc_sid).sn_name)); - } - } else if (exestack.ga_len > 0) { - // Walk the stack backwards, starting from the current frame. - for (int idx = exestack.ga_len - 1; idx; idx--) { - entry = ((estack_T *)exestack.ga_data) + idx; - if (entry->es_type == ETYPE_SCRIPT) { - return xstrdup(entry->es_name); + assert(entry == ((estack_T *)exestack.ga_data) + exestack.ga_len - 1); + // Walk the stack backwards, starting from the current frame. + for (int idx = exestack.ga_len - 1; idx >= 0; idx--, entry--) { + if (entry->es_type == ETYPE_UFUNC) { + const sctx_T *const def_ctx = &entry->es_info.ufunc->uf_script_ctx; + + if (def_ctx->sc_sid > 0) { + return xstrdup((char *)(SCRIPT_ITEM(def_ctx->sc_sid).sn_name)); + } else { + return NULL; + } + } else if (entry->es_type == ETYPE_AUCMD) { + const sctx_T *const def_ctx = &entry->es_info.aucmd->script_ctx; + + if (def_ctx->sc_sid > 0) { + return xstrdup((char *)(SCRIPT_ITEM(def_ctx->sc_sid).sn_name)); + } else { + return NULL; } + } else if (entry->es_type == ETYPE_SCRIPT) { + return xstrdup(entry->es_name); } } return NULL; |