Expanding and creating code templates in Eclipse when using emacs keybindings - eclipse

How do I expand code templates in Eclipse when using the emacs keybindings?
Is there a hotkey for turning selected code into a template?

Apparently for C/C++ you have to enable templates in Window -> Preferences-> C/C++ -> Editor -> Content-assist -> Advanced.
Uncheck everything except templates and check templates in both the upper and lower boxes.
Then in the editor type a template name like:
for
and hit Alt + / to expand it into:
for (var = 0; var < max; ++var) {
}
Use Tab to fill in the blanks.
NOTE: eclipse 3.5

Related

Indentation in Eclipse

I am trying to indent my code in eclipse .
List<TestDB> list=session.createCriteria(TestDB.class).add(Restrictions.eq("testCase",testCase)).list();
I type my code as above and when I save my code the line is indented as follows :-
List<TestDB> list = session.createCriteria(TestDB.class)
.add(Restrictions.eq("testCase", testCase)).list();
I tried this from SO :-
How do I disable auto-indent in Eclipse Helios (Java)?
But it is did not help . Can anyone please help me with the indentation ?
Window -> Preferences -> Java -> Editor -> Save Actions -> Deactivate Perform the selected actions on save.
Also right click your project, select Properties and check the same setting here.

Eclipse editor show variable occurrence

In Eclipse Standard Installation the editor marks all occurrences of a variable if you click on it with a cursor.
e.g. Setting the cursor somewhere on the 'foo' Variables it highlights all other foo's too.
public void printString(String foo){
System.out.println(foo); }
Any ideas where to switch this behavior on again or why the feature doesn't work ?
I know the workaround is 'References->Workspace' but the auto highlighting is much more convenient.
You are asking about the "Toggle Mark Occurrences" the short cut for this is Alt + Shift + O
You can also enable it from
Window > Preferences > Java > Editor > Mark Occurrences

Eclipse does not format this if statement correctly

This should be easy to answer:
I have Eclipse set to wrap Java code over 80 chars to respect my margin.
This code never wraps:
if (expressionItem.type.isTypeCompatibleWith(containingNameLink.type) == false) {
reportParsingError("expression type incompatible with containing "
+ "context.");
}
Question: how do I set my code formatter preferences so that the margin is respected?
Did you press CTRL + SHIFT + F (or right click > source > format) ? Here it works fine. The code is not automatically formatted as you type, you need to tell eclipse to format it.
Click Windows > Preferences. Go to Java > Editor > Save Action Enable Perform the selected action on save then enable Formatt source code option.
Refer below pic:
Click on Formatter link to edit settings for Formatter.

How to Fix "Mark Occurrences" in Eclipse?

Eclipse is a great editor, and among it's many wonderful features one of my favorites is the Mark Occurrences feature. However, I recently installed the Aptana plug-in, and in trying to configure it I somehow managed to break Mark Occurrences in my Eclipse installation.
The feature still works somewhat, but instead of highlighting all occurrences of a given object, it now only highlights the occurrence where it is first created. In other words, in:
1. Dog dog = new Dog();
2. dog.bark();
3. dog.bark();
Only the "dog" in line 1 would be highlighted, not the "dog" in 2 or 3.
However, before I know I had things configured such that all three "dog" references would be highlighted by Eclipse. Does anyone know what configuration option I changed to "break" the marking of occurrences like this?
If the option mentioned by laurie is checked and you're wondering why it isn't working, you might have hit Alt-Shift-O sometime:
Cannot highlight all occurrences of a selected word in Eclipse
Note, that "Organize Imports" has Ctrl-Shift-O...
Check the following preference setting:
Preferences > General > Editors > Text Editors > Annotations
In here compare the settings for Occurrences and Write Occurrences.
You probably don't have the Text as higlighted option checked
There is another way to toggle the Mark Occurrences feature (apart from Preferences -> Java -> Editor -> Mark Occurrences)
Simply click the "Toggle Mark Occurrences" button from the toolbar. This can be seen in the image below. If you don't see the item in your bar you can turn on by selecting Window > Perspective > Customize Perspective... > Editor Presentation > Toggle Mark Occurrences
You can use a keyboard shortcut to toggle it, also:
On Windows: Alt + Shift + O
On OS X: Option + Command + O
Hope that helps
Preference > Java > Editor > Mark Ocurrences > check: Mark Ocurrences of the selected element in the current file.
and eclipse won't highlight occurences if your project contains errors
check the Problems view to be sure you project is clean
Go
Java> Editor > Mark Occurrences
Uncheck "Keep Marks when the section changes" then click Ok
Restart Eclipse.
This work for me.
Double click on the class or the package in it disappears. Have no fear.
( I also activated this feature by mistake while pressing selecting a word)

Change Eclipse variable autohighlight color

I have customized my own colors in eclipse but cannot find where to change the auto highlight color when you click on a variable and it highlights all other uses. Has anyone done this before?
Preferences -> General -> Editors -> Text Editors -> Annotations -> Occurrences
How to change your various variable background-highlighting "occurrences" settings
For anyone who'd like a screenshot and more details:
Tested in Eclipse 2022-12 (4.26.0) on Ubuntu 22.04.
You may have various "Occurrences" settings to change. Each one causes variables of the same name from various language file types to be highlighted in different kinds of files. I have 5 or so "occurrences" settings in Window → Preferences → General → Editors → Text Editors → Annotations → in the “Annotation types” window:
Bash occurrences
C/C++ Occurrences
C/C++ Write Occurrences
Occurrences
Occurrences (LiClipse)
I have changed all 5 to the same custom color: #414104, which is a nice-looking brown which looks great for dark themes.
Here's a screenshot prior to changing that setting for "Occurrences (LiClipse)":
And here's the new color I set all 5 to: #414104:
References:
The accepted answer
I first wrote about this in my Eclipse setup instructions on a new Linux (or other OS) computer document, where I have documented this and a lot more.