How do I modify the EL opening template in Eclipse?
Asked Answered
W

2

16

Whenever I am working in a JSP file and I type ${ to start an el (Expression Language) tag, Eclipse will automatically add } (with a space before the closing brace) after the cursor so that I get ${ } instead of ${}.

Is there a code template in Preferences that I can modify to change this behavior, or is it beyond user preference control?

I have checked in Preferences: Web: JSP Files: Editor: Templates, but none of those templates match. I've also looked in several other sections in Preferences but haven't found anything promising.

Whom answered 6/6, 2015 at 16:20 Comment(5)
There were no answers for Kepler. #20107319Amersfoort
@user880772 Thanks for the link, though; there was an answer suggesting turning off auto-close of EL tags, which is an improvement at least.Whom
eclipse.dzone.com/news/effective-eclipse-custom-templMonkhmer
@Monkhmer that would require me to type $ { ctrl-space. Turning off auto-close is a better solution requiring less mental effort. And neither solution fully hits the mark.Whom
Given there's no straightforward solution (just workarounds and hacks), I have logged a bug on Eclipse's bug tracker in the hopes that Eclipse Mars (the next version after Luna) fixes this.Whom
L
3

What @Mero provided (see comments on answer above) might not be an exact answer, but creating a JSP Template probably the closest thing that I've found.

A few notes for anyone that wants to go that route:

Create a new template through menu Window->Preferences, then in the drill down menu navigate to Web->JSP Files->Editor->Templates. Click New.

Name is a shortcut you can type (the same way typing sysout ctrl+space in Java is a shortcut for System.out.println()). I suggest something simple like el. This allows you to type e l ctrl-space instead of $ { ctrl-space to pull it up.

Context tells it when it should appear in intellisense. I suggest creating two of this template where one has a context of JSP Attribute value and the other has a context of All JSP.

Description is just informative. Put whatever you want. I put 'EL Script' myself.

Pattern is where you put what will be inserted. Put $${${cursor}} or $${${script}}, depending on preference. See below for explanation on the differences.

In Eclipse Templates ${} is how you put variables in the template, so to make it actually print ${} you have to escape the $ with a $$ leading to $${}.

The predefined variable ${cursor} defines where the cursor is after intellisense replaces the el, so to have the cursor appear in between the curly braces you want to do this: $${${cursor}}.

Using any variable that is not predefined (in this case, ${script}) will simply put in that variable with a box around it and allow you to type over it and press enter when you're done, allowing you to move to the end of the closing curly brace.

Note: I understand that this is not an actual answer, but rather is a workaround. I'm putting it here simply so that those who are fine with a workaround can know how to go about doing it.

Edit

For those that don't like having to type ctrl-space, a workaround could be to have the template name start with< since on JSP pages, the < opens the intellisense, so for instance, you could have the name be <el or <$.

Lentissimo answered 17/6, 2015 at 19:38 Comment(0)
W
0

A workaround but not an answer:

Disable auto-close of EL tags. You type ${expression} and get ${expression}|, rather than typing ${expression and getting ${expression| }. (| denotes the cursor location)

See this answer, from when this same question was asked of Eclipse Kepler: https://mcmap.net/q/821202/-get-rid-of-that-silly-space-eclipse-generates-when-you-open-an-el-expression

Whom answered 17/6, 2015 at 19:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.