From 7d2a6cf9f0c597f8780a8da7bec8acd33d2c9c66 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Mon, 23 Feb 2009 22:25:24 -0500 Subject: Attempt to preserve existing EOL mode for opened files; core/file_io.lua --- core/file_io.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'core/file_io.lua') 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() -- cgit v1.2.3