summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-01-02 14:31:22 +0100
committerBram Moolenaar <Bram@vim.org>2020-01-02 14:31:22 +0100
commitb9adef79eca6f95bc7376ff3a6a383e436c5d6ea (patch)
tree0b91933fe657397aee86a36dcacc3b45837bc9f6
parent271fa08a35b8d320d3a40db4ddae83b698fdd4fb (diff)
downloadvim-git-b9adef79eca6f95bc7376ff3a6a383e436c5d6ea.tar.gz
patch 8.2.0078: expanding <sfile> works differently the second timev8.2.0078
Problem: Expanding <sfile> works differently the second time. Solution: Keep the expanded name when redefining a function. (closes #5425)
-rw-r--r--src/testdir/test_vimscript.vim17
-rw-r--r--src/userfunc.c6
-rw-r--r--src/version.c2
3 files changed, 24 insertions, 1 deletions
diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim
index 89112dead..c890fb779 100644
--- a/src/testdir/test_vimscript.vim
+++ b/src/testdir/test_vimscript.vim
@@ -1642,6 +1642,23 @@ func Test_script_local_func()
enew! | close
endfunc
+func Test_script_expand_sfile()
+ let lines =<< trim END
+ func s:snr()
+ return expand('<sfile>')
+ endfunc
+ let g:result = s:snr()
+ END
+ call writefile(lines, 'Xexpand')
+ source Xexpand
+ call assert_match('<SNR>\d\+_snr', g:result)
+ source Xexpand
+ call assert_match('<SNR>\d\+_snr', g:result)
+
+ call delete('Xexpand')
+ unlet g:result
+endfunc
+
func Test_compound_assignment_operators()
" Test for number
let x = 1
diff --git a/src/userfunc.c b/src/userfunc.c
index a8bc34ae8..95862fe87 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -2572,9 +2572,13 @@ ex_function(exarg_T *eap)
}
else
{
- // redefine existing function
+ char_u *exp_name = fp->uf_name_exp;
+
+ // redefine existing function, keep the expanded name
VIM_CLEAR(name);
+ fp->uf_name_exp = NULL;
func_clear_items(fp);
+ fp->uf_name_exp = exp_name;
#ifdef FEAT_PROFILE
fp->uf_profiling = FALSE;
fp->uf_prof_initialized = FALSE;
diff --git a/src/version.c b/src/version.c
index 118dad505..4516eb71b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -743,6 +743,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 78,
+/**/
77,
/**/
76,