How do I extend the margin of the Eclipse source formatter? - java

Whenever I use Source > Format in Eclipse, it wraps the line starting at row 80. But my program has a lot of long lines and I'd like to extend its tolerance to 120. I've tried searching for a setting where I can change this but can't find one. Can this be done?

You can find it under Preferences->Java->Code Style->Formatter.
Click on the Edit button next to the currently active profile, go to the Line Wrapping tab and change the Maximum line width setting.

Go to Window/Prefences and open Java/Code Style Formatter. Then edit the profile. You can change the margin on the "Line Wrapping" tab ("Maximum line width").

Related

Hitting the tab key in the middle of the line inserts a tab instead of indenting

In Eclipse for Java, when I hit the tab key in the middle or at the end of a line, it inserts a tab instead of indenting. I can't find the setting to fix this, and an hour of googling has gotten me infinite pages about tabs vs. spaces and no answers. Please, help!
There is a setting I found under Java -> Editor -> Typing called "Tab key adjusts the indentation of the current line." It is definitely checked, but the indentation is only adjusted if the cursor is at the beginning of the line.
Several things you can do:
To indent several lines at once, you can select a portion of the text and press tab. This of course works for a single line too.
Press command-I to auto-indent, pretty handy trick.
Neither of these options do exactly what you asked for (quickly indent this line one tab to the right), but that's all I can think of in Eclipse.

code,string and comments split across multiple lines

While editing java code in eclipse, may be I pressed some key combo, or something else, but strings, code and comments in my entire file is now split into multiple lines. The newline is inserted at every object property/method.
Ex.:
object.prop1.method1()
has become:
object
.prop1
.method1()
What can I do to revert back???
Here is one small screenshot:
Thanx in advance...
You might have hit the auto formatter with Ctrl + Shift + F. Although the formatting seems strange and would definetly not be the default. Try hitting it again and see what happens.
You can configure the formatter in the preferences under Java=>Code Style=>Formatter
Ctrl+ Shfit + F - the short cut for format.
If have saved and ctrl + z do not work than only a new roll out from repository. If you do not have any then you can change change your format settings and perform operation one more time, but this time on your rules .
To set the format go to:
Options > Preferences > Java > Code Style > Formatter
If you press Ctrl+Shift+F your code gets formatted. (This must be what you pressed)
The formatter follows certain rules. You can find those rules if you go in Eclipse:
Window->Preferences->Java->Code Style->Formatter
There you must edit the current profile so that you can have more characters per line. This option is in tab
Line Wrapping -> Maximum line width
If you set this value large enough and press again Ctrl+Shift+F everything is going to be restored.
Thnx all for the suggestions....it worked by using code formatter and changing a few options
Thanx again...

Is it possible to modify Eclipse's comment behavior to add the slashes at the current level of indentation, rather than at the beginning of the row?

By default, pressing the Comment out shortcut keys Ctrl + /, has behavior like this:
Notice that the // get added at the left-most position of the row.
Is there a way to set it so that the // appear at the same level of indention as the code that is being commented out?
e.g.
Perhaps a Python habit, but I find it much easier to parse when everything is at the same indention level.
Is there a way to change where the slashes show up?
Yes, it's possible.
go to this link for detailed info
First go to Preferences, then
On the left side of the box, expand the Java option, then expand Code
Style and finally click Formatter
You'll land on the Java-Profile page:
The other, temporary way is via CTRL+SHIFT+F shortcut ( Eclipse: Change the block comment style of ctrl+shift+/ ) . So you'd highlight those comments, and press the combo.
I would then also use a shortcut for CTRL+SHIFT+F , like ALT+F5 (press CTRL+3 , 'keys' to get the preferences page.

text color coding in Netbeans

I have a pretty annoying issue with text highlighting on my EL statements.
I have scrolled through every field in the Options/Fonts&Colors/Syntax Control Panel three times, paying extra attention to the Expression Language options and I can not find the parameter that controls the white background of the whole ${initParam.productImagePath} expression statement.
Try looking under Fonts&Color -> Syntax. Then select the language and check all the color settings there.
UPDATE
I would add that sometimes the settings are inherited... it can be really hard to find which setting controls the color.
You can save the color settings exporting ("Export" button) then change every setting under "Expression Language" just to see if it changes.
Also, you can look through all colors in all languages and tabs until you find the color that matches the one you are seeing in the editor.
I'm guessing you may have done all this already, but I want to be sure I give the most complete answer I know of just in case.
Did you also check the entries in the Fonts&Colors Highlighting-Tab?
Your image shows that the white expression is not in the current selected line, so my guess is that you have enabled "highlight Search" (small Editor Toolbar). Another guess: if you are using the jVi Plugin, there's another highlight search parameter in jVi's settings dialog.

how to turn off break line in eclipse

Does anybody know how to turn line breaking in eclipse after you press CTRL + SHIFT + F (code format), ex :
System.err
.println("Incorrect file name, make sure you include .extension with your file name");
Go to Window->Preferences->Java->Code Style->Formatter. Create new formatter. Click on edit and then pick tab Line Wrapping and set Line Wrapping policy to Do not wrap.
The default line wrapping in Eclipse is really rather irritating and the main reason why is that the 'line width' is set as 80 characters, clearly a hangover from the nineteen eighties. This really should be updated now that everyone uses high resolution monitors instead of 80 char wide punch cards.
You probably don't want to turn it off entirely but instead you want to change the 'line width' to something more sensible (otherwise when you use the auto formatter you may get lines of code that go on forever).
I would suggest a value of 140, which seems to work nicely for most of us now using 1080p monitors.
In order to do this you need to...
With-in Preferences, navigate to...
> Java
> Code Style
> Formatter
You can't edit the default profiles so you have to hit New... and type a name like 'Eclipse 140 Line Width' for your profile and OK.
Then Edit the profile
Change to the Line Wrapping tab
Change the Maximum Line width from 80 to 140.
Then OK your way out.
If you then want to fix up your existing code, select your target code and use the Source > Format menu option.
In Helios, set 'Line Wrapping/Function Call/Indentation Policy' to 'Indent on Column' for all cases. This seems to stop the pathological case where it splits a line to try and fit within a fixed width but ends up with it further to the right than it would have been unsplit.
Or, as suggested above, disable line wrapping, or set a very wide line width. But I find it better to have it wrap and get it right than not to wrap at all.
There is an option "never join wrapped lines". This will help to keep our custom wrapping unchanged. Great Feature.

Categories

Resources