vim-patch:8.2.0078: expanding <sfile> works differently the second time

Problem:    Expanding <sfile> works differently the second time.
Solution:   Keep the expanded name when redefining a function. (closes vim/vim#5425)
b9adef79ec
This commit is contained in:
zeertzjq 2022-08-13 15:46:20 +08:00
parent de72f9098a
commit 3a8b859147
2 changed files with 21 additions and 1 deletions

View File

@ -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;
}

View File

@ -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('<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