Created
March 6, 2017 05:55
-
-
Save justinfx/341cf167098254317a87de0fc00f45cb to your computer and use it in GitHub Desktop.
SublimeText 3 - anaconda_go plugin - Workaround for 'fmt on save' bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Workaround for https://github.com/DamnWidget/anaconda_go/issues/9 | |
""" | |
import re | |
import sublime, sublime_plugin | |
class GoImportsOnSave(sublime_plugin.EventListener): | |
""" | |
Run goimports against Go language syntax documents, on save. | |
For use in combination with the GoImports SublimeText plugin package. | |
""" | |
# Supported syntax | |
_SYNTAX = frozenset(["go"]) | |
_RX_SOURCE = re.compile(r'source\.(\S+)') | |
def on_pre_save(self, view): | |
enabled = view.settings().get("goimports_on_save", False) | |
if not enabled: | |
return | |
scope = view.scope_name(0) | |
match = self._RX_SOURCE.match(scope) | |
if not match: | |
return | |
syntax = match.group(1) | |
if syntax.lower() not in self._SYNTAX: | |
return | |
try: | |
view.run_command("go_imports") | |
except Exception as e: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment