Maintain OS specific end-of-lines in code files. #133
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Possibly fixes #112 and #85.
At the moment we are having issues processing the Windows end of line format (
\r\n
). In essence scintilla automatically selects the host OS line ending type (as it should), so we have the editor producing\r\n
endings, and the default saving option in python tries to convert to the native type, replacing each\n
with\r\n
, and causing the final format saved as\r\r\n
. By the default open options, which try to convert windows line endings into single\n
, this is then read back as\n\n
.We should definitely keep compatibility with the Windows format for both opening and saving files. So the idea is to keep scintilla appending
\r\n
, save the files as they are edited without any modifications, and opening them without converting the windows line ending into single\n
either.So I've added the
newline=\n
argument to the eachopen()
used to write the editor file. This sets the default line endings as\n
, which does not replace\n\r
with\n
, it just leaves them alone. Theopen()
calls for reading files have been configured tonewline=os.linesep
, which should maintain the same behaviour on linux/osx and not translate the windows\r\n
into\n
.I have left the settings file alone as all the new lines produced by Python itself should be
\n
and correctly converted. However we should note that the log file currently copies logs the code every time the file is saved, so this could be revisited in the future.So, a general question I’ve got is if we are maintining Python2 compatibility at all? The
open(newline=)
argument is Python3 only.