From 83e5e22298f4b34763fddafd741be50923ae02bb Mon Sep 17 00:00:00 2001 From: kdav5758 Date: Thu, 1 Jul 2021 18:52:00 -0500 Subject: [PATCH] only save if buffer is modifiable --- lua/autosave/modules/autocmds.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/autosave/modules/autocmds.lua b/lua/autosave/modules/autocmds.lua index a8bcfed..e0002e3 100644 --- a/lua/autosave/modules/autocmds.lua +++ b/lua/autosave/modules/autocmds.lua @@ -36,7 +36,9 @@ local function actual_save() end function M.do_save() - local cs_exists, cs_filetype = true, true + + -- cs = can save + local cs_exists, cs_filetype, cs_modifiable = true, true, true if not (next(opts["excluded_filetypes"]) == nil) then if (table_has_value(opts["excluded_filetypes"], api.nvim_eval([[&filetype]])) == true) then @@ -50,7 +52,11 @@ function M.do_save() end end - if (cs_exists == true and cs_filetype == true) then + if (api.nvim_eval([[&modifiable]]) == 0) then + cs_modifiable = false + end + + if (cs_exists == true and cs_filetype == true and cs_modifiable == true) then actual_save() end end