Eclipse CDT Code Formatter - eclipse

Is there a way to force the Eclipse CDT Codestyle Formatter to ignore the blank lines?
As an example we would like to have 2 blank lines between functions in C like the pep8 for python uses
// 2 lines between function
void foo()
{
}
void bar()
{
}
But the Formatter removes this blank lines to 1 line for each. So how can i change that behavior.
// 1 lines between function
void foo()
{
}
void bar()
{
}
Thanks for your help

Related

How can I add space between code and comment?

I'm using nerdcommenter alongside neovim, and every time I comment out a block of code with <leader>cc, the code isn't really spaced out:
fn main() {
//println!("Hello, world!");
}
I want to get an output of something like this:
fn main() {
// println!("Hello, world!");
}
Is there a command or configuration that I'm missing out on? (I haven't configured nerdcommenter at all in my vimrc)
See the plugin docs : use g:NERDSpaceDelims configuration option
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
Or for Neovim with Lua configuration :
vim.g.NERDSpaceDelims = 1

in vscode default formatter for JavaScript, how to avoid space before brace?

here is my code
function foo(){
}
after passing it through the default formatter(alt+shift+f) I get:
function foo() {
}
(note the added space in the first line)
My question is: how do I set up the formatter so it does not add the space?

Visual Studio Code Does Not Comment-out Empty Lines

Visual Studio Code Does Not Comment-out Empty Lines
I've searched everywhere for a solution to this issue but couldn't find anything, and it's been bugging me for months now.
Basically what happens is that VS Code ignores empty lines when you tell it to comment out multiple lines of code.
So for example, let's say I highlighted all the code below and told VS Code to comment it out:
package com.mycompany.app;
public class MyApp {
public static void main(String[] args) {
SayHello();
}
static void SayHello() {
System.out.println("Hello!");
}
}
What I expected to get:
// package com.mycompany.app;
//
// public class MyApp {
// public static void main(String[] args) {
// SayHello();
// }
//
// static void SayHello() {
// System.out.println("Hello!");
// }
// }
What I got instead:
// package com.mycompany.app;
// public class MyApp {
// public static void main(String[] args) {
// SayHello();
// }
// static void SayHello() {
// System.out.println("Hello!");
// }
// }
I've only experienced this with Java and Golang so far, but I assume this happens for all other languages inside VS Code too.
The reason I want my comments to stay connected to each other is so I know which lines I commented out together in case I need to uncomment them back.
I am also aware of the Shift + Alt + A shortcut, but that typically uses Block Comments (which I don't like using), and I only want Line Comments.
Is there a setting I'm missing? Because I tried searching within VS Code and couldn't find anything either.
Any help would be greatly appreciated.
An option to have empty lines commented out is coming to v1.48. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_48.md#thank-you and https://github.com/microsoft/vscode/pull/93160
New setting:
Editor > Comments: Ignore Empty Lines default is true (will ignore)
[editor.comments.includeEmptyLines]
In Insiders' Build already v1.48.
A new VS Code setting has been added that resolves this issue:
"editor.comments.ignoreEmptyLines": false
Unfortunately, it is only tagged as "insiders-released" despite being included in Stable versions of VS Code.
Hopefully, this issue gets addressed in future versions.
Multi-line Editing seems to be the only alternative solution so far.
Press and hold the Alt key and press either Up or Down so your cursor expands to multiple lines. Then just add // manually.
It isn't very intuitive, but it works. Hopefully, the VS Code team will address this issue someday.
UPDATE: This feature has now been added to the VS Code backlog! (https://github.com/microsoft/vscode/issues/88480)

Eclipse Editor - SWT StyledText CaretListener offset not corresponding to real file line number

I am currently working on an Eclipse plugin. In order to do an action, I need to listen to the caret listener of the active tab.
public void partOpened(IWorkbenchPartReference partRef) {
AbstractTextEditor e = (AbstractTextEditor) ((IEditorReference) partRef).getEditor(false);
StyledText sText = ((StyledText) e.getAdapter(Control.class));
sText.addCaretListener(new CaretListener() {
#Override
public void caretMoved(CaretEvent event) {
IDocument d = e.getDocumentProvider().getDocument(e.getEditorInput());
...
int line = d.getLineOfOffset(event.caretOffset);
Point p = sText.getLocationAtOffset(event.caretOffset);
}
});
}
I use this code to add the CaretListener on the latest opened tab.
The variable line is correct only when no code blocks are collapsed.
In fact, the offset returned by the event is linked to the StyledText, but I'd like to get the line number of the file.
This picture shows an example of folded text. The StyledText caret offset will give me something like line 6, 7 and 8, instead of 6, 7 and 12 (like Eclipse does).
Is there a way to "transform" the StyledText offset to a "real file" offset ? I could retrieve the line as a String and find it in the file, but it sounds like a bad idea.
Thanks !
For folding editors the editor's source viewer will implement ITextViewerExtension5 which provides a widgetOffset2ModelOffset method to make this adjustment.
Get the caret position using something like:
ISourceViewer sourceViewer = e.getSourceViewer();
int caret;
if (sourceViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5)sourceViewer;
caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
} else {
int offset = sourceViewer.getVisibleRegion().getOffset();
caret = offset + styledText.getCaretOffset();
}

Eclipse custom formatting

I'm trying to create a JAVA code formatter such that it doesn't wrap any lines. BUT for any lines in my code that I have manually wrapped I want the formatter to respect them and not format them in to one line.
For example:
public Class {
public Class(String a,
String b,
String c,
String d) {
// The constructor arguments should stay as they are
}
public void aMethod() {
// This statement should not be wrapped
get().doSomething().getAnohterMethodThatHasAReeeeeeeaalllyyLongName();
}
}
I have made the line width 9999 (the max), and I have turned off line wrapping for everything. What have I missed?
Thanks.
I opened the preference page for
"Java - Code Style - Formatter"
and activated "never join lines"
and selected "Do not wrap" in the combo box "line wrapping policy"
After this change i was able to write code, which was not wrapped.