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]) } +
     "&amp;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