From a09f1751c01d66a3b7519c72909746611d12a7f2 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Wed, 15 Jun 2016 08:52:26 -0400 Subject: Allow binary files to be encoded in something else. UTF-16 files (and other encodings with null bytes) are initially recognized as binary files (no encoding). Allow encodings to be set for such files after load. --- core/file_io.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core/file_io.lua') diff --git a/core/file_io.lua b/core/file_io.lua index bd018e5a..62966f3a 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -173,17 +173,19 @@ end -- LuaDoc is in core/.buffer.luadoc. local function set_encoding(buffer, encoding) - assert(buffer.encoding, _L['Cannot change binary file encoding']) local pos, first_visible_line = buffer.current_pos, buffer.first_visible_line local text = buffer:get_text() - text = text:iconv(buffer.encoding, 'UTF-8') - text = text:iconv(encoding, buffer.encoding) - text = text:iconv('UTF-8', encoding) + if buffer.encoding then + text = text:iconv(buffer.encoding, 'UTF-8') + if encoding then text = text:iconv(encoding, buffer.encoding) end + end + if encoding then text = text:iconv('UTF-8', encoding) end buffer:clear_all() buffer:add_text(text, #text) buffer:line_scroll(0, first_visible_line) buffer:goto_pos(pos) buffer.encoding = encoding + buffer.code_page = buffer.encoding and buffer.CP_UTF8 or 0 end -- Sets the default buffer encoding. events_connect(events.BUFFER_NEW, function() -- cgit v1.2.3