diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-11-25 19:15:05 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-11-25 19:27:38 +0000 |
commit | c5d770d311841ea5230426cc4c868e8db27300a8 (patch) | |
tree | dd21f70127b4b8b5f109baefc8ecc5016f507c91 /src/nvim/optionstr.c | |
parent | 9be89f131f87608f224f0ee06d199fcd09d32176 (diff) | |
parent | 081beb3659bd6d8efc3e977a160b1e72becbd8a2 (diff) | |
download | rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.gz rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.bz2 rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.zip |
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'src/nvim/optionstr.c')
-rw-r--r-- | src/nvim/optionstr.c | 101 |
1 files changed, 76 insertions, 25 deletions
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index c8f19d7ccf..bfb26a0be6 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -72,8 +72,9 @@ static char *(p_ambw_values[]) = { "single", "double", NULL }; static char *(p_bg_values[]) = { "light", "dark", NULL }; static char *(p_bkc_values[]) = { "yes", "auto", "no", "breaksymlink", "breakhardlink", NULL }; static char *(p_bo_values[]) = { "all", "backspace", "cursor", "complete", "copy", "ctrlg", "error", - "esc", "ex", "hangul", "lang", "mess", "showmatch", "operator", - "register", "shell", "spell", "wildmode", NULL }; + "esc", "ex", "hangul", "insertmode", "lang", "mess", "showmatch", + "operator", "register", "shell", "spell", "term", "wildmode", + NULL }; // Note: Keep this in sync with briopt_check() static char *(p_briopt_values[]) = { "shift:", "min:", "sbr", "list:", "column:", NULL }; // Note: Keep this in sync with diffopt_changed() @@ -83,7 +84,7 @@ static char *(p_dip_values[]) = { "filler", "context:", "iblank", "icase", "indent-heuristic", "linematch:", "algorithm:", NULL }; static char *(p_dip_algorithm_values[]) = { "myers", "minimal", "patience", "histogram", NULL }; static char *(p_nf_values[]) = { "bin", "octal", "hex", "alpha", "unsigned", "blank", NULL }; -static char *(p_ff_values[]) = { FF_UNIX, FF_DOS, FF_MAC, NULL }; +static char *(p_ff_values[]) = { "unix", "dos", "mac", NULL }; static char *(p_cb_values[]) = { "unnamed", "unnamedplus", NULL }; static char *(p_cmp_values[]) = { "internal", "keepascii", NULL }; // Note: Keep this in sync with fill_culopt_flags() @@ -234,6 +235,7 @@ void check_buf_options(buf_T *buf) check_string_option(&buf->b_p_ep); check_string_option(&buf->b_p_path); check_string_option(&buf->b_p_tags); + check_string_option(&buf->b_p_ffu); check_string_option(&buf->b_p_tfu); check_string_option(&buf->b_p_tc); check_string_option(&buf->b_p_dict); @@ -249,7 +251,6 @@ void check_buf_options(buf_T *buf) /// Free the string allocated for an option. /// Checks for the string being empty_string_option. This may happen if we're out of memory, /// xstrdup() returned NULL, which was replaced by empty_string_option by check_options(). -/// Does NOT check for P_ALLOCED flag! void free_string_option(char *p) { if (p != empty_string_option) { @@ -282,15 +283,27 @@ static bool valid_filetype(const char *val) /// Handle setting 'signcolumn' for value 'val'. Store minimum and maximum width. /// +/// @param wcl when NULL: use "wp->w_p_scl" +/// @param wp when NULL: only parse "scl" +/// /// @return OK when the value is valid, FAIL otherwise -int check_signcolumn(win_T *wp) +int check_signcolumn(char *scl, win_T *wp) { - char *val = wp->w_p_scl; + char *val = empty_string_option; + if (scl != NULL) { + val = scl; + } else if (wp != NULL) { + val = wp->w_p_scl; + } + if (*val == NUL) { return FAIL; } if (check_opt_strings(val, p_scl_values, false) == OK) { + if (wp == NULL) { + return OK; + } if (!strncmp(val, "no", 2)) { // no wp->w_minscwidth = wp->w_maxscwidth = SCL_NO; } else if (!strncmp(val, "nu", 2) && (wp->w_p_nu || wp->w_p_rnu)) { // number @@ -320,6 +333,9 @@ int check_signcolumn(win_T *wp) if (min < 1 || max < 2 || min > 8 || min >= max) { return FAIL; } + if (wp == NULL) { + return OK; + } wp->w_minscwidth = min; wp->w_maxscwidth = max; } @@ -404,9 +420,9 @@ const char *check_stl_option(char *s) /// often illegal in a file name. Be more permissive if "secure" is off. bool check_illegal_path_names(char *val, uint32_t flags) { - return (((flags & P_NFNAME) + return (((flags & kOptFlagNFname) && strpbrk(val, (secure ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL) - || ((flags & P_NDNAME) + || ((flags & kOptFlagNDname) && strpbrk(val, "*?[|;&<>\r\n") != NULL)); } @@ -639,6 +655,9 @@ const char *did_set_backupcopy(optset_T *args) if (opt_flags & OPT_LOCAL) { bkc = buf->b_p_bkc; flags = &buf->b_bkc_flags; + } else if (!(opt_flags & OPT_GLOBAL)) { + // When using :set, clear the local flags. + buf->b_bkc_flags = 0; } if ((opt_flags & OPT_LOCAL) && *bkc == NUL) { @@ -716,11 +735,14 @@ const char *did_set_breakat(optset_T *args FUNC_ATTR_UNUSED) const char *did_set_breakindentopt(optset_T *args) { win_T *win = (win_T *)args->os_win; - if (briopt_check(win) == FAIL) { + char **varp = (char **)args->os_varp; + + if (briopt_check(*varp, varp == &win->w_p_briopt ? win : NULL) == FAIL) { return e_invarg; } + // list setting requires a redraw - if (win == curwin && win->w_briopt_list) { + if (varp == &win->w_p_briopt && win->w_briopt_list) { redraw_all_later(UPD_NOT_VALID); } @@ -870,10 +892,11 @@ int expand_set_chars_option(optexpand_T *args, int *numMatches, char ***matches) } /// The 'cinoptions' option is changed. -const char *did_set_cinoptions(optset_T *args FUNC_ATTR_UNUSED) +const char *did_set_cinoptions(optset_T *args) { + buf_T *buf = (buf_T *)args->os_buf; // TODO(vim): recognize errors - parse_cino(curbuf); + parse_cino(buf); return NULL; } @@ -897,7 +920,8 @@ int expand_set_clipboard(optexpand_T *args, int *numMatches, char ***matches) const char *did_set_colorcolumn(optset_T *args) { win_T *win = (win_T *)args->os_win; - return check_colorcolumn(win); + char **varp = (char **)args->os_varp; + return check_colorcolumn(*varp, varp == &win->w_p_cc ? win : NULL); } /// The 'comments' option is changed. @@ -1050,6 +1074,9 @@ const char *did_set_completeopt(optset_T *args FUNC_ATTR_UNUSED) if (args->os_flags & OPT_LOCAL) { cot = buf->b_p_cot; flags = &buf->b_cot_flags; + } else if (!(args->os_flags & OPT_GLOBAL)) { + // When using :set, clear the local flags. + buf->b_cot_flags = 0; } if (check_opt_strings(cot, p_cot_values, true) != OK) { @@ -1358,7 +1385,7 @@ const char *did_set_filetype_or_syntax(optset_T *args) args->os_value_changed = strcmp(args->os_oldval.string.data, *varp) != 0; - // Since we check the value, there is no need to set P_INSECURE, + // Since we check the value, there is no need to set kOptFlagInsecure, // even when the value comes from a modeline. args->os_value_checked = true; @@ -1447,8 +1474,7 @@ const char *did_set_foldmethod(optset_T *args) { win_T *win = (win_T *)args->os_win; char **varp = (char **)args->os_varp; - if (check_opt_strings(*varp, p_fdm_values, false) != OK - || *win->w_p_fdm == NUL) { + if (check_opt_strings(*varp, p_fdm_values, false) != OK || **varp == NUL) { return e_invarg; } foldUpdateAll(win); @@ -1572,12 +1598,28 @@ int expand_set_inccommand(optexpand_T *args, int *numMatches, char ***matches) matches); } +/// The 'iskeyword' option is changed. +const char *did_set_iskeyword(optset_T *args) +{ + char **varp = (char **)args->os_varp; + + if (varp == &p_isk) { // only check for global-value + if (check_isopt(*varp) == FAIL) { + return e_invarg; + } + } else { // fallthrough for local-value + return did_set_isopt(args); + } + + return NULL; +} + /// The 'isident' or the 'iskeyword' or the 'isprint' or the 'isfname' option is /// changed. const char *did_set_isopt(optset_T *args) { buf_T *buf = (buf_T *)args->os_buf; - // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[] + // 'isident', 'iskeyword', 'isprint' or 'isfname' option: refill g_chartab[] // If the new option is invalid, use old value. // 'lisp' option: refill g_chartab[] for '-' char if (buf_init_chartab(buf, true) == FAIL) { @@ -1624,7 +1666,7 @@ const char *did_set_keymap(optset_T *args) secure = secure_save; - // Since we check the value, there is no need to set P_INSECURE, + // Since we check the value, there is no need to set kOptFlagInsecure, // even when the value comes from a modeline. args->os_value_checked = true; @@ -2079,8 +2121,9 @@ int expand_set_showcmdloc(optexpand_T *args, int *numMatches, char ***matches) const char *did_set_signcolumn(optset_T *args) { win_T *win = (win_T *)args->os_win; + char **varp = (char **)args->os_varp; const char *oldval = args->os_oldval.string.data; - if (check_signcolumn(win) != OK) { + if (check_signcolumn(*varp, varp == &win->w_p_scl ? win : NULL) != OK) { return e_invarg; } // When changing the 'signcolumn' to or from 'number', recompute the @@ -2115,10 +2158,10 @@ const char *did_set_spellfile(optset_T *args) // When there is a window for this buffer in which 'spell' // is set load the wordlists. - if ((!valid_spellfile(*varp))) { + if (!valid_spellfile(*varp)) { return e_invarg; } - return did_set_spell_option(true); + return did_set_spell_option(); } /// The 'spelllang' option is changed. @@ -2131,15 +2174,22 @@ const char *did_set_spelllang(optset_T *args) if (!valid_spelllang(*varp)) { return e_invarg; } - return did_set_spell_option(false); + return did_set_spell_option(); } /// The 'spelloptions' option is changed. const char *did_set_spelloptions(optset_T *args) { win_T *win = (win_T *)args->os_win; - if (opt_strings_flags(win->w_s->b_p_spo, p_spo_values, &(win->w_s->b_p_spo_flags), - true) != OK) { + int opt_flags = args->os_flags; + const char *val = args->os_newval.string.data; + + if (!(opt_flags & OPT_LOCAL) + && opt_strings_flags(val, p_spo_values, &spo_flags, true) != OK) { + return e_invarg; + } + if (!(opt_flags & OPT_GLOBAL) + && opt_strings_flags(val, p_spo_values, &win->w_s->b_p_spo_flags, true) != OK) { return e_invarg; } return NULL; @@ -2541,7 +2591,8 @@ const char *did_set_winbar(optset_T *args) const char *did_set_winhighlight(optset_T *args) { win_T *win = (win_T *)args->os_win; - if (!parse_winhl_opt(win)) { + char **varp = (char **)args->os_varp; + if (!parse_winhl_opt(*varp, varp == &win->w_p_winhl ? win : NULL)) { return e_invarg; } return NULL; |