aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--init.lua36
1 files changed, 18 insertions, 18 deletions
diff --git a/init.lua b/init.lua
index 52a7045..7fd5ee0 100644
--- a/init.lua
+++ b/init.lua
@@ -10,6 +10,20 @@ end
M.path = get_default_cache_path()
+local read_cursors = function()
+ local f = io.open(M.path)
+ if f == nil then
+ return
+ end
+ -- read positions per file path
+ for line in f:lines() do
+ for path, pos in string.gmatch(line, '(.+)[,%s](%d+)') do
+ cursors[path] = pos
+ end
+ end
+ f:close()
+end
+
local apply_cursor_pos = function(win)
if win.file == nil or win.file.path == nil then
return
@@ -22,18 +36,12 @@ local apply_cursor_pos = function(win)
vis:feedkeys("zz")
end
-local read_cursors = function()
- local f = io.open(M.path)
- if f == nil then
+local set_cursor_pos = function(win)
+ if win.file == nil or win.file.path == nil then
return
end
- -- read positions per file path
- for line in f:lines() do
- for path, pos in string.gmatch(line, '(.+)[,%s](%d+)') do
- cursors[path] = pos
- end
- end
- f:close()
+ -- set cursor pos for current file path
+ cursors[win.file.path] = win.selection.pos
end
local write_cursors = function()
@@ -60,14 +68,6 @@ local write_cursors = function()
f:close()
end
-local set_cursor_pos = function(win)
- 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
-
vis.events.subscribe(vis.events.INIT, read_cursors)
vis.events.subscribe(vis.events.WIN_OPEN, apply_cursor_pos)
vis.events.subscribe(vis.events.WIN_CLOSE, set_cursor_pos)