diff --git a/Tidy.py b/Tidy.py index cf949ce..8631dfa 100644 --- a/Tidy.py +++ b/Tidy.py @@ -1,3 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + from sublime_plugin import TextCommand from sublime import Region from subprocess import call @@ -5,7 +8,6 @@ from StringIO import StringIO from sys import path - # load the git submodule extra = abspath('PythonTidy') if not exists(join(extra, '.git')): @@ -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))