diff options
author | 2007-09-27 23:05:20 -0400 | |
---|---|---|
committer | 2007-09-27 23:05:20 -0400 | |
commit | ece35a566f002bb0454d3f02a87ca51a48a7c7c5 (patch) | |
tree | 47976d27bce1b458aa4d27d82853e76d76426b6f | |
parent | 0c947b9f153824d092437c8f06aee28602814d00 (diff) |
Added buffer:reload() function.
-rw-r--r-- | core/events.lua | 1 | ||||
-rw-r--r-- | core/file_io.lua | 18 | ||||
-rw-r--r-- | modules/textadept/key_commands.lua | 3 |
3 files changed, 21 insertions, 1 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. diff --git a/modules/textadept/key_commands.lua b/modules/textadept/key_commands.lua index 5d8c3bb0..4f69bb7b 100644 --- a/modules/textadept/key_commands.lua +++ b/modules/textadept/key_commands.lua @@ -10,7 +10,7 @@ module('_m.textadept.key_commands', package.seeall) A: A C G J K L O Q W X Z CS: C D G J L Q R S T U W SA: A C D E G H I J K L M O Q R S T W X Z - CA: A C G H J K L O Q R S T V W X Y Z + CA: A C G H J K L O Q S T V W X Y Z CSA: C D G H J K L O Q R S T U W X Z ]]-- @@ -32,6 +32,7 @@ keys.ct.v = {} -- View chain -- Standard commands. New, open, save, etc. keys.ct.n = { t.new_buffer } keys.cr = { t.io.open } +keys.car = { 'reload', b } keys.co = { 'save', b } keys.cso = { 'save_as', b } keys.cx = { 'close', b } |