Sublime Forum

Fold all functions in a file

#1

How can I fold all the functions in a file?

Right now when I use the “Fold all” command, it folds all the functions except the function that my caret is currently in.

Is this a bug? I would think that fold all would simply fold all…

How can I have fold all, actually…fold all.

0 Likes

#2

Hi!

I’ve done a little plugin that fold all the functions: https://github.com/math2001/st-user-package/blob/master/fold_function.py

Create a file in your user directory, and paste the code.

Add a key binding:

{ "keys": ["alt+f"], "command": "fold_function" }

Matt

0 Likes

#3

Thanks I will give it a try!

EDIT: It didn’t do anything in a c++ source file.

0 Likes

#4

That might be because it’s finding functions by checking for the scope meta.function, but in C++ classes the methods use the scope meta.method. Functions still show up as functions, so for completeness it should probably check for both of them.

0 Likes

#5

Hi!

It is because you type your code like this:

ContactUser *ContactsModel::contact(int row) const
{
    return contacts.value(row);
}

And not like this (like I do):

ContactUser *ContactsModel::contact(int row) const {
    return contacts.value(row);
}

So, I just added a condition that should fix this. Update the code from the same file (link just above)

Thanks @OdatNurd: I now use entity.name.function

Matt

0 Likes