[TextMate] Feature Request

Allan Odgaard allan at macromates.com
Tue Oct 12 12:00:21 UTC 2004


On 12. Oct 2004, at 11:39, Timothy Martens wrote:

>> If you wan't, I can experiment a bit and send a step-by-step 
>> explanation on how to make such a macro.
> yes

Okay, select Command / Edit Menu… and press the + sign.

Enter a suiting name and a key equivalent and put this in the 
command(s): text box (leave the other things as their defaults):
----------8<----------
cd "$TM_DIRECTORY"
image=$TM_SELECTED_TEXT

# check if image exists on disk
[ -f $image ] || { echo $image; exit 1; }

# extract width, height and alt-text
w=`file "$image" | perl -pe 's/^.*,\s*(\d+)[ x]+(\d+)\s*(,.*|$)/$1/'`
h=`file "$image" | perl -pe 's/^.*,\s*(\d+)[ x]+(\d+)\s*(,.*|$)/$1/'`
alt=`echo $image | perl -pe 's/^(.*\/)?(.*?)(\..*)?$/$2/g'`

# write the img tag to stdout
echo "<img src=\"$image\" width=\"$w\" height=\"$h\" alt=\"$alt\" />"
---------->8----------

With this command I can write: "images/apache_pb.gif", select it, and 
execute the above command, and it turns into: "<img 
src="images/apache_pb.gif" width="259" height="259" alt="apache_pb" />"

Of course it'll be easier when we add the drag hooks, and it'll be 
better when 'insert as snippet' becomes an output option (since you can 
then have the alt-text selected, and another placeholder after the 
image or similar).

And as said, the 'file' command can only give image dimensions for PNG 
and GIF pictures.  It may be possible to query apple script actually, 
but startup time for AS is poor IMHO.

I'll figure out a solution when I do the drag hooks, so that we can 
ship with a default drag hook for images that just works... :)

>> I don't know if it's best to start with the filename or the img-tag  
>> (and then just insert the width/height)?!?
> not quite sure what you mean Allan

Well, either you could be interested in inserting width/height to an 
existing image tag, or you could want TM to create the img-tag from the 
file name.

I made the above command expect the latter.


Kind regards Allan




More information about the textmate mailing list