Skip to content

Commit

Permalink
Merge pull request #41 from sorbits/master
Browse files Browse the repository at this point in the history
Improve indentation and folding rules, add test⇥ snippet and “open package” command
  • Loading branch information
AlanQuatermain committed Jul 17, 2013
2 parents 23ff67f + f3b6c46 commit 0bdec37
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 56 deletions.
80 changes: 80 additions & 0 deletions Commands/Open Package.tmCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
require "shellwords"
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/;
$2
else
defaultText = %x{ /usr/bin/pbpaste -pboard find }
require "#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb"
TextMate::UI.request_string :title =&gt; "Open Package", :default =&gt; defaultText, :prompt =&gt; "Which package do you wish to open?"
end
end
def go_path
env = %x{"${TM_GO:-go}" env}
if $? == 0
lcal, root = [], []
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" }
end
end
[ lcal, root ].flatten
else
ENV['GOPATH'].to_s.split(':').map { |dir| "#{dir}/src" }
end
end
def find_package_path(package)
go_path.each do |dir|
path = File.expand_path(package, dir)
if File.directory?(path)
files = Dir.entries(path).select { |file| file =~ /\.go$/ &amp;&amp; file !~ /_test\.go$/ }
return files.size == 1 ? File.join(path, files.first) : path
end
end
nil
end
if package = import_path()
if path = find_package_path(package)
%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}’."
end
end
</string>
<key>input</key>
<string>selection</string>
<key>inputFormat</key>
<string>text</string>
<key>keyEquivalent</key>
<string>@D</string>
<key>name</key>
<string>Open Package</string>
<key>outputCaret</key>
<string>afterOutput</string>
<key>outputFormat</key>
<string>text</string>
<key>outputLocation</key>
<string>discard</string>
<key>scope</key>
<string>source.go</string>
<key>uuid</key>
<string>D3CD6B51-3A7E-4356-85F4-B76B8336BEF2</string>
<key>version</key>
<integer>2</integer>
</dict>
</plist>
2 changes: 2 additions & 0 deletions Preferences/Folding.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<string>source.go</string>
<key>settings</key>
<dict>
<key>foldingIndentedBlockStart</key>
<string>^\s*(case|default)\b</string>
<key>foldingStartMarker</key>
<string>(?x)
/\*\*(?!\*) # opening C-style comment with 2 asterisks but no third later on
Expand Down
24 changes: 18 additions & 6 deletions Preferences/Indentation Rules.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@
<key>settings</key>
<dict>
<key>decreaseIndentPattern</key>
<string>^(.*\*/)?(\s*\}([^}{"']*\{)?[;\s]*?|\s*\)([^)("']*\()?[;\s]*?|(?:\s*(case|default).*:))(//.*|/\*.*\*/\s*)*?</string>
<string>(?x)^
( .* [*]/ )?
( \s* \} .*
| \s* \) ( [^)("'\n]* \( )? [;,\s]*
| ( \s* (case|default)\b .* )
)
( \s* ( //.* | /[*] .*? [*]/ ) )*
\s* $</string>
<key>increaseIndentPattern</key>
<string>^(?:.*\*\/)?(?:(.*\{[^}"'\n]*)|(?:\s*(case|default).*:)|(.*\([^)"'\n]*))(\/\/.*|\/\*.*\*\/\s*)*?$</string>
<key>indentNextLinePattern</key>
<string>^(?!(.*[});:\w\d"'`])?\s*(\/\/|\/\*.*\*\/\s*$)).*[^\s;:{})"'`\w\d]\s*$</string>
<key>unIndentedLinePattern</key>
<string>^\s*((\/\*|\*\/|\/\/|import\b.*|package\b.*).*)?$</string>
<string>(?x)^
( .* [*]/ )?
( ( .* \{ [^}"'\n]* )
| ( .* \( [^)"'\n]* )
| ( \s* (case|default)\b .* )
)
( \s* ( //.* | /[*] .*? [*]/ ) )*
\s* $</string>
<key>zeroIndentPattern</key>
<string>^(?!default:)\w+:.*$</string>
</dict>
<key>uuid</key>
<string>160118A4-208D-4422-AFF0-0C21B5B78AAF</string>
Expand Down
4 changes: 2 additions & 2 deletions Snippets/Package.tmSnippet
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>content</key>
<string>${1/^main$|(.+)/(?1:\/*
<string>${1/^main$|(.+)/(?1:/*
The $1 package implements ... bananas?
*\/
*/
)/}package ${1:main}</string>
<key>name</key>
<string>Package</string>
Expand Down
28 changes: 28 additions & 0 deletions Snippets/Test.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>content</key>
<string>package ${1:`base="${TM_FILEPATH%_test.go}.go"
if [[ -f "$base" ]] &amp;&amp; grep -q '^package ' "$base"
then grep -m1 '^package ' "$base"|cut -d' ' -f2
else echo 'main'
fi`}
import (
"testing"
)
func Test${2:${TM_DISPLAYNAME/^(.*?)(_test)?(\.go)?$/${1:/capitalize}/}}(t *testing.T) {
$0t.Fatal("no test body")
}</string>
<key>name</key>
<string>Test</string>
<key>scope</key>
<string>source.go</string>
<key>tabTrigger</key>
<string>test</string>
<key>uuid</key>
<string>C6F66AFB-B50B-45AF-B2B2-819CC3464E56</string>
</dict>
</plist>
40 changes: 0 additions & 40 deletions Support/goerrs.rb

This file was deleted.

11 changes: 3 additions & 8 deletions Support/gomate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
require "#{ENV['TM_SUPPORT_PATH']}/lib/web_preview"
require "#{ENV['TM_SUPPORT_PATH']}/lib/tm/executor"
require "#{ENV['TM_SUPPORT_PATH']}/lib/tm/save_current_document"
require "#{ENV['TM_BUNDLE_SUPPORT']}/goerrs"

# 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'] : '') +
Expand All @@ -25,6 +24,7 @@ def Go::go(command, options={})

if command == 'test' && ENV['TM_FILENAME'] =~ /(_test)?(\.go)$/
basename = $`
args.push("-v")
args.push("#{basename}.go")
args.push("#{basename}_test.go")
opts[:chdir] = ENV['TM_DIRECTORY']
Expand Down Expand Up @@ -90,13 +90,8 @@ def Go::gofmt
if err.nil? || err == ''
puts out
else
html_header("Formatting \"#{ENV['TM_FILENAME']}\"...", "go",
# html_head below is used to style the error lines like those displayed when a compiler error occurs
:html_head => '<style type="text/css">.err { color: red; } pre { font-style: normal; white-space: normal; }</style>')
puts '<pre>'
puts Go::link_errs(err, :err)
puts '</pre>'
html_footer
args << {:use_hashbang => false, :version_args => ['version'], :version_regex => /\Ago version (.*)/}
TextMate::Executor.run(*args)
TextMate.exit_show_html
end
end
Expand Down
3 changes: 3 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<string>0F6A8710-54FC-48F5-9D02-D093DA001D17</string>
<string>73628139-0077-4F09-9B72-77546D7C2D2D</string>
<string>------------------------------------</string>
<string>D3CD6B51-3A7E-4356-85F4-B76B8336BEF2</string>
<string>7BCFCFC8-9152-4638-8436-E17B0C754C8D</string>
<string>------------------------------------</string>
<string>B0271A46-F6EF-4D2F-95A6-EC067E69155C</string>
<string>------------------------------------</string>
<string>C64599DA-E362-4411-9782-58A9C7F1B05A</string>
Expand Down Expand Up @@ -104,6 +106,7 @@
<string>CFE21C25-71DE-48A9-8FE6-2A40D8DF16EF</string>
<string>2DFA9510-6F88-4BC6-A409-DA4075DEA8FF</string>
<string>5E6327B4-8BD5-4079-8B25-D8D3EF9E89FB</string>
<string>C6F66AFB-B50B-45AF-B2B2-819CC3464E56</string>
</array>
<key>name</key>
<string>Organization</string>
Expand Down

0 comments on commit 0bdec37

Please sign in to comment.