[TxMt] saving without trailing spaces and tabs...

Allan Odgaard throw-away-1 at macromates.com
Tue Mar 21 22:06:21 UTC 2006


On 21/3/2006, at 17:48, Dan Ridley wrote:

> If you really want to get it into one command, you can use this:
>
> perl -pe 's/[\t ]+$//g' > "$TM_FILEPATH" && cat "$TM_FILEPATH"
>
>  (Input: Entire Document
>   Output: Replace Document)
>
> There are two problems with this, though:
>
>  * TextMate will not know that you've overwritten the file, so  
> while the file contents on disk will match the file contents in  
> TextMate, you'll still get the "unsaved" bullet on your tab, and  
> will be prompted to save on close.
>  * You'll be returned to the beginning of the current line when you  
> run it.

If you set the command to save before, it will think the file is up- 
to-date (even though the command makes a second save), and if you set  
the output to discard, you should get rid of the latter problem (then  
also remove the » && cat "$TM_FILEPATH"«).

It does however not handle the case where the file is untitled.






Just FYI (meant for the list) I am currently (amongst other) looking  
into extending commands to be used in various (callback) events, and  
directly on files (from the file browser). So long-term the way to  
strip trailing spaces (and similar) will be a method very similar to  
this (but with a slightly extended infrastructure to make it more  
graceful).




More information about the textmate mailing list