It all depends on which editor you use. In vim, you can enable folding with:
set foldenable
Then you can use different bending methods, for the main languages you can set:
set foldmethod=syntax
which allows you to bend syntax.
There are half a dozen folding methods, I think it would be best to read
help folding
which should answer everything.
source share