comparison 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
comparison
equal deleted inserted replaced
28448:68c4651c8dfc 28449:80ed5ad30d28
155 emsg(_(e_cannot_expand_sfile_in_vim9_function)); 155 emsg(_(e_cannot_expand_sfile_in_vim9_function));
156 emsg_off = save_emsg_off; 156 emsg_off = save_emsg_off;
157 return NULL; 157 return NULL;
158 } 158 }
159 159
160 // If evaluated in a function return the path of the script where the 160 // If evaluated in a function or autocommand, return the path of the script
161 // function is defined, at script level the current script path is returned 161 // where it is defined, at script level the current script path is returned
162 // instead. 162 // instead.
163 if (which == ESTACK_SCRIPT) 163 if (which == ESTACK_SCRIPT)
164 { 164 {
165 if (entry->es_type == ETYPE_UFUNC) 165 entry = ((estack_T *)exestack.ga_data) + exestack.ga_len - 1;
166 { 166 // Walk the stack backwards, starting from the current frame.
167 sctx_T *def_ctx = &entry->es_info.ufunc->uf_script_ctx; 167 for (idx = exestack.ga_len - 1; idx >= 0; --idx, --entry)
168 168 {
169 if (def_ctx->sc_sid > 0) 169 if (entry->es_type == ETYPE_UFUNC)
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 { 170 {
177 entry = ((estack_T *)exestack.ga_data) + idx; 171 sctx_T *def_ctx = &entry->es_info.ufunc->uf_script_ctx;
178 172
179 if (entry->es_type == ETYPE_SCRIPT) 173 if (def_ctx->sc_sid > 0)
180 return vim_strsave(entry->es_name); 174 return vim_strsave(SCRIPT_ITEM(def_ctx->sc_sid)->sn_name);
175 else
176 return NULL;
177 }
178 else if (entry->es_type == ETYPE_AUCMD)
179 {
180 sctx_T *def_ctx = acp_script_ctx(entry->es_info.aucmd);
181
182 if (def_ctx->sc_sid > 0)
183 return vim_strsave(SCRIPT_ITEM(def_ctx->sc_sid)->sn_name);
184 else
185 return NULL;
186 }
187 else if (entry->es_type == ETYPE_SCRIPT)
188 {
189 return vim_strsave(entry->es_name);
181 } 190 }
182 } 191 }
183 return NULL; 192 return NULL;
184 } 193 }
185 194