diff options
author | 2009-02-23 22:25:24 -0500 | |
---|---|---|
committer | 2009-02-23 22:25:24 -0500 | |
commit | 7d2a6cf9f0c597f8780a8da7bec8acd33d2c9c66 (patch) | |
tree | 36eeb65bd8f10add7f7e1399f8e679fa7eda8e39 | |
parent | dd1240d13b8cb12f6fa1770704445d35e75447f9 (diff) | |
download | textadept-7d2a6cf9f0c597f8780a8da7bec8acd33d2c9c66.tar.gz textadept-7d2a6cf9f0c597f8780a8da7bec8acd33d2c9c66.zip |
Attempt to preserve existing EOL mode for opened files; core/file_io.lua
-rw-r--r-- | core/file_io.lua | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/core/file_io.lua b/core/file_io.lua index 32764f12..12367c47 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -41,8 +41,17 @@ local function open_helper(filename) end local buffer = textadept.new_buffer() if text then + -- Check for binary file. If it is one, it's not UTF-8 local chunk = #text > 65536 and text:sub(1, 65536) or text - if chunk:find('\0') then buffer.code_page = 0 end -- binary file; no UTF-8 + if chunk:find('\0') then buffer.code_page = 0 end + -- Tries to set the buffer's EOL mode appropriately based on the file. + local c = textadept.constants + local s, e = text:find('\r\n?') + if s and e then + buffer.eol_mode = (s == e and c.SC_EOL_CR or c.SC_EOL_CRLF) + else + buffer.eol_mode = c.SC_EOL_LF + end buffer:add_text(text, #text) buffer:goto_pos(0) buffer:empty_undo_buffer() |