ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Fold​Functions

by math2001 ST3

Sublime Text plugin to fold functions. And it supports functions with arguments on more than one line!

Details

Installs

  • Total 4K
  • Win 2K
  • Mac 748
  • Linux 801
Feb 18 Feb 17 Feb 16 Feb 15 Feb 14 Feb 13 Feb 12 Feb 11 Feb 10 Feb 9 Feb 8 Feb 7 Feb 6 Feb 5 Feb 4 Feb 3 Feb 2 Feb 1 Jan 31 Jan 30 Jan 29 Jan 28 Jan 27 Jan 26 Jan 25 Jan 24 Jan 23 Jan 22 Jan 21 Jan 20 Jan 19 Jan 18 Jan 17 Jan 16 Jan 15 Jan 14 Jan 13 Jan 12 Jan 11 Jan 10 Jan 9 Jan 8 Jan 7 Jan 6 Jan 5 Jan 4
Windows 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Mac 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

Readme

Source
raw.​githubusercontent.​com

FoldFunctions

This package folds every functions in the current file, so that you can have a global view of it, and then unfold a few, so that you don't have to scroll a lot, skipping over the functions you're not interested in at the moment.

For now, the following language are supported:

  • Python :heart:
  • JavaScript

The good part is that it supports arguments on multiple lines, like so (in this case, it's python):

def my_function(argument_number_one, argument_number_two,
                argument_number_three):
    print('It works!!')

    for i in range(10):
        print('It really does!')

Example of folding with this package - FoldFunctions - through the command palette of Sublime Text

Installation

Because it is not available on package control for now, you have to add this repo “manually” to your list.

Using package control

  1. Open up the command palette (ctrl+shift+p), and find Package Control: Add Repository. Then enter the URL of this repo: https://github.com/math2001/FoldFunctions in the input field.
  2. Open up the command palette again and find Package Control: Install Package, and just search for FoldFunctions. (just a normal install)

Using the command line

cd "%APPDATA%\Sublime Text 3\Packages"             # on window
cd ~/Library/Application\ Support/Sublime\ Text\ 3 # on mac
cd ~/.config/sublime-text-3                        # on linux

git clone "https://github.com/math2001/FoldFunctions"

Which solution do I choose?

It depends of your needs:

  • If you intend to just use FoldFunctions, then pick the first solution (Package Control), you'll get automatic update.
  • On the opposite side, if you want to tweak it, use the second solution. Note that, to get updates, you'll have to git pull

Usage

The command is accessible from the command palette.

  • ctrl+shift+p
  • Search for Fold Functions
  • hit enter

Note: The caption will be the same, whichever supported language file you are editing, but the actual command will change. :wink:

Adding a key binding

It's up to you, but I prefer to have this command bound to this command, in my case, alt+f. So, here's what I've done:

{
    "keys": ["alt+f"],
    "command": "fold_python_functions",
    "context": [
        {"key": "selector", "operand": "source.python"}
    ]
},
{
    "keys": ["alt+f"],
    "command": "fold_javascript_functions",
    "context": [
        {"key": "selector", "operand": "source.js"}
    ]
}