Example #1
0
    def run(self, edit):
        selection = []
        nwsOffset = self.prev_non_whitespace()

        # do formatting and replacement
        replaceRegion = None
        formatSelection = False

        replaceRegion = sublime.Region(0, self.view.size())
        res = python_beautifier.beautify(self.view.substr(replaceRegion))
        self.view.replace(edit, replaceRegion, res)

        # re-place cursor
        offset = self.get_nws_offset(nwsOffset, self.view.substr(sublime.Region(0, self.view.size())))
        rc = self.view.rowcol(offset)
        pt = self.view.text_point(rc[0], rc[1])
        sel = self.view.sel()
        sel.clear()
        self.view.sel().add(sublime.Region(pt))

        self.view.show_at_center(pt)
Example #2
0
#use this script to run the formatter via terminal

import python_beautifier
from sys import argv

script, input_file_name, output_file_name = argv

output_file = open(output_file_name, 'w')

input_file = open(input_file_name)

result = python_beautifier.beautify(input_file.read())

output_file.write(result)

output_file.close()