diff options
author | 2016-06-15 08:52:26 -0400 | |
---|---|---|
committer | 2016-06-15 08:52:26 -0400 | |
commit | a09f1751c01d66a3b7519c72909746611d12a7f2 (patch) | |
tree | 0e1dc7d20b6f66100589e5e28f289dbeeed31d35 /core/file_io.lua | |
parent | 16bf7c94537afe0883b1e80b2dbdbfaf7e6d391a (diff) | |
download | textadept-a09f1751c01d66a3b7519c72909746611d12a7f2.tar.gz textadept-a09f1751c01d66a3b7519c72909746611d12a7f2.zip |
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.
Diffstat (limited to 'core/file_io.lua')
-rw-r--r-- | core/file_io.lua | 10 |
1 files changed, 6 insertions, 4 deletions
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() |