3

I am refactoring legacy code. Looks like:

for (int i = 0; i < something.length; i++) {
    .... 
    ....
    lots of code here
    ....
    if (a.good != b.bad) {
       ....
       ....  .... 
       ....
       lots of code here
       ....
       if (foo.bar == spam.something && something else) {
           .... 
           ....
           lots of code here
           ....
           I AM HERE SOMEWHERE. 
           ....
       }
    }
}

What happens a lot is, I am at a point in code and all I can see is basically small portion of the code. So I have to scroll to get the global context.

       if (foo.bar == spam.something && something else) {
           .... 
           ....
           lots of code here
           ....
           I AM HERE SOMEWHERE. 
           ....
       }

What I would like to see is something like:

for (int i = 0; i < something.length; i++) {
    ...
    if (a.good != b.bad) {
       ...
       if (foo.bar == spam.something && something else) {
           I AM HERE SOMEWHERE. 
           // code
       }
    }
}

I want emacs to collapse code between conditionals, loops and functions. If this happens automatically then that would be great. How can I do that?

  • 3
    Take a look at [`hideshow`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Hideshow.html) – Dan Oct 15 '18 at 14:19
  • check this .. https://emacs.stackexchange.com/questions/3145/display-the-beginning-of-a-scope-when-it-is-out-of-screen – junnu Oct 16 '18 at 09:28

0 Answers0