<s> import sublime , sublime_plugin , re , sys , os , json <EOL> directory = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> libs_path = os . path . join ( directory , "<STR_LIT>" ) <EOL> src_path = os . path . join ( directory , "<STR_LIT:src>" ) <EOL> is_py2k = sys . version_info < ( <NUM_LIT:3> , <NUM_LIT:0> ) <EOL> def add_lib_path ( lib_path ) : <EOL> def _try_get_short_path ( path ) : <EOL> path = os . path . normpath ( path ) <EOL> if is_py2k and os . name == '<STR_LIT>' and isinstance ( path , unicode ) : <EOL> try : <EOL> import locale <EOL> path = path . encode ( locale . getpreferredencoding ( ) ) <EOL> except : <EOL> from ctypes import windll , create_unicode_buffer <EOL> buf = create_unicode_buffer ( <NUM_LIT> ) <EOL> if windll . kernel32 . GetShortPathNameW ( path , buf , len ( buf ) ) : <EOL> path = buf . value <EOL> return path <EOL> lib_path = _try_get_short_path ( lib_path ) <EOL> if lib_path not in sys . path : <EOL> sys . path . append ( lib_path ) <EOL> add_lib_path ( libs_path ) <EOL> add_lib_path ( os . path . join ( libs_path , "<STR_LIT>" ) ) <EOL> add_lib_path ( os . path . join ( libs_path , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> add_lib_path ( src_path ) <EOL> import jsbeautifier , jsbeautifier . unpackers <EOL> import jsf , jsf_activation , jsf_rc <EOL> s = None <EOL> def plugin_loaded ( ) : <EOL> global s <EOL> s = sublime . load_settings ( "<STR_LIT>" ) <EOL> if is_py2k : <EOL> plugin_loaded ( ) <EOL> class PreSaveFormatListner ( sublime_plugin . EventListener ) : <EOL> """<STR_LIT>""" <EOL> def on_pre_save ( self , view ) : <EOL> if ( s . get ( "<STR_LIT>" ) == True and jsf_activation . is_js_buffer ( view ) ) : <EOL> view . run_command ( "<STR_LIT>" ) <EOL> class JsFormatCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> settings = self . view . settings ( ) <EOL> opts = jsbeautifier . default_options ( ) <EOL> opts . indent_char = "<STR_LIT:U+0020>" if settings . get ( "<STR_LIT>" ) else "<STR_LIT:\t>" <EOL> opts . indent_size = int ( settings . get ( "<STR_LIT>" ) ) if opts . indent_char == "<STR_LIT:U+0020>" else <NUM_LIT:1> <EOL> opts = jsf_rc . augment_options ( opts , s ) <EOL> if ( s . get ( "<STR_LIT>" ) == True ) : <EOL> opts = jsf_rc . augment_options_by_rc_files ( opts , self . view ) <EOL> selection = self . view . sel ( ) [ <NUM_LIT:0> ] <EOL> if ( len ( selection ) > <NUM_LIT:0> ) : <EOL> jsf . format_selection ( self . view , edit , opts ) <EOL> else : <EOL> jsf . format_whole_file ( self . view , edit , opts ) <EOL> def is_visible ( self ) : <EOL> return jsf_activation . is_js_buffer ( self . view ) </s>
