Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save caoer/7330970 to your computer and use it in GitHub Desktop.
Save caoer/7330970 to your computer and use it in GitHub Desktop.
import sublime, sublime_plugin, os
class ExpandSelectionToDelimsCommand(sublime_plugin.TextCommand):
def run(self, edit):
begindelims = ["\"", "\'", "(", "<", "[", "{"]
enddelims = ["\"", "\'", ")", ">", "]", "}"]
view = self.view
oldSelRegions = list(view.sel())
for thisregion in oldSelRegions:
thisRegionBegin = thisregion.begin() - 1
thisRegionEnd = thisregion.end()
if( (thisregion.begin() != thisRegionEnd) and (view.substr(thisRegionBegin) in begindelims) ):
thisRegionBegin -= 1
while ((view.substr(thisRegionBegin) not in begindelims) and (thisRegionBegin >= 0)):
thisRegionBegin -= 1
thisRegionBegin += 1
if( (thisregion.begin() != thisRegionEnd) and (view.substr(thisRegionEnd) in enddelims) ):
thisRegionEnd += 1
while((view.substr(thisRegionEnd) not in enddelims) and (thisRegionEnd < view.size())):
thisRegionEnd += 1
view.sel().add(sublime.Region(thisRegionBegin, thisRegionEnd))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment