[quote=“quarnster”]I did this for my ADB logcat plugin. It shouldn’t be too hard for someone to adapt it to a separate plugin. Cutting and pasting the relevant code bit:
view.run_command("unfold_all")
endline, endcol = view.rowcol(view.size())
line = 0
currRegion = None
regions = ]
while line < endline:
region = view.full_line(view.text_point(line, 0))
data = view.substr(region)
if self.filter.search(data) == None:
if currRegion == None:
currRegion = region
else:
currRegion = currRegion.cover(region)
else:
if currRegion:
regions.append(currRegion)
currRegion = None
line += 1
if currRegion:
regions.append(currRegion)
view.fold(regions)
[/quote]
Outstanding. I cobbled this together despite my horrible Python skills. I called it All because that’s what it was called back on the mainframe.
import sublime, sublime_plugin
class AllCommand(sublime_plugin.TextCommand):
def done(self,arg):
self.foldstr = arg
self.all()
def change(self,arg):
pass
def cancel(self):
pass
def all(self):
view = self.view
view.run_command("unfold_all")
endline, endcol = view.rowcol(view.size())
line = 0
currRegion = None
regions = ]
while line < endline:
region = view.full_line(view.text_point(line, 0))
data = view.substr(region)
if data.find(self.foldstr) == -1:
if currRegion == None:
currRegion = region
else:
currRegion = currRegion.cover(region)
else:
if currRegion:
regions.append(currRegion)
currRegion = None
line += 1
if currRegion:
regions.append(currRegion)
view.fold(regions)
def run(self, edit):
window = self.view.window()
window.show_input_panel("Fold Away Except","",self.done,self.change,self.cancel)
Thanks for your help.