The following foldexpr is giving me headaches because it doesn't work
under all circumstances:
fun! s:outlinerFoldingRule(n)
return getline(a:n) =~ '^\s*:' ?
\ 20 : indent(a:n) < indent(a:n+1) ?
\ ('>'.(1+indent(a:n)/&l:tabstop)) : (indent(a:n)/&l:tabstop)
endf
fun! Outliner()
setlocal autoindent
setlocal formatoptions=tcqrn1jo
setlocal comments=fb:*,fb:-,b::
setlocal textwidth=80
setlocal foldmethod=expr
setlocal foldexpr=s:outlinerFoldingRule(v:lnum)
setlocal foldlevel=2
let &l:tabstop=4
let &l:shiftwidth=4
let &l:softtabstop=4
endf
Sample text (copy and paste in a new buffer):
1 Title
1.1
: Note 1
: Some note
1.1.1
1.1.1.1
: Note 2
: Some note
1.1.1.2
1.1.2
1.1.2.1
After :call Outliner(), za folds/unfolds all sections, except for notes.
If I give zR then everything folds/unfolds as expected. But then, if I add
a section (say, 1.1.3) then things go nuts: for example, za on 1.1.2 folds
1.1 instead of 1.1.2. In other cases, I get "No fold found" errors.
Call Outliner() again and press zR, and everything is fine again (until
the next modification). What's wrong with the code above?
Nicola
--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment