diff --git a/CHANGELOG.md b/CHANGELOG.md
index 71d3f1e..7a9841e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,16 @@ Planned:
- Rework some snippets, like a single import without an alias
- Add support for all go tools like fix, vet, lint, oracle
+###3.2.0 / 2015-09-18
+- [Support for dynamically determining gopath, package name, and package path @fmccann](https://github.com/syscrusher/golang.tmbundle/commit/49440460f058e80ccf0f2bd44891b48164091128)
+- [Support for golint and goimports @fmccann](https://github.com/syscrusher/golang.tmbundle/commit/49440460f058e80ccf0f2bd44891b48164091128)
+- [Display package name when running command against package name @fmccann](https://github.com/syscrusher/golang.tmbundle/commit/49440460f058e80ccf0f2bd44891b48164091128)
+- [Allow run and build on unsaved files @tg](https://github.com/syscrusher/golang.tmbundle/commit/4809d74ea36654bdd9a2475ded6f729eb3082b65)
+- [Fmt updates document without saving the current version @tg](https://github.com/syscrusher/golang.tmbundle/commit/998d17a9f8024b2c6571f242d2d93f44723c3e87)
+- [Automatically format documents on save @tg](https://github.com/syscrusher/golang.tmbundle/commit/8e6a71b1f8e986b7644c3286c1f4c538dc1345ec)
+- [Add fmt.Print snippet @jish](https://github.com/syscrusher/golang.tmbundle/commit/f73850c2774b1bbe6c7ecec40e4bbbb376fa1225)
+- [Add fmt.Fprintf snippet](https://github.com/syscrusher/golang.tmbundle/commit/ead451fa74a98628ddeb50ab6d901be18b60bba7)
+
###3.1.0 / 2015-02-04
- [Run all non-run commands against current directory @tg](https://github.com/syscrusher/golang.tmbundle/commit/d3f09ee3bbe5fba76964e1bdc23e7d7247b733ee)
- [Allow run and build on unsaved files @tg](https://github.com/syscrusher/golang.tmbundle/commit/4809d74ea36654bdd9a2475ded6f729eb3082b65)
@@ -106,6 +116,6 @@ Imported some community additions and bugfixes to bring compatibility with OS X
- Variable initialization is FINALLY matching correctly. Should work for every style & number of variables, even in-line in loop statements.
- Matches exported variable names correctly (i.e. those beginning with an uppercase letter).
- Dot-accessed variable match no longer consumes the preceding '.' character.
-
+
###0.1.0 / 2009-11-14
-- Initial Revision
\ No newline at end of file
+- Initial Revision
diff --git a/Commands/Fmt.tmCommand b/Commands/Fmt.tmCommand
index b764723..5c8a1d3 100644
--- a/Commands/Fmt.tmCommand
+++ b/Commands/Fmt.tmCommand
@@ -14,7 +14,7 @@
inputFormat
text
keyEquivalent
- ^H
+
name
Fmt
outputCaret
diff --git a/Commands/Imports.tmCommand b/Commands/Imports.tmCommand
new file mode 100644
index 0000000..dec115c
--- /dev/null
+++ b/Commands/Imports.tmCommand
@@ -0,0 +1,34 @@
+
+
+
+
+ beforeRunningCommand
+ saveModifiedFiles
+ command
+ #!/usr/bin/env ruby18
+
+require "#{ENV['TM_BUNDLE_SUPPORT']}/gomate"
+Go::goimports
+
+ input
+ document
+ inputFormat
+ text
+ keyEquivalent
+ ^H
+ name
+ Imports
+ outputCaret
+ interpolateByLine
+ outputFormat
+ text
+ outputLocation
+ replaceDocument
+ scope
+ source.go
+ uuid
+ 5509FB1E-C780-44ED-8BCF-4300ABC30C32
+ version
+ 2
+
+
diff --git a/Commands/Lint.tmCommand b/Commands/Lint.tmCommand
new file mode 100644
index 0000000..1e30700
--- /dev/null
+++ b/Commands/Lint.tmCommand
@@ -0,0 +1,34 @@
+
+
+
+
+ beforeRunningCommand
+ saveActiveFile
+ command
+ #!/usr/bin/env ruby18
+
+require "#{ENV['TM_BUNDLE_SUPPORT']}/gomate"
+Go::golint
+
+ input
+ none
+ inputFormat
+ text
+ keyEquivalent
+ ^L
+ name
+ Lint
+ outputCaret
+ interpolateByLine
+ outputFormat
+ html
+ outputLocation
+ newWindow
+ scope
+ source.go
+ uuid
+ 7E52594B-80CA-4EDD-B2B8-C54EB3844E95
+ version
+ 2
+
+
diff --git a/Commands/Open Package.tmCommand b/Commands/Open Package.tmCommand
index 97e6106..e54bcd6 100644
--- a/Commands/Open Package.tmCommand
+++ b/Commands/Open Package.tmCommand
@@ -6,37 +6,43 @@
nop
command
#!/usr/bin/env ruby18
-require "shellwords"
+require "shellwords"
+require "#{ENV['TM_BUNDLE_SUPPORT']}/gomate" # import to get dynamic gopath if set
def import_path
- if ENV.has_key? 'TM_SELECTED_TEXT'
- ENV['TM_SELECTED_TEXT']
- elsif ENV['TM_CURRENT_LINE'] =~ /^\s*(?:import\s+)?(?:\.|[[:alpha:]_][[:alnum:]_]*\s+)?(["`])(.*?)\1/;
+ if ENV.has_key? 'TM_SELECTED_TEXT'
+ ENV['TM_SELECTED_TEXT']
+ elsif ENV['TM_CURRENT_LINE'] =~ /^\s*(?:import\s+)?(?:\.|[[:alpha:]_][[:alnum:]_]*\s+)?(["`])(.*?)\1/;
$2
else
defaultText = %x{ /usr/bin/pbpaste -pboard find }
- require "#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb"
- TextMate::UI.request_string :title => "Open Package", :default => defaultText, :prompt => "Which package do you wish to open?"
+ require "#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb"
+ TextMate::UI.request_string :title => "Open Package", :default => defaultText, :prompt => "Which package do you wish to open?"
end
end
def go_path
- env = %x{"${TM_GO:-go}" env}
+ env = %x{"${TM_GO:-go}" env}
if $? == 0
lcal, root = [], []
- env.scan(/^GO(PATH|ROOT)="(.*)"/) do |key,value|
+ env.scan(/^GO(PATH|ROOT)="(.*)"/) do |key,value|
case key
- when 'PATH': lcal = value.split(':').map { |dir| "#{dir}/src" }
- when 'ROOT': root = value.split(':').map { |dir| "#{dir}/src/pkg" }
+ when 'PATH': lcal = value.split(':').map { |dir| "#{dir}/src" }
+ when 'ROOT': root = value.split(':').map { |dir| "#{dir}/src/pkg" }
end
end
[ lcal, root ].flatten
else
- ENV['GOPATH'].to_s.split(':').map { |dir| "#{dir}/src" }
+ ENV['GOPATH'].to_s.split(':').map { |dir| "#{dir}/src" }
end
end
def find_package_path(package)
+ if ENV.has_key?('TM_GO_DYNAMIC_PKG_PATH')
+ path = `#{ENV['TM_GO_DYNAMIC_PKG_PATH']} #{package}`.chomp
+ return path if path != nil && !path.empty?
+ end
+
go_path.each do |dir|
path = File.expand_path(package, dir)
if File.directory?(path)
@@ -49,10 +55,10 @@ end
if package = import_path()
if path = find_package_path(package)
- %x{"$TM_MATE" #{path.shellescape}}
+ %x{"$TM_MATE" #{path.shellescape}}
else
- require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb"
- TextMate.exit_show_tool_tip "Unable to locate package for import path ‘#{package}’."
+ require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb"
+ TextMate.exit_show_tool_tip "Unable to locate package for import path ‘#{package}’."
end
end
diff --git a/README.md b/README.md
index d14d55c..3848467 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,14 @@
-## golang.tmbundle v3.1.0
+## golang.tmbundle v3.2.0
(a TextMate 2 bundle for the go programming language)
### Installation
TextMate by default will detect .go files and load [Jim Dovey's bundle](https://github.com/AlanQuatermain/go-tmbundle). This is a fork with additional improvements merged from around the community.
Big changes from the default version:
-- all non-run go commands operate on the current directory instead of per file (thanks [tg](https://github.com/tg))
+- Support for goimports (thanks [fmccann](https://github.com/fmccann))
+- Support for golint (thanks [fmccann](https://github.com/fmccann))
+- Users can supply commands via ENV variables (TM\_GO\_DYNAMIC\_GOPATH, TM\_GO\_DYNAMIC\_PKG, TM\_GO\_DYNAMIC\_PKG\_PATH). The bundle will consult these commands if defined to dynamically change the gopath or package based on the current directory. (thanks [fmccann](https://github.com/fmccann))
+- all non-run go commands operate on the current directory instead of per file if the package is not defined dynamically. (thanks [tg](https://github.com/tg)).
- run and build work on unsaved files (thanks [tg](https://github.com/tg))
- added print, println, printf, and fprintf snippets (thanks [jish](https://github.com/jish))
- bugfixes
@@ -13,8 +16,8 @@ Big changes from the default version:
To install this bundle manually, open a Terminal window and do:
```Shell
-mkdir ~/Library/Application\ Support/Avian/Bundles
-cd ~/Library/Application\ Support/Avian/Bundles
+mkdir -p ~/Library/Application\ Support/Avian/Pristine\ Copy/Bundles
+cd ~/Library/Application\ Support/Avian/Pristine\ Copy/Bundles
git clone git://github.com/syscrusher/golang.tmbundle.git
```
@@ -26,8 +29,20 @@ go get -u github.com/nsf/gocode
go get -u code.google.com/p/go.tools/cmd/godoc
```
+This bundle uses goimports for cleaning up imports and reformatting code, which can be installed with:
+
+```Shell
+go get -u go get golang.org/x/tools/cmd/goimports
+```
+
+This bundle uses golint for linting code, which can be installed with:
+
+```Shell
+go get -u github.com/golang/lint/golint
+```
+
### Features
-The bundle implements language syntax, completion via gocode, some snippets, and some compile/format/documentation commands for the [Go language](http://golang.org/).
+The bundle implements language syntax, completion via gocode, some snippets, and some compile/format/documentation commands for the [Go language](http://golang.org/).
### Snippets
@@ -113,4 +128,4 @@ This is a fork from [Jim Dovey](https://github.com/AlanQuatermain) who has done
>Thanks be to lasersox and Infininight over at the [#textmate room on IRC](irc://irc.freenode.net/textmate) for all their help in cleaning up this here bundle, and for helping me to optimize my regex use in the language grammar.
Thanks to Martin Kühl for his extensive additions to this project's snippets and commands. Also Infininight's work on updating the bundle to use the TextMate's new Ruby interface and Jeremy & Sylvain's work on supporting Go 1.0 has been invaluable. Their assistance and stewardship while I've been deep in the world of Objective-C is very much appreciated.
-Happy coding :)
\ No newline at end of file
+Happy coding :)
diff --git a/Support/gomate.rb b/Support/gomate.rb
index a6c9d83..82b0149 100755
--- a/Support/gomate.rb
+++ b/Support/gomate.rb
@@ -9,11 +9,20 @@
# TextMate's special GOPATH used in .tm_properties files prepended to the environment's GOPATH
ENV['GOPATH'] = (ENV.has_key?('TM_GOPATH') ? ENV['TM_GOPATH'] : '') +
- (ENV.has_key?('GOPATH') ? ':' + ENV['GOPATH'] : '').sub(/^:+/,'')
+ (ENV.has_key?('GOPATH') ? ':' + ENV['GOPATH'] : '')
+
+# Call tool to determine gopath
+if ENV.has_key?('TM_GO_DYNAMIC_GOPATH')
+ Dir.chdir(ENV['TM_DIRECTORY']) do
+ ENV['GOPATH'] = `#{ENV['TM_GO_DYNAMIC_GOPATH']}`.chomp
+ end
+end
+
module Go
def Go::go(command, options={})
# TextMate's special TM_GO or expect 'go' on PATH
go_cmd = ENV['TM_GO'] || 'go'
+
TextMate.save_if_untitled('go')
TextMate::Executor.make_project_master_current_document
@@ -29,10 +38,21 @@ def Go::go(command, options={})
opts[:chdir] = directory
end
- if command == 'run' || !directory
+ # Call tool to determine package; default to directory name
+ pkg = directory
+ if ENV.has_key?('TM_GO_DYNAMIC_PKG')
+ Dir.chdir(ENV['TM_DIRECTORY']) do
+ pkg = `#{ENV['TM_GO_DYNAMIC_PKG']}`.chomp
+ pkg = nil if pkg == nil || pkg.empty?
+ end
+ end
+
+ if command == 'run' || !pkg
args.push(ENV['TM_FILEPATH'])
else
args.push("-v") # list packages being operated on
+ args.push(pkg)
+ opts[:noun] = pkg
end
args.push(opts)
@@ -70,4 +90,61 @@ def Go::godoc
TextMate.exit_show_tool_tip(err)
end
end
+
+ def Go::gofmt
+ # TextMate's special TM_GOFMT or expect 'gofmt' on PATH
+ gofmt_cmd = ENV['TM_GOFMT'] || 'gofmt'
+ TextMate.save_if_untitled('go')
+
+ args = []
+ args.push(gofmt_cmd)
+ args.push(ENV['TM_FILEPATH'])
+
+ out, err = TextMate::Process.run(*args)
+
+ if err.nil? || err == ''
+ puts out
+ else
+ args << {:use_hashbang => false, :version_args => ['version'], :version_regex => /\Ago version (.*)/}
+ TextMate::Executor.run(*args)
+ TextMate.exit_show_html
+ end
+ end
+
+ def Go::goimports
+ goimport_cmd = ENV['TM_GOIMPORTS'] || 'goimports'
+ TextMate.save_if_untitled('go')
+
+ args = []
+ args.push(goimport_cmd)
+ args.push(ENV['TM_FILEPATH'])
+
+ out, err = TextMate::Process.run(*args)
+
+ if err.nil? || err == ''
+ puts out
+ else
+ args << {:use_hashbang => false}
+ TextMate::Executor.run(*args)
+ TextMate.exit_show_html
+ end
+ end
+
+ def Go::golint
+ golint = ENV['TM_GOLINT'] || 'golint'
+ TextMate.save_if_untitled('go')
+ TextMate::Executor.make_project_master_current_document
+
+ args = Array.new
+ opts = {:use_hashbang => false, :verb => 'Linting', :version_replace => 'golint'}
+
+ file_length = ENV['TM_DIRECTORY'].length + 1
+ go_file = ENV['TM_FILEPATH'][file_length..-1]
+ opts[:chdir] = ENV['TM_DIRECTORY']
+
+ args.push(go_file)
+ args.push(opts)
+
+ TextMate::Executor.run(golint, *args)
+ end
end
diff --git a/info.plist b/info.plist
index c84bb84..5d76f8b 100644
--- a/info.plist
+++ b/info.plist
@@ -7,7 +7,7 @@
contactName
syscrusher
description
- Support for the <a href="http://golang.org">Go programming language</a>.
+ Support for the <a href="http://golang.org">Go programming language</a>.
mainMenu
excludedItems
@@ -25,6 +25,8 @@
7BCFCFC8-9152-4638-8436-E17B0C754C8D
------------------------------------
B0271A46-F6EF-4D2F-95A6-EC067E69155C
+ 5509FB1E-C780-44ED-8BCF-4300ABC30C32
+ 7E52594B-80CA-4EDD-B2B8-C54EB3844E95
------------------------------------
C64599DA-E362-4411-9782-58A9C7F1B05A
88695E43-E330-4A5A-9492-C604DBD10A27