<s> import os <EOL> import re <EOL> import stat <EOL> import subprocess <EOL> import sublime <EOL> import sublime_plugin <EOL> from Vintageous . ex import ex_error <EOL> from Vintageous . ex import shell <EOL> from Vintageous . ex . ex_error import Display <EOL> from Vintageous . ex . ex_error import ERR_CANT_FIND_DIR_IN_CDPATH <EOL> from Vintageous . ex . ex_error import ERR_CANT_MOVE_LINES_ONTO_THEMSELVES <EOL> from Vintageous . ex . ex_error import ERR_CANT_WRITE_FILE <EOL> from Vintageous . ex . ex_error import ERR_EMPTY_BUFFER <EOL> from Vintageous . ex . ex_error import ERR_FILE_EXISTS <EOL> from Vintageous . ex . ex_error import ERR_INVALID_ADDRESS <EOL> from Vintageous . ex . ex_error import ERR_NO_FILE_NAME <EOL> from Vintageous . ex . ex_error import ERR_OTHER_BUFFER_HAS_CHANGES <EOL> from Vintageous . ex . ex_error import ERR_READONLY_FILE <EOL> from Vintageous . ex . ex_error import ERR_UNSAVED_CHANGES <EOL> from Vintageous . ex . ex_error import show_error <EOL> from Vintageous . ex . ex_error import show_message <EOL> from Vintageous . ex . ex_error import show_status <EOL> from Vintageous . ex . ex_error import show_not_implemented <EOL> from Vintageous . ex . ex_error import VimError <EOL> from Vintageous . ex . parser . parser import parse_command_line <EOL> from Vintageous . ex . plat . windows import get_oem_cp <EOL> from Vintageous . ex . plat . windows import get_startup_info <EOL> from Vintageous . state import State <EOL> from Vintageous . vi import abbrev <EOL> from Vintageous . vi import utils <EOL> from Vintageous . vi . constants import MODE_NORMAL <EOL> from Vintageous . vi . constants import MODE_VISUAL <EOL> from Vintageous . vi . constants import MODE_VISUAL_LINE <EOL> from Vintageous . vi . core import ViWindowCommandBase <EOL> from Vintageous . vi . mappings import Mappings <EOL> from Vintageous . vi . search import find_all_in_range <EOL> from Vintageous . vi . settings import set_global <EOL> from Vintageous . vi . settings import set_local <EOL> from Vintageous . vi . sublime import has_dirty_buffers <EOL> from Vintageous . vi . utils import adding_regions <EOL> from Vintageous . vi . utils import first_sel <EOL> from Vintageous . vi . utils import modes <EOL> from Vintageous . vi . utils import R <EOL> from Vintageous . vi . utils import resolve_insertion_point_at_b <EOL> from Vintageous . vi . utils import row_at <EOL> GLOBAL_RANGES = [ ] <EOL> CURRENT_LINE_RANGE = { '<STR_LIT>' : '<STR_LIT:.>' , '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : [ ] , '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : [ ] } <EOL> def changing_cd ( f , * args , ** kwargs ) : <EOL> def inner ( * args , ** kwargs ) : <EOL> try : <EOL> state = State ( args [ <NUM_LIT:0> ] . view ) <EOL> except AttributeError : <EOL> state = State ( args [ <NUM_LIT:0> ] . window . active_view ( ) ) <EOL> old = os . getcwd ( ) <EOL> try : <EOL> os . chdir ( state . settings . vi [ '<STR_LIT>' ] or old ) <EOL> f ( * args , ** kwargs ) <EOL> finally : <EOL> os . chdir ( old ) <EOL> return inner <EOL> def get_view_info ( v ) : <EOL> """<STR_LIT>""" <EOL> path = v . file_name ( ) <EOL> if path : <EOL> parent , leaf = os . path . split ( path ) <EOL> parent = os . path . basename ( parent ) <EOL> path = os . path . join ( parent , leaf ) <EOL> else : <EOL> path = v . name ( ) or str ( v . buffer_id ( ) ) <EOL> leaf = v . name ( ) or '<STR_LIT>' <EOL> status = [ ] <EOL> if not v . file_name ( ) : <EOL> status . append ( "<STR_LIT:t>" ) <EOL> if v . is_dirty ( ) : <EOL> status . append ( "<STR_LIT:*>" ) <EOL> if v . is_read_only ( ) : <EOL> status . append ( "<STR_LIT:r>" ) <EOL> if status : <EOL> leaf += '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( status ) <EOL> return [ leaf , path ] <EOL> class ExTextCommandBase ( sublime_plugin . TextCommand ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ) . __init__ ( * args , ** kwargs ) <EOL> def serialize_sel ( self ) : <EOL> sels = [ ( r . a , r . b ) for r in list ( self . view . sel ( ) ) ] <EOL> self . view . settings ( ) . set ( '<STR_LIT>' , { '<STR_LIT>' : sels } ) <EOL> def deserialize_sel ( self , name = '<STR_LIT>' ) : <EOL> return self . view . settings ( ) . get ( '<STR_LIT>' ) [ name ] or [ ] <EOL> def set_sel ( self ) : <EOL> sel = self . deserialize_sel ( ) <EOL> self . view . sel ( ) . clear ( ) <EOL> self . view . sel ( ) . add_all ( [ sublime . Region ( b ) for ( a , b ) in sel ] ) <EOL> def set_next_sel ( self , data ) : <EOL> self . view . settings ( ) . set ( '<STR_LIT>' , { '<STR_LIT>' : data } ) <EOL> def set_mode ( self ) : <EOL> state = State ( self . view ) <EOL> state . enter_normal_mode ( ) <EOL> self . view . run_command ( '<STR_LIT>' ) <EOL> def run ( self , edit , * args , ** kwargs ) : <EOL> self . serialize_sel ( ) <EOL> self . run_ex_command ( edit , * args , ** kwargs ) <EOL> self . set_sel ( ) <EOL> self . set_mode ( ) <EOL> class ExGoto ( ViWindowCommandBase ) : <EOL> def run ( self , command_line ) : <EOL> if not command_line : <EOL> return <EOL> parsed = parse_command_line ( command_line ) <EOL> r = parsed . line_range . resolve ( self . _view ) <EOL> line_nr = row_at ( self . _view , r . a ) + <NUM_LIT:1> <EOL> self . enter_normal_mode ( mode = self . state . mode ) <EOL> self . state . enter_normal_mode ( ) <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> self . window . run_command ( '<STR_LIT>' , { '<STR_LIT>' : line_nr , '<STR_LIT>' : self . state . mode } ) <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> self . _view . show ( self . _view . sel ( ) [ <NUM_LIT:0> ] ) <EOL> class ExShellOut ( sublime_plugin . TextCommand ) : <EOL> """<STR_LIT>""" <EOL> _last_command = None <EOL> @ changing_cd <EOL> def run ( self , edit , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> shell_cmd = parsed . command . command <EOL> if shell_cmd == '<STR_LIT:!>' : <EOL> if not _last_command : <EOL> return <EOL> shell_cmd = ExShellOut . _last_command <EOL> ExShellOut . _last_command = shell_cmd <EOL> try : <EOL> if not parsed . line_range . is_empty : <EOL> shell . filter_thru_shell ( <EOL> view = self . view , <EOL> edit = edit , <EOL> regions = [ parsed . line_range . resolve ( self . view ) ] , <EOL> cmd = shell_cmd ) <EOL> else : <EOL> out = shell . run_and_read ( self . view , shell_cmd ) <EOL> output_view = self . view . window ( ) . create_output_panel ( '<STR_LIT>' ) <EOL> output_view . settings ( ) . set ( "<STR_LIT>" , False ) <EOL> output_view . settings ( ) . set ( "<STR_LIT>" , False ) <EOL> output_view . settings ( ) . set ( "<STR_LIT>" , False ) <EOL> output_view = self . view . window ( ) . create_output_panel ( '<STR_LIT>' ) <EOL> output_view . run_command ( '<STR_LIT>' , { '<STR_LIT>' : out , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True } ) <EOL> self . view . window ( ) . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> except NotImplementedError : <EOL> show_not_implemented ( ) <EOL> class ExShell ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def open_shell ( self , command ) : <EOL> return subprocess . Popen ( command , cwd = os . getcwd ( ) ) <EOL> @ changing_cd <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> if sublime . platform ( ) == '<STR_LIT>' : <EOL> term = self . view . settings ( ) . get ( '<STR_LIT>' ) <EOL> term = term or os . environ . get ( '<STR_LIT>' ) or os . environ . get ( "<STR_LIT>" ) <EOL> if not term : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> try : <EOL> self . open_shell ( [ term , '<STR_LIT>' , '<STR_LIT>' ] ) . wait ( ) <EOL> except Exception as e : <EOL> print ( e ) <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> elif sublime . platform ( ) == '<STR_LIT>' : <EOL> term = self . view . settings ( ) . get ( '<STR_LIT>' ) <EOL> term = term or os . environ . get ( '<STR_LIT>' ) or os . environ . get ( "<STR_LIT>" ) <EOL> if not term : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> try : <EOL> self . open_shell ( [ term , '<STR_LIT>' , '<STR_LIT>' ] ) . wait ( ) <EOL> except Exception as e : <EOL> print ( e ) <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> elif sublime . platform ( ) == '<STR_LIT>' : <EOL> self . open_shell ( [ '<STR_LIT>' , '<STR_LIT>' ] ) . wait ( ) <EOL> else : <EOL> show_not_implemented ( ) <EOL> class ExReadShellOut ( sublime_plugin . TextCommand ) : <EOL> '''<STR_LIT>''' <EOL> @ changing_cd <EOL> def run ( self , edit , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> r = parsed . line_range . resolve ( self . view ) <EOL> target_point = min ( r . end ( ) , self . view . size ( ) ) <EOL> if parsed . command . command : <EOL> if sublime . platform ( ) == '<STR_LIT>' : <EOL> the_shell = self . view . settings ( ) . get ( '<STR_LIT>' ) <EOL> the_shell = the_shell or os . path . expandvars ( "<STR_LIT>" ) <EOL> if not the_shell : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> try : <EOL> p = subprocess . Popen ( [ the_shell , '<STR_LIT:-c>' , parsed . command . command ] , <EOL> stdout = subprocess . PIPE ) <EOL> except Exception as e : <EOL> print ( e ) <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> self . view . insert ( edit , target_point , p . communicate ( ) [ <NUM_LIT:0> ] [ : - <NUM_LIT:1> ] . decode ( '<STR_LIT:utf-8>' ) . strip ( ) + '<STR_LIT:\n>' ) <EOL> elif sublime . platform ( ) == '<STR_LIT>' : <EOL> p = subprocess . Popen ( [ '<STR_LIT>' , '<STR_LIT>' , parsed . command . command ] , <EOL> stdout = subprocess . PIPE , <EOL> startupinfo = get_startup_info ( ) <EOL> ) <EOL> cp = '<STR_LIT>' + get_oem_cp ( ) <EOL> rv = p . communicate ( ) [ <NUM_LIT:0> ] . decode ( cp ) [ : - <NUM_LIT:2> ] . strip ( ) <EOL> self . view . insert ( edit , target_point , rv . strip ( ) + '<STR_LIT:\n>' ) <EOL> else : <EOL> show_not_implemented ( ) <EOL> else : <EOL> show_not_implemented ( ) <EOL> return <EOL> class ExPromptSelectOpenFile ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> self . file_names = [ get_view_info ( view ) for view in self . window . views ( ) ] <EOL> self . view_ids = [ view . id ( ) for view in self . window . views ( ) ] <EOL> self . window . show_quick_panel ( self . file_names , self . on_done ) <EOL> def on_done ( self , index ) : <EOL> if index == - <NUM_LIT:1> : <EOL> return <EOL> sought_id = self . view_ids [ index ] <EOL> for view in self . window . views ( ) : <EOL> if view . id ( ) == sought_id : <EOL> self . window . focus_view ( view ) <EOL> class ExMap ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> if not ( parsed . command . keys and parsed . command . command ) : <EOL> show_not_implemented ( '<STR_LIT>' ) <EOL> return <EOL> mappings = Mappings ( self . state ) <EOL> mappings . add ( modes . NORMAL , parsed . command . keys , parsed . command . command ) <EOL> mappings . add ( modes . OPERATOR_PENDING , parsed . command . keys , parsed . command . command ) <EOL> mappings . add ( modes . VISUAL , parsed . command . keys , parsed . command . command ) <EOL> class ExUnmap ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> unmap = parse_command_line ( command_line ) <EOL> mappings = Mappings ( self . state ) <EOL> try : <EOL> mappings . remove ( modes . NORMAL , unmap . command . keys ) <EOL> mappings . remove ( modes . OPERATOR_PENDING , unmap . command . keys ) <EOL> mappings . remove ( modes . VISUAL , unmap . command . keys ) <EOL> except KeyError : <EOL> sublime . status_message ( '<STR_LIT>' ) <EOL> class ExNmap ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> nmap_command = parse_command_line ( command_line ) <EOL> keys , command = ( nmap_command . command . keys , <EOL> nmap_command . command . command ) <EOL> mappings = Mappings ( self . state ) <EOL> mappings . add ( modes . NORMAL , keys , command ) <EOL> class ExNunmap ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> nunmap_command = parse_command_line ( command_line ) <EOL> mappings = Mappings ( self . state ) <EOL> try : <EOL> mappings . remove ( modes . NORMAL , nunmap_command . command . keys ) <EOL> except KeyError : <EOL> sublime . status_message ( '<STR_LIT>' ) <EOL> class ExOmap ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> omap_command = parse_command_line ( command_line ) <EOL> keys , command = ( omap_command . command . keys , <EOL> omap_command . command . command ) <EOL> mappings = Mappings ( self . state ) <EOL> mappings . add ( modes . OPERATOR_PENDING , keys , command ) <EOL> class ExOunmap ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> ounmap_command = parse_command_line ( command_line ) <EOL> mappings = Mappings ( self . state ) <EOL> try : <EOL> mappings . remove ( modes . OPERATOR_PENDING , ounmap_command . command . keys ) <EOL> except KeyError : <EOL> sublime . status_message ( '<STR_LIT>' ) <EOL> class ExVmap ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> vmap_command = parse_command_line ( command_line ) <EOL> keys , command = ( vmap_command . command . keys , <EOL> vmap_command . command . command ) <EOL> mappings = Mappings ( self . state ) <EOL> mappings . add ( modes . VISUAL , keys , command ) <EOL> mappings . add ( modes . VISUAL_LINE , keys , command ) <EOL> mappings . add ( modes . VISUAL_BLOCK , keys , command ) <EOL> class ExVunmap ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> vunmap_command = parse_command_line ( command_line ) <EOL> mappings = Mappings ( self . state ) <EOL> try : <EOL> mappings . remove ( modes . VISUAL , vunmap_command . command . keys ) <EOL> mappings . remove ( modes . VISUAL_LINE , vunmap_command . command . keys ) <EOL> mappings . remove ( modes . VISUAL_BLOCK , vunmap_command . command . keys ) <EOL> except KeyError : <EOL> sublime . status_message ( '<STR_LIT>' ) <EOL> class ExAbbreviate ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> if not command_line : <EOL> self . show_abbreviations ( ) <EOL> return <EOL> parsed = parse_command_line ( command_line ) <EOL> if not ( parsed . command . short and parsed . command . full ) : <EOL> show_not_implemented ( '<STR_LIT>' ) <EOL> return <EOL> abbrev . Store ( ) . set ( parsed . command . short , parsed . command . full ) <EOL> def show_abbreviations ( self ) : <EOL> abbrevs = [ '<STR_LIT>' . format ( item [ '<STR_LIT>' ] , item [ '<STR_LIT>' ] ) <EOL> for item in <EOL> abbrev . Store ( ) . get_all ( ) ] <EOL> self . window . show_quick_panel ( abbrevs , <EOL> None , <EOL> flags = sublime . MONOSPACE_FONT ) <EOL> class ExUnabbreviate ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> if not parsed . command . short : <EOL> return <EOL> abbrev . Store ( ) . erase ( parsed . command . short ) <EOL> class ExPrintWorkingDir ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> @ changing_cd <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> show_status ( os . getcwd ( ) ) <EOL> class ExWriteFile ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def check_is_readonly ( self , fname ) : <EOL> '''<STR_LIT>''' <EOL> if not fname : <EOL> return <EOL> try : <EOL> mode = os . stat ( fname ) <EOL> read_only = ( stat . S_IMODE ( mode . st_mode ) & stat . S_IWUSR != stat . S_IWUSR ) <EOL> except FileNotFoundError : <EOL> return <EOL> return read_only <EOL> @ changing_cd <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> if not command_line : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> parsed = parse_command_line ( command_line ) <EOL> if parsed . command . options : <EOL> show_not_implemented ( "<STR_LIT>" ) <EOL> return <EOL> if parsed . command . command : <EOL> show_not_implemented ( '<STR_LIT>' ) <EOL> return <EOL> if not self . _view : <EOL> return <EOL> if parsed . command . appends : <EOL> self . do_append ( parsed ) <EOL> return <EOL> if parsed . command . command : <EOL> show_not_implemented ( "<STR_LIT>" ) <EOL> return <EOL> if parsed . command . target_file : <EOL> self . do_write ( parsed ) <EOL> return <EOL> if not self . _view . file_name ( ) : <EOL> show_error ( VimError ( ERR_NO_FILE_NAME ) ) <EOL> return <EOL> read_only = ( self . check_is_readonly ( self . _view . file_name ( ) ) <EOL> or self . _view . is_read_only ( ) ) <EOL> if read_only and not parsed . command . forced : <EOL> utils . blink ( ) <EOL> show_error ( VimError ( ERR_READONLY_FILE ) ) <EOL> return <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> def do_append ( self , parsed_command ) : <EOL> if parsed_command . command . target_file : <EOL> self . do_append_to_file ( parsed_command ) <EOL> return <EOL> r = None <EOL> if parsed_command . line_range . is_empty : <EOL> r = R ( <NUM_LIT:0> , self . _view . size ( ) ) <EOL> else : <EOL> r = parsed_command . line_range . resolve ( self . _view ) <EOL> text = self . _view . substr ( r ) <EOL> text = text if text . startswith ( '<STR_LIT:\n>' ) else '<STR_LIT:\n>' + text <EOL> location = resolve_insertion_point_at_b ( first_sel ( self . _view ) ) <EOL> self . _view . run_command ( '<STR_LIT>' , { '<STR_LIT>' : text } ) <EOL> utils . replace_sel ( self . _view , R ( self . _view . line ( location ) . a ) ) <EOL> self . enter_normal_mode ( mode = self . state . mode ) <EOL> self . state . enter_normal_mode ( ) <EOL> def do_append_to_file ( self , parsed_command ) : <EOL> r = None <EOL> if parsed_command . line_range . is_empty : <EOL> r = R ( <NUM_LIT:0> , self . _view . size ( ) ) <EOL> else : <EOL> r = parsed_command . line_range . resolve ( self . _view ) <EOL> fname = parsed_command . command . target_file <EOL> if not parsed_command . command . forced and not os . path . exists ( fname ) : <EOL> show_error ( VimError ( ERR_CANT_WRITE_FILE ) ) <EOL> return <EOL> try : <EOL> with open ( fname , '<STR_LIT>' ) as f : <EOL> text = self . _view . substr ( r ) <EOL> f . write ( text ) <EOL> show_status ( '<STR_LIT>' + os . path . abspath ( fname ) ) <EOL> return <EOL> except IOError as e : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( e ) <EOL> print ( '<STR_LIT>' ) <EOL> return <EOL> def do_write ( self , ex_command ) : <EOL> fname = ex_command . command . target_file <EOL> if not ex_command . command . forced : <EOL> if os . path . exists ( fname ) : <EOL> utils . blink ( ) <EOL> show_error ( VimError ( ERR_FILE_EXISTS ) ) <EOL> return <EOL> if self . check_is_readonly ( fname ) : <EOL> utils . blink ( ) <EOL> show_error ( VimError ( ERR_READONLY_FILE ) ) <EOL> return <EOL> region = None <EOL> if ex_command . line_range . is_empty : <EOL> region = R ( <NUM_LIT:0> , self . _view . size ( ) ) <EOL> else : <EOL> region = ex_command . line_range . resolve ( self . _view ) <EOL> assert region is not None , "<STR_LIT>" <EOL> try : <EOL> expanded_path = os . path . expandvars ( os . path . expanduser ( fname ) ) <EOL> expanded_path = os . path . abspath ( expanded_path ) <EOL> with open ( expanded_path , '<STR_LIT>' ) as f : <EOL> text = self . _view . substr ( region ) <EOL> f . write ( text ) <EOL> self . _view . retarget ( expanded_path ) <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> except IOError as e : <EOL> show_error ( VimError ( ERR_CANT_WRITE_FILE ) ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( e ) <EOL> print ( '<STR_LIT>' ) <EOL> class ExWriteAll ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> @ changing_cd <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> forced = parsed . command . forced <EOL> for v in ( v for v in self . window . views ( ) if v . file_name ( ) ) : <EOL> if v . is_read_only ( ) and not forced : <EOL> continue <EOL> v . run_command ( '<STR_LIT>' ) <EOL> class ExFile ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> if self . _view . file_name ( ) : <EOL> fname = self . _view . file_name ( ) <EOL> else : <EOL> fname = '<STR_LIT>' <EOL> attrs = '<STR_LIT>' <EOL> if self . _view . is_read_only ( ) : <EOL> attrs = '<STR_LIT>' <EOL> if self . _view . is_dirty ( ) : <EOL> attrs = '<STR_LIT>' <EOL> lines = '<STR_LIT>' <EOL> if self . _view . rowcol ( self . _view . size ( ) ) [ <NUM_LIT:0> ] : <EOL> lines = self . _view . rowcol ( self . _view . size ( ) ) [ <NUM_LIT:0> ] + <NUM_LIT:1> <EOL> if not isinstance ( lines , str ) : <EOL> vr = self . _view . visible_region ( ) <EOL> start_row , end_row = self . _view . rowcol ( vr . begin ( ) ) [ <NUM_LIT:0> ] , self . _view . rowcol ( vr . end ( ) ) [ <NUM_LIT:0> ] <EOL> mid = ( start_row + end_row + <NUM_LIT:2> ) / <NUM_LIT:2> <EOL> percent = float ( mid ) / lines * <NUM_LIT> <EOL> msg = fname <EOL> if attrs : <EOL> msg += "<STR_LIT>" % attrs <EOL> if isinstance ( lines , str ) : <EOL> msg += "<STR_LIT>" % lines <EOL> else : <EOL> msg += "<STR_LIT>" % ( lines , int ( percent ) ) <EOL> sublime . status_message ( '<STR_LIT>' % msg ) <EOL> class ExMove ( ExTextCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run_ex_command ( self , edit , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> move_command = parse_command_line ( command_line ) <EOL> if move_command . command . address is None : <EOL> show_error ( VimError ( ERR_INVALID_ADDRESS ) ) <EOL> return <EOL> source = move_command . line_range . resolve ( self . view ) <EOL> if any ( s . contains ( source ) for s in self . view . sel ( ) ) : <EOL> show_error ( VimError ( ERR_CANT_MOVE_LINES_ONTO_THEMSELVES ) ) <EOL> return <EOL> destination = move_command . command . address . resolve ( self . view ) <EOL> if destination == source : <EOL> return <EOL> text = self . view . substr ( source ) <EOL> if destination . end ( ) >= self . view . size ( ) : <EOL> text = '<STR_LIT:\n>' + text . rstrip ( ) <EOL> if destination == R ( - <NUM_LIT:1> ) : <EOL> destination = R ( <NUM_LIT:0> ) <EOL> if destination . end ( ) < source . begin ( ) : <EOL> self . view . erase ( edit , source ) <EOL> self . view . insert ( edit , destination . end ( ) , text ) <EOL> self . set_next_sel ( [ [ destination . a , destination . b ] ] ) <EOL> return <EOL> self . view . insert ( edit , destination . end ( ) , text ) <EOL> self . view . erase ( edit , source ) <EOL> self . set_next_sel ( [ [ destination . a , destination . a ] ] ) <EOL> class ExCopy ( ExTextCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ) . __init__ ( * args , ** kwargs ) <EOL> def run_ex_command ( self , edit , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> unresolved = parsed . command . calculate_address ( ) <EOL> if unresolved is None : <EOL> show_error ( VimError ( ERR_INVALID_ADDRESS ) ) <EOL> return <EOL> target_region = unresolved . resolve ( self . view ) <EOL> address = None <EOL> if target_region == R ( - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> address = <NUM_LIT:0> <EOL> else : <EOL> row = utils . row_at ( self . view , target_region . begin ( ) ) + <NUM_LIT:1> <EOL> address = self . view . text_point ( row , <NUM_LIT:0> ) <EOL> source = parsed . line_range . resolve ( self . view ) <EOL> text = self . view . substr ( source ) <EOL> if address >= self . view . size ( ) : <EOL> address = self . view . size ( ) <EOL> text = '<STR_LIT:\n>' + text [ : - <NUM_LIT:1> ] <EOL> self . view . insert ( edit , address , text ) <EOL> cursor_dest = self . view . line ( address + len ( text ) - <NUM_LIT:1> ) . begin ( ) <EOL> self . set_next_sel ( [ ( cursor_dest , cursor_dest ) ] ) <EOL> class ExOnly ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> if not command_line : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> parsed = parse_command_line ( command_line ) <EOL> if not parsed . command . forced and has_dirty_buffers ( self . window ) : <EOL> show_error ( VimError ( ERR_OTHER_BUFFER_HAS_CHANGES ) ) <EOL> return <EOL> current_id = self . _view . id ( ) <EOL> for view in self . window . views ( ) : <EOL> if view . id ( ) == current_id : <EOL> continue <EOL> if view . is_dirty ( ) : <EOL> view . set_scratch ( True ) <EOL> view . close ( ) <EOL> class ExDoubleAmpersand ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> new_command_line = '<STR_LIT>' . format ( <EOL> str ( parsed . line_range ) , <EOL> '<STR_LIT>' . join ( parsed . command . params [ '<STR_LIT>' ] ) , <EOL> parsed . command . params [ '<STR_LIT:count>' ] , <EOL> ) <EOL> self . window . run_command ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : new_command_line . strip ( ) <EOL> } ) <EOL> class ExSubstitute ( sublime_plugin . TextCommand ) : <EOL> '''<STR_LIT>''' <EOL> last_pattern = None <EOL> last_flags = [ ] <EOL> last_replacement = '<STR_LIT>' <EOL> def run ( self , edit , command_line = '<STR_LIT>' ) : <EOL> if not command_line : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> parsed = parse_command_line ( command_line ) <EOL> pattern = parsed . command . pattern <EOL> replacement = parsed . command . replacement <EOL> count = parsed . command . count <EOL> flags = parsed . command . flags <EOL> if not pattern : <EOL> pattern = ExSubstitute . last_pattern <EOL> replacement = ExSubstitute . last_replacement <EOL> flags = [ ] <EOL> count = <NUM_LIT:0> <EOL> if not pattern : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> ExSubstitute . last_pattern = pattern <EOL> ExSubstitute . last_replacement = replacement <EOL> ExSubstitute . last_flags = flags <EOL> computed_flags = re . MULTILINE <EOL> computed_flags |= re . IGNORECASE if ( '<STR_LIT:i>' in flags ) else <NUM_LIT:0> <EOL> try : <EOL> compiled_rx = re . compile ( pattern , flags = computed_flags ) <EOL> except Exception as e : <EOL> sublime . status_message ( <EOL> "<STR_LIT>" % ( e . message , pattern ) ) <EOL> print ( "<STR_LIT>" <EOL> % ( e . message , pattern ) ) <EOL> return <EOL> replace_count = <NUM_LIT:0> if ( flags and '<STR_LIT:g>' in flags ) else <NUM_LIT:1> <EOL> target_region = parsed . line_range . resolve ( self . view ) <EOL> if '<STR_LIT:c>' in flags : <EOL> self . replace_confirming ( edit , pattern , compiled_rx , replacement , replace_count , target_region ) <EOL> return <EOL> line_text = self . view . substr ( target_region ) <EOL> new_text = re . sub ( compiled_rx , replacement , line_text , count = replace_count ) <EOL> self . view . replace ( edit , target_region , new_text ) <EOL> def replace_confirming ( self , edit , pattern , compiled_rx , replacement , <EOL> replace_count , target_region ) : <EOL> last_row = row_at ( self . view , target_region . b - <NUM_LIT:1> ) <EOL> start = target_region . begin ( ) <EOL> while True : <EOL> match = self . view . find ( pattern , start ) <EOL> if ( match == R ( - <NUM_LIT:1> ) ) or ( row_at ( self . view , match . a ) > last_row ) : <EOL> self . view . show ( first_sel ( self . view ) . begin ( ) ) <EOL> return <EOL> size_before = self . view . size ( ) <EOL> with adding_regions ( self . view , '<STR_LIT>' , [ match ] , '<STR_LIT>' ) : <EOL> self . view . show ( match . a , True ) <EOL> if sublime . ok_cancel_dialog ( "<STR_LIT>" ) : <EOL> text = self . view . substr ( match ) <EOL> substituted = re . sub ( compiled_rx , replacement , text , count = replace_count ) <EOL> self . view . replace ( edit , match , substituted ) <EOL> start = match . b + ( self . view . size ( ) - size_before ) <EOL> class ExDelete ( ExTextCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def select ( self , regions , register ) : <EOL> self . view . sel ( ) . clear ( ) <EOL> to_store = [ ] <EOL> for r in regions : <EOL> self . view . sel ( ) . add ( r ) <EOL> if register : <EOL> to_store . append ( self . view . substr ( self . view . full_line ( r ) ) ) <EOL> if register : <EOL> text = '<STR_LIT>' . join ( to_store ) <EOL> if not text . endswith ( '<STR_LIT:\n>' ) : <EOL> text = text + '<STR_LIT:\n>' <EOL> state = State ( self . view ) <EOL> state . registers [ register ] = [ text ] <EOL> def run_ex_command ( self , edit , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> r = parsed . line_range . resolve ( self . view ) <EOL> if r == R ( - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> r = self . view . full_line ( <NUM_LIT:0> ) <EOL> self . select ( [ r ] , parsed . command . params [ '<STR_LIT>' ] ) <EOL> self . view . erase ( edit , r ) <EOL> self . set_next_sel ( [ ( r . a , r . a ) ] ) <EOL> class ExGlobal ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> most_recent_pat = None <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> global_range = None <EOL> if parsed . line_range . is_empty : <EOL> global_range = R ( <NUM_LIT:0> , self . _view . size ( ) ) <EOL> else : <EOL> global_range = parsed . line_range . resolve ( self . _view ) <EOL> pattern = parsed . command . pattern <EOL> if pattern : <EOL> ExGlobal . most_recent_pat = pattern <EOL> else : <EOL> pattern = ExGlobal . most_recent_pat <EOL> subcmd = parsed . command . subcommand <EOL> try : <EOL> matches = find_all_in_range ( self . _view , pattern , <EOL> global_range . begin ( ) , global_range . end ( ) ) <EOL> except Exception as e : <EOL> msg = "<STR_LIT>" % ( str ( e ) , pattern ) <EOL> sublime . status_message ( msg ) <EOL> print ( msg ) <EOL> return <EOL> if not matches or not parsed . command . subcommand . cooperates_with_global : <EOL> return <EOL> matches = [ self . _view . full_line ( r . begin ( ) ) for r in matches ] <EOL> matches = [ [ r . a , r . b ] for r in matches ] <EOL> self . window . run_command ( subcmd . target_command , { <EOL> '<STR_LIT>' : str ( subcmd ) , <EOL> '<STR_LIT>' : matches , <EOL> } ) <EOL> class ExPrint ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' , global_lines = None ) : <EOL> assert command_line , '<STR_LIT>' <EOL> if self . _view . size ( ) == <NUM_LIT:0> : <EOL> show_error ( VimError ( ERR_EMPTY_BUFFER ) ) <EOL> return <EOL> parsed = parse_command_line ( command_line ) <EOL> r = parsed . line_range . resolve ( self . _view ) <EOL> lines = self . get_lines ( r , global_lines ) <EOL> display = self . window . new_file ( ) <EOL> display . set_scratch ( True ) <EOL> if '<STR_LIT:l>' in parsed . command . flags : <EOL> display . settings ( ) . set ( '<STR_LIT>' , '<STR_LIT:all>' ) <EOL> for ( text , row ) in lines : <EOL> characters = '<STR_LIT>' <EOL> if '<STR_LIT:#>' in parsed . command . flags : <EOL> characters = "<STR_LIT>" . format ( row , text ) . lstrip ( ) <EOL> else : <EOL> characters = text . lstrip ( ) <EOL> display . run_command ( '<STR_LIT>' , { '<STR_LIT>' : characters } ) <EOL> def get_lines ( self , parsed_range , global_lines ) : <EOL> if global_lines : <EOL> return [ ( self . _view . substr ( R ( a , b ) ) , row_at ( self . _view , a ) ) for ( a , b ) in global_lines ] <EOL> to_display = [ ] <EOL> for line in self . _view . full_line ( parsed_range ) : <EOL> text = self . _view . substr ( line ) <EOL> to_display . append ( ( text , row_at ( self . _view , line . begin ( ) ) ) ) <EOL> return to_display <EOL> class ExQuitCommand ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> quit_command = parse_command_line ( command_line ) <EOL> view = self . _view <EOL> if quit_command . command . forced : <EOL> view . set_scratch ( True ) <EOL> if view . is_dirty ( ) and not quit_command . command . forced : <EOL> show_error ( VimError ( ERR_UNSAVED_CHANGES ) ) <EOL> return <EOL> if not view . file_name ( ) and not quit_command . command . forced : <EOL> show_error ( VimError ( ERR_NO_FILE_NAME ) ) <EOL> return <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> if len ( self . window . views ( ) ) == <NUM_LIT:0> : <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> return <EOL> if not self . window . views_in_group ( self . window . active_group ( ) ) : <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> class ExQuitAllCommand ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> if parsed . command . forced : <EOL> for v in self . window . views ( ) : <EOL> if v . is_dirty ( ) : <EOL> v . set_scratch ( True ) <EOL> elif has_dirty_buffers ( self . window ) : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> class ExWriteAndQuitCommand ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> if parsed . command . forced : <EOL> show_not_implemented ( ) <EOL> return <EOL> if self . _view . is_read_only ( ) : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> if not self . _view . file_name ( ) : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> self . window . run_command ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> class ExBrowse ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line ) : <EOL> assert command_line , '<STR_LIT>' <EOL> self . window . run_command ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : self . state . settings . vi [ '<STR_LIT>' ] <EOL> } ) <EOL> class ExEdit ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> @ changing_cd <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> if parsed . command . file_name : <EOL> file_name = os . path . expanduser ( <EOL> os . path . expandvars ( parsed . command . file_name ) ) <EOL> if self . _view . is_dirty ( ) and not parsed . command . forced : <EOL> show_error ( VimError ( ERR_UNSAVED_CHANGES ) ) <EOL> return <EOL> if os . path . isdir ( file_name ) : <EOL> show_message ( '<STR_LIT>' , displays = Display . ALL ) <EOL> return <EOL> if not os . path . isabs ( file_name ) : <EOL> file_name = os . path . join ( <EOL> self . state . settings . vi [ '<STR_LIT>' ] , <EOL> file_name ) <EOL> if not os . path . exists ( file_name ) : <EOL> msg = '<STR_LIT>' . format ( os . path . basename ( file_name ) ) <EOL> parent = os . path . dirname ( file_name ) <EOL> if parent and not os . path . exists ( parent ) : <EOL> msg = '<STR_LIT>' . format ( parsed . command . file_name ) <EOL> self . window . open_file ( file_name ) <EOL> sublime . set_timeout ( <EOL> lambda : show_message ( msg , displays = Display . ALL ) , <NUM_LIT> ) <EOL> return <EOL> show_not_implemented ( <EOL> '<STR_LIT>' . format ( command_line ) ) <EOL> return <EOL> if parsed . command . forced or not self . _view . is_dirty ( ) : <EOL> self . _view . run_command ( '<STR_LIT>' ) <EOL> return <EOL> if self . _view . is_dirty ( ) : <EOL> show_error ( VimError ( ERR_UNSAVED_CHANGES ) ) <EOL> return <EOL> show_error ( VimError ( ERR_UNSAVED_CHANGES ) ) <EOL> class ExCquit ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> class ExExit ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> if self . _view . is_dirty ( ) : <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> if len ( self . window . views ( ) ) == <NUM_LIT:0> : <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> class ExListRegisters ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line ) : <EOL> def show_lines ( line_count ) : <EOL> lines_display = '<STR_LIT>' . format ( line_count - <NUM_LIT:1> ) <EOL> return lines_display if line_count > <NUM_LIT:1> else '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> pairs = [ ( k , v ) for ( k , v ) in self . state . registers . to_dict ( ) . items ( ) if v ] <EOL> pairs = [ ( k , repr ( v [ <NUM_LIT:0> ] ) , len ( v ) ) for ( k , v ) in pairs ] <EOL> pairs = [ '<STR_LIT>' . format ( k , v , show_lines ( lines ) ) for ( k , v , lines ) in pairs ] <EOL> self . window . show_quick_panel ( pairs , self . on_done , flags = sublime . MONOSPACE_FONT ) <EOL> def on_done ( self , idx ) : <EOL> """<STR_LIT>""" <EOL> if idx == - <NUM_LIT:1> : <EOL> return <EOL> value = list ( self . state . registers . to_dict ( ) . values ( ) ) [ idx ] <EOL> self . state . registers [ '<STR_LIT:">' ] = [ value ] <EOL> class ExNew ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> @ changing_cd <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> class ExYank ( sublime_plugin . TextCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , edit , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> register = parsed . command . register <EOL> line_range = parsed . line_range . resolve ( self . view ) <EOL> if not register : <EOL> register = '<STR_LIT:">' <EOL> text = self . view . substr ( line_range ) <EOL> state = State ( self . view ) <EOL> state . registers [ register ] = [ text ] <EOL> if register == '<STR_LIT:">' : <EOL> state . registers [ '<STR_LIT:0>' ] = [ text ] <EOL> class TabControlCommand ( ViWindowCommandBase ) : <EOL> def run ( self , command , file_name = None , forced = False ) : <EOL> view_count = len ( self . window . views ( ) ) <EOL> ( group_index , view_index ) = self . window . get_view_index ( self . _view ) <EOL> if command == '<STR_LIT>' : <EOL> if not file_name : <EOL> self . window . run_command ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> } ) <EOL> else : <EOL> cur_dir = os . path . dirname ( self . _view . file_name ( ) ) <EOL> self . window . open_file ( os . path . join ( cur_dir , file_name ) ) <EOL> elif command == '<STR_LIT>' : <EOL> self . window . run_command ( '<STR_LIT>' , { <EOL> '<STR_LIT:index>' : ( view_index + <NUM_LIT:1> ) % view_count } ) <EOL> elif command == '<STR_LIT>' : <EOL> self . window . run_command ( '<STR_LIT>' , { <EOL> '<STR_LIT:index>' : ( view_index + view_count - <NUM_LIT:1> ) % view_count } ) <EOL> elif command == "<STR_LIT>" : <EOL> self . window . run_command ( '<STR_LIT>' , { '<STR_LIT:index>' : view_count - <NUM_LIT:1> } ) <EOL> elif command == "<STR_LIT>" : <EOL> self . window . run_command ( '<STR_LIT>' , { '<STR_LIT:index>' : <NUM_LIT:0> } ) <EOL> elif command == '<STR_LIT>' : <EOL> quit_command_line = '<STR_LIT>' + '<STR_LIT>' if not forced else '<STR_LIT:!>' <EOL> group = self . window . views_in_group ( group_index ) <EOL> if any ( view . is_dirty ( ) for view in group ) : <EOL> show_error ( VimError ( ERR_OTHER_BUFFER_HAS_CHANGES ) ) <EOL> return <EOL> for view in group : <EOL> if view . id ( ) == self . _view . id ( ) : <EOL> continue <EOL> self . window . focus_view ( view ) <EOL> self . window . run_command ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : quit_command_line } ) <EOL> self . window . focus_view ( self . _view ) <EOL> else : <EOL> show_message ( "<STR_LIT>" , displays = Display . ALL ) <EOL> class ExTabOpenCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self , file_name = None ) : <EOL> self . window . run_command ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : file_name } , ) <EOL> class ExTabnextCommand ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> self . window . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" } , ) <EOL> class ExTabprevCommand ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> self . window . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" } , ) <EOL> class ExTablastCommand ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> self . window . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" } , ) <EOL> class ExTabfirstCommand ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> self . window . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" } , ) <EOL> class ExTabonlyCommand ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> self . window . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : parsed . command . forced } ) <EOL> class ExCdCommand ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> @ changing_cd <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> if self . _view . is_dirty ( ) and not parsed . command . forced : <EOL> show_error ( VimError ( ERR_UNSAVED_CHANGES ) ) <EOL> return <EOL> if not parsed . command . path : <EOL> self . state . settings . vi [ '<STR_LIT>' ] = os . path . expanduser ( "<STR_LIT>" ) <EOL> self . _view . run_command ( '<STR_LIT>' ) <EOL> return <EOL> if parsed . command . path == '<STR_LIT>' : <EOL> fname = self . _view . file_name ( ) <EOL> if fname : <EOL> self . state . settings . vi [ '<STR_LIT>' ] = os . path . dirname ( fname ) <EOL> self . _view . run_command ( '<STR_LIT>' ) <EOL> return <EOL> path = os . path . realpath ( os . path . expandvars ( os . path . expanduser ( parsed . command . path ) ) ) <EOL> if not os . path . exists ( path ) : <EOL> show_error ( VimError ( ERR_CANT_FIND_DIR_IN_CDPATH ) ) <EOL> return <EOL> self . state . settings . vi [ '<STR_LIT>' ] = path <EOL> self . _view . run_command ( '<STR_LIT>' ) <EOL> class ExCddCommand ( ViWindowCommandBase ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> if self . _view . is_dirty ( ) and not parsed . command . forced : <EOL> show_error ( VimError ( ERR_UNSAVED_CHANGES ) ) <EOL> return <EOL> path = os . path . dirname ( self . _view . file_name ( ) ) <EOL> try : <EOL> self . state . settings . vi [ '<STR_LIT>' ] = path <EOL> show_status ( path ) <EOL> except IOError : <EOL> show_error ( VimError ( ERR_CANT_FIND_DIR_IN_CDPATH ) ) <EOL> class ExVsplit ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> MAX_SPLITS = <NUM_LIT:4> <EOL> LAYOUT_DATA = { <EOL> <NUM_LIT:1> : { "<STR_LIT>" : [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] ] , "<STR_LIT>" : [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] , "<STR_LIT>" : [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] } , <EOL> <NUM_LIT:2> : { "<STR_LIT>" : [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> ] ] , "<STR_LIT>" : [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] , "<STR_LIT>" : [ <NUM_LIT:0.0> , <NUM_LIT:0.5> , <NUM_LIT:1.0> ] } , <EOL> <NUM_LIT:3> : { "<STR_LIT>" : [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:1> ] ] , "<STR_LIT>" : [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] , "<STR_LIT>" : [ <NUM_LIT:0.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0> ] } , <EOL> <NUM_LIT:4> : { "<STR_LIT>" : [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:1> ] , [ <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:1> ] ] , "<STR_LIT>" : [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] , "<STR_LIT>" : [ <NUM_LIT:0.0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0> ] } , <EOL> } <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> parsed = parse_command_line ( command_line ) <EOL> file_name = parsed . command . params [ '<STR_LIT>' ] <EOL> groups = self . window . num_groups ( ) <EOL> if groups >= ExVsplit . MAX_SPLITS : <EOL> show_message ( "<STR_LIT>" , displays = Display . ALL ) <EOL> return <EOL> old_view = self . _view <EOL> pos = "<STR_LIT>" . format ( * old_view . rowcol ( old_view . sel ( ) [ <NUM_LIT:0> ] . b ) ) <EOL> current_file_name = old_view . file_name ( ) + pos <EOL> self . window . run_command ( '<STR_LIT>' , ExVsplit . LAYOUT_DATA [ groups + <NUM_LIT:1> ] ) <EOL> if file_name : <EOL> existing = self . window . find_open_file ( file_name ) <EOL> pos = '<STR_LIT>' <EOL> if existing : <EOL> pos = "<STR_LIT>" . format ( * existing . rowcol ( existing . sel ( ) [ <NUM_LIT:0> ] . b ) ) <EOL> self . open_file ( file_name + pos ) <EOL> return <EOL> self . open_file ( current_file_name ) <EOL> def open_file ( self , file_name ) : <EOL> flags = ( sublime . FORCE_GROUP | sublime . ENCODED_POSITION ) <EOL> self . window . open_file ( file_name , group = ( self . window . num_groups ( ) - <NUM_LIT:1> ) , <EOL> flags = flags ) <EOL> class ExUnvsplit ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> groups = self . window . num_groups ( ) <EOL> if groups == <NUM_LIT:1> : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> return <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> self . window . run_command ( '<STR_LIT>' , ExVsplit . LAYOUT_DATA [ groups - <NUM_LIT:1> ] ) <EOL> class ExSetLocal ( ViWindowCommandBase ) : <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> option = parsed . command . option <EOL> value = parsed . command . value <EOL> if option . endswith ( '<STR_LIT:?>' ) : <EOL> show_not_implemented ( ) <EOL> return <EOL> try : <EOL> set_local ( self . _view , option , value ) <EOL> except KeyError : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> except ValueError : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> class ExSet ( ViWindowCommandBase ) : <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> option = parsed . command . option <EOL> value = parsed . command . value <EOL> print ( locals ( ) ) <EOL> if option . endswith ( '<STR_LIT:?>' ) : <EOL> show_not_implemented ( ) <EOL> return <EOL> try : <EOL> set_global ( self . _view , option , value ) <EOL> except KeyError : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> except ValueError : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> class ExLet ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> parsed = parse_command_line ( command_line ) <EOL> self . state . variables . set ( parsed . command . variable_name , <EOL> parsed . command . variable_value ) <EOL> class ExWriteAndQuitAll ( ViWindowCommandBase ) : <EOL> '''<STR_LIT>''' <EOL> def run ( self , command_line = '<STR_LIT>' ) : <EOL> assert command_line , '<STR_LIT>' <EOL> if not all ( v . file_name ( ) for v in self . window . views ( ) ) : <EOL> show_error ( VimError ( ERR_NO_FILE_NAME ) ) <EOL> utils . blink ( ) <EOL> return <EOL> if any ( v . is_read_only ( ) for v in self . window . views ( ) ) : <EOL> show_error ( VimError ( ERR_READONLY_FILE ) ) <EOL> utils . blink ( ) <EOL> return <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> assert not any ( v . is_dirty ( ) for v in self . window . views ( ) ) <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> self . window . run_command ( '<STR_LIT>' ) </s>
