Eclipse auto-formatter, disable auto line-wrapping of comment lines - eclipse

I love eclipse auto formatting, but there's one feature that's driving me raging mad:
Since I use wrap-lines in my auto-formmatter, code like this:
private static Location _location = null; // this is a comment
turns into horrible, horrible code like this:
private static Location _location = null; // this
// is
// a
// comment
this is not only painful to watch, but not at all convenient to change back...
Is there any way to remove line-wrapping for comments, or at least fix so it doesn't look like an absolute mess?
Thanks

I think that the thing you are specifically asking about you can achieve by editing your formatter:
Window -> Preferences -> Java -> Code Style -> Formatter. There edit you click on Edit...
If you are using the default Eclipse formatter you will need to edit the profile name (you cna not edit built in profile).
Go to comments
Deselect line comment formatting.
That way no formatting of comments of the type // will be done.

This annoys me also. To fix the wrapped comments you can use the keyboard shortcut CTL+ALT+J to join the comments onto one line. The comment-indicator characters (// or *) will still be there but at least it will save you some steps. Then you can just run a find and replace for the comment-indicators.

Related

Get func placeholder values from a snippet to appear after hitting tab at top level code level

New to swift and xcode, version 11.3.1.
If I hit func<tab> in a class, the placeholder values pop in nicely and I can tab through them to complete them.
However, when I have a simple playground file open and hit func<tab> I don't see any placeholder values. Just the keyword func appears.
How do I turn on these placeholder values for top-level functions?
What you are talking about are "code snippets". You can insert them not only by typing the "magic word", but also by clicking on the plus sign on the top right, then choosing from the list:
If you search for "Function", you can find the one you're looking for.
But who wants to click a button when writing code, right? It seems like some of the snippets somehow can't be used in playgrounds, while others can. This seems like an Xcode bug. For me, things like var, varget, vargetset all worked.
As an workaround, you can create your own code snippet for a function. First, paste this code into Xcode:
func <#name#>(<#parameters#>) -> <#return type#> {
<#function body#>
}
Select all of it, then go to Editor -> Create Code Snippet. Give it a name, and most importantly, a "Completion".
Apparently, you can still put func as the "Completion" and it will work.
I'm not sure if there is a better answer but here is what worked to get the func snippet to show up while editing a "playground" file:
1) Edit snippets file with: sudo vim /Applications/Xcode.app/Contents/PlugIns/IDESourceEditor.framework/Versions/A/Resources/SystemCodeSnippets.codesnippets
2) Search for snippet and find the related scope key and modify the array of the scope key to <string>All</string>:
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>All</string>
</array>
Yes, I could create my own snippet which is the same as the built-in snippet but then I have two different snippets that do the same thing, which I found annoying.

Eclipse Neon 2.0 Append automatically comments

Smalle question.
Is there a way to append automatically generate comments/trigger notification/popup window at the end of new code.
Example:
int i = 0; //my comment
Whenever I start writing "int i = 0;", "//my comment" is appended automatically.
Or if u have any suggestion regarding something like this.
Kind regards,
Gregory
There are code templates
Goto Window -> Preferences -> Java -> Code Style -> Code Templates
Under Code there are different options, maybe yours is Method Body
Click on Edit, remove the comment and Save

Eclipse formatting cause CSS to stop working

I have following CSS in my style.css:
.btfl-alert-warning:not(.selectize-control):not(.selectize-dropdown-content):not(.selectize-dropdown)
{
//some properties
}
Now, when I use Eclipse formatting, eclipse make space between 'not' and parenthesis and I get something like this:
.btfl-alert-warning:not (.selectize-control ):not (.selectize-dropdown-content
):not (.selectize-dropdown ) {
}
After using formatter second time it looks much worse, but the point is after adding this 'space' this selector just stop work. I checked all CSS formatter options in Eclipse but nothing helped me.
Do you have any idea how to prevent ruining this CSS?
You could go to Preferences -> CSS -> Code Style:
Then modify it as you want it to show.
In the case you can't make it in the CSS(Code Style), you might don't apply the format in eclipse, it is fine to do all the work in Eclipse, once you finish when you have a production ready CSS/HTML/JS/.... you can use atom from GitHub to apply format to your CSS/HTML/JS/.... use the plugins from AtomLinter
I hope this helps you.
I ended up using additional css file called style_do_not_format.css which contains only that css and comment about not formatting this file because it cause css to stop work. In my style.css file i use
#IMPORT url("style_do_not_format.css");

Netbeans Code Templates Formatting syntax

I'd like to know what's the syntax or the language used to format the code templates in netbeans ide. I mean, in the default templates I can see things like;
while (${EXP default="exp"})
{
${selection line}${cursor}
}
And:
// <editor-fold defaultstate="collapsed" desc="${comment}">
${selection}${cursor}// </editor-fold>
And I experimented and did this:
int ${IDX newVarName default="loop"};
for (${IDX} = 0; ${IDX} < ${SIZE int default="size"}; ${IDX}++)
{
${cursor}
}
And it works but I don't really know where the "${IDX}" or the "${SIZE int default="size"}" or the "${selection}${cursor}" comes from and what other statements can I use to format my templates.
Is this some scripting or programming language?
Where can I find this information?
I think Netbeans uses the template engine Freemarker for this. So all variables (= ${...}) are filled in by Netbeans at the time you use the template.
Unfortunately I don't have a full list of all default variables / methods you can use, but here are two of them listed:
${cursor}:
defines a position where the caret will be located after the editing
of the code template values finishes.
${selection}:
defines a position for pasting the content of the editor selection.
This is used by so-called 'selection templates' that appear as hints
whenever the user selects some text in the editor.
See here: http://wiki.netbeans.org/Java_EditorUsersGuide#How_to_use_Code_Templates
${IDX} looks like a custom variable you use.
See also:
- Code Assistance in the NetBeans IDE Java Editor: A Reference Guide (Code Template)
- Code Templates in NetBeans IDE for PHP
How_to_use_Code_Templates pretty much covers everything there is.
Looking at CodeTemplateParameter.java shows there is another hint called "completionInvoke" which requests showing of the code completion popup for the currently focused text component, but that is all.

Does the Eclipse editor have an equivalent of Emacs's "align-regex"?

I've been using Eclipse pretty regularly for several years now, but I admit to not having explored all the esoterica it has to offer, particularly in the areas of what formatting features the editors offer.
The main thing I miss from (X)emacs is the "align-regex" command, which let me take several lines into a region and then format them so that some common pattern in all lines was aligned. The simplest example of this is a series of variable assignments:
var str = new String('aString');
var index = 0;
var longCamelCaseObjectName = new LongNameObject();
After doing align-regex on "=", that would become:
var str = new String('aString');
var index = 0;
var longCamelCaseObjectName = new LongNameObject();
Now, you may have your own thoughts on stylistic (ab)use of white space and alignment, etc., but that's just an example (I'm actually trying to align a different kind of mess entirely).
Can anyone tell me off-hand if there's an easy key-combo-shortcut for this in Eclipse? Or even a moderately-tricky one?
You can set the formatter to do this:
Preferences -> Java -> Code Style -> Formatter. Click 'Edit' on the profile (you may need to make a new one since you can't edit the default).
In the indentation section select 'Align fields with columns'.
Then, in your code CTRL+SHIFT+F will run that formatter.
That will of course run all the other rules, so you may want to peruse the various options here.
Version 2.8.7 of the Emacs+ plugin now supplies a fairly complete align-regexp implementation in Eclipse
If you wish to do something more complex than just aligning fields (or anything else the Eclipse code formatter offers you) you are pretty much left with having to write your own plugin.
columns4eclipse is a nice option. It is an Eclipse plugin that allow you to do the alignments you mention in your question. I use it with Eclipse 4.3 and 4.5, it works well. I had made a gif video showing its use but my answer got deleted by a mod, so I let you try and see by yourself.
This plug-in does exactly what you want: OCDFormat
It works in all text files, not only Java.