How can i hinder Eclipse from inserting CRLFs? - eclipse

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 .

Related

Visual studio code end of line setting (file with inconsistent line endings)

Is it possible to keep original end of lines in the file?
(I use visual studio code to edit files on a linux server through SAMBA)
There is a button at right bottom to choose either LF or CRLF,
but it replace all the end of lines in the file.
example:
line1 \r\n
line2 \r\n
line3 \n
No, it is not possible in VSCode to preserve the original line endings when they are not the same throughout a file. Internally, for each file, VSCode only stores a single _eol value, and when multi-line text is requested, inserts it between every line on the fly.
See, for example, method getText() in mirrorTextModel.ts. MirrorTextModel is a base class of ExtHostDocumentData, which implements the TextDocument entity exposed in the API.

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 to remove empty line from the end of new class - 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.

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.

Is there a way to copy code from eclipse including ine numbers

I am writing a little bit of documentation and code explanation. I would like to copy code from eclipse including line numbers, so that it becomes easier to reference the code in the text.
Is there any way to do this in eclipse or some other IDE, editor?
Since Eclipse 3.4 and bug 19602, you will print the line numbers if you have activated them on the Eclipse editor.
alt text http://img706.imageshack.us/img706/7605/eclipseshowlines.png
Printing a source will give you:
alt text http://img341.imageshack.us/img341/9899/eclipseprint.png
You can do it by printing a PDF of source file, then copying source with line numbers from the PDF document.
It works for me with eclipse PDT + CutePDF, it should also work with Acrobat PDF printer
Another not-so-clean work-around to achieve this. This is specific to the Subversive plug-in.
3 steps to follow:
Delete the piece of code you need to copy and save the source file.
Right click the file and chose option Team -> Create Patch.. and save it to a file, say copy.patch
Undo (Ctrl + Z) the changes to revert the deletion done in step 1 and save the source file again.
Open the patch file and use the contents.
This also includes the file-name (if desired) along with the line number and retains the indentation.