diff --git a/Commands/Open Package.tmCommand b/Commands/Open Package.tmCommand new file mode 100644 index 0000000..fd92b93 --- /dev/null +++ b/Commands/Open Package.tmCommand @@ -0,0 +1,80 @@ + + + + + beforeRunningCommand + nop + command + #!/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 => "Open Package", :default => defaultText, :prompt => "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$/ && 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 + + input + selection + inputFormat + text + keyEquivalent + @D + name + Open Package + outputCaret + afterOutput + outputFormat + text + outputLocation + discard + scope + source.go + uuid + D3CD6B51-3A7E-4356-85F4-B76B8336BEF2 + version + 2 + + diff --git a/Preferences/Folding.tmPreferences b/Preferences/Folding.tmPreferences index bfca2c7..0eba128 100644 --- a/Preferences/Folding.tmPreferences +++ b/Preferences/Folding.tmPreferences @@ -8,6 +8,8 @@ source.go settings + foldingIndentedBlockStart + ^\s*(case|default)\b foldingStartMarker (?x) /\*\*(?!\*) # opening C-style comment with 2 asterisks but no third later on diff --git a/Preferences/Indentation Rules.tmPreferences b/Preferences/Indentation Rules.tmPreferences index acd806b..b82604b 100644 --- a/Preferences/Indentation Rules.tmPreferences +++ b/Preferences/Indentation Rules.tmPreferences @@ -9,13 +9,25 @@ settings decreaseIndentPattern - ^(.*\*/)?(\s*\}([^}{"']*\{)?[;\s]*?|\s*\)([^)("']*\()?[;\s]*?|(?:\s*(case|default).*:))(//.*|/\*.*\*/\s*)*? + (?x)^ + ( .* [*]/ )? + ( \s* \} .* + | \s* \) ( [^)("'\n]* \( )? [;,\s]* + | ( \s* (case|default)\b .* ) + ) + ( \s* ( //.* | /[*] .*? [*]/ ) )* + \s* $ increaseIndentPattern - ^(?:.*\*\/)?(?:(.*\{[^}"'\n]*)|(?:\s*(case|default).*:)|(.*\([^)"'\n]*))(\/\/.*|\/\*.*\*\/\s*)*?$ - indentNextLinePattern - ^(?!(.*[});:\w\d"'`])?\s*(\/\/|\/\*.*\*\/\s*$)).*[^\s;:{})"'`\w\d]\s*$ - unIndentedLinePattern - ^\s*((\/\*|\*\/|\/\/|import\b.*|package\b.*).*)?$ + (?x)^ + ( .* [*]/ )? + ( ( .* \{ [^}"'\n]* ) + | ( .* \( [^)"'\n]* ) + | ( \s* (case|default)\b .* ) + ) + ( \s* ( //.* | /[*] .*? [*]/ ) )* + \s* $ + zeroIndentPattern + ^(?!default:)\w+:.*$ uuid 160118A4-208D-4422-AFF0-0C21B5B78AAF diff --git a/Snippets/Package.tmSnippet b/Snippets/Package.tmSnippet index 7d85ce1..58cfcbd 100644 --- a/Snippets/Package.tmSnippet +++ b/Snippets/Package.tmSnippet @@ -3,9 +3,9 @@ content - ${1/^main$|(.+)/(?1:\/* + ${1/^main$|(.+)/(?1:/* The $1 package implements ... bananas? -*\/ +*/ )/}package ${1:main} name Package diff --git a/Snippets/Test.tmSnippet b/Snippets/Test.tmSnippet new file mode 100644 index 0000000..6d9bb65 --- /dev/null +++ b/Snippets/Test.tmSnippet @@ -0,0 +1,28 @@ + + + + + content + package ${1:`base="${TM_FILEPATH%_test.go}.go" +if [[ -f "$base" ]] && 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") +} + name + Test + scope + source.go + tabTrigger + test + uuid + C6F66AFB-B50B-45AF-B2B2-819CC3464E56 + + diff --git a/Support/goerrs.rb b/Support/goerrs.rb deleted file mode 100755 index 5fd0a7f..0000000 --- a/Support/goerrs.rb +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env ruby - -require "#{ENV['TM_SUPPORT_PATH']}/lib/escape" -require "pathname" - -module Go - def Go::normalize_file(file) - return nil if file == 'untitled' - return file if Pathname.new(file).absolute? - base = ENV['TM_PROJECT_DIRECTORY'] || ENV['TM_DIRECTORY'] || Dir.getwd - File.join(base, file) - end - - def Go::href(file, line) - file = normalize_file(file) - link = "txmt://open?line=#{line}" - link << "&url=file://#{e_url(file)}" if file - link - end - - def Go::link_errs(str, type) - if str.count(':') == 2 - str.gsub!(/^(.+):(\d+):\s+(.+)$/) do - file, line, msg = $1, $2, $3 - text = "" - text << "#{htmlize(File.basename(file))}:#{line}" - text << ": #{htmlize(msg)}
" - text - end - else - str.gsub!(/^(.+):(\d+):(\d+):\s+(.+)$/) do - file, line, col, msg = $1, $2, $3, $4 - text = "" - text << "#{htmlize(File.basename(file))}:#{line}" - text << ": #{htmlize(msg)}
" - text - end - end - end -end diff --git a/Support/gomate.rb b/Support/gomate.rb index 5e765e6..6c2b5a2 100755 --- a/Support/gomate.rb +++ b/Support/gomate.rb @@ -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'] : '') + @@ -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'] @@ -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 => '') - puts '
'
-      puts Go::link_errs(err, :err)
-      puts '
' - html_footer + args << {:use_hashbang => false, :version_args => ['version'], :version_regex => /\Ago version (.*)/} + TextMate::Executor.run(*args) TextMate.exit_show_html end end diff --git a/info.plist b/info.plist index eb920cb..8ea3728 100644 --- a/info.plist +++ b/info.plist @@ -20,7 +20,9 @@ 0F6A8710-54FC-48F5-9D02-D093DA001D17 73628139-0077-4F09-9B72-77546D7C2D2D ------------------------------------ + D3CD6B51-3A7E-4356-85F4-B76B8336BEF2 7BCFCFC8-9152-4638-8436-E17B0C754C8D + ------------------------------------ B0271A46-F6EF-4D2F-95A6-EC067E69155C ------------------------------------ C64599DA-E362-4411-9782-58A9C7F1B05A @@ -104,6 +106,7 @@ CFE21C25-71DE-48A9-8FE6-2A40D8DF16EF 2DFA9510-6F88-4BC6-A409-DA4075DEA8FF 5E6327B4-8BD5-4079-8B25-D8D3EF9E89FB + C6F66AFB-B50B-45AF-B2B2-819CC3464E56 name Organization