[TxMt] Clickable URLs in text files

Allan Odgaard allan at macromates.com
Mon May 23 19:28:29 UTC 2005


On May 23, 2005, at 14:51, Kai von Fintel wrote:

> So, how hard would it be for someone to write a command thingy to make
> such functionality available in TextMate?

Should be pretty easy.

You have TM_COLUMN_NUMBER as the caret position and TM_CURRENT_LINE  
as the contents of the current line.

Slapping together something quick in bash yeilds:

for (( i = $TM_COLUMN_NUMBER-1; i >= 0; i-- )); do
    res=$(perl -pe <<<${TM_CURRENT_LINE:$i} 's/^(((https?|ftp|mailto): 
\S+?)(?=[),.]*(\s|$)|$)|).*/$1/')
    if [[ -n $res ]]; then
       open "$res"
       break
    fi
done

This will find the first URL (using a rather primitive regex) to the  
left of the caret. It's rather slow though.

If you're using this in plain text you can put something like this in  
the Plain text.plist to get these highlighted:
    { name = "markup.underline.link";
      match = "(https?|ftp|mailto):\\S+?(?=[),.]*(\\s|$)|$)";
    },

If you're running recent betas then you can also put  
“markup.underline.link” in the scope of the command, so that the key  
equivalent will only fire when actually on an URL (which allows you  
to select a key that'd normally be used for something else).

> [...] I don't have the time to investigate this myself.

In that case you should put up a bounty for those whiling to spend  
their time solving your problems! ;)





More information about the textmate mailing list