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

refactor: use vim._with where possible #29244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dundargoc
Copy link
Member

@dundargoc dundargoc commented Jun 8, 2024

This mostly means replacing nvim_buf_call and nvim_win_call with
vim._with.

@github-actions github-actions bot added the refactor changes that are not features or bugfixes label Jun 8, 2024
@dundargoc dundargoc removed lsp treesitter diagnostic filetype filetype detection, filetype.lua snippet labels Jun 8, 2024
@dundargoc dundargoc force-pushed the refactor/with branch 2 times, most recently from a969bc7 to e811ce4 Compare June 8, 2024 21:19
@dundargoc dundargoc changed the title refactor: use vim._with everywhere refactor: use vim._with where possible Jun 8, 2024
Copy link
Member

@justinmk justinmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have (explicit) tests that verify that options/etc are restored even when f() throws an error?

@dundargoc
Copy link
Member Author

Do we have (explicit) tests that verify that options/etc are restored even when f() throws an error?

#29280

This mostly means replacing `nvim_buf_call` and `nvim_win_call` with
`vim._with`.
@dundargoc dundargoc marked this pull request as ready for review June 26, 2024 15:24
vim.cmd [[set isfname+=@-@]]
local url = vim.fn.expand('<cfile>')
vim.o.isfname = old_isfname
local url = vim._with({ o = { isfname = vim.o.isfname .. ',@-@' } }, function()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend using more targeted scopes for options. As isfname is global option, I'd use go instead of o.
It seems to make code more explicit while avoiding extra step in implementation that decided which scope should be used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's more correct. If isfname becomes global-local in the future, won't vim.go be incorrect (since we're changing the default/global value rather than the value of the buffer)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 'isfname' scopes are changed, then using bo or wo here will be better. Right now this option is sensible to be used with go, as its scope is global. Using o as scope here will only lead to more work done during this function execution with the same result as go.

That said, It is not particularly strong opinion per se.

test/functional/autocmd/autocmd_spec.lua Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor changes that are not features or bugfixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants