aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/file_io.lua11
-rw-r--r--modules/textadept/key_commands.lua23
2 files changed, 31 insertions, 3 deletions
diff --git a/core/file_io.lua b/core/file_io.lua
index cdc09af0..c7433479 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -3,11 +3,21 @@
---
-- Provides file input/output routines for Textadept.
-- Opens and saves files and sessions and reads API files.
+--
+-- Events:
+-- file_opened(filename)
+-- file_saved_as(filename)
module('textadept.io', package.seeall)
local events = textadept.events
---
+-- List of recently opened files.
+-- @class table
+-- @name recent_files
+recent_files = {}
+
+---
-- [Local function] Opens a file or goes to its already open buffer.
-- @param filename The absolute path to the file to open.
local function open_helper(filename)
@@ -25,6 +35,7 @@ local function open_helper(filename)
buffer.filename = filename
buffer:set_save_point()
events.handle('file_opened', filename)
+ recent_files[#recent_files + 1] = filename
end
---
diff --git a/modules/textadept/key_commands.lua b/modules/textadept/key_commands.lua
index 2072795f..afdc36de 100644
--- a/modules/textadept/key_commands.lua
+++ b/modules/textadept/key_commands.lua
@@ -6,7 +6,7 @@ module('_m.textadept.key_commands', package.seeall)
--[[
C: G Q
- A: A C G J K L O Q R W X Z
+ 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
@@ -130,11 +130,12 @@ local m_macro = _m.textadept.macros
keys.cam = { m_macro.toggle_record }
keys.csam = { m_macro.play }
-keys.cr = { textadept.io.open }
+local t_io = textadept.io
+keys.cr = { t_io.open }
keys.co = { 'save', b }
keys.cso = { 'save_as', b }
keys.cx = { 'close', b }
-keys.csx = { textadept.io.close_all }
+keys.csx = { t_io.close_all }
keys.cz = { 'undo', b }
keys.csz = { 'redo', b }
keys.as.a = { 'select_all', b }
@@ -143,6 +144,22 @@ keys.ap = { 'goto_buffer', v, -1, false }
keys.can = { textadept.goto_view, 1, false }
keys.cap = { textadept.goto_view, -1, false }
+local RECENT_FILES = 1
+textadept.events.add_handler('user_list_selection',
+ function(type, text) if type == RECENT_FILES then t_io.open(text) end end)
+
+keys.ar = { function()
+ local buffer = buffer
+ local list = ''
+ local sep = buffer.auto_c_separator
+ buffer.auto_c_separator = ('|'):byte()
+ for _, filename in ipairs(t_io.recent_files) do
+ list = filename..'|'..list
+ end
+ buffer:user_list_show( RECENT_FILES, list:sub(1, -2) )
+ buffer.auto_c_separator = sep
+end }
+
local m_events = textadept.events
keys.cab = { m_events.handle, 'call_tip_click', 1 }
keys.caf = { m_events.handle, 'call_tip_click', 2 }