diff options
| author | Famiu Haque <famiuhaque@proton.me> | 2024-03-25 03:14:00 +0600 |
|---|---|---|
| committer | Lewis Russell <me@lewisr.dev> | 2024-03-26 20:56:42 +0000 |
| commit | de87197fdc3aa8123a060fc3a780e087c8e258ac (patch) | |
| tree | 202d0097c36178fe6565781789667fe8390a6eba /src/nvim/option.c | |
| parent | d3771e68a2a6be47a3ec158c9b0aff892a9038b9 (diff) | |
| download | rneovim-de87197fdc3aa8123a060fc3a780e087c8e258ac.tar.gz rneovim-de87197fdc3aa8123a060fc3a780e087c8e258ac.tar.bz2 rneovim-de87197fdc3aa8123a060fc3a780e087c8e258ac.zip | |
refactor(options): make `immutable` and `hidden` options distinct
Problem: Currently, the `immutable` property of options can be applied for options that are hidden and options whose value simply can't be changed. Which is problematic when attempting to convert an option like `'maxcombine'` into an immutable option, because trying to `:set` an immutable option currently gives an error, which is only desired behavior for hidden options, not options that are actually immutable.
Solution: Separate the `immutable` property into two distinct `hidden` and `immutable` properties. Change all options with the `immutable` property to use the `hidden` property instead. Also add `p_mco` as an `immutable` option, as its value cannot be changed, and the underlying variable is not used anywhere.
Diffstat (limited to 'src/nvim/option.c')
| -rw-r--r-- | src/nvim/option.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 73a5af5520..e4f32ebec4 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2898,8 +2898,6 @@ static const char *validate_num_option(OptIndex opt_idx, void *varp, OptInt *new } else if (value > p_wiw) { return e_winwidth; } - } else if (varp == &p_mco) { - *newval = MAX_MCO; } else if (varp == &p_titlelen) { if (value < 0) { return e_positive; @@ -3483,11 +3481,11 @@ static const char *did_set_option(OptIndex opt_idx, void *varp, OptVal old_value .os_win = curwin }; - if (direct) { - // Don't do any extra processing if setting directly. + if (direct || opt->immutable) { + // Don't do any extra processing if setting directly or if option is immutable. } - // Disallow changing immutable options. - else if (opt->immutable && !optval_equal(old_value, new_value)) { + // Disallow changing hidden options. + else if (opt->hidden && !optval_equal(old_value, new_value)) { errmsg = e_unsupportedoption; } // Disallow changing some options from secure mode. @@ -3511,8 +3509,9 @@ static const char *did_set_option(OptIndex opt_idx, void *varp, OptVal old_value restore_chartab = did_set_cb_args.os_restore_chartab; } - // If an error is detected, restore the previous value and don't do any further processing. - if (errmsg != NULL) { + // If option is immutable or if an error is detected, restore the previous value and don't do any + // further processing. + if (opt->immutable || errmsg != NULL) { set_option_varp(opt_idx, varp, old_value, true); // When resetting some values, need to act on it. if (restore_chartab) { @@ -4227,7 +4226,7 @@ static int optval_default(OptIndex opt_idx, void *varp) vimoption_T *opt = &options[opt_idx]; // Hidden or immutable options always use their default value. - if (varp == NULL || opt->immutable) { + if (varp == NULL || opt->hidden || opt->immutable) { return true; } |