diff options
| author | Alin Mr <almr.oss@outlook.com> | 2024-05-03 11:46:37 +0000 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2024-05-03 16:48:03 +0200 |
| commit | c6225bc306dd2feaab5067aca3380dab1806e18e (patch) | |
| tree | 92cac82faeea04458530a886dd1b1e669839323a /init.lua | |
| parent | dce094a0c6730ae47d27e90a84d2f582aba42736 (diff) | |
| download | vis-lockfiles-c6225bc306dd2feaab5067aca3380dab1806e18e.tar.gz vis-lockfiles-c6225bc306dd2feaab5067aca3380dab1806e18e.zip | |
init.lua: map filenames to lockfiles
also solves re-locking a file we own (e.g. no-arg `:e`)
Diffstat (limited to 'init.lua')
| -rw-r--r-- | init.lua | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -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) |
