Sublime Forum

Fold Python functions with indented line?

#1

If I define a function like this:

def func1(var1, var2, var3):
    """
    """
    # do something
    return

the code folding works as expected, and it lets me fold the entire function.

But if the function contains many variables, to comply with PEP8 (https://www.python.org/dev/peps/pep-0008/) I have to put the variables in a second line, like so:

def func1(
        var1, var2, var3, var4, var5, var6, var7, ...):
    """
    """
    # do something
    return

The indentation of the variables line prevents the code folding from working. Is there any way around this that doesn’t involve a PEP8 violation?

Thanks!

2 Likes

#2

Yes, there is! Since you seem to code in python, why don’t you make your own Sublime Text plugin that does this?

I tried to do the exact same, but I wanted it to work with JavaScript too, which is a bad idea.

If you have any trouble with making it, ask me (or anyone else) after you’ve done a bit of research, and we’ll help you out!

Good luck!

Hum… I decided to have a quick crack at it. It’s dirty but it works. Here it is: https://github.com/math2001/FoldFunctions

2 Likes

#3

Wonderful thank you very much Math! Will it be available through https://packagecontrol.io/ soon?

0 Likes

#4

Didn’t plan on doing that, but yes, maybe :smile:

0 Likes

#5

Thanks! It’d be great if you did. It’s simpler to manage, not having individual repos for each installed package.

0 Likes

#6

Here you go: https://github.com/wbond/package_control_channel/pull/6376 Now we just someone to merge it.. It’s been merged.

1 Like

#7

Great, thank you! I’ll wait for the package to show up and install it.

0 Likes