aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/.buffer.luadoc8
-rw-r--r--core/file_io.lua13
2 files changed, 13 insertions, 8 deletions
diff --git a/core/.buffer.luadoc b/core/.buffer.luadoc
index dd13b8e5..9170dc37 100644
--- a/core/.buffer.luadoc
+++ b/core/.buffer.luadoc
@@ -2698,6 +2698,14 @@ function new() end
function text_range(buffer, start_pos, end_pos) end
---
+-- Converts the current buffer's contents to encoding *encoding*.
+-- @param buffer A buffer.
+-- @param encoding The string encoding to set. Valid encodings are ones that GNU
+-- iconv accepts.
+-- @usage io.set_buffer_encoding('ASCII')
+function set_encoding(buffer, encoding) end
+
+---
-- Returns the buffer's lexer name.
-- If *current* is `true`, returns the name of the lexer under the caret in
-- a multiple-language lexer.
diff --git a/core/file_io.lua b/core/file_io.lua
index 6b860e3b..6c66632e 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -191,13 +191,8 @@ function io.reload_file()
buffer.mod_time = lfs.attributes(buffer.filename, 'modification')
end
----
--- Converts the current buffer's contents to encoding *encoding*.
--- @param encoding The string encoding to set. Valid encodings are ones that GNU
--- iconv accepts.
--- @usage io.set_buffer_encoding('ASCII')
--- @name set_buffer_encoding
-function io.set_buffer_encoding(encoding)
+-- 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()
@@ -211,7 +206,9 @@ function io.set_buffer_encoding(encoding)
buffer.encoding, buffer.encoding_bom = encoding, io.boms[encoding]
end
-- Sets the default buffer encoding.
-events_connect(events.BUFFER_NEW, function() buffer.encoding = 'UTF-8' end)
+events_connect(events.BUFFER_NEW, function()
+ buffer.set_encoding, buffer.encoding = set_encoding, 'UTF-8'
+end)
---
-- Saves the current buffer to its file.