aboutsummaryrefslogtreecommitdiff
path: root/lua/encrypt/setup-buffer.lua
diff options
context:
space:
mode:
authorDavid Elentok <3david@gmail.com>2024-05-14 18:15:13 +0300
committerDavid Elentok <3david@gmail.com>2024-05-14 18:17:09 +0300
commita805d34f123bc8add01bd44ad28f0baf57710083 (patch)
treeb868cef404823eaf4b7c78316459cf8b2a3fd013 /lua/encrypt/setup-buffer.lua
downloadencrypt.nvim-a805d34f123bc8add01bd44ad28f0baf57710083.tar.gz
Initial commit
Diffstat (limited to 'lua/encrypt/setup-buffer.lua')
-rw-r--r--lua/encrypt/setup-buffer.lua28
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