From c6225bc306dd2feaab5067aca3380dab1806e18e Mon Sep 17 00:00:00 2001 From: Alin Mr Date: Fri, 3 May 2024 11:46:37 +0000 Subject: init.lua: map filenames to lockfiles also solves re-locking a file we own (e.g. no-arg `:e`) --- init.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 2644eea..398e54e 100644 --- a/init.lua +++ b/init.lua @@ -51,12 +51,13 @@ end local created_locks = {} vis.events.subscribe(vis.events.FILE_OPEN, function(file) - if not file.path then + if created_locks[file.path] or not file.path then + -- either a noname buffer, or already locked by us return end local lfile_path = lockfiles.lock_file_path(get_lock_dir(), file.path) if lockfiles.create_lock_file(get_lock_dir(), lfile_path) then - created_locks[lfile_path] = true + created_locks[file.path] = lfile_path elseif not confirm(lfile_path) then os.exit(1) end @@ -66,10 +67,10 @@ vis.events.subscribe(vis.events.FILE_CLOSE, function(file) if not file.path then return end - local lfile_path = lockfiles.lock_file_path(get_lock_dir(), file.path) - if created_locks[lfile_path] then + local lfile_path = created_locks[file.path] + if lfile_path then lockfiles.delete_lock_file(lfile_path) - created_locks[lfile_path] = nil + created_locks[file.path] = nil end end) -- cgit v1.2.3