[TxMt] Linefeeds in commands & snippets

led lindsay at pobox.com
Fri May 12 08:12:01 UTC 2006


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 at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate
>
>




More information about the textmate mailing list