aboutsummaryrefslogtreecommitdiff
path: root/lua/encrypt/setup-buffer.lua
diff options
context:
space:
mode:
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