Sunday, August 31, 2008

Eclipse template variables ${selection} and ${clipboard}

I just filed two enhancement requests in bugzilla at Eclipse.org:

245788 Add a template variable ${selection} and allow Surround With action to deal consider it.
245790 Add a template variable ${clipboard}

The jist of the enhancement is that two new template variables should be added:

${selection} - this is replaced by what ever was the selection in the editor at the time of template insertion was invoked. Note that this requires a template invocation machanism that does not destroy the selection in text editor.
${clipboard} - this is replaced by the text content of the the clipboard.

Here is a use case:

template name: hyperlink
template pattern:

<a href="${clipboard}">${selection}</a>${cursor}

and with text http://www.google.com/ in the clipboard and the text

Google|

selected in the Eclipse editor.

Invoking the hyperlink template using the Surround with... action yields:

<a herf="http://www.google.com">Google</a>

Granted this would have been easy to type but imagine a complex URL copied into the clipboard from the browser address bar in place of "http://www.google.com/".

Please vote on the enhancement if you like this idea.

2 comments:

Tod said...

Well we now have ${word_selection} and ${line_selection} so they must listen to you. Still looking for that ${clipboard} variable.

Tod said...

Well at some point they listened to you and we have ${word_selection} and ${line_selection} I'm still looking for that ${clipboard} variable though.

(BTW - hate the fact that you have word verification turned on. If I don't get it right it wipes out my comment - isn't it enough to have folks log on?)