Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I modify the EL opening template in Eclipse?

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.

like image 225
Martin Avatar asked Jun 06 '15 16:06

Martin


People also ask

How to edit template Eclipse?

The Templates Preferences page is accessed from Window | Preferences | PHP | Templates . To remove a template from the list of available options, unmark its checkbox in the list. To edit an existing template, select it from the list and click Edit.

How to open template in Eclipse?

Click Ctrl+Space. The Content Assist box will appear, listing all available templates and completion options that begin with that combination of keys. Templates are marked in the content assist list with a blue square. Double-click the required template from the list.


1 Answers

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 <$.

like image 105
Trevor Young Avatar answered Oct 19 '22 20:10

Trevor Young