From f7fde0173af95925e7324b7d3c09776173dab8a7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Aug 2024 10:13:45 +0800 Subject: vim-patch:9.0.0632: calling a function from an "expr" option has overhead Problem: Calling a function from an "expr" option has too much overhead. Solution: Add call_simple_func() and use it for 'foldexpr' https://github.com/vim/vim/commit/87b4e5c5db9d1cfd6f2e79656e1a6cff3c69d15f Cherry-pick a call_func() change from patch 8.2.1343. Add expr-option-function docs to options.txt. Co-authored-by: Bram Moolenaar --- test/old/testdir/test_fold.vim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test') diff --git a/test/old/testdir/test_fold.vim b/test/old/testdir/test_fold.vim index 36f72f5e01..a0eb3afdbb 100644 --- a/test/old/testdir/test_fold.vim +++ b/test/old/testdir/test_fold.vim @@ -386,6 +386,32 @@ func Test_foldexpr_no_interrupt_addsub() set foldmethod& foldexpr& endfunc +" Fold function defined in another script +func Test_foldexpr_compiled() + throw 'Skipped: Vim9 script is N/A' + new + let lines =<< trim END + vim9script + def FoldFunc(): number + return v:lnum + enddef + + set foldmethod=expr + set foldexpr=s:FoldFunc() + END + call writefile(lines, 'XfoldExpr', 'D') + source XfoldExpr + + call setline(1, ['one', 'two', 'three']) + redraw + call assert_equal(1, foldlevel(1)) + call assert_equal(2, foldlevel(2)) + call assert_equal(3, foldlevel(3)) + + bwipe! + set foldmethod& foldexpr& +endfunc + func Check_foldlevels(expected) call assert_equal(a:expected, map(range(1, line('$')), 'foldlevel(v:val)')) endfunc -- cgit