aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/events.lua1
-rw-r--r--core/file_io.lua18
2 files changed, 19 insertions, 0 deletions
diff --git a/core/events.lua b/core/events.lua
index bfd5ef09..3fe609e3 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -306,6 +306,7 @@ add_handler('margin_click',
add_handler('buffer_new',
function() -- set additional buffer functions
local buffer, textadept = buffer, textadept
+ buffer.reload = textadept.io.reload
buffer.save = textadept.io.save
buffer.save_as = textadept.io.save_as
buffer.close = textadept.io.close
diff --git a/core/file_io.lua b/core/file_io.lua
index c7433479..e4d36db0 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -53,6 +53,24 @@ function open(filenames)
end
---
+-- Reloads the file in a given buffer.
+-- @param buffer The buffer to reload. This must be the currently focused
+-- buffer.
+-- @usage buffer:reload()
+function reload(buffer)
+ textadept.check_focused_buffer(buffer)
+ if not buffer.filename then return end
+ local f, err = io.open(buffer.filename)
+ if f then
+ local pos = buffer.current_pos
+ buffer:set_text( f:read('*all') )
+ buffer.current_pos = pos
+ buffer:set_save_point()
+ f:close()
+ end
+end
+
+---
-- Saves the current buffer to a file.
-- @param buffer The buffer to save. Its 'filename' property is used as the
-- path of the file to save to. This must be the currently focused buffer.