[TxMt] external Editor

Hans-Joerg Bibiko bibiko at eva.mpg.de
Mon Apr 14 09:51:33 UTC 2008


> On the other hand it would also be possible to use CSSEdit as CSS  
> editor for CSS definitions specified inside an HTML file. You select  
> the CSS stuff, the selection will be saved as /tmp/tm.css, this file  
> will be opened in CSSEdit, and if you save that file and close  
> CSSEdit the content of /tmp/tm.css will be inserted in TM.

If someone is interested here's the code:
[I do not have CSSEdit but it should work and, of course, the code can  
be optimized ;)]

tmcommand:
Input: selection or nothing
Output: replace selected text
Save: nothing
Command:

# get indention
HEAD=$(echo -en "$TM_SELECTED_TEXT" | head -n 1 | perl -ne 'm/ 
^([\t ]*)/;print $1')

# write selection to file
echo -en "$TM_SELECTED_TEXT" | perl -pe "s/^$HEAD//g;" > /tmp/tm.css

# open CSSEdit
open -a CSSEdit /tmp/tm.css

# wait for CSSEdit (it must be quitted!)
while [ `ps -ax | grep 'CSSEdit\.app' | wc -l` == "1" ]
do
	sleep 0.5
done

# write file back to TM
if [ -f /tmp/tm.css ]; then
	cat /tmp/tm.css | sed "s/^/$HEAD/"
	rm /tmp/tm.css
else
	beep
	exit_discard
fi

Scope Selector: source.css


To kill this command simply press APPLE+.

--Hans

-------------- next part --------------
A non-text attachment was scrubbed...
Name: CSSEdit.tmCommand
Type: application/octet-stream
Size: 1214 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20080414/7da674a2/attachment.tmCommand>
-------------- next part --------------



More information about the textmate mailing list