<s> import sublime , sublime_plugin <EOL> class SelectQuoted ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit , around = False ) : <EOL> selections = self . view . sel ( ) <EOL> newSel = [ ] <EOL> for originalRegion in selections : <EOL> region = originalRegion if originalRegion . a <= originalRegion . b else sublime . Region ( originalRegion . b , originalRegion . a ) <EOL> newRegion = self . getStringRegion ( region , around ) <EOL> if newRegion is None : <EOL> newSel . append ( originalRegion ) <EOL> else : <EOL> newRegion = newRegion if originalRegion . a <= originalRegion . b else sublime . Region ( newRegion . b , newRegion . a ) <EOL> newSel . append ( newRegion ) <EOL> selections . clear ( ) <EOL> for reg in newSel : <EOL> selections . add ( reg ) <EOL> def getStringRegion ( self , region , around = False ) : <EOL> """<STR_LIT>""" <EOL> region = sublime . Region ( region . a , max ( region . a , region . b - <NUM_LIT:1> ) ) <EOL> for pos in range ( region . a , region . b + <NUM_LIT:1> ) : <EOL> if self . view . score_selector ( pos , "<STR_LIT>" ) <= <NUM_LIT:0> : <EOL> return None <EOL> if self . view . score_selector ( region . a , "<STR_LIT>" ) > <NUM_LIT:0> : <EOL> around = True <EOL> if self . view . score_selector ( region . b , "<STR_LIT>" ) > <NUM_LIT:0> : <EOL> around = True <EOL> if ( self . view . score_selector ( region . a - <NUM_LIT:1> , "<STR_LIT>" ) > <NUM_LIT:0> and <EOL> self . view . score_selector ( region . b + <NUM_LIT:1> , "<STR_LIT>" ) > <NUM_LIT:0> ) : <EOL> around = True <EOL> if around : <EOL> shouldExpandA = lambda a : ( ( not ( self . view . score_selector ( a , "<STR_LIT>" ) > <NUM_LIT:0> and not self . view . score_selector ( a - <NUM_LIT:1> , "<STR_LIT>" ) > <NUM_LIT:0> ) ) and ( self . view . score_selector ( a - <NUM_LIT:1> , "<STR_LIT>" ) > <NUM_LIT:1> ) ) <EOL> shouldExpandB = lambda b : ( ( not ( self . view . score_selector ( b - <NUM_LIT:1> , "<STR_LIT>" ) > <NUM_LIT:0> and not self . view . score_selector ( b , "<STR_LIT>" ) > <NUM_LIT:0> ) ) and ( self . view . score_selector ( b , "<STR_LIT>" ) > <NUM_LIT:1> ) ) <EOL> else : <EOL> shouldExpandA = lambda a : ( ( not self . view . score_selector ( a - <NUM_LIT:1> , "<STR_LIT>" ) > <NUM_LIT:0> ) and ( self . view . score_selector ( a - <NUM_LIT:1> , "<STR_LIT>" ) > <NUM_LIT:1> ) ) <EOL> shouldExpandB = lambda b : ( ( not self . view . score_selector ( b , "<STR_LIT>" ) > <NUM_LIT:0> ) and ( self . view . score_selector ( b , "<STR_LIT>" ) > <NUM_LIT:1> ) ) <EOL> expandedRegion = sublime . Region ( region . a , region . b ) <EOL> expandedA = region . a <EOL> expandedB = region . b <EOL> while shouldExpandA ( expandedA ) : <EOL> expandedA = expandedA - <NUM_LIT:1> <EOL> while shouldExpandB ( expandedB ) : <EOL> expandedB = expandedB + <NUM_LIT:1> <EOL> return sublime . Region ( expandedA , expandedB ) <EOL> def description ( self , around = False ) : <EOL> if around : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" </s>
