[TxMt] no-frills ctags
Chris Thomas
chris at m-audio.com
Thu Jan 27 04:49:53 UTC 2005
I got curious. Here's no-frills (and no-warranty) ctags lookup suitable
for use with the TM command editor. Select the identifier you're
looking for and run this command to find it. Tested with the output
from the ancient ctags command installed with Mac OS X. It doesn't
support any 'ex' commands except pattern matching. It probably does not
work with the extended ctags format, but it would be trivial to make
the necessary modifications.
There is one problem, however: either my URI syntax is wrong or
TextMate's 'txmt://' handler doesn't seem to be handling the 'line'
parameter.
It would be nice to be able to access this command from the contextual
menu.
ruby <<END
search_string = ENV['TM_SELECTED_TEXT']
exit if search_string == ""
# find the tags file in the folder containing the active file
tagfile_path = File.dirname(ENV['TM_FILEPATH']) + "/tags"
tags = File.open(tagfile_path, "r").read
tagarray = tags.scan(
/(#{search_string})\t(.*?)\t\\/\\^(.*)\\\$\\/\n/ )
linearray = tagarray.collect do |t|
puts t.join("\t")
identifier = t[2]
path = t[1]
sourcefile = File.open(path, "r")
while( sourcefile.gets )
break if \$_ =~ Regexp.new(Regexp.escape(identifier))
end
sourcefile.lineno
end
tagarray.each_with_index do |t, index|
puts "#{t[1]}:#{linearray[index]} #{\$_}"
command = %Q{open
txmt://open?url=file://#{File.expand_path(t[1])}&line=#{linearray
[index]}}
puts command
system(command)
end
END
More information about the textmate
mailing list