Christian Brabandt wrote:
> 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?
The idea of the "s1" kind of values is that this matches a line that's
the end of a fold. Thus it indeed applies to the following line, not
the current one. Good example is a C comment:
/*
* comment
*/
Here matching "/*" with "a1" and "*/" with "s1" should work.
I'll adjust the documentatin.
--
hundred-and-one symptoms of being an internet addict:
128. You can access the Net -- via your portable and cellular phone.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.