<s> import sublime <EOL> import sublime_plugin <EOL> import threading <EOL> import time <EOL> if int ( sublime . version ( ) ) < <NUM_LIT> : <EOL> from sublime_haskell_common import get_cabal_project_dir_and_name_of_view , get_setting , get_setting_async , is_haskell_source , LockedObject , log , log_trace <EOL> else : <EOL> from SublimeHaskell . sublime_haskell_common import get_cabal_project_dir_and_name_of_view , get_setting , get_setting_async , is_haskell_source , LockedObject , log , log_trace <EOL> class SublimeHaskellAutobuild ( sublime_plugin . EventListener ) : <EOL> def __init__ ( self ) : <EOL> super ( SublimeHaskellAutobuild , self ) . __init__ ( ) <EOL> self . fly_agent = FlyCheckLint ( ) <EOL> self . fly_agent . start ( ) <EOL> def on_post_save ( self , view ) : <EOL> auto_build_enabled = get_setting ( '<STR_LIT>' ) <EOL> auto_check_enabled = get_setting ( '<STR_LIT>' ) <EOL> auto_lint_enabled = get_setting ( '<STR_LIT>' ) <EOL> cabal_project_dir , cabal_project_name = get_cabal_project_dir_and_name_of_view ( view ) <EOL> self . fly_agent . nofly ( ) <EOL> if auto_build_enabled and cabal_project_dir is not None : <EOL> view . window ( ) . run_command ( '<STR_LIT>' ) <EOL> elif auto_check_enabled and auto_lint_enabled : <EOL> view . window ( ) . run_command ( '<STR_LIT>' ) <EOL> elif auto_check_enabled : <EOL> view . window ( ) . run_command ( '<STR_LIT>' ) <EOL> elif auto_lint_enabled : <EOL> view . window ( ) . run_command ( '<STR_LIT>' ) <EOL> def on_modified ( self , view ) : <EOL> lint_check_fly = get_setting ( '<STR_LIT>' ) <EOL> auto_check_enabled = get_setting ( '<STR_LIT>' ) <EOL> auto_lint_enabled = get_setting ( '<STR_LIT>' ) <EOL> if lint_check_fly and is_haskell_source ( view ) and view . file_name ( ) : <EOL> self . fly_agent . fly ( view ) <EOL> class FlyCheckLint ( threading . Thread ) : <EOL> def __init__ ( self ) : <EOL> super ( FlyCheckLint , self ) . __init__ ( ) <EOL> self . daemon = True <EOL> self . view = LockedObject ( [ ] ) <EOL> self . event = threading . Event ( ) <EOL> def fly ( self , view ) : <EOL> with self . view as v : <EOL> v [ : ] = [ view ] <EOL> self . event . set ( ) <EOL> def nofly ( self ) : <EOL> with self . view as v : <EOL> v [ : ] = [ ] <EOL> self . event . set ( ) <EOL> def run ( self ) : <EOL> while True : <EOL> self . event . wait ( ) <EOL> self . event . clear ( ) <EOL> time . sleep ( get_setting_async ( '<STR_LIT>' , <NUM_LIT:5> ) ) <EOL> view_ = None <EOL> with self . view as v : <EOL> if v : <EOL> view_ = v [ <NUM_LIT:0> ] <EOL> v [ : ] = [ ] <EOL> if view_ is None : <EOL> continue <EOL> auto_check_enabled = get_setting_async ( '<STR_LIT>' ) <EOL> auto_lint_enabled = get_setting_async ( '<STR_LIT>' ) <EOL> sublime . set_timeout ( lambda : view_ . window ( ) . run_command ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> if auto_check_enabled and auto_lint_enabled : <EOL> sublime . set_timeout ( lambda : view_ . window ( ) . run_command ( '<STR_LIT>' , { '<STR_LIT>' : True } ) , <NUM_LIT:0> ) <EOL> elif auto_check_enabled : <EOL> sublime . set_timeout ( lambda : view_ . window ( ) . run_command ( '<STR_LIT>' , { '<STR_LIT>' : True } ) , <NUM_LIT:0> ) <EOL> elif auto_lint_enabled : <EOL> sublime . set_timeout ( lambda : view_ . window ( ) . run_command ( '<STR_LIT>' , { '<STR_LIT>' : True } ) , <NUM_LIT:0> ) </s>
