aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlend Lind Madsen <erlendf80@gmail.com>2020-10-29 12:53:18 +0100
committerErlend Lind Madsen <erlendf80@gmail.com>2020-10-29 12:53:18 +0100
commit1ad44a9109e250a86f38415c90bbefe3f3e62da5 (patch)
tree82e0043efc4c897427181bbdca64208897d19465
parentf36f51f60070298bb19fb92f58acc06e8dc6a0c6 (diff)
downloadvis-cursors-1ad44a9109e250a86f38415c90bbefe3f3e62da5.tar.gz
buffered write | remove unnecessary set cursors
-rw-r--r--init.lua25
1 files changed, 15 insertions, 10 deletions
diff --git a/init.lua b/init.lua
index 69e29bf..12d4552 100644
--- a/init.lua
+++ b/init.lua
@@ -26,26 +26,31 @@ function read_cursors()
cursors = {}
local f = io.open(M.path)
if f == nil then return end
+ -- read positions per file path
for line in f:lines() do
- for k, v in string.gmatch(line, '(.+)%s(%d+)') do
- cursors[k] = v
+ for path, pos in string.gmatch(line, '(.+)%s(%d+)') do
+ cursors[path] = pos
end
end
f:close()
- for win in vis:windows() do
- apply_cursor_pos(win)
- end
end
function write_cursors()
local f = io.open(M.path, 'w+')
if f == nil then return end
- local a = {}
- for k in pairs(cursors) do table.insert(a, k) end
- table.sort(a)
- for i,k in ipairs(a) do
- f:write(string.format('%s %d\n', k, cursors[k]))
+ -- sort paths
+ local paths = {}
+ for path in pairs(cursors) do
+ table.insert(paths, path)
end
+ table.sort(paths)
+ -- buffer cursors string
+ local t = {}
+ for i, path in ipairs(paths) do
+ table.insert(t, string.format('%s %d', path, cursors[path]))
+ end
+ local s = table.concat(t, '\n')
+ f:write(s)
f:close()
end