#NEWLINE# def run( self , edit , syntax = False , saving = False ) : #NEWLINE# #INDENT# if self . view . is_scratch ( ) : #NEWLINE# #INDENT# return show_error ( 'File is scratch' ) #NEWLINE# #UNINDENT# file_name = self . view . file_name ( ) #NEWLINE# formatter = Formatter ( self . view , file_name , syntax , file_text_utf ) #NEWLINE# if ( not formatter . exists ( ) ) : #NEWLINE# #INDENT# if saving : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# return show_error ( ( ( 'Formatter for this file type (' + formatter . syntax ) + ') not found.' ) ) #NEWLINE# #UNINDENT# if ( saving and ( not formatter . formatOnSaveEnabled ( ) ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# file_text = sublime . Region ( 0 , self . view . size ( ) ) #NEWLINE# file_text_utf = self . view . substr ( file_text ) . encode ( 'utf-8' ) #NEWLINE# if ( len ( file_text_utf ) == 0 ) : #NEWLINE# #INDENT# return show_error ( 'No code found.' ) #NEWLINE# #UNINDENT# ( stdout , stderr ) = formatter . format ( file_text_utf ) #NEWLINE# if ( ( len ( stderr ) == 0 ) and ( len ( stdout ) > 0 ) ) : #NEWLINE# #INDENT# self . view . replace ( edit , file_text , stdout ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# show_error ( ( 'Format error:\n' + stderr ) )