diff options
| author | David Elentok <3david@gmail.com> | 2024-05-14 18:15:13 +0300 |
|---|---|---|
| committer | David Elentok <3david@gmail.com> | 2024-05-14 18:17:09 +0300 |
| commit | a805d34f123bc8add01bd44ad28f0baf57710083 (patch) | |
| tree | b868cef404823eaf4b7c78316459cf8b2a3fd013 /lua/encrypt/setup-buffer.lua | |
| download | encrypt.nvim-a805d34f123bc8add01bd44ad28f0baf57710083.tar.gz | |
Initial commit
Diffstat (limited to 'lua/encrypt/setup-buffer.lua')
| -rw-r--r-- | lua/encrypt/setup-buffer.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lua/encrypt/setup-buffer.lua b/lua/encrypt/setup-buffer.lua new file mode 100644 index 0000000..a09cdfb --- /dev/null +++ b/lua/encrypt/setup-buffer.lua @@ -0,0 +1,28 @@ +local encrypt = require("encrypt.encrypt") + +local function createWriteAutoCmd() + if vim.b["encryptionAutoCmd"] ~= nil then + return + end + + vim.b["encryptionAutoCmd"] = vim.api.nvim_create_autocmd({ "BufWriteCmd" }, { + callback = function() + if vim.b["encrypted"] ~= true then + return + end + + encrypt() + end, + }) +end + +local function setupBuffer() + -- buftype="acwrite" means save using the BufWriteCmd command + vim.bo.buftype = "acwrite" + vim.bo.swapfile = false + vim.bo.undofile = false + vim.b["encrypted"] = true + createWriteAutoCmd() +end + +return setupBuffer |
