<s> import sublime <EOL> import sublime_plugin <EOL> import os <EOL> from threading import Thread <EOL> from . import sublimelint <EOL> from . lint import persist <EOL> from . lint . edit import Edit <EOL> def error_command ( f ) : <EOL> def run ( self , edit , ** kwargs ) : <EOL> vid = self . view . id ( ) <EOL> if vid in persist . errors and persist . errors [ vid ] : <EOL> f ( self , self . view , persist . errors [ vid ] , ** kwargs ) <EOL> return run <EOL> def select_line ( view , line ) : <EOL> sel = view . sel ( ) <EOL> point = view . text_point ( line , <NUM_LIT:0> ) <EOL> sel . clear ( ) <EOL> sel . add ( view . line ( point ) ) <EOL> class sublimelint_next_error ( sublime_plugin . TextCommand ) : <EOL> @ error_command <EOL> def run ( self , view , errors , direction = <NUM_LIT:1> ) : <EOL> self . view . run_command ( '<STR_LIT>' ) <EOL> sel = view . sel ( ) <EOL> if len ( sel ) == <NUM_LIT:0> : <EOL> sel . add ( ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> line = view . rowcol ( sel [ <NUM_LIT:0> ] . a ) [ <NUM_LIT:0> ] <EOL> errors = list ( errors ) <EOL> if line in errors : errors . remove ( line ) <EOL> errors = sorted ( errors + [ line ] ) <EOL> i = errors . index ( line ) + direction <EOL> if i >= len ( errors ) : <EOL> i -= len ( errors ) <EOL> select_line ( view , errors [ i ] ) <EOL> view . show_at_center ( sel [ <NUM_LIT:0> ] ) <EOL> class sublimelint_all_errors ( sublime_plugin . TextCommand ) : <EOL> @ error_command <EOL> def run ( self , view , errors ) : <EOL> options = [ ] <EOL> option_to_line = [ ] <EOL> for lineno , messages in sorted ( errors . items ( ) ) : <EOL> line = view . substr ( <EOL> view . full_line ( view . text_point ( lineno , <NUM_LIT:0> ) ) <EOL> ) <EOL> while messages : <EOL> option_to_line . append ( lineno ) <EOL> options . append ( <EOL> [ ( "<STR_LIT>" % ( lineno + <NUM_LIT:1> , line . strip ( ) ) ) ] + <EOL> [ m for m in messages [ : <NUM_LIT:2> ] ] <EOL> ) <EOL> messages = messages [ <NUM_LIT:2> : ] <EOL> def center_line ( i ) : <EOL> if i != - <NUM_LIT:1> : <EOL> select_line ( view , option_to_line [ i ] ) <EOL> view . show_at_center ( view . sel ( ) [ <NUM_LIT:0> ] ) <EOL> view . window ( ) . show_quick_panel ( options , center_line , sublime . MONOSPACE_FONT ) <EOL> class sublimelint_report ( sublime_plugin . WindowCommand ) : <EOL> def run ( self , on = '<STR_LIT>' ) : <EOL> output = self . window . new_file ( ) <EOL> output . set_name ( '<STR_LIT>' ) <EOL> output . set_scratch ( True ) <EOL> if on == '<STR_LIT>' or on == '<STR_LIT>' : <EOL> for view in self . window . views ( ) : <EOL> self . report ( output , view ) <EOL> if on == '<STR_LIT>' or on == '<STR_LIT>' : <EOL> for folder in self . window . folders ( ) : <EOL> self . folder ( output , folder ) <EOL> def folder ( self , output , folder ) : <EOL> for root , dirs , files in os . walk ( folder ) : <EOL> for name in files : <EOL> path = os . path . join ( root , name ) <EOL> if os . stat ( path ) . st_size < <NUM_LIT> * <NUM_LIT> : <EOL> pass <EOL> def report ( self , output , view ) : <EOL> def finish_lint ( view , linters ) : <EOL> if not linters : <EOL> return <EOL> with Edit ( output ) as edit : <EOL> if not any ( l . errors for l in linters ) : <EOL> return <EOL> filename = os . path . basename ( linters [ <NUM_LIT:0> ] . filename or '<STR_LIT>' ) <EOL> out = '<STR_LIT>' . format ( filename ) <EOL> for linter in linters : <EOL> if linter . errors : <EOL> for line , errors in sorted ( linter . errors . items ( ) ) : <EOL> for error in errors : <EOL> out += '<STR_LIT>' . format ( line , error ) <EOL> edit . insert ( output . size ( ) , out ) <EOL> args = ( view . id ( ) , finish_lint ) <EOL> Thread ( target = sublimelint . SublimeLint . lint , args = args ) . start ( ) </s>
