Bram,
this question came up on stackexchange:
http://vi.stackexchange.com/q/5543/71
In short take this file foldexpr.vim:
#v+
$ cat foldexpr.vim
"" This is a demo, the fold starts here. This line has foldlevel 2
" This line is folded wrong, it should have foldlevel 1, but has foldlevel 2
" Another test line. What foldlevel does it have?
" Another test line. What foldlevel does it have?
function! VimFolds(lnum)
let thisline = getline(a:lnum)
if match(thisline, '^""') >= 0
return '>2'
elseif match(thisline, '^" ') >= 0
return 's1'
else
return '='
endif
endfunction
setlocal foldmethod=expr
setlocal foldexpr=VimFolds(v:lnum)
set foldcolumn=3
set foldminlines=0
$
vim -u NONE -N -c ':so %' foldexpr.vim
#v-
Note the second line has foldlevel 2 instead of 1
It looks like the special string 's1' does substract one after the
current line. So either the documentation:
,----[ :h fold-expr ]-
| "s1", "s2", .. subtract one, two, .. from the fold level of the
| previous line
`----
or the code is wrong. Looking at foldlevelExpr() I see this code:
,----[ fold.c ... foldlevelExpr() ]-
| /* "s1", "s2", .. : subtract from the fold level */
| case 's': if (flp->lvl >= 0)
| {
| if (n > flp->lvl)
| flp->lvl_next = 0;
| else
| flp->lvl_next = flp->lvl - n;
| flp->end = flp->lvl_next + 1;
| }
| break;
`----
Note, that flp->lvl is not set and remains at the current value. So what
do you think: A bug or a (undocumented) feature?
Best,
Christian
--
Bescheidenheit ist so beliebt, weil sie einem die Arroganz erleichtert.