Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does eclipse figure if a file has unix or dos-style line endings?

I am looking at some Java Code in Eclipse on Windows. The line termination characters (DOS-style) do not display properly (empty lines everywhere..).

The Problem is that the Code is from a Windows ClearCase vob for which I do not have check-in permissions, so it is read-only (changing the line-termination characters with auto-format is not possible). Creating a full copy and changing the line termintators is out of the question as the code might change while I am looking at it..

I found Preferences->Workspace->"New text file line delimiter", but it seems that this does not display the line termination characters in existing files properly.

How do I make eclipse display the text file as it was meant to display?

Edit: Notepad displays the file correctly. Ultra-Edit also detects it as unix-style and suggests converting it to DOS (but displays properly when declining it). gvim detects the file as unix and displays ^M and the end of the line.

I have checked the file in binary and it does not contain any \n characters that do not follow a \r character. Could there be any other way that Eclipse distinguishes unix from dos-style line endings?

I found this sequence of characters: 0d0d 0a0d 0d0a (\r\r\n\r\r\n). I suppose this is why it does not work..

like image 892
0x89 Avatar asked Nov 05 '10 09:11

0x89


People also ask

How do I know if a file is LF or CR LF?

use a text editor like notepad++ that can help you with understanding the line ends. It will show you the line end formats used as either Unix(LF) or Macintosh(CR) or Windows(CR LF) on the task bar of the tool. you can also go to View->Show Symbol->Show End Of Line to display the line ends as LF/ CR LF/CR.

What is Unix style line endings?

Text files created on DOS/Windows machines have different line endings than files created on Unix/Linux. DOS uses carriage return and line feed ("\r\n") as a line ending, which Unix uses just line feed ("\n").

How do I view CR LF in Unix?

Open any text file and click on the pilcrow (¶) button. Notepad++ will show all of the characters with newline characters in either the CR and LF format. If it is a Windows EOL encoded file, the newline characters of CR LF will appear (\r\n). If the file is UNIX or Mac EOL encoded, then it will only show LF (\n).


2 Answers

What OS are you running on? Eclipse auto detect line terminators. I never seen it fail and display extra newlines. is it possible that your file actually does not double newlines? maybe try to view it with another editor (notepad++, editplus)

like image 179
Omry Yadan Avatar answered Sep 28 '22 02:09

Omry Yadan


Go to Preferences->General->Workspace You will see Text file encoding where you can change it to the encoding you prefer and there is the New text file line delimiter where you have to option of using unix, windows or mac os

like image 21
s-hunter Avatar answered Sep 28 '22 00:09

s-hunter