From 4310f7e4b692c5a53c481781ecb8037c893a83a5 Mon Sep 17 00:00:00 2001 From: undrpaidtekmnky Date: Wed, 4 Dec 2024 04:55:09 -0700 Subject: [PATCH] Add autosave --- lazy-lock.json | 5 +++- lua/plugins/autosave-nvim.lua | 44 +++++++++++++++++++++++++++++++++++ lua/plugins/init.lua | 1 + lua/plugins/lualine-nvim.lua | 4 ---- 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 lua/plugins/autosave-nvim.lua delete mode 100644 lua/plugins/lualine-nvim.lua diff --git a/lazy-lock.json b/lazy-lock.json index 63c9bff..5d207b4 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,7 +1,9 @@ { "LuaSnip": { "branch": "master", "commit": "33b06d72d220aa56a7ce80a0dd6f06c70cd82b9d" }, "NvChad": { "branch": "v2.5", "commit": "bbc3d43db088c141b142a40cd5f717635833a54e" }, + "auto-save.nvim": { "branch": "main", "commit": "5fbcaac0a2698c87a9a1bd2083cb6949505cca12" }, "base46": { "branch": "v2.5", "commit": "40943fc668bf8f1caa4cc45f71c784cf0d3cc34f" }, + "bufferline.nvim": { "branch": "main", "commit": "261a72b90d6db4ed8014f7bda976bcdc9dd7ce76" }, "cmake-tools.nvim": { "branch": "master", "commit": "53bc5261e1e0b0d28be465d2b2b07a6f0646e1eb" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, @@ -37,11 +39,12 @@ "nvim-notify": { "branch": "master", "commit": "fbef5d32be8466dd76544a257d3f3dce20082a07" }, "nvim-numbertoggle": { "branch": "main", "commit": "c5827153f8a955886f1b38eaea6998c067d2992f" }, "nvim-tree.lua": { "branch": "master", "commit": "ca7c4c33cac2ad66ec69d45e465379716ef0cc97" }, - "nvim-treesitter": { "branch": "master", "commit": "3edea87978b2ee93b197513e5cdf86012d33b7fa" }, + "nvim-treesitter": { "branch": "master", "commit": "b0fc560c758eeaa53b099c0843f82bcd762a9235" }, "nvim-web-devicons": { "branch": "master", "commit": "203da76ecfbb4b192cf830665b03eb651b635c94" }, "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, "telescope.nvim": { "branch": "master", "commit": "2eca9ba22002184ac05eddbe47a7fe2d5a384dfc" }, "toggleterm.nvim": { "branch": "main", "commit": "022ff5594acccc8d90d2e46dc43994f7722ebdf7" }, + "tokyonight.nvim": { "branch": "main", "commit": "15d83cda572d7498b43bbdaa223bc75bf341183e" }, "ui": { "branch": "v3.0", "commit": "7905539f1e10f460811dc0db800355611f8a527a" }, "vim-cmake": { "branch": "master", "commit": "896bc2189c8ade62d00a0ebedc59c65d9d9b0d65" }, "vim-floaterm": { "branch": "master", "commit": "4e28c8dd0271e10a5f55142fb6fe9b1599ee6160" }, diff --git a/lua/plugins/autosave-nvim.lua b/lua/plugins/autosave-nvim.lua new file mode 100644 index 0000000..487bfd0 --- /dev/null +++ b/lua/plugins/autosave-nvim.lua @@ -0,0 +1,44 @@ +local group = vim.api.nvim_create_augroup("autosave", {}) + +vim.api.nvim_create_autocmd("User", { + pattern = "AutoSaveWritePost", + group = group, + callback = function(opts) + if opts.data.saved_buffer ~= nil then + print("AutoSaved at " .. vim.fn.strftime("%H:%M:%S")) + end + end, +}) + +return { + { + + "okuuva/auto-save.nvim", + version = "^1.0.0", -- see https://devhints.io/semver, alternatively use '*' to use the latest tagged release + cmd = "ASToggle", -- optional for lazy loading on command + event = { "InsertLeave", "TextChanged" }, -- optional for lazy loading on trigger events + opts = { + -- your config goes here + -- or just leave it empty :) + -- + + enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it) + trigger_events = { -- See :h events + immediate_save = { "BufLeave", "FocusLost" }, -- vim events that trigger an immediate save + defer_save = { "InsertLeave", "TextChanged" }, -- vim events that trigger a deferred save (saves after `debounce_delay`) + cancel_deferred_save = { "InsertEnter" }, -- vim events that cancel a pending deferred save + }, + -- function that takes the buffer handle and determines whether to save the current buffer or not + -- return true: if buffer is ok to be saved + -- return false: if it's not ok to be saved + -- if set to `nil` then no specific condition is applied + condition = nil, + write_all_buffers = false, -- write all buffers when the current one meets `condition` + noautocmd = false, -- do not execute autocmds when saving + lockmarks = false, -- lock marks when saving, see `:h lockmarks` for more details + debounce_delay = 1000, -- delay after which a pending save is executed + -- log debug messages to 'auto-save.log' file in neovim cache directory, set to `true` to enable + debug = false, + }, + }, +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index acfb274..8e10d74 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -59,4 +59,5 @@ return { require("configs.mason-conform") end, }, + } diff --git a/lua/plugins/lualine-nvim.lua b/lua/plugins/lualine-nvim.lua deleted file mode 100644 index 7c6877b..0000000 --- a/lua/plugins/lualine-nvim.lua +++ /dev/null @@ -1,4 +0,0 @@ -return { - "nvim-lualine/lualine.nvim", - dependencies = { "nvim-tree/nvim-web-devicons" }, -}