Shawn
Shawn

Reputation: 1593

Is there a way to fold eclipse sub-blocks like an "if" statement?

Currently Eclipse only fold the java doc and at function level, but when reading long methods, there could be quite a lot of if/else etc, is there a way to fold them?

Upvotes: 62

Views: 54275

Answers (9)

Luke
Luke

Reputation: 93

Fold java source code like "if else for" statement

install pluins com.cb.eclipse.folding

restart your Eclipse make sure the pluins enabled

Click "Window->Preferences->Java->Editor->Folding"

  1. Select folding: select "Coffee Bytes Java Folding"
  2. Switch to "User Defined Regions"
  3. "Start Identifier" = { ; End Identifier = }
  4. click "Apply and Close"
  5. Reopen java source editor you will see "if" or "for" block is collapsable

enter image description here

Upvotes: 2

Ivan Kryvosheia
Ivan Kryvosheia

Reputation: 183

For now, there is built-in function.
Click "Window->Preferences->C/C++->Editor->Folding" and then enable appropriate option you want.
Apply, close and either refresh project or reopen eclipse.

Upvotes: 4

lahmania
lahmania

Reputation: 411

in updated versions of Eclipse

Change folding preferences at:

Window -> Preferences -> C/C++ -> Editor -> Folding -> Enable folding of preprocessor branches (#if/#else)

Enable folding using ctrl + shift + /

Upvotes: 22

Kishan
Kishan

Reputation: 1190

As weird as it looks like, sounds like developers never thought about that. if you have a big if statement or any switch/loop ... just use notepad++ to be able to fold/unfold

Upvotes: 2

hasanghaforian
hasanghaforian

Reputation: 14022

I found the Coffee-Bytes plugin. I downloaded it from this link and found this guide by the author, for using it.

You can find more details in these references:

What code folding plugins work on Eclipse 3.6?
How to use Coffee-Bytes code folding

Upvotes: 21

Al Lelopath
Al Lelopath

Reputation: 6778

For Python, i.e. Eclipse/PyDev, go to Windows > Preferences > PyDev > Editor > Code Folding and check all the boxes.

Upvotes: 1

z00l
z00l

Reputation: 906

Ok, this is a little bit older, but maybe someone could find this useful: In most cases you can surround the piece of code by an additional pair of scope brackets, and to remember what you folded you can add a line comment.

For example, if you want to collapse the following:

int SectionA_var1;
int SectionA_var2;
int SectionA_var3;
int SectionA_var4;
int SectionA_var5;
int SectionB_var1;

just add the brackets an the comment:

{ // SectionA
    int SectionA_var1;
    int SectionA_var2;
    int SectionA_var3;
    int SectionA_var4;
    int SectionA_var5;
}
int SectionB_var1;

Then you get the (-) sign and you can collapse the whole section to this:

{ // SectionA[...]
int SectionB_var1;

No plugin necessary, and until now I had no situation where this gave me any downsides, except that you cannot use it on a top level declaration to collapse methods.

Upvotes: 2

stacker
stacker

Reputation: 68942

No, in the Preferences Dialog (Menu Window/Prefernces): Java/Editor/Folding you may choose,

  • Comments
  • Head Comments
  • Inner Types
  • Members and Imports

if Enable Folding is checked.

If you wan't to do this because the blocks are so long that can't reconize the structure you should consider to split if/else blocks into methods using Alt-Shift-M (Extract Method)

Upvotes: 9

pm_labs
pm_labs

Reputation: 1145

It appears Eclipse does not have built-in support for folding if/else statements but allows folding for other more complex cases like Anonymous inner classes. Try looking for plugins like this one (last modified 2007, try it if it supports your Eclipse version).

Upvotes: 8

Related Questions