mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:partial:8.2.3908: cannot use a script-local function for 'foldtext'
Problem: Cannot use a script-local function for 'foldtext'.
Solution: Expand "s:" and "<SID>". (Yegappan Lakshmanan, closes vim/vim#9411)
27708e6c7b
Only port the changes actually related to 'foldtext'.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
parent
9671908c68
commit
5e97984188
@ -117,7 +117,7 @@ Try to avoid the "=", "a" and "s" return values, since Vim often has to search
|
||||
backwards for a line for which the fold level is defined. This can be slow.
|
||||
|
||||
If the 'foldexpr' expression starts with s: or |<SID>|, then it is replaced
|
||||
with the script ID (|local-function|). Example: >
|
||||
with the script ID (|local-function|). Examples: >
|
||||
set foldexpr=s:MyFoldExpr()
|
||||
set foldexpr=<SID>SomeFoldExpr()
|
||||
<
|
||||
@ -526,6 +526,11 @@ The resulting line is truncated to fit in the window, it never wraps.
|
||||
When there is room after the text, it is filled with the character specified
|
||||
by 'fillchars'.
|
||||
|
||||
If the 'foldtext' expression starts with s: or |<SID>|, then it is replaced
|
||||
with the script ID (|local-function|). Examples: >
|
||||
set foldtext=s:MyFoldText()
|
||||
set foldtext=<SID>SomeFoldText()
|
||||
<
|
||||
Note that backslashes need to be used for characters that the ":set" command
|
||||
handles differently: Space, backslash and double-quote. |option-backslash|
|
||||
|
||||
|
@ -1483,6 +1483,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
|
||||
}
|
||||
} else if (varp == &p_dex
|
||||
|| varp == &curwin->w_p_fde
|
||||
|| varp == &curwin->w_p_fdt
|
||||
|| gvarp == &p_fex
|
||||
|| gvarp == &p_inex
|
||||
|| gvarp == &p_inde
|
||||
@ -1499,6 +1500,9 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
|
||||
if (varp == &curwin->w_p_fde) { // 'foldexpr'
|
||||
p_opt = &curwin->w_p_fde;
|
||||
}
|
||||
if (varp == &curwin->w_p_fdt) { // 'foldtext'
|
||||
p_opt = &curwin->w_p_fdt;
|
||||
}
|
||||
if (gvarp == &p_fex) { // 'formatexpr'
|
||||
p_opt = &curbuf->b_p_fex;
|
||||
}
|
||||
|
@ -1299,6 +1299,37 @@ func Test_foldexpr_scriptlocal_func()
|
||||
bw!
|
||||
endfunc
|
||||
|
||||
" Test for using a script-local function for 'foldtext'
|
||||
func Test_foldtext_scriptlocal_func()
|
||||
func! s:FoldText()
|
||||
let g:FoldTextArgs = [v:foldstart, v:foldend]
|
||||
return foldtext()
|
||||
endfunc
|
||||
new | only
|
||||
call setline(1, range(50))
|
||||
let g:FoldTextArgs = []
|
||||
set foldmethod=manual
|
||||
set foldtext=s:FoldText()
|
||||
norm! 4Gzf4j
|
||||
redraw!
|
||||
call assert_equal(expand('<SID>') .. 'FoldText()', &foldtext)
|
||||
call assert_equal([4, 8], g:FoldTextArgs)
|
||||
set foldtext&
|
||||
bw!
|
||||
new | only
|
||||
call setline(1, range(50))
|
||||
let g:FoldTextArgs = []
|
||||
set foldmethod=manual
|
||||
set foldtext=<SID>FoldText()
|
||||
norm! 8Gzf4j
|
||||
redraw!
|
||||
call assert_equal(expand('<SID>') .. 'FoldText()', &foldtext)
|
||||
call assert_equal([8, 12], g:FoldTextArgs)
|
||||
set foldtext&
|
||||
bw!
|
||||
delfunc s:FoldText
|
||||
endfunc
|
||||
|
||||
" Make sure a fold containing a nested fold is split correctly when using
|
||||
" foldmethod=indent
|
||||
func Test_fold_split()
|
||||
|
Loading…
Reference in New Issue
Block a user