<s> import re , sys <EOL> import functools as fu <EOL> import sublime , sublime_plugin <EOL> from copy import copy <EOL> if sublime . version ( ) < '<STR_LIT>' : <EOL> _ST3 = False <EOL> import paragraph <EOL> import sbp_layout as ll <EOL> else : <EOL> _ST3 = True <EOL> import Default . paragraph as paragraph <EOL> from . import sbp_layout as ll <EOL> REGION_FIND = "<STR_LIT>" <EOL> REGION_SELECTED = "<STR_LIT>" <EOL> JOVE_STATUS = "<STR_LIT>" <EOL> default_sbp_sexpr_separators = "<STR_LIT>" ; <EOL> default_sbp_word_separators = "<STR_LIT>" ; <EOL> ensure_visible_cmds = set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> kill_cmds = set ( ) <EOL> repeatable_cmds = set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def pluralize ( string , count , es = "<STR_LIT:s>" ) : <EOL> if count == <NUM_LIT:1> : <EOL> return "<STR_LIT>" % ( count , string ) <EOL> else : <EOL> return "<STR_LIT>" % ( count , string , es ) <EOL> class SettingsManager : <EOL> def get ( key , default = None ) : <EOL> global_settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> settings = sublime . active_window ( ) . active_view ( ) . settings ( ) <EOL> return settings . get ( key , global_settings . get ( key , default ) ) <EOL> class KillRing : <EOL> KILL_RING_SIZE = <NUM_LIT:64> <EOL> class Kill ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , regions ) : <EOL> self . regions = regions <EOL> self . n_regions = len ( regions ) <EOL> def join_if_possible ( self , regions , forward ) : <EOL> if len ( regions ) != self . n_regions : <EOL> return False <EOL> for i , c in enumerate ( regions ) : <EOL> if forward : <EOL> self . regions [ i ] += regions [ i ] <EOL> else : <EOL> self . regions [ i ] = regions [ i ] + self . regions [ i ] <EOL> return True <EOL> def set_clipboard ( self ) : <EOL> sublime . set_clipboard ( self . regions [ <NUM_LIT:0> ] ) <EOL> def same_as ( self , regions ) : <EOL> if len ( regions ) != self . n_regions : <EOL> return False <EOL> for me , him in zip ( regions , self . regions ) : <EOL> if me != him : <EOL> return False <EOL> return True <EOL> def __init__ ( self ) : <EOL> self . entries = [ None ] * self . KILL_RING_SIZE <EOL> self . index = <NUM_LIT:0> <EOL> self . pop_index = None <EOL> def add ( self , regions , forward , join ) : <EOL> total_bytes = sum ( ( len ( c ) for c in regions ) ) <EOL> if total_bytes == <NUM_LIT:0> : <EOL> return <EOL> index = self . index <EOL> try : <EOL> if not join : <EOL> if self . entries [ index ] and self . entries [ index ] . same_as ( regions ) : <EOL> return <EOL> else : <EOL> if self . entries [ index ] and self . entries [ index ] . join_if_possible ( regions , forward ) : <EOL> return <EOL> index = ( index + <NUM_LIT:1> ) % self . KILL_RING_SIZE <EOL> self . entries [ index ] = KillRing . Kill ( regions ) <EOL> finally : <EOL> self . index = index <EOL> self . entries [ index ] . set_clipboard ( ) <EOL> def get_current ( self , n_regions , pop ) : <EOL> entries = self . entries <EOL> clipboard = result = None <EOL> if pop == <NUM_LIT:0> : <EOL> index = self . index <EOL> entry = entries [ index ] <EOL> if n_regions == <NUM_LIT:1> : <EOL> clipboard = sublime . get_clipboard ( ) <EOL> if clipboard and ( entry is None or entry . n_regions != <NUM_LIT:1> or entry . regions [ <NUM_LIT:0> ] != clipboard ) : <EOL> result = [ clipboard ] <EOL> self . add ( result , True , False ) <EOL> elif entries [ index ] : <EOL> result = entries [ index ] . regions <EOL> self . pop_index = None <EOL> else : <EOL> if self . pop_index is None : <EOL> self . pop_index = self . index <EOL> incr = - <NUM_LIT:1> if pop > <NUM_LIT:0> else <NUM_LIT:1> <EOL> index = ( self . pop_index + incr ) % self . KILL_RING_SIZE <EOL> while entries [ index ] is None : <EOL> if index == self . pop_index : <EOL> return None <EOL> index = ( index + incr ) % self . KILL_RING_SIZE <EOL> self . pop_index = index <EOL> result = entries [ index ] . regions <EOL> entries [ index ] . set_clipboard ( ) <EOL> while len ( result ) < n_regions : <EOL> result *= <NUM_LIT:2> <EOL> return result [ <NUM_LIT:0> : n_regions ] <EOL> kill_ring = KillRing ( ) <EOL> class MarkRing : <EOL> MARK_RING_SIZE = <NUM_LIT:16> <EOL> def __init__ ( self , view ) : <EOL> self . view = view <EOL> self . index = <NUM_LIT:0> <EOL> self . view . erase_regions ( "<STR_LIT>" ) <EOL> for i in range ( self . MARK_RING_SIZE ) : <EOL> self . view . erase_regions ( self . get_key ( i ) ) <EOL> def get_key ( self , index ) : <EOL> return "<STR_LIT>" + str ( index ) <EOL> def clear ( self ) : <EOL> self . view . erase_regions ( "<STR_LIT>" ) <EOL> def has_visible_mark ( self ) : <EOL> return self . view . get_regions ( "<STR_LIT>" ) != None and len ( self . view . get_regions ( "<STR_LIT>" ) ) > <NUM_LIT:0> <EOL> def display ( self ) : <EOL> regions = self . get ( ) <EOL> if regions is not None : <EOL> self . view . add_regions ( "<STR_LIT>" , regions , "<STR_LIT>" , "<STR_LIT>" , sublime . HIDDEN ) <EOL> def get ( self ) : <EOL> return self . view . get_regions ( self . get_key ( self . index ) ) <EOL> def set ( self , regions , reuse_index = False ) : <EOL> if self . get ( ) == regions : <EOL> return <EOL> if not reuse_index : <EOL> self . index = ( self . index + <NUM_LIT:1> ) % self . MARK_RING_SIZE <EOL> self . view . add_regions ( self . get_key ( self . index ) , regions , "<STR_LIT>" , "<STR_LIT>" , sublime . HIDDEN ) <EOL> self . display ( ) <EOL> def exchange ( self , regions ) : <EOL> current = self . get ( ) <EOL> if current is not None : <EOL> self . set ( regions , True ) <EOL> return current <EOL> def pop ( self ) : <EOL> regions = self . get ( ) <EOL> start = self . index <EOL> while True : <EOL> self . index -= <NUM_LIT:1> <EOL> if self . index < <NUM_LIT:0> : <EOL> self . index = self . MARK_RING_SIZE - <NUM_LIT:1> <EOL> if self . get ( ) or self . index == start : <EOL> break <EOL> self . display ( ) <EOL> return regions <EOL> isearch_info = dict ( ) <EOL> def isearch_info_for ( view ) : <EOL> if isinstance ( view , sublime . Window ) : <EOL> window = view <EOL> else : <EOL> window = view . window ( ) <EOL> if window : <EOL> return isearch_info . get ( window . id ( ) , None ) <EOL> return None <EOL> def set_isearch_info_for ( view , info ) : <EOL> window = view . window ( ) <EOL> isearch_info [ window . id ( ) ] = info <EOL> return info <EOL> def clear_isearch_info_for ( view ) : <EOL> window = view . window ( ) <EOL> del ( isearch_info [ window . id ( ) ] ) <EOL> class ViewState ( ) : <EOL> view_state_dict = dict ( ) <EOL> current = None <EOL> def __init__ ( self , view ) : <EOL> self . view = view <EOL> self . active_mark = False <EOL> self . mark_ring = MarkRing ( view ) <EOL> self . reset ( ) <EOL> @ classmethod <EOL> def on_view_closed ( cls , view ) : <EOL> if view . id ( ) in cls . view_state_dict : <EOL> del ( cls . view_state_dict [ view . id ( ) ] ) <EOL> @ classmethod <EOL> def get ( cls , view ) : <EOL> if ViewState . current is None or ViewState . current . view != view : <EOL> state = cls . view_state_dict . get ( view . id ( ) , None ) <EOL> if state is None : <EOL> state = ViewState ( view ) <EOL> cls . view_state_dict [ view . id ( ) ] = state <EOL> state . view = view <EOL> ViewState . current = state <EOL> return ViewState . current <EOL> def reset ( self ) : <EOL> self . this_cmd = None <EOL> self . last_cmd = None <EOL> self . argument_supplied = False <EOL> self . argument_value = <NUM_LIT:0> <EOL> self . argument_negative = False <EOL> self . drag_count = <NUM_LIT:0> <EOL> self . entered = <NUM_LIT:0> <EOL> def get_count ( self , peek = False ) : <EOL> if self . argument_supplied : <EOL> count = self . argument_value <EOL> if self . argument_negative : <EOL> if count == <NUM_LIT:0> : <EOL> count = - <NUM_LIT:1> <EOL> else : <EOL> count = - count <EOL> if not peek : <EOL> self . argument_negative = False <EOL> if not peek : <EOL> self . argument_supplied = False <EOL> else : <EOL> count = <NUM_LIT:1> <EOL> return count <EOL> def last_was_kill_cmd ( self ) : <EOL> return self . last_cmd in kill_cmds <EOL> class ViewWatcher ( sublime_plugin . EventListener ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ViewWatcher , self ) . __init__ ( * args , ** kwargs ) <EOL> self . pending_dedups = <NUM_LIT:0> <EOL> def on_close ( self , view ) : <EOL> ViewState . on_view_closed ( view ) <EOL> def on_modified ( self , view ) : <EOL> CmdUtil ( view ) . toggle_active_mark_mode ( False ) <EOL> def on_activated_async ( self , view ) : <EOL> info = isearch_info_for ( view ) <EOL> if info and not view . settings ( ) . get ( "<STR_LIT>" ) : <EOL> info . done ( ) <EOL> def on_query_context ( self , view , key , operator , operand , match_all ) : <EOL> def test ( a ) : <EOL> if operator == sublime . OP_EQUAL : <EOL> return a == operand <EOL> if operator == sublime . OP_NOT_EQUAL : <EOL> return a != operand <EOL> return False <EOL> if key == "<STR_LIT>" : <EOL> return test ( isearch_info_for ( view ) is not None ) <EOL> if key == "<STR_LIT>" : <EOL> if not SettingsManager . get ( "<STR_LIT>" , False ) : <EOL> return False <EOL> return CmdUtil ( view ) . state . mark_ring . has_visible_mark ( ) == operand <EOL> if key == "<STR_LIT>" : <EOL> return test ( SettingsManager . get ( "<STR_LIT>" ) ) <EOL> if key == "<STR_LIT>" : <EOL> return test ( SettingsManager . get ( "<STR_LIT>" ) ) <EOL> if key == "<STR_LIT>" : <EOL> return test ( SettingsManager . get ( "<STR_LIT>" ) or not SettingsManager . get ( "<STR_LIT>" ) ) <EOL> if key == '<STR_LIT>' : <EOL> return test ( CmdUtil ( view ) . has_prefix_arg ( ) ) <EOL> def on_post_save ( self , view ) : <EOL> self . pending_dedups += <NUM_LIT:1> <EOL> def doit ( ) : <EOL> self . pending_dedups -= <NUM_LIT:1> <EOL> if self . pending_dedups == <NUM_LIT:0> : <EOL> dedup_views ( sublime . active_window ( ) ) <EOL> sublime . set_timeout ( doit , <NUM_LIT:50> ) <EOL> class CmdWatcher ( sublime_plugin . EventListener ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( CmdWatcher , self ) . __init__ ( * args , ** kwargs ) <EOL> def on_anything ( self , view ) : <EOL> view . erase_status ( JOVE_STATUS ) <EOL> def on_window_command ( self , window , cmd , args ) : <EOL> info = isearch_info_for ( window ) <EOL> def check ( ) : <EOL> if info is not None and window . active_view ( ) != info . view : <EOL> info . done ( ) <EOL> if info is not None : <EOL> sublime . set_timeout ( check , <NUM_LIT:0> ) <EOL> def on_text_command ( self , view , cmd , args ) : <EOL> if isearch_info_for ( view ) is not None : <EOL> if cmd not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return ( '<STR_LIT>' , { '<STR_LIT>' : cmd , '<STR_LIT>' : args } ) <EOL> return <EOL> vs = ViewState . get ( view ) <EOL> self . on_anything ( view ) <EOL> if args is None : <EOL> args = { } <EOL> if not cmd . startswith ( "<STR_LIT>" ) : <EOL> vs . this_cmd = cmd <EOL> if cmd == '<STR_LIT>' : <EOL> info = isearch_info_for ( view ) <EOL> if info : <EOL> info . done ( ) <EOL> vs . drag_count = <NUM_LIT:2> if '<STR_LIT>' in args else <NUM_LIT:0> <EOL> if cmd in ( '<STR_LIT>' , '<STR_LIT>' ) and vs . active_mark and not args . get ( '<STR_LIT>' , False ) : <EOL> args [ '<STR_LIT>' ] = True <EOL> return ( cmd , args ) <EOL> if not vs . argument_supplied : <EOL> return None <EOL> if cmd in repeatable_cmds : <EOL> count = vs . get_count ( ) <EOL> args . update ( { <EOL> '<STR_LIT>' : cmd , <EOL> '<STR_LIT>' : abs ( count ) , <EOL> } ) <EOL> if count < <NUM_LIT:0> and '<STR_LIT>' in args : <EOL> args [ '<STR_LIT>' ] = not args [ '<STR_LIT>' ] <EOL> return ( "<STR_LIT>" , args ) <EOL> elif cmd == '<STR_LIT>' : <EOL> args [ '<STR_LIT>' ] *= vs . get_count ( ) <EOL> return ( cmd , args ) <EOL> def on_post_text_command ( self , view , cmd , args ) : <EOL> vs = ViewState . get ( view ) <EOL> cm = CmdUtil ( view ) <EOL> if vs . active_mark and vs . this_cmd != '<STR_LIT>' and vs . last_cmd == '<STR_LIT>' : <EOL> if cmd != "<STR_LIT>" : <EOL> cm . toggle_active_mark_mode ( False ) <EOL> if not cmd . startswith ( "<STR_LIT>" ) : <EOL> vs . argument_value = <NUM_LIT:0> <EOL> vs . argument_supplied = False <EOL> vs . last_cmd = cmd <EOL> if vs . active_mark : <EOL> cm . set_cursors ( cm . get_regions ( ) ) <EOL> if cmd in ensure_visible_cmds and cm . just_one_cursor ( ) : <EOL> cm . ensure_visible ( cm . get_last_cursor ( ) ) <EOL> def on_selection_modified ( self , view ) : <EOL> vs = ViewState . get ( view ) <EOL> selection = view . sel ( ) <EOL> if len ( selection ) == <NUM_LIT:1> and vs . this_cmd == '<STR_LIT>' : <EOL> cm = CmdUtil ( view , vs ) ; <EOL> if vs . drag_count == <NUM_LIT:2> : <EOL> region = view . sel ( ) [ <NUM_LIT:0> ] <EOL> cm . set_mark ( [ sublime . Region ( region . a ) ] , and_selection = False ) <EOL> cm . toggle_active_mark_mode ( True ) <EOL> elif vs . drag_count == <NUM_LIT:0> : <EOL> cm . toggle_active_mark_mode ( False ) <EOL> vs . drag_count += <NUM_LIT:1> <EOL> def on_modified ( self , view ) : <EOL> ViewState . get ( view ) . this_cmd = None <EOL> self . on_anything ( view ) <EOL> class WindowCmdWatcher ( sublime_plugin . EventListener ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( WindowCmdWatcher , self ) . __init__ ( * args , ** kwargs ) <EOL> def on_window_command ( self , window , cmd , args ) : <EOL> if cmd == "<STR_LIT>" and args and args [ '<STR_LIT>' ] == '<STR_LIT>' and '<STR_LIT>' not in args : <EOL> lm = ll . LayoutManager ( window . layout ( ) ) <EOL> if args [ "<STR_LIT>" ] == '<STR_LIT>' : <EOL> pos = lm . next ( window . active_group ( ) ) <EOL> else : <EOL> pos = lm . next ( window . active_group ( ) , - <NUM_LIT:1> ) <EOL> args [ "<STR_LIT>" ] = pos <EOL> return cmd , args <EOL> class CmdUtil : <EOL> def __init__ ( self , view , state = None , edit = None ) : <EOL> self . view = view <EOL> if state is None : <EOL> state = ViewState . get ( self . view ) <EOL> self . state = state <EOL> self . edit = edit <EOL> def set_status ( self , msg ) : <EOL> self . view . set_status ( JOVE_STATUS , msg ) <EOL> def get_point ( self ) : <EOL> sel = self . view . sel ( ) <EOL> if len ( sel ) > <NUM_LIT:0> : <EOL> return sel [ <NUM_LIT:0> ] . b <EOL> return - <NUM_LIT:1> <EOL> def reset_target_column ( self ) : <EOL> selection = self . view . sel ( ) <EOL> if len ( selection ) == <NUM_LIT:1> and selection [ <NUM_LIT:0> ] . empty ( ) and selection [ <NUM_LIT:0> ] . b < self . view . size ( ) : <EOL> self . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : True } ) <EOL> self . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : False } ) <EOL> def get_tab_size ( self ) : <EOL> return self . view . settings ( ) . get ( "<STR_LIT>" , <NUM_LIT:8> ) <EOL> def get_mark ( self ) : <EOL> mark = self . view . get_regions ( "<STR_LIT>" ) <EOL> if mark : <EOL> mark = mark [ <NUM_LIT:0> ] <EOL> return mark . a <EOL> def no_empty_regions ( self , regions ) : <EOL> for r in regions : <EOL> if r . empty ( ) : <EOL> return False <EOL> return True <EOL> def all_empty_regions ( self , regions ) : <EOL> for r in regions : <EOL> if not r . empty ( ) : <EOL> return False <EOL> return True <EOL> def get_regions ( self ) : <EOL> view = self . view <EOL> cursors = list ( view . sel ( ) ) <EOL> if not self . state . active_mark and self . no_empty_regions ( cursors ) : <EOL> return cursors <EOL> marks = self . view . get_regions ( "<STR_LIT>" ) <EOL> if len ( marks ) == len ( cursors ) : <EOL> regions = [ sublime . Region ( m . a , c . b ) for m , c in zip ( marks , cursors ) ] <EOL> for i , r in enumerate ( regions [ <NUM_LIT:1> : ] ) : <EOL> if r . intersects ( regions [ i ] ) : <EOL> self . set_status ( "<STR_LIT>" ) <EOL> return regions <EOL> self . set_status ( "<STR_LIT>" . format ( len ( marks ) , len ( cursors ) ) ) <EOL> def get_encompassing_region ( self ) : <EOL> regions = self . get_regions ( ) <EOL> if regions : <EOL> return sublime . Region ( regions [ <NUM_LIT:0> ] . begin ( ) , regions [ - <NUM_LIT:1> ] . end ( ) ) <EOL> return None <EOL> def save_cursors ( self , name ) : <EOL> cursors = self . get_cursors ( ) <EOL> if cursors : <EOL> cursors = [ sublime . Region ( c . b ) for c in cursors ] <EOL> self . view . add_regions ( name , cursors , "<STR_LIT>" , "<STR_LIT>" , sublime . HIDDEN ) <EOL> def restore_cursors ( self , name ) : <EOL> cursors = self . view . get_regions ( name ) <EOL> if cursors : <EOL> self . set_selection ( cursors ) <EOL> self . view . erase_regions ( name ) <EOL> def for_each_line ( self , region ) : <EOL> view = self . view <EOL> pos = region . begin ( ) <EOL> limit = region . end ( ) <EOL> if pos == limit : <EOL> limit += <NUM_LIT:1> <EOL> while pos < limit : <EOL> line = view . line ( pos ) <EOL> yield line <EOL> pos = line . end ( ) + <NUM_LIT:1> <EOL> def is_blank ( self , a , b ) : <EOL> text = self . view . substr ( sublime . Region ( a , b ) ) <EOL> return re . match ( r'<STR_LIT>' , text ) is not None <EOL> def get_line_indent ( self , pos ) : <EOL> data , col , region = self . get_line_info ( pos ) <EOL> m = re . match ( r'<STR_LIT>' , data ) <EOL> return ( len ( m . group ( <NUM_LIT:0> ) ) , col ) <EOL> def set_mark ( self , regions = None , update_status = True , and_selection = True ) : <EOL> view = self . view <EOL> mark_ring = self . state . mark_ring <EOL> if regions is None : <EOL> regions = self . get_cursors ( ) <EOL> mark_ring . set ( regions ) <EOL> if self . state . active_mark : <EOL> self . set_cursors ( self . get_regions ( ) ) <EOL> if update_status : <EOL> self . set_status ( "<STR_LIT>" ) <EOL> def set_active_mark_mode ( self ) : <EOL> self . set_cursors ( self . get_regions ( ) ) <EOL> self . state . active_mark = True <EOL> def toggle_active_mark_mode ( self , value = None ) : <EOL> if value is not None and self . state . active_mark == value : <EOL> return <EOL> self . state . active_mark = value if value is not None else ( not self . state . active_mark ) <EOL> if self . state . active_mark : <EOL> self . set_cursors ( self . get_regions ( ) ) <EOL> else : <EOL> self . make_cursors_empty ( ) <EOL> def swap_point_and_mark ( self ) : <EOL> view = self . view <EOL> mark_ring = self . state . mark_ring <EOL> mark = mark_ring . exchange ( self . get_cursors ( ) ) <EOL> if mark is not None : <EOL> self . set_cursors ( mark ) <EOL> if self . state . active_mark : <EOL> self . set_cursors ( self . get_regions ( ) ) <EOL> else : <EOL> self . set_status ( "<STR_LIT>" ) <EOL> def get_cursors ( self , begin = False ) : <EOL> return [ sublime . Region ( c . a if begin else c . b ) if not c . empty ( ) else c for c in self . view . sel ( ) ] <EOL> def count_cursors ( self ) : <EOL> return len ( self . view . sel ( ) ) <EOL> def get_last_cursor ( self ) : <EOL> return self . view . sel ( ) [ - <NUM_LIT:1> ] <EOL> def set_cursors ( self , regions , ensure_visible = True ) : <EOL> if not regions : <EOL> return <EOL> sel = self . view . sel ( ) <EOL> sel . clear ( ) <EOL> sel . add_all ( regions ) <EOL> if ensure_visible : <EOL> self . ensure_visible ( regions [ - <NUM_LIT:1> ] ) <EOL> def make_cursors_empty ( self ) : <EOL> selection = self . view . sel ( ) <EOL> cursors = [ sublime . Region ( c . b ) for c in selection ] <EOL> selection . clear ( ) <EOL> selection . add_all ( cursors ) <EOL> def set_selection ( self , regions ) : <EOL> if isinstance ( regions , sublime . Region ) : <EOL> regions = [ regions ] <EOL> selection = self . view . sel ( ) <EOL> selection . clear ( ) <EOL> selection . add_all ( regions ) <EOL> def get_line_info ( self , point ) : <EOL> view = self . view <EOL> region = view . line ( point ) <EOL> data = view . substr ( region ) <EOL> row , col = view . rowcol ( point ) <EOL> return ( data , col , region ) <EOL> def run_window_command ( self , cmd , args ) : <EOL> self . view . window ( ) . run_command ( cmd , args ) <EOL> def has_prefix_arg ( self ) : <EOL> return self . state . argument_supplied <EOL> def just_one_cursor ( self ) : <EOL> return len ( self . view . sel ( ) ) == <NUM_LIT:1> <EOL> def get_count ( self , peek = False ) : <EOL> return self . state . get_count ( peek ) <EOL> def for_each_cursor ( self , function , * args , ** kwargs ) : <EOL> view = self . view <EOL> selection = view . sel ( ) <EOL> regions = list ( selection ) <EOL> selection . clear ( ) <EOL> can_modify = kwargs . pop ( '<STR_LIT>' , False ) <EOL> if can_modify : <EOL> key = "<STR_LIT>" <EOL> view . add_regions ( key , regions , "<STR_LIT>" , "<STR_LIT>" , sublime . HIDDEN ) <EOL> for i in range ( len ( regions ) ) : <EOL> regions = view . get_regions ( key ) <EOL> if i >= len ( regions ) : <EOL> break <EOL> selection . add ( regions [ i ] ) <EOL> cursor = function ( regions [ i ] , * args , ** kwargs ) <EOL> selection . clear ( ) <EOL> cursors = view . get_regions ( key ) <EOL> view . erase_regions ( key ) <EOL> else : <EOL> cursors = [ ] <EOL> for i , cursor in enumerate ( regions ) : <EOL> selection . add ( cursor ) <EOL> cursor = function ( cursor , * args , ** kwargs ) <EOL> selection . clear ( ) <EOL> cursors . append ( cursor ) <EOL> selection . add_all ( cursors ) <EOL> def goto_line ( self , line ) : <EOL> if line >= <NUM_LIT:0> : <EOL> view = self . view <EOL> point = view . text_point ( line - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> self . push_mark_and_goto_position ( point ) <EOL> def push_mark_and_goto_position ( self , pos ) : <EOL> if self . get_point ( ) != pos : <EOL> self . set_mark ( ) <EOL> self . set_cursors ( [ sublime . Region ( pos ) ] , ensure_visible = True ) <EOL> if self . state . active_mark : <EOL> self . set_cursors ( self . get_regions ( ) ) <EOL> def is_visible ( self , pos ) : <EOL> visible = self . view . visible_region ( ) <EOL> return visible . contains ( pos ) <EOL> def ensure_visible ( self , cursor , force = False ) : <EOL> if force or not self . is_visible ( cursor . b ) : <EOL> self . view . show_at_center ( cursor . b ) <EOL> def is_word_char ( self , pos , forward , separators ) : <EOL> if not forward : <EOL> if pos == <NUM_LIT:0> : <EOL> return False <EOL> pos -= <NUM_LIT:1> <EOL> char = self . view . substr ( pos ) <EOL> return not ( char in "<STR_LIT>" or char in separators ) <EOL> def is_one_of ( self , pos , chars ) : <EOL> return self . view . substr ( pos ) in chars <EOL> def to_other_end ( self , point , direction ) : <EOL> brac = "<STR_LIT>" <EOL> kets = "<STR_LIT>" <EOL> view = self . view <EOL> scope_name = view . scope_name ( point ) <EOL> if scope_name . find ( "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> return None <EOL> ch = view . substr ( point ) <EOL> if direction > <NUM_LIT:0> and view . substr ( point ) in brac : <EOL> return self . run_command ( "<STR_LIT>" , { "<STR_LIT:to>" : "<STR_LIT>" } , point = point ) <EOL> elif direction < <NUM_LIT:0> and view . substr ( point - <NUM_LIT:1> ) in kets : <EOL> if point < view . size ( ) and view . substr ( point ) in brac : <EOL> return self . run_command ( "<STR_LIT>" , { "<STR_LIT:to>" : "<STR_LIT>" } , point = point - <NUM_LIT:1> ) - <NUM_LIT:1> <EOL> else : <EOL> return self . run_command ( "<STR_LIT>" , { "<STR_LIT:to>" : "<STR_LIT>" } , point = point ) <EOL> start = point + direction <EOL> self . run_command ( "<STR_LIT>" , { "<STR_LIT:to>" : "<STR_LIT>" } , point = start ) <EOL> r = view . sel ( ) [ <NUM_LIT:0> ] <EOL> return r . end ( ) if direction > <NUM_LIT:0> else r . begin ( ) <EOL> def run_command ( self , cmd , args , point = None ) : <EOL> view = self . view <EOL> if point is not None : <EOL> view . sel ( ) . clear ( ) <EOL> view . sel ( ) . add ( sublime . Region ( point , point ) ) <EOL> view . run_command ( cmd , args ) <EOL> return self . get_point ( ) <EOL> class SbpTextCommand ( sublime_plugin . TextCommand ) : <EOL> should_reset_target_column = False <EOL> is_kill_cmd = False <EOL> is_ensure_visible_cmd = False <EOL> unregistered = False <EOL> def run ( self , edit , ** kwargs ) : <EOL> vs = ViewState . get ( self . view ) <EOL> cmd = self . jove_cmd_name <EOL> if vs . entered == <NUM_LIT:0> and ( cmd != '<STR_LIT>' or self . unregistered ) : <EOL> vs . this_cmd = cmd <EOL> vs . entered += <NUM_LIT:1> <EOL> util = CmdUtil ( self . view , state = vs , edit = edit ) <EOL> try : <EOL> self . run_cmd ( util , ** kwargs ) <EOL> finally : <EOL> vs . entered -= <NUM_LIT:1> <EOL> if vs . entered == <NUM_LIT:0> and ( cmd != '<STR_LIT>' or self . unregistered ) : <EOL> vs . last_cmd = vs . this_cmd <EOL> vs . argument_value = <NUM_LIT:0> <EOL> vs . argument_supplied = False <EOL> if self . should_reset_target_column : <EOL> util . reset_target_column ( ) <EOL> class SbpWindowCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self , ** kwargs ) : <EOL> self . util = CmdUtil ( self . window . active_view ( ) , state = ViewState . get ( self . window . active_view ( ) ) ) <EOL> self . run_cmd ( self . util , ** kwargs ) <EOL> class SbpChainCommand ( SbpTextCommand ) : <EOL> """<STR_LIT>""" <EOL> def run_cmd ( self , util , commands , use_window = False ) : <EOL> for c in commands : <EOL> if '<STR_LIT>' in c : <EOL> util . run_window_command ( c [ '<STR_LIT>' ] , c [ '<STR_LIT:args>' ] ) <EOL> elif '<STR_LIT>' in c : <EOL> util . run_command ( c [ '<STR_LIT>' ] , c [ '<STR_LIT:args>' ] ) <EOL> class SbpDoTimesCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , cmd , _times , ** args ) : <EOL> view = self . view <EOL> window = view . window ( ) <EOL> visible = view . visible_region ( ) <EOL> def doit ( ) : <EOL> for i in range ( _times ) : <EOL> window . run_command ( cmd , args ) <EOL> if cmd in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> sublime . set_timeout ( doit , <NUM_LIT:10> ) <EOL> else : <EOL> doit ( ) <EOL> cursor = util . get_last_cursor ( ) <EOL> if not visible . contains ( cursor . b ) : <EOL> util . ensure_visible ( cursor , True ) <EOL> class SbpShowScopeCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , direction = <NUM_LIT:1> ) : <EOL> point = util . get_point ( ) <EOL> name = self . view . scope_name ( point ) <EOL> region = self . view . extract_scope ( point ) <EOL> status = "<STR_LIT>" % ( region . size ( ) , name ) <EOL> print ( status ) <EOL> self . view . set_status ( JOVE_STATUS , status ) <EOL> class SbpMoveWordCommand ( SbpTextCommand ) : <EOL> should_reset_target_column = True <EOL> is_ensure_visible_cmd = True <EOL> def find_by_class_fallback ( self , view , point , forward , classes , seperators ) : <EOL> if forward : <EOL> delta = <NUM_LIT:1> <EOL> end_position = self . view . size ( ) <EOL> if point > end_position : <EOL> point = end_position <EOL> else : <EOL> delta = - <NUM_LIT:1> <EOL> end_position = <NUM_LIT:0> <EOL> if point < end_position : <EOL> point = end_position <EOL> while point != end_position : <EOL> if view . classify ( point ) & classes != <NUM_LIT:0> : <EOL> return point <EOL> point += delta <EOL> return point <EOL> def find_by_class_native ( self , view , point , forward , classes , separators ) : <EOL> return view . find_by_class ( point , forward , classes , separators ) <EOL> def run_cmd ( self , util , direction = <NUM_LIT:1> ) : <EOL> view = self . view <EOL> separators = SettingsManager . get ( "<STR_LIT>" , default_sbp_word_separators ) <EOL> count = util . get_count ( ) * direction <EOL> forward = count > <NUM_LIT:0> <EOL> count = abs ( count ) <EOL> def call_find_by_class ( point , classes , separators ) : <EOL> '''<STR_LIT>''' <EOL> if _ST3 : <EOL> return self . find_by_class_native ( view , point , forward , classes , separators ) <EOL> else : <EOL> return self . find_by_class_fallback ( view , point , forward , classes , separators ) <EOL> def move_word0 ( cursor , first = False ) : <EOL> point = cursor . b <EOL> if forward : <EOL> if not first or not util . is_word_char ( point , True , separators ) : <EOL> point = call_find_by_class ( point , sublime . CLASS_WORD_START , separators ) <EOL> point = call_find_by_class ( point , sublime . CLASS_WORD_END , separators ) <EOL> else : <EOL> if not first or not util . is_word_char ( point , False , separators ) : <EOL> point = call_find_by_class ( point , sublime . CLASS_WORD_END , separators ) <EOL> point = call_find_by_class ( point , sublime . CLASS_WORD_START , separators ) <EOL> return sublime . Region ( point , point ) <EOL> for c in range ( count ) : <EOL> util . for_each_cursor ( move_word0 , first = ( c == <NUM_LIT:0> ) ) <EOL> class SbpMoveBackToIndentation ( SbpTextCommand ) : <EOL> should_reset_target_column = True <EOL> def run_cmd ( self , util , direction = <NUM_LIT:1> ) : <EOL> view = self . view <EOL> def to_indentation ( cursor ) : <EOL> start = cursor . begin ( ) <EOL> while util . is_one_of ( start , "<STR_LIT>" ) : <EOL> start += <NUM_LIT:1> <EOL> return start <EOL> util . run_command ( "<STR_LIT>" , { "<STR_LIT:to>" : "<STR_LIT>" , "<STR_LIT>" : False } ) <EOL> util . for_each_cursor ( to_indentation ) <EOL> class SbpToWordCommand ( SbpTextCommand ) : <EOL> should_reset_target_column = True <EOL> def run_cmd ( self , util , direction = <NUM_LIT:1> ) : <EOL> view = self . view <EOL> separators = SettingsManager . get ( "<STR_LIT>" , default_sbp_word_separators ) <EOL> forward = direction > <NUM_LIT:0> <EOL> def to_word ( cursor ) : <EOL> point = cursor . b <EOL> if forward : <EOL> if not util . is_word_char ( point , True , separators ) : <EOL> point = view . find_by_class ( point , True , sublime . CLASS_WORD_START , separators ) <EOL> else : <EOL> if not util . is_word_char ( point , False , separators ) : <EOL> point = view . find_by_class ( point , False , sublime . CLASS_WORD_END , separators ) <EOL> return sublime . Region ( point , point ) <EOL> util . for_each_cursor ( to_word ) <EOL> class SbpCaseRegion ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , mode ) : <EOL> region = util . get_regions ( ) <EOL> text = util . view . substr ( region ) <EOL> if mode == "<STR_LIT>" : <EOL> text = text . upper ( ) <EOL> elif mode == "<STR_LIT>" : <EOL> text = text . lower ( ) <EOL> else : <EOL> util . set_status ( "<STR_LIT>" ) <EOL> return <EOL> util . view . replace ( util . edit , region , text ) <EOL> class SbpCaseWordCommand ( SbpTextCommand ) : <EOL> should_reset_target_column = True <EOL> def run_cmd ( self , util , mode , direction = <NUM_LIT:1> ) : <EOL> view = self . view <EOL> count = util . get_count ( True ) <EOL> selection = view . sel ( ) <EOL> regions = list ( selection ) <EOL> empty = util . all_empty_regions ( regions ) <EOL> if empty : <EOL> direction = - <NUM_LIT:1> if count < <NUM_LIT:0> else <NUM_LIT:1> <EOL> util . run_command ( "<STR_LIT>" , { "<STR_LIT>" : <NUM_LIT:1> } ) <EOL> new_regions = [ ] <EOL> for r , s in zip ( regions , selection ) : <EOL> new_regions . append ( r . cover ( s ) ) <EOL> selection . clear ( ) <EOL> selection . add_all ( new_regions ) <EOL> if mode in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> util . run_command ( mode + "<STR_LIT>" , { } ) <EOL> else : <EOL> for r in selection : <EOL> util . view . replace ( util . edit , r , view . substr ( r ) . title ( ) ) <EOL> if empty : <EOL> if count < <NUM_LIT:0> : <EOL> selection . clear ( ) <EOL> selection . add_all ( regions ) <EOL> else : <EOL> for r in new_regions : <EOL> r . a = r . b = r . end ( ) <EOL> selection . clear ( ) <EOL> selection . add_all ( new_regions ) <EOL> class SbpMoveSexprCommand ( SbpTextCommand ) : <EOL> is_ensure_visible_cmd = True <EOL> should_reset_target_column = True <EOL> def run_cmd ( self , util , direction = <NUM_LIT:1> ) : <EOL> view = self . view <EOL> separators = SettingsManager . get ( "<STR_LIT>" , default_sbp_sexpr_separators ) <EOL> count = util . get_count ( ) * direction <EOL> forward = count > <NUM_LIT:0> <EOL> count = abs ( count ) <EOL> def advance ( cursor , first ) : <EOL> point = cursor . b <EOL> if forward : <EOL> limit = view . size ( ) <EOL> while point < limit : <EOL> if util . is_word_char ( point , True , separators ) : <EOL> point = view . find_by_class ( point , True , sublime . CLASS_WORD_END , separators ) <EOL> break <EOL> else : <EOL> ch = view . substr ( point ) <EOL> if ch in "<STR_LIT>" : <EOL> next_point = util . to_other_end ( point , direction ) <EOL> if next_point is not None : <EOL> point = next_point <EOL> break <EOL> point += <NUM_LIT:1> <EOL> else : <EOL> while point > <NUM_LIT:0> : <EOL> if util . is_word_char ( point , False , separators ) : <EOL> point = view . find_by_class ( point , False , sublime . CLASS_WORD_START , separators ) <EOL> break <EOL> else : <EOL> ch = view . substr ( point - <NUM_LIT:1> ) <EOL> if ch in "<STR_LIT>" : <EOL> next_point = util . to_other_end ( point , direction ) <EOL> if next_point is not None : <EOL> point = next_point <EOL> break <EOL> point -= <NUM_LIT:1> <EOL> cursor . a = cursor . b = point <EOL> return cursor <EOL> for c in range ( count ) : <EOL> util . for_each_cursor ( advance , ( c == <NUM_LIT:0> ) ) <EOL> class SbpMoveToParagraphCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , direction = <NUM_LIT:1> ) : <EOL> s = self . view . sel ( ) [ <NUM_LIT:0> ] <EOL> if direction == <NUM_LIT:1> : <EOL> if s . begin ( ) == <NUM_LIT:0> : <EOL> return <EOL> point = paragraph . expand_to_paragraph ( self . view , s . begin ( ) - <NUM_LIT:1> ) . begin ( ) <EOL> else : <EOL> if s . end ( ) == self . view . size ( ) : <EOL> return <EOL> point = paragraph . expand_to_paragraph ( self . view , s . end ( ) + <NUM_LIT:1> ) . end ( ) <EOL> self . view . sel ( ) . clear ( ) <EOL> if point < <NUM_LIT:0> : <EOL> point = <NUM_LIT:0> <EOL> if point > self . view . size ( ) : <EOL> point = self . view . size ( ) <EOL> self . view . sel ( ) . add ( sublime . Region ( point , point ) ) <EOL> self . view . show ( self . view . sel ( ) [ <NUM_LIT:0> ] . begin ( ) ) <EOL> class SbpMoveThenDeleteCommand ( SbpTextCommand ) : <EOL> is_ensure_visible_cmd = True <EOL> is_kill_cmd = True <EOL> def run_cmd ( self , util , move_cmd , ** kwargs ) : <EOL> view = self . view <EOL> selection = view . sel ( ) <EOL> count = util . get_count ( True ) <EOL> if '<STR_LIT>' in kwargs : <EOL> count *= kwargs [ '<STR_LIT>' ] <EOL> orig_cursors = [ s for s in selection ] <EOL> view . run_command ( move_cmd , kwargs ) <EOL> new_cursors = [ s for s in selection ] <EOL> selection . clear ( ) <EOL> for old , new in zip ( orig_cursors , new_cursors ) : <EOL> if old < new : <EOL> selection . add ( sublime . Region ( old . begin ( ) , new . end ( ) ) ) <EOL> else : <EOL> selection . add ( sublime . Region ( new . begin ( ) , old . end ( ) ) ) <EOL> cursors = list ( selection ) <EOL> regions_overlap = False <EOL> for i , c in enumerate ( cursors [ <NUM_LIT:1> : ] ) : <EOL> if cursors [ i ] . contains ( c . begin ( ) ) : <EOL> regions_overlap = True <EOL> break <EOL> if regions_overlap : <EOL> selection . clear ( ) <EOL> selection . add_all ( orig_cursors ) <EOL> return <EOL> regions = [ view . substr ( r ) for r in view . sel ( ) ] <EOL> kill_ring . add ( regions , forward = count > <NUM_LIT:0> , join = util . state . last_was_kill_cmd ( ) ) <EOL> for region in selection : <EOL> view . erase ( util . edit , region ) <EOL> class SbpGotoLineCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util ) : <EOL> if util . has_prefix_arg ( ) : <EOL> util . goto_line ( util . get_count ( ) ) <EOL> else : <EOL> util . run_window_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:text>" : "<STR_LIT::>" } ) <EOL> class SbpDeleteWhiteSpaceCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util ) : <EOL> util . for_each_cursor ( self . delete_white_space , util , can_modify = True ) <EOL> def delete_white_space ( self , cursor , util , ** kwargs ) : <EOL> view = self . view <EOL> line = view . line ( cursor . a ) <EOL> data = view . substr ( line ) <EOL> row , col = view . rowcol ( cursor . a ) <EOL> start = col <EOL> while start - <NUM_LIT:1> >= <NUM_LIT:0> and data [ start - <NUM_LIT:1> : start ] in ( "<STR_LIT>" ) : <EOL> start -= <NUM_LIT:1> <EOL> end = col <EOL> limit = len ( data ) <EOL> while end + <NUM_LIT:1> < limit and data [ end : end + <NUM_LIT:1> ] in ( "<STR_LIT>" ) : <EOL> end += <NUM_LIT:1> <EOL> view . erase ( util . edit , sublime . Region ( line . begin ( ) + start , line . begin ( ) + end ) ) <EOL> return None <EOL> class SbpUniversalArgumentCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , value ) : <EOL> state = util . state <EOL> if not state . argument_supplied : <EOL> state . argument_supplied = True <EOL> if value == '<STR_LIT>' : <EOL> state . argument_value = <NUM_LIT:4> <EOL> elif value == '<STR_LIT>' : <EOL> state . argument_negative = True <EOL> else : <EOL> state . argument_value = value <EOL> elif value == '<STR_LIT>' : <EOL> state . argument_value *= <NUM_LIT:4> <EOL> elif isinstance ( value , int ) : <EOL> state . argument_value *= <NUM_LIT:10> <EOL> state . argument_value += value <EOL> elif value == '<STR_LIT>' : <EOL> state . argument_value = - state . argument_value <EOL> class SbpShiftRegionCommand ( SbpTextCommand ) : <EOL> """<STR_LIT>""" <EOL> def run_cmd ( self , util , direction ) : <EOL> view = self . view <EOL> state = util . state <EOL> regions = util . get_regions ( ) <EOL> if not regions : <EOL> regions = util . get_cursors ( ) <EOL> if regions : <EOL> util . save_cursors ( "<STR_LIT>" ) <EOL> util . toggle_active_mark_mode ( False ) <EOL> selection = self . view . sel ( ) <EOL> selection . clear ( ) <EOL> if state . argument_supplied : <EOL> cols = direction * util . get_count ( ) <EOL> else : <EOL> cols = direction * util . get_tab_size ( ) <EOL> amount = abs ( cols ) <EOL> count = <NUM_LIT:0> <EOL> shifted = <NUM_LIT:0> <EOL> for region in regions : <EOL> for line in util . for_each_line ( region ) : <EOL> count += <NUM_LIT:1> <EOL> if cols < <NUM_LIT:0> and ( line . size ( ) < amount or not util . is_blank ( line . a , line . a + amount ) ) : <EOL> continue <EOL> selection . add ( sublime . Region ( line . a , line . a ) ) <EOL> shifted += <NUM_LIT:1> <EOL> if cols > <NUM_LIT:0> : <EOL> self . view . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT:U+0020>" * cols } ) <EOL> else : <EOL> for i in range ( amount ) : <EOL> self . view . run_command ( "<STR_LIT>" ) <EOL> util . restore_cursors ( "<STR_LIT>" ) <EOL> sublime . set_timeout ( lambda : util . set_status ( "<STR_LIT>" % ( shifted , count ) ) , <NUM_LIT:100> ) <EOL> def enum ( ** enums ) : <EOL> return type ( '<STR_LIT>' , ( ) , enums ) <EOL> SCROLL_TYPES = enum ( TOP = <NUM_LIT:1> , CENTER = <NUM_LIT:0> , BOTTOM = <NUM_LIT:2> ) <EOL> class SbpCenterViewCommand ( SbpTextCommand ) : <EOL> '''<STR_LIT>''' <EOL> last_sel = None <EOL> last_scroll_type = None <EOL> last_visible_region = None <EOL> def rowdiff ( self , start , end ) : <EOL> r1 , c1 = self . view . rowcol ( start ) <EOL> r2 , c2 = self . view . rowcol ( end ) <EOL> return r2 - r1 <EOL> def run_cmd ( self , util , center_only = False ) : <EOL> view = self . view <EOL> point = util . get_point ( ) <EOL> if util . has_prefix_arg ( ) : <EOL> lines = util . get_count ( ) <EOL> line_height = view . line_height ( ) <EOL> ignore , point_offy = view . text_to_layout ( point ) <EOL> offx , ignore = view . viewport_position ( ) <EOL> view . set_viewport_position ( ( offx , point_offy - line_height * lines ) ) <EOL> elif center_only : <EOL> self . view . show_at_center ( util . get_point ( ) ) <EOL> else : <EOL> self . cycle_center_view ( view . sel ( ) [ <NUM_LIT:0> ] ) <EOL> def cycle_center_view ( self , start ) : <EOL> if start != SbpCenterViewCommand . last_sel : <EOL> SbpCenterViewCommand . last_visible_region = None <EOL> SbpCenterViewCommand . last_scroll_type = SCROLL_TYPES . CENTER <EOL> SbpCenterViewCommand . last_sel = start <EOL> self . view . show_at_center ( SbpCenterViewCommand . last_sel ) <EOL> return <EOL> else : <EOL> SbpCenterViewCommand . last_scroll_type = ( SbpCenterViewCommand . last_scroll_type + <NUM_LIT:1> ) % <NUM_LIT:3> <EOL> SbpCenterViewCommand . last_sel = start <EOL> if SbpCenterViewCommand . last_visible_region == None : <EOL> SbpCenterViewCommand . last_visible_region = self . view . visible_region ( ) <EOL> if SbpCenterViewCommand . last_scroll_type == SCROLL_TYPES . CENTER : <EOL> self . view . show_at_center ( SbpCenterViewCommand . last_sel ) <EOL> elif SbpCenterViewCommand . last_scroll_type == SCROLL_TYPES . TOP : <EOL> row , col = self . view . rowcol ( SbpCenterViewCommand . last_visible_region . end ( ) ) <EOL> diff = self . rowdiff ( SbpCenterViewCommand . last_visible_region . begin ( ) , SbpCenterViewCommand . last_sel . begin ( ) ) <EOL> self . view . show ( self . view . text_point ( row + diff - <NUM_LIT:2> , <NUM_LIT:0> ) , False ) <EOL> elif SbpCenterViewCommand . last_scroll_type == SCROLL_TYPES . BOTTOM : <EOL> row , col = self . view . rowcol ( SbpCenterViewCommand . last_visible_region . begin ( ) ) <EOL> diff = self . rowdiff ( SbpCenterViewCommand . last_sel . begin ( ) , SbpCenterViewCommand . last_visible_region . end ( ) ) <EOL> self . view . show ( self . view . text_point ( row - diff + <NUM_LIT:2> , <NUM_LIT:0> ) , False ) <EOL> class SbpSetMarkCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util ) : <EOL> state = util . state <EOL> if state . argument_supplied : <EOL> cursors = state . mark_ring . pop ( ) <EOL> if cursors : <EOL> util . set_cursors ( cursors ) <EOL> else : <EOL> util . set_status ( "<STR_LIT>" ) <EOL> state . this_cmd = "<STR_LIT>" <EOL> elif state . this_cmd == state . last_cmd : <EOL> util . toggle_active_mark_mode ( ) <EOL> else : <EOL> util . set_mark ( ) <EOL> if SettingsManager . get ( "<STR_LIT>" , False ) : <EOL> util . set_active_mark_mode ( ) <EOL> class SbpCancelMarkCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util ) : <EOL> if util . state . active_mark : <EOL> util . toggle_active_mark_mode ( ) <EOL> util . state . mark_ring . clear ( ) <EOL> class SbpSwapPointAndMarkCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , toggle_active_mark_mode = False ) : <EOL> if util . state . argument_supplied or toggle_active_mark_mode : <EOL> util . toggle_active_mark_mode ( ) <EOL> else : <EOL> util . swap_point_and_mark ( ) <EOL> class SbpMoveToCommand ( SbpTextCommand ) : <EOL> is_ensure_visible_cmd = True <EOL> def run_cmd ( self , util , to , always_push_mark = False ) : <EOL> if to == '<STR_LIT>' : <EOL> util . push_mark_and_goto_position ( <NUM_LIT:0> ) <EOL> elif to == '<STR_LIT>' : <EOL> util . push_mark_and_goto_position ( self . view . size ( ) ) <EOL> elif to in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> visible = self . view . visible_region ( ) <EOL> pos = visible . a if to == '<STR_LIT>' else visible . b <EOL> if always_push_mark : <EOL> util . push_mark_and_goto_position ( pos ) <EOL> else : <EOL> util . set_cursors ( [ sublime . Region ( pos ) ] ) <EOL> class SbpOpenLineCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util ) : <EOL> view = self . view <EOL> for point in view . sel ( ) : <EOL> view . insert ( util . edit , point . b , "<STR_LIT:\n>" ) <EOL> view . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : False } ) <EOL> class SbpKillRegionCommand ( SbpTextCommand ) : <EOL> is_kill_cmd = True <EOL> def run_cmd ( self , util , is_copy = False ) : <EOL> view = self . view <EOL> regions = util . get_regions ( ) <EOL> if regions : <EOL> data = [ view . substr ( r ) for r in regions ] <EOL> kill_ring . add ( data , True , False ) <EOL> if not is_copy : <EOL> for r in reversed ( regions ) : <EOL> view . erase ( util . edit , r ) <EOL> else : <EOL> bytes = sum ( len ( d ) for d in data ) <EOL> util . set_status ( "<STR_LIT>" % ( bytes , len ( data ) ) ) <EOL> util . toggle_active_mark_mode ( False ) <EOL> class SbpPaneCmdCommand ( SbpWindowCommand ) : <EOL> def run_cmd ( self , util , cmd , ** kwargs ) : <EOL> if cmd == '<STR_LIT>' : <EOL> self . split ( self . window , util , ** kwargs ) <EOL> elif cmd == '<STR_LIT>' : <EOL> self . grow ( self . window , util , ** kwargs ) <EOL> elif cmd == '<STR_LIT>' : <EOL> self . destroy ( self . window , ** kwargs ) <EOL> elif cmd in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . move ( self . window , ** kwargs ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> def grow ( self , window , util , direction ) : <EOL> if window . num_groups ( ) == <NUM_LIT:1> : <EOL> return <EOL> layout = window . layout ( ) <EOL> lm = ll . LayoutManager ( layout ) <EOL> rows = lm . rows ( ) <EOL> cols = lm . cols ( ) <EOL> cells = layout [ '<STR_LIT>' ] <EOL> width = height = dx = dy = <NUM_LIT:0> <EOL> for g , cell in enumerate ( cells ) : <EOL> view = window . active_view_in_group ( g ) <EOL> w , h = view . viewport_extent ( ) <EOL> width += w <EOL> height += h <EOL> dx += cols [ cell [ <NUM_LIT:2> ] ] - cols [ cell [ <NUM_LIT:0> ] ] <EOL> dy += rows [ cell [ <NUM_LIT:3> ] ] - rows [ cell [ <NUM_LIT:1> ] ] <EOL> width /= dx <EOL> height /= dy <EOL> current = window . active_group ( ) <EOL> view = util . view <EOL> count = util . get_count ( ) <EOL> if direction in ( '<STR_LIT:g>' , '<STR_LIT:s>' ) : <EOL> unit = view . line_height ( ) / height <EOL> else : <EOL> unit = view . em_width ( ) / width <EOL> window . set_layout ( lm . extend ( current , direction , unit , count ) ) <EOL> def ensure_visible ( ) : <EOL> for g in range ( window . num_groups ( ) ) : <EOL> view = window . active_view_in_group ( g ) <EOL> util = CmdUtil ( view ) <EOL> util . ensure_visible ( util . get_point ( ) ) <EOL> sublime . set_timeout ( ensure_visible , <NUM_LIT:50> ) <EOL> def split ( self , window , util , stype ) : <EOL> layout = window . layout ( ) <EOL> current = window . active_group ( ) <EOL> group_count = window . num_groups ( ) <EOL> view = window . active_view ( ) <EOL> extent = view . viewport_extent ( ) <EOL> if stype == "<STR_LIT:h>" and extent [ <NUM_LIT:1> ] / <NUM_LIT:2> <= <NUM_LIT:4> * view . line_height ( ) : <EOL> return False <EOL> if stype == "<STR_LIT:v>" and extent [ <NUM_LIT:0> ] / <NUM_LIT:2> <= <NUM_LIT:20> * view . em_width ( ) : <EOL> return False <EOL> lm = ll . LayoutManager ( layout ) <EOL> if not lm . split ( current , stype ) : <EOL> return False <EOL> window . set_layout ( lm . build ( ) ) <EOL> window . run_command ( "<STR_LIT>" ) <EOL> new_view = window . active_view ( ) <EOL> window . set_view_index ( new_view , group_count , <NUM_LIT:0> ) <EOL> window . focus_view ( view ) <EOL> window . focus_group ( group_count + <NUM_LIT:1> ) <EOL> def setup_views ( ) : <EOL> selection = new_view . sel ( ) <EOL> selection . clear ( ) <EOL> selection . add_all ( [ r for r in view . sel ( ) ] ) <EOL> new_view . set_viewport_position ( view . viewport_position ( ) , False ) <EOL> point = util . get_point ( ) <EOL> new_view . show ( point ) <EOL> view . show ( point ) <EOL> sublime . set_timeout ( setup_views , <NUM_LIT:10> ) <EOL> return True <EOL> def destroy ( self , window , pane ) : <EOL> if window . num_groups ( ) == <NUM_LIT:1> : <EOL> return <EOL> view = window . active_view ( ) <EOL> layout = window . layout ( ) <EOL> current = window . active_group ( ) <EOL> lm = ll . LayoutManager ( layout ) <EOL> if pane == "<STR_LIT>" : <EOL> views = [ window . active_view_in_group ( i ) for i in range ( window . num_groups ( ) ) ] <EOL> del ( views [ current ] ) <EOL> lm . killSelf ( current ) <EOL> else : <EOL> lm . killOther ( current ) <EOL> views = [ window . active_view ( ) ] <EOL> window . set_layout ( lm . build ( ) ) <EOL> for i in range ( window . num_groups ( ) ) : <EOL> view = views [ i ] <EOL> window . focus_group ( i ) <EOL> window . focus_view ( view ) <EOL> window . focus_group ( max ( <NUM_LIT:0> , current - <NUM_LIT:1> ) ) <EOL> dedup_views ( window ) <EOL> def move ( self , window , ** kwargs ) : <EOL> if '<STR_LIT>' in kwargs : <EOL> window . focus_group ( kwargs [ "<STR_LIT>" ] ) <EOL> return <EOL> direction = kwargs [ '<STR_LIT>' ] <EOL> if direction in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> direction = <NUM_LIT:1> if direction == "<STR_LIT>" else - <NUM_LIT:1> <EOL> current = window . active_group ( ) <EOL> current += direction <EOL> num_groups = window . num_groups ( ) <EOL> if current < <NUM_LIT:0> : <EOL> current = num_groups - <NUM_LIT:1> <EOL> elif current >= num_groups : <EOL> current = <NUM_LIT:0> <EOL> window . focus_group ( current ) <EOL> else : <EOL> view = window . active_view ( ) <EOL> group , index = window . get_view_index ( view ) <EOL> views = window . views_in_group ( group ) <EOL> direction = <NUM_LIT:1> if direction == "<STR_LIT:right>" else - <NUM_LIT:1> <EOL> index += direction <EOL> if index >= len ( views ) : <EOL> index = <NUM_LIT:0> <EOL> elif index < <NUM_LIT:0> : <EOL> index = len ( views ) - <NUM_LIT:1> <EOL> window . focus_view ( views [ index ] ) <EOL> class SbpMoveForKillLineCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , ** kwargs ) : <EOL> view = self . view <EOL> state = util . state <EOL> if state . argument_supplied : <EOL> count = abs ( util . get_count ( ) ) <EOL> line_mode = True <EOL> else : <EOL> line_mode = False <EOL> def advance ( cursor ) : <EOL> start = cursor . b <EOL> text , index , region = util . get_line_info ( start ) <EOL> if line_mode : <EOL> for i in range ( abs ( count ) ) : <EOL> view . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : True } ) <EOL> end = util . get_point ( ) <EOL> if region . contains ( end ) : <EOL> end = region . end ( ) <EOL> else : <EOL> end = view . line ( util . get_point ( ) ) . begin ( ) <EOL> util . set_cursors ( sublime . Region ( end ) ) <EOL> else : <EOL> end = region . end ( ) <EOL> import re <EOL> if re . match ( r'<STR_LIT>' , text [ index : ] ) and end < util . view . size ( ) : <EOL> end += <NUM_LIT:1> <EOL> return sublime . Region ( end , end ) <EOL> util . for_each_cursor ( advance ) <EOL> class SbpYankCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , pop = <NUM_LIT:0> ) : <EOL> if pop and util . state . last_cmd != '<STR_LIT>' : <EOL> util . set_status ( "<STR_LIT>" ) <EOL> return <EOL> view = self . view <EOL> cursors = list ( view . sel ( ) ) <EOL> data = kill_ring . get_current ( len ( cursors ) , pop ) <EOL> if not data : <EOL> return <EOL> if pop != <NUM_LIT:0> : <EOL> regions = util . get_regions ( ) <EOL> if not regions : <EOL> return <EOL> for r in reversed ( regions ) : <EOL> view . erase ( util . edit , r ) <EOL> cursors = util . get_cursors ( ) <EOL> for region , data in reversed ( list ( zip ( cursors , data ) ) ) : <EOL> view . replace ( util . edit , region , data ) <EOL> util . state . mark_ring . set ( util . get_cursors ( begin = True ) , True ) <EOL> util . make_cursors_empty ( ) <EOL> util . ensure_visible ( util . get_last_cursor ( ) ) <EOL> class ISearchInfo ( ) : <EOL> last_search = None <EOL> class StackItem ( ) : <EOL> def __init__ ( self , search , regions , selected , current_index , forward , wrapped ) : <EOL> self . prev = None <EOL> self . search = search <EOL> self . regions = regions <EOL> self . selected = selected <EOL> self . current_index = current_index <EOL> self . forward = forward <EOL> self . try_wrapped = False <EOL> self . wrapped = wrapped <EOL> if current_index >= <NUM_LIT:0> and regions : <EOL> selected . append ( regions [ current_index ] ) <EOL> def get_point ( self ) : <EOL> if self . current_index >= <NUM_LIT:0> : <EOL> r = self . regions [ self . current_index ] <EOL> return r . begin ( ) if self . forward else r . end ( ) <EOL> return None <EOL> def clone ( self ) : <EOL> return copy . copy ( self ) <EOL> def step ( self , forward , keep ) : <EOL> index = self . current_index <EOL> matches = len ( self . regions ) <EOL> if ( self . regions and ( index < <NUM_LIT:0> or ( index == <NUM_LIT:0> and not forward ) or ( index == matches - <NUM_LIT:1> ) and forward ) ) : <EOL> index = <NUM_LIT:0> if forward else matches - <NUM_LIT:1> <EOL> if self . try_wrapped or not self . regions : <EOL> wrapped = True <EOL> self . try_wrapped = False <EOL> else : <EOL> self . try_wrapped = True <EOL> return None <EOL> elif ( forward and index < matches - <NUM_LIT:1> ) or ( not forward and index > <NUM_LIT:0> ) : <EOL> index = index + <NUM_LIT:1> if forward else index - <NUM_LIT:1> <EOL> wrapped = self . wrapped <EOL> else : <EOL> return None <EOL> selected = copy ( self . selected ) <EOL> if not keep and len ( selected ) > <NUM_LIT:0> : <EOL> del ( selected [ - <NUM_LIT:1> ] ) <EOL> return ISearchInfo . StackItem ( self . search , self . regions , selected , index , forward , wrapped ) <EOL> def __init__ ( self , view , forward , regex ) : <EOL> self . view = view <EOL> self . current = ISearchInfo . StackItem ( "<STR_LIT>" , [ ] , [ ] , - <NUM_LIT:1> , forward , False ) <EOL> self . util = CmdUtil ( view ) <EOL> self . window = view . window ( ) <EOL> self . point = self . util . get_cursors ( ) <EOL> self . update ( ) <EOL> self . input_view = None <EOL> self . in_changes = <NUM_LIT:0> <EOL> self . forward = forward <EOL> self . regex = regex <EOL> def open ( self ) : <EOL> window = self . view . window ( ) <EOL> self . input_view = window . show_input_panel ( "<STR_LIT>" % ( "<STR_LIT>" if self . regex else "<STR_LIT>" , ) , <EOL> "<STR_LIT>" , self . on_done , self . on_change , self . on_cancel ) <EOL> def on_done ( self , val ) : <EOL> self . finish ( abort = False ) <EOL> def on_cancel ( self ) : <EOL> self . finish ( abort = True ) <EOL> def on_change ( self , val ) : <EOL> if self . in_changes > <NUM_LIT:0> : <EOL> self . in_changes -= <NUM_LIT:1> <EOL> return <EOL> if self . current and self . current . search == val : <EOL> return <EOL> self . find ( val ) <EOL> def find ( self , val ) : <EOL> flags = <NUM_LIT:0> if self . regex else sublime . LITERAL <EOL> if not re . search ( r'<STR_LIT>' , val ) : <EOL> flags |= sublime . IGNORECASE <EOL> if len ( val ) > <NUM_LIT:0> : <EOL> regions = self . view . find_all ( val , flags ) <EOL> pos = None <EOL> if self . current : <EOL> pos = self . current . get_point ( ) <EOL> if pos is None : <EOL> pos = self . point [ - <NUM_LIT:1> ] . b <EOL> index = self . find_closest ( regions , pos , self . forward ) <EOL> self . push ( ISearchInfo . StackItem ( val , regions , [ ] , index , self . forward , self . current . wrapped ) ) <EOL> else : <EOL> regions = None <EOL> index = - <NUM_LIT:1> <EOL> self . update ( ) <EOL> def push ( self , item ) : <EOL> item . prev = self . current <EOL> self . current = item <EOL> def pop ( self ) : <EOL> if self . current . prev : <EOL> self . current = self . current . prev <EOL> self . set_text ( self . current . search ) <EOL> self . forward = self . current . forward <EOL> self . update ( ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> def hide_panel ( self ) : <EOL> window = self . view . window ( ) <EOL> if window : <EOL> window . run_command ( "<STR_LIT>" ) <EOL> def done ( self ) : <EOL> self . finish ( ) <EOL> def set_text ( self , text , is_pop = True ) : <EOL> if is_pop : <EOL> self . in_changes += <NUM_LIT:1> <EOL> self . input_view . run_command ( "<STR_LIT>" ) <EOL> self . input_view . run_command ( "<STR_LIT>" ) <EOL> self . input_view . run_command ( "<STR_LIT>" , { "<STR_LIT>" : text } ) <EOL> def not_in_error ( self ) : <EOL> si = self . current <EOL> while si and not si . selected and si . search : <EOL> si = si . prev <EOL> return si <EOL> def finish ( self , abort = False ) : <EOL> util = self . util <EOL> if isearch_info_for ( self . view ) != self : <EOL> return <EOL> if self . current and self . current . search : <EOL> ISearchInfo . last_search = self . current . search <EOL> util . set_status ( "<STR_LIT>" ) <EOL> point_set = False <EOL> if not abort : <EOL> selection = self . view . sel ( ) <EOL> selection . clear ( ) <EOL> current = self . current <EOL> not_in_error = self . not_in_error ( ) <EOL> if current and current . selected : <EOL> if not current . forward : <EOL> selected = ( sublime . Region ( s . b , s . a ) for s in current . selected ) <EOL> else : <EOL> selected = current . selected <EOL> selection . add_all ( selected ) <EOL> point_set = True <EOL> elif not_in_error and not_in_error . regions : <EOL> selection . add_all ( [ not_in_error . regions [ not_in_error . current_index ] ] ) <EOL> point_set = True <EOL> if not point_set : <EOL> util . set_cursors ( self . point ) <EOL> else : <EOL> util . set_mark ( self . point , and_selection = False ) <EOL> self . view . erase_regions ( REGION_FIND ) <EOL> self . view . erase_regions ( REGION_SELECTED ) <EOL> clear_isearch_info_for ( self . view ) <EOL> self . hide_panel ( ) <EOL> def update ( self ) : <EOL> si = self . current <EOL> if si is None : <EOL> return <EOL> not_in_error = self . not_in_error ( ) <EOL> flags = sublime . DRAW_NO_FILL if _ST3 else sublime . DRAW_OUTLINED <EOL> self . view . add_regions ( REGION_FIND , si . regions , "<STR_LIT:text>" , "<STR_LIT>" , flags ) <EOL> selected = si . selected or ( not_in_error . selected and [ not_in_error . selected [ - <NUM_LIT:1> ] ] ) or [ ] <EOL> self . view . add_regions ( REGION_SELECTED , selected , "<STR_LIT:string>" , "<STR_LIT>" , sublime . DRAW_NO_OUTLINE ) <EOL> if selected : <EOL> self . view . show ( selected [ - <NUM_LIT:1> ] ) <EOL> status = "<STR_LIT>" <EOL> if si != not_in_error or si . try_wrapped : <EOL> status += "<STR_LIT>" <EOL> if self . current . wrapped : <EOL> status += "<STR_LIT>" <EOL> status += "<STR_LIT>" + ( "<STR_LIT>" if self . current . forward else "<STR_LIT>" ) <EOL> if si != not_in_error : <EOL> if len ( self . current . regions ) > <NUM_LIT:0> : <EOL> status += "<STR_LIT>" % ( pluralize ( "<STR_LIT>" , len ( self . current . regions ) , "<STR_LIT>" ) , ( "<STR_LIT>" if self . forward else "<STR_LIT>" ) ) <EOL> else : <EOL> n_cursors = min ( len ( si . selected ) , len ( si . regions ) ) <EOL> status += "<STR_LIT>" % ( pluralize ( "<STR_LIT>" , len ( si . regions ) , "<STR_LIT>" ) , pluralize ( "<STR_LIT>" , n_cursors ) ) <EOL> self . util . set_status ( status ) <EOL> def next ( self , keep , forward = None ) : <EOL> if self . current . prev is None : <EOL> if ISearchInfo . last_search : <EOL> self . set_text ( ISearchInfo . last_search , is_pop = False ) <EOL> else : <EOL> if forward is None : <EOL> forward = self . current . forward <EOL> new = self . current . step ( forward = forward , keep = keep ) <EOL> if new : <EOL> self . push ( new ) <EOL> self . update ( ) <EOL> def keep_all ( self ) : <EOL> while self . current . regions and self . current . current_index < len ( self . current . regions ) : <EOL> new = self . current . step ( forward = self . current . forward , keep = True ) <EOL> if new : <EOL> self . push ( new ) <EOL> else : <EOL> break <EOL> self . update ( ) <EOL> def append_from_cursor ( self ) : <EOL> si = self . current <EOL> if len ( si . search ) > <NUM_LIT:0> and not si . selected : <EOL> return <EOL> view = self . view <EOL> limit = view . size ( ) <EOL> if si . selected : <EOL> point = si . selected [ - <NUM_LIT:1> ] . end ( ) <EOL> else : <EOL> point = self . point [ <NUM_LIT:0> ] . b <EOL> if point >= limit : <EOL> return <EOL> helper = self . util <EOL> search = si . search <EOL> separators = SettingsManager . get ( "<STR_LIT>" , default_sbp_word_separators ) <EOL> case_sensitive = re . search ( r'<STR_LIT>' , search ) is not None <EOL> def append_one ( ch ) : <EOL> if not case_sensitive : <EOL> ch = ch . lower ( ) <EOL> if self . regex and ch in "<STR_LIT>" : <EOL> return "<STR_LIT:\\>" + ch <EOL> return ch <EOL> if point < limit : <EOL> search += append_one ( view . substr ( point ) ) <EOL> point += <NUM_LIT:1> <EOL> self . on_change ( search ) <EOL> while point < limit and helper . is_word_char ( point , True , separators ) : <EOL> ch = view . substr ( point ) <EOL> search += append_one ( ch ) <EOL> self . on_change ( search ) <EOL> point += <NUM_LIT:1> <EOL> self . set_text ( self . current . search ) <EOL> def quit ( self ) : <EOL> close = False <EOL> if self . current . regions : <EOL> close = True <EOL> else : <EOL> while self . current . prev and not self . current . prev . regions : <EOL> self . current = self . current . prev <EOL> if self . current . prev is None : <EOL> close = True <EOL> if close : <EOL> self . finish ( abort = True ) <EOL> else : <EOL> self . pop ( ) <EOL> def find_closest ( self , regions , pos , forward ) : <EOL> if len ( regions ) == <NUM_LIT:0> : <EOL> return - <NUM_LIT:1> <EOL> found = False <EOL> if forward : <EOL> for index , r in enumerate ( regions ) : <EOL> if r . end ( ) >= pos : <EOL> return index <EOL> return - <NUM_LIT:1> <EOL> else : <EOL> for index , r in enumerate ( regions ) : <EOL> if r . begin ( ) > pos : <EOL> return index - <NUM_LIT:1> <EOL> return len ( regions ) - <NUM_LIT:1> <EOL> class SbpIncSearchCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , cmd = None , ** kwargs ) : <EOL> info = isearch_info_for ( self . view ) <EOL> if info is None or cmd is None : <EOL> regex = kwargs . get ( '<STR_LIT>' , False ) <EOL> if util . state . argument_supplied : <EOL> regex = not regex <EOL> info = set_isearch_info_for ( self . view , ISearchInfo ( self . view , kwargs [ '<STR_LIT>' ] , regex ) ) <EOL> info . open ( ) <EOL> else : <EOL> if cmd == "<STR_LIT>" : <EOL> info . next ( ** kwargs ) <EOL> elif cmd == "<STR_LIT>" : <EOL> info . pop ( ) <EOL> elif cmd == "<STR_LIT>" : <EOL> info . append_from_cursor ( ) <EOL> elif cmd == "<STR_LIT>" : <EOL> info . keep_all ( ) <EOL> elif cmd == "<STR_LIT>" : <EOL> info . done ( ) <EOL> elif cmd == "<STR_LIT>" : <EOL> info . quit ( ) <EOL> elif cmd == "<STR_LIT>" : <EOL> info . input_view . run_command ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" , cmd , kwargs ) <EOL> def is_visible ( self , ** kwargs ) : <EOL> return False <EOL> class SbpIncSearchEscapeCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , next_cmd , next_args ) : <EOL> info = isearch_info_for ( self . view ) <EOL> info . done ( ) <EOL> info . view . run_command ( next_cmd , next_args ) <EOL> class SbpTabCmdCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util , indent_on_repeat = False ) : <EOL> point = util . get_point ( ) <EOL> indent , cursor = util . get_line_indent ( point ) <EOL> tab_size = util . get_tab_size ( ) <EOL> if util . state . active_mark or cursor > indent : <EOL> util . run_command ( "<STR_LIT>" , { } ) <EOL> else : <EOL> if indent_on_repeat and util . state . last_cmd == util . state . this_cmd : <EOL> util . run_command ( "<STR_LIT>" , { } ) <EOL> else : <EOL> if ( indent % tab_size ) != <NUM_LIT:0> : <EOL> delta = tab_size - ( indent % tab_size ) <EOL> self . view . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT:U+0020>" * delta } ) <EOL> if cursor < indent : <EOL> util . run_command ( "<STR_LIT>" , { "<STR_LIT:to>" : "<STR_LIT>" , "<STR_LIT>" : False } ) <EOL> util . run_command ( "<STR_LIT>" , { } ) <EOL> class SbpQuitCommand ( SbpTextCommand ) : <EOL> def run_cmd ( self , util ) : <EOL> window = self . view . window ( ) <EOL> info = isearch_info_for ( self . view ) <EOL> if info : <EOL> info . quit ( ) <EOL> return <EOL> for cmd in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> window . run_command ( cmd ) <EOL> if util . state . active_mark : <EOL> util . toggle_active_mark_mode ( ) <EOL> return <EOL> s = list ( self . view . sel ( ) ) <EOL> if s : <EOL> start = s [ <NUM_LIT:0> ] . a <EOL> end = s [ - <NUM_LIT:1> ] . b <EOL> if util . is_visible ( end ) : <EOL> pos = end <EOL> elif util . is_visible ( start ) : <EOL> pos = start <EOL> else : <EOL> visible = self . view . visible_region ( ) <EOL> top_line = self . view . rowcol ( visible . begin ( ) ) [ <NUM_LIT:0> ] <EOL> bottom_line = self . view . rowcol ( visible . end ( ) ) [ <NUM_LIT:0> ] <EOL> pos = self . view . text_point ( ( top_line + bottom_line ) / <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> util . set_selection ( sublime . Region ( pos ) ) <EOL> class SbpZapToCharEdit ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit , begin , end ) : <EOL> region = sublime . Region ( int ( begin ) , int ( end ) ) <EOL> kill_ring . add ( [ self . view . substr ( region ) ] , True , False ) <EOL> self . view . erase ( edit , region ) <EOL> class SbpZapToCharCommand ( SbpTextCommand ) : <EOL> is_kill_cmd = True <EOL> panel = None <EOL> def run_cmd ( self , util , ** args ) : <EOL> self . util = util <EOL> self . panel = self . view . window ( ) . show_input_panel ( "<STR_LIT>" , "<STR_LIT>" , self . zap , self . on_change , None ) <EOL> def zap ( self ) : <EOL> pass <EOL> def on_change ( self , content ) : <EOL> """<STR_LIT>""" <EOL> if self . panel == None : <EOL> return <EOL> self . panel . window ( ) . run_command ( "<STR_LIT>" ) <EOL> start = finish = self . util . get_point ( ) <EOL> found = False <EOL> while not found and finish < self . view . size ( ) : <EOL> data = self . view . substr ( finish ) <EOL> if data == content : <EOL> found = True <EOL> break <EOL> finish += <NUM_LIT:1> <EOL> if found : <EOL> self . view . run_command ( "<STR_LIT>" , { "<STR_LIT>" : start , "<STR_LIT:end>" : finish + <NUM_LIT:1> } ) <EOL> else : <EOL> sublime . status_message ( "<STR_LIT>" % content ) <EOL> class SbpConvertPlistToJsonCommand ( SbpTextCommand ) : <EOL> JSON_SYNTAX = "<STR_LIT>" <EOL> PLIST_SYNTAX = "<STR_LIT>" <EOL> def run_cmd ( self , util ) : <EOL> import json <EOL> from plistlib import readPlistFromBytes , writePlistToBytes <EOL> data = self . view . substr ( sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) ) . encode ( "<STR_LIT:utf-8>" ) <EOL> self . view . replace ( util . edit , sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) , <EOL> json . dumps ( readPlistFromBytes ( data ) , indent = <NUM_LIT:4> , separators = ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) ) ) <EOL> self . view . set_syntax_file ( JSON_SYNTAX ) <EOL> class SbpConvertJsonToPlistCommand ( SbpTextCommand ) : <EOL> JSON_SYNTAX = "<STR_LIT>" <EOL> PLIST_SYNTAX = "<STR_LIT>" <EOL> def run_cmd ( self , util ) : <EOL> import json <EOL> from plistlib import readPlistFromBytes , writePlistToBytes <EOL> data = json . loads ( self . view . substr ( sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) ) ) <EOL> self . view . replace ( util . edit , sublime . Region ( <NUM_LIT:0> , self . view . size ( ) ) , writePlistToBytes ( data ) . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . view . set_syntax_file ( PLIST_SYNTAX ) <EOL> class SbpTrimTrailingWhiteSpaceAndEnsureNewlineAtEofCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit , trim_whitespace , ensure_newline ) : <EOL> if trim_whitespace : <EOL> trailing_white_space = self . view . find_all ( "<STR_LIT>" ) <EOL> trailing_white_space . reverse ( ) <EOL> for r in trailing_white_space : <EOL> self . view . erase ( edit , r ) <EOL> if ensure_newline : <EOL> if self . view . size ( ) > <NUM_LIT:0> and self . view . substr ( self . view . size ( ) - <NUM_LIT:1> ) != '<STR_LIT:\n>' : <EOL> self . view . insert ( edit , self . view . size ( ) , "<STR_LIT:\n>" ) <EOL> class SbpPreSaveWhiteSpaceHook ( sublime_plugin . EventListener ) : <EOL> def on_pre_save ( self , view ) : <EOL> trim = SettingsManager . get ( "<STR_LIT>" ) == True <EOL> ensure = SettingsManager . get ( "<STR_LIT>" ) == True <EOL> if trim or ensure : <EOL> view . run_command ( "<STR_LIT>" , <EOL> { "<STR_LIT>" : trim , "<STR_LIT>" : ensure } ) <EOL> def dedup_views ( window ) : <EOL> group = window . active_group ( ) <EOL> for g in range ( window . num_groups ( ) ) : <EOL> found = dict ( ) <EOL> views = window . views_in_group ( g ) <EOL> active = window . active_view_in_group ( g ) <EOL> for v in views : <EOL> if v . is_dirty ( ) : <EOL> continue <EOL> id = v . buffer_id ( ) <EOL> if id in found : <EOL> if v == active : <EOL> before = found [ id ] <EOL> found [ id ] = v <EOL> v = before <EOL> window . focus_view ( v ) <EOL> window . run_command ( '<STR_LIT>' ) <EOL> else : <EOL> found [ id ] = v <EOL> window . focus_view ( active ) <EOL> window . focus_group ( group ) <EOL> def InitModule ( module_name ) : <EOL> def get_cmd_name ( cls ) : <EOL> name = cls . __name__ <EOL> name = re . sub ( '<STR_LIT>' , r'<STR_LIT>' , name ) . lower ( ) <EOL> return name [ <NUM_LIT:0> : len ( name ) - <NUM_LIT:8> ] <EOL> module = sys . modules [ module_name ] <EOL> for name in dir ( module ) : <EOL> if name . startswith ( "<STR_LIT>" ) : <EOL> cls = getattr ( module , name ) <EOL> try : <EOL> if not issubclass ( cls , SbpTextCommand ) : <EOL> continue <EOL> except : <EOL> continue <EOL> name = get_cmd_name ( cls ) <EOL> cls . jove_cmd_name = name <EOL> if cls . is_kill_cmd : <EOL> kill_cmds . add ( name ) <EOL> if cls . is_ensure_visible_cmd : <EOL> ensure_visible_cmds . add ( name ) <EOL> InitModule ( __name__ ) </s>
