make my own auto save the auto-save plugin is being weird
This commit is contained in:
parent
2063357974
commit
9bce2b0d42
5 changed files with 33 additions and 27 deletions
|
@ -55,7 +55,6 @@
|
|||
"nvim_plugin-nvim-treesitter/nvim-treesitter" = nvim-treesitter.withAllGrammars;
|
||||
"nvim_plugin-nvim-lua/plenary.nvim" = plenary-nvim;
|
||||
"nvim_plugin-catppuccin/nvim" = catppuccin-nvim;
|
||||
"nvim_plugin-Pocco81/auto-save.nvim" = auto-save-nvim;
|
||||
"nvim_plugin-MunifTanjim/nui.nvim" = nui-nvim;
|
||||
"nvim_plugin-rcarriga/nvim-notify" = nvim-notify;
|
||||
"nvim_plugin-folke/noice.nvim" = noice-nvim;
|
||||
|
|
|
@ -10,7 +10,6 @@ vim.api.nvim_create_autocmd("TextYankPost", {
|
|||
end,
|
||||
})
|
||||
|
||||
|
||||
-- TODO is there a better way for these?
|
||||
-- https://www.youtube.com/watch?v=NecszftvMFI vim.filetype.add
|
||||
vim.api.nvim_create_autocmd("BufRead", {
|
||||
|
@ -58,3 +57,29 @@ vim.api.nvim_create_autocmd("VimLeavePre", {
|
|||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local auto_save_disallowed_filetypes = { "TelescopePrompt", "quickfix", "terminal" }
|
||||
local auto_save_debounce = {}
|
||||
vim.api.nvim_create_autocmd({ "InsertLeave", "TextChanged", "TextChangedI", "BufLeave" }, {
|
||||
group = group,
|
||||
callback = function(event)
|
||||
local modifiable = vim.api.nvim_buf_get_option(event.buf, "modifiable")
|
||||
local filetype = vim.api.nvim_buf_get_option(event.buf, "filetype")
|
||||
local modified = vim.api.nvim_buf_get_option(event.buf, "modified")
|
||||
if
|
||||
modifiable
|
||||
and modified
|
||||
and U.table_not_contains(auto_save_disallowed_filetypes, filetype)
|
||||
then
|
||||
if auto_save_debounce[event.buf] ~= 1 then
|
||||
auto_save_debounce[event.buf] = 1
|
||||
vim.defer_fn(function()
|
||||
vim.api.nvim_buf_call(event.buf, function()
|
||||
vim.api.nvim_command("silent! write")
|
||||
end)
|
||||
auto_save_debounce[event.buf] = nil
|
||||
end, 500)
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -27,7 +27,7 @@ U.keymaps({
|
|||
{ ";", ":", desc = "No shift to enter command mode with semicolon. Alias ; to :", mode = nvx },
|
||||
{ "<leader>Q", "<nop>", mode = nvx }, -- don't do normal Q quit
|
||||
{ "<leader>a", "<esc>ggVG", desc = "Select all", mode = nvx },
|
||||
{ "Q", "<cmd>SessionSave<cr><cmd>qa!<cr>", desc = "Quit all", mode = nvx },
|
||||
{ "Q", "<cmd>SessionSave<cr><cmd>qa<cr>", desc = "Quit all", mode = nvx },
|
||||
{ "<leader>y", '"+y', desc = "Copy to system clipboard", mode = nvx },
|
||||
{ "<leader>p", '"+p', desc = "Paste from system clipboard", mode = nvx },
|
||||
{ "<esc>", "<cmd>nohlsearch<cr><esc>", desc = "Clear search on escape" },
|
||||
|
@ -54,7 +54,8 @@ U.keymaps({
|
|||
{
|
||||
"<leader>q",
|
||||
function()
|
||||
-- Custom close/quit
|
||||
-- Custom close/quituto
|
||||
--
|
||||
-- * if non empty buffer, we will simply open a new empty buffer unless
|
||||
-- it is in the close always list
|
||||
-- * if empty buffer, then we will quit this buffer
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
return {
|
||||
"Pocco81/auto-save.nvim",
|
||||
event = "BufEnter",
|
||||
opts = {
|
||||
execution_message = {
|
||||
message = function()
|
||||
return ""
|
||||
end,
|
||||
},
|
||||
trigger_events = { "InsertLeave", "TextChanged", "TextChangedI", "BufLeave" },
|
||||
condition = function(buf)
|
||||
local disallowed_filetypes = { "TelescopePrompt", "quickfix", "terminal" }
|
||||
local utils = require("auto-save.utils.data")
|
||||
if
|
||||
vim.fn.getbufvar(buf, "&modifiable") == 1
|
||||
and utils.not_in(vim.fn.getbufvar(buf, "&filetype"), disallowed_filetypes)
|
||||
then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
},
|
||||
}
|
|
@ -106,6 +106,10 @@ function M.table_contains(table, element)
|
|||
return false
|
||||
end
|
||||
|
||||
function M.table_not_contains(table, element)
|
||||
return not M.table_contains(table, element)
|
||||
end
|
||||
|
||||
-- From https://github.com/lukas-reineke/onedark.nvim/blob/master/lua/onedark.lua
|
||||
function M.highlight(group, options)
|
||||
local guifg = options.fg or "NONE"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue