<s> import re <EOL> import sublime <EOL> import sublime_plugin <EOL> class IndentListItemCommand ( sublime_plugin . TextCommand ) : <EOL> bullet_pattern = r'<STR_LIT>' <EOL> bullet_pattern_re = re . compile ( bullet_pattern ) <EOL> line_pattern_re = re . compile ( r'<STR_LIT>' + bullet_pattern ) <EOL> spaces_re = re . compile ( r'<STR_LIT>' ) <EOL> def run ( self , edit , reverse = False ) : <EOL> for region in self . view . sel ( ) : <EOL> if region . a != region . b : <EOL> continue <EOL> line = self . view . line ( region ) <EOL> line_content = self . view . substr ( line ) <EOL> new_line = line_content <EOL> m = self . line_pattern_re . match ( new_line ) <EOL> if not m : <EOL> return <EOL> tab_str = self . view . settings ( ) . get ( '<STR_LIT>' , <NUM_LIT:4> ) * '<STR_LIT:U+0020>' <EOL> sep_str = '<STR_LIT:U+0020>' if m . group ( <NUM_LIT:4> ) else '<STR_LIT>' <EOL> prev_line = self . view . line ( sublime . Region ( line . begin ( ) - <NUM_LIT:1> , line . begin ( ) - <NUM_LIT:1> ) ) <EOL> prev_line_content = self . view . substr ( prev_line ) <EOL> prev_prev_line = self . view . line ( sublime . Region ( prev_line . begin ( ) - <NUM_LIT:1> , prev_line . begin ( ) - <NUM_LIT:1> ) ) <EOL> prev_prev_line_content = self . view . substr ( prev_prev_line ) <EOL> if not reverse : <EOL> new_line = self . bullet_pattern_re . sub ( tab_str + sep_str + r'<STR_LIT>' , new_line ) <EOL> if prev_line_content : <EOL> new_line = '<STR_LIT:\n>' + new_line <EOL> else : <EOL> if not new_line . startswith ( tab_str ) : <EOL> continue <EOL> new_line = re . sub ( tab_str + sep_str + self . bullet_pattern , r'<STR_LIT>' , new_line ) <EOL> if prev_line_content : <EOL> new_line = '<STR_LIT:\n>' + new_line <EOL> else : <EOL> prev_spaces = self . spaces_re . match ( prev_prev_line_content ) . group ( <NUM_LIT:0> ) <EOL> spaces = self . spaces_re . match ( new_line ) . group ( <NUM_LIT:0> ) <EOL> if prev_spaces == spaces : <EOL> line = sublime . Region ( line . begin ( ) - <NUM_LIT:1> , line . end ( ) ) <EOL> endings = [ '<STR_LIT:.>' , '<STR_LIT:)>' ] <EOL> if self . view . settings ( ) . get ( '<STR_LIT>' , True ) : <EOL> bullets = self . view . settings ( ) . get ( '<STR_LIT>' , [ '<STR_LIT:*>' , '<STR_LIT:->' , '<STR_LIT:+>' ] ) <EOL> def change_bullet ( m ) : <EOL> bullet = m . group ( <NUM_LIT:1> ) <EOL> try : <EOL> return bullets [ ( bullets . index ( bullet ) + ( <NUM_LIT:1> if not reverse else - <NUM_LIT:1> ) ) % len ( bullets ) ] <EOL> except ValueError : <EOL> pass <EOL> n = m . group ( <NUM_LIT:2> ) <EOL> ending = endings [ ( endings . index ( m . group ( <NUM_LIT:4> ) ) + ( <NUM_LIT:1> if not reverse else - <NUM_LIT:1> ) ) % len ( endings ) ] <EOL> if n . isdigit ( ) : <EOL> return '<STR_LIT>' + ending <EOL> elif n != '<STR_LIT:#>' : <EOL> return '<STR_LIT>' + ending <EOL> return m . group ( <NUM_LIT:2> ) + ending <EOL> new_line = self . bullet_pattern_re . sub ( change_bullet , new_line ) <EOL> self . view . replace ( edit , line , '<STR_LIT>' ) <EOL> self . view . run_command ( '<STR_LIT>' , { '<STR_LIT>' : new_line } ) <EOL> def is_enabled ( self ) : <EOL> return bool ( self . view . score_selector ( self . view . sel ( ) [ <NUM_LIT:0> ] . a , '<STR_LIT>' ) ) </s>
