Folding depth

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Folding depth

Pablo Giménez Pizarro
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

--
Un saludo
Best Regards
Pablo Giménez

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Folding depth

Nikhilesh S
On Tue, Sep 21, 2010 at 07:57:10PM +0100, Pablo Giménez wrote:
> Hi vimers.
> Is there any way to limit the depth for folding.

How about 'fdn'?

BTW, helpgrep is very useful, I found this using

:helpgrep fold.*depth

--
Nikhilesh S
http://www.nikhilesh.info

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Folding depth

Nikolay Aleksandrovich Pavlov
In reply to this post by Pablo Giménez Pizarro
Ответ на сообщение «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)

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Folding depth

Pablo Giménez Pizarro
Thanks guys.
I got it working now, I just add suppor for my folding function for
Python to use foldnestmax option.
cheers

2010/9/21 ZyX <[hidden email]>:

> Ответ на сообщение «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
>



--
Un saludo
Best Regards
Pablo Giménez

--
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