-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
I am working on a command to sort my GTD list by context. The problem I have is that if I have not saved the file, the command sorts the saved version of the file instead of what's currently in TextMate. How do I select the current file instead of the saved file? Thanks.
Mike
On Jun 17, 2006, at 6:33 PM, Mike Mellor wrote:
I am working on a command to sort my GTD list by context. The problem I have is that if I have not saved the file, the command sorts the saved version of the file instead of what's currently in TextMate. How do I select the current file instead of the saved file? Thanks.
You can either set the entire document as the input to the command, and then process that, or you can tell the command to save the file first.
Mike
Haris
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Jun 17, 2006, at 3:51 PM, Charilaos Skiadas wrote:
On Jun 17, 2006, at 6:33 PM, Mike Mellor wrote:
I am working on a command to sort my GTD list by context. The problem I have is that if I have not saved the file, the command sorts the saved version of the file instead of what's currently in TextMate. How do I select the current file instead of the saved file? Thanks.
You can either set the entire document as the input to the command, and then process that, or you can tell the command to save the file first.
Mike
Haris
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.
Mike
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.
Mike
Haris
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
On Jun 17, 2006, at 10:15 PM, Mike Mellor wrote:
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.
I don't even understand how it even sorts the whole file, it seems to me it would only work on the selected text, if any. But you haven't yet told us what the input and output for the command is. I would suggest: 1) Set the input of the command to be the entire document 2) Change $fileName = ENV['TM_SELECTED_TEXT'] to $fileName = STDIN.read
Do I understand correctly that up to the "puts line" part, your method just separates the string into an array of each of its lines? In that case, you could simply do:
def mySort(fileName) #opens lists and sends them to be sorted list = fileName.to_s.split("\n") list.each do |line| puts line #this will actually call a sorting method end end
Btw, any particular reason you create these global variables, $fileName etc? You could probably just work with local variables.
Thanks.
Mike
Haris
#!/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
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Jun 17, 2006, at 7:45 PM, Charilaos Skiadas wrote:
- Change $fileName = ENV['TM_SELECTED_TEXT'] to $fileName =
STDIN.read
That did it!
Do I understand correctly that up to the "puts line" part, your method just separates the string into an array of each of its lines? In that case, you could simply do:
I didn't want to load up the entire file into an E-mail. There are several other methods that I left out.
Btw, any particular reason you create these global variables, $fileName etc? You could probably just work with local variables.
It made sense when I started, not sure if I still need the globals, but it works now.
Thanks for all the help!
Mike