-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
base: master
Are you sure you want to change the base?
Conversation
a969bc7
to
e811ce4
Compare
vim._with
everywherevim._with
where possible
There was a problem hiding this 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?
|
This mostly means replacing `nvim_buf_call` and `nvim_win_call` with `vim._with`.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
This mostly means replacing
nvim_buf_call
andnvim_win_call
withvim._with
.