Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Tidy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

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')):
Expand All @@ -32,7 +34,11 @@ def run(self, edit):
setup()
view = self.view
region = Region(0L, view.size())
source = StringIO(view.substr(region))
sourcestr = view.substr(region)
encoding = view.encoding()
if encoding == 'undefined':
encoding = 'utf-8'
source = StringIO(sourcestr.encode(encoding))
output = StringIO()
PythonTidy.tidy_up(source, output)
view.replace(edit, region, output.getvalue())
view.replace(edit, region, output.getvalue().decode(encoding))