Commit 23aa93a395409e852e03554b54ef65851668d252
- Date: Thu Apr 17 08:55:31 +0000 2008
- Committer: Dr Nic Williams (drnicwilliams@gmail.com)
- Author: Dr Nic Williams (drnicwilliams@gmail.com)
- Commit SHA1: 23aa93a395409e852e03554b54ef65851668d252
- Tree SHA1: 3f64df541b669bb7013de84c743f5dac921b0070
go_to_external: works for 'ruby-debug' now
Commit diff
| |   |
| 1 | 1 | require 'rubygems' |
| 2 | 2 | $:.unshift "#{ENV['TM_BUNDLE_SUPPORT']}/lib" |
| 3 | require "ruby_tm_helpers" |
| 3 | 4 | require "grep_helpers" |
| 4 | 5 | # DEMO TARGET: require 'hpricot' |
| 6 | # DEMO TARGET: require 'ruby-debug' |
| 7 | # DEMO TARGET: require 'map_by_method' |
| 5 | 8 | |
| 6 | | class GoToExternal |
| 9 | module GoToExternal |
| 10 | extend self |
| 7 | 11 | # Returns the path of the project or file that best |
| 8 | 12 | # matches the context of where the cursor/caret is currently |
| 9 | | def self.run |
| 10 | | target_gem = ENV['TM_CURRENT_WORD'] |
| 13 | def run |
| 14 | target_gem = target_term #ENV['TM_CURRENT_WORD'] |
| 11 | 15 | if gem_spec = Gem.source_index.find_name(target_gem).last |
| 12 | | gem_path = gem_spec.full_gem_path |
| 13 | | %x{open -a TextMate #{gem_path}} |
| 16 | gem_path = gem_spec.full_gem_path |
| 17 | tm_open gem_path |
| 14 | 18 | else |
| 15 | 19 | puts "No RubyGem with name '#{target_gem}'" |
| 16 | 20 | end |
| 17 | 21 | end |
| 22 | |
| 23 | def target_term |
| 24 | filepath = tm_expanded_selection( |
| 25 | :backward => /[\w\/.-]+/, |
| 26 | :forward => /[\w\/.-]+/ |
| 27 | ).strip |
| 28 | end |
| 18 | 29 | end |
| toggle raw diff |
--- a/Support/lib/go_to_external.rb
+++ b/Support/lib/go_to_external.rb
@@ -1,18 +1,29 @@
require 'rubygems'
$:.unshift "#{ENV['TM_BUNDLE_SUPPORT']}/lib"
+require "ruby_tm_helpers"
require "grep_helpers"
# DEMO TARGET: require 'hpricot'
+# DEMO TARGET: require 'ruby-debug'
+# DEMO TARGET: require 'map_by_method'
-class GoToExternal
+module GoToExternal
+ extend self
# Returns the path of the project or file that best
# matches the context of where the cursor/caret is currently
- def self.run
- target_gem = ENV['TM_CURRENT_WORD']
+ def run
+ target_gem = target_term #ENV['TM_CURRENT_WORD']
if gem_spec = Gem.source_index.find_name(target_gem).last
- gem_path = gem_spec.full_gem_path
- %x{open -a TextMate #{gem_path}}
+ gem_path = gem_spec.full_gem_path
+ tm_open gem_path
else
puts "No RubyGem with name '#{target_gem}'"
end
end
+
+ def target_term
+ filepath = tm_expanded_selection(
+ :backward => /[\w\/.-]+/,
+ :forward => /[\w\/.-]+/
+ ).strip
+ end
end
\ No newline at end of file |
| |   |
| 42 | 42 | file = $1 |
| 43 | 43 | line = $2 |
| 44 | 44 | end |
| 45 | | |
| 45 | |
| 46 | 46 | unless /^\//.match(file) |
| 47 | 47 | file = File.join((ENV['TM_PROJECT_DIRECTORY'] || Dir.pwd), file) |
| 48 | 48 | end |
| 49 | | |
| 49 | |
| 50 | 50 | args = [] |
| 51 | 51 | args << "-w" if wait |
| 52 | 52 | args << e_sh(file) |
| … | … | |
| 58 | 58 | def tm_expanded_selection(options = {}) |
| 59 | 59 | text=ENV['TM_SELECTED_TEXT'].to_s |
| 60 | 60 | return text unless text.empty? |
| 61 | | |
| 61 | |
| 62 | 62 | options = { |
| 63 | 63 | :input_type => :doc, |
| 64 | 64 | :input => nil, |
| … | … | |
| 67 | 67 | :line_number => ENV['TM_LINE_NUMBER'].to_i, |
| 68 | 68 | :col_number => ENV['TM_COLUMN_NUMBER'].to_i |
| 69 | 69 | }.merge(options) |
| 70 | | |
| 70 | |
| 71 | 71 | col_number, line_number = options[:col_number], options[:line_number] |
| 72 | | |
| 72 | |
| 73 | 73 | doc = options[:input] ||= $stdin.read |
| 74 | | |
| 75 | | line = |
| 74 | |
| 75 | line = |
| 76 | 76 | case options[:input_type] |
| 77 | 77 | when :doc then doc.split("\n")[line_number - 1] |
| 78 | 78 | when :line then doc |
| 79 | | else |
| 79 | else |
| 80 | 80 | raise "Can't handle input_type #{options[:input_type]} for tm_expanded_selection" |
| 81 | 81 | end |
| 82 | | |
| 82 | |
| 83 | 83 | last_part = line[ (col_number - 1)..-1] |
| 84 | 84 | first_part = line[ 0..col_number - 2] |
| 85 | 85 | |
| toggle raw diff |
--- a/Support/lib/ruby_tm_helpers.rb
+++ b/Support/lib/ruby_tm_helpers.rb
@@ -42,11 +42,11 @@ def tm_open(file, options = {})
file = $1
line = $2
end
-
+
unless /^\//.match(file)
file = File.join((ENV['TM_PROJECT_DIRECTORY'] || Dir.pwd), file)
end
-
+
args = []
args << "-w" if wait
args << e_sh(file)
@@ -58,7 +58,7 @@ end
def tm_expanded_selection(options = {})
text=ENV['TM_SELECTED_TEXT'].to_s
return text unless text.empty?
-
+
options = {
:input_type => :doc,
:input => nil,
@@ -67,19 +67,19 @@ def tm_expanded_selection(options = {})
:line_number => ENV['TM_LINE_NUMBER'].to_i,
:col_number => ENV['TM_COLUMN_NUMBER'].to_i
}.merge(options)
-
+
col_number, line_number = options[:col_number], options[:line_number]
-
+
doc = options[:input] ||= $stdin.read
-
- line =
+
+ line =
case options[:input_type]
when :doc then doc.split("\n")[line_number - 1]
when :line then doc
- else
+ else
raise "Can't handle input_type #{options[:input_type]} for tm_expanded_selection"
end
-
+
last_part = line[ (col_number - 1)..-1]
first_part = line[ 0..col_number - 2]
|