diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2021-12-04 14:30:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-04 14:30:27 -0700 |
commit | 1e6eeca9d1360554ee18525603e83c3a1999a622 (patch) | |
tree | 74bdad7d2506a0a93d112230fe9c3bf1f8652675 /src/nvim/option.c | |
parent | 222ef0c00d97aa2d5e17ca6b14aea037155595ee (diff) | |
parent | 71ac00ccb523383411b907b5fdf00a376e24a6f0 (diff) | |
download | rneovim-1e6eeca9d1360554ee18525603e83c3a1999a622.tar.gz rneovim-1e6eeca9d1360554ee18525603e83c3a1999a622.tar.bz2 rneovim-1e6eeca9d1360554ee18525603e83c3a1999a622.zip |
Merge pull request #15996 from gpanders/nvim_get_option_value
feat(api): add nvim_{get,set}_option_value
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r-- | src/nvim/option.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 45e2032b35..ee5f62d826 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4771,7 +4771,8 @@ static int findoption(const char *const arg) /// @param stringval NULL when only checking existence /// /// @returns: -/// Number or Toggle option: 1, *numval gets value. +/// Toggle option: 2, *numval gets value. +/// Number option: 1, *numval gets value. /// String option: 0, *stringval gets allocated string. /// Hidden Number or Toggle option: -1. /// hidden String option: -2. @@ -4804,16 +4805,18 @@ int get_option_value(const char *name, long *numval, char_u **stringval, int opt } if (options[opt_idx].flags & P_NUM) { *numval = *(long *)varp; + return 1; + } + + // Special case: 'modified' is b_changed, but we also want to consider + // it set when 'ff' or 'fenc' changed. + if ((int *)varp == &curbuf->b_changed) { + *numval = curbufIsChanged(); } else { - // Special case: 'modified' is b_changed, but we also want to consider - // it set when 'ff' or 'fenc' changed. - if ((int *)varp == &curbuf->b_changed) { - *numval = curbufIsChanged(); - } else { - *numval = (long)*(int *)varp; // NOLINT(whitespace/cast) - } + *numval = (long)*(int *)varp; // NOLINT(whitespace/cast) } - return 1; + + return 2; } // Returns the option attributes and its value. Unlike the above function it @@ -4909,7 +4912,7 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o // only getting a pointer, no need to use aucmd_prepbuf() curbuf = (buf_T *)from; curwin->w_buffer = curbuf; - varp = get_varp(p); + varp = get_varp_scope(p, OPT_LOCAL); curbuf = save_curbuf; curwin->w_buffer = curbuf; } @@ -4917,7 +4920,7 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o win_T *save_curwin = curwin; curwin = (win_T *)from; curbuf = curwin->w_buffer; - varp = get_varp(p); + varp = get_varp_scope(p, OPT_LOCAL); curwin = save_curwin; curbuf = curwin->w_buffer; } |