From 3a8b8591477b4802af73436e93bd1283d4bab518 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 13 Aug 2022 15:46:20 +0800 Subject: vim-patch:8.2.0078: expanding works differently the second time Problem: Expanding works differently the second time. Solution: Keep the expanded name when redefining a function. (closes vim/vim#5425) https://github.com/vim/vim/commit/b9adef79eca6f95bc7376ff3a6a383e436c5d6ea --- src/nvim/eval/userfunc.c | 5 ++++- src/nvim/testdir/test_vimscript.vim | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index bcd8eb4d4c..83be330592 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -2442,9 +2442,12 @@ void ex_function(exarg_T *eap) fp = NULL; overwrite = true; } else { - // redefine existing function + char_u *exp_name = fp->uf_name_exp; + // redefine existing function, keep the expanded name XFREE_CLEAR(name); + fp->uf_name_exp = NULL; func_clear_items(fp); + fp->uf_name_exp = exp_name; fp->uf_profiling = false; fp->uf_prof_initialized = false; } diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim index d16783cf31..0f204cdd0c 100644 --- a/src/nvim/testdir/test_vimscript.vim +++ b/src/nvim/testdir/test_vimscript.vim @@ -1573,6 +1573,23 @@ func Test_script_local_func() enew! | close endfunc +func Test_script_expand_sfile() + let lines =<< trim END + func s:snr() + return expand('') + endfunc + let g:result = s:snr() + END + call writefile(lines, 'Xexpand') + source Xexpand + call assert_match('\d\+_snr', g:result) + source Xexpand + call assert_match('\d\+_snr', g:result) + + call delete('Xexpand') + unlet g:result +endfunc + func Test_compound_assignment_operators() " Test for number let x = 1 -- cgit