Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(autocmds): toggle format-on-save properly #2659

Merged
merged 1 commit into from Jun 6, 2022

Conversation

choplin
Copy link
Contributor

@choplin choplin commented May 26, 2022

Description

LvimToggleFormatOnSave can disable the format-on-save feature properly, but once the feature is disabled from the enabled state, this command cannot enable it again. This is because vim.api.nvim_get_autocmds returns an empty list after disabling the feature.

This commit checks the size of the returned autocmd list when M.toggle_format_on_save is called and enables the feature if the size is 0.

How Has This Been Tested?

Run LvimToggleFormatOnSave several times, and confirm that the code is automatically formatted after running LvimToggleFormatOnSave from the disabled state.

@kylo252
Copy link
Collaborator

kylo252 commented May 26, 2022

Good catch!

I think I originally wanted to delete the augroup itself, but that solution was flakey because I was getting errors about it still being in-use.

@choplin
Copy link
Contributor Author

choplin commented May 28, 2022

Should I fix the commit message to pass the lint-commits?

@kylo252
Copy link
Collaborator

kylo252 commented May 30, 2022

Should I fix the commit message to pass the lint-commits?

yes please

@kylo252 kylo252 changed the title Fix LvimToggleFormatOnSave not working properly fix(autocmds): toggle format-on-save properly May 30, 2022
`LvimToggleFormatOnSave` can disable the format-on-save feature properly, but once the feature
is disabled from the enabled state, this command cannot enable it again.
This is because `vim.api.nvim_get_autocmds` returns an empty list after disabling the feature.

This commit checks the size of the returned autocmd list when `M.toolge_format_on_save` is
called and enables the feature if the size is 0.
@choplin
Copy link
Contributor Author

choplin commented Jun 6, 2022

@kylo252 Revised the commit message and force-pushed. Could you please approve to run CI?

@kylo252
Copy link
Collaborator

kylo252 commented Jun 6, 2022

Thanks!

@kylo252 kylo252 merged commit f778a38 into LunarVim:rolling Jun 6, 2022
@choplin choplin deleted the patch-1 branch June 7, 2022 05:31
danielo515 pushed a commit to danielo515/LunarVim that referenced this pull request Jun 12, 2022
tomazursic pushed a commit to tomazursic/LunarVim that referenced this pull request Jun 12, 2022
* upstream/master:
  chore: update changelog
  chore: bump plugins version (LunarVim#2654)
  fix(autocmds): toggle format-on-save properly (LunarVim#2659)
  fix(nvimtree): update nvim-tree setup (LunarVim#2681)
  fix(log): add date to the timestamp of logs (LunarVim#2669)
  feat(cmp): add option to disable friendly-snippets (LunarVim#2660)
  feat: prompt when closing modified/term buffers (LunarVim#2658)
tomazursic pushed a commit to tomazursic/LunarVim that referenced this pull request Jun 12, 2022
* upstream/rolling:
  feat(which-key): added search command for colour highlights (LunarVim#2693)
  fix: skip calling nvim-tree.setup() more than once (LunarVim#2707)
  chore: bump plugins version (LunarVim#2654)
  fix(autocmds): toggle format-on-save properly (LunarVim#2659)
  fix(nvimtree): update nvim-tree setup (LunarVim#2681)
  fix(log): add date to the timestamp of logs (LunarVim#2669)
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.

None yet

2 participants