Forked from robertcollier4/expand_selection_to_delims.py
Created
November 6, 2013 04:38
-
-
Save caoer/7330970 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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