[TxMt] Using non-saved file with TM command

Mike Mellor alaskamike at gmail.com
Sun Jun 18 03:15:30 UTC 2006


On Jun 17, 2006, at 5:14 PM, Charilaos Skiadas wrote:

> On Jun 17, 2006, at 7:58 PM, Mike Mellor wrote:
>>
>> Maybe I'm using the wrong variable - I'm trying to use  
>> 'TM_SELECTED_TEXT' but that doesn't seem to work.  I would prefer  
>> to work with the current version (buffer) than the saved file.   
>> Thanks.
>
> Maybe you could tell us what the text of your command is, what the  
> input and output settings are, and an example of the behavior you  
> want and what you see? I'm afraid  "doesn't seem to work"  does not  
> offer us any indication as to *why* it doesn't work.
>
> If you want to toy with the selected text though, my recommendation  
> would be to set your input as "selection", with whatever  
> appropriate fallback, and work with that.

Here is the code (well, the method in question).  It is a command in  
my bundle.  What I want is to sort the whole file using a specific  
sequence, I don't want to have to select the text.  The sorting works  
OK; I have a version that properly sorts the file.  The problem is  
that it only sorts the saved version of the file.  I would prefer to  
sort the existing version that is open in TextMate.  What I want tthe  
following code to do is take the file from TextMate and convert it to  
an array for sorting.   Thanks.

Mike

#!/usr/bin/ruby -w

# This is where the GTD files are kept
$myPath = ENV['TM_DIRECTORY']
$fileName = ENV['TM_SELECTED_TEXT']

def mySort fileName
   #opens lists and sends them to be sorted
   a = fileName.to_s + "\n"
   re = /\n/
   list = []
   while a.length > 0
     if a =~ re
       task = "#{$`}"
       list.push task
       a = "#{$'}"
     end
   end
   list.each do |line|
     puts line #this will actually call a sorting method
   end
end

mySort $fileName








More information about the textmate mailing list