From a805d34f123bc8add01bd44ad28f0baf57710083 Mon Sep 17 00:00:00 2001 From: David Elentok <3david@gmail.com> Date: Tue, 14 May 2024 18:15:13 +0300 Subject: Initial commit --- lua/encrypt/setup-buffer.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lua/encrypt/setup-buffer.lua (limited to 'lua/encrypt/setup-buffer.lua') 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 -- cgit v1.2.3