Home Download Buy Blog Forum Support

Coding folding does not work properly

Coding folding does not work properly

Postby gregor.hoch on Tue Oct 25, 2011 4:32 pm

Hi, the addition of code folder is great! I just love it.... :)

There are, however, some cases which make the folding of functions or if-clases fail.
Problem 1: ST2 does not recognize a folding element.
Problem 1: ST2 does not fold the whole code of a loop/if/for but is 'interrupted' by a comment line (or maybe because of intention)

Both problems are illustrated in the attached screenshots. Is that a general problem or related to the language definition (in this case, it's R)?

Thanks!
Attachments
problem2b.png
illustration of problem 2
problem2b.png (13.97 KiB) Viewed 1084 times
problem2a.png
illustration of problem 2
problem2a.png (15.88 KiB) Viewed 1085 times
problem1.png
illustration of problem 1
problem1.png (14.63 KiB) Viewed 1085 times
gregor.hoch
 
Posts: 143
Joined: Sat Oct 01, 2011 7:54 pm

Re: Coding folding does not work properly

Postby gregor.hoch on Tue Oct 25, 2011 4:36 pm

I just confirmed: the indentation seems to be the problem.
I can see that code folding based on indentations works perfectly for Python but it does not for any other language that uses symbols to delineate loops etc. Perfect indentations is not required in these languages and code folding should be based on '{' and '}'...

or again, can I solve this with the language definition?
gregor.hoch
 
Posts: 143
Joined: Sat Oct 01, 2011 7:54 pm

Re: Coding folding does not work properly

Postby facelessuser on Tue Oct 25, 2011 5:56 pm

Yeah, it works great in Python, but I was having this problem in C files as well, so I coded up a simple function for use with BracketHighlighter to fold by brackets.

If you happen to use BracketHighlighter, you can create a file called foldbracket.py and drop in this code (I have not yet included it by default in the repo yet)
Code: Select all
import bracket_plugin


class fold_bracket(bracket_plugin.BracketPluginCommand):
    def run(self, bracket, content, selection):
        new_content = [content]
        if content.size > 0:
            if self.view.fold(content) == False:
                new_content = self.view.unfold(content)
        self.attr.set_selection(new_content)


To map it to a shortcut you can just use this replacing the key sequence with whatever shortcut you would like:
Code: Select all
{
      "keys": ["ctrl+shift+b","ctrl+shift+f"],
      "command": "bracket_highlighter_key",
      "args":
      {
         "plugin": {"type": ["quote", "tag", "bracket"],"command" : "foldbracket.fold_bracket"}
      }
   }


But in general I think this should be fixed in the core ST2.

Edit: Removed an unnecessary parameter from the code.
facelessuser
 
Posts: 1549
Joined: Tue Apr 05, 2011 7:38 pm

Re: Coding folding does not work properly

Postby gregor.hoch on Fri Oct 28, 2011 1:55 pm

Thanks for posting this. I also hope that it gets addressed in the core ST2 considering that most popular languages don't use indentation like Python does...
gregor.hoch
 
Posts: 143
Joined: Sat Oct 01, 2011 7:54 pm

Re: Coding folding does not work properly

Postby facelessuser on Fri Oct 28, 2011 3:16 pm

No problem. I hope this gets addressed as well. I personally think folding by indentation should be the exception to the rule. Most languages are not indentation sensitive.

I work for a big cooperation, so a lot of people modify the same code, so we get some weird indentation in many places. It seems there are many people who are not sensitive to indentation as well.

I personally think folding by brackets should be the default with a setting that allows you to keep a list of languages you would like use folding by indentation. We have an internal scripting language that doesn't really use brackets for function blocks, so I still think that indentation folding is still a needed option, just not the only needed option.
facelessuser
 
Posts: 1549
Joined: Tue Apr 05, 2011 7:38 pm


Return to General Discussion

Who is online

Users browsing this forum: thyresias and 37 guests