[TxMt] Re: Linefeeds in commands & snippets

Jacob Rus jrus at fas.harvard.edu
Fri May 12 10:17:28 UTC 2006


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




More information about the textmate mailing list