Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2a4eca1143
Fetching contributors…

Cannot retrieve contributors at this time

43 lines (33 sloc) 1.193 kb
from sublime_plugin import TextCommand
from sublime import Region
from subprocess import call
from os.path import abspath, expanduser, exists, join
from StringIO import StringIO
from sys import path
# load the git submodule
extra = abspath('PythonTidy')
if not exists(join(extra, '.git')):
call(['git', 'submodule', 'init'])
call(['git', 'submodule', 'update'])
# tweak path to allow importing PythonTidy from the git submodule
path.insert(0, extra)
import PythonTidy
import PythonTidyWrapper
path.remove(extra)
def setup():
xml = expanduser('~/.pythontidy.xml')
if exists(xml):
config = PythonTidyWrapper.Config(file=xml)
config.to_pythontidy_namespace()
class python_tidy(TextCommand):
def run(self, edit):
setup()
view = self.view
region = Region(0L, view.size())
encoding = view.encoding()
if not encoding or encoding == u'Undefined':
encoding = view.settings().get('default_encoding')
source = StringIO(view.substr(region).encode(encoding))
output = StringIO()
PythonTidy.tidy_up(source, output)
view.replace(edit, region, output.getvalue().decode(encoding))
Jump to Line
Something went wrong with that request. Please try again.