Sunday, August 31, 2008

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

I just filed two enhancement requests in bugzilla at

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 in the clipboard and the text


selected in the Eclipse editor.

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

<a herf="">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 "".

Please vote on the enhancement if you like this idea.


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?)