I am trying to create a command that will replace text on a line with new text (actually modified text from the current line). Here is the code that I am using:
#!/usr/bin/python import os
def texter(): oldtask = os.environ['TM_CURRENT_LINE'] # oldtask = "Alligator" newtask = "DONE " for i in range (len(oldtask)): if i > 4: newtask = newtask + oldtask[i] print newtask texter()
The problem that I have is that it inserts a line feed at the end of the new text. Is there a way to prevent that? Thanks.
Mike
This is a Python issue. Python writes a newline to the end of all print statements, which is where this is coming from. You could write:
print newtask,
which would not write a newline, but would add a space. In order to write -just- the text, this would work:
#!/usr/bin/python import os,sys
def texter(): oldtask = os.environ['TM_CURRENT_LINE'] # oldtask = "Alligator" newtask = "DONE " for i in range (len(oldtask)): if i > 4: newtask = newtask + oldtask[i] sys.stdout.write(newtask) texter()
Lindsay
On 12 May 2006, at 07:28, Mike Mellor wrote:
I am trying to create a command that will replace text on a line with new text (actually modified text from the current line). Here is the code that I am using:
#!/usr/bin/python import os
def texter(): oldtask = os.environ['TM_CURRENT_LINE'] # oldtask = "Alligator" newtask = "DONE " for i in range (len(oldtask)): if i > 4: newtask = newtask + oldtask[i] print newtask texter()
The problem that I have is that it inserts a line feed at the end of the new text. Is there a way to prevent that? Thanks.
Mike
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
I suggest the following:
#!/usr/bin/env python import sys, os
oldtask = os.environ['TM_CURRENT_LINE'] sys.stdout.write("DONE " + oldtask[4:])
-Jacob
led wrote:
This is a Python issue. Python writes a newline to the end of all print statements, which is where this is coming from. You could write:
print newtask,
which would not write a newline, but would add a space. In order to write -just- the text, this would work:
#!/usr/bin/python import os,sys
def texter(): oldtask = os.environ['TM_CURRENT_LINE'] # oldtask = "Alligator" newtask = "DONE " for i in range (len(oldtask)): if i > 4: newtask = newtask + oldtask[i] sys.stdout.write(newtask) texter()
Lindsay
On 12 May 2006, at 07:28, Mike Mellor wrote:
I am trying to create a command that will replace text on a line with new text (actually modified text from the current line). Here is the code that I am using:
#!/usr/bin/python import os
def texter(): oldtask = os.environ['TM_CURRENT_LINE'] # oldtask = "Alligator" newtask = "DONE " for i in range (len(oldtask)): if i > 4: newtask = newtask + oldtask[i] print newtask texter()
The problem that I have is that it inserts a line feed at the end of the new text. Is there a way to prevent that? Thanks.
Mike