Skip to content

feat: add nested option - #83

Open
dawidd6 wants to merge 1 commit into
okuuva:mainfrom
dawidd6:nested
Open

feat: add nested option#83
dawidd6 wants to merge 1 commit into
okuuva:mainfrom
dawidd6:nested

Conversation

@dawidd6

@dawidd6 dawidd6 commented Jul 25, 2026

Copy link
Copy Markdown

https://neovim.io/doc/user/autocmd/#autocmd-nested

This is very useful for people that want autocommands run when auto-saving. For example auto-format should work without any hassle when this option is turned on.

@primeapple

Copy link
Copy Markdown
Collaborator

Could you explain what problem you are trying to solve here? We have a section for autoformat already in the README.

@dawidd6

dawidd6 commented Jul 27, 2026

Copy link
Copy Markdown
Author

README instructions for autoformat are complicated and did not work for me at all. Also there are other autocmds that one would like to run on auto save, for example saving sops encrypted buffers. Nested autocmd easily ensures all on-save autocmds will run, without any special configuration needed.

If you think this feature isn't needed, then it's okay, no worries. I just think it might be useful for others like me, hence the PR.

@primeapple

Copy link
Copy Markdown
Collaborator

I see your point, but I don't get why it shouldn't work. It did the last time I tried but maybe something in neovim core might have changed.

Could you adjust the readme as well, especially the part with the autoformat instructions and how it would look like with your new setting? Could you try it out and maybe give us steps to reproduce? So that we can make sure there is an actual problem with autoformat?

@dawidd6

dawidd6 commented Jul 28, 2026

Copy link
Copy Markdown
Author

This is the config that does not work for me:

require("auto-save").setup({
	trigger_events = {
		defer_save = {},
		cancel_deferred_save = {},
	},
	condition = function(buf)
		return vim.api.nvim_get_mode().mode == "n" and vim.bo[buf].buftype == ""
	end,
})

I have confirmed that deferred save works just fine, buffer is formatted and saved, but I don't need deferred save and immediate auto save does not trigger autoformat. That's why nested = true is necessary.

@primeapple

primeapple commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

I wondered why it even worked so far. The reason is that we defer the save for defer_save events. That means it runs not in the autocommand, that means nested is not needed.

I honestly think the safest option is to set nested to true by default for the immediate_safe and defered_save autocommands. The cancel_defered_save one doesn't need it as it doesn't execute any important event.

What do you think @okuuva ? What is your opinion @dawidd6 ?

@dawidd6

dawidd6 commented Jul 29, 2026

Copy link
Copy Markdown
Author

Fine by me, but it might be a kind of breaking change for some. Maybe we should only set nested to true when noautocmd is false 馃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants