>
> I use a pretty simple folding algorithm for C files and it works very well:
>
> " This is in my .vimrc
> set foldnestmax=1
>
> " And these are in .vim/ftplugin/c.vim
> syn sync fromstart
> set foldmethod=syntax
>
> I guess the default settings for C files are also loaded from
> /usr/share/vim/vim72/syntax/c.vim etc.
>
> The above settings do exactly what I need, folding only top level
> braces, i.e. if I have
>
> void x( )
> {
> something
> {
> .................
> }
> }
> void y( )
> {
> etc
> {
> .........
> }
> somemorestuff
> {
> ...........
> }
> }
>
> then folding everything produces
>
> void x( )
> -----------------folded--------------
> void y( )
> -----------------folded--------------
>
> And if the folded regions are unfolded, there are no enclosed folds
> either (only top level braces are folded).
>
> This is all good.
>
> Now I have a hard time reproducing all of this with javascript files :(
>
> If I copy the same settings from ~/.vim/ftplugin/c.vim to
> ~/.vim/ftplugin/javascript.vim I don't get the same results, for
> example vim can't find folds where there should be one, for example
> between two top level braces.
>
> I guess the different behavior has to do with the fact that although
> my custom settings are the same, the system wide
> /usr/share/vim/vim72/syntax/* settings are not the same for javascript
> and C.
>
> I tried solving the problem by :set filetype=c for javascript, which
> indeed does the folding as I expect it, but it comes with all sorts of
> other problems due to the source file not being C but javascript (for
> example something({ ........ }) which is common in javascript
> highlights the braces in red, indicating an error, since this
> construct is indeed erroneous in C).
>
> So my question is: how would I make vim fold only top level braces
> once for javascript files?
By the way, I did read
:help :syn-end
:help :syn-contains
:help :syn-contained
:help :syn-keepend
But still out of luck. With javascript either everything is folded
between the first { and the last } (which means the entire file is
folded, not each function separately) or no folds are found.
Cheers,
Daniel
--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment