Code folding in Eclipse

孤人 提交于 2019-11-28 10:40:58

Eclipse supports code folding.

Go to workbench preferences -> General -> Editors -> Structured Text Editors, and check the "Enable folding" box.

Then go to workbench preferences -> Java -> Editor -> Folding, and adjust your folding preferences.

The <editor-fold and #region can be used as a block folding wrapping anything you want, including not just a function or a comment but both or even multiples functions, comments, variables, etc.

Eclipse does not has such functionality. I am using Eclipse Neon and still missing this.

DanChianucci

Windows->Preferences->(C/C++)->Editors->Folding

(C/C++) will change based on the language you are using. Generally each language plugin will have its own folding options

I created a fork and an update site for the old coffee bytes code folding plugin that works with Eclipse Neon: https://github.com/stefaneidelloth/EclipseFolding/raw/master/com.cb.platsupp.site

Although this is an old question, I'd like to add some input.

Eclipse doesn't natively support custom code folding blocks, as does Visual Studio with its #region and #endregion directives, or Netbeans with its //<editor-fold defaulstate="collapsed" desc="My custom code folding block" and //</editor-fold>.

(IntelliJ supports this as well, with both aforementioned methods working, depending on how the IDE is configured.)


If you happen to be working in Eclipse with the CDT (as in C/C++), there is a way around. I've tried installing the plugins mentioned, but they either do not exist anymore, or the installation makes the IDE unstable.

Create a header file in a central location, which contains macros, etc (optional). In that header, simply define a FOLD macro, as below:

#define FOLD //

Each file that #includes your central header file will also have a reference to the macro above.

An example use of this would be:

#ifdef FOLD Struct MyFileStruct
#pragma pack(1)
typedef struct MyFileStruct {
        WCHAR fileName[FILENAMELEN];  // File name
        WCHAR fileInfos[32];          // File info
        WCHAR fileDate[32];           // File date
        DWORD sizeInBytes;            // File size
} File;
#pragma pack()
#endif

If the way this works is unclear, I suggest looking in to the C Preprocessor

I hope this is of some use!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!