diff options
author | Erlend Lind Madsen <erlendf80@gmail.com> | 2022-01-23 23:44:11 +0100 |
---|---|---|
committer | Erlend Lind Madsen <erlendf80@gmail.com> | 2022-01-23 23:44:11 +0100 |
commit | 0e2808e825f0043228fcf59f7cb534387d939eae (patch) | |
tree | 0751c75730481f2318257c95d14abadf2ae01370 | |
parent | f022a93bbbb796ac44739dfdf2dd819d70189411 (diff) | |
download | vis-cursors-0e2808e825f0043228fcf59f7cb534387d939eae.tar.gz |
re-read files on win_close and move current path to top
-rw-r--r-- | init.lua | 35 |
1 files changed, 22 insertions, 13 deletions
@@ -16,8 +16,7 @@ M.path = get_default_cache_path() -- default maxsize M.maxsize = 1000 --- read cursors from file on init -local on_init = function() +function read_files() -- read file local f = io.open(M.path) @@ -25,6 +24,8 @@ local on_init = function() return end + files = {} + -- read positions per file path for line in f:lines() do for path, pos in string.gmatch(line, '(.+)[,%s](%d+)') do @@ -36,6 +37,11 @@ local on_init = function() f:close() end +-- read cursors from file on init +local on_init = function() + read_files() +end + -- apply cursor pos on win open local on_win_open = function(win) @@ -43,17 +49,6 @@ local on_win_open = function(win) return end - -- remove old occurences of path - for i, path in ipairs(files) do - if path == win.file.path then - table.remove(files, i) - break - end - end - - -- insert current path to top of files - table.insert(files, 1, win.file.path) - -- init cursor path if nil local pos = cursors[win.file.path] if pos == nil then @@ -71,9 +66,23 @@ end -- set cursor pos on close local on_win_close = function(win) + -- re-read files in case they've changed + read_files() + + -- remove old occurences of current path + for i, path in ipairs(files) do + if path == win.file.path then + table.remove(files, i) + end + end + + -- insert current path to top of files + table.insert(files, 1, win.file.path) + if win.file == nil or win.file.path == nil then return end + -- set cursor pos for current file path cursors[win.file.path] = win.selection.pos end |