Mercurial > vim
comparison src/scriptfile.c @ 28403:2655935b5ccc v8.2.4726
patch 8.2.4726: cannot use expand() to get the script name
Commit: https://github.com/vim/vim/commit/6013d0045dec7ca7c0068fbe186c42d754a7368b
Author: LemonBoy <thatlemon@gmail.com>
Date: Sat Apr 9 21:42:10 2022 +0100
patch 8.2.4726: cannot use expand() to get the script name
Problem: Cannot use expand() to get the script name.
Solution: Support expand('<script>'). (closes https://github.com/vim/vim/issues/10121)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 09 Apr 2022 22:45:03 +0200 |
parents | 4b322951ebac |
children | 6f753a8125f0 |
comparison
equal
deleted
inserted
replaced
28402:401c4206d38c | 28403:2655935b5ccc |
---|---|
116 return ((estack_T *)exestack.ga_data) + exestack.ga_len; | 116 return ((estack_T *)exestack.ga_data) + exestack.ga_len; |
117 } | 117 } |
118 | 118 |
119 /* | 119 /* |
120 * Get the current value for <sfile> in allocated memory. | 120 * Get the current value for <sfile> in allocated memory. |
121 * "which" is ESTACK_SFILE for <sfile> and ESTACK_STACK for <stack>. | 121 * "which" is ESTACK_SFILE for <sfile>, ESTACK_STACK for <stack> or |
122 * ESTACK_SCRIPT for <script>. | |
122 */ | 123 */ |
123 char_u * | 124 char_u * |
124 estack_sfile(estack_arg_T which UNUSED) | 125 estack_sfile(estack_arg_T which UNUSED) |
125 { | 126 { |
126 estack_T *entry; | 127 estack_T *entry; |
151 if (emsg_off == 1) | 152 if (emsg_off == 1) |
152 // f_expand() silences errors but we do want this one | 153 // f_expand() silences errors but we do want this one |
153 emsg_off = 0; | 154 emsg_off = 0; |
154 emsg(_(e_cannot_expand_sfile_in_vim9_function)); | 155 emsg(_(e_cannot_expand_sfile_in_vim9_function)); |
155 emsg_off = save_emsg_off; | 156 emsg_off = save_emsg_off; |
157 return NULL; | |
158 } | |
159 | |
160 // If evaluated in a function return the path of the script where the | |
161 // function is defined, at script level the current script path is returned | |
162 // instead. | |
163 if (which == ESTACK_SCRIPT) | |
164 { | |
165 if (entry->es_type == ETYPE_UFUNC) | |
166 { | |
167 sctx_T *def_ctx = &entry->es_info.ufunc->uf_script_ctx; | |
168 | |
169 if (def_ctx->sc_sid > 0) | |
170 return vim_strsave(SCRIPT_ITEM(def_ctx->sc_sid)->sn_name); | |
171 } | |
172 else if (exestack.ga_len > 0) | |
173 { | |
174 // Walk the stack backwards, starting from the current frame. | |
175 for (idx = exestack.ga_len - 1; idx; --idx) | |
176 { | |
177 entry = ((estack_T *)exestack.ga_data) + idx; | |
178 | |
179 if (entry->es_type == ETYPE_SCRIPT) | |
180 return vim_strsave(entry->es_name); | |
181 } | |
182 } | |
156 return NULL; | 183 return NULL; |
157 } | 184 } |
158 | 185 |
159 // Give information about each stack entry up to the root. | 186 // Give information about each stack entry up to the root. |
160 // For a function we compose the call stack, as it was done in the past: | 187 // For a function we compose the call stack, as it was done in the past: |