auto-save.nvim icon indicating copy to clipboard operation
auto-save.nvim copied to clipboard

Feature request: set delay before autosaving

Open okuuva opened this issue 3 years ago • 3 comments

It would be nice to be able to set a delay before autosave is run after receiving trigger event.

Use case: I use tidy because cleaning up trailing whitespaces is a task best left to automation. Using tidy with auto-save.nvim makes pasting stuff from registers at the end of line / file hard because file is automatically saved (and thus cleaned of traling spaces / lines) immediately after exiting insert mode.

Setting debounce_delay doesn't help because if I understood it correctly it only prevents the same buffer getting saved multiple times during the given time frame and it still saves the buffer immediately if it hasn't already been saved during that time frame.

okuuva avatar Oct 09 '22 11:10 okuuva

I think I might be able to implement this with an autocommand that emits a custom event after a given delay when it receives a triggering event. If somebody has any better ideas I'm all ears.

okuuva avatar Oct 09 '22 11:10 okuuva

This is a problem with tidy, not auto-save. It should allow specifying the event that triggers it, but it's hardcoded:

https://github.com/mcauley-penney/tidy.nvim/blob/9b15a0eb12d6d4f0bb5c197c1f5b72bcc57f09ff/lua/tidy/init.lua#L49

vim.api.nvim_create_autocmd("BufWritePre", {

Ideally, we could get some sort of grouping mechanism for these "auto-whatever" plugins, but as a largely enthusiast group of authors, it's not easy to synchronize.

ehaynes99 avatar Nov 29 '22 04:11 ehaynes99

That is indeed a problem with tidy but I still think it would be nice to have a user specified delay before autosave. If nothing more it would act as a workaround for other auto-plugins with no configuration options.

okuuva avatar Nov 29 '22 07:11 okuuva