How to remove empty line from the end of new class - Eclipse - eclipse

I currently work on Eclipse Juno 4.2 (but problem is connected with older versions of eclipse as well) and I found an irritating issue. When we try to create new class with a default formatter settings, eclipse put an empty line at the end of file.
I tried to figure out by myself how to remove this annoying line and search in formatter options. I found option that could help solve my problem but i found it's disable by default.
My question is: How to get rid of this line?

It's not really an empty line. It just appears that way in Eclipse.
When you see the blank line in Eclipse, it means that the last line of the file is terminated by a new line character. That is, the last characters in your Java file are probably }\n (on *nix, with LF line endings) or }\r\n (CRLF line endings on Windows), followed in each case by the end of the file.
You can prove this to yourself using tail or cat on *nix. If the prompt appears on the same line as the last line of code, then there's no trailing new line. If the prompt appears on a separate line, then there is a trailing new line character. If there's a blank line before the prompt, then there's an empty line in the file.
If the above doesn't convince you, use a hex editor. :o) An empty line would appear as two consecutive line endings: \n\n or \r\n\r\n (on *nix and windows respectively).
There's nothing wrong with the last line of your file having a new line character at the end. In fact, it's a good idea to leave it there, because some tools will warn if it's not there. These tools include Checkstyle (there's an Eclipse Checkstyle plugin) and diff.
Eclipse allows you to put the cursor there in case you want to add new content to the end of the file. (This isn't often needed in Java, because most people don't put more than one top-level type in a file.)
Best just to leave it there, and get used to Eclipse showing it.

Related

Eclipse 2021-12: Hidden code sections - Looking collapsed without any way to expand

In my Java files I have frequently issues like the following example:
Eclipse is hiding lines and there is no way to expand them.
My first assumption was that the line endings might be inconsistent (mixed Unix/Windows line endings), so I changed them to Windows line endings with Notepad++, but this did not solve the problem.
How could I fix this problem?

Changing the default display of line breaks in search window?

I recently switched from Textwrangler to BBEdit. I use these editors to perform large multi-file GREP-search mainly. But in BBEdit I noticed that line breaks automatically get converted to \n in the search window, and that makes in very hard for me to get an overview of the search I'm about to perform, when everything is on one line.
When I copy a text with line breaks, for example
Line
Line
Line
and paste it in the search window, it looks like this:
Line\n\nLine\n\nLine
In TextWrangler I was able to see the line breaks as line breaks, not \n. How can I change that in BBEdit?
Thanks!

Line breaks using dlmcell in Matlab - shows up in Notepad++ but not Notepad

I am using the function dlmcell in Matlab to output text. I want text on a new line each time I append using dlmcell.
When I open my written document in Notepad++, each snippet of text is on a new line as I want it. However, opening it in Notepad that comes with windows, everything is on the same line. Can somebody tell me why this is, and how to fix it?
I'm assuming you're using the string \n to declare a new line in your output. For Notepad++ this is sufficient, because it interprets a new line just with \n. For the Windows Editor you need to include the carriage return also:
substitute:
\n with \r\n
This way not just a new line is created, it also tells the editor to actually continue on the next line.
To illustrate what I mean, open your output file with Notepad++ and activate View > Show Symbol > All characters and you will see something like:
I wrote this with Notepad++ and it automatically adds CR (carriage return) and LF (line feed) at the end of every line. Matlab doesn't if you don't tell it. So your output file only contains LF without the above mentioned substitution.
I've had a look into dlmcell, which is a FEX-function. In the current version \r\n is implemented actually. Do you have the newest version of that function (Download)? If not, something else must be wrong, please post some code.

How can i hinder Eclipse from inserting CRLFs?

I just reinstalled Eclipse Juno.
The problem i have is when i create a new file and start writing, CRLFs are inserted on Return.
Second case: When i fully mark the text of a file (without CRLFs) ans COPY them into another file (i use CRTL+A and DEL to get rid of the file contents and then PASTE i get the file content with CRLFs!)
The resulting file looks like:
Test blah CRLF
Line two ... CRLF
CRLF
How can i get rid of them?
Solution to this is to configure Eclipse accordingly.
Windows->Preferences->General->Workspace
In the right lower corner there is a setting called "New text fiel line delimiter" which i had to switch from Windows to Unix.
The already CRLF prensent i had to remove using Eclispe->File->Convert line delimiters to ->Unix .

Automatic EOL conversion in Eclipse

Need to keep EOL format consistent in all resources under Eclipse workspace.
I know about Eclipse preference that sets new line style for newly created files, but I would like to have automatic conversion for already existing files. Is there some settings/plugins?
I want just setup once and be sure that all line endings are in the same format.
In addition to the Window > Preferences > General > Workspace setting for new files that you already know about, there is a File > Convert Line Delimiters To option. I don't know of any existing plugin/tool that will do this automatically when you save, but you could certainly write one or make converting the line ending part of your process.
To make it easier on yourself, you can bind keyboard shortcuts to the conversion commands by going to Window > Preferences > General > Keys and filtering using "delimiter":
In Eclipse, to convert the line endings for existing files:
Go to the file browser view, and click on the project/folder/file that you wish to convert.
From the menu bar, select File > Convert Line Delimiters To > Windows / Unix / MacOS 9.
You can Search your resources with the Search-Dialog and go to the tab File Search. There you can enter a Regular expression. Enter \r\n or whatever line ending you want to change.
Then hit the Replace .. Button instead of Search.
I want just setup once and be sure that all line endings are in the same format.
... ok, my answer does not consider this.
You might get usefull results with Eclipse save actions: If the eclipse formatter also converts the EOL style, you could use it to modify EOL style only for the files you are modifying.
Unfortunately I don't have eclipse here, so I can't test if this actually works. Worth a try, however.