From f8753cc08fa505afadfc4c1d94a5861bc53315ea Mon Sep 17 00:00:00 2001 From: Andreas Zeidler Date: Sun, 25 Sep 2011 16:23:14 +0200 Subject: [PATCH] Initial version integrating Chuck Rhode's PythonTidy (see http://pypi.python.org/pypi/PythonTidy/) --- Default (Linux).sublime-keymap | 3 +++ Default (OSX).sublime-keymap | 3 +++ Default (Windows).sublime-keymap | 3 +++ PythonTidy.py | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 Default (Linux).sublime-keymap create mode 100644 Default (OSX).sublime-keymap create mode 100644 Default (Windows).sublime-keymap create mode 100644 PythonTidy.py diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap new file mode 100644 index 0000000..45beeb4 --- /dev/null +++ b/Default (Linux).sublime-keymap @@ -0,0 +1,3 @@ +[ + { "keys": ["ctrl+shift+alt+t"], "command": "python_tidy" } +] \ No newline at end of file diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap new file mode 100644 index 0000000..9f80845 --- /dev/null +++ b/Default (OSX).sublime-keymap @@ -0,0 +1,3 @@ +[ + { "keys": ["super+ctrl+alt+t"], "command": "python_tidy" } +] \ No newline at end of file diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap new file mode 100644 index 0000000..45beeb4 --- /dev/null +++ b/Default (Windows).sublime-keymap @@ -0,0 +1,3 @@ +[ + { "keys": ["ctrl+shift+alt+t"], "command": "python_tidy" } +] \ No newline at end of file diff --git a/PythonTidy.py b/PythonTidy.py new file mode 100644 index 0000000..43d918c --- /dev/null +++ b/PythonTidy.py @@ -0,0 +1,19 @@ +from sublime_plugin import TextCommand +from sublime import Region +from subprocess import Popen, PIPE +from os.path import expanduser, exists + + +cmd = ['pythontidy'] +config = expanduser('~/.pythontidy.xml') +if exists(config): + cmd.extend(['-c', config]) + + +class python_tidy(TextCommand): + def run(self, edit): + view = self.view + region = Region(0L, view.size()) + tidy = Popen(cmd, bufsize=-1, stdin=PIPE, stdout=PIPE, stderr=PIPE) + output, error = tidy.communicate(view.substr(region)) + view.replace(edit, region, output)