[Haakon Riiser]
> I'm trying to make a fold expression that increases the fold level
> whenever a "{" appears at the end of a line, and decreases when a
> "}" appears at the beginning. I'm having problems writing such
> an expression because the "sN" construct doesn't affect the fold
> level of the line for which it is returned. :-(
>
> Example: Take the following fold expression:
> [...]
By the way, I am aware that I can work around this problem by
caching the previous line's fold level. I'm currently using this
function, which seems to work (haven't tested it thoroughly yet,
though):
fun! Fold_level()
if v:lnum == 1
let b:prev_fold_level = 0
return 0
endif
let prevline = getline(v:lnum - 1)
let prevline = Remove_cstrings_and_ccomments(prevline)
let thisline = getline(v:lnum)
let thisline = Remove_cstrings_and_ccomments(thisline)
if match(thisline, '^\s*}') != -1 && match(prevline, '{\s*$') == -1
let b:prev_fold_level -= 1
elseif match(prevline, '{\s*$') != -1 && match(thisline, '^\s*}') == -1
let b:prev_fold_level += 1
endif
return b:prev_fold_level
endfun
--
Haakon
--
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