Tip 12: Collapsing Code

From Vlsiwiki
Jump to: navigation, search

Once you have a bunch of code, it becomes difficult to navigate. Before, I showed that you can use Tip 7: etags to do this , but there is also another way: collapsing code. Both vim and emacs support this concept.

emacs

In emacs, this feature is implemented in a "minor mode". To run it, type M-x outline-minor-mode. After this, you type M-x hide-other. In a C/C++ program, this will put ellipses between function braces { ... }. Your code is still there, but hidden. If you move to one of these functions, you can then type M-x show-subtree and the code will display again. There are ways to incrementally show more and more, but this shows either none or all. That is usually good enough.

vim

In vim, it is called "folding". Since I don't use emacs, you can find a tutorial on it here.