Skip to content

Commit

Permalink
New: ability to refold
Browse files Browse the repository at this point in the history
  • Loading branch information
titoBouzout committed Mar 13, 2012
1 parent 0082fd9 commit 1dc9cbc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
21 changes: 19 additions & 2 deletions BufferScroll.py
Expand Up @@ -128,6 +128,10 @@ def save(self, view, where):
# # bookmarks
db[id]['b'] = [[item.a, item.b] for item in view.get_regions("bookmarks")]

# previous folding save, to be able to refold
if 'f' in db[id] and list(db[id]['f']) != []:
db[id]['pf'] = list(db[id]['f'])

# folding
if int(sublime.version()) >= 2167:
db[id]['f'] = [[item.a, item.b] for item in view.folded_regions()]
Expand Down Expand Up @@ -236,7 +240,20 @@ def restore(self, view, where):
else:
view.set_viewport_position(tuple(db[id]['l']['0']), False)

class buffer_scroll_forget(sublime_plugin.ApplicationCommand):
class BufferScrollForget(sublime_plugin.ApplicationCommand):
def run(self, what):
if what == 'color_scheme':
sublime.active_window().active_view().settings().erase('color_scheme')
sublime.active_window().active_view().settings().erase('color_scheme')

class BufferScrollReFold(sublime_plugin.WindowCommand):
def run(self):
view = sublime.active_window().active_view()
if view:
id, index = BufferScroll().view_id(view)
if id in db:
if 'pf' in db[id]:
rs = []
for r in db[id]['pf']:
rs.append(sublime.Region(int(r[0]), int(r[1])))
if len(rs):
view.fold(rs)
17 changes: 17 additions & 0 deletions Main.sublime-menu
@@ -1,4 +1,21 @@
[
{
"caption": "Edit",
"mnemonic": "E",
"id": "edit",
"children":
[
{
"caption": "Code Folding",
"id": "fold",
"children":
[
{"caption":"-"},
{ "caption": "Refold", "command": "buffer_scroll_re_fold" }
]
}
]
},
{
"caption": "Preferences",
"mnemonic": "n",
Expand Down

0 comments on commit 1dc9cbc

Please sign in to comment.