<s> import sublime <EOL> from collections import defaultdict <EOL> from collections import namedtuple <EOL> import json <EOL> vi_user_setting = namedtuple ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> WINDOW_SETTINGS = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> SCOPE_WINDOW = <NUM_LIT:1> <EOL> SCOPE_VIEW = <NUM_LIT:2> <EOL> SCOPE_VI_VIEW = <NUM_LIT:3> <EOL> SCOPE_VI_WINDOW = <NUM_LIT:4> <EOL> def volatile ( f ) : <EOL> VintageSettings . _volatile_settings . append ( f . __name__ ) <EOL> return f <EOL> def destroy ( view ) : <EOL> try : <EOL> del VintageSettings . _volatile [ view . id ( ) ] <EOL> except KeyError : <EOL> pass <EOL> def set_generic_view_setting ( view , name , value , opt , globally = False ) : <EOL> if opt . scope == SCOPE_VI_VIEW : <EOL> name = '<STR_LIT>' + name <EOL> if not opt . parser : <EOL> if not globally or ( opt . scope not in ( SCOPE_VI_VIEW , SCOPE_VI_WINDOW ) ) : <EOL> view . settings ( ) . set ( name , value ) <EOL> else : <EOL> prefs = sublime . load_settings ( '<STR_LIT>' ) <EOL> prefs . set ( name , value ) <EOL> sublime . save_settings ( '<STR_LIT>' ) <EOL> return <EOL> else : <EOL> if not globally or ( opt . scope not in ( SCOPE_VI_VIEW , SCOPE_VI_WINDOW ) ) : <EOL> view . settings ( ) . set ( name , opt . parser ( value ) ) <EOL> else : <EOL> name = '<STR_LIT>' + name <EOL> prefs = sublime . load_settings ( '<STR_LIT>' ) <EOL> prefs . set ( name , opt . parser ( value ) ) <EOL> sublime . save_settings ( '<STR_LIT>' ) <EOL> return <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def set_minimap ( view , name , value , opt , globally = False ) : <EOL> view . window ( ) . run_command ( '<STR_LIT>' ) <EOL> def set_sidebar ( view , name , value , opt , globally = False ) : <EOL> view . window ( ) . run_command ( '<STR_LIT>' ) <EOL> def opt_bool_parser ( value ) : <EOL> if value . lower ( ) in ( '<STR_LIT:false>' , '<STR_LIT:true>' , '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:yes>' , '<STR_LIT>' ) : <EOL> if value . lower ( ) in ( '<STR_LIT:true>' , '<STR_LIT:1>' , '<STR_LIT:yes>' ) : <EOL> return True <EOL> return False <EOL> def opt_rulers_parser ( value ) : <EOL> try : <EOL> converted = json . loads ( value ) <EOL> if isinstance ( converted , list ) : <EOL> return converted <EOL> else : <EOL> raise ValueError <EOL> except ValueError : <EOL> raise <EOL> except TypeError : <EOL> raise ValueError <EOL> VI_OPTIONS = { <EOL> '<STR_LIT>' : vi_user_setting ( scope = SCOPE_VI_VIEW , values = ( True , False , '<STR_LIT:0>' , '<STR_LIT:1>' ) , default = True , parser = None , action = set_generic_view_setting , negatable = False ) , <EOL> '<STR_LIT>' : vi_user_setting ( scope = SCOPE_VI_VIEW , values = ( True , False , '<STR_LIT:0>' , '<STR_LIT:1>' ) , default = True , parser = opt_bool_parser , action = set_generic_view_setting , negatable = True ) , <EOL> '<STR_LIT>' : vi_user_setting ( scope = SCOPE_VI_VIEW , values = ( True , False , '<STR_LIT:0>' , '<STR_LIT:1>' ) , default = False , parser = opt_bool_parser , action = set_generic_view_setting , negatable = True ) , <EOL> '<STR_LIT>' : vi_user_setting ( scope = SCOPE_VI_VIEW , values = ( True , False , '<STR_LIT:0>' , '<STR_LIT:1>' ) , default = True , parser = opt_bool_parser , action = set_generic_view_setting , negatable = True ) , <EOL> '<STR_LIT>' : vi_user_setting ( scope = SCOPE_VI_VIEW , values = ( True , False , '<STR_LIT:0>' , '<STR_LIT:1>' ) , default = True , parser = opt_bool_parser , action = set_generic_view_setting , negatable = True ) , <EOL> '<STR_LIT>' : vi_user_setting ( scope = SCOPE_VI_WINDOW , values = ( True , False , '<STR_LIT:0>' , '<STR_LIT:1>' ) , default = True , parser = opt_bool_parser , action = set_generic_view_setting , negatable = True ) , <EOL> '<STR_LIT>' : vi_user_setting ( scope = SCOPE_VIEW , values = None , default = [ ] , parser = opt_rulers_parser , action = set_generic_view_setting , negatable = False ) , <EOL> '<STR_LIT>' : vi_user_setting ( scope = SCOPE_WINDOW , values = ( True , False , '<STR_LIT:0>' , '<STR_LIT:1>' ) , default = True , parser = None , action = set_minimap , negatable = True ) , <EOL> '<STR_LIT>' : vi_user_setting ( scope = SCOPE_WINDOW , values = ( True , False , '<STR_LIT:0>' , '<STR_LIT:1>' ) , default = True , parser = None , action = set_sidebar , negatable = True ) , <EOL> } <EOL> def iter_settings ( prefix = '<STR_LIT>' ) : <EOL> if prefix . startswith ( '<STR_LIT>' ) : <EOL> for item in ( x for ( x , y ) in VI_OPTIONS . items ( ) if y . negatable ) : <EOL> if ( '<STR_LIT>' + item ) . startswith ( prefix ) : <EOL> yield '<STR_LIT>' + item <EOL> else : <EOL> for k in sorted ( VI_OPTIONS . keys ( ) ) : <EOL> if ( prefix == '<STR_LIT>' ) or k . startswith ( prefix ) : <EOL> yield k <EOL> def set_local ( view , name , value ) : <EOL> try : <EOL> opt = VI_OPTIONS [ name ] <EOL> if not value and opt . negatable : <EOL> opt . action ( view , name , '<STR_LIT:1>' , opt ) <EOL> return <EOL> opt . action ( view , name , value , opt ) <EOL> except KeyError as e : <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> try : <EOL> opt = VI_OPTIONS [ name [ <NUM_LIT:2> : ] ] <EOL> if opt . negatable : <EOL> opt . action ( view , name [ <NUM_LIT:2> : ] , '<STR_LIT:0>' , opt ) <EOL> return <EOL> except KeyError : <EOL> pass <EOL> raise <EOL> def set_global ( view , name , value ) : <EOL> try : <EOL> opt = VI_OPTIONS [ name ] <EOL> if not value and opt . negatable : <EOL> opt . action ( view , name , '<STR_LIT:1>' , opt , globally = True ) <EOL> return <EOL> opt . action ( view , name , value , opt , globally = True ) <EOL> except KeyError as e : <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> try : <EOL> opt = VI_OPTIONS [ name [ <NUM_LIT:2> : ] ] <EOL> if opt . negatable : <EOL> opt . action ( view , name [ <NUM_LIT:2> : ] , '<STR_LIT:0>' , opt , globally = True ) <EOL> return <EOL> except KeyError : <EOL> pass <EOL> raise <EOL> def get_option ( view , name ) : <EOL> try : <EOL> option_data = VI_OPTIONS [ name ] <EOL> except KeyError : <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> if option_data . scope == SCOPE_WINDOW : <EOL> value = view . window ( ) . settings ( ) . get ( '<STR_LIT>' + name ) <EOL> else : <EOL> value = view . settings ( ) . get ( '<STR_LIT>' + name ) <EOL> return value if ( value in option_data . values ) else option_data . default <EOL> class SublimeSettings ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , view = None ) : <EOL> self . view = view <EOL> def __get__ ( self , instance , owner ) : <EOL> if instance is not None : <EOL> return SublimeSettings ( instance . v ) <EOL> return SublimeSettings ( ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . view . settings ( ) . get ( key ) <EOL> def __setitem__ ( self , key , value ) : <EOL> self . view . settings ( ) . set ( key , value ) <EOL> class VintageSettings ( object ) : <EOL> """<STR_LIT>""" <EOL> _volatile_settings = [ ] <EOL> _volatile = defaultdict ( dict ) <EOL> def __init__ ( self , view = None ) : <EOL> self . view = view <EOL> if view is not None and not isinstance ( self . view . settings ( ) . get ( '<STR_LIT>' ) , dict ) : <EOL> self . view . settings ( ) . set ( '<STR_LIT>' , dict ( ) ) <EOL> if view is not None and view . window ( ) is not None and not isinstance ( self . view . window ( ) . settings ( ) . get ( '<STR_LIT>' ) , dict ) : <EOL> self . view . window ( ) . settings ( ) . set ( '<STR_LIT>' , dict ( ) ) <EOL> def __get__ ( self , instance , owner ) : <EOL> if instance is not None : <EOL> return VintageSettings ( instance . v ) <EOL> return VintageSettings ( ) <EOL> def __getitem__ ( self , key ) : <EOL> try : <EOL> return get_option ( self . view , key ) <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> if key not in WINDOW_SETTINGS : <EOL> try : <EOL> return self . _get_volatile ( key ) <EOL> except KeyError : <EOL> value = self . _get_vintageous_view_setting ( key ) <EOL> else : <EOL> value = self . _get_vintageous_window_setting ( key ) <EOL> except ( KeyError , AttributeError ) : <EOL> value = None <EOL> return value <EOL> def __setitem__ ( self , key , value ) : <EOL> if key not in WINDOW_SETTINGS : <EOL> if key in VintageSettings . _volatile_settings : <EOL> self . _set_volatile ( key , value ) <EOL> return <EOL> setts , target = self . view . settings ( ) . get ( '<STR_LIT>' ) , self . view <EOL> else : <EOL> setts , target = self . view . window ( ) . settings ( ) . get ( '<STR_LIT>' ) , self . view . window ( ) <EOL> setts [ key ] = value <EOL> target . settings ( ) . set ( '<STR_LIT>' , setts ) <EOL> def _get_vintageous_view_setting ( self , key ) : <EOL> return self . view . settings ( ) . get ( '<STR_LIT>' ) . get ( key ) <EOL> def _get_vintageous_window_setting ( self , key ) : <EOL> return self . view . window ( ) . settings ( ) . get ( '<STR_LIT>' ) . get ( key ) <EOL> def _get_volatile ( self , key ) : <EOL> try : <EOL> return VintageSettings . _volatile [ self . view . id ( ) ] [ key ] <EOL> except KeyError : <EOL> raise KeyError ( '<STR_LIT>' % key ) <EOL> def _set_volatile ( self , key , value ) : <EOL> try : <EOL> VintageSettings . _volatile [ self . view . id ( ) ] [ key ] = value <EOL> except KeyError : <EOL> raise KeyError ( '<STR_LIT>' % ( key , value ) ) <EOL> class SublimeWindowSettings ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , view = None ) : <EOL> self . view = view <EOL> def __get__ ( self , instance , owner ) : <EOL> if instance is not None : <EOL> return SublimeSettings ( instance . v . window ( ) ) <EOL> return SublimeSettings ( ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . view . window ( ) . settings ( ) . get ( key ) <EOL> def __setitem__ ( self , key , value ) : <EOL> self . view . window ( ) . settings ( ) . set ( key , value ) <EOL> class SettingsManager ( object ) : <EOL> view = SublimeSettings ( ) <EOL> vi = VintageSettings ( ) <EOL> window = SublimeWindowSettings ( ) <EOL> def __init__ ( self , view ) : <EOL> self . v = view </s>
