From ece35a566f002bb0454d3f02a87ca51a48a7c7c5 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Thu, 27 Sep 2007 23:05:20 -0400 Subject: Added buffer:reload() function. --- core/file_io.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'core/file_io.lua') 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 @@ -52,6 +52,24 @@ function open(filenames) for filename in filenames:gmatch('[^|\n]+') do open_helper(filename) end 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 -- cgit v1.2.3