aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlend Lind Madsen <erlendf80@gmail.com>2022-01-23 21:38:14 +0100
committerErlend Lind Madsen <erlendf80@gmail.com>2022-01-23 21:40:14 +0100
commit92db312669fa6ca3d70e30467f22ffa2b18a6987 (patch)
tree9ee5cddb29f033aa9ec16805ee30354179ded8bf
parent2741697da0086d1f8d3756e1c19c7e053ee20e98 (diff)
downloadvis-cursors-92db312669fa6ca3d70e30467f22ffa2b18a6987.tar.gz
reorder methods
-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)