-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
19 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
# Sublime3 Plugin that runs goimports on the current file | ||
# Sublime Text 3 Plugin that integrates goimports with your favorite editor | ||
# | ||
# Author: Lukas Zilka ([email protected]) | ||
# | ||
import sublime | ||
import sublime_plugin | ||
import subprocess | ||
import io | ||
import os | ||
|
||
MY_PATH = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
def install(): | ||
script = [ | ||
"GOPATH='%s' go get github.com/bradfitz/goimports" % MY_PATH | ||
] | ||
for ln in script: | ||
p = subprocess.Popen(ln, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
if p.wait(): | ||
print("Error when installing goimports:") | ||
print(p.stdout.read()) | ||
print(p.stderr.read()) | ||
|
||
if not os.path.exists(os.path.join(MY_PATH, "bin/goimports")): | ||
install() | ||
|
||
s = sublime.load_settings("GoImports.sublime-settings") | ||
|
||
|
@@ -18,7 +34,8 @@ def run(self, edit, saving=False): | |
content = self.view.substr(selection) | ||
|
||
# Shove that content down goimports process's throat. | ||
process = subprocess.Popen([s.get("go_imports_bin_path")], stdin=subprocess.PIPE, stdout=subprocess.PIPE) | ||
process = subprocess.Popen([os.path.join(MY_PATH, "bin/goimports")], | ||
stdin=subprocess.PIPE, stdout=subprocess.PIPE) | ||
process.stdin.write(bytes(content, 'utf8')) | ||
process.stdin.close() | ||
process.wait() | ||
|
This file was deleted.
Oops, something went wrong.