<s> """<STR_LIT>""" <EOL> import sublime <EOL> from diff_match_patch import diff_match_patch <EOL> class MergeException ( Exception ) : <EOL> pass <EOL> def _merge_code ( view , edit , code , formatted ) : <EOL> def ss ( start , end ) : <EOL> return view . substr ( sublime . Region ( start , end ) ) <EOL> dmp = diff_match_patch ( ) <EOL> diffs = dmp . diff_main ( code , formatted ) <EOL> dmp . diff_cleanupEfficiency ( diffs ) <EOL> i = <NUM_LIT:0> <EOL> dirty = False <EOL> for k , s in diffs : <EOL> l = len ( s ) <EOL> if k == <NUM_LIT:0> : <EOL> l = len ( s ) <EOL> if ss ( i , i + l ) != s : <EOL> raise MergeException ( '<STR_LIT>' , dirty ) <EOL> i += l <EOL> else : <EOL> dirty = True <EOL> if k > <NUM_LIT:0> : <EOL> view . insert ( edit , i , s ) <EOL> i += l <EOL> else : <EOL> if ss ( i , i + l ) != s : <EOL> raise MergeException ( '<STR_LIT>' , dirty ) <EOL> view . erase ( edit , sublime . Region ( i , i + l ) ) <EOL> return dirty <EOL> def merge_code ( view , edit , code , formatted_code ) : <EOL> vs = view . settings ( ) <EOL> ttts = vs . get ( "<STR_LIT>" ) <EOL> if not code . strip ( ) : <EOL> return ( False , '<STR_LIT>' ) <EOL> vs . set ( "<STR_LIT>" , False ) <EOL> dirty = False <EOL> err = '<STR_LIT>' <EOL> try : <EOL> dirty = _merge_code ( view , edit , code , formatted_code ) <EOL> except MergeException as exc : <EOL> dirty = True <EOL> err = "<STR_LIT>" % exc <EOL> view . replace ( edit , sublime . Region ( <NUM_LIT:0> , view . size ( ) ) , code ) <EOL> except Exception as ex : <EOL> err = "<STR_LIT>" % ex <EOL> finally : <EOL> vs . set ( "<STR_LIT>" , ttts ) <EOL> return ( dirty , err ) </s>
