okuuva / auto-save.nvim

🧶 Automatically save your changes in NeoVim
GNU General Public License v3.0
151 stars 8 forks source link

auto saving with every change #39

Closed sameer1612 closed 9 months ago

sameer1612 commented 11 months ago

It is saving whenever I make any change in the buffer, (x, D, insert, etc). I just want it to save when current buffer gets hidden, as in being replaced by another file I open with telescope.

return {
  "okuuva/auto-save.nvim",
  opts = {
    enabled = true,
    execution_message = {
      enabled = true,
      message = function() -- message to print on save
        return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S"))
      end,
      dim = 0.18, -- dim the color of `message`
      cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea
    },
    trigger_events = {
      immediate_save = { "BufHidden" }, -- vim events that trigger an immediate save
      defer_save = {}, -- vim events that trigger a deferred save (saves after `debounce_delay`)
      cancel_defered_save = {}, -- 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 = true, -- write all buffers when the current one meets `condition`
    noautocmd = false, -- do not execute autocmds when saving
    debounce_delay = 0, -- 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,
  },
}
sameer1612 commented 11 months ago

@okuuva this is pretty much same configs as mentioned in the readme. can you please check the trigger events in my setup

okuuva commented 11 months ago

@sameer1612 I'll try to do some debugging tomorrow but I'd say you want BufLeave as the trigger event instead of BufHidden. You could also try setting defer_save and cancel_defer_save to nil instead of an empty table.

primeapple commented 11 months ago

I can not reproduce your problems @sameer1612, your setup works for me. Could you do a screencast with the debug window open? (tail -f ~/.cache/nvim/auto-save.log, with debug set to true?)

What is your version? (see lazy-lock.json file)

sameer1612 commented 11 months ago

I can not reproduce your problems @sameer1612, your setup works for me. Could you do a screencast with the debug window open? (tail -f ~/.cache/nvim/auto-save.log, with debug set to true?)

What is your version? (see lazy-lock.json file)

sure @primeapple . My requirement: I want my file to be saved whenever I move to some other buffer. (Not when my buffer content changes)

No logs found! (@okuuva I have your suggested changes and restarted as well)

image

From lazy lock file: "auto-save.nvim": { "branch": "main", "commit": "979b6c82f60cfa80f4cf437d77446d0ded0addf0" },

Screencast here:

https://youtu.be/DSxugLKsHEs

primeapple commented 11 months ago

Yeah, your problem is that you are still on the old fork. Lazy didn't recognize that, because the plugins names are the same. This should by brought up to https://github.com/folke/lazy.nvim

For now, what you can do is to comment out the entire auto-save.lua file, resync, check that the line in lazy-lock.json got deleted. Now readd it and it should fetch the right repository.

sameer1612 commented 11 months ago

Yeah, your problem is that you are still on the old fork. Lazy didn't recognize that, because the plugins names are the same. This should by brought up to https://github.com/folke/lazy.nvim

For now, what you can do is to comment out the entire auto-save.lua file, resync, check that the line in lazy-lock.json got deleted. Now readd it and it should fetch the right repository.

I tried your suggested steps. But, the lock file shows the latest commit from this repo.
"auto-save.nvim": { "branch": "main", "commit": "610e72307d675fcc15098c5a435ad89e45aaf855" } Commit hash checks out:

image
primeapple commented 11 months ago

Ok, so now you are on the correct commit. Before you had

"auto-save.nvim": { "branch": "main", "commit": "979b6c82f60cfa80f4cf437d77446d0ded0addf0" },

Please try if it works now.

sameer1612 commented 11 months ago

Ok, so now you are on the correct commit. Before you had

"auto-save.nvim": { "branch": "main", "commit": "979b6c82f60cfa80f4cf437d77446d0ded0addf0" },

Please try if it works now.

Negative. ☹️

primeapple commented 11 months ago

Does debugging work now?

okuuva commented 10 months ago

@sameer1612 One thing I spotted now in the config is that you have debounce_delay set to 0. That's known to cause some problems. Since you're only using immediate_save you can leave it to the default value of 1000.

alexgorbatchev commented 8 months ago

I'm having the same issue on neovim 0.9.5, the changes are saved immediately after exiting from edit mode or right after making a change (ie iabc<esc>) or navigating after a change (ddj). I'm using default config and lazyvim

[Wed Jan 10 09:59:33 2024] [/home/alex/.config/nvim/lua/plugins/example.lua] - Abort saving buffer
[Wed Jan 10 09:59:43 2024] [/home/alex/.config/nvim/lua/plugins/ide.lua] - Should save buffer
[Wed Jan 10 09:59:43 2024] [/home/alex/.config/nvim/lua/plugins/ide.lua] - Abort saving buffer
[Wed Jan 10 10:00:00 2024] [/home/alex/.config/nvim/lua/plugins/ide.lua] - Should save buffer
[Wed Jan 10 10:00:00 2024] [/home/alex/.config/nvim/lua/plugins/ide.lua] - Timer started
[Wed Jan 10 10:00:01 2024] [/home/alex/.config/nvim/lua/plugins/ide.lua] - Abort saving buffer
alexgorbatchev commented 8 months ago

nvm, realized that defer_save = { "InsertLeave", "TextChanged" } was my problem, changing it to {} got me desired results.