Ответ на сообщение «Folding depth», 
присланное в 22:57:10 21 сентября 2010, Вторник,
отправитель Pablo Giménez:

You said `no matter the folding methods I use', so you have probably discovered 
`foldnestmax' option. I think that for any method it is possible only with the 
custom script. The attached script partially does the thing (it opens all folds 
with foldlevel>3), but it has at least one bug: sometimes it opens fold under 
cursor. You will also have to remap some of `z?' normal commands, foldlevel() 
function will be helpful.

Текст сообщения:
> Hi vimers.
> Is there any way to limit the depth for folding.
> I mean if I don't want folders to be created for more than 3 levels of
> folding is it possible to specify it so no matter the folding methos I
> use the depth will be limited to a certain amount?
> thanks
function! s:sortlevels(a, b)
    let [a, b]=[a:a+0, a:b+0]
    return ((a==b)?(0):((a<b)?(1):(-1)))
endfunction
function! Unfold(level)
    let view=winsaveview()
    let startline=1
    let endline=line('$')
    let closedfolds={}
    let line=startline
    let savedfoldopen=&foldopen
    set foldopen=
    while line<=endline
        let foldend=foldclosedend(line)
        if foldend!=-1
            let foldlevel=foldlevel(line)
            if foldlevel>a:level
                execute 'normal! '.line.'ggzO'
                let line=foldend
            else
                if !has_key(closedfolds, foldlevel)
                    let closedfolds[foldlevel]=[]
                endif
                call add(closedfolds[foldlevel], line)
                execute 'normal! zo'
            endif
        endif
        let line+=1
    endwhile
    for foldlevel in sort(keys(closedfolds), 's:sortlevels')
        for line in closedfolds[foldlevel]
            execute 'normal! '.line.'ggzc'
        endfor
    endfor
    set nofoldenable
    call winrestview(view)
    let &foldopen=savedfoldopen
    set foldenable
endfunction
autocmd BufEnter * call Unfold(3)

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to