summaryrefslogtreecommitdiffstats
path: root/src/ex_docmd.c
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2022-04-09 21:42:10 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-09 21:42:10 +0100
commit6013d0045dec7ca7c0068fbe186c42d754a7368b (patch)
tree739c5e84ced49602b15e033e3af9c909f9cc3e50 /src/ex_docmd.c
parent2ce97ae6aaec7007cca16a446d73161b82f2ba69 (diff)
patch 8.2.4726: cannot use expand() to get the script namev8.2.4726
Problem: Cannot use expand() to get the script name. Solution: Support expand('<script>'). (closes #10121)
Diffstat (limited to 'src/ex_docmd.c')
-rw-r--r--src/ex_docmd.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 7e3cb7ec37..42824d7bb4 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -8957,8 +8957,10 @@ find_cmdline_var(char_u *src, int *usedlen)
#define SPEC_SLNUM (SPEC_SFILE + 1)
"<stack>", // call stack
#define SPEC_STACK (SPEC_SLNUM + 1)
+ "<script>", // script file name
+#define SPEC_SCRIPT (SPEC_STACK + 1)
"<afile>", // autocommand file name
-#define SPEC_AFILE (SPEC_STACK + 1)
+#define SPEC_AFILE (SPEC_SCRIPT + 1)
"<abuf>", // autocommand buffer number
#define SPEC_ABUF (SPEC_AFILE + 1)
"<amatch>", // autocommand match name
@@ -9226,14 +9228,28 @@ eval_vars(
break;
case SPEC_SFILE: // file name for ":so" command
+ result = estack_sfile(ESTACK_SFILE);
+ if (result == NULL)
+ {
+ *errormsg = _(e_no_source_file_name_to_substitute_for_sfile);
+ return NULL;
+ }
+ resultbuf = result; // remember allocated string
+ break;
case SPEC_STACK: // call stack
- result = estack_sfile(spec_idx == SPEC_SFILE
- ? ESTACK_SFILE : ESTACK_STACK);
+ result = estack_sfile(ESTACK_STACK);
+ if (result == NULL)
+ {
+ *errormsg = _(e_no_call_stack_to_substitute_for_stack);
+ return NULL;
+ }
+ resultbuf = result; // remember allocated string
+ break;
+ case SPEC_SCRIPT: // script file name
+ result = estack_sfile(ESTACK_SCRIPT);
if (result == NULL)
{
- *errormsg = spec_idx == SPEC_SFILE
- ? _(e_no_source_file_name_to_substitute_for_sfile)
- : _(e_no_call_stack_to_substitute_for_stack);
+ *errormsg = _(e_no_script_file_name_to_substitute_for_script);
return NULL;
}
resultbuf = result; // remember allocated string