I am trying to modify my view lists command. It is based on the TODO bundle command, but I am trying to use string comparison instead of regexp to test lines. As far as I can tell, the sorting is going ok, but I'm having trouble with the output. It seems to show everything except for the task itself (the content). Here is the code, any idea what's going wrong? Thanks.
Mike
#!/usr/bin/env ruby
$myPath = ENV['TM_DIRECTORY'] $tags = [] #user defined contexts
def readContexts(a) # processes contexts.gtd into script context, tabCommand, tabString, regex, color = a.split(/|/) $tags.push({:label => context, :regexp => regex, :color => color, :matches => []}) end
require "#{ENV['TM_SUPPORT_PATH']}/lib/textmate" require "erb" include ERB::Util
def TextMate.file_link (file, line = 0) return "txmt://open/?url=file://" + file.gsub(/[^a-zA-Z0-9.-/]/) { |m| sprintf("%%%02X", m[0]) } + "&line=" + line.to_s end
# the contexts.gtd file is read, and converted into $contexts file = File.open($myPath+"/contexts.gtd", "r") file.each do |line| readContexts(line) end
# sorting happens $tags.each do |tag| context = tag[:label] myFiles = Dir.entries($myPath) myFiles.each do |fileName| if (fileName[-3,3] == "gtd") and (fileName != "contexts.gtd") lineno = 0 mFile = File.open(fileName) mFile.each do |line| lineno = lineno + 1 re = /\s/ ctask = re.match(line) if ctask.pre_match == context results = { :file => fileName[0..-5], :line => lineno, :content => ctask.post_match } results[:match] = html_escape($1) tag[:matches] << results end end end end end
tmpl_file = "#{ENV['TM_BUNDLE_SUPPORT']}/template.rhtml" puts ERB.new(File.open(tmpl_file), 0, '<>').result
I was probably a little too brief on the description of my problem... I am trying to modify a command in the GTD bundle that is based on a command in the TODO bundle. The command goes through all of the files in a given directory, and creates a list grouped by the context of each line in the files that is displayed as an HTML document. The TODO version greps each line, which is problematic when I have similar contexts, such as TASK and WORK_TASK (also, having a context word in any other line will also generate a false true). I have modified the code to compare string values for the context and the first word in each line. I think that this comparison is working properly, but I am having trouble with the resulting list. It should show a context as a header, then the file name, line number, and content of each line for that context. It currently shows the filename and line number, but not the content.
With that additional information, can anyone see what's going wrong? Thanks.
Mike
On 7/10/06, Mike Mellor alaskamike@gmail.com wrote:
I am trying to modify my view lists command. It is based on the TODO bundle command, but I am trying to use string comparison instead of regexp to test lines. As far as I can tell, the sorting is going ok, but I'm having trouble with the output. It seems to show everything except for the task itself (the content). Here is the code, any idea what's going wrong? Thanks.
Mike
#!/usr/bin/env ruby
$myPath = ENV['TM_DIRECTORY']
$tags = [] #user defined contexts
def readContexts(a) # processes contexts.gtd into script context, tabCommand, tabString, regex, color = a.split(/|/) $tags.push({:label => context, :regexp => regex, :color => color, :matches => []}) end
require "#{ENV['TM_SUPPORT_PATH']}/lib/textmate" require "erb" include ERB::Util
def TextMate.file_link (file, line = 0) return "txmt://open/?url=file://" + file.gsub(/[^a-zA-Z0-9.-/]/) { |m| sprintf("%%%02X", m[0]) } + "&line=" + line.to_s end
# the contexts.gtd file is read, and converted into $contexts file = File.open($myPath+"/contexts.gtd", "r") file.each do |line| readContexts(line) end
# sorting happens $tags.each do |tag| context = tag[:label] myFiles = Dir.entries($myPath) myFiles.each do |fileName| if (fileName[-3,3] == "gtd") and (fileName != "contexts.gtd") lineno = 0 mFile = File.open(fileName) mFile.each do |line| lineno = lineno + 1 re = /\s/ ctask = re.match(line) if ctask.pre_match == context results = { :file => fileName[0..-5], :line => lineno, :content => ctask.post_match } results[:match] = html_escape($1) tag[:matches] << results end end end end end
tmpl_file = "#{ENV['TM_BUNDLE_SUPPORT']}/template.rhtml" puts ERB.new(File.open(tmpl_file), 0, '<>').result
What I would suggest is that you pretty-print the hash results right after you populate it, so that you know which key is problematic. I would guess though that your problem might be this line: results[:match] = html_escape($1)
It will not match anything, since there is no group in the regexp. I don't know what you use that for, but you might want to change it a bit. On Jul 11, 2006, at 12:21 PM, Mike Mellor wrote:
I was probably a little too brief on the description of my problem... I am trying to modify a command in the GTD bundle that is based on a command in the TODO bundle. The command goes through all of the files in a given directory, and creates a list grouped by the context of each line in the files that is displayed as an HTML document. The TODO version greps each line, which is problematic when I have similar contexts, such as TASK and WORK_TASK (also, having a context word in any other line will also generate a false true). I have modified the code to compare string values for the context and the first word in each line. I think that this comparison is working properly, but I am having trouble with the resulting list. It should show a context as a header, then the file name, line number, and content of each line for that context. It currently shows the filename and line number, but not the content.
With that additional information, can anyone see what's going wrong? Thanks.
Mike
On 7/10/06, Mike Mellor < alaskamike@gmail.com> wrote:I am trying to modify my view lists command. It is based on the TODO bundle command, but I am trying to use string comparison instead of regexp to test lines. As far as I can tell, the sorting is going ok, but I'm having trouble with the output. It seems to show everything except for the task itself (the content). Here is the code, any idea what's going wrong? Thanks.
Mike
#!/usr/bin/env ruby
$myPath = ENV['TM_DIRECTORY']
$tags = [] #user defined contexts
def readContexts(a) # processes contexts.gtd into script context, tabCommand, tabString, regex, color = a.split(/|/) $tags.push({:label => context, :regexp => regex, :color => color, :matches => []}) end
require "#{ENV['TM_SUPPORT_PATH']}/lib/textmate" require "erb" include ERB::Util
def TextMate.file_link (file, line = 0) return "txmt://open/?url=file://" + file.gsub(/[^a-zA-Z0-9.-/]/) { |m| sprintf("%%%02X", m[0]) } + "&line=" + line.to_s end
# the contexts.gtd file is read, and converted into $contexts file = File.open($myPath+"/contexts.gtd", "r") file.each do |line| readContexts(line) end
# sorting happens $tags.each do |tag| context = tag[:label] myFiles = Dir.entries($myPath) myFiles.each do |fileName| if (fileName[-3,3] == "gtd") and (fileName != " contexts.gtd") lineno = 0 mFile = File.open(fileName) mFile.each do |line| lineno = lineno + 1 re = /\s/ ctask = re.match(line) if ctask.pre_match == context results = { :file => fileName[0..-5], :line => lineno, :content => ctask.post_match } results[:match] = html_escape($1) tag[:matches] << results end end end end end
tmpl_file = "#{ENV['TM_BUNDLE_SUPPORT']}/template.rhtml" puts ERB.new(File.open(tmpl_file), 0, '<>').result
Haris
On 7/11/06, Charilaos Skiadas cskiadas@uchicago.edu wrote:
What I would suggest is that you pretty-print the hash results right after you populate it, so that you know which key is problematic. I would guess though that your problem might be this line: results[:match] = html_escape($1)
I have done some "puts'ing" to confirm that the data is there. How do I pretty-print? That may be the best solution to this.
As far as the problem line, I don't know what it does either. Maybe I'll jus tdelete and see what happens.
Thanks,
Mike
On Jul 11, 2006, at 2:03 PM, Mike Mellor wrote:
I have done some "puts'ing" to confirm that the data is there. How do I pretty-print? That may be the best solution to this.
you need to do: require 'pp' at some point, and then use: pp obj instead of puts obj
As far as the problem line, I don't know what it does either. Maybe I'll jus tdelete and see what happens.
You'll have to look in the erb template to see what it does. It is used as the text to show up next to the link, so you might want something there. I'm guessing you might want the post-match, but then again I don't know much about your file format.
Thanks,
Mike
Haris
On Jul 11, 2006, at 11:21 AM, Charilaos Skiadas wrote:
As far as the problem line, I don't know what it does either. Maybe I'll jus tdelete and see what happens.
You'll have to look in the erb template to see what it does. It is used as the text to show up next to the link, so you might want something there. I'm guessing you might want the post-match, but then again I don't know much about your file format.
The erb template was the issue. I must have changed something on the command side as I was reworking it. I changed a :match to a :content and now it seems to work perfectly! Thanks.
Mike