Quantcast

fold functions only (not if, for, switch...)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

fold functions only (not if, for, switch...)

fkater@googlemail.com
Hi,

I would like to fold C code at { and } but with functions only, not
for 'if', 'for', 'switch' etc.

And I would like to keep #if, #endif folds, too.

(1)
My current workaround is not satisfying because I spoil the code with
markers: I fold based on markers '#if', '#endif' and add them in C
comments for funtions like this:

FUNC(...){/*#if*/
   ...
}/*#endif*/

(2)
I would love to go for syntax folding but the default folds on 'if',
'for' etc as well. I do not like using the default syntax folding +
simply set foldminlines=SOMELINES because it never really fits (you
can have many short functions, and I do not want to fold long or short
if() clauses at all).

(3)
I tried setting up my own c.vim syntax, but it seems quite complex to
define what is a pattern for a function? Because function names are
hard to define,  but 'if', 'for', 'switch' are known, I though of
going the other way round excluding patterns like "if + ( ... ) {"
from my function fold group somehow. I failed.

(4)
Finally I thought, an easier approach was to allow #if, #endif as
usual, and { } folds just for the top level (not nested), as functions
never appear nested inside of {}. But how to do that?

Thank You for any hint!

 Felix

--
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
|  
Report Content as Inappropriate

Re: fold functions only (not if, for, switch...)

Ben Fritz


On Sep 10, 4:07 am, "[hidden email]" <[hidden email]>
wrote:
> Hi,
>
> I would like to fold C code at { and } but with functions only, not
> for 'if', 'for', 'switch' etc.
>
> And I would like to keep #if, #endif folds, too.
>

This might be easier to do with a foldexpr instead of syntax folding,
especially if you don't want to make an entirely new c.vim file.
Create a function that will determine whether the current line is a
function definition, start of pre-processor block, end of pre-
processor block, or top-level '}' and use it with foldmethod=expr. See
the :help for how to use these options.

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