andreikop / enki

A text editor for programmers
http://enki-editor.org
GNU General Public License v2.0
161 stars 38 forks source link

Enki does not terminate files with a newline unless I explicitly create an empty line #63

Closed vi closed 12 years ago

vi commented 12 years ago

\n is a line terminator, not separator.

Text should end with \n by default.

Enki should create files ending in "\n" easily (and files without trailing \n less easy, i.e. by opening existing No newline at end of file file).

andreikop commented 12 years ago

I checked vim behavior - it is the same, as enki. And I would prefer to leave as is. If you want to have \n after last line - you can do it easily. If you don't want to have it - you also can do it easily.

vi commented 12 years ago

But after starting using Enki I noticed that such files started appearing which was not the case in Vim...

Example session: $ vim /tmp/q i12345Esc;wq $ enki /tmp/w 12345 Alt+F4; save checked $ diff -ur /tmp/{q,w} ... -12345 +12345 \ No newline at end of file

Maybe missing EOL at end of file should be highlighted somehow + Enki should automatically add a new line at the end if user types in the last empty line (user may explicitly delete it if he wants).

vi commented 12 years ago

Nano, ed and gedit also creates a EOL-terminated files by default. (but not Emacs unfortunately)

andreikop commented 12 years ago

Hmm. I checked vim once more. If file is empty (0 bytes) - vim lefts it as is. But for not empty files it appends EOL.

Done. Will see if functionality is useful.

Forgot to push to github. Will be available later.

andreikop commented 9 years ago

clarification: Vim saves 0-byte file if file was saved just after creation. But if any edit operation was done - EOL is added. So even absolutely empty file saved as one EOL symbol. Enki now always adds EOL to any text. So, it is impossible to generate 0-byte file with Enki

dglent commented 8 years ago

I have remarked this also. I would like to have this option to create a new line at the end. Now i create it at every time manually when i realise that is missing in diff checks before committing...

@hlamer: could be reviewed to add it even as a non default option?

andreikop commented 8 years ago

I don't quite understand how many new lines are necessary. Enki always adds 1 EOL when saving, and strips back when loading. If you see asdf on the screen, Enki saves

a@a-desktop ~/tmp $ od -tx1 test.txt
0000000 61 73 64 66 0a
dglent commented 8 years ago

If there is a new line at the end of the file and the file is edited and saved in enki, the new line at the end is removed and diffs show the message: "\ No newline at end of file" There is also a pylint message "W292 no newline at the end of file"

andreikop commented 8 years ago

If you create new file, type just x and save the file, what is the file size on the file system?

dglent commented 8 years ago

1 byte

andreikop commented 8 years ago

Hmm, very interesting. Could you please debug this and this code?

dglent commented 8 years ago

I cannot reproduce it with git version and python3 it saves a 2 bytes file, ok with the new line. I switch definitely to python3 and git version

andreikop commented 8 years ago

Hmm. Very interesting problem, since for me and the others py2 also works fine. But let's focus on stabilization py3 version.