-
-
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
fix(api): make nil value in nvim_set_option_value clear local value #16710
Conversation
Does this work for global-local bool/number options? I e |
Thanks, forgot about these. These will need to be specially handled unfortunately, as they are in |
For special options such as 'undolevels' and 'scrolloff', this sets the local value to the special "unset" value (e.g. -12345 for 'undolevels').
da59081
to
246f080
Compare
src/nvim/api/vim.c
Outdated
rv = BOOLEAN_OBJ(numval); | ||
break; | ||
default: | ||
rv = INTEGER_OBJ(numval); |
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 suggest using NIL
to represent unset autoread
value.
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.
-1
is used in do_set()
:
Lines 1211 to 1218 in abb2b1a
// For 'autoread' -1 means to use global value. | |
if ((int *)varp == &curbuf->b_p_ar | |
&& opt_flags == OPT_LOCAL) { | |
value = -1; | |
} else { | |
value = *(int *)get_varp_scope(&(options[opt_idx]), | |
OPT_GLOBAL); | |
} |
:set autoread
:setl autoread<
:echo &l:autoread
-1
Shouldn't we try and keep the API version consistent with the Vim script version?
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.
what congruence? &l:autoread
always returns an integer value, never a bool, so already using booleans breaks that rule in that case. vim script cannot change it to neither v:true
/ v:false
nor v:null
due to backwards compatibility, while I think API functions should use API types whenever possible/reasonable.
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.
Ok done.
yes please, if we can make the API return bools instead of ints, that would be GREAT for the common case of: if not vim.opt.xyz:get() then do_something() end where |
Backport failed for Please cherry-pick the changes locally. git fetch origin release-0.6
git worktree add -d .worktree/backport-16710-to-release-0.6 origin/release-0.6
cd .worktree/backport-16710-to-release-0.6
git checkout -b backport-16710-to-release-0.6
ancref=$(git merge-base b42e0c40c8b8e906eccb14db0d0648a39e49c363 e5e7834e88db9fecad00565fb59ba1a6a7cc1c8b)
git cherry-pick -x $ancref..e5e7834e88db9fecad00565fb59ba1a6a7cc1c8b |
Ah, this shouldn't be backported since #15996 was not backported. |
Fix a bug in
nvim_set_option_value
that would set number and boolean optionsto
0
orfalse
respectively when passingnil
as the value. A value ofnil
should instead clear the local value, which has different meanings fordifferent option types:
String options: set the local value to the empty string (
""
) which has theeffect of using the global value of the option for global-local options.
Number and boolean options: set the local value to the global value.
TODO:
autoread
,scrolloff
,undolevels
)