Sublime Forum

Fold all code at open file

#1

Hi, I have two questions.
First, there is a configuration to when open a file folding all codes (for any file type)?
Second, there is a configuration to save all points of code folds that I do in file and save in the current instance of Sublime? For example: I fold 2 functions, save file and close application with file opened in Sublime, after when I open Sublime again, open the file with same 2 functions folded?

1 Like

#2

#[1]

##@ Packages\PluginDirectory\PluginName.py

import sublime, sublime_plugin

class EventListener( sublime_plugin.EventListener ):

	def on_load ( self, view ):

		view.run_command ( "fold_by_level", { "level": 1 } )
		# set "level" to your preference

#[2]

##Try BufferScroll

( I haven’t used it yet, but it’s in my queue of plugins to check out for the same reason you asked about )

2 Likes

#3

@fico

I tried the method [1] that described and could not make it work, can help to work?
The BufferScroll described in method [2] works fine, saving all points of code folds and bookmarks

0 Likes

#4

I’m not too sure what the issue could be. I have some additional code in the file where I tested it; but I tried commenting everything else out & it still works fine.

What is the full path where you placed the file? Mine is @:

C:\Users\__USER_NAME__\AppData\Roaming\Sublime Text 3\Packages\DevTools\DevTools.py
0 Likes

#5

@fico I use debian, save the file in /Packages/PluginDirectory\PluginName.py as u said and need configure any keybind?

0 Likes

#6

No keybinding is required, as the entire function is contained within the listener. There are no commands that can be called in that file.

Not sure if it matters, but I use ST3 & Windows 10. Are you using ST2 by any chance?

0 Likes

#7

I just save the code that u post but the eventListener don’t work when load a file.

I using ST3 and Debian Jessie

0 Likes

#8

@fico
Checking again where I saved the code [1] and move directory to ~/.config/sublime-text-3/Packages/User work’s fine. I also changed fold_by_level to fold_all
Thanks for help

2 Likes

#9

It worked for me on ST2 (placing the PluginName.py file in ~/.config/sublime-text-2/Packages/User directory), thank you very much, you saved me a lot of folding time :slight_smile:

0 Likes

#10

Just to assure visitors on this date that the code given in the Solution #1 by Fico works perfectly alright.
For Linux ST3, Just copy the given code above, paste into a file (name of your choice with “py” extension) and save that into “~/.config/sublime-text/Packages/User/”
This should do the trick. Open any file. If it doesn’t work as desired, you may have to restart your ST3. That’s it.

0 Likes