From 2bed0d1d978b42184564201088ea5fef12ec8581 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 22 Aug 2022 13:56:50 +0800 Subject: vim-patch:8.2.4753: error from setting an option is silently ignored (#19888) Problem: Error from setting an option is silently ignored. Solution: Handle option value errors better. Fix uses of N_(). https://github.com/vim/vim/commit/31e5c60a682840959cae6273ccadd9aae48c928d --- src/nvim/option.c | 57 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 17 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 5c487a7c62..0cf5b4bddf 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -91,6 +91,19 @@ #include "nvim/os/input.h" #include "nvim/os/lang.h" +static char e_unknown_option[] + = N_("E518: Unknown option"); +static char e_not_allowed_in_modeline[] + = N_("E520: Not allowed in a modeline"); +static char e_not_allowed_in_modeline_when_modelineexpr_is_off[] + = N_("E992: Not allowed in a modeline when 'modelineexpr' is off"); +static char e_key_code_not_set[] + = N_("E846: Key code not set"); +static char e_number_required_after_equal[] + = N_("E521: Number required after ="); +static char e_preview_window_already_exists[] + = N_("E590: A preview window already exists"); + /* * The options that are local to a window or buffer have "indir" set to one of * these values. Special values: @@ -404,7 +417,7 @@ void set_init_1(bool clean_arg) // NOTE: mlterm's author is being asked to 'set' a variable // instead of an environment variable due to inheritance. if (os_env_exists("MLTERM")) { - set_option_value("tbidi", 1L, NULL, 0); + set_option_value_give_err("tbidi", 1L, NULL, 0); } didset_options2(); @@ -915,7 +928,7 @@ int do_set(char *arg, int opt_flags) nextchar = (uint8_t)arg[len]; if (opt_idx == -1 && key == 0) { // found a mismatch: skip - errmsg = N_("E518: Unknown option"); + errmsg = e_unknown_option; goto skip; } @@ -926,7 +939,7 @@ int do_set(char *arg, int opt_flags) if (vim_strchr("=:!&<", nextchar) == NULL && (!(options[opt_idx].flags & P_BOOL) || nextchar == '?')) { - errmsg = _(e_unsupportedoption); + errmsg = e_unsupportedoption; } goto skip; } @@ -953,11 +966,11 @@ int do_set(char *arg, int opt_flags) // Disallow changing some options from modelines. if (opt_flags & OPT_MODELINE) { if (flags & (P_SECURE | P_NO_ML)) { - errmsg = N_("E520: Not allowed in a modeline"); + errmsg = e_not_allowed_in_modeline; goto skip; } if ((flags & P_MLE) && !p_mle) { - errmsg = N_("E992: Not allowed in a modeline when 'modelineexpr' is off"); + errmsg = e_not_allowed_in_modeline_when_modelineexpr_is_off; goto skip; } // In diff mode some options are overruled. This avoids that @@ -1025,7 +1038,7 @@ int do_set(char *arg, int opt_flags) } } } else { - errmsg = N_("E846: Key code not set"); + errmsg = e_key_code_not_set; goto skip; } if (nextchar != '?' @@ -1118,11 +1131,11 @@ int do_set(char *arg, int opt_flags) // Allow negative, octal and hex numbers. vim_str2nr((char_u *)arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, true); if (i == 0 || (arg[i] != NUL && !ascii_iswhite(arg[i]))) { - errmsg = N_("E521: Number required after ="); + errmsg = e_number_required_after_equal; goto skip; } } else { - errmsg = N_("E521: Number required after ="); + errmsg = e_number_required_after_equal; goto skip; } @@ -1971,6 +1984,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va { int old_value = *(int *)varp; int old_global_value = 0; + char *errmsg = NULL; // Disallow changing some options from secure mode if ((secure || sandbox != 0) @@ -2092,7 +2106,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va FOR_ALL_WINDOWS_IN_TAB(win, curtab) { if (win->w_p_pvw && win != curwin) { curwin->w_p_pvw = false; - return N_("E590: A preview window already exists"); + return e_preview_window_already_exists; } } } @@ -2151,10 +2165,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va } } else if ((int *)varp == &curwin->w_p_spell) { // 'spell' if (curwin->w_p_spell) { - char *errmsg = did_set_spelllang(curwin); - if (errmsg != NULL) { - emsg(_(errmsg)); - } + errmsg = did_set_spelllang(curwin); } } @@ -2191,7 +2202,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va p_deco = true; // Force-set the necessary keymap for arabic. - set_option_value("keymap", 0L, "arabic", OPT_LOCAL); + errmsg = set_option_value("keymap", 0L, "arabic", OPT_LOCAL); } else { /* * 'arabic' is reset, handle various sub-settings. @@ -2271,7 +2282,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va } check_redraw(options[opt_idx].flags); - return NULL; + return errmsg; } /// Set the value of a number option, taking care of side effects @@ -2898,7 +2909,7 @@ void set_tty_background(const char *value) ? "autocmd VimEnter * ++once ++nested set bg=light" : "autocmd VimEnter * ++once ++nested set bg=dark"); } else { - set_option_value("bg", 0L, value, 0); + set_option_value_give_err("bg", 0L, value, 0); reset_option_was_set("bg"); } } @@ -3147,7 +3158,7 @@ bool is_hidden_option(int opt_idx) /// is cleared (the exact semantics of this depend /// on the option). /// -/// @return NULL on success, error message on error. +/// @return NULL on success, an untranslated error message on error. char *set_option_value(const char *const name, const long number, const char *const string, const int opt_flags) FUNC_ATTR_NONNULL_ARG(1) @@ -3217,6 +3228,18 @@ char *set_option_value(const char *const name, const long number, const char *co return NULL; } +/// Call set_option_value() and when an error is returned report it. +/// +/// @param opt_flags OPT_LOCAL or 0 (both) +void set_option_value_give_err(const char *name, long number, const char *string, int opt_flags) +{ + char *errmsg = set_option_value(name, number, string, opt_flags); + + if (errmsg != NULL) { + emsg(_(errmsg)); + } +} + /// Return true if "name" is a string option. /// Returns false if option "name" does not exist. bool is_string_option(const char *name) -- cgit From 6cc6e11929ad76a2dc5204aed95cb9ed1dafde23 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 23 Aug 2022 22:00:19 +0800 Subject: vim-patch:9.0.0206: redraw flags are not named specifically (#19913) Problem: Redraw flags are not named specifically. Solution: Prefix "UPD_" to the flags, for UPDate_screen(). https://github.com/vim/vim/commit/a4d158b3c839e96ed98ff87c7b7124ff4518c4ff --- src/nvim/option.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 0cf5b4bddf..b1d5be8cb7 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -847,7 +847,7 @@ int do_set(char *arg, int opt_flags) didset_options(); didset_options2(); ui_refresh_options(); - redraw_all_later(CLEAR); + redraw_all_later(UPD_CLEAR); } else { showoptions(1, opt_flags); did_show = true; @@ -2089,7 +2089,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va paste_option_changed(); } else if ((int *)varp == &p_ic && p_hls) { // when 'ignorecase' is set or reset and 'hlsearch' is set, redraw - redraw_all_later(SOME_VALID); + redraw_all_later(UPD_SOME_VALID); } else if ((int *)varp == &p_hls) { // when 'hlsearch' is set or reset: reset no_hlsearch set_no_hlsearch(false); @@ -2184,7 +2184,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va // Enable Arabic shaping (major part of what Arabic requires) if (!p_arshape) { p_arshape = true; - redraw_all_later(NOT_VALID); + redraw_all_later(UPD_NOT_VALID); } } @@ -2741,15 +2741,15 @@ void check_redraw(uint32_t flags) changed_window_setting(); } if (flags & P_RBUF) { - redraw_curbuf_later(NOT_VALID); + redraw_curbuf_later(UPD_NOT_VALID); } if (flags & P_RWINONLY) { - redraw_later(curwin, NOT_VALID); + redraw_later(curwin, UPD_NOT_VALID); } if (doclear) { - redraw_all_later(CLEAR); + redraw_all_later(UPD_CLEAR); } else if (all) { - redraw_all_later(NOT_VALID); + redraw_all_later(UPD_NOT_VALID); } } @@ -3817,12 +3817,12 @@ void unset_global_local_option(char *name, void *from) case PV_LCS: clear_string_option(&((win_T *)from)->w_p_lcs); set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs, true); - redraw_later((win_T *)from, NOT_VALID); + redraw_later((win_T *)from, UPD_NOT_VALID); break; case PV_FCS: clear_string_option(&((win_T *)from)->w_p_fcs); set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs, true); - redraw_later((win_T *)from, NOT_VALID); + redraw_later((win_T *)from, UPD_NOT_VALID); break; case PV_VE: clear_string_option(&((win_T *)from)->w_p_ve); -- cgit From 40855b0143a864739a6037921e15699445dcf8a7 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Sun, 31 Jul 2022 16:20:57 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 206 ++++++++++++++++++++++++++---------------------------- 1 file changed, 101 insertions(+), 105 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index b1d5be8cb7..b2525b73a0 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -464,7 +464,7 @@ static void set_option_default(int opt_idx, int opt_flags) (char *)options[opt_idx].def_val, opt_flags, 0); } else { if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) { - free_string_option(*(char_u **)(varp)); + free_string_option(*(char **)(varp)); } *(char_u **)varp = options[opt_idx].def_val; options[opt_idx].flags &= ~P_ALLOCED; @@ -603,14 +603,14 @@ void free_all_options(void) if (options[i].indir == PV_NONE) { // global option: free value and default value. if ((options[i].flags & P_ALLOCED) && options[i].var != NULL) { - free_string_option(*(char_u **)options[i].var); + free_string_option(*(char **)options[i].var); } if (options[i].flags & P_DEF_ALLOCED) { - free_string_option(options[i].def_val); + free_string_option((char *)options[i].def_val); } } else if (options[i].var != VAR_WIN && (options[i].flags & P_STRING)) { // buffer-local option: free global value - clear_string_option((char_u **)options[i].var); + clear_string_option((char **)options[i].var); } } free_operatorfunc_option(); @@ -730,7 +730,7 @@ void set_helplang_default(const char *lang) int idx = findoption("hlg"); if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) { if (options[idx].flags & P_ALLOCED) { - free_string_option(p_hlg); + free_string_option((char *)p_hlg); } p_hlg = (char_u *)xmemdupz(lang, lang_len); // zh_CN becomes "cn", zh_TW becomes "tw". @@ -1185,7 +1185,7 @@ int do_set(char *arg, int opt_flags) // A global-local string option might have an empty // option as value to indicate that the global // value should be used. - if (((int)options[opt_idx].indir & PV_BOTH) && origval_l == empty_option) { + if (((int)options[opt_idx].indir & PV_BOTH) && origval_l == (char_u *)empty_option) { origval_l = origval_g; } } @@ -1205,7 +1205,7 @@ int do_set(char *arg, int opt_flags) // required when an environment variable was set // later if (newval == NULL) { - newval = empty_option; + newval = (char_u *)empty_option; } else if (!(options[opt_idx].flags & P_NO_DEF_EXP)) { s = option_expand(opt_idx, newval); if (s == NULL) { @@ -1233,7 +1233,7 @@ int do_set(char *arg, int opt_flags) i = getdigits_int((char **)varp, true, 0); switch (i) { case 0: - *(char_u **)varp = empty_option; + *(char **)varp = empty_option; break; case 1: *(char_u **)varp = vim_strsave((char_u *)"indent,eol"); @@ -1797,17 +1797,17 @@ static void didset_options2(void) highlight_changed(); // Parse default for 'fillchars'. - (void)set_chars_option(curwin, &curwin->w_p_fcs, true); + (void)set_chars_option(curwin, (char_u **)&curwin->w_p_fcs, true); // Parse default for 'listchars'. - (void)set_chars_option(curwin, &curwin->w_p_lcs, true); + (void)set_chars_option(curwin, (char_u **)&curwin->w_p_lcs, true); // Parse default for 'wildmode'. check_opt_wim(); xfree(curbuf->b_p_vsts_array); - (void)tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array); + (void)tabstop_set((char_u *)curbuf->b_p_vsts, &curbuf->b_p_vsts_array); xfree(curbuf->b_p_vts_array); - (void)tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array); + (void)tabstop_set((char_u *)curbuf->b_p_vts, &curbuf->b_p_vts_array); } /// Check for string options that are NULL (normally only termcap options). @@ -1817,7 +1817,7 @@ void check_options(void) for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) { if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL) { - check_string_option((char_u **)get_varp(&(options[opt_idx]))); + check_string_option((char **)get_varp(&(options[opt_idx]))); } } } @@ -3597,12 +3597,12 @@ int makeset(FILE *fd, int opt_flags, int local_only) /// 'sessionoptions' or 'viewoptions' contains "folds" but not "options". int makefoldset(FILE *fd) { - if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL - || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0) + if (put_setstring(fd, "setlocal", "fdm", (char_u **)&curwin->w_p_fdm, 0) == FAIL + || put_setstring(fd, "setlocal", "fde", (char_u **)&curwin->w_p_fde, 0) == FAIL - || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0) + || put_setstring(fd, "setlocal", "fmr", (char_u **)&curwin->w_p_fmr, 0) == FAIL - || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0) + || put_setstring(fd, "setlocal", "fdi", (char_u **)&curwin->w_p_fdi, 0) == FAIL || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL @@ -3803,7 +3803,7 @@ void unset_global_local_option(char *name, void *from) clear_string_option(&((win_T *)from)->w_p_stl); break; case PV_WBR: - clear_string_option((char_u **)&((win_T *)from)->w_p_wbr); + clear_string_option(&((win_T *)from)->w_p_wbr); break; case PV_UL: buf->b_p_ul = NO_LOCAL_UNDOLEVEL; @@ -3816,12 +3816,12 @@ void unset_global_local_option(char *name, void *from) break; case PV_LCS: clear_string_option(&((win_T *)from)->w_p_lcs); - set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs, true); + set_chars_option((win_T *)from, (char_u **)&((win_T *)from)->w_p_lcs, true); redraw_later((win_T *)from, UPD_NOT_VALID); break; case PV_FCS: clear_string_option(&((win_T *)from)->w_p_fcs); - set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs, true); + set_chars_option((win_T *)from, (char_u **)&((win_T *)from)->w_p_fcs, true); redraw_later((win_T *)from, UPD_NOT_VALID); break; case PV_VE: @@ -4238,7 +4238,7 @@ char_u *get_equalprg(void) if (*curbuf->b_p_ep == NUL) { return p_ep; } - return curbuf->b_p_ep; + return (char_u *)curbuf->b_p_ep; } /// Copy options from one window to another. @@ -4260,19 +4260,19 @@ void copy_winopt(winopt_T *from, winopt_T *to) to->wo_list = from->wo_list; to->wo_nu = from->wo_nu; to->wo_rnu = from->wo_rnu; - to->wo_ve = vim_strsave(from->wo_ve); + to->wo_ve = xstrdup(from->wo_ve); to->wo_ve_flags = from->wo_ve_flags; to->wo_nuw = from->wo_nuw; to->wo_rl = from->wo_rl; - to->wo_rlc = vim_strsave(from->wo_rlc); - to->wo_sbr = vim_strsave(from->wo_sbr); - to->wo_stl = vim_strsave(from->wo_stl); + to->wo_rlc = xstrdup(from->wo_rlc); + to->wo_sbr = xstrdup(from->wo_sbr); + to->wo_stl = xstrdup(from->wo_stl); to->wo_wbr = xstrdup(from->wo_wbr); to->wo_wrap = from->wo_wrap; to->wo_wrap_save = from->wo_wrap_save; to->wo_lbr = from->wo_lbr; to->wo_bri = from->wo_bri; - to->wo_briopt = vim_strsave(from->wo_briopt); + to->wo_briopt = xstrdup(from->wo_briopt); to->wo_scb = from->wo_scb; to->wo_scb_save = from->wo_scb_save; to->wo_crb = from->wo_crb; @@ -4280,32 +4280,30 @@ void copy_winopt(winopt_T *from, winopt_T *to) to->wo_spell = from->wo_spell; to->wo_cuc = from->wo_cuc; to->wo_cul = from->wo_cul; - to->wo_culopt = vim_strsave(from->wo_culopt); - to->wo_cc = vim_strsave(from->wo_cc); + to->wo_culopt = xstrdup(from->wo_culopt); + to->wo_cc = xstrdup(from->wo_cc); to->wo_diff = from->wo_diff; to->wo_diff_saved = from->wo_diff_saved; - to->wo_cocu = vim_strsave(from->wo_cocu); + to->wo_cocu = xstrdup(from->wo_cocu); to->wo_cole = from->wo_cole; - to->wo_fdc = vim_strsave(from->wo_fdc); - to->wo_fdc_save = from->wo_diff_saved - ? vim_strsave(from->wo_fdc_save) : empty_option; + to->wo_fdc = xstrdup(from->wo_fdc); + to->wo_fdc_save = from->wo_diff_saved ? xstrdup(from->wo_fdc_save) : empty_option; to->wo_fen = from->wo_fen; to->wo_fen_save = from->wo_fen_save; - to->wo_fdi = vim_strsave(from->wo_fdi); + to->wo_fdi = xstrdup(from->wo_fdi); to->wo_fml = from->wo_fml; to->wo_fdl = from->wo_fdl; to->wo_fdl_save = from->wo_fdl_save; - to->wo_fdm = vim_strsave(from->wo_fdm); - to->wo_fdm_save = from->wo_diff_saved - ? vim_strsave(from->wo_fdm_save) : empty_option; + to->wo_fdm = xstrdup(from->wo_fdm); + to->wo_fdm_save = from->wo_diff_saved ? xstrdup(from->wo_fdm_save) : empty_option; to->wo_fdn = from->wo_fdn; - to->wo_fde = vim_strsave(from->wo_fde); - to->wo_fdt = vim_strsave(from->wo_fdt); - to->wo_fmr = vim_strsave(from->wo_fmr); - to->wo_scl = vim_strsave(from->wo_scl); - to->wo_winhl = vim_strsave(from->wo_winhl); - to->wo_fcs = vim_strsave(from->wo_fcs); - to->wo_lcs = vim_strsave(from->wo_lcs); + to->wo_fde = xstrdup(from->wo_fde); + to->wo_fdt = xstrdup(from->wo_fdt); + to->wo_fmr = xstrdup(from->wo_fmr); + to->wo_scl = xstrdup(from->wo_scl); + to->wo_winhl = xstrdup(from->wo_winhl); + to->wo_fcs = xstrdup(from->wo_fcs); + to->wo_lcs = xstrdup(from->wo_lcs); to->wo_winbl = from->wo_winbl; // Copy the script context so that we know were the value was last set. @@ -4343,7 +4341,7 @@ static void check_winopt(winopt_T *wop) check_string_option(&wop->wo_fcs); check_string_option(&wop->wo_lcs); check_string_option(&wop->wo_ve); - check_string_option((char_u **)&wop->wo_wbr); + check_string_option(&wop->wo_wbr); } /// Free the allocated memory inside a winopt_T. @@ -4369,7 +4367,7 @@ void clear_winopt(winopt_T *wop) clear_string_option(&wop->wo_fcs); clear_string_option(&wop->wo_lcs); clear_string_option(&wop->wo_ve); - clear_string_option((char_u **)&wop->wo_wbr); + clear_string_option(&wop->wo_wbr); } void didset_window_options(win_T *wp, bool valid_cursor) @@ -4377,8 +4375,8 @@ void didset_window_options(win_T *wp, bool valid_cursor) check_colorcolumn(wp); briopt_check(wp); fill_culopt_flags(NULL, wp); - set_chars_option(wp, &wp->w_p_fcs, true); - set_chars_option(wp, &wp->w_p_lcs, true); + set_chars_option(wp, (char_u **)&wp->w_p_fcs, true); + set_chars_option(wp, (char_u **)&wp->w_p_lcs, true); parse_winhl_opt(wp); // sets w_hl_needs_update also for w_p_winbl check_blending(wp); set_winbar_win(wp, false, valid_cursor); @@ -4451,7 +4449,7 @@ void buf_copy_options(buf_T *buf, int flags) // (jumping back to a help file with CTRL-T or CTRL-O) dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) || buf->b_p_initialized; if (dont_do_help) { // don't free b_p_isk - save_p_isk = buf->b_p_isk; + save_p_isk = (char_u *)buf->b_p_isk; buf->b_p_isk = NULL; } // Always free the allocated strings. If not already initialized, @@ -4459,19 +4457,19 @@ void buf_copy_options(buf_T *buf, int flags) if (!buf->b_p_initialized) { free_buf_options(buf, true); buf->b_p_ro = false; // don't copy readonly - buf->b_p_fenc = vim_strsave(p_fenc); + buf->b_p_fenc = (char *)vim_strsave(p_fenc); switch (*p_ffs) { case 'm': - buf->b_p_ff = vim_strsave((char_u *)FF_MAC); + buf->b_p_ff = xstrdup(FF_MAC); break; case 'd': - buf->b_p_ff = vim_strsave((char_u *)FF_DOS); + buf->b_p_ff = xstrdup(FF_DOS); break; case 'u': - buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); + buf->b_p_ff = xstrdup(FF_UNIX); break; default: - buf->b_p_ff = vim_strsave(p_ff); + buf->b_p_ff = (char *)vim_strsave(p_ff); break; } buf->b_p_bh = empty_option; @@ -4516,42 +4514,42 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_swf = p_swf; COPY_OPT_SCTX(buf, BV_SWF); } - buf->b_p_cpt = vim_strsave(p_cpt); + buf->b_p_cpt = (char *)vim_strsave(p_cpt); COPY_OPT_SCTX(buf, BV_CPT); #ifdef BACKSLASH_IN_FILENAME buf->b_p_csl = vim_strsave(p_csl); COPY_OPT_SCTX(buf, BV_CSL); #endif - buf->b_p_cfu = vim_strsave(p_cfu); + buf->b_p_cfu = (char *)vim_strsave(p_cfu); COPY_OPT_SCTX(buf, BV_CFU); - buf->b_p_ofu = vim_strsave(p_ofu); + buf->b_p_ofu = (char *)vim_strsave(p_ofu); COPY_OPT_SCTX(buf, BV_OFU); - buf->b_p_tfu = vim_strsave(p_tfu); + buf->b_p_tfu = (char *)vim_strsave(p_tfu); COPY_OPT_SCTX(buf, BV_TFU); buf->b_p_sts = p_sts; COPY_OPT_SCTX(buf, BV_STS); buf->b_p_sts_nopaste = p_sts_nopaste; - buf->b_p_vsts = vim_strsave(p_vsts); + buf->b_p_vsts = (char *)vim_strsave(p_vsts); COPY_OPT_SCTX(buf, BV_VSTS); - if (p_vsts && p_vsts != empty_option) { + if (p_vsts && p_vsts != (char_u *)empty_option) { (void)tabstop_set(p_vsts, &buf->b_p_vsts_array); } else { buf->b_p_vsts_array = NULL; } buf->b_p_vsts_nopaste = p_vsts_nopaste - ? vim_strsave(p_vsts_nopaste) + ? (char *)vim_strsave(p_vsts_nopaste) : NULL; - buf->b_p_com = vim_strsave(p_com); + buf->b_p_com = (char *)vim_strsave(p_com); COPY_OPT_SCTX(buf, BV_COM); - buf->b_p_cms = vim_strsave(p_cms); + buf->b_p_cms = (char *)vim_strsave(p_cms); COPY_OPT_SCTX(buf, BV_CMS); - buf->b_p_fo = vim_strsave(p_fo); + buf->b_p_fo = (char *)vim_strsave(p_fo); COPY_OPT_SCTX(buf, BV_FO); - buf->b_p_flp = vim_strsave(p_flp); + buf->b_p_flp = (char *)vim_strsave(p_flp); COPY_OPT_SCTX(buf, BV_FLP); - buf->b_p_nf = vim_strsave(p_nf); + buf->b_p_nf = (char *)vim_strsave(p_nf); COPY_OPT_SCTX(buf, BV_NF); - buf->b_p_mps = vim_strsave(p_mps); + buf->b_p_mps = (char *)vim_strsave(p_mps); COPY_OPT_SCTX(buf, BV_MPS); buf->b_p_si = p_si; COPY_OPT_SCTX(buf, BV_SI); @@ -4561,18 +4559,18 @@ void buf_copy_options(buf_T *buf, int flags) COPY_OPT_SCTX(buf, BV_CI); buf->b_p_cin = p_cin; COPY_OPT_SCTX(buf, BV_CIN); - buf->b_p_cink = vim_strsave(p_cink); + buf->b_p_cink = (char *)vim_strsave(p_cink); COPY_OPT_SCTX(buf, BV_CINK); - buf->b_p_cino = vim_strsave(p_cino); + buf->b_p_cino = (char *)vim_strsave(p_cino); COPY_OPT_SCTX(buf, BV_CINO); - buf->b_p_cinsd = vim_strsave(p_cinsd); + buf->b_p_cinsd = (char *)vim_strsave(p_cinsd); COPY_OPT_SCTX(buf, BV_CINSD); // Don't copy 'filetype', it must be detected buf->b_p_ft = empty_option; buf->b_p_pi = p_pi; COPY_OPT_SCTX(buf, BV_PI); - buf->b_p_cinw = vim_strsave(p_cinw); + buf->b_p_cinw = (char *)vim_strsave(p_cinw); COPY_OPT_SCTX(buf, BV_CINW); buf->b_p_lisp = p_lisp; COPY_OPT_SCTX(buf, BV_LISP); @@ -4581,25 +4579,25 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_smc = p_smc; COPY_OPT_SCTX(buf, BV_SMC); buf->b_s.b_syn_isk = empty_option; - buf->b_s.b_p_spc = vim_strsave(p_spc); + buf->b_s.b_p_spc = (char *)vim_strsave(p_spc); COPY_OPT_SCTX(buf, BV_SPC); (void)compile_cap_prog(&buf->b_s); - buf->b_s.b_p_spf = vim_strsave(p_spf); + buf->b_s.b_p_spf = (char *)vim_strsave(p_spf); COPY_OPT_SCTX(buf, BV_SPF); - buf->b_s.b_p_spl = vim_strsave(p_spl); + buf->b_s.b_p_spl = (char *)vim_strsave(p_spl); COPY_OPT_SCTX(buf, BV_SPL); - buf->b_s.b_p_spo = vim_strsave(p_spo); + buf->b_s.b_p_spo = (char *)vim_strsave(p_spo); COPY_OPT_SCTX(buf, BV_SPO); - buf->b_p_inde = vim_strsave(p_inde); + buf->b_p_inde = (char *)vim_strsave(p_inde); COPY_OPT_SCTX(buf, BV_INDE); - buf->b_p_indk = vim_strsave(p_indk); + buf->b_p_indk = (char *)vim_strsave(p_indk); COPY_OPT_SCTX(buf, BV_INDK); buf->b_p_fp = empty_option; - buf->b_p_fex = vim_strsave(p_fex); + buf->b_p_fex = (char *)vim_strsave(p_fex); COPY_OPT_SCTX(buf, BV_FEX); - buf->b_p_sua = vim_strsave(p_sua); + buf->b_p_sua = (char *)vim_strsave(p_sua); COPY_OPT_SCTX(buf, BV_SUA); - buf->b_p_keymap = vim_strsave(p_keymap); + buf->b_p_keymap = (char *)vim_strsave(p_keymap); COPY_OPT_SCTX(buf, BV_KMAP); buf->b_kmap_state |= KEYMAP_INIT; // This isn't really an option, but copying the langmap and IME @@ -4626,12 +4624,12 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_tc_flags = 0; buf->b_p_def = empty_option; buf->b_p_inc = empty_option; - buf->b_p_inex = vim_strsave(p_inex); + buf->b_p_inex = (char *)vim_strsave(p_inex); COPY_OPT_SCTX(buf, BV_INEX); buf->b_p_dict = empty_option; buf->b_p_tsr = empty_option; buf->b_p_tsrfu = empty_option; - buf->b_p_qe = vim_strsave(p_qe); + buf->b_p_qe = (char *)vim_strsave(p_qe); COPY_OPT_SCTX(buf, BV_QE); buf->b_p_udf = p_udf; COPY_OPT_SCTX(buf, BV_UDF); @@ -4645,21 +4643,21 @@ void buf_copy_options(buf_T *buf, int flags) * or to a help buffer. */ if (dont_do_help) { - buf->b_p_isk = save_p_isk; - if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { + buf->b_p_isk = (char *)save_p_isk; + if (p_vts && p_vts != (char_u *)empty_option && !buf->b_p_vts_array) { (void)tabstop_set(p_vts, &buf->b_p_vts_array); } else { buf->b_p_vts_array = NULL; } } else { - buf->b_p_isk = vim_strsave(p_isk); + buf->b_p_isk = (char *)vim_strsave(p_isk); COPY_OPT_SCTX(buf, BV_ISK); did_isk = true; buf->b_p_ts = p_ts; COPY_OPT_SCTX(buf, BV_TS); - buf->b_p_vts = vim_strsave(p_vts); + buf->b_p_vts = (char *)vim_strsave(p_vts); COPY_OPT_SCTX(buf, BV_VTS); - if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { + if (p_vts && p_vts != (char_u *)empty_option && !buf->b_p_vts_array) { (void)tabstop_set(p_vts, &buf->b_p_vts_array); } else { buf->b_p_vts_array = NULL; @@ -5065,7 +5063,7 @@ bool has_format_option(int x) if (p_paste) { return false; } - return vim_strchr((char *)curbuf->b_p_fo, x) != NULL; + return vim_strchr(curbuf->b_p_fo, x) != NULL; } /// @returns true if "x" is present in 'shortmess' option, or @@ -5105,7 +5103,7 @@ static void paste_option_changed(void) xfree(buf->b_p_vsts_nopaste); } buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option - ? vim_strsave(buf->b_p_vsts) + ? xstrdup(buf->b_p_vsts) : NULL; } @@ -5124,7 +5122,7 @@ static void paste_option_changed(void) if (p_vsts_nopaste) { xfree(p_vsts_nopaste); } - p_vsts_nopaste = p_vsts && p_vsts != empty_option + p_vsts_nopaste = p_vsts && p_vsts != (char_u *)empty_option ? vim_strsave(p_vsts) : NULL; } @@ -5160,9 +5158,9 @@ static void paste_option_changed(void) p_sts = 0; p_ai = 0; if (p_vsts) { - free_string_option(p_vsts); + free_string_option((char *)p_vsts); } - p_vsts = empty_option; + p_vsts = (char_u *)empty_option; } else if (old_p_paste) { // Paste switched from on to off: Restore saved values. @@ -5176,12 +5174,10 @@ static void paste_option_changed(void) if (buf->b_p_vsts) { free_string_option(buf->b_p_vsts); } - buf->b_p_vsts = buf->b_p_vsts_nopaste - ? vim_strsave(buf->b_p_vsts_nopaste) - : empty_option; + buf->b_p_vsts = buf->b_p_vsts_nopaste ? xstrdup(buf->b_p_vsts_nopaste) : empty_option; xfree(buf->b_p_vsts_array); if (buf->b_p_vsts && buf->b_p_vsts != empty_option) { - (void)tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array); + (void)tabstop_set((char_u *)buf->b_p_vsts, &buf->b_p_vsts_array); } else { buf->b_p_vsts_array = NULL; } @@ -5203,9 +5199,9 @@ static void paste_option_changed(void) p_tw = p_tw_nopaste; p_wm = p_wm_nopaste; if (p_vsts) { - free_string_option(p_vsts); + free_string_option((char *)p_vsts); } - p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option; + p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : (char_u *)empty_option; } old_p_paste = p_paste; @@ -5286,7 +5282,7 @@ int fill_culopt_flags(char_u *val, win_T *wp) char_u culopt_flags_new = 0; if (val == NULL) { - p = wp->w_p_culopt; + p = (char_u *)wp->w_p_culopt; } else { p = val; } @@ -5437,7 +5433,7 @@ bool can_bs(int what) /// the file must be considered changed when the value is different. void save_file_ff(buf_T *buf) { - buf->b_start_ffc = *buf->b_p_ff; + buf->b_start_ffc = (unsigned char)(*buf->b_p_ff); buf->b_start_eol = buf->b_p_eol; buf->b_start_bomb = buf->b_p_bomb; @@ -5445,7 +5441,7 @@ void save_file_ff(buf_T *buf) if (buf->b_start_fenc == NULL || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) { xfree(buf->b_start_fenc); - buf->b_start_fenc = (char *)vim_strsave(buf->b_p_fenc); + buf->b_start_fenc = xstrdup(buf->b_p_fenc); } } @@ -5493,7 +5489,7 @@ bool briopt_check(win_T *wp) bool bri_sbr = false; int bri_list = 0; - char *p = (char *)wp->w_p_briopt; + char *p = wp->w_p_briopt; while (*p != NUL) { if (STRNCMP(p, "shift:", 6) == 0 && ((p[6] == '-' && ascii_isdigit(p[7])) || ascii_isdigit(p[6]))) { @@ -5550,16 +5546,16 @@ char_u *get_showbreak_value(win_T *const win) return p_sbr; } if (STRCMP(win->w_p_sbr, "NONE") == 0) { - return empty_option; + return (char_u *)empty_option; } - return win->w_p_sbr; + return (char_u *)win->w_p_sbr; } /// Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC. int get_fileformat(const buf_T *buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - int c = *buf->b_p_ff; + int c = (unsigned char)(*buf->b_p_ff); if (buf->b_p_bin || c == 'u') { return EOL_UNIX; @@ -5586,7 +5582,7 @@ int get_fileformat_force(const buf_T *buf, const exarg_T *eap) ? (eap->force_bin == FORCE_BIN) : buf->b_p_bin) { return EOL_UNIX; } - c = *buf->b_p_ff; + c = (unsigned char)(*buf->b_p_ff); } if (c == 'u') { return EOL_UNIX; -- cgit From fa1c761d62667c28e4d3a81f379abeddb878f3cd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 26 Aug 2022 08:25:36 +0800 Subject: vim-patch:9.0.0036: 'fillchars' cannot have window-local values Problem: 'fillchars' cannot have window-local values. Solution: Make 'fillchars' global-local. (closes vim/vim#5206) https://github.com/vim/vim/commit/96ba25ac01279f73c0ecb5d4aa4ff37aa359e5eb Cherry-pick g:run_nr from patch 8.2.0454. N/A patches for version.c: vim-patch:9.0.0037: build error Problem: Build error. Solution: Add missing change. https://github.com/vim/vim/commit/510f03738dfcadfe2099c5b6a58cb75f64dbaa82 --- src/nvim/option.c | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index b2525b73a0..6912f93daa 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4250,6 +4250,14 @@ void win_copy_options(win_T *wp_from, win_T *wp_to) didset_window_options(wp_to, true); } +static char *copy_option_val(const char *val) +{ + if (val == empty_option) { + return empty_option; // no need to allocate memory + } + return xstrdup(val); +} + /// Copy the options from one winopt_T to another. /// Doesn't free the old option values in "to", use clear_winopt() for that. /// The 'scroll' option is not copied, because it depends on the window height. @@ -4258,21 +4266,23 @@ void copy_winopt(winopt_T *from, winopt_T *to) { to->wo_arab = from->wo_arab; to->wo_list = from->wo_list; + to->wo_lcs = copy_option_val(from->wo_lcs); + to->wo_fcs = copy_option_val(from->wo_fcs); to->wo_nu = from->wo_nu; to->wo_rnu = from->wo_rnu; - to->wo_ve = xstrdup(from->wo_ve); + to->wo_ve = copy_option_val(from->wo_ve); to->wo_ve_flags = from->wo_ve_flags; to->wo_nuw = from->wo_nuw; to->wo_rl = from->wo_rl; - to->wo_rlc = xstrdup(from->wo_rlc); - to->wo_sbr = xstrdup(from->wo_sbr); - to->wo_stl = xstrdup(from->wo_stl); - to->wo_wbr = xstrdup(from->wo_wbr); + to->wo_rlc = copy_option_val(from->wo_rlc); + to->wo_sbr = copy_option_val(from->wo_sbr); + to->wo_stl = copy_option_val(from->wo_stl); + to->wo_wbr = copy_option_val(from->wo_wbr); to->wo_wrap = from->wo_wrap; to->wo_wrap_save = from->wo_wrap_save; to->wo_lbr = from->wo_lbr; to->wo_bri = from->wo_bri; - to->wo_briopt = xstrdup(from->wo_briopt); + to->wo_briopt = copy_option_val(from->wo_briopt); to->wo_scb = from->wo_scb; to->wo_scb_save = from->wo_scb_save; to->wo_crb = from->wo_crb; @@ -4280,30 +4290,28 @@ void copy_winopt(winopt_T *from, winopt_T *to) to->wo_spell = from->wo_spell; to->wo_cuc = from->wo_cuc; to->wo_cul = from->wo_cul; - to->wo_culopt = xstrdup(from->wo_culopt); - to->wo_cc = xstrdup(from->wo_cc); + to->wo_culopt = copy_option_val(from->wo_culopt); + to->wo_cc = copy_option_val(from->wo_cc); to->wo_diff = from->wo_diff; to->wo_diff_saved = from->wo_diff_saved; - to->wo_cocu = xstrdup(from->wo_cocu); + to->wo_cocu = copy_option_val(from->wo_cocu); to->wo_cole = from->wo_cole; - to->wo_fdc = xstrdup(from->wo_fdc); + to->wo_fdc = copy_option_val(from->wo_fdc); to->wo_fdc_save = from->wo_diff_saved ? xstrdup(from->wo_fdc_save) : empty_option; to->wo_fen = from->wo_fen; to->wo_fen_save = from->wo_fen_save; - to->wo_fdi = xstrdup(from->wo_fdi); + to->wo_fdi = copy_option_val(from->wo_fdi); to->wo_fml = from->wo_fml; to->wo_fdl = from->wo_fdl; to->wo_fdl_save = from->wo_fdl_save; - to->wo_fdm = xstrdup(from->wo_fdm); + to->wo_fdm = copy_option_val(from->wo_fdm); to->wo_fdm_save = from->wo_diff_saved ? xstrdup(from->wo_fdm_save) : empty_option; to->wo_fdn = from->wo_fdn; - to->wo_fde = xstrdup(from->wo_fde); - to->wo_fdt = xstrdup(from->wo_fdt); - to->wo_fmr = xstrdup(from->wo_fmr); - to->wo_scl = xstrdup(from->wo_scl); - to->wo_winhl = xstrdup(from->wo_winhl); - to->wo_fcs = xstrdup(from->wo_fcs); - to->wo_lcs = xstrdup(from->wo_lcs); + to->wo_fde = copy_option_val(from->wo_fde); + to->wo_fdt = copy_option_val(from->wo_fdt); + to->wo_fmr = copy_option_val(from->wo_fmr); + to->wo_scl = copy_option_val(from->wo_scl); + to->wo_winhl = copy_option_val(from->wo_winhl); to->wo_winbl = from->wo_winbl; // Copy the script context so that we know were the value was last set. @@ -4338,8 +4346,8 @@ static void check_winopt(winopt_T *wop) check_string_option(&wop->wo_cocu); check_string_option(&wop->wo_briopt); check_string_option(&wop->wo_winhl); - check_string_option(&wop->wo_fcs); check_string_option(&wop->wo_lcs); + check_string_option(&wop->wo_fcs); check_string_option(&wop->wo_ve); check_string_option(&wop->wo_wbr); } @@ -4364,8 +4372,8 @@ void clear_winopt(winopt_T *wop) clear_string_option(&wop->wo_cocu); clear_string_option(&wop->wo_briopt); clear_string_option(&wop->wo_winhl); - clear_string_option(&wop->wo_fcs); clear_string_option(&wop->wo_lcs); + clear_string_option(&wop->wo_fcs); clear_string_option(&wop->wo_ve); clear_string_option(&wop->wo_wbr); } -- cgit From 6547f4397fe643f194763306f8fcdfc6f6ce4b24 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 26 Aug 2022 18:49:29 +0800 Subject: vim-patch:8.1.2331: the option.c file is still very big (#19954) Problem: The option.c file is still very big. Solution: Move a few functions to where they fit better. (Yegappan Lakshmanan, closes vim/vim#4895) https://github.com/vim/vim/commit/7bae0b1bc84a95d565ffab38cf7f82ad21c656b6 vim-patch:9.0.0271: using INIT() in non-header files Problem: Using INIT() in non-header files. Solution: Remove INIT(). (closes vim/vim#10981) https://github.com/vim/vim/commit/9b7d2a959646560f5770329f4428c4739eed4656 --- src/nvim/option.c | 167 +----------------------------------------------------- 1 file changed, 3 insertions(+), 164 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 6912f93daa..3f7c200928 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -30,6 +30,7 @@ #include "nvim/arglist.h" #include "nvim/ascii.h" #include "nvim/buffer.h" +#include "nvim/change.h" #include "nvim/charset.h" #include "nvim/cursor_shape.h" #include "nvim/decoration_provider.h" @@ -71,6 +72,7 @@ #include "nvim/popupmenu.h" #include "nvim/regexp.h" #include "nvim/screen.h" +#include "nvim/search.h" #include "nvim/spell.h" #include "nvim/spellfile.h" #include "nvim/spellsuggest.h" @@ -1600,7 +1602,7 @@ void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked /// Convert a key name or string into a key value. /// Used for 'wildchar' and 'cedit' options. -static int string_to_key(char_u *arg) +int string_to_key(char_u *arg) { if (*arg == '<') { return find_key_option(arg + 1, true); @@ -1611,24 +1613,6 @@ static int string_to_key(char_u *arg) return *arg; } -/// Check value of 'cedit' and set cedit_key. -/// Returns NULL if value is OK, error message otherwise. -char *check_cedit(void) -{ - int n; - - if (*p_cedit == NUL) { - cedit_key = -1; - } else { - n = string_to_key(p_cedit); - if (vim_isprintc(n)) { - return e_invarg; - } - cedit_key = n; - } - return NULL; -} - // When changing 'title', 'titlestring', 'icon' or 'iconstring', call // maketitle() to create and display it. // When switching the title or icon off, call ui_set_{icon,title}(NULL) to get @@ -5364,59 +5348,6 @@ int option_set_callback_func(char_u *optval, Callback *optcb) return OK; } -/// Read the 'wildmode' option, fill wim_flags[]. -int check_opt_wim(void) -{ - char_u new_wim_flags[4]; - char_u *p; - int i; - int idx = 0; - - for (i = 0; i < 4; i++) { - new_wim_flags[i] = 0; - } - - for (p = p_wim; *p; p++) { - for (i = 0; ASCII_ISALPHA(p[i]); i++) {} - if (p[i] != NUL && p[i] != ',' && p[i] != ':') { - return FAIL; - } - if (i == 7 && STRNCMP(p, "longest", 7) == 0) { - new_wim_flags[idx] |= WIM_LONGEST; - } else if (i == 4 && STRNCMP(p, "full", 4) == 0) { - new_wim_flags[idx] |= WIM_FULL; - } else if (i == 4 && STRNCMP(p, "list", 4) == 0) { - new_wim_flags[idx] |= WIM_LIST; - } else if (i == 8 && STRNCMP(p, "lastused", 8) == 0) { - new_wim_flags[idx] |= WIM_BUFLASTUSED; - } else { - return FAIL; - } - p += i; - if (*p == NUL) { - break; - } - if (*p == ',') { - if (idx == 3) { - return FAIL; - } - idx++; - } - } - - // fill remaining entries with last flag - while (idx < 3) { - new_wim_flags[idx + 1] = new_wim_flags[idx]; - idx++; - } - - // only when there are no errors, wim_flags[] is changed - for (i = 0; i < 4; i++) { - wim_flags[i] = new_wim_flags[i]; - } - return OK; -} - /// Check if backspacing over something is allowed. /// @param what BS_INDENT, BS_EOL, BS_START, or BS_NOSTOP bool can_bs(int what) @@ -5437,98 +5368,6 @@ bool can_bs(int what) return vim_strchr((char *)p_bs, what) != NULL; } -/// Save the current values of 'fileformat' and 'fileencoding', so that we know -/// the file must be considered changed when the value is different. -void save_file_ff(buf_T *buf) -{ - buf->b_start_ffc = (unsigned char)(*buf->b_p_ff); - buf->b_start_eol = buf->b_p_eol; - buf->b_start_bomb = buf->b_p_bomb; - - // Only use free/alloc when necessary, they take time. - if (buf->b_start_fenc == NULL - || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) { - xfree(buf->b_start_fenc); - buf->b_start_fenc = xstrdup(buf->b_p_fenc); - } -} - -/// Return true if 'fileformat' and/or 'fileencoding' has a different value -/// from when editing started (save_file_ff() called). -/// Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was -/// changed and 'binary' is not set. -/// Also when 'endofline' was changed and 'fixeol' is not set. -/// When "ignore_empty" is true don't consider a new, empty buffer to be -/// changed. -bool file_ff_differs(buf_T *buf, bool ignore_empty) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT -{ - // In a buffer that was never loaded the options are not valid. - if (buf->b_flags & BF_NEVERLOADED) { - return false; - } - if (ignore_empty - && (buf->b_flags & BF_NEW) - && buf->b_ml.ml_line_count == 1 - && *ml_get_buf(buf, (linenr_T)1, false) == NUL) { - return false; - } - if (buf->b_start_ffc != *buf->b_p_ff) { - return true; - } - if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol) { - return true; - } - if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb) { - return true; - } - if (buf->b_start_fenc == NULL) { - return *buf->b_p_fenc != NUL; - } - return STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0; -} - -/// This is called when 'breakindentopt' is changed and when a window is -/// initialized -bool briopt_check(win_T *wp) -{ - int bri_shift = 0; - int bri_min = 20; - bool bri_sbr = false; - int bri_list = 0; - - char *p = wp->w_p_briopt; - while (*p != NUL) { - if (STRNCMP(p, "shift:", 6) == 0 - && ((p[6] == '-' && ascii_isdigit(p[7])) || ascii_isdigit(p[6]))) { - p += 6; - bri_shift = getdigits_int(&p, true, 0); - } else if (STRNCMP(p, "min:", 4) == 0 && ascii_isdigit(p[4])) { - p += 4; - bri_min = getdigits_int(&p, true, 0); - } else if (STRNCMP(p, "sbr", 3) == 0) { - p += 3; - bri_sbr = true; - } else if (STRNCMP(p, "list:", 5) == 0) { - p += 5; - bri_list = (int)getdigits(&p, false, 0); - } - if (*p != ',' && *p != NUL) { - return false; - } - if (*p == ',') { - p++; - } - } - - wp->w_briopt_shift = bri_shift; - wp->w_briopt_min = bri_min; - wp->w_briopt_sbr = bri_sbr; - wp->w_briopt_list = bri_list; - - return true; -} - /// Get the local or global value of 'backupcopy'. /// /// @param buf The buffer. -- cgit From 0b72e23bf13ade1e76d11eae6990014098b3928d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 26 Aug 2022 22:37:20 +0800 Subject: vim-patch:8.2.0674: some source files are too big (#19959) Problem: Some source files are too big. Solution: Move text formatting functions to a new file. (Yegappan Lakshmanan, closes vim/vim#6021) https://github.com/vim/vim/commit/11abd095210fc84e5dcee87b9baed86061caefe4 Cherry-pick set_can_cindent() from patch 8.1.2062. Cherry-pick global old_indent from patch 8.2.2127. --- src/nvim/option.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 3f7c200928..95c3ccf71c 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5047,17 +5047,6 @@ static int wc_use_keyname(char_u *varp, long *wcp) return false; } -/// Return true if format option 'x' is in effect. -/// Take care of no formatting when 'paste' is set. -bool has_format_option(int x) - FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT -{ - if (p_paste) { - return false; - } - return vim_strchr(curbuf->b_p_fo, x) != NULL; -} - /// @returns true if "x" is present in 'shortmess' option, or /// 'shortmess' contains 'a' and "x" is present in SHM_ALL_ABBREVIATIONS. bool shortmess(int x) -- cgit From 395277036014189c03b8969fc0a5cd2bdc5c8631 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 10:36:35 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 95c3ccf71c..3a5550ffc0 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -439,7 +439,7 @@ void set_init_1(bool clean_arg) #ifdef HAVE_WORKING_LIBINTL // GNU gettext 0.10.37 supports this feature: set the codeset used for // translated messages independently from the current locale. - (void)bind_textdomain_codeset(PROJECT_NAME, (char *)p_enc); + (void)bind_textdomain_codeset(PROJECT_NAME, p_enc); #endif // Set the default for 'helplang'. @@ -1483,7 +1483,7 @@ int do_set(char *arg, int opt_flags) // for ":set" on local options. Note: when setting // 'syntax' or 'filetype' autocommands may be // triggered that can cause havoc. - errmsg = did_set_string_option(opt_idx, (char_u **)varp, oldval, + errmsg = did_set_string_option(opt_idx, (char **)varp, (char *)oldval, errbuf, sizeof(errbuf), opt_flags, &value_checked); @@ -1699,16 +1699,14 @@ int get_shada_parameter(int type) /// Return NULL if the parameter is not specified in the string. char_u *find_shada_parameter(int type) { - char_u *p; - - for (p = p_shada; *p; p++) { + for (char *p = p_shada; *p; p++) { if (*p == type) { - return p + 1; + return (char_u *)p + 1; } if (*p == 'n') { // 'n' is always the last one break; } - p = (char_u *)vim_strchr((char *)p, ','); // skip until next ',' + p = vim_strchr(p, ','); // skip until next ',' if (p == NULL) { // hit the end without finding parameter break; } @@ -1745,7 +1743,7 @@ static char_u *option_expand(int opt_idx, char_u *val) */ expand_env_esc(val, NameBuff, MAXPATHL, (char_u **)options[opt_idx].var == &p_tags, false, - (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" : + (char_u **)options[opt_idx].var == (char_u **)&p_sps ? (char_u *)"file:" : NULL); if (STRCMP(NameBuff, val) == 0) { // they are the same return NULL; @@ -2883,7 +2881,7 @@ bool set_tty_option(const char *name, char *value) void set_tty_background(const char *value) { - if (option_was_set("bg") || strequal((char *)p_bg, value)) { + if (option_was_set("bg") || strequal(p_bg, value)) { // background is already set... ignore return; } @@ -4449,7 +4447,7 @@ void buf_copy_options(buf_T *buf, int flags) if (!buf->b_p_initialized) { free_buf_options(buf, true); buf->b_p_ro = false; // don't copy readonly - buf->b_p_fenc = (char *)vim_strsave(p_fenc); + buf->b_p_fenc = xstrdup(p_fenc); switch (*p_ffs) { case 'm': buf->b_p_ff = xstrdup(FF_MAC); @@ -4461,7 +4459,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_ff = xstrdup(FF_UNIX); break; default: - buf->b_p_ff = (char *)vim_strsave(p_ff); + buf->b_p_ff = xstrdup(p_ff); break; } buf->b_p_bh = empty_option; @@ -4512,9 +4510,9 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_csl = vim_strsave(p_csl); COPY_OPT_SCTX(buf, BV_CSL); #endif - buf->b_p_cfu = (char *)vim_strsave(p_cfu); + buf->b_p_cfu = xstrdup(p_cfu); COPY_OPT_SCTX(buf, BV_CFU); - buf->b_p_ofu = (char *)vim_strsave(p_ofu); + buf->b_p_ofu = xstrdup(p_ofu); COPY_OPT_SCTX(buf, BV_OFU); buf->b_p_tfu = (char *)vim_strsave(p_tfu); COPY_OPT_SCTX(buf, BV_TFU); @@ -4531,7 +4529,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_vsts_nopaste = p_vsts_nopaste ? (char *)vim_strsave(p_vsts_nopaste) : NULL; - buf->b_p_com = (char *)vim_strsave(p_com); + buf->b_p_com = xstrdup(p_com); COPY_OPT_SCTX(buf, BV_COM); buf->b_p_cms = (char *)vim_strsave(p_cms); COPY_OPT_SCTX(buf, BV_CMS); @@ -4551,18 +4549,18 @@ void buf_copy_options(buf_T *buf, int flags) COPY_OPT_SCTX(buf, BV_CI); buf->b_p_cin = p_cin; COPY_OPT_SCTX(buf, BV_CIN); - buf->b_p_cink = (char *)vim_strsave(p_cink); + buf->b_p_cink = xstrdup(p_cink); COPY_OPT_SCTX(buf, BV_CINK); - buf->b_p_cino = (char *)vim_strsave(p_cino); + buf->b_p_cino = xstrdup(p_cino); COPY_OPT_SCTX(buf, BV_CINO); - buf->b_p_cinsd = (char *)vim_strsave(p_cinsd); + buf->b_p_cinsd = xstrdup(p_cinsd); COPY_OPT_SCTX(buf, BV_CINSD); // Don't copy 'filetype', it must be detected buf->b_p_ft = empty_option; buf->b_p_pi = p_pi; COPY_OPT_SCTX(buf, BV_PI); - buf->b_p_cinw = (char *)vim_strsave(p_cinw); + buf->b_p_cinw = xstrdup(p_cinw); COPY_OPT_SCTX(buf, BV_CINW); buf->b_p_lisp = p_lisp; COPY_OPT_SCTX(buf, BV_LISP); @@ -4587,7 +4585,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_fp = empty_option; buf->b_p_fex = (char *)vim_strsave(p_fex); COPY_OPT_SCTX(buf, BV_FEX); - buf->b_p_sua = (char *)vim_strsave(p_sua); + buf->b_p_sua = xstrdup(p_sua); COPY_OPT_SCTX(buf, BV_SUA); buf->b_p_keymap = (char *)vim_strsave(p_keymap); COPY_OPT_SCTX(buf, BV_KMAP); @@ -4642,7 +4640,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_vts_array = NULL; } } else { - buf->b_p_isk = (char *)vim_strsave(p_isk); + buf->b_p_isk = xstrdup(p_isk); COPY_OPT_SCTX(buf, BV_ISK); did_isk = true; buf->b_p_ts = p_ts; @@ -5052,8 +5050,8 @@ static int wc_use_keyname(char_u *varp, long *wcp) bool shortmess(int x) { return (p_shm != NULL - && (vim_strchr((char *)p_shm, x) != NULL - || (vim_strchr((char *)p_shm, 'a') != NULL + && (vim_strchr(p_shm, x) != NULL + || (vim_strchr(p_shm, 'a') != NULL && vim_strchr((char *)SHM_ALL_ABBREVIATIONS, x) != NULL))); } @@ -5354,7 +5352,7 @@ bool can_bs(int what) case '0': return false; } - return vim_strchr((char *)p_bs, what) != NULL; + return vim_strchr(p_bs, what) != NULL; } /// Get the local or global value of 'backupcopy'. @@ -5379,7 +5377,7 @@ char_u *get_showbreak_value(win_T *const win) FUNC_ATTR_WARN_UNUSED_RESULT { if (win->w_p_sbr == NULL || *win->w_p_sbr == NUL) { - return p_sbr; + return (char_u *)p_sbr; } if (STRCMP(win->w_p_sbr, "NONE") == 0) { return (char_u *)empty_option; -- cgit From 523600ea6cc1edb7b4d116fdf70437a6b7f226d1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 27 Aug 2022 11:26:47 +0800 Subject: vim-patch:8.2.1269: language and locale code spread out (#19964) Problem: Language and locale code spread out. Solution: Move relevant code to src/locale.c. (Yegappan Lakshmanan, closes vim/vim#6509) https://github.com/vim/vim/commit/054f14bbe58fece17f1a74ca63f0b37518f0b4de Also remove redundant includes. --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 3a5550ffc0..4bf978d2f6 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -39,7 +39,6 @@ #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" -#include "nvim/ex_cmds2.h" #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" #include "nvim/ex_session.h" @@ -53,6 +52,7 @@ #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/keycodes.h" +#include "nvim/locale.h" #include "nvim/macros.h" #include "nvim/mapping.h" #include "nvim/mbyte.h" -- cgit From 691f4715c0cf4bc11ea2280db8777e6dd174a8ac Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 264 ++++++++++++++++++++++++++---------------------------- 1 file changed, 126 insertions(+), 138 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 4bf978d2f6..c3f803e543 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -149,7 +149,7 @@ static int p_et_nopaste; static long p_sts_nopaste; static long p_tw_nopaste; static long p_wm_nopaste; -static char_u *p_vsts_nopaste; +static char *p_vsts_nopaste; typedef struct vimoption { char *fullname; // full option name @@ -455,7 +455,7 @@ static void set_option_default(int opt_idx, int opt_flags) char_u *varp; // pointer to variable for current option int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; - varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); + varp = (char_u *)get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); uint32_t flags = options[opt_idx].flags; if (varp != NULL) { // skip hidden option, nothing to do for it if (flags & P_STRING) { @@ -675,12 +675,12 @@ void set_init_3(void) if (FNAMECMP(p, "csh") == 0 || FNAMECMP(p, "tcsh") == 0) { if (do_sp) { - p_sp = (char_u *)"|& tee"; - options[idx_sp].def_val = p_sp; + p_sp = "|& tee"; + options[idx_sp].def_val = (char_u *)p_sp; } if (do_srr) { - p_srr = (char_u *)">&"; - options[idx_srr].def_val = p_srr; + p_srr = ">&"; + options[idx_srr].def_val = (char_u *)p_srr; } } else if (FNAMECMP(p, "sh") == 0 || FNAMECMP(p, "ksh") == 0 @@ -694,12 +694,12 @@ void set_init_3(void) || FNAMECMP(p, "dash") == 0) { // Always use POSIX shell style redirection if we reach this if (do_sp) { - p_sp = (char_u *)"2>&1| tee"; - options[idx_sp].def_val = p_sp; + p_sp = "2>&1| tee"; + options[idx_sp].def_val = (char_u *)p_sp; } if (do_srr) { - p_srr = (char_u *)">%s 2>&1"; - options[idx_srr].def_val = p_srr; + p_srr = ">%s 2>&1"; + options[idx_srr].def_val = (char_u *)p_srr; } } xfree(p); @@ -810,7 +810,7 @@ int do_set(char *arg, int opt_flags) int opt_idx; char *errmsg; char errbuf[80]; - char_u *startarg; + char *startarg; int prefix; // 1: nothing, 0: "no", 2: "inv" in front of name char_u nextchar; // next non-white char after option name int afterchar; // character just after option name @@ -833,7 +833,7 @@ int do_set(char *arg, int opt_flags) while (*arg != NUL) { // loop to process all options errmsg = NULL; - startarg = (char_u *)arg; // remember for error message + startarg = arg; // remember for error message if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]) && !(opt_flags & OPT_MODELINE)) { @@ -947,7 +947,7 @@ int do_set(char *arg, int opt_flags) } flags = options[opt_idx].flags; - varp = (char *)get_varp_scope(&(options[opt_idx]), opt_flags); + varp = get_varp_scope(&(options[opt_idx]), opt_flags); } else { flags = P_STRING; } @@ -1543,12 +1543,12 @@ skip: if (errmsg != NULL) { STRLCPY(IObuff, _(errmsg), IOSIZE); i = (int)STRLEN(IObuff) + 2; - if (i + ((char_u *)arg - startarg) < IOSIZE) { + if (i + (arg - startarg) < IOSIZE) { // append the argument with the error STRCAT(IObuff, ": "); - assert((char_u *)arg >= startarg); - memmove(IObuff + i, startarg, (size_t)((char_u *)arg - startarg)); - IObuff[i + ((char_u *)arg - startarg)] = NUL; + assert(arg >= startarg); + memmove(IObuff + i, startarg, (size_t)(arg - startarg)); + IObuff[i + (arg - startarg)] = NUL; } // make sure all characters are printable trans_characters((char *)IObuff, IOSIZE); @@ -1741,7 +1741,7 @@ static char_u *option_expand(int opt_idx, char_u *val) * names. * For 'spellsuggest' expand after "file:". */ - expand_env_esc(val, NameBuff, MAXPATHL, + expand_env_esc(val, (char_u *)NameBuff, MAXPATHL, (char_u **)options[opt_idx].var == &p_tags, false, (char_u **)options[opt_idx].var == (char_u **)&p_sps ? (char_u *)"file:" : NULL); @@ -1749,7 +1749,7 @@ static char_u *option_expand(int opt_idx, char_u *val) return NULL; } - return NameBuff; + return (char_u *)NameBuff; } /// After setting various option values: recompute variables that depend on @@ -1779,17 +1779,17 @@ static void didset_options2(void) highlight_changed(); // Parse default for 'fillchars'. - (void)set_chars_option(curwin, (char_u **)&curwin->w_p_fcs, true); + (void)set_chars_option(curwin, &curwin->w_p_fcs, true); // Parse default for 'listchars'. - (void)set_chars_option(curwin, (char_u **)&curwin->w_p_lcs, true); + (void)set_chars_option(curwin, &curwin->w_p_lcs, true); // Parse default for 'wildmode'. check_opt_wim(); xfree(curbuf->b_p_vsts_array); - (void)tabstop_set((char_u *)curbuf->b_p_vsts, &curbuf->b_p_vsts_array); + (void)tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array); xfree(curbuf->b_p_vts_array); - (void)tabstop_set((char_u *)curbuf->b_p_vts, &curbuf->b_p_vts_array); + (void)tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array); } /// Check for string options that are NULL (normally only termcap options). @@ -1858,10 +1858,10 @@ void redraw_titles(void) /// Return true if "val" is a valid name: only consists of alphanumeric ASCII /// characters or characters in "allowed". -bool valid_name(const char_u *val, const char *allowed) +bool valid_name(const char *val, const char *allowed) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - for (const char_u *s = val; *s != NUL; s++) { + for (const char_u *s = (char_u *)val; *s != NUL; s++) { if (!ASCII_ISALNUM(*s) && vim_strchr(allowed, *s) == NULL) { return false; @@ -2930,14 +2930,14 @@ getoption_T get_option_value(const char *name, long *numval, char **stringval, i return gov_unknown; } - char_u *varp = get_varp_scope(&(options[opt_idx]), opt_flags); + char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); if (options[opt_idx].flags & P_STRING) { if (varp == NULL) { // hidden option return gov_hidden_string; } if (stringval != NULL) { - if ((char_u **)varp == &p_pt) { // 'pastetoggle' + if ((char **)varp == &p_pt) { // 'pastetoggle' *stringval = str2special_save(*(char **)(varp), false, false); } else { *stringval = xstrdup(*(char **)(varp)); @@ -3056,7 +3056,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_scope(p, OPT_LOCAL); + varp = (char_u *)get_varp_scope(p, OPT_LOCAL); curbuf = save_curbuf; curwin->w_buffer = curbuf; } @@ -3064,7 +3064,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_scope(p, OPT_LOCAL); + varp = (char_u *)get_varp_scope(p, OPT_LOCAL); curwin = save_curwin; curbuf = curwin->w_buffer; } @@ -3170,7 +3170,7 @@ char *set_option_value(const char *const name, const long number, const char *co return set_string_option(opt_idx, s, opt_flags); } - varp = get_varp_scope(&(options[opt_idx]), opt_flags); + varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); if (varp != NULL) { // hidden option is not changed if (number == 0 && string != NULL) { int idx; @@ -3306,7 +3306,7 @@ static void showoptions(int all, int opt_flags) varp = NULL; if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) != 0) { if (p->indir != PV_NONE) { - varp = get_varp_scope(p, opt_flags); + varp = (char_u *)get_varp_scope(p, opt_flags); } } else { varp = get_varp(p); @@ -3410,13 +3410,12 @@ void ui_refresh_options(void) /// @param opt_flags OPT_LOCAL or OPT_GLOBAL static void showoneopt(vimoption_T *p, int opt_flags) { - char_u *varp; int save_silent = silent_mode; silent_mode = false; info_message = true; // use mch_msg(), not mch_errmsg() - varp = get_varp_scope(p, opt_flags); + char_u *varp = (char_u *)get_varp_scope(p, opt_flags); // for 'modified' we also need to check if 'ff' or 'fenc' changed. if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed @@ -3462,7 +3461,7 @@ static void showoneopt(vimoption_T *p, int opt_flags) int makeset(FILE *fd, int opt_flags, int local_only) { vimoption_T *p; - char_u *varp; // currently used value + char *varp; // currently used value char_u *varp_fresh; // local value char_u *varp_local = NULL; // fresh value char *cmd; @@ -3499,7 +3498,7 @@ int makeset(FILE *fd, int opt_flags, int local_only) continue; } // Global values are only written when not at the default value. - if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp)) { + if ((opt_flags & OPT_GLOBAL) && optval_default(p, (char_u *)varp)) { continue; } @@ -3518,11 +3517,11 @@ int makeset(FILE *fd, int opt_flags, int local_only) // When fresh value of window-local option is not at the // default, need to write it too. if (!(opt_flags & OPT_GLOBAL) && !local_only) { - varp_fresh = get_varp_scope(p, OPT_GLOBAL); + varp_fresh = (char_u *)get_varp_scope(p, OPT_GLOBAL); if (!optval_default(p, varp_fresh)) { round = 1; - varp_local = varp; - varp = varp_fresh; + varp_local = (char_u *)varp; + varp = (char *)varp_fresh; } } } @@ -3530,7 +3529,7 @@ int makeset(FILE *fd, int opt_flags, int local_only) // Round 1: fresh value for window-local options. // Round 2: other values - for (; round <= 2; varp = varp_local, round++) { + for (; round <= 2; varp = (char *)varp_local, round++) { if (round == 1 || (opt_flags & OPT_GLOBAL)) { cmd = "set"; } else { @@ -3558,8 +3557,7 @@ int makeset(FILE *fd, int opt_flags, int local_only) } do_endif = true; } - if (put_setstring(fd, cmd, p->fullname, (char_u **)varp, - p->flags) == FAIL) { + if (put_setstring(fd, cmd, p->fullname, (char **)varp, p->flags) == FAIL) { return FAIL; } if (do_endif) { @@ -3579,25 +3577,21 @@ int makeset(FILE *fd, int opt_flags, int local_only) /// 'sessionoptions' or 'viewoptions' contains "folds" but not "options". int makefoldset(FILE *fd) { - if (put_setstring(fd, "setlocal", "fdm", (char_u **)&curwin->w_p_fdm, 0) == FAIL - || put_setstring(fd, "setlocal", "fde", (char_u **)&curwin->w_p_fde, 0) - == FAIL - || put_setstring(fd, "setlocal", "fmr", (char_u **)&curwin->w_p_fmr, 0) - == FAIL - || put_setstring(fd, "setlocal", "fdi", (char_u **)&curwin->w_p_fdi, 0) - == FAIL + if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL + || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0) == FAIL + || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0) == FAIL + || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0) == FAIL || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL - || put_setbool(fd, "setlocal", "fen", - curwin->w_p_fen) == FAIL) { + || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL) { return FAIL; } return OK; } -static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, uint64_t flags) +static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_t flags) { char_u *s; char_u *buf = NULL; @@ -3612,7 +3606,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, uint6 // options some characters have to be escaped with // CTRL-V or backslash if (valuep == &p_pt) { - s = *valuep; + s = (char_u *)(*valuep); while (*s != NUL) { if (put_escstr(fd, (char_u *)str2special((const char **)&s, false, false), 2) @@ -3625,13 +3619,13 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, uint6 // replace home directory in the whole option value into "buf" buf = xmalloc(size); - home_replace(NULL, (char *)(*valuep), (char *)buf, size, false); + home_replace(NULL, *valuep, (char *)buf, size, false); // If the option value is longer than MAXPATHL, we need to append // each comma separated part of the option separately, so that it // can be expanded when read back. if (size >= MAXPATHL && (flags & P_COMMA) != 0 - && vim_strchr((char *)(*valuep), ',') != NULL) { + && vim_strchr(*valuep, ',') != NULL) { part = xmalloc(size); // write line break to clear the option, e.g. ':set rtp=' @@ -3659,7 +3653,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, uint6 return FAIL; } xfree(buf); - } else if (put_escstr(fd, *valuep, 2) == FAIL) { + } else if (put_escstr(fd, (char_u *)(*valuep), 2) == FAIL) { return FAIL; } } @@ -3798,12 +3792,12 @@ void unset_global_local_option(char *name, void *from) break; case PV_LCS: clear_string_option(&((win_T *)from)->w_p_lcs); - set_chars_option((win_T *)from, (char_u **)&((win_T *)from)->w_p_lcs, true); + set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs, true); redraw_later((win_T *)from, UPD_NOT_VALID); break; case PV_FCS: clear_string_option(&((win_T *)from)->w_p_fcs); - set_chars_option((win_T *)from, (char_u **)&((win_T *)from)->w_p_fcs, true); + set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs, true); redraw_later((win_T *)from, UPD_NOT_VALID); break; case PV_VE: @@ -3814,81 +3808,81 @@ void unset_global_local_option(char *name, void *from) } /// Get pointer to option variable, depending on local or global scope. -static char_u *get_varp_scope(vimoption_T *p, int opt_flags) +static char *get_varp_scope(vimoption_T *p, int opt_flags) { if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) { if (p->var == VAR_WIN) { - return (char_u *)GLOBAL_WO(get_varp(p)); + return GLOBAL_WO(get_varp(p)); } - return p->var; + return (char *)p->var; } if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) { switch ((int)p->indir) { case PV_FP: - return (char_u *)&(curbuf->b_p_fp); + return (char *)&(curbuf->b_p_fp); case PV_EFM: - return (char_u *)&(curbuf->b_p_efm); + return (char *)&(curbuf->b_p_efm); case PV_GP: - return (char_u *)&(curbuf->b_p_gp); + return (char *)&(curbuf->b_p_gp); case PV_MP: - return (char_u *)&(curbuf->b_p_mp); + return (char *)&(curbuf->b_p_mp); case PV_EP: - return (char_u *)&(curbuf->b_p_ep); + return (char *)&(curbuf->b_p_ep); case PV_KP: - return (char_u *)&(curbuf->b_p_kp); + return (char *)&(curbuf->b_p_kp); case PV_PATH: - return (char_u *)&(curbuf->b_p_path); + return (char *)&(curbuf->b_p_path); case PV_AR: - return (char_u *)&(curbuf->b_p_ar); + return (char *)&(curbuf->b_p_ar); case PV_TAGS: - return (char_u *)&(curbuf->b_p_tags); + return (char *)&(curbuf->b_p_tags); case PV_TC: - return (char_u *)&(curbuf->b_p_tc); + return (char *)&(curbuf->b_p_tc); case PV_SISO: - return (char_u *)&(curwin->w_p_siso); + return (char *)&(curwin->w_p_siso); case PV_SO: - return (char_u *)&(curwin->w_p_so); + return (char *)&(curwin->w_p_so); case PV_DEF: - return (char_u *)&(curbuf->b_p_def); + return (char *)&(curbuf->b_p_def); case PV_INC: - return (char_u *)&(curbuf->b_p_inc); + return (char *)&(curbuf->b_p_inc); case PV_DICT: - return (char_u *)&(curbuf->b_p_dict); + return (char *)&(curbuf->b_p_dict); case PV_TSR: - return (char_u *)&(curbuf->b_p_tsr); + return (char *)&(curbuf->b_p_tsr); case PV_TSRFU: - return (char_u *)&(curbuf->b_p_tsrfu); + return (char *)&(curbuf->b_p_tsrfu); case PV_TFU: - return (char_u *)&(curbuf->b_p_tfu); + return (char *)&(curbuf->b_p_tfu); case PV_SBR: - return (char_u *)&(curwin->w_p_sbr); + return (char *)&(curwin->w_p_sbr); case PV_STL: - return (char_u *)&(curwin->w_p_stl); + return (char *)&(curwin->w_p_stl); case PV_WBR: - return (char_u *)&(curwin->w_p_wbr); + return (char *)&(curwin->w_p_wbr); case PV_UL: - return (char_u *)&(curbuf->b_p_ul); + return (char *)&(curbuf->b_p_ul); case PV_LW: - return (char_u *)&(curbuf->b_p_lw); + return (char *)&(curbuf->b_p_lw); case PV_BKC: - return (char_u *)&(curbuf->b_p_bkc); + return (char *)&(curbuf->b_p_bkc); case PV_MENC: - return (char_u *)&(curbuf->b_p_menc); + return (char *)&(curbuf->b_p_menc); case PV_FCS: - return (char_u *)&(curwin->w_p_fcs); + return (char *)&(curwin->w_p_fcs); case PV_LCS: - return (char_u *)&(curwin->w_p_lcs); + return (char *)&(curwin->w_p_lcs); case PV_VE: - return (char_u *)&(curwin->w_p_ve); + return (char *)&(curwin->w_p_ve); } return NULL; // "cannot happen" } - return get_varp(p); + return (char *)get_varp(p); } /// Get pointer to option variable at 'opt_idx', depending on local or global /// scope. -char_u *get_option_varp_scope(int opt_idx, int opt_flags) +char *get_option_varp_scope(int opt_idx, int opt_flags) { return get_varp_scope(&(options[opt_idx]), opt_flags); } @@ -4365,8 +4359,8 @@ void didset_window_options(win_T *wp, bool valid_cursor) check_colorcolumn(wp); briopt_check(wp); fill_culopt_flags(NULL, wp); - set_chars_option(wp, (char_u **)&wp->w_p_fcs, true); - set_chars_option(wp, (char_u **)&wp->w_p_lcs, true); + set_chars_option(wp, &wp->w_p_fcs, true); + set_chars_option(wp, &wp->w_p_lcs, true); parse_winhl_opt(wp); // sets w_hl_needs_update also for w_p_winbl check_blending(wp); set_winbar_win(wp, false, valid_cursor); @@ -4504,7 +4498,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_swf = p_swf; COPY_OPT_SCTX(buf, BV_SWF); } - buf->b_p_cpt = (char *)vim_strsave(p_cpt); + buf->b_p_cpt = xstrdup(p_cpt); COPY_OPT_SCTX(buf, BV_CPT); #ifdef BACKSLASH_IN_FILENAME buf->b_p_csl = vim_strsave(p_csl); @@ -4514,32 +4508,30 @@ void buf_copy_options(buf_T *buf, int flags) COPY_OPT_SCTX(buf, BV_CFU); buf->b_p_ofu = xstrdup(p_ofu); COPY_OPT_SCTX(buf, BV_OFU); - buf->b_p_tfu = (char *)vim_strsave(p_tfu); + buf->b_p_tfu = xstrdup(p_tfu); COPY_OPT_SCTX(buf, BV_TFU); buf->b_p_sts = p_sts; COPY_OPT_SCTX(buf, BV_STS); buf->b_p_sts_nopaste = p_sts_nopaste; - buf->b_p_vsts = (char *)vim_strsave(p_vsts); + buf->b_p_vsts = xstrdup(p_vsts); COPY_OPT_SCTX(buf, BV_VSTS); - if (p_vsts && p_vsts != (char_u *)empty_option) { + if (p_vsts && p_vsts != empty_option) { (void)tabstop_set(p_vsts, &buf->b_p_vsts_array); } else { buf->b_p_vsts_array = NULL; } - buf->b_p_vsts_nopaste = p_vsts_nopaste - ? (char *)vim_strsave(p_vsts_nopaste) - : NULL; + buf->b_p_vsts_nopaste = p_vsts_nopaste ? xstrdup(p_vsts_nopaste) : NULL; buf->b_p_com = xstrdup(p_com); COPY_OPT_SCTX(buf, BV_COM); - buf->b_p_cms = (char *)vim_strsave(p_cms); + buf->b_p_cms = xstrdup(p_cms); COPY_OPT_SCTX(buf, BV_CMS); - buf->b_p_fo = (char *)vim_strsave(p_fo); + buf->b_p_fo = xstrdup(p_fo); COPY_OPT_SCTX(buf, BV_FO); - buf->b_p_flp = (char *)vim_strsave(p_flp); + buf->b_p_flp = xstrdup(p_flp); COPY_OPT_SCTX(buf, BV_FLP); - buf->b_p_nf = (char *)vim_strsave(p_nf); + buf->b_p_nf = xstrdup(p_nf); COPY_OPT_SCTX(buf, BV_NF); - buf->b_p_mps = (char *)vim_strsave(p_mps); + buf->b_p_mps = xstrdup(p_mps); COPY_OPT_SCTX(buf, BV_MPS); buf->b_p_si = p_si; COPY_OPT_SCTX(buf, BV_SI); @@ -4569,25 +4561,25 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_smc = p_smc; COPY_OPT_SCTX(buf, BV_SMC); buf->b_s.b_syn_isk = empty_option; - buf->b_s.b_p_spc = (char *)vim_strsave(p_spc); + buf->b_s.b_p_spc = xstrdup(p_spc); COPY_OPT_SCTX(buf, BV_SPC); (void)compile_cap_prog(&buf->b_s); - buf->b_s.b_p_spf = (char *)vim_strsave(p_spf); + buf->b_s.b_p_spf = xstrdup(p_spf); COPY_OPT_SCTX(buf, BV_SPF); - buf->b_s.b_p_spl = (char *)vim_strsave(p_spl); + buf->b_s.b_p_spl = xstrdup(p_spl); COPY_OPT_SCTX(buf, BV_SPL); - buf->b_s.b_p_spo = (char *)vim_strsave(p_spo); + buf->b_s.b_p_spo = xstrdup(p_spo); COPY_OPT_SCTX(buf, BV_SPO); - buf->b_p_inde = (char *)vim_strsave(p_inde); + buf->b_p_inde = xstrdup(p_inde); COPY_OPT_SCTX(buf, BV_INDE); - buf->b_p_indk = (char *)vim_strsave(p_indk); + buf->b_p_indk = xstrdup(p_indk); COPY_OPT_SCTX(buf, BV_INDK); buf->b_p_fp = empty_option; - buf->b_p_fex = (char *)vim_strsave(p_fex); + buf->b_p_fex = xstrdup(p_fex); COPY_OPT_SCTX(buf, BV_FEX); buf->b_p_sua = xstrdup(p_sua); COPY_OPT_SCTX(buf, BV_SUA); - buf->b_p_keymap = (char *)vim_strsave(p_keymap); + buf->b_p_keymap = xstrdup(p_keymap); COPY_OPT_SCTX(buf, BV_KMAP); buf->b_kmap_state |= KEYMAP_INIT; // This isn't really an option, but copying the langmap and IME @@ -4614,12 +4606,12 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_tc_flags = 0; buf->b_p_def = empty_option; buf->b_p_inc = empty_option; - buf->b_p_inex = (char *)vim_strsave(p_inex); + buf->b_p_inex = xstrdup(p_inex); COPY_OPT_SCTX(buf, BV_INEX); buf->b_p_dict = empty_option; buf->b_p_tsr = empty_option; buf->b_p_tsrfu = empty_option; - buf->b_p_qe = (char *)vim_strsave(p_qe); + buf->b_p_qe = xstrdup(p_qe); COPY_OPT_SCTX(buf, BV_QE); buf->b_p_udf = p_udf; COPY_OPT_SCTX(buf, BV_UDF); @@ -4634,7 +4626,7 @@ void buf_copy_options(buf_T *buf, int flags) */ if (dont_do_help) { buf->b_p_isk = (char *)save_p_isk; - if (p_vts && p_vts != (char_u *)empty_option && !buf->b_p_vts_array) { + if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { (void)tabstop_set(p_vts, &buf->b_p_vts_array); } else { buf->b_p_vts_array = NULL; @@ -4645,9 +4637,9 @@ void buf_copy_options(buf_T *buf, int flags) did_isk = true; buf->b_p_ts = p_ts; COPY_OPT_SCTX(buf, BV_TS); - buf->b_p_vts = (char *)vim_strsave(p_vts); + buf->b_p_vts = xstrdup(p_vts); COPY_OPT_SCTX(buf, BV_VTS); - if (p_vts && p_vts != (char_u *)empty_option && !buf->b_p_vts_array) { + if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { (void)tabstop_set(p_vts, &buf->b_p_vts_array); } else { buf->b_p_vts_array = NULL; @@ -4966,7 +4958,7 @@ void ExpandOldSetting(int *num_file, char ***file) if (expand_option_idx >= 0) { // Put string of option value in NameBuff. option_value2string(&options[expand_option_idx], expand_option_flags); - var = NameBuff; + var = (char_u *)NameBuff; } else { var = (char_u *)""; } @@ -4999,9 +4991,7 @@ void ExpandOldSetting(int *num_file, char ***file) /// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL static void option_value2string(vimoption_T *opp, int opt_flags) { - char_u *varp; - - varp = get_varp_scope(opp, opt_flags); + char_u *varp = (char_u *)get_varp_scope(opp, opt_flags); if (opp->flags & P_NUM) { long wc = 0; @@ -5023,7 +5013,7 @@ static void option_value2string(vimoption_T *opp, int opt_flags) } else if (opp->flags & P_EXPAND) { home_replace(NULL, (char *)varp, (char *)NameBuff, MAXPATHL, false); // Translate 'pastetoggle' into special key names. - } else if ((char_u **)opp->var == &p_pt) { + } else if ((char **)opp->var == &p_pt) { str2specialbuf((const char *)p_pt, (char *)NameBuff, MAXPATHL); } else { STRLCPY(NameBuff, varp, MAXPATHL); @@ -5052,7 +5042,7 @@ bool shortmess(int x) return (p_shm != NULL && (vim_strchr(p_shm, x) != NULL || (vim_strchr(p_shm, 'a') != NULL - && vim_strchr((char *)SHM_ALL_ABBREVIATIONS, x) != NULL))); + && vim_strchr(SHM_ALL_ABBREVIATIONS, x) != NULL))); } /// paste_option_changed() - Called after p_paste was set or reset. @@ -5101,9 +5091,7 @@ static void paste_option_changed(void) if (p_vsts_nopaste) { xfree(p_vsts_nopaste); } - p_vsts_nopaste = p_vsts && p_vsts != (char_u *)empty_option - ? vim_strsave(p_vsts) - : NULL; + p_vsts_nopaste = p_vsts && p_vsts != empty_option ? xstrdup(p_vsts) : NULL; } // Always set the option values, also when 'paste' is set when it is @@ -5137,9 +5125,9 @@ static void paste_option_changed(void) p_sts = 0; p_ai = 0; if (p_vsts) { - free_string_option((char *)p_vsts); + free_string_option(p_vsts); } - p_vsts = (char_u *)empty_option; + p_vsts = empty_option; } else if (old_p_paste) { // Paste switched from on to off: Restore saved values. @@ -5156,7 +5144,7 @@ static void paste_option_changed(void) buf->b_p_vsts = buf->b_p_vsts_nopaste ? xstrdup(buf->b_p_vsts_nopaste) : empty_option; xfree(buf->b_p_vsts_array); if (buf->b_p_vsts && buf->b_p_vsts != empty_option) { - (void)tabstop_set((char_u *)buf->b_p_vsts, &buf->b_p_vsts_array); + (void)tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array); } else { buf->b_p_vsts_array = NULL; } @@ -5178,9 +5166,9 @@ static void paste_option_changed(void) p_tw = p_tw_nopaste; p_wm = p_wm_nopaste; if (p_vsts) { - free_string_option((char *)p_vsts); + free_string_option(p_vsts); } - p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : (char_u *)empty_option; + p_vsts = p_vsts_nopaste ? xstrdup(p_vsts_nopaste) : empty_option; } old_p_paste = p_paste; @@ -5248,20 +5236,20 @@ void fill_breakat_flags(void) } if (p_breakat != NULL) { - for (p = p_breakat; *p; p++) { + for (p = (char_u *)p_breakat; *p; p++) { breakat_flags[*p] = true; } } } /// fill_culopt_flags() -- called when 'culopt' changes value -int fill_culopt_flags(char_u *val, win_T *wp) +int fill_culopt_flags(char *val, win_T *wp) { - char_u *p; + char *p; char_u culopt_flags_new = 0; if (val == NULL) { - p = (char_u *)wp->w_p_culopt; + p = wp->w_p_culopt; } else { p = val; } @@ -5473,7 +5461,7 @@ void set_fileformat(int eol_style, int opt_flags) } /// Skip to next part of an option argument: skip space and comma -char_u *skip_to_option_part(const char_u *p) +char *skip_to_option_part(const char *p) { if (*p == ',') { p++; @@ -5481,7 +5469,7 @@ char_u *skip_to_option_part(const char_u *p) while (*p == ' ') { p++; } - return (char_u *)p; + return (char *)p; } /// Isolate one part of a string option separated by `sep_chars`. @@ -5516,7 +5504,7 @@ size_t copy_option_part(char **option, char *buf, size_t maxlen, char *sep_chars if (*p != NUL && *p != ',') { // skip non-standard separator p++; } - p = (char *)skip_to_option_part((char_u *)p); // p points to next file name + p = skip_to_option_part(p); // p points to next file name *option = p; return len; -- cgit From 58f30a326f34319801e7921f32c83e8320d85f6c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index c3f803e543..f9b32d50af 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3299,7 +3299,7 @@ static void showoptions(int all, int opt_flags) item_count = 0; for (p = &options[0]; p->fullname != NULL; p++) { // apply :filter /pat/ - if (message_filtered((char_u *)p->fullname)) { + if (message_filtered(p->fullname)) { continue; } -- cgit From f58a9795990a3b324f66912e4ae33dae7eb7474d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 30 Aug 2022 06:26:06 +0800 Subject: vim-patch:9.0.0318: clearing screen causes flicker (#19993) Problem: Clearing screen causes flicker. Solution: Do not clear but redraw in more cases. Add () to "wait_return". https://github.com/vim/vim/commit/13608d851a0470ced30921428b3313c023d395d8 Only 2 lines of actual code change. --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index f9b32d50af..455070c742 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1553,7 +1553,7 @@ skip: // make sure all characters are printable trans_characters((char *)IObuff, IOSIZE); - no_wait_return++; // wait_return done later + no_wait_return++; // wait_return() done later emsg((char *)IObuff); // show error highlighted no_wait_return--; -- cgit From 5f92d9b345e11adb73df33dc22a8e656aca73b6c Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 1 Sep 2022 09:44:01 +0200 Subject: perf(messages): don't call ui_flush() per message line in various places When msgsep is used, message scrolling is emulated. To make message output fast, inhibit emulated scrolling until the full message text is known --- src/nvim/option.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 455070c742..269a21b512 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3355,7 +3355,6 @@ static void showoptions(int all, int opt_flags) showoneopt(items[i], opt_flags); col += INC; } - ui_flush(); os_breakcheck(); } } -- cgit From 49e893f296bca9eef5ff45a3d746c261d055bf10 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 269a21b512..f8b7d96305 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -664,8 +664,8 @@ void set_init_3(void) : !(options[idx_sp].flags & P_WAS_SET); size_t len = 0; - char_u *p = (char_u *)invocation_path_tail(p_sh, &len); - p = vim_strnsave(p, len); + char *p = (char *)invocation_path_tail(p_sh, &len); + p = xstrnsave(p, len); { // @@ -1131,7 +1131,7 @@ int do_set(char *arg, int opt_flags) } } else if (*arg == '-' || ascii_isdigit(*arg)) { // Allow negative, octal and hex numbers. - vim_str2nr((char_u *)arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, true); + vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, true); if (i == 0 || (arg[i] != NUL && !ascii_iswhite(arg[i]))) { errmsg = e_number_required_after_equal; goto skip; -- cgit From 1ffd527c837fb2465c9659273bbe5447a1352db2 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 2 Sep 2022 17:39:49 +0100 Subject: refactor: migrate comment style (#20012) Done automatically using the following perl command: perl -pi -0777pe 's#\n\K */\*\n(.+?)\s*\*/\n#join("\n", map { $_ =~ s:^\s*\K \*://:; $_ } split("\n", $1)) . "\n"#sge' src/nvim/**/*.c Co-authored-by: zeertzjq Co-authored-by: zeertzjq --- src/nvim/option.c | 227 ++++++++++++++++++++---------------------------------- 1 file changed, 85 insertions(+), 142 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index f8b7d96305..12c2888f5c 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -106,14 +106,12 @@ static char e_number_required_after_equal[] static char e_preview_window_already_exists[] = N_("E590: A preview window already exists"); -/* - * The options that are local to a window or buffer have "indir" set to one of - * these values. Special values: - * PV_NONE: global option. - * PV_WIN is added: window-local option - * PV_BUF is added: buffer-local option - * PV_BOTH is added: global option which also has a local value. - */ +// The options that are local to a window or buffer have "indir" set to one of +// these values. Special values: +// PV_NONE: global option. +// PV_WIN is added: window-local option +// PV_BUF is added: buffer-local option +// PV_BOTH is added: global option which also has a local value. #define PV_BOTH 0x1000 #define PV_WIN 0x2000 #define PV_BUF 0x4000 @@ -128,10 +126,8 @@ typedef enum { PV_MAXVAL = 0xffff, // to avoid warnings for value out of range } idopt_T; -/* - * Options local to a window have a value local to a buffer and global to all - * buffers. Indicate this by setting "var" to VAR_WIN. - */ +// Options local to a window have a value local to a buffer and global to all +// buffers. Indicate this by setting "var" to VAR_WIN. #define VAR_WIN ((char_u *)-1) static char *p_term = NULL; @@ -164,14 +160,12 @@ typedef struct vimoption { LastSet last_set; // script in which the option was last set } vimoption_T; -/* - * options[] is initialized here. - * The order of the options MUST be alphabetic for ":set all" and findoption(). - * All option names MUST start with a lowercase letter (for findoption()). - * Exception: "t_" options are at the end. - * The options with a NULL variable are 'hidden': a set command for them is - * ignored and they are not printed. - */ +// options[] is initialized here. +// The order of the options MUST be alphabetic for ":set all" and findoption(). +// All option names MUST start with a lowercase letter (for findoption()). +// Exception: "t_" options are at the end. +// The options with a NULL variable are 'hidden': a set command for them is +// ignored and they are not printed. #ifdef INCLUDE_GENERATED_DECLARATIONS # include "options.generated.h" @@ -197,10 +191,8 @@ void set_init_1(bool clean_arg) langmap_init(); - /* - * Find default value for 'shell' option. - * Don't use it if it is empty. - */ + // Find default value for 'shell' option. + // Don't use it if it is empty. { const char *shell = os_getenv("SHELL"); if (shell != NULL) { @@ -215,10 +207,8 @@ void set_init_1(bool clean_arg) } } - /* - * Set the default for 'backupskip' to include environment variables for - * temp files. - */ + // Set the default for 'backupskip' to include environment variables for + // temp files. { #ifdef UNIX static char *(names[4]) = { "", "TMPDIR", "TEMP", "TMP" }; @@ -354,10 +344,8 @@ void set_init_1(bool clean_arg) rtp = NULL; // ownership taken } - /* - * Set all the options (except the terminal options) to their default - * value. Also set the global value for local options. - */ + // Set all the options (except the terminal options) to their default + // value. Also set the global value for local options. set_options_default(0); curbuf->b_p_initialized = true; @@ -380,15 +368,13 @@ void set_init_1(bool clean_arg) // didset_options() because it only depends on 'encoding'. init_spell_chartab(); - /* - * Expand environment variables and things like "~" for the defaults. - * If option_expand() returns non-NULL the variable is expanded. This can - * only happen for non-indirect options. - * Also set the default to the expanded value, so ":set" does not list - * them. - * Don't set the P_ALLOCED flag, because we don't want to free the - * default. - */ + // Expand environment variables and things like "~" for the defaults. + // If option_expand() returns non-NULL the variable is expanded. This can + // only happen for non-indirect options. + // Also set the default to the expanded value, so ":set" does not list + // them. + // Don't set the P_ALLOCED flag, because we don't want to free the + // default. for (opt_idx = 0; options[opt_idx].fullname; opt_idx++) { if (options[opt_idx].flags & P_NO_DEF_EXP) { continue; @@ -635,10 +621,8 @@ void set_init_2(bool headless) } comp_col(); - /* - * 'window' is only for backwards compatibility with Vi. - * Default is Rows - 1. - */ + // 'window' is only for backwards compatibility with Vi. + // Default is Rows - 1. if (!option_was_set("window")) { p_window = Rows - 1; } @@ -758,11 +742,9 @@ void set_title_defaults(void) { int idx1; - /* - * If GUI is (going to be) used, we can always set the window title and - * icon name. Saves a bit of time, because the X11 display server does - * not need to be contacted. - */ + // If GUI is (going to be) used, we can always set the window title and + // icon name. Saves a bit of time, because the X11 display server does + // not need to be contacted. idx1 = findoption("title"); if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) { options[idx1].def_val = (char_u *)(intptr_t)0; @@ -837,10 +819,8 @@ int do_set(char *arg, int opt_flags) if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]) && !(opt_flags & OPT_MODELINE)) { - /* - * ":set all" show all options. - * ":set all&" set all options to their default value. - */ + // ":set all" show all options. + // ":set all&" set all options to their default value. arg += 3; if (*arg == '&') { arg++; @@ -1016,9 +996,7 @@ int do_set(char *arg, int opt_flags) || (prefix == 1 && vim_strchr("=:&<", nextchar) == NULL && !(flags & P_BOOL))) { - /* - * print value - */ + // print value if (did_show) { msg_putchar('\n'); // cursor below last one } else { @@ -1057,11 +1035,9 @@ int do_set(char *arg, int opt_flags) goto skip; } - /* - * ":set opt!": invert - * ":set opt&": reset to default value - * ":set opt<": reset to global value - */ + // ":set opt!": invert + // ":set opt&": reset to default value + // ":set opt<": reset to global value if (nextchar == '!') { value = *(int *)(varp) ^ 1; } else if (nextchar == '&') { @@ -1076,10 +1052,8 @@ int do_set(char *arg, int opt_flags) OPT_GLOBAL); } } else { - /* - * ":set invopt": invert - * ":set opt" or ":set noopt": set or reset - */ + // ":set invopt": invert + // ":set opt" or ":set noopt": set or reset if (nextchar != NUL && !ascii_iswhite(afterchar)) { errmsg = e_trailing; goto skip; @@ -1289,11 +1263,10 @@ int do_set(char *arg, int opt_flags) arg++; } - /* - * Copy the new string into allocated memory. - * Can't use set_string_option_direct(), because - * we need to remove the backslashes. - */ + // Copy the new string into allocated memory. + // Can't use set_string_option_direct(), because + // we need to remove the backslashes. + // get a bit too much newlen = (unsigned)STRLEN(arg) + 1; if (adding || prepending || removing) { @@ -1302,14 +1275,12 @@ int do_set(char *arg, int opt_flags) newval = xmalloc(newlen); s = newval; - /* - * Copy the string, skip over escaped chars. - * For WIN32 backslashes before normal - * file name characters are not removed, and keep - * backslash at start, for "\\machine\path", but - * do remove it for "\\\\machine\\path". - * The reverse is found in ExpandOldSetting(). - */ + // Copy the string, skip over escaped chars. + // For WIN32 backslashes before normal + // file name characters are not removed, and keep + // backslash at start, for "\\machine\path", but + // do remove it for "\\\\machine\\path". + // The reverse is found in ExpandOldSetting(). while (*arg && !ascii_iswhite(*arg)) { if (*arg == '\\' && arg[1] != NUL #ifdef BACKSLASH_IN_FILENAME @@ -1335,11 +1306,9 @@ int do_set(char *arg, int opt_flags) } *s = NUL; - /* - * Expand environment variables and ~. - * Don't do it when adding without inserting a - * comma. - */ + // Expand environment variables and ~. + // Don't do it when adding without inserting a + // comma. if (!(adding || prepending || removing) || (flags & P_COMMA)) { s = option_expand(opt_idx, newval); @@ -1521,12 +1490,10 @@ int do_set(char *arg, int opt_flags) } skip: - /* - * Advance to next argument. - * - skip until a blank found, taking care of backslashes - * - skip blanks - * - skip one "=val" argument (for hidden options ":set gfn =xx") - */ + // Advance to next argument. + // - skip until a blank found, taking care of backslashes + // - skip blanks + // - skip one "=val" argument (for hidden options ":set gfn =xx") for (i = 0; i < 2; i++) { while (*arg != NUL && !ascii_iswhite(*arg)) { if (*arg++ == '\\' && *arg != NUL) { @@ -1629,10 +1596,8 @@ void did_set_title(void) /// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL void set_options_bin(int oldval, int newval, int opt_flags) { - /* - * The option values that are changed when 'bin' changes are - * copied when 'bin is set and restored when 'bin' is reset. - */ + // The option values that are changed when 'bin' changes are + // copied when 'bin is set and restored when 'bin' is reset. if (newval) { if (!oldval) { // switched on if (!(opt_flags & OPT_GLOBAL)) { @@ -1735,12 +1700,10 @@ static char_u *option_expand(int opt_idx, char_u *val) return NULL; } - /* - * Expanding this with NameBuff, expand_env() must not be passed IObuff. - * Escape spaces when expanding 'tags', they are used to separate file - * names. - * For 'spellsuggest' expand after "file:". - */ + // Expanding this with NameBuff, expand_env() must not be passed IObuff. + // Escape spaces when expanding 'tags', they are used to separate file + // names. + // For 'spellsuggest' expand after "file:". expand_env_esc(val, (char_u *)NameBuff, MAXPATHL, (char_u **)options[opt_idx].var == &p_tags, false, (char_u **)options[opt_idx].var == (char_u **)&p_sps ? (char_u *)"file:" : @@ -2153,9 +2116,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va if ((int *)varp == &curwin->w_p_arab) { if (curwin->w_p_arab) { - /* - * 'arabic' is set, handle various sub-settings. - */ + // 'arabic' is set, handle various sub-settings. if (!p_tbidi) { // set rightleft mode if (!curwin->w_p_rl) { @@ -2186,9 +2147,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va // Force-set the necessary keymap for arabic. errmsg = set_option_value("keymap", 0L, "arabic", OPT_LOCAL); } else { - /* - * 'arabic' is reset, handle various sub-settings. - */ + // 'arabic' is reset, handle various sub-settings. if (!p_tbidi) { // reset rightleft mode if (curwin->w_p_rl) { @@ -2209,9 +2168,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va } } - /* - * End of handling side effects for bool options. - */ + // End of handling side effects for bool options. // after handling side effects, call autocommand @@ -3328,9 +3285,7 @@ static void showoptions(int all, int opt_flags) } } - /* - * display the items - */ + // display the items if (run == 1) { assert(Columns <= INT_MAX - GAP && Columns + GAP >= INT_MIN + 3 @@ -3467,15 +3422,13 @@ int makeset(FILE *fd, int opt_flags, int local_only) int round; int pri; - /* - * Some options are never written: - * - Options that don't have a default (terminal name, columns, lines). - * - Terminal options. - * - Hidden options. - * - * Do the loop over "options[]" twice: once for options with the - * P_PRI_MKRC flag and once without. - */ + // Some options are never written: + // - Options that don't have a default (terminal name, columns, lines). + // - Terminal options. + // - Hidden options. + // + // Do the loop over "options[]" twice: once for options with the + // P_PRI_MKRC flag and once without. for (pri = 1; pri >= 0; pri--) { for (p = &options[0]; p->fullname; p++) { if (!(p->flags & P_NO_MKRC) @@ -4400,10 +4353,8 @@ void buf_copy_options(buf_T *buf, int flags) int dont_do_help; int did_isk = false; - /* - * Skip this when the option defaults have not been set yet. Happens when - * main() allocates the first buffer. - */ + // Skip this when the option defaults have not been set yet. Happens when + // main() allocates the first buffer. if (p_cpo != NULL) { // // Always copy when entering and 'cpo' contains 'S'. @@ -4617,12 +4568,10 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_lw = empty_option; buf->b_p_menc = empty_option; - /* - * Don't copy the options set by ex_help(), use the saved values, - * when going from a help buffer to a non-help buffer. - * Don't touch these at all when BCO_NOHELP is used and going from - * or to a help buffer. - */ + // Don't copy the options set by ex_help(), use the saved values, + // when going from a help buffer to a non-help buffer. + // Don't touch these at all when BCO_NOHELP is used and going from + // or to a help buffer. if (dont_do_help) { buf->b_p_isk = (char *)save_p_isk; if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { @@ -4652,10 +4601,8 @@ void buf_copy_options(buf_T *buf, int flags) } } - /* - * When the options should be copied (ignoring BCO_ALWAYS), set the - * flag that indicates that the options have been initialized. - */ + // When the options should be copied (ignoring BCO_ALWAYS), set the + // flag that indicates that the options have been initialized. if (should_copy) { buf->b_p_initialized = true; } @@ -4947,9 +4894,7 @@ void ExpandOldSetting(int *num_file, char ***file) *num_file = 0; *file = xmalloc(sizeof(char_u *)); - /* - * For a terminal key code expand_option_idx is < 0. - */ + // For a terminal key code expand_option_idx is < 0. if (expand_option_idx < 0) { expand_option_idx = findoption((const char *)expand_option_name); } @@ -5055,10 +5000,8 @@ static void paste_option_changed(void) static int save_hkmap = 0; if (p_paste) { - /* - * Paste switched from off to on. - * Save the current values, so they can be restored later. - */ + // Paste switched from off to on. + // Save the current values, so they can be restored later. if (!old_p_paste) { // save options for each buffer FOR_ALL_BUFFERS(buf) { -- cgit From 73207cae611a1efb8cd17139e8228772daeb9866 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 12c2888f5c..e54e6080f0 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -420,7 +420,7 @@ void set_init_1(bool clean_arg) // use utf-8 as 'default' if locale encoding can't be detected. p = (char_u *)xmemdupz(S_LEN("utf-8")); } - fenc_default = p; + fenc_default = (char *)p; #ifdef HAVE_WORKING_LIBINTL // GNU gettext 0.10.37 supports this feature: set the codeset used for @@ -1129,9 +1129,9 @@ int do_set(char *arg, int opt_flags) opt_flags); } else if (opt_idx >= 0) { // String. char_u *save_arg = NULL; - char_u *s = NULL; + char *s = NULL; char_u *oldval = NULL; // previous value if *varp - char_u *newval; + char *newval; char_u *origval = NULL; char_u *origval_l = NULL; char_u *origval_g = NULL; @@ -1175,24 +1175,24 @@ int do_set(char *arg, int opt_flags) } if (nextchar == '&') { // set to default val - newval = options[opt_idx].def_val; + newval = (char *)options[opt_idx].def_val; // expand environment variables and ~ since the // default value was already expanded, only // required when an environment variable was set // later if (newval == NULL) { - newval = (char_u *)empty_option; + newval = empty_option; } else if (!(options[opt_idx].flags & P_NO_DEF_EXP)) { - s = option_expand(opt_idx, newval); + s = (char *)option_expand(opt_idx, (char_u *)newval); if (s == NULL) { s = newval; } - newval = vim_strsave(s); + newval = xstrdup(s); } else { - newval = (char_u *)xstrdup((char *)newval); + newval = xstrdup(newval); } } else if (nextchar == '<') { // set to global val - newval = vim_strsave(*(char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL)); + newval = xstrdup(*(char **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL)); } else { arg++; // jump to after the '=' or ':' @@ -1212,13 +1212,13 @@ int do_set(char *arg, int opt_flags) *(char **)varp = empty_option; break; case 1: - *(char_u **)varp = vim_strsave((char_u *)"indent,eol"); + *(char_u **)varp = (char_u *)xstrdup("indent,eol"); break; case 2: - *(char_u **)varp = vim_strsave((char_u *)"indent,eol,start"); + *(char_u **)varp = (char_u *)xstrdup("indent,eol,start"); break; case 3: - *(char_u **)varp = vim_strsave((char_u *)"indent,eol,nostop"); + *(char_u **)varp = (char_u *)xstrdup("indent,eol,nostop"); break; } xfree(oldval); @@ -1301,7 +1301,7 @@ int do_set(char *arg, int opt_flags) arg += i; s += i; } else { - *s++ = (uint8_t)(*arg++); + *s++ = *arg++; } } *s = NUL; @@ -1311,7 +1311,7 @@ int do_set(char *arg, int opt_flags) // comma. if (!(adding || prepending || removing) || (flags & P_COMMA)) { - s = option_expand(opt_idx, newval); + s = (char *)option_expand(opt_idx, (char_u *)newval); if (s != NULL) { xfree(newval); newlen = (unsigned)STRLEN(s) + 1; @@ -1328,7 +1328,7 @@ int do_set(char *arg, int opt_flags) i = 0; // init for GCC if (removing || (flags & P_NODUP)) { i = (int)STRLEN(newval); - s = find_dup_item(origval, newval, flags); + s = (char *)find_dup_item(origval, (char_u *)newval, flags); // do not add if already there if ((adding || prepending) && s != NULL) { @@ -1340,7 +1340,7 @@ int do_set(char *arg, int opt_flags) // if no duplicate, move pointer to end of // original value if (s == NULL) { - s = origval + (int)STRLEN(origval); + s = (char *)origval + (int)STRLEN(origval); } } @@ -1377,7 +1377,7 @@ int do_set(char *arg, int opt_flags) if (*s) { // may need to remove a comma if (flags & P_COMMA) { - if (s == origval) { + if (s == (char *)origval) { // include comma after string if (s[i] == ',') { i++; @@ -1388,7 +1388,7 @@ int do_set(char *arg, int opt_flags) i++; } } - STRMOVE(newval + (s - origval), s + i); + STRMOVE(newval + (s - (char *)origval), s + i); } } @@ -1399,14 +1399,14 @@ int do_set(char *arg, int opt_flags) // 'whichwrap' if (flags & P_ONECOMMA) { if (*s != ',' && *(s + 1) == ',' - && vim_strchr((char *)s + 2, *s) != NULL) { + && vim_strchr(s + 2, *s) != NULL) { // Remove the duplicated value and the next comma. STRMOVE(s, s + 2); continue; } } else { if ((!(flags & P_COMMA) || *s != ',') - && vim_strchr((char *)s + 1, *s) != NULL) { + && vim_strchr(s + 1, *s) != NULL) { STRMOVE(s, s + 1); continue; } @@ -1421,7 +1421,7 @@ int do_set(char *arg, int opt_flags) } // Set the new value. - *(char_u **)(varp) = newval; + *(char_u **)(varp) = (char_u *)newval; // origval may be freed by // did_set_string_option(), make a copy. @@ -1431,7 +1431,7 @@ int do_set(char *arg, int opt_flags) // newval (and varp) may become invalid if the // buffer is closed by autocommands. - saved_newval = (newval != NULL) ? xstrdup((char *)newval) : 0; + saved_newval = (newval != NULL) ? xstrdup(newval) : 0; { uint32_t *p = insecure_flag(curwin, opt_idx, opt_flags); @@ -4451,7 +4451,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_cpt = xstrdup(p_cpt); COPY_OPT_SCTX(buf, BV_CPT); #ifdef BACKSLASH_IN_FILENAME - buf->b_p_csl = vim_strsave(p_csl); + buf->b_p_csl = xstrdup(p_csl); COPY_OPT_SCTX(buf, BV_CSL); #endif buf->b_p_cfu = xstrdup(p_cfu); @@ -4826,7 +4826,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi int num_normal = 0; // Nr of matching non-term-code settings int match; int count = 0; - char_u *str; + char *str; int loop; static char *(names[]) = { "all" }; int ic = regmatch->rm_ic; // remember the ignore-case flag @@ -4848,7 +4848,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi } } } - for (size_t opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL; + for (size_t opt_idx = 0; (str = options[opt_idx].fullname) != NULL; opt_idx++) { if (options[opt_idx].var == NULL) { continue; @@ -4858,7 +4858,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi continue; } match = false; - if (vim_regexec(regmatch, (char *)str, (colnr_T)0) + if (vim_regexec(regmatch, str, (colnr_T)0) || (options[opt_idx].shortname != NULL && vim_regexec(regmatch, options[opt_idx].shortname, @@ -4870,7 +4870,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi if (loop == 0) { num_normal++; } else { - (*file)[count++] = (char *)vim_strsave(str); + (*file)[count++] = xstrdup(str); } } } @@ -4881,7 +4881,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi } else { return OK; } - *file = xmalloc((size_t)(*num_file) * sizeof(char_u *)); + *file = xmalloc((size_t)(*num_file) * sizeof(char *)); } } return OK; @@ -5230,7 +5230,7 @@ int fill_culopt_flags(char *val, win_T *wp) /// Set the callback function value for an option that accepts a function name, /// lambda, et al. (e.g. 'operatorfunc', 'tagfunc', etc.) /// @return OK if the option is successfully set to a function, otherwise FAIL -int option_set_callback_func(char_u *optval, Callback *optcb) +int option_set_callback_func(char *optval, Callback *optcb) { if (optval == NULL || *optval == NUL) { callback_free(optcb); @@ -5242,7 +5242,7 @@ int option_set_callback_func(char_u *optval, Callback *optcb) || (STRNCMP(optval, "function(", 9) == 0) || (STRNCMP(optval, "funcref(", 8) == 0)) { // Lambda expression or a funcref - tv = eval_expr((char *)optval); + tv = eval_expr(optval); if (tv == NULL) { return FAIL; } @@ -5250,7 +5250,7 @@ int option_set_callback_func(char_u *optval, Callback *optcb) // treat everything else as a function name string tv = xcalloc(1, sizeof(*tv)); tv->v_type = VAR_STRING; - tv->vval.v_string = (char *)vim_strsave(optval); + tv->vval.v_string = xstrdup(optval); } Callback cb; -- cgit From c5322e752e9e568de907f7a1ef733bbfe342140c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 64 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index e54e6080f0..dbc2102541 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -156,7 +156,7 @@ typedef struct vimoption { // buffer-local option: global value idopt_T indir; // global option: PV_NONE; // local option: indirect option index - char_u *def_val; // default values for variable (neovim!!) + char *def_val; // default values for variable (neovim!!) LastSet last_set; // script in which the option was last set } vimoption_T; @@ -290,7 +290,7 @@ void set_init_1(bool clean_arg) buf[j] = NUL; opt_idx = findoption("cdpath"); if (opt_idx >= 0) { - options[opt_idx].def_val = buf; + options[opt_idx].def_val = (char *)buf; options[opt_idx].flags |= P_DEF_ALLOCED; } else { xfree(buf); // cannot happen @@ -384,7 +384,7 @@ void set_init_1(bool clean_arg) && options[opt_idx].var != NULL) { p = _(*(char **)options[opt_idx].var); } else { - p = (char *)option_expand(opt_idx, NULL); + p = option_expand(opt_idx, NULL); } if (p != NULL) { p = xstrdup(p); @@ -392,7 +392,7 @@ void set_init_1(bool clean_arg) if (options[opt_idx].flags & P_DEF_ALLOCED) { xfree(options[opt_idx].def_val); } - options[opt_idx].def_val = (char_u *)p; + options[opt_idx].def_val = p; options[opt_idx].flags |= P_DEF_ALLOCED; } } @@ -449,12 +449,12 @@ static void set_option_default(int opt_idx, int opt_flags) // freeing and allocating the value. if (options[opt_idx].indir != PV_NONE) { set_string_option_direct(NULL, opt_idx, - (char *)options[opt_idx].def_val, opt_flags, 0); + options[opt_idx].def_val, opt_flags, 0); } else { if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) { free_string_option(*(char **)(varp)); } - *(char_u **)varp = options[opt_idx].def_val; + *(char **)varp = options[opt_idx].def_val; options[opt_idx].flags &= ~P_ALLOCED; } } else if (flags & P_NUM) { @@ -533,9 +533,7 @@ static void set_string_default(const char *name, char *val, bool allocated) xfree(options[opt_idx].def_val); } - options[opt_idx].def_val = allocated - ? (char_u *)val - : (char_u *)xstrdup(val); + options[opt_idx].def_val = allocated ? val : xstrdup(val); options[opt_idx].flags |= P_DEF_ALLOCED; } } @@ -579,7 +577,7 @@ void set_number_default(char *name, long val) opt_idx = findoption(name); if (opt_idx >= 0) { - options[opt_idx].def_val = (char_u *)(intptr_t)val; + options[opt_idx].def_val = (char *)(intptr_t)val; } } @@ -594,7 +592,7 @@ void free_all_options(void) free_string_option(*(char **)options[i].var); } if (options[i].flags & P_DEF_ALLOCED) { - free_string_option((char *)options[i].def_val); + free_string_option(options[i].def_val); } } else if (options[i].var != VAR_WIN && (options[i].flags & P_STRING)) { // buffer-local option: free global value @@ -648,7 +646,7 @@ void set_init_3(void) : !(options[idx_sp].flags & P_WAS_SET); size_t len = 0; - char *p = (char *)invocation_path_tail(p_sh, &len); + char *p = (char *)invocation_path_tail((char_u *)p_sh, &len); p = xstrnsave(p, len); { @@ -660,11 +658,11 @@ void set_init_3(void) || FNAMECMP(p, "tcsh") == 0) { if (do_sp) { p_sp = "|& tee"; - options[idx_sp].def_val = (char_u *)p_sp; + options[idx_sp].def_val = p_sp; } if (do_srr) { p_srr = ">&"; - options[idx_srr].def_val = (char_u *)p_srr; + options[idx_srr].def_val = p_srr; } } else if (FNAMECMP(p, "sh") == 0 || FNAMECMP(p, "ksh") == 0 @@ -679,11 +677,11 @@ void set_init_3(void) // Always use POSIX shell style redirection if we reach this if (do_sp) { p_sp = "2>&1| tee"; - options[idx_sp].def_val = (char_u *)p_sp; + options[idx_sp].def_val = p_sp; } if (do_srr) { p_srr = ">%s 2>&1"; - options[idx_srr].def_val = (char_u *)p_srr; + options[idx_srr].def_val = p_srr; } } xfree(p); @@ -747,12 +745,12 @@ void set_title_defaults(void) // not need to be contacted. idx1 = findoption("title"); if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) { - options[idx1].def_val = (char_u *)(intptr_t)0; + options[idx1].def_val = 0; p_title = 0; } idx1 = findoption("icon"); if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) { - options[idx1].def_val = (char_u *)(intptr_t)0; + options[idx1].def_val = 0; p_icon = 0; } } @@ -1175,7 +1173,7 @@ int do_set(char *arg, int opt_flags) } if (nextchar == '&') { // set to default val - newval = (char *)options[opt_idx].def_val; + newval = options[opt_idx].def_val; // expand environment variables and ~ since the // default value was already expanded, only // required when an environment variable was set @@ -1183,7 +1181,7 @@ int do_set(char *arg, int opt_flags) if (newval == NULL) { newval = empty_option; } else if (!(options[opt_idx].flags & P_NO_DEF_EXP)) { - s = (char *)option_expand(opt_idx, (char_u *)newval); + s = option_expand(opt_idx, newval); if (s == NULL) { s = newval; } @@ -1311,7 +1309,7 @@ int do_set(char *arg, int opt_flags) // comma. if (!(adding || prepending || removing) || (flags & P_COMMA)) { - s = (char *)option_expand(opt_idx, (char_u *)newval); + s = option_expand(opt_idx, newval); if (s != NULL) { xfree(newval); newlen = (unsigned)STRLEN(s) + 1; @@ -1683,7 +1681,7 @@ char_u *find_shada_parameter(int type) /// These string options cannot be indirect! /// If "val" is NULL expand the current value of the option. /// Return pointer to NameBuff, or NULL when not expanded. -static char_u *option_expand(int opt_idx, char_u *val) +static char *option_expand(int opt_idx, char *val) { // if option doesn't need expansion nothing to do if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL) { @@ -1691,7 +1689,7 @@ static char_u *option_expand(int opt_idx, char_u *val) } if (val == NULL) { - val = *(char_u **)options[opt_idx].var; + val = *(char **)options[opt_idx].var; } // If val is longer than MAXPATHL no meaningful expansion can be done, @@ -1704,15 +1702,15 @@ static char_u *option_expand(int opt_idx, char_u *val) // Escape spaces when expanding 'tags', they are used to separate file // names. // For 'spellsuggest' expand after "file:". - expand_env_esc(val, (char_u *)NameBuff, MAXPATHL, + expand_env_esc((char_u *)val, (char_u *)NameBuff, MAXPATHL, (char_u **)options[opt_idx].var == &p_tags, false, (char_u **)options[opt_idx].var == (char_u **)&p_sps ? (char_u *)"file:" : NULL); - if (STRCMP(NameBuff, val) == 0) { // they are the same + if (strcmp(NameBuff, val) == 0) { // they are the same return NULL; } - return (char_u *)NameBuff; + return NameBuff; } /// After setting various option values: recompute variables that depend on @@ -2133,7 +2131,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va // Arabic requires a utf-8 encoding, inform the user if it's not // set. - if (STRCMP(p_enc, "utf-8") != 0) { + if (strcmp(p_enc, "utf-8") != 0) { static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"); msg_source(HL_ATTR(HLF_W)); @@ -2758,7 +2756,7 @@ int findoption_len(const char *const arg, const size_t len) if (STRLEN(options[opt_idx].fullname) == 7) { return findoption_len("shada", 5); } - assert(STRCMP(options[opt_idx].fullname, "viminfofile") == 0); + assert(strcmp(options[opt_idx].fullname, "viminfofile") == 0); return findoption_len("shadafile", 9); } } @@ -3329,7 +3327,7 @@ static int optval_default(vimoption_T *p, char_u *varp) return *(int *)varp == (int)(intptr_t)p->def_val; } // P_STRING - return STRCMP(*(char_u **)varp, p->def_val) == 0; + return strcmp(*(char **)varp, p->def_val) == 0; } /// Send update to UIs with values of UI relevant options @@ -5309,7 +5307,7 @@ char_u *get_showbreak_value(win_T *const win) if (win->w_p_sbr == NULL || *win->w_p_sbr == NUL) { return (char_u *)p_sbr; } - if (STRCMP(win->w_p_sbr, "NONE") == 0) { + if (strcmp(win->w_p_sbr, "NONE") == 0) { return (char_u *)empty_option; } return (char_u *)win->w_p_sbr; @@ -5455,13 +5453,13 @@ size_t copy_option_part(char **option, char *buf, size_t maxlen, char *sep_chars /// Return true when 'shell' has "csh" in the tail. int csh_like_shell(void) { - return strstr(path_tail((char *)p_sh), "csh") != NULL; + return strstr(path_tail(p_sh), "csh") != NULL; } /// Return true when 'shell' has "fish" in the tail. bool fish_like_shell(void) { - return strstr(path_tail((char *)p_sh), "fish") != NULL; + return strstr(path_tail(p_sh), "fish") != NULL; } /// Return the number of requested sign columns, based on current @@ -5619,7 +5617,7 @@ static Dictionary vimoption2dict(vimoption_T *opt) const char *type; Object def; // TODO(bfredl): do you even nocp? - char_u *def_val = opt->def_val; + char_u *def_val = (char_u *)opt->def_val; if (opt->flags & P_STRING) { type = "string"; def = CSTR_TO_OBJ(def_val ? (char *)def_val : ""); -- cgit From 684bc749efef0fa31395d349f4495d79ec5f3fd5 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index dbc2102541..ab4db30aaf 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -654,8 +654,8 @@ void set_init_3(void) // Default for p_sp is "| tee", for p_srr is ">". // For known shells it is changed here to include stderr. // - if (FNAMECMP(p, "csh") == 0 - || FNAMECMP(p, "tcsh") == 0) { + if (path_fnamecmp(p, "csh") == 0 + || path_fnamecmp(p, "tcsh") == 0) { if (do_sp) { p_sp = "|& tee"; options[idx_sp].def_val = p_sp; @@ -664,16 +664,16 @@ void set_init_3(void) p_srr = ">&"; options[idx_srr].def_val = p_srr; } - } else if (FNAMECMP(p, "sh") == 0 - || FNAMECMP(p, "ksh") == 0 - || FNAMECMP(p, "mksh") == 0 - || FNAMECMP(p, "pdksh") == 0 - || FNAMECMP(p, "zsh") == 0 - || FNAMECMP(p, "zsh-beta") == 0 - || FNAMECMP(p, "bash") == 0 - || FNAMECMP(p, "fish") == 0 - || FNAMECMP(p, "ash") == 0 - || FNAMECMP(p, "dash") == 0) { + } else if (path_fnamecmp(p, "sh") == 0 + || path_fnamecmp(p, "ksh") == 0 + || path_fnamecmp(p, "mksh") == 0 + || path_fnamecmp(p, "pdksh") == 0 + || path_fnamecmp(p, "zsh") == 0 + || path_fnamecmp(p, "zsh-beta") == 0 + || path_fnamecmp(p, "bash") == 0 + || path_fnamecmp(p, "fish") == 0 + || path_fnamecmp(p, "ash") == 0 + || path_fnamecmp(p, "dash") == 0) { // Always use POSIX shell style redirection if we reach this if (do_sp) { p_sp = "2>&1| tee"; @@ -1237,19 +1237,19 @@ int do_set(char *arg, int opt_flags) *errbuf = NUL; i = getdigits_int(&arg, true, 0); if (i & 1) { - STRLCAT(errbuf, "b,", sizeof(errbuf)); + xstrlcat(errbuf, "b,", sizeof(errbuf)); } if (i & 2) { - STRLCAT(errbuf, "s,", sizeof(errbuf)); + xstrlcat(errbuf, "s,", sizeof(errbuf)); } if (i & 4) { - STRLCAT(errbuf, "h,l,", sizeof(errbuf)); + xstrlcat(errbuf, "h,l,", sizeof(errbuf)); } if (i & 8) { - STRLCAT(errbuf, "<,>,", sizeof(errbuf)); + xstrlcat(errbuf, "<,>,", sizeof(errbuf)); } if (i & 16) { - STRLCAT(errbuf, "[,],", sizeof(errbuf)); + xstrlcat(errbuf, "[,],", sizeof(errbuf)); } save_arg = (char_u *)arg; arg = errbuf; -- cgit From 3ff46544c9872b4161fd098569c30b55fe3abd36 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index ab4db30aaf..de9510cf8a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1266,7 +1266,7 @@ int do_set(char *arg, int opt_flags) // we need to remove the backslashes. // get a bit too much - newlen = (unsigned)STRLEN(arg) + 1; + newlen = (unsigned)strlen(arg) + 1; if (adding || prepending || removing) { newlen += (unsigned)STRLEN(origval) + 1; } @@ -1312,7 +1312,7 @@ int do_set(char *arg, int opt_flags) s = option_expand(opt_idx, newval); if (s != NULL) { xfree(newval); - newlen = (unsigned)STRLEN(s) + 1; + newlen = (unsigned)strlen(s) + 1; if (adding || prepending || removing) { newlen += (unsigned)STRLEN(origval) + 1; } @@ -1357,10 +1357,10 @@ int do_set(char *arg, int opt_flags) i--; } memmove(newval + i + comma, newval, - STRLEN(newval) + 1); + strlen(newval) + 1); memmove(newval, origval, (size_t)i); } else { - i = (int)STRLEN(newval); + i = (int)strlen(newval); STRMOVE(newval + i + comma, origval); } if (comma) { @@ -1507,7 +1507,7 @@ skip: if (errmsg != NULL) { STRLCPY(IObuff, _(errmsg), IOSIZE); - i = (int)STRLEN(IObuff) + 2; + i = (int)strlen(IObuff) + 2; if (i + (arg - startarg) < IOSIZE) { // append the argument with the error STRCAT(IObuff, ": "); @@ -1694,7 +1694,7 @@ static char *option_expand(int opt_idx, char *val) // If val is longer than MAXPATHL no meaningful expansion can be done, // expand_env() would truncate the string. - if (val == NULL || STRLEN(val) > MAXPATHL) { + if (val == NULL || strlen(val) > MAXPATHL) { return NULL; } @@ -2753,7 +2753,7 @@ int findoption_len(const char *const arg, const size_t len) } else { // Nvim: handle option aliases. if (STRNCMP(options[opt_idx].fullname, "viminfo", 7) == 0) { - if (STRLEN(options[opt_idx].fullname) == 7) { + if (strlen(options[opt_idx].fullname) == 7) { return findoption_len("shada", 5); } assert(strcmp(options[opt_idx].fullname, "viminfofile") == 0); @@ -3274,7 +3274,7 @@ static void showoptions(int all, int opt_flags) len = 1; // a toggle option fits always } else { option_value2string(p, opt_flags); - len = (int)STRLEN(p->fullname) + vim_strsize((char *)NameBuff) + 1; + len = (int)strlen(p->fullname) + vim_strsize((char *)NameBuff) + 1; } if ((len <= INC - GAP && run == 1) || (len > INC - GAP && run == 2)) { @@ -3565,7 +3565,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ } } } else if ((flags & P_EXPAND) != 0) { - size_t size = (size_t)STRLEN(*valuep) + 1; + size_t size = (size_t)strlen(*valuep) + 1; // replace home directory in the whole option value into "buf" buf = xmalloc(size); -- cgit From 907fc8ac373226556b84c2fdc4fe26525bbdb2c4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 13 Sep 2022 06:23:33 +0800 Subject: vim-patch:9.0.0449: there is no easy way to translate a key code into a string (#20168) Problem: There is no easy way to translate a string with a key code into a readable string. Solution: Add the keytrans() function. (closes vim/vim#11114) https://github.com/vim/vim/commit/cdc839353f68ca43db6446e1b727fc7ba657b738 vim-patch:7b2d87220c6c Add missing part of patch https://github.com/vim/vim/commit/7b2d87220c6c974d5cdae672b6f9620a6bcbd1dc --- src/nvim/option.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index de9510cf8a..5adec084e6 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3558,9 +3558,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ if (valuep == &p_pt) { s = (char_u *)(*valuep); while (*s != NUL) { - if (put_escstr(fd, (char_u *)str2special((const char **)&s, false, - false), 2) - == FAIL) { + if (put_escstr(fd, (char_u *)str2special((const char **)&s, false, false), 2) == FAIL) { return FAIL; } } -- cgit From 708bd686516b420c2b65f4bc4d2c58fe43fb945e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 13 Sep 2022 12:56:30 +0200 Subject: feat(ui): use msg_grid based implementation for cmdheight=0 --- src/nvim/option.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 5adec084e6..8ef06bcba8 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2570,9 +2570,10 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, Rows = (int)p_lines; Columns = (int)p_columns; check_screensize(); - if (cmdline_row > Rows - p_ch && Rows > p_ch) { - assert(p_ch >= 0 && Rows - p_ch <= INT_MAX); - cmdline_row = (int)(Rows - p_ch); + int new_row = (int)(Rows - MAX(p_ch, 1)); + if (cmdline_row > new_row && Rows > p_ch) { + assert(p_ch >= 0 && new_row <= INT_MAX); + cmdline_row = new_row; } } if (p_window >= Rows || !option_was_set("window")) { -- cgit From 18139a69bc048aebe592df7a633793bfb9cbea39 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 17 Sep 2022 15:39:04 +0800 Subject: vim-patch:8.2.0690: line number of option set by modeline is wrong (#20228) Problem: Line number of option set by modeline is wrong. Solution: Do not double the line number. (Ozaki Kiichi, closes vim/vim#6035) https://github.com/vim/vim/commit/5125874951669944a5f6a4163d6e5d437ae6321e --- src/nvim/option.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 8ef06bcba8..a772b85826 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1891,15 +1891,16 @@ void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx) int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; int indir = (int)options[opt_idx].indir; nlua_set_sctx(&script_ctx); - const LastSet last_set = { - .script_ctx = { - script_ctx.sc_sid, - script_ctx.sc_seq, - script_ctx.sc_lnum + SOURCING_LNUM - }, - current_channel_id + LastSet last_set = { + .script_ctx = script_ctx, + .channel_id = current_channel_id, }; + // Modeline already has the line number set. + if (!(opt_flags & OPT_MODELINE)) { + last_set.script_ctx.sc_lnum += SOURCING_LNUM; + } + // Remember where the option was set. For local options need to do that // in the buffer or window structure. if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0) { -- cgit From 6d557e324fd4223fff3279a0112f40431c540163 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 18 Sep 2022 03:17:15 +0200 Subject: vim-patch:8.1.0941: macros for MS-Windows are inconsistent (#20215) Problem: Macros for MS-Windows are inconsistent, using "32", "3264 and others. Solution: Use MSWIN for all MS-Windows builds. Use FEAT_GUI_MSWIN for the GUI build. (Hirohito Higashi, closes vim/vim#3932) https://github.com/vim/vim/commit/4f97475d326c2773a78561fb874e4f23c25cbcd9 --- src/nvim/option.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index a772b85826..0381baa635 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -83,7 +83,7 @@ #include "nvim/undo.h" #include "nvim/vim.h" #include "nvim/window.h" -#ifdef WIN32 +#ifdef MSWIN # include "nvim/os/pty_conpty_win.h" #endif #include "nvim/api/extmark.h" @@ -1274,7 +1274,7 @@ int do_set(char *arg, int opt_flags) s = newval; // Copy the string, skip over escaped chars. - // For WIN32 backslashes before normal + // For MS-Windows backslashes before normal // file name characters are not removed, and keep // backslash at start, for "\\machine\path", but // do remove it for "\\\\machine\\path". -- cgit From 71e70d0c9919f1ab25fe3940b32ce549f49b30e8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 09:43:37 +0800 Subject: vim-patch:9.0.0537: the do_set() function is much too long (#20274) Problem: The do_set() function is much too long. Solution: Move setting of a string option to a separate function. https://github.com/vim/vim/commit/4740394f230dda09d6e9337465305741d8ee4fa3 Cherry-pick some tests from Vim patch 8.2.0540. --- src/nvim/option.c | 727 +++++++++++++++++++++++++++--------------------------- 1 file changed, 365 insertions(+), 362 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 0381baa635..2a45f3b38b 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -173,6 +173,13 @@ typedef struct vimoption { #define OPTION_COUNT ARRAY_SIZE(options) +typedef enum { + OP_NONE = 0, + OP_ADDING, ///< "opt+=arg" + OP_PREPENDING, ///< "opt^=arg" + OP_REMOVING, ///< "opt-=arg" +} set_op_T; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "option.c.generated.h" #endif @@ -770,6 +777,349 @@ void ex_set(exarg_T *eap) (void)do_set(eap->arg, flags); } +/// Part of do_set() for string options. +/// @return FAIL on failure, do not process further options. +static int do_set_string(int opt_idx, int opt_flags, char **arg, int nextchar, set_op_T op_arg, + uint32_t flags, char *varp_arg, char *errbuf, size_t errbuflen, + int *value_checked, char **errmsg) +{ + set_op_T op = op_arg; + char *varp = varp_arg; + char *save_arg = NULL; + char *s = NULL; + char_u *oldval = NULL; // previous value if *varp + char *newval; + char_u *origval = NULL; + char_u *origval_l = NULL; + char_u *origval_g = NULL; + char *saved_origval = NULL; + char *saved_origval_l = NULL; + char *saved_origval_g = NULL; + char *saved_newval = NULL; + unsigned newlen; + int comma; + char whichwrap[80]; + + // When using ":set opt=val" for a global option + // with a local value the local value will be + // reset, use the global value here. + if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 + && ((int)options[opt_idx].indir & PV_BOTH)) { + varp = (char *)options[opt_idx].var; + } + + // The old value is kept until we are sure that the new value is valid. + oldval = *(char_u **)varp; + + if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) { + origval_l = *(char_u **)get_varp_scope(&(options[opt_idx]), OPT_LOCAL); + origval_g = *(char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); + + // A global-local string option might have an empty option as value to + // indicate that the global value should be used. + if (((int)options[opt_idx].indir & PV_BOTH) && origval_l == (char_u *)empty_option) { + origval_l = origval_g; + } + } + + // When setting the local value of a global option, the old value may be + // the global value. + if (((int)options[opt_idx].indir & PV_BOTH) && (opt_flags & OPT_LOCAL)) { + origval = *(char_u **)get_varp(&options[opt_idx]); + } else { + origval = oldval; + } + + if (nextchar == '&') { // set to default val + newval = options[opt_idx].def_val; + // expand environment variables and ~ since the default value was + // already expanded, only required when an environment variable was set + // later + if (newval == NULL) { + newval = empty_option; + } else if (!(options[opt_idx].flags & P_NO_DEF_EXP)) { + s = option_expand(opt_idx, newval); + if (s == NULL) { + s = newval; + } + newval = xstrdup(s); + } else { + newval = xstrdup(newval); + } + } else if (nextchar == '<') { // set to global val + newval = xstrdup(*(char **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL)); + } else { + (*arg)++; // jump to after the '=' or ':' + + // Set 'keywordprg' to ":help" if an empty + // value was passed to :set by the user. + // Misuse errbuf[] for the resulting string. + if (varp == (char *)&p_kp && (**arg == NUL || **arg == ' ')) { + STRCPY(errbuf, ":help"); + save_arg = *arg; + *arg = errbuf; + } else if (varp == (char *)&p_bs && ascii_isdigit(**(char_u **)varp)) { + // Convert 'backspace' number to string, for + // adding, prepending and removing string. + int i = getdigits_int((char **)varp, true, 0); + switch (i) { + case 0: + *(char **)varp = empty_option; + break; + case 1: + *(char_u **)varp = (char_u *)xstrdup("indent,eol"); + break; + case 2: + *(char_u **)varp = (char_u *)xstrdup("indent,eol,start"); + break; + case 3: + *(char_u **)varp = (char_u *)xstrdup("indent,eol,nostop"); + break; + } + xfree(oldval); + if (origval == oldval) { + origval = *(char_u **)varp; + } + if (origval_l == oldval) { + origval_l = *(char_u **)varp; + } + if (origval_g == oldval) { + origval_g = *(char_u **)varp; + } + oldval = *(char_u **)varp; + } else if (varp == (char *)&p_ww && ascii_isdigit(**arg)) { + // Convert 'whichwrap' number to string, for backwards compatibility + // with Vim 3.0. + *whichwrap = NUL; + int i = getdigits_int(arg, true, 0); + if (i & 1) { + xstrlcat(whichwrap, "b,", sizeof(whichwrap)); + } + if (i & 2) { + xstrlcat(whichwrap, "s,", sizeof(whichwrap)); + } + if (i & 4) { + xstrlcat(whichwrap, "h,l,", sizeof(whichwrap)); + } + if (i & 8) { + xstrlcat(whichwrap, "<,>,", sizeof(whichwrap)); + } + if (i & 16) { + xstrlcat(whichwrap, "[,],", sizeof(whichwrap)); + } + if (*whichwrap != NUL) { // remove trailing , + whichwrap[strlen(whichwrap) - 1] = NUL; + } + save_arg = *arg; + *arg = whichwrap; + } else if (**arg == '>' && (varp == (char *)&p_dir || varp == (char *)&p_bdir)) { + // Remove '>' before 'dir' and 'bdir', for backwards compatibility with + // version 3.0 + (*arg)++; + } + + // Copy the new string into allocated memory. + // Can't use set_string_option_direct(), because we need to remove the + // backslashes. + + // get a bit too much + newlen = (unsigned)strlen(*arg) + 1; + if (op != OP_NONE) { + newlen += (unsigned)STRLEN(origval) + 1; + } + newval = xmalloc(newlen); + s = newval; + + // Copy the string, skip over escaped chars. + // For MS-Windows backslashes before normal file name characters + // are not removed, and keep backslash at start, for "\\machine\path", + // but do remove it for "\\\\machine\\path". + // The reverse is found in ExpandOldSetting(). + while (**arg && !ascii_iswhite(**arg)) { + if (**arg == '\\' && (*arg)[1] != NUL +#ifdef BACKSLASH_IN_FILENAME + && !((flags & P_EXPAND) + && vim_isfilec((*arg)[1]) + && !ascii_iswhite((*arg)[1]) + && ((*arg)[1] != '\\' + || (s == newval && (*arg)[2] != '\\'))) +#endif + ) { + (*arg)++; // remove backslash + } + int i = utfc_ptr2len(*arg); + if (i > 1) { + // copy multibyte char + memmove(s, *arg, (size_t)i); + *arg += i; + s += i; + } else { + *s++ = *(*arg)++; + } + } + *s = NUL; + + // Expand environment variables and ~. + // Don't do it when adding without inserting a comma. + if (op == OP_NONE || (flags & P_COMMA)) { + s = option_expand(opt_idx, newval); + if (s != NULL) { + xfree(newval); + newlen = (unsigned)strlen(s) + 1; + if (op != OP_NONE) { + newlen += (unsigned)STRLEN(origval) + 1; + } + newval = xmalloc(newlen); + STRCPY(newval, s); + } + } + + // locate newval[] in origval[] when removing it + // and when adding to avoid duplicates + int len = 0; + if (op == OP_REMOVING || (flags & P_NODUP)) { + len = (int)STRLEN(newval); + s = (char *)find_dup_item(origval, (char_u *)newval, flags); + + // do not add if already there + if ((op == OP_ADDING || op == OP_PREPENDING) && s != NULL) { + op = OP_NONE; + STRCPY(newval, origval); + } + + // if no duplicate, move pointer to end of original value + if (s == NULL) { + s = (char *)origval + (int)STRLEN(origval); + } + } + + // concatenate the two strings; add a ',' if needed + if (op == OP_ADDING || op == OP_PREPENDING) { + comma = ((flags & P_COMMA) && *origval != NUL && *newval != NUL); + if (op == OP_ADDING) { + len = (int)STRLEN(origval); + // Strip a trailing comma, would get 2. + if (comma && len > 1 + && (flags & P_ONECOMMA) == P_ONECOMMA + && origval[len - 1] == ',' + && origval[len - 2] != '\\') { + len--; + } + memmove(newval + len + comma, newval, strlen(newval) + 1); + memmove(newval, origval, (size_t)len); + } else { + len = (int)strlen(newval); + STRMOVE(newval + len + comma, origval); + } + if (comma) { + newval[len] = ','; + } + } + + // Remove newval[] from origval[]. (Note: "len" has been set above and + // is used here). + if (op == OP_REMOVING) { + STRCPY(newval, origval); + if (*s) { + // may need to remove a comma + if (flags & P_COMMA) { + if (s == (char *)origval) { + // include comma after string + if (s[len] == ',') { + len++; + } + } else { + // include comma before string + s--; + len++; + } + } + STRMOVE(newval + (s - (char *)origval), s + len); + } + } + + if (flags & P_FLAGLIST) { + // Remove flags that appear twice. + for (s = newval; *s;) { + // if options have P_FLAGLIST and P_ONECOMMA such as + // 'whichwrap' + if (flags & P_ONECOMMA) { + if (*s != ',' && *(s + 1) == ',' + && vim_strchr(s + 2, *s) != NULL) { + // Remove the duplicated value and the next comma. + STRMOVE(s, s + 2); + continue; + } + } else { + if ((!(flags & P_COMMA) || *s != ',') + && vim_strchr(s + 1, *s) != NULL) { + STRMOVE(s, s + 1); + continue; + } + } + s++; + } + } + + if (save_arg != NULL) { // number for 'whichwrap' + *arg = save_arg; + } + } + + // Set the new value. + *(char_u **)(varp) = (char_u *)newval; + + // origval may be freed by did_set_string_option(), make a copy. + saved_origval = (origval != NULL) ? xstrdup((char *)origval) : NULL; + saved_origval_l = (origval_l != NULL) ? xstrdup((char *)origval_l) : NULL; + saved_origval_g = (origval_g != NULL) ? xstrdup((char *)origval_g) : NULL; + + // newval (and varp) may become invalid if the buffer is closed by + // autocommands. + saved_newval = (newval != NULL) ? xstrdup(newval) : NULL; + + { + uint32_t *p = insecure_flag(curwin, opt_idx, opt_flags); + const int secure_saved = secure; + + // When an option is set in the sandbox, from a modeline or in secure + // mode, then deal with side effects in secure mode. Also when the + // value was set with the P_INSECURE flag and is not completely + // replaced. + if ((opt_flags & OPT_MODELINE) + || sandbox != 0 + || (op != OP_NONE && (*p & P_INSECURE))) { + secure = 1; + } + + // Handle side effects, and set the global value for ":set" on local + // options. Note: when setting 'syntax' or 'filetype' autocommands may + // be triggered that can cause havoc. + *errmsg = did_set_string_option(opt_idx, (char **)varp, (char *)oldval, + errbuf, errbuflen, + opt_flags, value_checked); + + secure = secure_saved; + } + + if (*errmsg == NULL) { + if (!starting) { + trigger_optionsset_string(opt_idx, opt_flags, saved_origval, saved_origval_l, + saved_origval_g, saved_newval); + } + if (options[opt_idx].flags & P_UI_OPTION) { + ui_call_option_set(cstr_as_string(options[opt_idx].fullname), + STRING_OBJ(cstr_as_string(saved_newval))); + } + } + xfree(saved_origval); + xfree(saved_origval_l); + xfree(saved_origval_g); + xfree(saved_newval); + + return *errmsg == NULL ? OK : FAIL; +} + /// Parse 'arg' for option settings. /// /// 'arg' may be IObuff, but only when no errors can be present and option @@ -801,9 +1151,7 @@ int do_set(char *arg, int opt_flags) uint32_t flags; // flags for current option char *varp = NULL; // pointer to variable for current option int did_show = false; // already showed one value - int adding; // "opt+=arg" - int prepending; // "opt^=arg" - int removing; // "opt-=arg" + set_op_T op = 0; if (*arg == NUL) { showoptions(0, opt_flags); @@ -890,18 +1238,16 @@ int do_set(char *arg, int opt_flags) len++; } - adding = false; - prepending = false; - removing = false; + op = OP_NONE; if (arg[len] != NUL && arg[len + 1] == '=') { if (arg[len] == '+') { - adding = true; // "+=" + op = OP_ADDING; // "+=" len++; } else if (arg[len] == '^') { - prepending = true; // "^=" + op = OP_PREPENDING; // "^=" len++; } else if (arg[len] == '-') { - removing = true; // "-=" + op = OP_REMOVING; // "-=" len++; } } @@ -1024,7 +1370,6 @@ int do_set(char *arg, int opt_flags) errmsg = e_trailing; } } else { - int value_is_replaced = !prepending && !adding && !removing; int value_checked = false; if (flags & P_BOOL) { // boolean @@ -1113,368 +1458,26 @@ int do_set(char *arg, int opt_flags) goto skip; } - if (adding) { + if (op == OP_ADDING) { value = *(long *)varp + value; } - if (prepending) { + if (op == OP_PREPENDING) { value = *(long *)varp * value; } - if (removing) { + if (op == OP_REMOVING) { value = *(long *)varp - value; } errmsg = set_num_option(opt_idx, (char_u *)varp, (long)value, errbuf, sizeof(errbuf), opt_flags); } else if (opt_idx >= 0) { // String. - char_u *save_arg = NULL; - char *s = NULL; - char_u *oldval = NULL; // previous value if *varp - char *newval; - char_u *origval = NULL; - char_u *origval_l = NULL; - char_u *origval_g = NULL; - char *saved_origval = NULL; - char *saved_origval_l = NULL; - char *saved_origval_g = NULL; - char *saved_newval = NULL; - unsigned newlen; - int comma; - - // When using ":set opt=val" for a global option - // with a local value the local value will be - // reset, use the global value here. - if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 - && ((int)options[opt_idx].indir & PV_BOTH)) { - varp = (char *)options[opt_idx].var; - } - - // The old value is kept until we are sure that the - // new value is valid. - oldval = *(char_u **)varp; - - if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) { - origval_l = *(char_u **)get_varp_scope(&(options[opt_idx]), OPT_LOCAL); - origval_g = *(char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); - - // A global-local string option might have an empty - // option as value to indicate that the global - // value should be used. - if (((int)options[opt_idx].indir & PV_BOTH) && origval_l == (char_u *)empty_option) { - origval_l = origval_g; - } - } - - // When setting the local value of a global - // option, the old value may be the global value. - if (((int)options[opt_idx].indir & PV_BOTH) && (opt_flags & OPT_LOCAL)) { - origval = *(char_u **)get_varp(&options[opt_idx]); - } else { - origval = oldval; - } - - if (nextchar == '&') { // set to default val - newval = options[opt_idx].def_val; - // expand environment variables and ~ since the - // default value was already expanded, only - // required when an environment variable was set - // later - if (newval == NULL) { - newval = empty_option; - } else if (!(options[opt_idx].flags & P_NO_DEF_EXP)) { - s = option_expand(opt_idx, newval); - if (s == NULL) { - s = newval; - } - newval = xstrdup(s); - } else { - newval = xstrdup(newval); - } - } else if (nextchar == '<') { // set to global val - newval = xstrdup(*(char **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL)); - } else { - arg++; // jump to after the '=' or ':' - - // Set 'keywordprg' to ":help" if an empty - // value was passed to :set by the user. - // Misuse errbuf[] for the resulting string. - if (varp == (char *)&p_kp && (*arg == NUL || *arg == ' ')) { - STRCPY(errbuf, ":help"); - save_arg = (char_u *)arg; - arg = errbuf; - } else if (varp == (char *)&p_bs && ascii_isdigit(**(char_u **)varp)) { - // Convert 'backspace' number to string, for - // adding, prepending and removing string. - i = getdigits_int((char **)varp, true, 0); - switch (i) { - case 0: - *(char **)varp = empty_option; - break; - case 1: - *(char_u **)varp = (char_u *)xstrdup("indent,eol"); - break; - case 2: - *(char_u **)varp = (char_u *)xstrdup("indent,eol,start"); - break; - case 3: - *(char_u **)varp = (char_u *)xstrdup("indent,eol,nostop"); - break; - } - xfree(oldval); - if (origval == oldval) { - origval = *(char_u **)varp; - } - if (origval_l == oldval) { - origval_l = *(char_u **)varp; - } - if (origval_g == oldval) { - origval_g = *(char_u **)varp; - } - oldval = *(char_u **)varp; - } else if (varp == (char *)&p_ww && ascii_isdigit(*arg)) { - // Convert 'whichwrap' number to string, for - // backwards compatibility with Vim 3.0. - // Misuse errbuf[] for the resulting string. - *errbuf = NUL; - i = getdigits_int(&arg, true, 0); - if (i & 1) { - xstrlcat(errbuf, "b,", sizeof(errbuf)); - } - if (i & 2) { - xstrlcat(errbuf, "s,", sizeof(errbuf)); - } - if (i & 4) { - xstrlcat(errbuf, "h,l,", sizeof(errbuf)); - } - if (i & 8) { - xstrlcat(errbuf, "<,>,", sizeof(errbuf)); - } - if (i & 16) { - xstrlcat(errbuf, "[,],", sizeof(errbuf)); - } - save_arg = (char_u *)arg; - arg = errbuf; - } else if (*arg == '>' - && (varp == (char *)&p_dir - || varp == (char *)&p_bdir)) { - // Remove '>' before 'dir' and 'bdir', for - // backwards compatibility with version 3.0 - arg++; - } - - // Copy the new string into allocated memory. - // Can't use set_string_option_direct(), because - // we need to remove the backslashes. - - // get a bit too much - newlen = (unsigned)strlen(arg) + 1; - if (adding || prepending || removing) { - newlen += (unsigned)STRLEN(origval) + 1; - } - newval = xmalloc(newlen); - s = newval; - - // Copy the string, skip over escaped chars. - // For MS-Windows backslashes before normal - // file name characters are not removed, and keep - // backslash at start, for "\\machine\path", but - // do remove it for "\\\\machine\\path". - // The reverse is found in ExpandOldSetting(). - while (*arg && !ascii_iswhite(*arg)) { - if (*arg == '\\' && arg[1] != NUL -#ifdef BACKSLASH_IN_FILENAME - && !((flags & P_EXPAND) - && vim_isfilec(arg[1]) - && !ascii_iswhite(arg[1]) - && (arg[1] != '\\' - || (s == newval - && arg[2] != '\\'))) -#endif - ) { - arg++; // remove backslash - } - i = utfc_ptr2len(arg); - if (i > 1) { - // copy multibyte char - memmove(s, arg, (size_t)i); - arg += i; - s += i; - } else { - *s++ = *arg++; - } - } - *s = NUL; - - // Expand environment variables and ~. - // Don't do it when adding without inserting a - // comma. - if (!(adding || prepending || removing) - || (flags & P_COMMA)) { - s = option_expand(opt_idx, newval); - if (s != NULL) { - xfree(newval); - newlen = (unsigned)strlen(s) + 1; - if (adding || prepending || removing) { - newlen += (unsigned)STRLEN(origval) + 1; - } - newval = xmalloc(newlen); - STRCPY(newval, s); - } - } - - // locate newval[] in origval[] when removing it - // and when adding to avoid duplicates - i = 0; // init for GCC - if (removing || (flags & P_NODUP)) { - i = (int)STRLEN(newval); - s = (char *)find_dup_item(origval, (char_u *)newval, flags); - - // do not add if already there - if ((adding || prepending) && s != NULL) { - prepending = false; - adding = false; - STRCPY(newval, origval); - } - - // if no duplicate, move pointer to end of - // original value - if (s == NULL) { - s = (char *)origval + (int)STRLEN(origval); - } - } - - // concatenate the two strings; add a ',' if - // needed - if (adding || prepending) { - comma = ((flags & P_COMMA) && *origval != NUL - && *newval != NUL); - if (adding) { - i = (int)STRLEN(origval); - // Strip a trailing comma, would get 2. - if (comma && i > 1 - && (flags & P_ONECOMMA) == P_ONECOMMA - && origval[i - 1] == ',' - && origval[i - 2] != '\\') { - i--; - } - memmove(newval + i + comma, newval, - strlen(newval) + 1); - memmove(newval, origval, (size_t)i); - } else { - i = (int)strlen(newval); - STRMOVE(newval + i + comma, origval); - } - if (comma) { - newval[i] = ','; - } - } - - // Remove newval[] from origval[]. (Note: "i" has - // been set above and is used here). - if (removing) { - STRCPY(newval, origval); - if (*s) { - // may need to remove a comma - if (flags & P_COMMA) { - if (s == (char *)origval) { - // include comma after string - if (s[i] == ',') { - i++; - } - } else { - // include comma before string - s--; - i++; - } - } - STRMOVE(newval + (s - (char *)origval), s + i); - } - } - - if (flags & P_FLAGLIST) { - // Remove flags that appear twice. - for (s = newval; *s;) { - // if options have P_FLAGLIST and P_ONECOMMA such as - // 'whichwrap' - if (flags & P_ONECOMMA) { - if (*s != ',' && *(s + 1) == ',' - && vim_strchr(s + 2, *s) != NULL) { - // Remove the duplicated value and the next comma. - STRMOVE(s, s + 2); - continue; - } - } else { - if ((!(flags & P_COMMA) || *s != ',') - && vim_strchr(s + 1, *s) != NULL) { - STRMOVE(s, s + 1); - continue; - } - } - s++; - } - } - - if (save_arg != NULL) { // number for 'whichwrap' - arg = (char *)save_arg; - } - } - - // Set the new value. - *(char_u **)(varp) = (char_u *)newval; - - // origval may be freed by - // did_set_string_option(), make a copy. - saved_origval = (origval != NULL) ? xstrdup((char *)origval) : 0; - saved_origval_l = (origval_l != NULL) ? xstrdup((char *)origval_l) : 0; - saved_origval_g = (origval_g != NULL) ? xstrdup((char *)origval_g) : 0; - - // newval (and varp) may become invalid if the - // buffer is closed by autocommands. - saved_newval = (newval != NULL) ? xstrdup(newval) : 0; - - { - uint32_t *p = insecure_flag(curwin, opt_idx, opt_flags); - const int secure_saved = secure; - - // When an option is set in the sandbox, from a - // modeline or in secure mode, then deal with side - // effects in secure mode. Also when the value was - // set with the P_INSECURE flag and is not - // completely replaced. - if ((opt_flags & OPT_MODELINE) - || sandbox != 0 - || (!value_is_replaced && (*p & P_INSECURE))) { - secure = 1; - } - - // Handle side effects, and set the global value - // for ":set" on local options. Note: when setting - // 'syntax' or 'filetype' autocommands may be - // triggered that can cause havoc. - errmsg = did_set_string_option(opt_idx, (char **)varp, (char *)oldval, - errbuf, sizeof(errbuf), - opt_flags, &value_checked); - - secure = secure_saved; - } - - if (errmsg == NULL) { - if (!starting) { - trigger_optionsset_string(opt_idx, opt_flags, saved_origval, saved_origval_l, - saved_origval_g, saved_newval); - } - if (options[opt_idx].flags & P_UI_OPTION) { - ui_call_option_set(cstr_as_string(options[opt_idx].fullname), - STRING_OBJ(cstr_as_string(saved_newval))); + if (do_set_string(opt_idx, opt_flags, &arg, nextchar, + op, flags, varp, errbuf, sizeof(errbuf), + &value_checked, &errmsg) == FAIL) { + if (errmsg != NULL) { + goto skip; } - } - xfree(saved_origval); - xfree(saved_origval_l); - xfree(saved_origval_g); - xfree(saved_newval); - - // If error detected, print the error message. - if (errmsg != NULL) { - goto skip; + break; } } else { // key code option(FIXME(tarruda): Show a warning or something @@ -1483,7 +1486,7 @@ int do_set(char *arg, int opt_flags) } if (opt_idx >= 0) { - did_set_option(opt_idx, opt_flags, value_is_replaced, value_checked); + did_set_option(opt_idx, opt_flags, op == OP_NONE, value_checked); } } -- cgit From 33f147147224010cd11a4d4fe5c88d7773a709ac Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 21:05:29 +0800 Subject: vim-patch:9.0.0540: assigning stack variable to argument confuses Coverity Problem: Assigning stack variable to argument confuses Coverity. Solution: Use a local pointer, also makes the code simpler. https://github.com/vim/vim/commit/6f98114e4a5db3917c4f9d2fec09e11b4b0d0be5 --- src/nvim/option.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 2a45f3b38b..62e4e74f2d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -779,10 +779,11 @@ void ex_set(exarg_T *eap) /// Part of do_set() for string options. /// @return FAIL on failure, do not process further options. -static int do_set_string(int opt_idx, int opt_flags, char **arg, int nextchar, set_op_T op_arg, +static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, set_op_T op_arg, uint32_t flags, char *varp_arg, char *errbuf, size_t errbuflen, int *value_checked, char **errmsg) { + char *arg = *argp; set_op_T op = op_arg; char *varp = varp_arg; char *save_arg = NULL; @@ -849,15 +850,15 @@ static int do_set_string(int opt_idx, int opt_flags, char **arg, int nextchar, s } else if (nextchar == '<') { // set to global val newval = xstrdup(*(char **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL)); } else { - (*arg)++; // jump to after the '=' or ':' + arg++; // jump to after the '=' or ':' // Set 'keywordprg' to ":help" if an empty // value was passed to :set by the user. // Misuse errbuf[] for the resulting string. - if (varp == (char *)&p_kp && (**arg == NUL || **arg == ' ')) { + if (varp == (char *)&p_kp && (*arg == NUL || *arg == ' ')) { STRCPY(errbuf, ":help"); - save_arg = *arg; - *arg = errbuf; + save_arg = arg; + arg = errbuf; } else if (varp == (char *)&p_bs && ascii_isdigit(**(char_u **)varp)) { // Convert 'backspace' number to string, for // adding, prepending and removing string. @@ -887,11 +888,11 @@ static int do_set_string(int opt_idx, int opt_flags, char **arg, int nextchar, s origval_g = *(char_u **)varp; } oldval = *(char_u **)varp; - } else if (varp == (char *)&p_ww && ascii_isdigit(**arg)) { + } else if (varp == (char *)&p_ww && ascii_isdigit(*arg)) { // Convert 'whichwrap' number to string, for backwards compatibility // with Vim 3.0. *whichwrap = NUL; - int i = getdigits_int(arg, true, 0); + int i = getdigits_int(&arg, true, 0); if (i & 1) { xstrlcat(whichwrap, "b,", sizeof(whichwrap)); } @@ -910,12 +911,12 @@ static int do_set_string(int opt_idx, int opt_flags, char **arg, int nextchar, s if (*whichwrap != NUL) { // remove trailing , whichwrap[strlen(whichwrap) - 1] = NUL; } - save_arg = *arg; - *arg = whichwrap; - } else if (**arg == '>' && (varp == (char *)&p_dir || varp == (char *)&p_bdir)) { + save_arg = arg; + arg = whichwrap; + } else if (*arg == '>' && (varp == (char *)&p_dir || varp == (char *)&p_bdir)) { // Remove '>' before 'dir' and 'bdir', for backwards compatibility with // version 3.0 - (*arg)++; + arg++; } // Copy the new string into allocated memory. @@ -923,7 +924,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **arg, int nextchar, s // backslashes. // get a bit too much - newlen = (unsigned)strlen(*arg) + 1; + newlen = (unsigned)strlen(arg) + 1; if (op != OP_NONE) { newlen += (unsigned)STRLEN(origval) + 1; } @@ -935,26 +936,26 @@ static int do_set_string(int opt_idx, int opt_flags, char **arg, int nextchar, s // are not removed, and keep backslash at start, for "\\machine\path", // but do remove it for "\\\\machine\\path". // The reverse is found in ExpandOldSetting(). - while (**arg && !ascii_iswhite(**arg)) { - if (**arg == '\\' && (*arg)[1] != NUL + while (*arg && !ascii_iswhite(*arg)) { + if (*arg == '\\' && arg[1] != NUL #ifdef BACKSLASH_IN_FILENAME && !((flags & P_EXPAND) - && vim_isfilec((*arg)[1]) - && !ascii_iswhite((*arg)[1]) - && ((*arg)[1] != '\\' - || (s == newval && (*arg)[2] != '\\'))) + && vim_isfilec(arg[1]) + && !ascii_iswhite(arg[1]) + && (arg[1] != '\\' + || (s == newval && arg[2] != '\\'))) #endif ) { - (*arg)++; // remove backslash + arg++; // remove backslash } - int i = utfc_ptr2len(*arg); + int i = utfc_ptr2len(arg); if (i > 1) { // copy multibyte char - memmove(s, *arg, (size_t)i); - *arg += i; + memmove(s, arg, (size_t)i); + arg += i; s += i; } else { - *s++ = *(*arg)++; + *s++ = *arg++; } } *s = NUL; @@ -1062,7 +1063,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **arg, int nextchar, s } if (save_arg != NULL) { // number for 'whichwrap' - *arg = save_arg; + arg = save_arg; } } @@ -1117,6 +1118,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **arg, int nextchar, s xfree(saved_origval_g); xfree(saved_newval); + *argp = arg; return *errmsg == NULL ? OK : FAIL; } -- cgit From 4371886293b4956530f8bec49b01c0ee02771434 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 21:08:14 +0800 Subject: vim-patch:9.0.0544: minor issues with setting a string option Problem: Minor issues with setting a string option. Solution: Adjust the code, add a test. (closes vim/vim#11192) https://github.com/vim/vim/commit/fcba86c0316dc0d6341078b50e7967206a1627a0 --- src/nvim/option.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 62e4e74f2d..5b67f0e471 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -854,11 +854,9 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, // Set 'keywordprg' to ":help" if an empty // value was passed to :set by the user. - // Misuse errbuf[] for the resulting string. if (varp == (char *)&p_kp && (*arg == NUL || *arg == ' ')) { - STRCPY(errbuf, ":help"); save_arg = arg; - arg = errbuf; + arg = ":help"; } else if (varp == (char *)&p_bs && ascii_isdigit(**(char_u **)varp)) { // Convert 'backspace' number to string, for // adding, prepending and removing string. @@ -936,7 +934,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, // are not removed, and keep backslash at start, for "\\machine\path", // but do remove it for "\\\\machine\\path". // The reverse is found in ExpandOldSetting(). - while (*arg && !ascii_iswhite(*arg)) { + while (*arg != NUL && !ascii_iswhite(*arg)) { if (*arg == '\\' && arg[1] != NUL #ifdef BACKSLASH_IN_FILENAME && !((flags & P_EXPAND) @@ -1062,8 +1060,8 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, } } - if (save_arg != NULL) { // number for 'whichwrap' - arg = save_arg; + if (save_arg != NULL) { + arg = save_arg; // arg was temporarily changed, restore it } } -- cgit From 4b7904d16b11915b16ea46b96f1ea6e28d87d5fd Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 27 Sep 2022 21:16:28 +0600 Subject: refactor: replace unnecessary helper functions in optionstr.c Replaces unnecessary helper functions in `optionstr.c` such as `get_option_flags()`, `get_option_fullname()`, `set_option_flag()`, `is_global_option()`, etc. with a single `get_option()` helper function that allows direct access to the `options` array. Also refactors `f_exists()` to use `get_varp_scope` instead of using `get_option_tv`. This opens up the path for removing `getoptions_T` altogether later down the line since the hidden option logic is no longer needed. --- src/nvim/option.c | 101 +++--------------------------------------------------- 1 file changed, 4 insertions(+), 97 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 5b67f0e471..e7d0b171f6 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -106,30 +106,6 @@ static char e_number_required_after_equal[] static char e_preview_window_already_exists[] = N_("E590: A preview window already exists"); -// The options that are local to a window or buffer have "indir" set to one of -// these values. Special values: -// PV_NONE: global option. -// PV_WIN is added: window-local option -// PV_BUF is added: buffer-local option -// PV_BOTH is added: global option which also has a local value. -#define PV_BOTH 0x1000 -#define PV_WIN 0x2000 -#define PV_BUF 0x4000 -#define PV_MASK 0x0fff -#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x)) -#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x)) -#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x)) - -// WV_ and BV_ values get typecasted to this for the "indir" field -typedef enum { - PV_NONE = 0, - PV_MAXVAL = 0xffff, // to avoid warnings for value out of range -} idopt_T; - -// Options local to a window have a value local to a buffer and global to all -// buffers. Indicate this by setting "var" to VAR_WIN. -#define VAR_WIN ((char_u *)-1) - static char *p_term = NULL; static char *p_ttytype = NULL; @@ -147,19 +123,6 @@ static long p_tw_nopaste; static long p_wm_nopaste; static char *p_vsts_nopaste; -typedef struct vimoption { - char *fullname; // full option name - char *shortname; // permissible abbreviation - uint32_t flags; // see below - char_u *var; // global option: pointer to variable; - // window-local option: VAR_WIN; - // buffer-local option: global value - idopt_T indir; // global option: PV_NONE; - // local option: indirect option index - char *def_val; // default values for variable (neovim!!) - LastSet last_set; // script in which the option was last set -} vimoption_T; - // options[] is initialized here. // The order of the options MUST be alphabetic for ":set all" and findoption(). // All option names MUST start with a lowercase letter (for findoption()). @@ -3047,47 +3010,10 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o return rv; } -/// Return the flags for the option at 'opt_idx'. -uint32_t get_option_flags(int opt_idx) -{ - return options[opt_idx].flags; -} - -/// Set a flag for the option at 'opt_idx'. -void set_option_flag(int opt_idx, uint32_t flag) -{ - options[opt_idx].flags |= flag; -} - -/// Clear a flag for the option at 'opt_idx'. -void clear_option_flag(int opt_idx, uint32_t flag) -{ - options[opt_idx].flags &= ~flag; -} - -/// Returns true if the option at 'opt_idx' is a global option -bool is_global_option(int opt_idx) -{ - return options[opt_idx].indir == PV_NONE; -} - -/// Returns true if the option at 'opt_idx' is a global option which also has a -/// local value. -int is_global_local_option(int opt_idx) +// Return information for option at 'opt_idx' +vimoption_T *get_option(int opt_idx) { - return options[opt_idx].indir & PV_BOTH; -} - -/// Returns true if the option at 'opt_idx' is a window-local option -bool is_window_local_option(int opt_idx) -{ - return options[opt_idx].var == VAR_WIN; -} - -/// Returns true if the option at 'opt_idx' is a hidden option -bool is_hidden_option(int opt_idx) -{ - return options[opt_idx].var == NULL; + return &options[opt_idx]; } /// Set the value of an option @@ -3761,7 +3687,7 @@ void unset_global_local_option(char *name, void *from) } /// Get pointer to option variable, depending on local or global scope. -static char *get_varp_scope(vimoption_T *p, int opt_flags) +char *get_varp_scope(vimoption_T *p, int opt_flags) { if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) { if (p->var == VAR_WIN) { @@ -3833,13 +3759,6 @@ static char *get_varp_scope(vimoption_T *p, int opt_flags) return (char *)get_varp(p); } -/// Get pointer to option variable at 'opt_idx', depending on local or global -/// scope. -char *get_option_varp_scope(int opt_idx, int opt_flags) -{ - return get_varp_scope(&(options[opt_idx]), opt_flags); -} - /// Get pointer to option variable. static char_u *get_varp(vimoption_T *p) { @@ -4149,18 +4068,6 @@ static char_u *get_varp(vimoption_T *p) return (char_u *)&(curbuf->b_p_wm); } -/// Return a pointer to the variable for option at 'opt_idx' -char_u *get_option_var(int opt_idx) -{ - return options[opt_idx].var; -} - -/// Return the full name of the option at 'opt_idx' -char *get_option_fullname(int opt_idx) -{ - return options[opt_idx].fullname; -} - /// Get the value of 'equalprg', either the buffer-local one or the global one. char_u *get_equalprg(void) { -- cgit From 6679687bb3909f853ae97dfa01ae08ea2baf7f97 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 26 Sep 2022 15:17:10 +0200 Subject: refactor(redraw): no type argument in update_screen() This was used in the past with assumption that curwin/curbuf is "special" but this has not been true since basically forever at this point. Reduce NOT_VALID/CLEAR panic in options.lua . These should not be set if an effect of the option is causing something which by itself invokes redraw_later(). --- src/nvim/option.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index e7d0b171f6..9d0ba6a478 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2634,9 +2634,8 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, /// Called after an option changed: check if something needs to be redrawn. void check_redraw(uint32_t flags) { - // Careful: P_RCLR and P_RALL are a combination of other P_ flags - bool doclear = (flags & P_RCLR) == P_RCLR; - bool all = ((flags & P_RALL) == P_RALL || doclear); + // Careful: P_RALL is a combination of other P_ flags + bool all = (flags & P_RALL) == P_RALL; if ((flags & P_RSTAT) || all) { // mark all status lines and window bars dirty status_redraw_all(); @@ -2651,9 +2650,7 @@ void check_redraw(uint32_t flags) if (flags & P_RWINONLY) { redraw_later(curwin, UPD_NOT_VALID); } - if (doclear) { - redraw_all_later(UPD_CLEAR); - } else if (all) { + if (all) { redraw_all_later(UPD_NOT_VALID); } } -- cgit From 7746f641b89d1d80b2121980f83ae1f322c30e89 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 4 Oct 2022 11:28:30 +0200 Subject: fix(options): no matter what is said, 'cmdheight' is tab-local (susy baka) --- src/nvim/option.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 9d0ba6a478..4a93fddc1b 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -147,6 +147,13 @@ typedef enum { # include "option.c.generated.h" #endif +void set_init_tablocal(void) +{ + // susy baka: cmdheight calls itself OPT_GLOBAL but is really tablocal! + int ch_idx = findoption("cmdheight"); + p_ch = (long)options[ch_idx].def_val; +} + /// Initialize the options, first part. /// /// Called only once from main(), just after creating the first buffer. -- cgit From bc64aa435b84bb3a43501e101c51507c75fbd349 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 6 Oct 2022 09:03:49 +0800 Subject: vim-patch:9.0.0665: setting 'cmdheight' has no effect if last window was resized (#20500) Problem: Setting 'cmdheight' has no effect if last window was resized. Solution: Do apply 'cmdheight' when told to. Use the frame height instead of the cmdline_row. (closes vim/vim#11286) https://github.com/vim/vim/commit/0816f473ab2f6cf7d8311c0f97371cada7f20d18 --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 4a93fddc1b..a2dd2e7d84 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2468,7 +2468,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, // if p_ch changed value, change the command line height // Only compute the new window layout when startup has been // completed. Otherwise the frame sizes may be wrong. - if (p_ch != old_value && full_screen) { + if ((p_ch != old_value || topframe->fr_height != Rows - p_ch) && full_screen) { command_height(); } } else if (pp == &p_uc) { -- cgit From 25dea99ce54de6a8c4369e28e0db82e1af669f24 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 6 Oct 2022 20:03:59 +0800 Subject: vim-patch:9.0.0670: no space for command line when there is a tabline (#20512) Problem: No space for command line when there is a tabline. Solution: Correct computation of where the command line should be. (closes vim/vim#11295) https://github.com/vim/vim/commit/c9f5f73206272ccad0aa536854debc5f9781978a --- src/nvim/option.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index a2dd2e7d84..c6a9d6b7db 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2468,7 +2468,9 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, // if p_ch changed value, change the command line height // Only compute the new window layout when startup has been // completed. Otherwise the frame sizes may be wrong. - if ((p_ch != old_value || topframe->fr_height != Rows - p_ch) && full_screen) { + if ((p_ch != old_value + || tabline_height() + topframe->fr_height != Rows - p_ch) + && full_screen) { command_height(); } } else if (pp == &p_uc) { -- cgit From d191070913dc195309926a91f97008defd877a71 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 7 Oct 2022 08:52:51 +0800 Subject: fix(ui): setting 'cmdheight' with global statusline (#20515) --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index c6a9d6b7db..208112561a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2469,7 +2469,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, // Only compute the new window layout when startup has been // completed. Otherwise the frame sizes may be wrong. if ((p_ch != old_value - || tabline_height() + topframe->fr_height != Rows - p_ch) + || tabline_height() + global_stl_height() + topframe->fr_height != Rows - p_ch) && full_screen) { command_height(); } -- cgit From 0ef6aaa3a73d5089bf53e804364950c81784574c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 12 Oct 2022 14:53:40 +0100 Subject: refactor: clint (#20600) --- src/nvim/option.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 208112561a..3c3a69e063 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -207,7 +207,7 @@ void set_init_1(bool clean_arg) p = "/tmp"; # endif mustfree = false; - } else + } else // NOLINT(readability/braces) #endif { p = vim_getenv(names[n]); @@ -2042,10 +2042,9 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va } redraw_titles(); modified_was_set = value; - } #ifdef BACKSLASH_IN_FILENAME - else if ((int *)varp == &p_ssl) { + } else if ((int *)varp == &p_ssl) { if (p_ssl) { psepc = '/'; psepcN = '\\'; @@ -2060,9 +2059,8 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va buflist_slash_adjust(); alist_slash_adjust(); scriptnames_slash_adjust(); - } #endif - else if ((int *)varp == &curwin->w_p_wrap) { + } else if ((int *)varp == &curwin->w_p_wrap) { // If 'wrap' is set, set w_leftcol to zero. if (curwin->w_p_wrap) { curwin->w_leftcol = 0; @@ -2681,7 +2679,7 @@ int findoption_len(const char *const arg, const size_t len) // letter. There are 26 letters, plus the first "t_" option. if (quick_tab[1] == 0) { p = options[0].fullname; - for (short int i = 1; (s = options[i].fullname) != NULL; i++) { + for (uint16_t i = 1; (s = options[i].fullname) != NULL; i++) { if (s[0] != p[0]) { if (s[0] == 't' && s[1] == '_') { quick_tab[26] = i; @@ -3598,8 +3596,7 @@ void unset_global_local_option(char *name, void *from) } p = &(options[opt_idx]); - switch ((int)p->indir) - { + switch ((int)p->indir) { // global option with local value: use local value if it's been set case PV_EP: clear_string_option(&buf->b_p_ep); @@ -4862,7 +4859,7 @@ static void option_value2string(vimoption_T *opp, int opt_flags) snprintf((char *)NameBuff, sizeof(NameBuff), "%" PRId64, - (int64_t)*(long *)varp); + (int64_t)(*(long *)varp)); } } else { // P_STRING varp = *(char_u **)(varp); -- cgit From 73bdfdd382bf2addd7816571608db6911448b48a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 13 Oct 2022 09:43:06 +0800 Subject: vim-patch:8.2.4453: :helpgrep may free an option that was not allocated Problem: :helpgrep may free an option that was not allocated. (Yegappan Lakshmanan) Solution: Check if the value was allocated. https://github.com/vim/vim/commit/4791fcd82565adcc60b86830e0bb6cd5b6eea0a6 --- src/nvim/option.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 3c3a69e063..11a92f7d56 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3112,6 +3112,12 @@ void set_option_value_give_err(const char *name, long number, const char *string } } +bool is_option_allocated(const char *name) +{ + int idx = findoption(name); + return idx >= 0 && (options[idx].flags & P_ALLOCED); +} + /// Return true if "name" is a string option. /// Returns false if option "name" does not exist. bool is_string_option(const char *name) -- cgit From 04cdea5f4ac49fa62cc4091a5c26791b80b4cc4c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 11a92f7d56..7202156c46 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -219,7 +219,7 @@ void set_init_1(bool clean_arg) xstrlcpy(item, p, len); add_pathsep(item); xstrlcat(item, "*", len); - if (find_dup_item(ga.ga_data, (char_u *)item, options[opt_idx].flags) + if (find_dup_item(ga.ga_data, item, options[opt_idx].flags) == NULL) { ga_grow(&ga, (int)len); if (!GA_EMPTY(&ga)) { @@ -242,15 +242,15 @@ void set_init_1(bool clean_arg) } { - char_u *cdpath; - char_u *buf; + char *cdpath; + char *buf; int i; int j; // Initialize the 'cdpath' option's default value. - cdpath = (char_u *)vim_getenv("CDPATH"); + cdpath = vim_getenv("CDPATH"); if (cdpath != NULL) { - buf = xmalloc(2 * STRLEN(cdpath) + 2); + buf = xmalloc(2 * strlen(cdpath) + 2); { buf[0] = ','; // start with ",", current dir first j = 1; @@ -267,7 +267,7 @@ void set_init_1(bool clean_arg) buf[j] = NUL; opt_idx = findoption("cdpath"); if (opt_idx >= 0) { - options[opt_idx].def_val = (char *)buf; + options[opt_idx].def_val = buf; options[opt_idx].flags |= P_DEF_ALLOCED; } else { xfree(buf); // cannot happen @@ -515,9 +515,9 @@ static void set_string_default(const char *name, char *val, bool allocated) } } -// For an option value that contains comma separated items, find "newval" in -// "origval". Return NULL if not found. -static char_u *find_dup_item(char_u *origval, const char_u *newval, uint32_t flags) +/// For an option value that contains comma separated items, find "newval" in +/// "origval". Return NULL if not found. +static char *find_dup_item(char *origval, const char *newval, uint32_t flags) FUNC_ATTR_NONNULL_ARG(2) { int bs = 0; @@ -526,8 +526,8 @@ static char_u *find_dup_item(char_u *origval, const char_u *newval, uint32_t fla return NULL; } - const size_t newlen = STRLEN(newval); - for (char_u *s = origval; *s != NUL; s++) { + const size_t newlen = strlen(newval); + for (char *s = origval; *s != NUL; s++) { if ((!(flags & P_COMMA) || s == origval || (s[-1] == ',' && !(bs & 1))) && STRNCMP(s, newval, newlen) == 0 && (!(flags & P_COMMA) || s[newlen] == ',' || s[newlen] == NUL)) { @@ -948,7 +948,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, int len = 0; if (op == OP_REMOVING || (flags & P_NODUP)) { len = (int)STRLEN(newval); - s = (char *)find_dup_item(origval, (char_u *)newval, flags); + s = find_dup_item((char *)origval, newval, flags); // do not add if already there if ((op == OP_ADDING || op == OP_PREPENDING) && s != NULL) { @@ -1182,7 +1182,7 @@ int do_set(char *arg, int opt_flags) } len++; if (opt_idx == -1) { - key = find_key_option((char_u *)arg + 1, true); + key = find_key_option(arg + 1, true); } } else { len = 0; @@ -1196,7 +1196,7 @@ int do_set(char *arg, int opt_flags) } opt_idx = findoption_len((const char *)arg, (size_t)len); if (opt_idx == -1) { - key = find_key_option((char_u *)arg, false); + key = find_key_option(arg, false); } } @@ -1543,7 +1543,7 @@ void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked int string_to_key(char_u *arg) { if (*arg == '<') { - return find_key_option(arg + 1, true); + return find_key_option((char *)arg + 1, true); } if (*arg == '^') { return CTRL_CHR(arg[1]); @@ -3151,9 +3151,9 @@ int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt) return key; } -static int find_key_option(const char_u *arg, bool has_lt) +static int find_key_option(const char *arg, bool has_lt) { - return find_key_option_len(arg, STRLEN(arg), has_lt); + return find_key_option_len((char_u *)arg, strlen(arg), has_lt); } /// if 'all' == 0: show changed options -- cgit From 19eb7054ff7b1fbc78e56e7f9ed6537b085147bc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Oct 2022 08:06:07 +0800 Subject: vim-patch:9.0.0761: cannot use 'indentexpr' for Lisp indenting Problem: Cannot use 'indentexpr' for Lisp indenting. Solution: Add the 'lispoptions' option. https://github.com/vim/vim/commit/49846fb1a31de99f49d6a7e70efe685197423c84 vim-patch:9.0.0762: build failure Problem: Build failure. Solution: Add missing change. https://github.com/vim/vim/commit/4b082c4bd05f504fda1acaa9d28fca55a2d04857 --- src/nvim/option.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 7202156c46..0b819aad43 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4008,6 +4008,8 @@ static char_u *get_varp(vimoption_T *p) return (char_u *)&(curbuf->b_p_fex); case PV_LISP: return (char_u *)&(curbuf->b_p_lisp); + case PV_LOP: + return (char_u *)&(curbuf->b_p_lop); case PV_ML: return (char_u *)&(curbuf->b_p_ml); case PV_MPS: @@ -4414,6 +4416,8 @@ void buf_copy_options(buf_T *buf, int flags) COPY_OPT_SCTX(buf, BV_CINO); buf->b_p_cinsd = xstrdup(p_cinsd); COPY_OPT_SCTX(buf, BV_CINSD); + buf->b_p_lop = xstrdup(p_lop); + COPY_OPT_SCTX(buf, BV_LOP); // Don't copy 'filetype', it must be detected buf->b_p_ft = empty_option; -- cgit From 784e498c4a9c1f03266ced5ec3f55c3a6c94b80d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 21 Oct 2022 14:47:44 +0200 Subject: refactor: clang-tidy fixes to silence clangd warning (#20683) * refactor: readability-uppercase-literal-suffix * refactor: readability-named-parameter * refactor: bugprone-suspicious-string-compare * refactor: google-readability-casting * refactor: readability-redundant-control-flow * refactor: bugprone-too-small-loop-variable * refactor: readability-non-const-parameter * refactor: readability-avoid-const-params-in-decls * refactor: google-readability-todo * refactor: readability-inconsistent-declaration-parameter-name * refactor: bugprone-suspicious-missing-comma * refactor: remove noisy or slow warnings --- src/nvim/option.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 0b819aad43..1a6cd0c1af 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3256,7 +3256,7 @@ static void showoptions(int all, int opt_flags) } /// Return true if option "p" has its default value. -static int optval_default(vimoption_T *p, char_u *varp) +static int optval_default(vimoption_T *p, const char_u *varp) { if (varp == NULL) { return true; // hidden option is always at default @@ -4889,7 +4889,7 @@ static void option_value2string(vimoption_T *opp, int opt_flags) /// Return true if "varp" points to 'wildchar' or 'wildcharm' and it can be /// printed as a keyname. /// "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'. -static int wc_use_keyname(char_u *varp, long *wcp) +static int wc_use_keyname(const char_u *varp, long *wcp) { if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm)) { *wcp = *(long *)varp; -- cgit From a53998ae78902309c225b323e0b8d9f1f75fe147 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Sat, 22 Oct 2022 13:54:29 +0600 Subject: fix: setting tabline option not redrawing tabline With #20374 tabline option is marked with 'statuslines' redraw flag. But 'statuslines' doesn't redraw tabline. As a result, tabline doesn't get redrawn when tabline option is set and statuslines get unnecessarily redrawn. This patch fixes the issue by adding a new redraw flag P_RTABL to redraw tabline. --- src/nvim/option.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 1a6cd0c1af..06662afd08 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2648,6 +2648,10 @@ void check_redraw(uint32_t flags) status_redraw_all(); } + if ((flags & P_RTABL) || all) { // mark tablines dirty + redraw_tabline = true; + } + if ((flags & P_RBUF) || (flags & P_RWIN) || all) { changed_window_setting(); } -- cgit From feabc1c98cb077f60fde1a14e8540f2cf99eb8d2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 29 Oct 2022 09:03:15 +0800 Subject: vim-patch:9.0.0816: CTRL-Z at end of file is always dropped Problem: CTRL-Z at end of file is always dropped. Solution: Add the 'endoffile' option, like the 'endofline' option. (closes vim/vim#11408, closes vim/vim#11397) Cherry-pick test_fixeol.vim changes from patch 8.2.1432. Cherry-pick 'endoffile' changes from latest Vim runtime update. https://github.com/vim/vim/commit/fb0cf2357e0c85bbfd9f9178705ad8d77b6b3b4e vim-patch:f0b567e32a46 Revert unintended Makefile change https://github.com/vim/vim/commit/f0b567e32a462fe838170a202919d18b53eff987 vim-patch:72c8e3c070b3 Fix wrong struct access for member. https://github.com/vim/vim/commit/72c8e3c070b30f82bc0d203a62c168e43a13e99b vim-patch:3f68a4136eb9 Add missing entry for the 'endoffile' option. https://github.com/vim/vim/commit/3f68a4136eb99840d739af5133ab31948f273f63 Co-authored-by: Bram Moolenaar --- src/nvim/option.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 06662afd08..8de86ce76e 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3978,6 +3978,8 @@ static char_u *get_varp(vimoption_T *p) return (char_u *)&(curbuf->b_p_cfu); case PV_OFU: return (char_u *)&(curbuf->b_p_ofu); + case PV_EOF: + return (char_u *)&(curbuf->b_p_eof); case PV_EOL: return (char_u *)&(curbuf->b_p_eol); case PV_FIXEOL: -- cgit From b92ed35a0bb873589bba9b51fdb92ffd00dc3e57 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 1 Apr 2022 18:12:55 +0800 Subject: vim-patch:8.2.4093: cached breakindent values not initialized properly Problem: Cached breakindent values not initialized properly. Solution: Initialize and cache formatlistpat. (Christian Brabandt, closes vim/vim#9526, closes vim/vim#9512) https://github.com/vim/vim/commit/c53b467473160b5cfce77277fbae414bf43e66ce Co-authored-by: Christian Brabandt --- src/nvim/option.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 8de86ce76e..dc9f01ff60 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5220,6 +5220,18 @@ unsigned int get_bkc_value(buf_T *buf) return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags; } +/// Get the local or global value of 'formatlistpat'. +/// +/// @param buf The buffer. +char *get_flp_value(buf_T *buf) +{ + return buf->b_p_flp ? buf->b_p_flp : p_flp; + if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL) { + return p_flp; + } + return buf->b_p_flp; +} + /// Get the local or global value of the 'virtualedit' flags. unsigned int get_ve_flags(void) { -- cgit From 8b43091392ec895c77b83ff5964cd37b54976089 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 1 Apr 2022 18:31:19 +0800 Subject: vim-patch:8.2.4100: early return when getting the 'formatlistpat' value Problem: Early return when getting the 'formatlistpat' value. Solution: Remove the first line. (Christian Brabandt) https://github.com/vim/vim/commit/04b871da800768287a8a432de568b11297db8686 --- src/nvim/option.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index dc9f01ff60..8142be4eb1 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5225,7 +5225,6 @@ unsigned int get_bkc_value(buf_T *buf) /// @param buf The buffer. char *get_flp_value(buf_T *buf) { - return buf->b_p_flp ? buf->b_p_flp : p_flp; if (buf->b_p_flp == NULL || *buf->b_p_flp == NUL) { return p_flp; } -- cgit From 83ea9e23a23408ee2bfbfbae01f081de011dc49b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 05:47:57 +0800 Subject: vim-patch:9.0.0835: the window title is not redrawn when 'endoffile' changes (#20951) Problem: The window title is not redrawn when 'endoffile' changes. Solution: redraw the window title when 'endoffile' is changed. (Ken Takata, closes vim/vim#11488) https://github.com/vim/vim/commit/845bbb72ed2da4b5fb2a503d91cfd6435df2f584 Co-authored-by: K.Takata --- src/nvim/option.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 8142be4eb1..306a63b74d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1975,14 +1975,12 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va } else if ((int *)varp == &curbuf->b_p_ma) { // when 'modifiable' is changed, redraw the window title redraw_titles(); - } else if ((int *)varp == &curbuf->b_p_eol) { - // when 'endofline' is changed, redraw the window title - redraw_titles(); - } else if ((int *)varp == &curbuf->b_p_fixeol) { - // when 'fixeol' is changed, redraw the window title - redraw_titles(); - } else if ((int *)varp == &curbuf->b_p_bomb) { - // when 'bomb' is changed, redraw the window title and tab page text + } else if ((int *)varp == &curbuf->b_p_eof + || (int *)varp == &curbuf->b_p_eol + || (int *)varp == &curbuf->b_p_fixeol + || (int *)varp == &curbuf->b_p_bomb) { + // redraw the window title and tab page text when 'endoffile', 'endofline', + // 'fixeol' or 'bomb' is changed redraw_titles(); } else if ((int *)varp == &curbuf->b_p_bin) { // when 'bin' is set also set some other options -- cgit From a79d28e4d7939c13f38cf4ce63ff240011bca96d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 6 Nov 2022 17:58:13 +0800 Subject: vim-patch:9.0.0265: no good reason why the "gf" command isn't in the tiny version (#20964) Problem: No good reason why the "gf" command is not in the tiny version. Solution: Graduate the file_in_path feature. https://github.com/vim/vim/commit/f80f40a55ccff0a4331c5fbd1ac446511f622ed0 Co-authored-by: Bram Moolenaar --- src/nvim/option.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 306a63b74d..523ae13e52 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4702,8 +4702,7 @@ void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) || p == (char_u *)&p_cdpath || p == (char_u *)&p_vdir) { xp->xp_context = EXPAND_DIRECTORIES; - if (p == (char_u *)&p_path - || p == (char_u *)&p_cdpath) { + if (p == (char_u *)&p_path || p == (char_u *)&p_cdpath) { xp->xp_backslash = XP_BS_THREE; } else { xp->xp_backslash = XP_BS_ONE; -- cgit From 731cdde28ea8d48cc23ba2752a08c261c87eee92 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 22 Oct 2022 12:36:38 +0200 Subject: refactor: fix clang-tidy warnings Enable and fix bugprone-misplaced-widening-cast warning. Fix some modernize-macro-to-enum and readability-else-after-return warnings, but don't enable them. While the warnings can be useful, they are in general too noisy to enable. --- src/nvim/option.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 523ae13e52..628e1a6581 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2950,15 +2950,13 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o if (p->indir & PV_WIN) { if (opt_type == SREQ_BUF) { return 0; // Requested buffer-local, not window-local option - } else { - rv |= SOPT_WIN; } + rv |= SOPT_WIN; } else if (p->indir & PV_BUF) { if (opt_type == SREQ_WIN) { return 0; // Requested window-local, not buffer-local option - } else { - rv |= SOPT_BUF; } + rv |= SOPT_BUF; } } @@ -2969,9 +2967,8 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o if (opt_type == SREQ_GLOBAL) { if (p->var == VAR_WIN) { return 0; - } else { - varp = p->var; } + varp = p->var; } else { if (opt_type == SREQ_BUF) { // Special case: 'modified' is b_changed, but we also want to @@ -3094,9 +3091,8 @@ char *set_option_value(const char *const name, const long number, const char *co } if (flags & P_NUM) { return set_num_option(opt_idx, varp, numval, NULL, 0, opt_flags); - } else { - return set_bool_option(opt_idx, varp, (int)numval, opt_flags); } + return set_bool_option(opt_idx, varp, (int)numval, opt_flags); } } return NULL; -- cgit From 900dd2bdab85b25237cec638265d44c2174154ed Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 20 Aug 2022 08:27:10 +0800 Subject: vim-patch:8.2.3665: cannot use a lambda for 'tagfunc' Problem: Cannot use a lambda for 'tagfunc'. Solution: Use 'tagfunc' like 'opfunc'. (Yegappan Lakshmanan, closes vim/vim#9204) https://github.com/vim/vim/commit/19916a8c8920b6a1fd737ffa6d4e363fc7a96319 Co-authored-by: Yegappan Lakshmanan --- src/nvim/option.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 523ae13e52..1eabe8c540 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -78,6 +78,7 @@ #include "nvim/spellsuggest.h" #include "nvim/strings.h" #include "nvim/syntax.h" +#include "nvim/tag.h" #include "nvim/ui.h" #include "nvim/ui_compositor.h" #include "nvim/undo.h" @@ -577,6 +578,7 @@ void free_all_options(void) } } free_operatorfunc_option(); + free_tagfunc_option(); } #endif @@ -4383,6 +4385,7 @@ void buf_copy_options(buf_T *buf, int flags) COPY_OPT_SCTX(buf, BV_OFU); buf->b_p_tfu = xstrdup(p_tfu); COPY_OPT_SCTX(buf, BV_TFU); + buf_set_tfu_callback(buf); buf->b_p_sts = p_sts; COPY_OPT_SCTX(buf, BV_STS); buf->b_p_sts_nopaste = p_sts_nopaste; -- cgit From 1e4adf4b56cb7a360d16c4d04290c50ae7e80fbc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 20 Aug 2022 08:45:15 +0800 Subject: vim-patch:8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc' Problem: Cannot use a lambda for 'completefunc' and 'omnifunc'. Solution: Implement lambda support. (Yegappan Lakshmanan, closes vim/vim#9257) https://github.com/vim/vim/commit/8658c759f05b317707d56e3b65a5ef63930c7498 Comment out Vim9 script in tests. Co-authored-by: Yegappan Lakshmanan --- src/nvim/option.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 1eabe8c540..da3fad0d61 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -51,6 +51,7 @@ #include "nvim/highlight_group.h" #include "nvim/indent.h" #include "nvim/indent_c.h" +#include "nvim/insexpand.h" #include "nvim/keycodes.h" #include "nvim/locale.h" #include "nvim/macros.h" @@ -4381,11 +4382,13 @@ void buf_copy_options(buf_T *buf, int flags) #endif buf->b_p_cfu = xstrdup(p_cfu); COPY_OPT_SCTX(buf, BV_CFU); + set_buflocal_cfu_callback(buf); buf->b_p_ofu = xstrdup(p_ofu); COPY_OPT_SCTX(buf, BV_OFU); + set_buflocal_ofu_callback(buf); buf->b_p_tfu = xstrdup(p_tfu); COPY_OPT_SCTX(buf, BV_TFU); - buf_set_tfu_callback(buf); + set_buflocal_tfu_callback(buf); buf->b_p_sts = p_sts; COPY_OPT_SCTX(buf, BV_STS); buf->b_p_sts_nopaste = p_sts_nopaste; -- cgit From 42e44d6d334bda8b97afe9e34a819ab293e5e10a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 10:26:54 +0800 Subject: vim-patch:8.2.3751: cannot assign a lambda to an option that takes a function Problem: Cannot assign a lambda to an option that takes a function. Solution: Automatically convert the lambda to a string. (Yegappan Lakshmanan, closes vim/vim#9286) https://github.com/vim/vim/commit/6409553b6e3b4de4e1d72b8ee5445595214581ff Co-authored-by: Yegappan Lakshmanan --- src/nvim/option.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index da3fad0d61..c0a1f14463 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2842,6 +2842,7 @@ int findoption(const char *const arg) /// Gets the value for an option. /// /// @param stringval NULL when only checking existence +/// @param flagsp set to the option flags (P_xxxx) (if not NULL) /// /// @returns: /// Number option: gov_number, *numval gets value. @@ -2851,7 +2852,8 @@ int findoption(const char *const arg) /// Hidden Toggle option: gov_hidden_bool. /// Hidden String option: gov_hidden_string. /// Unknown option: gov_unknown. -getoption_T get_option_value(const char *name, long *numval, char **stringval, int opt_flags) +getoption_T get_option_value(const char *name, long *numval, char **stringval, uint32_t *flagsp, + int scope) { if (get_tty_option(name, stringval)) { return gov_string; @@ -2862,7 +2864,12 @@ getoption_T get_option_value(const char *name, long *numval, char **stringval, i return gov_unknown; } - char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); + char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), scope); + + if (flagsp != NULL) { + // Return the P_xxxx option flags. + *flagsp = options[opt_idx].flags; + } if (options[opt_idx].flags & P_STRING) { if (varp == NULL) { // hidden option @@ -3092,7 +3099,7 @@ char *set_option_value(const char *const name, const long number, const char *co numval = -1; } else { char *s = NULL; - (void)get_option_value(name, &numval, &s, OPT_GLOBAL); + (void)get_option_value(name, &numval, &s, NULL, OPT_GLOBAL); } } if (flags & P_NUM) { @@ -3701,15 +3708,17 @@ void unset_global_local_option(char *name, void *from) } /// Get pointer to option variable, depending on local or global scope. -char *get_varp_scope(vimoption_T *p, int opt_flags) +/// +/// @param scope can be OPT_LOCAL, OPT_GLOBAL or a combination. +char *get_varp_scope(vimoption_T *p, int scope) { - if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE) { + if ((scope & OPT_GLOBAL) && p->indir != PV_NONE) { if (p->var == VAR_WIN) { return GLOBAL_WO(get_varp(p)); } return (char *)p->var; } - if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) { + if ((scope & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) { switch ((int)p->indir) { case PV_FP: return (char *)&(curbuf->b_p_fp); @@ -4863,9 +4872,9 @@ void ExpandOldSetting(int *num_file, char ***file) /// NameBuff[]. Must not be called with a hidden option! /// /// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL -static void option_value2string(vimoption_T *opp, int opt_flags) +static void option_value2string(vimoption_T *opp, int scope) { - char_u *varp = (char_u *)get_varp_scope(opp, opt_flags); + char_u *varp = (char_u *)get_varp_scope(opp, scope); if (opp->flags & P_NUM) { long wc = 0; -- cgit From d7bd7f13a8f026b8b95fdc49b4754f6199105891 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 11:04:33 +0800 Subject: vim-patch:8.2.3756: might crash when callback is not valid Problem: might crash when callback is not valid. Solution: Check for valid callback. (Yegappan Lakshmanan, closes vim/vim#9293) https://github.com/vim/vim/commit/4dc24eb5adbcc76838fae1e900936dd230209d96 Co-authored-by: Yegappan Lakshmanan --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index c0a1f14463..419cfb6873 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5193,7 +5193,7 @@ int option_set_callback_func(char *optval, Callback *optcb) } Callback cb; - if (!callback_from_typval(&cb, tv)) { + if (!callback_from_typval(&cb, tv) || cb.type == kCallbackNone) { tv_free(tv); return FAIL; } -- cgit From f8c671827710c6e9cca3bfd60c32098b2be8239a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 14 Nov 2022 18:04:36 +0000 Subject: feat(lua-api): avoid unnecessary allocations (#19877) Lua makes (or reuses) an internal copy of strings, so we can safely push buf pointers onto the stack. --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 23c4a1ccf3..330900a9d6 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3012,7 +3012,7 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o if (varp != NULL) { if (p->flags & P_STRING) { - *stringval = xstrdup(*(char **)(varp)); + *stringval = *(char **)(varp); } else if (p->flags & P_NUM) { *numval = *(long *)varp; } else { -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/option.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 330900a9d6..827b755ce8 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -21,14 +21,18 @@ #define IN_OPTION_C #include +#include #include #include #include +#include #include #include -#include "nvim/arglist.h" +#include "auto/config.h" +#include "nvim/api/private/defs.h" #include "nvim/ascii.h" +#include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/change.h" #include "nvim/charset.h" @@ -36,16 +40,18 @@ #include "nvim/decoration_provider.h" #include "nvim/diff.h" #include "nvim/drawscreen.h" -#include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" +#include "nvim/eval/typval_defs.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" #include "nvim/ex_session.h" -#include "nvim/fileio.h" #include "nvim/fold.h" #include "nvim/garray.h" -#include "nvim/getchar.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/grid_defs.h" #include "nvim/hardcopy.h" #include "nvim/highlight.h" #include "nvim/highlight_group.h" @@ -54,6 +60,7 @@ #include "nvim/insexpand.h" #include "nvim/keycodes.h" #include "nvim/locale.h" +#include "nvim/log.h" #include "nvim/macros.h" #include "nvim/mapping.h" #include "nvim/mbyte.h" @@ -66,22 +73,24 @@ #include "nvim/normal.h" #include "nvim/ops.h" #include "nvim/option.h" +#include "nvim/option_defs.h" #include "nvim/optionstr.h" #include "nvim/os/os.h" -#include "nvim/os_unix.h" #include "nvim/path.h" #include "nvim/popupmenu.h" +#include "nvim/pos.h" #include "nvim/regexp.h" +#include "nvim/runtime.h" #include "nvim/screen.h" -#include "nvim/search.h" +#include "nvim/sign_defs.h" #include "nvim/spell.h" #include "nvim/spellfile.h" #include "nvim/spellsuggest.h" #include "nvim/strings.h" -#include "nvim/syntax.h" #include "nvim/tag.h" +#include "nvim/terminal.h" +#include "nvim/types.h" #include "nvim/ui.h" -#include "nvim/ui_compositor.h" #include "nvim/undo.h" #include "nvim/vim.h" #include "nvim/window.h" @@ -90,7 +99,6 @@ #endif #include "nvim/api/extmark.h" #include "nvim/api/private/helpers.h" -#include "nvim/api/vim.h" #include "nvim/lua/executor.h" #include "nvim/os/input.h" #include "nvim/os/lang.h" -- cgit From f2b30b4d62b97da6ae1b4dd7c4e5730fc5bc95f7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 19 Nov 2022 10:57:06 +0800 Subject: vim-patch:8.2.0260: several lines of code are duplicated (#21108) Problem: Several lines of code are duplicated. Solution: Move duplicated code to a function. (Yegappan Lakshmanan, closes vim/vim#5330) https://github.com/vim/vim/commit/f4140488c72cad4dbf5449dba099cfa7de7bbb22 Using sizeof seems better than ARRAY_SIZE for vim_snprintf(). --- src/nvim/option.c | 115 ++++++++++++++++++++++-------------------------------- 1 file changed, 46 insertions(+), 69 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 827b755ce8..80931016a5 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1899,6 +1899,46 @@ void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx) } } +/// Apply the OptionSet autocommand. +static void apply_optionset_autocmd(int opt_idx, long opt_flags, long oldval, long oldval_g, + long newval, const char *errmsg) +{ + // Don't do this while starting up, failure or recursively. + if (starting || errmsg != NULL || *get_vim_var_str(VV_OPTION_TYPE) != NUL) { + return; + } + + char buf_old[12], buf_old_global[12], buf_new[12], buf_type[12]; + + vim_snprintf(buf_old, sizeof(buf_old), "%ld", oldval); + vim_snprintf(buf_old_global, sizeof(buf_old_global), "%ld", oldval_g); + vim_snprintf(buf_new, sizeof(buf_new), "%ld", newval); + vim_snprintf(buf_type, sizeof(buf_type), "%s", + (opt_flags & OPT_LOCAL) ? "local" : "global"); + set_vim_var_string(VV_OPTION_NEW, buf_new, -1); + set_vim_var_string(VV_OPTION_OLD, buf_old, -1); + set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); + if (opt_flags & OPT_LOCAL) { + set_vim_var_string(VV_OPTION_COMMAND, "setlocal", -1); + set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); + } + if (opt_flags & OPT_GLOBAL) { + set_vim_var_string(VV_OPTION_COMMAND, "setglobal", -1); + set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1); + } + if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) { + set_vim_var_string(VV_OPTION_COMMAND, "set", -1); + set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); + set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1); + } + if (opt_flags & OPT_MODELINE) { + set_vim_var_string(VV_OPTION_COMMAND, "modeline", -1); + set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); + } + apply_autocmds(EVENT_OPTIONSET, options[opt_idx].fullname, NULL, false, NULL); + reset_v_option_vars(); +} + /// Set the value of a boolean option, taking care of side effects /// /// @param[in] opt_idx Option index in options[] table. @@ -2153,40 +2193,10 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va options[opt_idx].flags |= P_WAS_SET; - // Don't do this while starting up or recursively. - if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL) { - char buf_old[2]; - char buf_old_global[2]; - char buf_new[2]; - char buf_type[7]; - vim_snprintf(buf_old, ARRAY_SIZE(buf_old), "%d", old_value ? true : false); - vim_snprintf(buf_old_global, ARRAY_SIZE(buf_old_global), "%d", old_global_value ? true : false); - vim_snprintf(buf_new, ARRAY_SIZE(buf_new), "%d", value ? true : false); - vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s", - (opt_flags & OPT_LOCAL) ? "local" : "global"); - set_vim_var_string(VV_OPTION_NEW, buf_new, -1); - set_vim_var_string(VV_OPTION_OLD, buf_old, -1); - set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); - if (opt_flags & OPT_LOCAL) { - set_vim_var_string(VV_OPTION_COMMAND, "setlocal", -1); - set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); - } - if (opt_flags & OPT_GLOBAL) { - set_vim_var_string(VV_OPTION_COMMAND, "setglobal", -1); - set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1); - } - if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) { - set_vim_var_string(VV_OPTION_COMMAND, "set", -1); - set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); - set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1); - } - if (opt_flags & OPT_MODELINE) { - set_vim_var_string(VV_OPTION_COMMAND, "modeline", -1); - set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); - } - apply_autocmds(EVENT_OPTIONSET, options[opt_idx].fullname, NULL, false, NULL); - reset_v_option_vars(); - } + apply_optionset_autocmd(opt_idx, opt_flags, + (long)(old_value ? true : false), + (long)(old_global_value ? true : false), + (long)(value ? true : false), NULL); if (options[opt_idx].flags & P_UI_OPTION) { ui_call_option_set(cstr_as_string(options[opt_idx].fullname), @@ -2596,41 +2606,8 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, options[opt_idx].flags |= P_WAS_SET; - // Don't do this while starting up, failure or recursively. - if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL) { - char buf_old[NUMBUFLEN]; - char buf_old_global[NUMBUFLEN]; - char buf_new[NUMBUFLEN]; - char buf_type[7]; - - vim_snprintf(buf_old, ARRAY_SIZE(buf_old), "%ld", old_value); - vim_snprintf(buf_old_global, ARRAY_SIZE(buf_old_global), "%ld", old_global_value); - vim_snprintf(buf_new, ARRAY_SIZE(buf_new), "%ld", value); - vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s", - (opt_flags & OPT_LOCAL) ? "local" : "global"); - set_vim_var_string(VV_OPTION_NEW, buf_new, -1); - set_vim_var_string(VV_OPTION_OLD, buf_old, -1); - set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); - if (opt_flags & OPT_LOCAL) { - set_vim_var_string(VV_OPTION_COMMAND, "setlocal", -1); - set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); - } - if (opt_flags & OPT_GLOBAL) { - set_vim_var_string(VV_OPTION_COMMAND, "setglobal", -1); - set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1); - } - if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) { - set_vim_var_string(VV_OPTION_COMMAND, "set", -1); - set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); - set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1); - } - if (opt_flags & OPT_MODELINE) { - set_vim_var_string(VV_OPTION_COMMAND, "modeline", -1); - set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1); - } - apply_autocmds(EVENT_OPTIONSET, options[opt_idx].fullname, NULL, false, NULL); - reset_v_option_vars(); - } + apply_optionset_autocmd(opt_idx, opt_flags, old_value, old_global_value, + value, errmsg); if (errmsg == NULL && options[opt_idx].flags & P_UI_OPTION) { ui_call_option_set(cstr_as_string(options[opt_idx].fullname), -- cgit From 40f3f75867bf03abfd90e0389a38197a00d37af1 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 72 +++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 80931016a5..b78fc7c27a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -702,14 +702,14 @@ void set_helplang_default(const char *lang) int idx = findoption("hlg"); if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) { if (options[idx].flags & P_ALLOCED) { - free_string_option((char *)p_hlg); + free_string_option(p_hlg); } - p_hlg = (char_u *)xmemdupz(lang, lang_len); + p_hlg = xmemdupz(lang, lang_len); // zh_CN becomes "cn", zh_TW becomes "tw". - if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) { - p_hlg[0] = (char_u)TOLOWER_ASC(p_hlg[3]); - p_hlg[1] = (char_u)TOLOWER_ASC(p_hlg[4]); - } else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C') { + if (STRNICMP(p_hlg, "zh_", 3) == 0 && strlen(p_hlg) >= 5) { + p_hlg[0] = (char)TOLOWER_ASC(p_hlg[3]); + p_hlg[1] = (char)TOLOWER_ASC(p_hlg[4]); + } else if (strlen(p_hlg) >= 1 && *p_hlg == 'C') { // any C like setting, such as C.UTF-8, becomes "en" p_hlg[0] = 'e'; p_hlg[1] = 'n'; @@ -1686,9 +1686,9 @@ static char *option_expand(int opt_idx, char *val) // Escape spaces when expanding 'tags', they are used to separate file // names. // For 'spellsuggest' expand after "file:". - expand_env_esc((char_u *)val, (char_u *)NameBuff, MAXPATHL, + expand_env_esc(val, NameBuff, MAXPATHL, (char_u **)options[opt_idx].var == &p_tags, false, - (char_u **)options[opt_idx].var == (char_u **)&p_sps ? (char_u *)"file:" : + (char_u **)options[opt_idx].var == (char_u **)&p_sps ? "file:" : NULL); if (strcmp(NameBuff, val) == 0) { // they are the same return NULL; @@ -4565,13 +4565,13 @@ static char_u expand_option_name[5] = { 't', '_', NUL, NUL, NUL }; static int expand_option_flags = 0; /// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL -void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) +void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) { - char_u nextchar; + char nextchar; uint32_t flags = 0; // init for GCC int opt_idx = 0; // init for GCC - char_u *p; - char_u *s; + char *p; + char *s; int is_term_option = false; int key; @@ -4579,12 +4579,12 @@ void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) xp->xp_context = EXPAND_SETTINGS; if (*arg == NUL) { - xp->xp_pattern = (char *)arg; + xp->xp_pattern = arg; return; } - p = arg + STRLEN(arg) - 1; + p = arg + strlen(arg) - 1; if (*p == ' ' && *(p - 1) != '\\') { - xp->xp_pattern = (char *)p + 1; + xp->xp_pattern = p + 1; return; } while (p > arg) { @@ -4610,7 +4610,7 @@ void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) xp->xp_context = EXPAND_BOOL_SETTINGS; p += 3; } - xp->xp_pattern = (char *)p; + xp->xp_pattern = p; arg = p; if (*arg == '<') { while (*p != '>') { @@ -4618,7 +4618,7 @@ void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) return; } } - key = get_special_key_code(arg + 1); + key = get_special_key_code((char_u *)arg + 1); if (key == 0) { // unknown name xp->xp_context = EXPAND_NOTHING; return; @@ -4638,8 +4638,8 @@ void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) } nextchar = *++p; is_term_option = true; - expand_option_name[2] = p[-2]; - expand_option_name[3] = p[-1]; + expand_option_name[2] = (char_u)p[-2]; + expand_option_name[3] = (char_u)p[-1]; } else { // Allow * wildcard. while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*') { @@ -4678,7 +4678,7 @@ void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) } else { expand_option_idx = opt_idx; } - xp->xp_pattern = (char *)p + 1; + xp->xp_pattern = p + 1; return; } xp->xp_context = EXPAND_NOTHING; @@ -4686,29 +4686,29 @@ void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) return; } - xp->xp_pattern = (char *)p + 1; + xp->xp_pattern = p + 1; if (flags & P_EXPAND) { - p = options[opt_idx].var; - if (p == (char_u *)&p_bdir - || p == (char_u *)&p_dir - || p == (char_u *)&p_path - || p == (char_u *)&p_pp - || p == (char_u *)&p_rtp - || p == (char_u *)&p_cdpath - || p == (char_u *)&p_vdir) { + p = (char *)options[opt_idx].var; + if (p == (char *)&p_bdir + || p == (char *)&p_dir + || p == (char *)&p_path + || p == (char *)&p_pp + || p == (char *)&p_rtp + || p == (char *)&p_cdpath + || p == (char *)&p_vdir) { xp->xp_context = EXPAND_DIRECTORIES; - if (p == (char_u *)&p_path || p == (char_u *)&p_cdpath) { + if (p == (char *)&p_path || p == (char *)&p_cdpath) { xp->xp_backslash = XP_BS_THREE; } else { xp->xp_backslash = XP_BS_ONE; } - } else if (p == (char_u *)&p_ft) { + } else if (p == (char *)&p_ft) { xp->xp_context = EXPAND_FILETYPE; } else { xp->xp_context = EXPAND_FILES; // for 'tags' need three backslashes for a space - if (p == (char_u *)&p_tags) { + if (p == (char *)&p_tags) { xp->xp_backslash = XP_BS_THREE; } else { xp->xp_backslash = XP_BS_ONE; @@ -4718,16 +4718,16 @@ void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) // For an option that is a list of file names, find the start of the // last file name. - for (p = arg + STRLEN(arg) - 1; p > (char_u *)xp->xp_pattern; p--) { + for (p = arg + strlen(arg) - 1; p > xp->xp_pattern; p--) { // count number of backslashes before ' ' or ',' if (*p == ' ' || *p == ',') { s = p; - while (s > (char_u *)xp->xp_pattern && *(s - 1) == '\\') { + while (s > xp->xp_pattern && *(s - 1) == '\\') { s--; } if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3)) || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0)) { - xp->xp_pattern = (char *)p + 1; + xp->xp_pattern = p + 1; break; } } @@ -4735,7 +4735,7 @@ void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) // for 'spellsuggest' start at "file:" if (options[opt_idx].var == (char_u *)&p_sps && STRNCMP(p, "file:", 5) == 0) { - xp->xp_pattern = (char *)p + 5; + xp->xp_pattern = p + 5; break; } } -- cgit From bd22585061b66d7f71d4832b4a81e950b3c9d19d Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index b78fc7c27a..01ad73005a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -771,7 +771,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, char *s = NULL; char_u *oldval = NULL; // previous value if *varp char *newval; - char_u *origval = NULL; + char *origval = NULL; char_u *origval_l = NULL; char_u *origval_g = NULL; char *saved_origval = NULL; @@ -807,9 +807,9 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, // When setting the local value of a global option, the old value may be // the global value. if (((int)options[opt_idx].indir & PV_BOTH) && (opt_flags & OPT_LOCAL)) { - origval = *(char_u **)get_varp(&options[opt_idx]); + origval = *(char **)get_varp(&options[opt_idx]); } else { - origval = oldval; + origval = (char *)oldval; } if (nextchar == '&') { // set to default val @@ -857,8 +857,8 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, break; } xfree(oldval); - if (origval == oldval) { - origval = *(char_u **)varp; + if ((char_u *)origval == oldval) { + origval = *(char **)varp; } if (origval_l == oldval) { origval_l = *(char_u **)varp; @@ -905,7 +905,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, // get a bit too much newlen = (unsigned)strlen(arg) + 1; if (op != OP_NONE) { - newlen += (unsigned)STRLEN(origval) + 1; + newlen += (unsigned)strlen(origval) + 1; } newval = xmalloc(newlen); s = newval; @@ -947,7 +947,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, xfree(newval); newlen = (unsigned)strlen(s) + 1; if (op != OP_NONE) { - newlen += (unsigned)STRLEN(origval) + 1; + newlen += (unsigned)strlen(origval) + 1; } newval = xmalloc(newlen); STRCPY(newval, s); @@ -958,8 +958,8 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, // and when adding to avoid duplicates int len = 0; if (op == OP_REMOVING || (flags & P_NODUP)) { - len = (int)STRLEN(newval); - s = find_dup_item((char *)origval, newval, flags); + len = (int)strlen(newval); + s = find_dup_item(origval, newval, flags); // do not add if already there if ((op == OP_ADDING || op == OP_PREPENDING) && s != NULL) { @@ -969,7 +969,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, // if no duplicate, move pointer to end of original value if (s == NULL) { - s = (char *)origval + (int)STRLEN(origval); + s = origval + (int)strlen(origval); } } @@ -977,7 +977,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, if (op == OP_ADDING || op == OP_PREPENDING) { comma = ((flags & P_COMMA) && *origval != NUL && *newval != NUL); if (op == OP_ADDING) { - len = (int)STRLEN(origval); + len = (int)strlen(origval); // Strip a trailing comma, would get 2. if (comma && len > 1 && (flags & P_ONECOMMA) == P_ONECOMMA @@ -1003,7 +1003,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, if (*s) { // may need to remove a comma if (flags & P_COMMA) { - if (s == (char *)origval) { + if (s == origval) { // include comma after string if (s[len] == ',') { len++; @@ -1014,7 +1014,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, len++; } } - STRMOVE(newval + (s - (char *)origval), s + len); + STRMOVE(newval + (s - origval), s + len); } } @@ -1050,7 +1050,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, *(char_u **)(varp) = (char_u *)newval; // origval may be freed by did_set_string_option(), make a copy. - saved_origval = (origval != NULL) ? xstrdup((char *)origval) : NULL; + saved_origval = (origval != NULL) ? xstrdup(origval) : NULL; saved_origval_l = (origval_l != NULL) ? xstrdup((char *)origval_l) : NULL; saved_origval_g = (origval_g != NULL) ? xstrdup((char *)origval_g) : NULL; -- cgit From b2bb3973d9c7f25acfead2718d74fcf5b1e4551e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 28 Nov 2022 20:01:36 +0800 Subject: vim-patch:9.0.0963: function name does not match autocmd event name (#21215) Problem: Function name does not match autocmd event name. Solution: Rename "optionsset" to "optionset". (closes vim/vim#11630) https://github.com/vim/vim/commit/269aa2b29ac3e4c0083d929e2477c95e7bd1177a --- src/nvim/option.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 01ad73005a..efeeac2968 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1084,8 +1084,8 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, if (*errmsg == NULL) { if (!starting) { - trigger_optionsset_string(opt_idx, opt_flags, saved_origval, saved_origval_l, - saved_origval_g, saved_newval); + trigger_optionset_string(opt_idx, opt_flags, saved_origval, saved_origval_l, + saved_origval_g, saved_newval); } if (options[opt_idx].flags & P_UI_OPTION) { ui_call_option_set(cstr_as_string(options[opt_idx].fullname), -- cgit From 3b96ccf7d35be90e49029dec76344d3d92ad91dc Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index efeeac2968..e67bacce61 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -539,7 +539,7 @@ static char *find_dup_item(char *origval, const char *newval, uint32_t flags) const size_t newlen = strlen(newval); for (char *s = origval; *s != NUL; s++) { if ((!(flags & P_COMMA) || s == origval || (s[-1] == ',' && !(bs & 1))) - && STRNCMP(s, newval, newlen) == 0 + && strncmp(s, newval, newlen) == 0 && (!(flags & P_COMMA) || s[newlen] == ',' || s[newlen] == NUL)) { return s; } @@ -1144,7 +1144,7 @@ int do_set(char *arg, int opt_flags) errmsg = NULL; startarg = arg; // remember for error message - if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3]) + if (strncmp(arg, "all", 3) == 0 && !isalpha(arg[3]) && !(opt_flags & OPT_MODELINE)) { // ":set all" show all options. // ":set all&" set all options to their default value. @@ -1163,10 +1163,10 @@ int do_set(char *arg, int opt_flags) } } else { prefix = 1; - if (STRNCMP(arg, "no", 2) == 0) { + if (strncmp(arg, "no", 2) == 0) { prefix = 0; arg += 2; - } else if (STRNCMP(arg, "inv", 3) == 0) { + } else if (strncmp(arg, "inv", 3) == 0) { prefix = 2; arg += 3; } @@ -2714,7 +2714,7 @@ int findoption_len(const char *const arg, const size_t len) opt_idx = -1; } else { // Nvim: handle option aliases. - if (STRNCMP(options[opt_idx].fullname, "viminfo", 7) == 0) { + if (strncmp(options[opt_idx].fullname, "viminfo", 7) == 0) { if (strlen(options[opt_idx].fullname) == 7) { return findoption_len("shada", 5); } @@ -4602,11 +4602,11 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) } p--; } - if (STRNCMP(p, "no", 2) == 0) { + if (strncmp(p, "no", 2) == 0) { xp->xp_context = EXPAND_BOOL_SETTINGS; p += 2; } - if (STRNCMP(p, "inv", 3) == 0) { + if (strncmp(p, "inv", 3) == 0) { xp->xp_context = EXPAND_BOOL_SETTINGS; p += 3; } @@ -4734,7 +4734,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) // for 'spellsuggest' start at "file:" if (options[opt_idx].var == (char_u *)&p_sps - && STRNCMP(p, "file:", 5) == 0) { + && strncmp(p, "file:", 5) == 0) { xp->xp_pattern = p + 5; break; } @@ -5116,16 +5116,16 @@ int fill_culopt_flags(char *val, win_T *wp) p = val; } while (*p != NUL) { - if (STRNCMP(p, "line", 4) == 0) { + if (strncmp(p, "line", 4) == 0) { p += 4; culopt_flags_new |= CULOPT_LINE; - } else if (STRNCMP(p, "both", 4) == 0) { + } else if (strncmp(p, "both", 4) == 0) { p += 4; culopt_flags_new |= CULOPT_LINE | CULOPT_NBR; - } else if (STRNCMP(p, "number", 6) == 0) { + } else if (strncmp(p, "number", 6) == 0) { p += 6; culopt_flags_new |= CULOPT_NBR; - } else if (STRNCMP(p, "screenline", 10) == 0) { + } else if (strncmp(p, "screenline", 10) == 0) { p += 10; culopt_flags_new |= CULOPT_SCRLINE; } @@ -5159,8 +5159,8 @@ int option_set_callback_func(char *optval, Callback *optcb) typval_T *tv; if (*optval == '{' - || (STRNCMP(optval, "function(", 9) == 0) - || (STRNCMP(optval, "funcref(", 8) == 0)) { + || (strncmp(optval, "function(", 9) == 0) + || (strncmp(optval, "funcref(", 8) == 0)) { // Lambda expression or a funcref tv = eval_expr(optval); if (tv == NULL) { -- cgit From 1aad5af637b0fc042e1155cc0955931e9ca75295 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 20:44:26 +0800 Subject: vim-patch:8.2.3829: no error when setting a func option to script-local function Problem: No error when setting a func option to a script-local function. Solution: Give an error if the name starts with "s:". (closes vim/vim#9358) https://github.com/vim/vim/commit/94c785d235dccacf6cdf38c5903115b61ca8a981 Omit test: reverted in patch 8.2.3838. Cherry-pick SCRIPT_ID_VALID from patch 8.2.1539. Co-authored-by: Bram Moolenaar --- src/nvim/option.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index e67bacce61..72090fdbcc 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5157,6 +5157,10 @@ int option_set_callback_func(char *optval, Callback *optcb) return OK; } + if (strncmp(optval, "s:", 2) == 0 && !SCRIPT_ID_VALID(current_sctx.sc_sid)) { + return FAIL; + } + typval_T *tv; if (*optval == '{' || (strncmp(optval, "function(", 9) == 0) -- cgit From 7d1019442642d51f1af49bafa3b0450841129c2d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 20:47:52 +0800 Subject: vim-patch:8.2.3838: cannot use script-local function for setting *func options Problem: Cannot use script-local function for setting *func options. Solution: Use the script context. (Yegappan Lakshmanan, closes vim/vim#9362) https://github.com/vim/vim/commit/db1a410b610b2c1941311acc57dcc4afec20720e Co-authored-by: Yegappan Lakshmanan --- src/nvim/option.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 72090fdbcc..6d461d9b9d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5157,10 +5157,6 @@ int option_set_callback_func(char *optval, Callback *optcb) return OK; } - if (strncmp(optval, "s:", 2) == 0 && !SCRIPT_ID_VALID(current_sctx.sc_sid)) { - return FAIL; - } - typval_T *tv; if (*optval == '{' || (strncmp(optval, "function(", 9) == 0) @@ -5174,7 +5170,26 @@ int option_set_callback_func(char *optval, Callback *optcb) // treat everything else as a function name string tv = xcalloc(1, sizeof(*tv)); tv->v_type = VAR_STRING; - tv->vval.v_string = xstrdup(optval); + + // Function name starting with "s:" are supported only in a vimscript + // context. + if (strncmp(optval, "s:", 2) == 0) { + char sid_buf[25]; + + if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) { + emsg(_(e_usingsid)); + return FAIL; + } + // Expand s: prefix into nr_ + snprintf(sid_buf, sizeof(sid_buf), "%" PRId64 "_", + (int64_t)current_sctx.sc_sid); + char *funcname = xmalloc(strlen(sid_buf) + strlen(optval + 2) + 1); + STRCPY(funcname, sid_buf); + STRCAT(funcname, optval + 2); + tv->vval.v_string = funcname; + } else { + tv->vval.v_string = xstrdup(optval); + } } Callback cb; -- cgit From 70ac0c9358251bf54f29a30a369880d94680ace7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 21:00:27 +0800 Subject: vim-patch:8.2.3889: duplicate code for translating script-local function name Problem: Duplicate code for translating script-local function name. Solution: Move the code to get_scriptlocal_funcname(). (Yegappan Lakshmanan, closes vim/vim#9393) https://github.com/vim/vim/commit/e7f4abd38b6e05100c699900c8f87281e363beb2 Co-authored-by: Yegappan Lakshmanan --- src/nvim/option.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 6d461d9b9d..e67bacce61 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5170,26 +5170,7 @@ int option_set_callback_func(char *optval, Callback *optcb) // treat everything else as a function name string tv = xcalloc(1, sizeof(*tv)); tv->v_type = VAR_STRING; - - // Function name starting with "s:" are supported only in a vimscript - // context. - if (strncmp(optval, "s:", 2) == 0) { - char sid_buf[25]; - - if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) { - emsg(_(e_usingsid)); - return FAIL; - } - // Expand s: prefix into nr_ - snprintf(sid_buf, sizeof(sid_buf), "%" PRId64 "_", - (int64_t)current_sctx.sc_sid); - char *funcname = xmalloc(strlen(sid_buf) + strlen(optval + 2) + 1); - STRCPY(funcname, sid_buf); - STRCAT(funcname, optval + 2); - tv->vval.v_string = funcname; - } else { - tv->vval.v_string = xstrdup(optval); - } + tv->vval.v_string = xstrdup(optval); } Callback cb; -- cgit From a91ba088abf7b21f640f671ad7f211c0957b4765 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Dec 2022 08:38:38 +0800 Subject: vim-patch:8.2.2182: Vim9: value of 'magic' is still relevant Problem: Vim9: value of 'magic' is still relevant. Solution: Always behave like 'magic' is on in Vim9 script (closes vim/vim#7509) https://github.com/vim/vim/commit/f4e2099e39ed4d71aed0f9a9579455aed5ec6cc2 EX_NONWHITE_OK is N/A: only applies to Vim9 script. Co-authored-by: Bram Moolenaar --- src/nvim/option.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index e67bacce61..eac8e09d9e 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5147,6 +5147,20 @@ int fill_culopt_flags(char *val, win_T *wp) return OK; } +/// Get the value of 'magic' taking "magic_overruled" into account. +bool magic_isset(void) +{ + switch (magic_overruled) { + case MAGIC_ON: + return true; + case MAGIC_OFF: + return false; + case MAGIC_NOT_SET: + break; + } + return p_magic; +} + /// Set the callback function value for an option that accepts a function name, /// lambda, et al. (e.g. 'operatorfunc', 'tagfunc', etc.) /// @return OK if the option is successfully set to a function, otherwise FAIL -- cgit From 46e4be0fd0002233bde613295607ce5eeb498567 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 4 Dec 2022 09:09:00 +0800 Subject: vim-patch:8.2.2295: incsearch does not detect empty pattern properly Problem: Incsearch does not detect empty pattern properly. Solution: Return magic state when skipping over a pattern. (Christian Brabandt, closes vim/vim#7612, closes vim/vim#6420) https://github.com/vim/vim/commit/d93a7fc1a98a58f8101ee780d4735079ad99ae35 --- src/nvim/option.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index eac8e09d9e..b1feac7d1b 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5151,11 +5151,11 @@ int fill_culopt_flags(char *val, win_T *wp) bool magic_isset(void) { switch (magic_overruled) { - case MAGIC_ON: + case OPTION_MAGIC_ON: return true; - case MAGIC_OFF: + case OPTION_MAGIC_OFF: return false; - case MAGIC_NOT_SET: + case OPTION_MAGIC_NOT_SET: break; } return p_magic; -- cgit From 4ca3519a7a5467047f645b9a99fc303a5016651e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 16 Dec 2022 11:24:44 +0000 Subject: refactor(option.c): reduce scope of locals (#21433) Co-authored-by: zeertzjq --- src/nvim/option.c | 160 +++++++++++++++++++++--------------------------------- 1 file changed, 61 insertions(+), 99 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index b1feac7d1b..1659de395a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -560,9 +560,7 @@ static char *find_dup_item(char *origval, const char *newval, uint32_t flags) /// Used for 'lines' and 'columns'. void set_number_default(char *name, long val) { - int opt_idx; - - opt_idx = findoption(name); + int opt_idx = findoption(name); if (opt_idx >= 0) { options[opt_idx].def_val = (char *)(intptr_t)val; } @@ -726,12 +724,10 @@ void set_helplang_default(const char *lang) /// machine. void set_title_defaults(void) { - int idx1; - // If GUI is (going to be) used, we can always set the window title and // icon name. Saves a bit of time, because the X11 display server does // not need to be contacted. - idx1 = findoption("title"); + int idx1 = findoption("title"); if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET)) { options[idx1].def_val = 0; p_title = 0; @@ -770,7 +766,6 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, char *save_arg = NULL; char *s = NULL; char_u *oldval = NULL; // previous value if *varp - char *newval; char *origval = NULL; char_u *origval_l = NULL; char_u *origval_g = NULL; @@ -778,8 +773,6 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, char *saved_origval_l = NULL; char *saved_origval_g = NULL; char *saved_newval = NULL; - unsigned newlen; - int comma; char whichwrap[80]; // When using ":set opt=val" for a global option @@ -812,6 +805,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, origval = (char *)oldval; } + char *newval; if (nextchar == '&') { // set to default val newval = options[opt_idx].def_val; // expand environment variables and ~ since the default value was @@ -903,9 +897,9 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, // backslashes. // get a bit too much - newlen = (unsigned)strlen(arg) + 1; + size_t newlen = strlen(arg) + 1; if (op != OP_NONE) { - newlen += (unsigned)strlen(origval) + 1; + newlen += strlen(origval) + 1; } newval = xmalloc(newlen); s = newval; @@ -975,7 +969,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, // concatenate the two strings; add a ',' if needed if (op == OP_ADDING || op == OP_PREPENDING) { - comma = ((flags & P_COMMA) && *origval != NUL && *newval != NUL); + int comma = ((flags & P_COMMA) && *origval != NUL && *newval != NUL); if (op == OP_ADDING) { len = (int)strlen(origval); // Strip a trailing comma, would get 2. @@ -1118,21 +1112,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, /// @return FAIL if an error is detected, OK otherwise int do_set(char *arg, int opt_flags) { - int opt_idx; - char *errmsg; - char errbuf[80]; - char *startarg; - int prefix; // 1: nothing, 0: "no", 2: "inv" in front of name - char_u nextchar; // next non-white char after option name - int afterchar; // character just after option name - int len; - int i; - varnumber_T value; - int key; - uint32_t flags; // flags for current option - char *varp = NULL; // pointer to variable for current option int did_show = false; // already showed one value - set_op_T op = 0; if (*arg == NUL) { showoptions(0, opt_flags); @@ -1140,9 +1120,11 @@ int do_set(char *arg, int opt_flags) goto theend; } + char errbuf[80]; + while (*arg != NUL) { // loop to process all options - errmsg = NULL; - startarg = arg; // remember for error message + char *errmsg = NULL; + char *startarg = arg; // remember for error message if (strncmp(arg, "all", 3) == 0 && !isalpha(arg[3]) && !(opt_flags & OPT_MODELINE)) { @@ -1162,7 +1144,7 @@ int do_set(char *arg, int opt_flags) did_show = true; } } else { - prefix = 1; + int prefix = 1; // 1: nothing, 0: "no", 2: "inv" in front of name if (strncmp(arg, "no", 2) == 0) { prefix = 0; arg += 2; @@ -1172,7 +1154,9 @@ int do_set(char *arg, int opt_flags) } // find end of name - key = 0; + int key = 0; + int len; + int opt_idx; if (*arg == '<') { opt_idx = -1; // look out for ;> @@ -1212,14 +1196,14 @@ int do_set(char *arg, int opt_flags) } // remember character after option name - afterchar = (uint8_t)arg[len]; + int afterchar = (uint8_t)arg[len]; // skip white space, allow ":set ai ?" while (ascii_iswhite(arg[len])) { len++; } - op = OP_NONE; + set_op_T op = OP_NONE; if (arg[len] != NUL && arg[len + 1] == '=') { if (arg[len] == '+') { op = OP_ADDING; // "+=" @@ -1232,13 +1216,16 @@ int do_set(char *arg, int opt_flags) len++; } } - nextchar = (uint8_t)arg[len]; + char_u nextchar = (uint8_t)arg[len]; // next non-white char after option name if (opt_idx == -1 && key == 0) { // found a mismatch: skip errmsg = e_unknown_option; goto skip; } + uint32_t flags; // flags for current option + char *varp = NULL; // pointer to variable for current option + if (opt_idx >= 0) { if (options[opt_idx].var == NULL) { // hidden option: skip // Only give an error message when requesting the value of @@ -1352,6 +1339,7 @@ int do_set(char *arg, int opt_flags) } } else { int value_checked = false; + varnumber_T value; if (flags & P_BOOL) { // boolean if (nextchar == '=' || nextchar == ':') { @@ -1428,6 +1416,7 @@ int do_set(char *arg, int opt_flags) goto skip; } } else if (*arg == '-' || ascii_isdigit(*arg)) { + int i; // Allow negative, octal and hex numbers. vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0, true); if (i == 0 || (arg[i] != NUL && !ascii_iswhite(arg[i]))) { @@ -1476,7 +1465,7 @@ skip: // - skip until a blank found, taking care of backslashes // - skip blanks // - skip one "=val" argument (for hidden options ":set gfn =xx") - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { while (*arg != NUL && !ascii_iswhite(*arg)) { if (*arg++ == '\\' && *arg != NUL) { arg++; @@ -1491,7 +1480,7 @@ skip: if (errmsg != NULL) { STRLCPY(IObuff, _(errmsg), IOSIZE); - i = (int)strlen(IObuff) + 2; + int i = (int)strlen(IObuff) + 2; if (i + (arg - startarg) < IOSIZE) { // append the argument with the error STRCAT(IObuff, ": "); @@ -1632,9 +1621,7 @@ void set_options_bin(int oldval, int newval, int opt_flags) /// number, return -1. int get_shada_parameter(int type) { - char_u *p; - - p = find_shada_parameter(type); + char_u *p = find_shada_parameter(type); if (p != NULL && ascii_isdigit(*p)) { return atoi((char *)p); } @@ -2661,14 +2648,13 @@ void check_redraw(uint32_t flags) int findoption_len(const char *const arg, const size_t len) { const char *s; - const char *p; static int quick_tab[27] = { 0, 0 }; // quick access table // For first call: Initialize the quick-access table. // It contains the index for the first option that starts with a certain // letter. There are 26 letters, plus the first "t_" option. if (quick_tab[1] == 0) { - p = options[0].fullname; + const char *p = options[0].fullname; for (uint16_t i = 1; (s = options[i].fullname) != NULL; i++) { if (s[0] != p[0]) { if (s[0] == 't' && s[1] == '_') { @@ -3033,10 +3019,7 @@ char *set_option_value(const char *const name, const long number, const char *co return NULL; // Fail silently; many old vimrcs set t_xx options. } - int opt_idx; - char_u *varp; - - opt_idx = findoption(name); + int opt_idx = findoption(name); if (opt_idx < 0) { semsg(_("E355: Unknown option: %s"), name); } else { @@ -3054,7 +3037,7 @@ char *set_option_value(const char *const name, const long number, const char *co return set_string_option(opt_idx, s, opt_flags); } - varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); + char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); if (varp != NULL) { // hidden option is not changed if (number == 0 && string != NULL) { int idx; @@ -3125,7 +3108,6 @@ bool is_string_option(const char *name) int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt) { int key = 0; - int modifiers; const char_u *arg = arg_arg; // Don't use get_special_key_code() for t_xx, we don't want it to call @@ -3134,7 +3116,7 @@ int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt) key = TERMCAP2KEY(arg[2], arg[3]); } else if (has_lt) { arg--; // put arg at the '<' - modifiers = 0; + int modifiers = 0; key = find_special_key(&arg, len + 1, &modifiers, FSK_KEYCODE | FSK_KEEP_X_KEY | FSK_SIMPLIFY, NULL); if (modifiers) { // can't handle modifiers here @@ -3155,16 +3137,6 @@ static int find_key_option(const char *arg, bool has_lt) /// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL static void showoptions(int all, int opt_flags) { - vimoption_T *p; - int col; - char_u *varp; - int item_count; - int run; - int row, rows; - int cols; - int i; - int len; - #define INC 20 #define GAP 3 @@ -3183,16 +3155,16 @@ static void showoptions(int all, int opt_flags) // 1. display the short items // 2. display the long items (only strings and numbers) // When "opt_flags" has OPT_ONECOLUMN do everything in run 2. - for (run = 1; run <= 2 && !got_int; run++) { + for (int run = 1; run <= 2 && !got_int; run++) { // collect the items in items[] - item_count = 0; - for (p = &options[0]; p->fullname != NULL; p++) { + int item_count = 0; + for (vimoption_T *p = &options[0]; p->fullname != NULL; p++) { // apply :filter /pat/ if (message_filtered(p->fullname)) { continue; } - varp = NULL; + char_u *varp = NULL; if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) != 0) { if (p->indir != PV_NONE) { varp = (char_u *)get_varp_scope(p, opt_flags); @@ -3202,6 +3174,7 @@ static void showoptions(int all, int opt_flags) } if (varp != NULL && (all == 1 || (all == 0 && !optval_default(p, varp)))) { + int len; if (opt_flags & OPT_ONECOLUMN) { len = Columns; } else if (p->flags & P_BOOL) { @@ -3217,13 +3190,15 @@ static void showoptions(int all, int opt_flags) } } + int rows; + // display the items if (run == 1) { assert(Columns <= INT_MAX - GAP && Columns + GAP >= INT_MIN + 3 && (Columns + GAP - 3) / INC >= INT_MIN && (Columns + GAP - 3) / INC <= INT_MAX); - cols = (Columns + GAP - 3) / INC; + int cols = (Columns + GAP - 3) / INC; if (cols == 0) { cols = 1; } @@ -3231,13 +3206,13 @@ static void showoptions(int all, int opt_flags) } else { // run == 2 rows = item_count; } - for (row = 0; row < rows && !got_int; row++) { + for (int row = 0; row < rows && !got_int; row++) { msg_putchar('\n'); // go to next line if (got_int) { // 'q' typed in more break; } - col = 0; - for (i = row; i < item_count; i += rows) { + int col = 0; + for (int i = row; i < item_count; i += rows) { msg_col = col; // make columns showoneopt(items[i], opt_flags); col += INC; @@ -3346,14 +3321,6 @@ static void showoneopt(vimoption_T *p, int opt_flags) /// Return FAIL on error, OK otherwise. int makeset(FILE *fd, int opt_flags, int local_only) { - vimoption_T *p; - char *varp; // currently used value - char_u *varp_fresh; // local value - char_u *varp_local = NULL; // fresh value - char *cmd; - int round; - int pri; - // Some options are never written: // - Options that don't have a default (terminal name, columns, lines). // - Terminal options. @@ -3361,8 +3328,8 @@ int makeset(FILE *fd, int opt_flags, int local_only) // // Do the loop over "options[]" twice: once for options with the // P_PRI_MKRC flag and once without. - for (pri = 1; pri >= 0; pri--) { - for (p = &options[0]; p->fullname; p++) { + for (int pri = 1; pri >= 0; pri--) { + for (vimoption_T *p = &options[0]; p->fullname; p++) { if (!(p->flags & P_NO_MKRC) && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0))) { // skip global option when only doing locals @@ -3376,7 +3343,7 @@ int makeset(FILE *fd, int opt_flags, int local_only) continue; } - varp = get_varp_scope(p, opt_flags); + char *varp = get_varp_scope(p, opt_flags); // currently used value // Hidden options are never written. if (!varp) { continue; @@ -3391,7 +3358,8 @@ int makeset(FILE *fd, int opt_flags, int local_only) continue; } - round = 2; + int round = 2; + char_u *varp_local = NULL; // fresh value if (p->indir != PV_NONE) { if (p->var == VAR_WIN) { // skip window-local option when only doing globals @@ -3401,7 +3369,7 @@ int makeset(FILE *fd, int opt_flags, int local_only) // When fresh value of window-local option is not at the // default, need to write it too. if (!(opt_flags & OPT_GLOBAL) && !local_only) { - varp_fresh = (char_u *)get_varp_scope(p, OPT_GLOBAL); + char_u *varp_fresh = (char_u *)get_varp_scope(p, OPT_GLOBAL); // local value if (!optval_default(p, varp_fresh)) { round = 1; varp_local = (char_u *)varp; @@ -3414,6 +3382,7 @@ int makeset(FILE *fd, int opt_flags, int local_only) // Round 1: fresh value for window-local options. // Round 2: other values for (; round <= 2; varp = (char *)varp_local, round++) { + char *cmd; if (round == 1 || (opt_flags & OPT_GLOBAL)) { cmd = "set"; } else { @@ -3477,10 +3446,8 @@ int makefoldset(FILE *fd) static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_t flags) { - char_u *s; char_u *buf = NULL; char_u *part = NULL; - char *p; if (fprintf(fd, "%s %s=", cmd, name) < 0) { return FAIL; @@ -3490,7 +3457,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ // options some characters have to be escaped with // CTRL-V or backslash if (valuep == &p_pt) { - s = (char_u *)(*valuep); + char_u *s = (char_u *)(*valuep); while (*s != NUL) { if (put_escstr(fd, (char_u *)str2special((const char **)&s, false, false), 2) == FAIL) { return FAIL; @@ -3514,7 +3481,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ if (put_eol(fd) == FAIL) { goto fail; } - p = (char *)buf; + char *p = (char *)buf; while (*p != NUL) { // for each comma separated option part, append value to // the option, :set rtp+=value @@ -4266,7 +4233,6 @@ void buf_copy_options(buf_T *buf, int flags) { int should_copy = true; char_u *save_p_isk = NULL; // init for GCC - int dont_do_help; int did_isk = false; // Skip this when the option defaults have not been set yet. Happens when @@ -4297,7 +4263,7 @@ void buf_copy_options(buf_T *buf, int flags) // Don't copy the options specific to a help buffer when // BCO_NOHELP is given or the options were initialized already // (jumping back to a help file with CTRL-T or CTRL-O) - dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) || buf->b_p_initialized; + bool dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) || buf->b_p_initialized; if (dont_do_help) { // don't free b_p_isk save_p_isk = (char_u *)buf->b_p_isk; buf->b_p_isk = NULL; @@ -4567,13 +4533,10 @@ static int expand_option_flags = 0; /// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) { - char nextchar; uint32_t flags = 0; // init for GCC int opt_idx = 0; // init for GCC char *p; - char *s; int is_term_option = false; - int key; expand_option_flags = opt_flags; @@ -4588,7 +4551,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) return; } while (p > arg) { - s = p; + char *s = p; // count number of backslashes before ' ' or ',' if (*p == ' ' || *p == ',') { while (s > arg && *(s - 1) == '\\') { @@ -4612,13 +4575,16 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) } xp->xp_pattern = p; arg = p; + + char nextchar; + if (*arg == '<') { while (*p != '>') { if (*p++ == NUL) { // expand terminal option name return; } } - key = get_special_key_code((char_u *)arg + 1); + int key = get_special_key_code((char_u *)arg + 1); if (key == 0) { // unknown name xp->xp_context = EXPAND_NOTHING; return; @@ -4721,7 +4687,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) for (p = arg + strlen(arg) - 1; p > xp->xp_pattern; p--) { // count number of backslashes before ' ' or ',' if (*p == ' ' || *p == ',') { - s = p; + char *s = p; while (s > xp->xp_pattern && *(s - 1) == '\\') { s--; } @@ -4744,17 +4710,15 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***file) { int num_normal = 0; // Nr of matching non-term-code settings - int match; int count = 0; - char *str; - int loop; static char *(names[]) = { "all" }; int ic = regmatch->rm_ic; // remember the ignore-case flag // do this loop twice: // loop == 0: count the number of matching options // loop == 1: copy the matching options into allocated memory - for (loop = 0; loop <= 1; loop++) { + for (int loop = 0; loop <= 1; loop++) { + int match; regmatch->rm_ic = ic; if (xp->xp_context != EXPAND_BOOL_SETTINGS) { for (match = 0; match < (int)ARRAY_SIZE(names); @@ -4768,6 +4732,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi } } } + char *str; for (size_t opt_idx = 0; (str = options[opt_idx].fullname) != NULL; opt_idx++) { if (options[opt_idx].var == NULL) { @@ -5090,15 +5055,12 @@ void reset_option_was_set(const char *name) /// fill_breakat_flags() -- called when 'breakat' changes value. void fill_breakat_flags(void) { - char_u *p; - int i; - - for (i = 0; i < 256; i++) { + for (int i = 0; i < 256; i++) { breakat_flags[i] = false; } if (p_breakat != NULL) { - for (p = (char_u *)p_breakat; *p; p++) { + for (char_u *p = (char_u *)p_breakat; *p; p++) { breakat_flags[*p] = true; } } -- cgit From 614d382621fa0b9d19287b63edb39b637409c581 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 16 Dec 2022 17:33:52 +0100 Subject: refactor: rename mch_msg => os_msg --- src/nvim/option.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 1659de395a..6cc919a1c6 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1505,11 +1505,11 @@ theend: if (silent_mode && did_show) { // After displaying option values in silent mode. silent_mode = false; - info_message = true; // use mch_msg(), not mch_errmsg() + info_message = true; // use os_msg(), not os_errmsg() msg_putchar('\n'); ui_flush(); silent_mode = true; - info_message = false; // use mch_msg(), not mch_errmsg() + info_message = false; // use os_msg(), not os_errmsg() } return OK; @@ -3274,7 +3274,7 @@ static void showoneopt(vimoption_T *p, int opt_flags) int save_silent = silent_mode; silent_mode = false; - info_message = true; // use mch_msg(), not mch_errmsg() + info_message = true; // use os_msg(), not os_errmsg() char_u *varp = (char_u *)get_varp_scope(p, opt_flags); -- cgit From ec1738a6ed08dd3a89fd07950fa2dcc55a72b705 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 21 Dec 2022 12:00:05 +0100 Subject: refactor: replace char_u with char 16 - remove STRNCMP (#21208) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 6cc919a1c6..1a6707f128 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3108,12 +3108,12 @@ bool is_string_option(const char *name) int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt) { int key = 0; - const char_u *arg = arg_arg; + const char *arg = (char *)arg_arg; // Don't use get_special_key_code() for t_xx, we don't want it to call // add_termcap_entry(). if (len >= 4 && arg[0] == 't' && arg[1] == '_') { - key = TERMCAP2KEY(arg[2], arg[3]); + key = TERMCAP2KEY((uint8_t)arg[2], (uint8_t)arg[3]); } else if (has_lt) { arg--; // put arg at the '<' int modifiers = 0; -- cgit From b102bf22c009d3543f71d9d21c1252b54f5d4a54 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 29 Dec 2022 03:07:49 +0100 Subject: fix(ui): allow resize commands to set 'cmdheight' to 0 Resolve https://github.com/neovim/neovim/issues/21558 --- src/nvim/option.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 1a6707f128..6785529f59 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2280,6 +2280,8 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, int minval = 0; if (value < minval) { errmsg = e_positive; + } else { + p_ch_was_zero = value == 0; } } else if (pp == &p_tm) { if (value < 0) { -- cgit From 5841a97500bffa5a2b9eed2eb41025f5587790ba Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 3 Jan 2023 10:07:43 +0000 Subject: feat!: remove hardcopy Co-authored-by: Justin M. Keyes --- src/nvim/option.c | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 1a6707f128..03d8faa90a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -52,7 +52,6 @@ #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/grid_defs.h" -#include "nvim/hardcopy.h" #include "nvim/highlight.h" #include "nvim/highlight_group.h" #include "nvim/indent.h" @@ -287,28 +286,6 @@ void set_init_1(bool clean_arg) } } -#if defined(MSWIN) || defined(MAC) - // Set print encoding on platforms that don't default to latin1 - set_string_default("printencoding", "hp-roman8", false); -#endif - - // 'printexpr' must be allocated to be able to evaluate it. - set_string_default("printexpr", -#ifdef UNIX - "system(['lpr'] " - "+ (empty(&printdevice)?[]:['-P', &printdevice]) " - "+ [v:fname_in])" - ". delete(v:fname_in)" - "+ v:shell_error", -#elif defined(MSWIN) - "system(['copy', v:fname_in, " - "empty(&printdevice)?'LPT1':&printdevice])" - ". delete(v:fname_in)", -#else - "", -#endif - false); - char *backupdir = stdpaths_user_state_subpath("backup", 2, true); const size_t backupdir_len = strlen(backupdir); backupdir = xrealloc(backupdir, backupdir_len + 3); @@ -611,7 +588,6 @@ void set_init_2(bool headless) p_window = Rows - 1; } set_number_default("window", Rows - 1); - (void)parse_printoptions(); // parse 'printoptions' default value } /// Initialize the options, part three: After reading the .vimrc -- cgit From 08c2c7480619ccdf0c92fe6ce76da5b73b0e395b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 2d59eec91f..922cf6eb4f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -889,7 +889,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, if (*arg == '\\' && arg[1] != NUL #ifdef BACKSLASH_IN_FILENAME && !((flags & P_EXPAND) - && vim_isfilec(arg[1]) + && vim_isfilec((uint8_t)arg[1]) && !ascii_iswhite(arg[1]) && (arg[1] != '\\' || (s == newval && arg[2] != '\\'))) @@ -4752,7 +4752,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi void ExpandOldSetting(int *num_file, char ***file) { - char_u *var = NULL; + char *var = NULL; *num_file = 0; *file = xmalloc(sizeof(char_u *)); @@ -4765,14 +4765,14 @@ void ExpandOldSetting(int *num_file, char ***file) if (expand_option_idx >= 0) { // Put string of option value in NameBuff. option_value2string(&options[expand_option_idx], expand_option_flags); - var = (char_u *)NameBuff; + var = NameBuff; } else { - var = (char_u *)""; + var = ""; } // A backslash is required before some characters. This is the reverse of // what happens in do_set(). - char_u *buf = vim_strsave_escaped(var, escape_chars); + char_u *buf = vim_strsave_escaped((char_u *)var, escape_chars); #ifdef BACKSLASH_IN_FILENAME // For MS-Windows et al. we don't double backslashes at the start and @@ -4781,7 +4781,7 @@ void ExpandOldSetting(int *num_file, char ***file) if (var[0] == '\\' && var[1] == '\\' && expand_option_idx >= 0 && (options[expand_option_idx].flags & P_EXPAND) - && vim_isfilec(var[2]) + && vim_isfilec((uint8_t)var[2]) && (var[2] != '\\' || (var == buf && var[4] != '\\'))) { STRMOVE(var, var + 1); } -- cgit From 149209400383c673fdb4fdd1c9a7639139f17936 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 14:13:06 +0100 Subject: refactor: replace char_u with char 17 - remove STRLCPY (#21235) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 922cf6eb4f..06de8be129 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1455,7 +1455,7 @@ skip: } if (errmsg != NULL) { - STRLCPY(IObuff, _(errmsg), IOSIZE); + xstrlcpy(IObuff, _(errmsg), IOSIZE); int i = (int)strlen(IObuff) + 2; if (i + (arg - startarg) < IOSIZE) { // append the argument with the error @@ -4798,15 +4798,15 @@ void ExpandOldSetting(int *num_file, char ***file) /// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL static void option_value2string(vimoption_T *opp, int scope) { - char_u *varp = (char_u *)get_varp_scope(opp, scope); + char *varp = get_varp_scope(opp, scope); if (opp->flags & P_NUM) { long wc = 0; - if (wc_use_keyname(varp, &wc)) { - STRLCPY(NameBuff, get_special_key_name((int)wc, 0), sizeof(NameBuff)); + if (wc_use_keyname((char_u *)varp, &wc)) { + xstrlcpy(NameBuff, (char *)get_special_key_name((int)wc, 0), sizeof(NameBuff)); } else if (wc != 0) { - STRLCPY(NameBuff, transchar((int)wc), sizeof(NameBuff)); + xstrlcpy(NameBuff, (char *)transchar((int)wc), sizeof(NameBuff)); } else { snprintf((char *)NameBuff, sizeof(NameBuff), @@ -4814,16 +4814,16 @@ static void option_value2string(vimoption_T *opp, int scope) (int64_t)(*(long *)varp)); } } else { // P_STRING - varp = *(char_u **)(varp); + varp = *(char **)(varp); if (varp == NULL) { // Just in case. NameBuff[0] = NUL; } else if (opp->flags & P_EXPAND) { - home_replace(NULL, (char *)varp, (char *)NameBuff, MAXPATHL, false); + home_replace(NULL, varp, (char *)NameBuff, MAXPATHL, false); // Translate 'pastetoggle' into special key names. } else if ((char **)opp->var == &p_pt) { str2specialbuf((const char *)p_pt, (char *)NameBuff, MAXPATHL); } else { - STRLCPY(NameBuff, varp, MAXPATHL); + xstrlcpy(NameBuff, varp, MAXPATHL); } } } -- cgit From 50f03773f4b9f4638489ccfd0503dc9e39e5de78 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:37:34 +0100 Subject: refactor: replace char_u with char 18 (#21237) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 06de8be129..a6ec0a08c2 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1465,10 +1465,10 @@ skip: IObuff[i + (arg - startarg)] = NUL; } // make sure all characters are printable - trans_characters((char *)IObuff, IOSIZE); + trans_characters(IObuff, IOSIZE); no_wait_return++; // wait_return() done later - emsg((char *)IObuff); // show error highlighted + emsg(IObuff); // show error highlighted no_wait_return--; return FAIL; @@ -3159,7 +3159,7 @@ static void showoptions(int all, int opt_flags) len = 1; // a toggle option fits always } else { option_value2string(p, opt_flags); - len = (int)strlen(p->fullname) + vim_strsize((char *)NameBuff) + 1; + len = (int)strlen(p->fullname) + vim_strsize(NameBuff) + 1; } if ((len <= INC - GAP && run == 1) || (len > INC - GAP && run == 2)) { @@ -3270,7 +3270,7 @@ static void showoneopt(vimoption_T *p, int opt_flags) msg_putchar('='); // put value string in NameBuff option_value2string(p, opt_flags); - msg_outtrans((char *)NameBuff); + msg_outtrans(NameBuff); } silent_mode = save_silent; @@ -4808,7 +4808,7 @@ static void option_value2string(vimoption_T *opp, int scope) } else if (wc != 0) { xstrlcpy(NameBuff, (char *)transchar((int)wc), sizeof(NameBuff)); } else { - snprintf((char *)NameBuff, + snprintf(NameBuff, sizeof(NameBuff), "%" PRId64, (int64_t)(*(long *)varp)); @@ -4821,7 +4821,7 @@ static void option_value2string(vimoption_T *opp, int scope) home_replace(NULL, varp, (char *)NameBuff, MAXPATHL, false); // Translate 'pastetoggle' into special key names. } else if ((char **)opp->var == &p_pt) { - str2specialbuf((const char *)p_pt, (char *)NameBuff, MAXPATHL); + str2specialbuf((const char *)p_pt, NameBuff, MAXPATHL); } else { xstrlcpy(NameBuff, varp, MAXPATHL); } -- cgit From 364b131f42509326c912c9b0fef5dfc94ed23b41 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:12:06 +0100 Subject: feat(ui): add 'statuscolumn' option Problem: Unable to customize the column next to a window ('gutter'). Solution: Add 'statuscolumn' option that follows the 'statusline' syntax, allowing to customize the status column. Also supporting the %@ click execute function label. Adds new items @C and @s which will print the fold and sign columns. Line numbers and signs can be clicked, highlighted, aligned, transformed, margined etc. --- src/nvim/option.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index a6ec0a08c2..fe905a5a05 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2094,6 +2094,9 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va if (curwin->w_p_spell) { errmsg = did_set_spelllang(curwin); } + } else if (((int *)varp == &curwin->w_p_nu || (int *)varp == &curwin->w_p_rnu) + && *curwin->w_p_stc != NUL) { // '(relative)number' + 'statuscolumn' + curwin->w_nrwidth_line_count = 0; } if ((int *)varp == &curwin->w_p_arab) { @@ -2316,7 +2319,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, } else if (pp == &curwin->w_p_nuw || pp == &curwin->w_allbuf_opt.wo_nuw) { if (value < 1) { errmsg = e_positive; - } else if (value > 20) { + } else if (value > MAX_NUMBERWIDTH) { errmsg = e_invarg; } } else if (pp == &curbuf->b_p_iminsert || pp == &p_iminsert) { @@ -3630,6 +3633,9 @@ void unset_global_local_option(char *name, void *from) clear_string_option(&((win_T *)from)->w_p_ve); ((win_T *)from)->w_ve_flags = 0; break; + case PV_STC: + clear_string_option(&((win_T *)from)->w_p_stc); + break; } } @@ -4014,6 +4020,8 @@ static char_u *get_varp(vimoption_T *p) return (char_u *)&(curwin->w_p_winhl); case PV_WINBL: return (char_u *)&(curwin->w_p_winbl); + case PV_STC: + return (char_u *)&(curwin->w_p_stc); default: iemsg(_("E356: get_varp ERROR")); } @@ -4102,6 +4110,7 @@ void copy_winopt(winopt_T *from, winopt_T *to) to->wo_scl = copy_option_val(from->wo_scl); to->wo_winhl = copy_option_val(from->wo_winhl); to->wo_winbl = from->wo_winbl; + to->wo_stc = copy_option_val(from->wo_stc); // Copy the script context so that we know were the value was last set. memmove(to->wo_script_ctx, from->wo_script_ctx, sizeof(to->wo_script_ctx)); @@ -4139,6 +4148,7 @@ static void check_winopt(winopt_T *wop) check_string_option(&wop->wo_fcs); check_string_option(&wop->wo_ve); check_string_option(&wop->wo_wbr); + check_string_option(&wop->wo_stc); } /// Free the allocated memory inside a winopt_T. @@ -4165,6 +4175,7 @@ void clear_winopt(winopt_T *wop) clear_string_option(&wop->wo_fcs); clear_string_option(&wop->wo_ve); clear_string_option(&wop->wo_wbr); + clear_string_option(&wop->wo_stc); } void didset_window_options(win_T *wp, bool valid_cursor) -- cgit From f2141de9e462ed8976b2a59337c32a0fcba2a11d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 13 Jan 2023 00:35:39 +0100 Subject: refactor: replace char_u with char 20 (#21714) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index fe905a5a05..423787ecfc 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4783,7 +4783,7 @@ void ExpandOldSetting(int *num_file, char ***file) // A backslash is required before some characters. This is the reverse of // what happens in do_set(). - char_u *buf = vim_strsave_escaped((char_u *)var, escape_chars); + char_u *buf = (char_u *)vim_strsave_escaped(var, (char *)escape_chars); #ifdef BACKSLASH_IN_FILENAME // For MS-Windows et al. we don't double backslashes at the start and -- cgit From e89c39d6f016a4140293755250e968e839009617 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 14 Jan 2023 08:58:28 +0100 Subject: refactor: replace char_u with char 21 (#21779) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 423787ecfc..02c770e608 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -608,7 +608,7 @@ void set_init_3(void) : !(options[idx_sp].flags & P_WAS_SET); size_t len = 0; - char *p = (char *)invocation_path_tail((char_u *)p_sh, &len); + char *p = (char *)invocation_path_tail(p_sh, &len); p = xstrnsave(p, len); { @@ -741,7 +741,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, char *varp = varp_arg; char *save_arg = NULL; char *s = NULL; - char_u *oldval = NULL; // previous value if *varp + char *oldval = NULL; // previous value if *varp char *origval = NULL; char_u *origval_l = NULL; char_u *origval_g = NULL; @@ -760,7 +760,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, } // The old value is kept until we are sure that the new value is valid. - oldval = *(char_u **)varp; + oldval = *(char **)varp; if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) { origval_l = *(char_u **)get_varp_scope(&(options[opt_idx]), OPT_LOCAL); @@ -778,7 +778,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, if (((int)options[opt_idx].indir & PV_BOTH) && (opt_flags & OPT_LOCAL)) { origval = *(char **)get_varp(&options[opt_idx]); } else { - origval = (char *)oldval; + origval = oldval; } char *newval; @@ -827,16 +827,16 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, break; } xfree(oldval); - if ((char_u *)origval == oldval) { + if (origval == oldval) { origval = *(char **)varp; } - if (origval_l == oldval) { + if (origval_l == (char_u *)oldval) { origval_l = *(char_u **)varp; } - if (origval_g == oldval) { + if (origval_g == (char_u *)oldval) { origval_g = *(char_u **)varp; } - oldval = *(char_u **)varp; + oldval = *(char **)varp; } else if (varp == (char *)&p_ww && ascii_isdigit(*arg)) { // Convert 'whichwrap' number to string, for backwards compatibility // with Vim 3.0. @@ -1045,7 +1045,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, // Handle side effects, and set the global value for ":set" on local // options. Note: when setting 'syntax' or 'filetype' autocommands may // be triggered that can cause havoc. - *errmsg = did_set_string_option(opt_idx, (char **)varp, (char *)oldval, + *errmsg = did_set_string_option(opt_idx, (char **)varp, oldval, errbuf, errbuflen, opt_flags, value_checked); -- cgit From f72cb97fa0db63e14363af60f45d0f2a0a84cc27 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 17 Jan 2023 08:09:51 +0800 Subject: vim-patch:9.0.1208: code is indented more than necessary (#21846) Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes vim/vim#11819) https://github.com/vim/vim/commit/a41e221935edab62672a15123af48f4f14ac1c7d Cherry-pick check_text_or_curbuf_locked() from patch 9.0.0947. Co-authored-by: Yegappan Lakshmanan --- src/nvim/option.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 02c770e608..85725f36ea 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -674,23 +674,25 @@ void set_helplang_default(const char *lang) return; } int idx = findoption("hlg"); - if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) { - if (options[idx].flags & P_ALLOCED) { - free_string_option(p_hlg); - } - p_hlg = xmemdupz(lang, lang_len); - // zh_CN becomes "cn", zh_TW becomes "tw". - if (STRNICMP(p_hlg, "zh_", 3) == 0 && strlen(p_hlg) >= 5) { - p_hlg[0] = (char)TOLOWER_ASC(p_hlg[3]); - p_hlg[1] = (char)TOLOWER_ASC(p_hlg[4]); - } else if (strlen(p_hlg) >= 1 && *p_hlg == 'C') { - // any C like setting, such as C.UTF-8, becomes "en" - p_hlg[0] = 'e'; - p_hlg[1] = 'n'; - } - p_hlg[2] = NUL; - options[idx].flags |= P_ALLOCED; + if (idx < 0 || (options[idx].flags & P_WAS_SET)) { + return; + } + + if (options[idx].flags & P_ALLOCED) { + free_string_option(p_hlg); + } + p_hlg = xmemdupz(lang, lang_len); + // zh_CN becomes "cn", zh_TW becomes "tw". + if (STRNICMP(p_hlg, "zh_", 3) == 0 && strlen(p_hlg) >= 5) { + p_hlg[0] = (char)TOLOWER_ASC(p_hlg[3]); + p_hlg[1] = (char)TOLOWER_ASC(p_hlg[4]); + } else if (strlen(p_hlg) >= 1 && *p_hlg == 'C') { + // any C like setting, such as C.UTF-8, becomes "en" + p_hlg[0] = 'e'; + p_hlg[1] = 'n'; } + p_hlg[2] = NUL; + options[idx].flags |= P_ALLOCED; } /// 'title' and 'icon' only default to true if they have not been set or reset @@ -5035,10 +5037,11 @@ bool option_was_set(const char *name) void reset_option_was_set(const char *name) { const int idx = findoption(name); - - if (idx >= 0) { - options[idx].flags &= ~P_WAS_SET; + if (idx < 0) { + return; } + + options[idx].flags &= ~P_WAS_SET; } /// fill_breakat_flags() -- called when 'breakat' changes value. -- cgit From 6734dd250355f8621a710d59c2089b38a65dbf18 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 20 Feb 2022 00:18:15 +0000 Subject: vim-patch:8.2.4463: completion only uses strict matching Problem: Completion only uses strict matching. Solution: Add the "fuzzy" item for 'wildoptions'. (Yegappan Lakshmanan, closes vim/vim#9803) https://github.com/vim/vim/commit/38b85cb4d7216705058708bacbc25ab90cd61595 Use MAX_FUZZY_MATCHES in fuzzy_match_str(). Omit fuzmatch_str_free() as it is only used on allocation failure. Co-authored-by: Yegappan Lakshmanan --- src/nvim/option.c | 88 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 15 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 85725f36ea..aec91a4dc6 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -36,6 +36,7 @@ #include "nvim/buffer.h" #include "nvim/change.h" #include "nvim/charset.h" +#include "nvim/cmdexpand.h" #include "nvim/cursor_shape.h" #include "nvim/decoration_provider.h" #include "nvim/diff.h" @@ -81,6 +82,7 @@ #include "nvim/regexp.h" #include "nvim/runtime.h" #include "nvim/screen.h" +#include "nvim/search.h" #include "nvim/sign_defs.h" #include "nvim/spell.h" #include "nvim/spellfile.h" @@ -4698,13 +4700,56 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) } } -int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***file) +/// Returns true if "str" either matches "regmatch" or fuzzy matches "pat". +/// +/// If "test_only" is true and "fuzzy" is false and if "str" matches the regular +/// expression "regmatch", then returns true. Otherwise returns false. +/// +/// If "test_only" is false and "fuzzy" is false and if "str" matches the +/// regular expression "regmatch", then stores the match in matches[idx] and +/// returns true. +/// +/// If "test_only" is true and "fuzzy" is true and if "str" fuzzy matches +/// "fuzzystr", then returns true. Otherwise returns false. +/// +/// If "test_only" is false and "fuzzy" is true and if "str" fuzzy matches +/// "fuzzystr", then stores the match details in fuzmatch[idx] and returns true. +static bool match_str(char *const str, regmatch_T *const regmatch, char **const matches, + const int idx, const bool test_only, const bool fuzzy, + const char *const fuzzystr, fuzmatch_str_T *const fuzmatch) +{ + if (!fuzzy) { + if (vim_regexec(regmatch, str, (colnr_T)0)) { + if (!test_only) { + matches[idx] = xstrdup(str); + } + return true; + } + } else { + const int score = fuzzy_match_str(str, fuzzystr); + if (score != 0) { + if (!test_only) { + fuzmatch[idx].idx = idx; + fuzmatch[idx].str = xstrdup(str); + fuzmatch[idx].score = score; + } + return true; + } + } + return false; +} + +int ExpandSettings(expand_T *xp, regmatch_T *regmatch, char *fuzzystr, int *numMatches, + char ***matches) { int num_normal = 0; // Nr of matching non-term-code settings int count = 0; static char *(names[]) = { "all" }; int ic = regmatch->rm_ic; // remember the ignore-case flag + fuzmatch_str_T *fuzmatch = NULL; + const bool fuzzy = cmdline_fuzzy_complete(fuzzystr); + // do this loop twice: // loop == 0: count the number of matching options // loop == 1: copy the matching options into allocated memory @@ -4714,11 +4759,12 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi if (xp->xp_context != EXPAND_BOOL_SETTINGS) { for (match = 0; match < (int)ARRAY_SIZE(names); match++) { - if (vim_regexec(regmatch, names[match], (colnr_T)0)) { + if (match_str(names[match], regmatch, *matches, + count, (loop == 0), fuzzy, fuzzystr, fuzmatch)) { if (loop == 0) { num_normal++; } else { - (*file)[count++] = xstrdup(names[match]); + count++; } } } @@ -4733,33 +4779,45 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi && !(options[opt_idx].flags & P_BOOL)) { continue; } - match = false; - if (vim_regexec(regmatch, str, (colnr_T)0) - || (options[opt_idx].shortname != NULL - && vim_regexec(regmatch, - options[opt_idx].shortname, - (colnr_T)0))) { - match = true; - } - if (match) { + if (match_str(str, regmatch, *matches, count, (loop == 0), + fuzzy, fuzzystr, fuzmatch)) { if (loop == 0) { num_normal++; } else { - (*file)[count++] = xstrdup(str); + count++; + } + } else if (!fuzzy && options[opt_idx].shortname != NULL + && vim_regexec(regmatch, options[opt_idx].shortname, (colnr_T)0)) { + // Compare against the abbreviated option name (for regular + // expression match). Fuzzy matching (previous if) already + // matches against both the expanded and abbreviated names. + if (loop == 0) { + num_normal++; + } else { + (*matches)[count++] = xstrdup(str); } } } if (loop == 0) { if (num_normal > 0) { - *num_file = num_normal; + *numMatches = num_normal; } else { return OK; } - *file = xmalloc((size_t)(*num_file) * sizeof(char *)); + if (!fuzzy) { + *matches = xmalloc((size_t)(*numMatches) * sizeof(char *)); + } else { + fuzmatch = xmalloc((size_t)(*numMatches) * sizeof(fuzmatch_str_T)); + } } } + + if (fuzzy) { + fuzzymatches_to_strmatches(fuzmatch, matches, count, false); + } + return OK; } -- cgit From 58f2dcfc887134f5ebc33c13d7ef5ce540f8a247 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 17 Jan 2023 16:46:43 +0800 Subject: vim-patch:8.2.4917: fuzzy expansion of option names is not right (#21853) Problem: Fuzzy expansion of option names is not right. Solution: Pass the fuzzy flag down the call chain. (Christian Brabandt, closes vim/vim#10380, closes vim/vim#10318) https://github.com/vim/vim/commit/cb747899bd99361a299a163f3aa55d5fe7d6f798 Co-authored-by: Christian Brabandt --- src/nvim/option.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index aec91a4dc6..024bf3af09 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4740,7 +4740,7 @@ static bool match_str(char *const str, regmatch_T *const regmatch, char **const } int ExpandSettings(expand_T *xp, regmatch_T *regmatch, char *fuzzystr, int *numMatches, - char ***matches) + char ***matches, const bool can_fuzzy) { int num_normal = 0; // Nr of matching non-term-code settings int count = 0; @@ -4748,7 +4748,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, char *fuzzystr, int *numM int ic = regmatch->rm_ic; // remember the ignore-case flag fuzmatch_str_T *fuzmatch = NULL; - const bool fuzzy = cmdline_fuzzy_complete(fuzzystr); + const bool fuzzy = can_fuzzy && cmdline_fuzzy_complete(fuzzystr); // do this loop twice: // loop == 0: count the number of matching options -- cgit From 0344bfad0fc87d2e256ea2b80de7abd069ba1dd2 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 17 Jan 2023 14:17:40 +0100 Subject: refactor: replace char_u with char 22 (#21786) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 024bf3af09..0c2a2f7060 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -999,14 +999,14 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, // 'whichwrap' if (flags & P_ONECOMMA) { if (*s != ',' && *(s + 1) == ',' - && vim_strchr(s + 2, *s) != NULL) { + && vim_strchr(s + 2, (uint8_t)(*s)) != NULL) { // Remove the duplicated value and the next comma. STRMOVE(s, s + 2); continue; } } else { if ((!(flags & P_COMMA) || *s != ',') - && vim_strchr(s + 1, *s) != NULL) { + && vim_strchr(s + 1, (uint8_t)(*s)) != NULL) { STRMOVE(s, s + 1); continue; } @@ -1106,7 +1106,7 @@ int do_set(char *arg, int opt_flags) char *errmsg = NULL; char *startarg = arg; // remember for error message - if (strncmp(arg, "all", 3) == 0 && !isalpha(arg[3]) + if (strncmp(arg, "all", 3) == 0 && !isalpha((uint8_t)arg[3]) && !(opt_flags & OPT_MODELINE)) { // ":set all" show all options. // ":set all&" set all options to their default value. @@ -1210,7 +1210,7 @@ int do_set(char *arg, int opt_flags) if (options[opt_idx].var == NULL) { // hidden option: skip // Only give an error message when requesting the value of // a hidden option, ignore setting it. - if (vim_strchr("=:!&<", nextchar) == NULL + if (vim_strchr("=:!&<", (uint8_t)nextchar) == NULL && (!(options[opt_idx].flags & P_BOOL) || nextchar == '?')) { errmsg = e_unsupportedoption; @@ -1264,7 +1264,7 @@ int do_set(char *arg, int opt_flags) goto skip; } - if (vim_strchr("?=:!&<", nextchar) != NULL) { + if (vim_strchr("?=:!&<", (uint8_t)nextchar) != NULL) { arg += len; if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i') { if (arg[3] == 'm') { // "opt&vim": set to Vim default @@ -1273,7 +1273,7 @@ int do_set(char *arg, int opt_flags) arg += 2; } } - if (vim_strchr("?!&<", nextchar) != NULL + if (vim_strchr("?!&<", (uint8_t)nextchar) != NULL && arg[1] != NUL && !ascii_iswhite(arg[1])) { errmsg = e_trailing; goto skip; @@ -1286,7 +1286,7 @@ int do_set(char *arg, int opt_flags) // if (nextchar == '?' || (prefix == 1 - && vim_strchr("=:&<", nextchar) == NULL + && vim_strchr("=:&<", (uint8_t)nextchar) == NULL && !(flags & P_BOOL))) { // print value if (did_show) { @@ -1359,7 +1359,7 @@ int do_set(char *arg, int opt_flags) errmsg = set_bool_option(opt_idx, (char_u *)varp, (int)value, opt_flags); } else { // Numeric or string. - if (vim_strchr("=:&<", nextchar) == NULL + if (vim_strchr("=:&<", (uint8_t)nextchar) == NULL || prefix != 1) { errmsg = e_invarg; goto skip; @@ -1775,7 +1775,7 @@ bool valid_name(const char *val, const char *allowed) { for (const char_u *s = (char_u *)val; *s != NUL; s++) { if (!ASCII_ISALNUM(*s) - && vim_strchr(allowed, *s) == NULL) { + && vim_strchr(allowed, (uint8_t)(*s)) == NULL) { return false; } } @@ -1974,7 +1974,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, const int va || (opt_flags & OPT_GLOBAL) || opt_flags == 0) && !bufIsChanged(bp) && bp->b_ml.ml_mfp != NULL) { u_compute_hash(bp, hash); - u_read_undo(NULL, hash, (char_u *)bp->b_fname); + u_read_undo(NULL, hash, bp->b_fname); } } } @@ -5388,9 +5388,9 @@ size_t copy_option_part(char **option, char *buf, size_t maxlen, char *sep_chars if (*p == '.') { buf[len++] = *p++; } - while (*p != NUL && vim_strchr(sep_chars, *p) == NULL) { + while (*p != NUL && vim_strchr(sep_chars, (uint8_t)(*p)) == NULL) { // Skip backslash before a separator character and space. - if (p[0] == '\\' && vim_strchr(sep_chars, p[1]) != NULL) { + if (p[0] == '\\' && vim_strchr(sep_chars, (uint8_t)p[1]) != NULL) { p++; } if (len < maxlen - 1) { -- cgit From 9a2dd52a6a2a17ae85102d738ab3620ef978d448 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 18 Jan 2023 06:27:45 +0800 Subject: vim-patch:9.0.1215: using isalpha() adds dependency on current locale Problem: Using isalpha() adds dependency on current locale. Solution: Do not use isalpha() for recognizing a URL or the end of an Ex command. (closes vim/vim#11835) https://github.com/vim/vim/commit/0ef9a5c09482649cf0cc6768ed6fc640b4ed2a0a --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 0c2a2f7060..227001d556 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1106,7 +1106,7 @@ int do_set(char *arg, int opt_flags) char *errmsg = NULL; char *startarg = arg; // remember for error message - if (strncmp(arg, "all", 3) == 0 && !isalpha((uint8_t)arg[3]) + if (strncmp(arg, "all", 3) == 0 && !ASCII_ISALPHA(arg[3]) && !(opt_flags & OPT_MODELINE)) { // ":set all" show all options. // ":set all&" set all options to their default value. -- cgit From 8a4285d5637c146a0ae606918a8e77063c6a5f0d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 18 Jan 2023 14:17:11 +0100 Subject: refactor: replace char_u with char 24 (#21823) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 227001d556..2bd3dcfe2d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1390,7 +1390,7 @@ int do_set(char *arg, int opt_flags) || *arg == '^' || (*arg != NUL && (!arg[1] || ascii_iswhite(arg[1])) && !ascii_isdigit(*arg)))) { - value = string_to_key((char_u *)arg); + value = string_to_key(arg); if (value == 0 && (long *)varp != &p_wcm) { errmsg = e_invarg; goto skip; @@ -1520,15 +1520,15 @@ void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked /// Convert a key name or string into a key value. /// Used for 'wildchar' and 'cedit' options. -int string_to_key(char_u *arg) +int string_to_key(char *arg) { if (*arg == '<') { - return find_key_option((char *)arg + 1, true); + return find_key_option(arg + 1, true); } if (*arg == '^') { - return CTRL_CHR(arg[1]); + return CTRL_CHR((uint8_t)arg[1]); } - return *arg; + return (uint8_t)(*arg); } // When changing 'title', 'titlestring', 'icon' or 'iconstring', call @@ -1601,9 +1601,9 @@ void set_options_bin(int oldval, int newval, int opt_flags) /// number, return -1. int get_shada_parameter(int type) { - char_u *p = find_shada_parameter(type); + char *p = find_shada_parameter(type); if (p != NULL && ascii_isdigit(*p)) { - return atoi((char *)p); + return atoi(p); } return -1; } @@ -1611,11 +1611,11 @@ int get_shada_parameter(int type) /// Find the parameter represented by the given character (eg ''', ':', '"', or /// '/') in the 'shada' option and return a pointer to the string after it. /// Return NULL if the parameter is not specified in the string. -char_u *find_shada_parameter(int type) +char *find_shada_parameter(int type) { for (char *p = p_shada; *p; p++) { if (*p == type) { - return (char_u *)p + 1; + return p + 1; } if (*p == 'n') { // 'n' is always the last one break; @@ -1773,7 +1773,7 @@ void redraw_titles(void) bool valid_name(const char *val, const char *allowed) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { - for (const char_u *s = (char_u *)val; *s != NUL; s++) { + for (const char *s = val; *s != NUL; s++) { if (!ASCII_ISALNUM(*s) && vim_strchr(allowed, (uint8_t)(*s)) == NULL) { return false; @@ -3090,10 +3090,10 @@ bool is_string_option(const char *name) // Translate a string like "t_xx", "" or "" to a key number. // When "has_lt" is true there is a '<' before "*arg_arg". // Returns 0 when the key is not recognized. -int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt) +int find_key_option_len(const char *arg_arg, size_t len, bool has_lt) { int key = 0; - const char *arg = (char *)arg_arg; + const char *arg = arg_arg; // Don't use get_special_key_code() for t_xx, we don't want it to call // add_termcap_entry(). @@ -3113,7 +3113,7 @@ int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt) static int find_key_option(const char *arg, bool has_lt) { - return find_key_option_len((char_u *)arg, strlen(arg), has_lt); + return find_key_option_len(arg, strlen(arg), has_lt); } /// if 'all' == 0: show changed options @@ -3431,7 +3431,7 @@ int makefoldset(FILE *fd) static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_t flags) { - char_u *buf = NULL; + char *buf = NULL; char_u *part = NULL; if (fprintf(fd, "%s %s=", cmd, name) < 0) { @@ -3444,7 +3444,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ if (valuep == &p_pt) { char_u *s = (char_u *)(*valuep); while (*s != NUL) { - if (put_escstr(fd, (char_u *)str2special((const char **)&s, false, false), 2) == FAIL) { + if (put_escstr(fd, (char *)str2special((const char **)&s, false, false), 2) == FAIL) { return FAIL; } } @@ -3453,7 +3453,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ // replace home directory in the whole option value into "buf" buf = xmalloc(size); - home_replace(NULL, *valuep, (char *)buf, size, false); + home_replace(NULL, *valuep, buf, size, false); // If the option value is longer than MAXPATHL, we need to append // each comma separated part of the option separately, so that it @@ -3466,7 +3466,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ if (put_eol(fd) == FAIL) { goto fail; } - char *p = (char *)buf; + char *p = buf; while (*p != NUL) { // for each comma separated option part, append value to // the option, :set rtp+=value @@ -3474,7 +3474,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ goto fail; } (void)copy_option_part(&p, (char *)part, size, ","); - if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL) { + if (put_escstr(fd, (char *)part, 2) == FAIL || put_eol(fd) == FAIL) { goto fail; } } @@ -3487,7 +3487,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_ return FAIL; } xfree(buf); - } else if (put_escstr(fd, (char_u *)(*valuep), 2) == FAIL) { + } else if (put_escstr(fd, *valuep, 2) == FAIL) { return FAIL; } } @@ -4843,7 +4843,7 @@ void ExpandOldSetting(int *num_file, char ***file) // A backslash is required before some characters. This is the reverse of // what happens in do_set(). - char_u *buf = (char_u *)vim_strsave_escaped(var, (char *)escape_chars); + char_u *buf = (char_u *)vim_strsave_escaped(var, escape_chars); #ifdef BACKSLASH_IN_FILENAME // For MS-Windows et al. we don't double backslashes at the start and @@ -4877,7 +4877,7 @@ static void option_value2string(vimoption_T *opp, int scope) if (wc_use_keyname((char_u *)varp, &wc)) { xstrlcpy(NameBuff, (char *)get_special_key_name((int)wc, 0), sizeof(NameBuff)); } else if (wc != 0) { - xstrlcpy(NameBuff, (char *)transchar((int)wc), sizeof(NameBuff)); + xstrlcpy(NameBuff, transchar((int)wc), sizeof(NameBuff)); } else { snprintf(NameBuff, sizeof(NameBuff), @@ -5260,16 +5260,16 @@ unsigned int get_ve_flags(void) /// /// @param win If not NULL, the window to get the local option from; global /// otherwise. -char_u *get_showbreak_value(win_T *const win) +char *get_showbreak_value(win_T *const win) FUNC_ATTR_WARN_UNUSED_RESULT { if (win->w_p_sbr == NULL || *win->w_p_sbr == NUL) { - return (char_u *)p_sbr; + return p_sbr; } if (strcmp(win->w_p_sbr, "NONE") == 0) { - return (char_u *)empty_option; + return empty_option; } - return (char_u *)win->w_p_sbr; + return win->w_p_sbr; } /// Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC. -- cgit From 4c531714ff24d82bf1a85decf0e0c63c5785e686 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 19 Jan 2023 15:25:56 +0100 Subject: refactor: replace char_u with char 25 (#21838) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/option.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 2bd3dcfe2d..268a1514c8 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -381,12 +381,12 @@ void set_init_1(bool clean_arg) // enc_locale() will try to find the encoding of the current locale. // This will be used when 'default' is used as encoding specifier // in 'fileencodings' - char_u *p = enc_locale(); + char *p = enc_locale(); if (p == NULL) { // use utf-8 as 'default' if locale encoding can't be detected. - p = (char_u *)xmemdupz(S_LEN("utf-8")); + p = xmemdupz(S_LEN("utf-8")); } - fenc_default = (char *)p; + fenc_default = p; #ifdef HAVE_WORKING_LIBINTL // GNU gettext 0.10.37 supports this feature: set the codeset used for @@ -1654,7 +1654,7 @@ static char *option_expand(int opt_idx, char *val) // names. // For 'spellsuggest' expand after "file:". expand_env_esc(val, NameBuff, MAXPATHL, - (char_u **)options[opt_idx].var == &p_tags, false, + (char **)options[opt_idx].var == &p_tags, false, (char_u **)options[opt_idx].var == (char_u **)&p_sps ? "file:" : NULL); if (strcmp(NameBuff, val) == 0) { // they are the same @@ -4034,12 +4034,12 @@ static char_u *get_varp(vimoption_T *p) } /// Get the value of 'equalprg', either the buffer-local one or the global one. -char_u *get_equalprg(void) +char *get_equalprg(void) { if (*curbuf->b_p_ep == NUL) { return p_ep; } - return (char_u *)curbuf->b_p_ep; + return curbuf->b_p_ep; } /// Copy options from one window to another. @@ -4225,7 +4225,7 @@ static void init_buf_opt_idx(void) void buf_copy_options(buf_T *buf, int flags) { int should_copy = true; - char_u *save_p_isk = NULL; // init for GCC + char *save_p_isk = NULL; // init for GCC int did_isk = false; // Skip this when the option defaults have not been set yet. Happens when @@ -4258,7 +4258,7 @@ void buf_copy_options(buf_T *buf, int flags) // (jumping back to a help file with CTRL-T or CTRL-O) bool dont_do_help = ((flags & BCO_NOHELP) && buf->b_help) || buf->b_p_initialized; if (dont_do_help) { // don't free b_p_isk - save_p_isk = (char_u *)buf->b_p_isk; + save_p_isk = buf->b_p_isk; buf->b_p_isk = NULL; } // Always free the allocated strings. If not already initialized, @@ -4453,7 +4453,7 @@ void buf_copy_options(buf_T *buf, int flags) // Don't touch these at all when BCO_NOHELP is used and going from // or to a help buffer. if (dont_do_help) { - buf->b_p_isk = (char *)save_p_isk; + buf->b_p_isk = save_p_isk; if (p_vts && p_vts != empty_option && !buf->b_p_vts_array) { (void)tabstop_set(p_vts, &buf->b_p_vts_array); } else { @@ -4843,7 +4843,7 @@ void ExpandOldSetting(int *num_file, char ***file) // A backslash is required before some characters. This is the reverse of // what happens in do_set(). - char_u *buf = (char_u *)vim_strsave_escaped(var, escape_chars); + char *buf = vim_strsave_escaped(var, escape_chars); #ifdef BACKSLASH_IN_FILENAME // For MS-Windows et al. we don't double backslashes at the start and @@ -4859,7 +4859,7 @@ void ExpandOldSetting(int *num_file, char ***file) } #endif - *file[0] = (char *)buf; + *file[0] = buf; *num_file = 1; } -- cgit From 00a7c40f4f5c3af97ef86f8b19f6c8ca93a66750 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 18 Jan 2023 14:40:06 +0000 Subject: refactor(option.c): reduce scope of locals --- src/nvim/option.c | 77 ++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 47 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 268a1514c8..eb1cbdf91c 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -175,8 +175,6 @@ void set_init_tablocal(void) /// editor state initialized here. Do logging in set_init_2 or later. void set_init_1(bool clean_arg) { - int opt_idx; - langmap_init(); // Find default value for 'shell' option. @@ -204,7 +202,7 @@ void set_init_1(bool clean_arg) static char *(names[3]) = { "TMPDIR", "TEMP", "TMP" }; #endif garray_T ga; - opt_idx = findoption("backupskip"); + int opt_idx = findoption("backupskip"); ga_init(&ga, 1, 100); for (size_t n = 0; n < ARRAY_SIZE(names); n++) { @@ -253,19 +251,14 @@ void set_init_1(bool clean_arg) } { - char *cdpath; - char *buf; - int i; - int j; - // Initialize the 'cdpath' option's default value. - cdpath = vim_getenv("CDPATH"); + char *cdpath = vim_getenv("CDPATH"); if (cdpath != NULL) { - buf = xmalloc(2 * strlen(cdpath) + 2); + char *buf = xmalloc(2 * strlen(cdpath) + 2); { buf[0] = ','; // start with ",", current dir first - j = 1; - for (i = 0; cdpath[i] != NUL; i++) { + int j = 1; + for (int i = 0; cdpath[i] != NUL; i++) { if (vim_ispathlistsep(cdpath[i])) { buf[j++] = ','; } else { @@ -276,7 +269,7 @@ void set_init_1(bool clean_arg) } } buf[j] = NUL; - opt_idx = findoption("cdpath"); + int opt_idx = findoption("cdpath"); if (opt_idx >= 0) { options[opt_idx].def_val = buf; options[opt_idx].flags |= P_DEF_ALLOCED; @@ -341,7 +334,7 @@ void set_init_1(bool clean_arg) // them. // Don't set the P_ALLOCED flag, because we don't want to free the // default. - for (opt_idx = 0; options[opt_idx].fullname; opt_idx++) { + for (int opt_idx = 0; options[opt_idx].fullname; opt_idx++) { if (options[opt_idx].flags & P_NO_DEF_EXP) { continue; } @@ -404,10 +397,10 @@ void set_init_1(bool clean_arg) /// @param opt_flags OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL static void set_option_default(int opt_idx, int opt_flags) { - char_u *varp; // pointer to variable for current option int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; - varp = (char_u *)get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); + // pointer to variable for current option + char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); uint32_t flags = options[opt_idx].flags; if (varp != NULL) { // skip hidden option, nothing to do for it if (flags & P_STRING) { @@ -509,12 +502,12 @@ static void set_string_default(const char *name, char *val, bool allocated) static char *find_dup_item(char *origval, const char *newval, uint32_t flags) FUNC_ATTR_NONNULL_ARG(2) { - int bs = 0; - if (origval == NULL) { return NULL; } + int bs = 0; + const size_t newlen = strlen(newval); for (char *s = origval; *s != NUL; s++) { if ((!(flags & P_COMMA) || s == origval || (s[-1] == ',' && !(bs & 1))) @@ -574,11 +567,9 @@ void set_init_2(bool headless) // set in set_init_1 but logging is not allowed there ILOG("startup runtimepath/packpath value: %s", p_rtp); - int idx; - // 'scroll' defaults to half the window height. The stored default is zero, // which results in the actual value computed from the window height. - idx = findoption("scroll"); + int idx = findoption("scroll"); if (idx >= 0 && !(options[idx].flags & P_WAS_SET)) { set_option_default(idx, OPT_LOCAL); } @@ -745,14 +736,8 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, char *varp = varp_arg; char *save_arg = NULL; char *s = NULL; - char *oldval = NULL; // previous value if *varp - char *origval = NULL; char_u *origval_l = NULL; char_u *origval_g = NULL; - char *saved_origval = NULL; - char *saved_origval_l = NULL; - char *saved_origval_g = NULL; - char *saved_newval = NULL; char whichwrap[80]; // When using ":set opt=val" for a global option @@ -764,7 +749,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, } // The old value is kept until we are sure that the new value is valid. - oldval = *(char **)varp; + char *oldval = *(char **)varp; if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) { origval_l = *(char_u **)get_varp_scope(&(options[opt_idx]), OPT_LOCAL); @@ -777,6 +762,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, } } + char *origval; // When setting the local value of a global option, the old value may be // the global value. if (((int)options[opt_idx].indir & PV_BOTH) && (opt_flags & OPT_LOCAL)) { @@ -1024,13 +1010,13 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar, *(char_u **)(varp) = (char_u *)newval; // origval may be freed by did_set_string_option(), make a copy. - saved_origval = (origval != NULL) ? xstrdup(origval) : NULL; - saved_origval_l = (origval_l != NULL) ? xstrdup((char *)origval_l) : NULL; - saved_origval_g = (origval_g != NULL) ? xstrdup((char *)origval_g) : NULL; + char *saved_origval = (origval != NULL) ? xstrdup(origval) : NULL; + char *saved_origval_l = (origval_l != NULL) ? xstrdup((char *)origval_l) : NULL; + char *saved_origval_g = (origval_g != NULL) ? xstrdup((char *)origval_g) : NULL; // newval (and varp) may become invalid if the buffer is closed by // autocommands. - saved_newval = (newval != NULL) ? xstrdup(newval) : NULL; + char *saved_newval = (newval != NULL) ? xstrdup(newval) : NULL; { uint32_t *p = insecure_flag(curwin, opt_idx, opt_flags); @@ -1707,9 +1693,7 @@ static void didset_options2(void) /// Check for string options that are NULL (normally only termcap options). void check_options(void) { - int opt_idx; - - for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) { + for (int opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++) { if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL) { check_string_option((char **)get_varp(&(options[opt_idx]))); } @@ -2880,7 +2864,6 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o return SOPT_STRING | SOPT_GLOBAL; } - char_u *varp = NULL; int rv = 0; int opt_idx = findoption(name); if (opt_idx < 0) { @@ -2930,6 +2913,8 @@ int get_option_value_strict(char *name, int64_t *numval, char **stringval, int o return rv; } + char_u *varp = NULL; + if (opt_type == SREQ_GLOBAL) { if (p->var == VAR_WIN) { return 0; @@ -3431,12 +3416,13 @@ int makefoldset(FILE *fd) static int put_setstring(FILE *fd, char *cmd, char *name, char **valuep, uint64_t flags) { - char *buf = NULL; - char_u *part = NULL; - if (fprintf(fd, "%s %s=", cmd, name) < 0) { return FAIL; } + + char *buf = NULL; + char_u *part = NULL; + if (*valuep != NULL) { // Output 'pastetoggle' as key names. For other // options some characters have to be escaped with @@ -3503,11 +3489,10 @@ fail: static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep) { - long wc; - if (fprintf(fd, "%s %s=", cmd, name) < 0) { return FAIL; } + long wc; if (wc_use_keyname((char_u *)valuep, &wc)) { // print 'wildchar' and 'wildcharm' as a key name if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0) { @@ -4526,11 +4511,6 @@ static int expand_option_flags = 0; /// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) { - uint32_t flags = 0; // init for GCC - int opt_idx = 0; // init for GCC - char *p; - int is_term_option = false; - expand_option_flags = opt_flags; xp->xp_context = EXPAND_SETTINGS; @@ -4538,7 +4518,7 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) xp->xp_pattern = arg; return; } - p = arg + strlen(arg) - 1; + char *p = arg + strlen(arg) - 1; if (*p == ' ' && *(p - 1) != '\\') { xp->xp_pattern = p + 1; return; @@ -4570,6 +4550,9 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) arg = p; char nextchar; + uint32_t flags = 0; + int opt_idx = 0; + int is_term_option = false; if (*arg == '<') { while (*p != '>') { -- cgit From f90d78654ad745b3d393771889fed767971204fb Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 18 Jan 2023 14:24:37 +0000 Subject: refactor(option.c): add get_varp_from and get_varp_scope_from --- src/nvim/option.c | 402 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 206 insertions(+), 196 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index eb1cbdf91c..2213b64f6f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3628,83 +3628,87 @@ void unset_global_local_option(char *name, void *from) } } -/// Get pointer to option variable, depending on local or global scope. -/// -/// @param scope can be OPT_LOCAL, OPT_GLOBAL or a combination. -char *get_varp_scope(vimoption_T *p, int scope) +char *get_varp_scope_from(vimoption_T *p, int scope, buf_T *buf, win_T *win) { if ((scope & OPT_GLOBAL) && p->indir != PV_NONE) { if (p->var == VAR_WIN) { - return GLOBAL_WO(get_varp(p)); + return GLOBAL_WO(get_varp_from(p, buf, win)); } return (char *)p->var; } if ((scope & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) { switch ((int)p->indir) { case PV_FP: - return (char *)&(curbuf->b_p_fp); + return (char *)&(buf->b_p_fp); case PV_EFM: - return (char *)&(curbuf->b_p_efm); + return (char *)&(buf->b_p_efm); case PV_GP: - return (char *)&(curbuf->b_p_gp); + return (char *)&(buf->b_p_gp); case PV_MP: - return (char *)&(curbuf->b_p_mp); + return (char *)&(buf->b_p_mp); case PV_EP: - return (char *)&(curbuf->b_p_ep); + return (char *)&(buf->b_p_ep); case PV_KP: - return (char *)&(curbuf->b_p_kp); + return (char *)&(buf->b_p_kp); case PV_PATH: - return (char *)&(curbuf->b_p_path); + return (char *)&(buf->b_p_path); case PV_AR: - return (char *)&(curbuf->b_p_ar); + return (char *)&(buf->b_p_ar); case PV_TAGS: - return (char *)&(curbuf->b_p_tags); + return (char *)&(buf->b_p_tags); case PV_TC: - return (char *)&(curbuf->b_p_tc); + return (char *)&(buf->b_p_tc); case PV_SISO: - return (char *)&(curwin->w_p_siso); + return (char *)&(win->w_p_siso); case PV_SO: - return (char *)&(curwin->w_p_so); + return (char *)&(win->w_p_so); case PV_DEF: - return (char *)&(curbuf->b_p_def); + return (char *)&(buf->b_p_def); case PV_INC: - return (char *)&(curbuf->b_p_inc); + return (char *)&(buf->b_p_inc); case PV_DICT: - return (char *)&(curbuf->b_p_dict); + return (char *)&(buf->b_p_dict); case PV_TSR: - return (char *)&(curbuf->b_p_tsr); + return (char *)&(buf->b_p_tsr); case PV_TSRFU: - return (char *)&(curbuf->b_p_tsrfu); + return (char *)&(buf->b_p_tsrfu); case PV_TFU: - return (char *)&(curbuf->b_p_tfu); + return (char *)&(buf->b_p_tfu); case PV_SBR: - return (char *)&(curwin->w_p_sbr); + return (char *)&(win->w_p_sbr); case PV_STL: - return (char *)&(curwin->w_p_stl); + return (char *)&(win->w_p_stl); case PV_WBR: - return (char *)&(curwin->w_p_wbr); + return (char *)&(win->w_p_wbr); case PV_UL: - return (char *)&(curbuf->b_p_ul); + return (char *)&(buf->b_p_ul); case PV_LW: - return (char *)&(curbuf->b_p_lw); + return (char *)&(buf->b_p_lw); case PV_BKC: - return (char *)&(curbuf->b_p_bkc); + return (char *)&(buf->b_p_bkc); case PV_MENC: - return (char *)&(curbuf->b_p_menc); + return (char *)&(buf->b_p_menc); case PV_FCS: - return (char *)&(curwin->w_p_fcs); + return (char *)&(win->w_p_fcs); case PV_LCS: - return (char *)&(curwin->w_p_lcs); + return (char *)&(win->w_p_lcs); case PV_VE: - return (char *)&(curwin->w_p_ve); + return (char *)&(win->w_p_ve); } return NULL; // "cannot happen" } - return (char *)get_varp(p); + return (char *)get_varp_from(p, buf, win); } -/// Get pointer to option variable. -static char_u *get_varp(vimoption_T *p) +/// Get pointer to option variable, depending on local or global scope. +/// +/// @param scope can be OPT_LOCAL, OPT_GLOBAL or a combination. +char *get_varp_scope(vimoption_T *p, int scope) +{ + return get_varp_scope_from(p, scope, curbuf, curwin); +} + +static char_u *get_varp_from(vimoption_T *p, buf_T *buf, win_T *win) { // hidden option, always return NULL if (p->var == NULL) { @@ -3717,305 +3721,311 @@ static char_u *get_varp(vimoption_T *p) // global option with local value: use local value if it's been set case PV_EP: - return *curbuf->b_p_ep != NUL - ? (char_u *)&curbuf->b_p_ep : p->var; + return *buf->b_p_ep != NUL + ? (char_u *)&buf->b_p_ep : p->var; case PV_KP: - return *curbuf->b_p_kp != NUL - ? (char_u *)&curbuf->b_p_kp : p->var; + return *buf->b_p_kp != NUL + ? (char_u *)&buf->b_p_kp : p->var; case PV_PATH: - return *curbuf->b_p_path != NUL - ? (char_u *)&(curbuf->b_p_path) : p->var; + return *buf->b_p_path != NUL + ? (char_u *)&(buf->b_p_path) : p->var; case PV_AR: - return curbuf->b_p_ar >= 0 - ? (char_u *)&(curbuf->b_p_ar) : p->var; + return buf->b_p_ar >= 0 + ? (char_u *)&(buf->b_p_ar) : p->var; case PV_TAGS: - return *curbuf->b_p_tags != NUL - ? (char_u *)&(curbuf->b_p_tags) : p->var; + return *buf->b_p_tags != NUL + ? (char_u *)&(buf->b_p_tags) : p->var; case PV_TC: - return *curbuf->b_p_tc != NUL - ? (char_u *)&(curbuf->b_p_tc) : p->var; + return *buf->b_p_tc != NUL + ? (char_u *)&(buf->b_p_tc) : p->var; case PV_SISO: - return curwin->w_p_siso >= 0 - ? (char_u *)&(curwin->w_p_siso) : p->var; + return win->w_p_siso >= 0 + ? (char_u *)&(win->w_p_siso) : p->var; case PV_SO: - return curwin->w_p_so >= 0 - ? (char_u *)&(curwin->w_p_so) : p->var; + return win->w_p_so >= 0 + ? (char_u *)&(win->w_p_so) : p->var; case PV_BKC: - return *curbuf->b_p_bkc != NUL - ? (char_u *)&(curbuf->b_p_bkc) : p->var; + return *buf->b_p_bkc != NUL + ? (char_u *)&(buf->b_p_bkc) : p->var; case PV_DEF: - return *curbuf->b_p_def != NUL - ? (char_u *)&(curbuf->b_p_def) : p->var; + return *buf->b_p_def != NUL + ? (char_u *)&(buf->b_p_def) : p->var; case PV_INC: - return *curbuf->b_p_inc != NUL - ? (char_u *)&(curbuf->b_p_inc) : p->var; + return *buf->b_p_inc != NUL + ? (char_u *)&(buf->b_p_inc) : p->var; case PV_DICT: - return *curbuf->b_p_dict != NUL - ? (char_u *)&(curbuf->b_p_dict) : p->var; + return *buf->b_p_dict != NUL + ? (char_u *)&(buf->b_p_dict) : p->var; case PV_TSR: - return *curbuf->b_p_tsr != NUL - ? (char_u *)&(curbuf->b_p_tsr) : p->var; + return *buf->b_p_tsr != NUL + ? (char_u *)&(buf->b_p_tsr) : p->var; case PV_TSRFU: - return *curbuf->b_p_tsrfu != NUL - ? (char_u *)&(curbuf->b_p_tsrfu) : p->var; + return *buf->b_p_tsrfu != NUL + ? (char_u *)&(buf->b_p_tsrfu) : p->var; case PV_FP: - return *curbuf->b_p_fp != NUL - ? (char_u *)&(curbuf->b_p_fp) : p->var; + return *buf->b_p_fp != NUL + ? (char_u *)&(buf->b_p_fp) : p->var; case PV_EFM: - return *curbuf->b_p_efm != NUL - ? (char_u *)&(curbuf->b_p_efm) : p->var; + return *buf->b_p_efm != NUL + ? (char_u *)&(buf->b_p_efm) : p->var; case PV_GP: - return *curbuf->b_p_gp != NUL - ? (char_u *)&(curbuf->b_p_gp) : p->var; + return *buf->b_p_gp != NUL + ? (char_u *)&(buf->b_p_gp) : p->var; case PV_MP: - return *curbuf->b_p_mp != NUL - ? (char_u *)&(curbuf->b_p_mp) : p->var; + return *buf->b_p_mp != NUL + ? (char_u *)&(buf->b_p_mp) : p->var; case PV_SBR: - return *curwin->w_p_sbr != NUL - ? (char_u *)&(curwin->w_p_sbr) : p->var; + return *win->w_p_sbr != NUL + ? (char_u *)&(win->w_p_sbr) : p->var; case PV_STL: - return *curwin->w_p_stl != NUL - ? (char_u *)&(curwin->w_p_stl) : p->var; + return *win->w_p_stl != NUL + ? (char_u *)&(win->w_p_stl) : p->var; case PV_WBR: - return *curwin->w_p_wbr != NUL - ? (char_u *)&(curwin->w_p_wbr) : p->var; + return *win->w_p_wbr != NUL + ? (char_u *)&(win->w_p_wbr) : p->var; case PV_UL: - return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL - ? (char_u *)&(curbuf->b_p_ul) : p->var; + return buf->b_p_ul != NO_LOCAL_UNDOLEVEL + ? (char_u *)&(buf->b_p_ul) : p->var; case PV_LW: - return *curbuf->b_p_lw != NUL - ? (char_u *)&(curbuf->b_p_lw) : p->var; + return *buf->b_p_lw != NUL + ? (char_u *)&(buf->b_p_lw) : p->var; case PV_MENC: - return *curbuf->b_p_menc != NUL - ? (char_u *)&(curbuf->b_p_menc) : p->var; + return *buf->b_p_menc != NUL + ? (char_u *)&(buf->b_p_menc) : p->var; case PV_FCS: - return *curwin->w_p_fcs != NUL - ? (char_u *)&(curwin->w_p_fcs) : p->var; + return *win->w_p_fcs != NUL + ? (char_u *)&(win->w_p_fcs) : p->var; case PV_LCS: - return *curwin->w_p_lcs != NUL - ? (char_u *)&(curwin->w_p_lcs) : p->var; + return *win->w_p_lcs != NUL + ? (char_u *)&(win->w_p_lcs) : p->var; case PV_VE: - return *curwin->w_p_ve != NUL - ? (char_u *)&curwin->w_p_ve : p->var; + return *win->w_p_ve != NUL + ? (char_u *)&win->w_p_ve : p->var; case PV_ARAB: - return (char_u *)&(curwin->w_p_arab); + return (char_u *)&(win->w_p_arab); case PV_LIST: - return (char_u *)&(curwin->w_p_list); + return (char_u *)&(win->w_p_list); case PV_SPELL: - return (char_u *)&(curwin->w_p_spell); + return (char_u *)&(win->w_p_spell); case PV_CUC: - return (char_u *)&(curwin->w_p_cuc); + return (char_u *)&(win->w_p_cuc); case PV_CUL: - return (char_u *)&(curwin->w_p_cul); + return (char_u *)&(win->w_p_cul); case PV_CULOPT: - return (char_u *)&(curwin->w_p_culopt); + return (char_u *)&(win->w_p_culopt); case PV_CC: - return (char_u *)&(curwin->w_p_cc); + return (char_u *)&(win->w_p_cc); case PV_DIFF: - return (char_u *)&(curwin->w_p_diff); + return (char_u *)&(win->w_p_diff); case PV_FDC: - return (char_u *)&(curwin->w_p_fdc); + return (char_u *)&(win->w_p_fdc); case PV_FEN: - return (char_u *)&(curwin->w_p_fen); + return (char_u *)&(win->w_p_fen); case PV_FDI: - return (char_u *)&(curwin->w_p_fdi); + return (char_u *)&(win->w_p_fdi); case PV_FDL: - return (char_u *)&(curwin->w_p_fdl); + return (char_u *)&(win->w_p_fdl); case PV_FDM: - return (char_u *)&(curwin->w_p_fdm); + return (char_u *)&(win->w_p_fdm); case PV_FML: - return (char_u *)&(curwin->w_p_fml); + return (char_u *)&(win->w_p_fml); case PV_FDN: - return (char_u *)&(curwin->w_p_fdn); + return (char_u *)&(win->w_p_fdn); case PV_FDE: - return (char_u *)&(curwin->w_p_fde); + return (char_u *)&(win->w_p_fde); case PV_FDT: - return (char_u *)&(curwin->w_p_fdt); + return (char_u *)&(win->w_p_fdt); case PV_FMR: - return (char_u *)&(curwin->w_p_fmr); + return (char_u *)&(win->w_p_fmr); case PV_NU: - return (char_u *)&(curwin->w_p_nu); + return (char_u *)&(win->w_p_nu); case PV_RNU: - return (char_u *)&(curwin->w_p_rnu); + return (char_u *)&(win->w_p_rnu); case PV_NUW: - return (char_u *)&(curwin->w_p_nuw); + return (char_u *)&(win->w_p_nuw); case PV_WFH: - return (char_u *)&(curwin->w_p_wfh); + return (char_u *)&(win->w_p_wfh); case PV_WFW: - return (char_u *)&(curwin->w_p_wfw); + return (char_u *)&(win->w_p_wfw); case PV_PVW: - return (char_u *)&(curwin->w_p_pvw); + return (char_u *)&(win->w_p_pvw); case PV_RL: - return (char_u *)&(curwin->w_p_rl); + return (char_u *)&(win->w_p_rl); case PV_RLC: - return (char_u *)&(curwin->w_p_rlc); + return (char_u *)&(win->w_p_rlc); case PV_SCROLL: - return (char_u *)&(curwin->w_p_scr); + return (char_u *)&(win->w_p_scr); case PV_WRAP: - return (char_u *)&(curwin->w_p_wrap); + return (char_u *)&(win->w_p_wrap); case PV_LBR: - return (char_u *)&(curwin->w_p_lbr); + return (char_u *)&(win->w_p_lbr); case PV_BRI: - return (char_u *)&(curwin->w_p_bri); + return (char_u *)&(win->w_p_bri); case PV_BRIOPT: - return (char_u *)&(curwin->w_p_briopt); + return (char_u *)&(win->w_p_briopt); case PV_SCBIND: - return (char_u *)&(curwin->w_p_scb); + return (char_u *)&(win->w_p_scb); case PV_CRBIND: - return (char_u *)&(curwin->w_p_crb); + return (char_u *)&(win->w_p_crb); case PV_COCU: - return (char_u *)&(curwin->w_p_cocu); + return (char_u *)&(win->w_p_cocu); case PV_COLE: - return (char_u *)&(curwin->w_p_cole); + return (char_u *)&(win->w_p_cole); case PV_AI: - return (char_u *)&(curbuf->b_p_ai); + return (char_u *)&(buf->b_p_ai); case PV_BIN: - return (char_u *)&(curbuf->b_p_bin); + return (char_u *)&(buf->b_p_bin); case PV_BOMB: - return (char_u *)&(curbuf->b_p_bomb); + return (char_u *)&(buf->b_p_bomb); case PV_BH: - return (char_u *)&(curbuf->b_p_bh); + return (char_u *)&(buf->b_p_bh); case PV_BT: - return (char_u *)&(curbuf->b_p_bt); + return (char_u *)&(buf->b_p_bt); case PV_BL: - return (char_u *)&(curbuf->b_p_bl); + return (char_u *)&(buf->b_p_bl); case PV_CHANNEL: - return (char_u *)&(curbuf->b_p_channel); + return (char_u *)&(buf->b_p_channel); case PV_CI: - return (char_u *)&(curbuf->b_p_ci); + return (char_u *)&(buf->b_p_ci); case PV_CIN: - return (char_u *)&(curbuf->b_p_cin); + return (char_u *)&(buf->b_p_cin); case PV_CINK: - return (char_u *)&(curbuf->b_p_cink); + return (char_u *)&(buf->b_p_cink); case PV_CINO: - return (char_u *)&(curbuf->b_p_cino); + return (char_u *)&(buf->b_p_cino); case PV_CINSD: - return (char_u *)&(curbuf->b_p_cinsd); + return (char_u *)&(buf->b_p_cinsd); case PV_CINW: - return (char_u *)&(curbuf->b_p_cinw); + return (char_u *)&(buf->b_p_cinw); case PV_COM: - return (char_u *)&(curbuf->b_p_com); + return (char_u *)&(buf->b_p_com); case PV_CMS: - return (char_u *)&(curbuf->b_p_cms); + return (char_u *)&(buf->b_p_cms); case PV_CPT: - return (char_u *)&(curbuf->b_p_cpt); + return (char_u *)&(buf->b_p_cpt); #ifdef BACKSLASH_IN_FILENAME case PV_CSL: - return (char_u *)&(curbuf->b_p_csl); + return (char_u *)&(buf->b_p_csl); #endif case PV_CFU: - return (char_u *)&(curbuf->b_p_cfu); + return (char_u *)&(buf->b_p_cfu); case PV_OFU: - return (char_u *)&(curbuf->b_p_ofu); + return (char_u *)&(buf->b_p_ofu); case PV_EOF: - return (char_u *)&(curbuf->b_p_eof); + return (char_u *)&(buf->b_p_eof); case PV_EOL: - return (char_u *)&(curbuf->b_p_eol); + return (char_u *)&(buf->b_p_eol); case PV_FIXEOL: - return (char_u *)&(curbuf->b_p_fixeol); + return (char_u *)&(buf->b_p_fixeol); case PV_ET: - return (char_u *)&(curbuf->b_p_et); + return (char_u *)&(buf->b_p_et); case PV_FENC: - return (char_u *)&(curbuf->b_p_fenc); + return (char_u *)&(buf->b_p_fenc); case PV_FF: - return (char_u *)&(curbuf->b_p_ff); + return (char_u *)&(buf->b_p_ff); case PV_FT: - return (char_u *)&(curbuf->b_p_ft); + return (char_u *)&(buf->b_p_ft); case PV_FO: - return (char_u *)&(curbuf->b_p_fo); + return (char_u *)&(buf->b_p_fo); case PV_FLP: - return (char_u *)&(curbuf->b_p_flp); + return (char_u *)&(buf->b_p_flp); case PV_IMI: - return (char_u *)&(curbuf->b_p_iminsert); + return (char_u *)&(buf->b_p_iminsert); case PV_IMS: - return (char_u *)&(curbuf->b_p_imsearch); + return (char_u *)&(buf->b_p_imsearch); case PV_INF: - return (char_u *)&(curbuf->b_p_inf); + return (char_u *)&(buf->b_p_inf); case PV_ISK: - return (char_u *)&(curbuf->b_p_isk); + return (char_u *)&(buf->b_p_isk); case PV_INEX: - return (char_u *)&(curbuf->b_p_inex); + return (char_u *)&(buf->b_p_inex); case PV_INDE: - return (char_u *)&(curbuf->b_p_inde); + return (char_u *)&(buf->b_p_inde); case PV_INDK: - return (char_u *)&(curbuf->b_p_indk); + return (char_u *)&(buf->b_p_indk); case PV_FEX: - return (char_u *)&(curbuf->b_p_fex); + return (char_u *)&(buf->b_p_fex); case PV_LISP: - return (char_u *)&(curbuf->b_p_lisp); + return (char_u *)&(buf->b_p_lisp); case PV_LOP: - return (char_u *)&(curbuf->b_p_lop); + return (char_u *)&(buf->b_p_lop); case PV_ML: - return (char_u *)&(curbuf->b_p_ml); + return (char_u *)&(buf->b_p_ml); case PV_MPS: - return (char_u *)&(curbuf->b_p_mps); + return (char_u *)&(buf->b_p_mps); case PV_MA: - return (char_u *)&(curbuf->b_p_ma); + return (char_u *)&(buf->b_p_ma); case PV_MOD: - return (char_u *)&(curbuf->b_changed); + return (char_u *)&(buf->b_changed); case PV_NF: - return (char_u *)&(curbuf->b_p_nf); + return (char_u *)&(buf->b_p_nf); case PV_PI: - return (char_u *)&(curbuf->b_p_pi); + return (char_u *)&(buf->b_p_pi); case PV_QE: - return (char_u *)&(curbuf->b_p_qe); + return (char_u *)&(buf->b_p_qe); case PV_RO: - return (char_u *)&(curbuf->b_p_ro); + return (char_u *)&(buf->b_p_ro); case PV_SCBK: - return (char_u *)&(curbuf->b_p_scbk); + return (char_u *)&(buf->b_p_scbk); case PV_SI: - return (char_u *)&(curbuf->b_p_si); + return (char_u *)&(buf->b_p_si); case PV_STS: - return (char_u *)&(curbuf->b_p_sts); + return (char_u *)&(buf->b_p_sts); case PV_SUA: - return (char_u *)&(curbuf->b_p_sua); + return (char_u *)&(buf->b_p_sua); case PV_SWF: - return (char_u *)&(curbuf->b_p_swf); + return (char_u *)&(buf->b_p_swf); case PV_SMC: - return (char_u *)&(curbuf->b_p_smc); + return (char_u *)&(buf->b_p_smc); case PV_SYN: - return (char_u *)&(curbuf->b_p_syn); + return (char_u *)&(buf->b_p_syn); case PV_SPC: - return (char_u *)&(curwin->w_s->b_p_spc); + return (char_u *)&(win->w_s->b_p_spc); case PV_SPF: - return (char_u *)&(curwin->w_s->b_p_spf); + return (char_u *)&(win->w_s->b_p_spf); case PV_SPL: - return (char_u *)&(curwin->w_s->b_p_spl); + return (char_u *)&(win->w_s->b_p_spl); case PV_SPO: - return (char_u *)&(curwin->w_s->b_p_spo); + return (char_u *)&(win->w_s->b_p_spo); case PV_SW: - return (char_u *)&(curbuf->b_p_sw); + return (char_u *)&(buf->b_p_sw); case PV_TFU: - return (char_u *)&(curbuf->b_p_tfu); + return (char_u *)&(buf->b_p_tfu); case PV_TS: - return (char_u *)&(curbuf->b_p_ts); + return (char_u *)&(buf->b_p_ts); case PV_TW: - return (char_u *)&(curbuf->b_p_tw); + return (char_u *)&(buf->b_p_tw); case PV_UDF: - return (char_u *)&(curbuf->b_p_udf); + return (char_u *)&(buf->b_p_udf); case PV_WM: - return (char_u *)&(curbuf->b_p_wm); + return (char_u *)&(buf->b_p_wm); case PV_VSTS: - return (char_u *)&(curbuf->b_p_vsts); + return (char_u *)&(buf->b_p_vsts); case PV_VTS: - return (char_u *)&(curbuf->b_p_vts); + return (char_u *)&(buf->b_p_vts); case PV_KMAP: - return (char_u *)&(curbuf->b_p_keymap); + return (char_u *)&(buf->b_p_keymap); case PV_SCL: - return (char_u *)&(curwin->w_p_scl); + return (char_u *)&(win->w_p_scl); case PV_WINHL: - return (char_u *)&(curwin->w_p_winhl); + return (char_u *)&(win->w_p_winhl); case PV_WINBL: - return (char_u *)&(curwin->w_p_winbl); + return (char_u *)&(win->w_p_winbl); case PV_STC: - return (char_u *)&(curwin->w_p_stc); + return (char_u *)&(win->w_p_stc); default: iemsg(_("E356: get_varp ERROR")); } // always return a valid pointer to avoid a crash! - return (char_u *)&(curbuf->b_p_wm); + return (char_u *)&(buf->b_p_wm); +} + +/// Get pointer to option variable. +static inline char_u *get_varp(vimoption_T *p) +{ + return get_varp_from(p, curbuf, curwin); } /// Get the value of 'equalprg', either the buffer-local one or the global one. -- cgit From 29215d3a4929e4fd3d45abc8f5f9d43691b0bc55 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 18 Jan 2023 14:45:54 +0000 Subject: refactor(option.c): de-nest set_option_value --- src/nvim/option.c | 102 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 49 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 2213b64f6f..63661020eb 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2992,58 +2992,62 @@ char *set_option_value(const char *const name, const long number, const char *co int opt_idx = findoption(name); if (opt_idx < 0) { semsg(_("E355: Unknown option: %s"), name); - } else { - uint32_t flags = options[opt_idx].flags; - // Disallow changing some options in the sandbox - if (sandbox > 0 && (flags & P_SECURE)) { - emsg(_(e_sandbox)); - return NULL; + return NULL; + } + + uint32_t flags = options[opt_idx].flags; + // Disallow changing some options in the sandbox + if (sandbox > 0 && (flags & P_SECURE)) { + emsg(_(e_sandbox)); + return NULL; + } + + if (flags & P_STRING) { + const char *s = string; + if (s == NULL || opt_flags & OPT_CLEAR) { + s = ""; } - if (flags & P_STRING) { - const char *s = string; - if (s == NULL || opt_flags & OPT_CLEAR) { - s = ""; - } - return set_string_option(opt_idx, s, opt_flags); - } - - char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); - if (varp != NULL) { // hidden option is not changed - if (number == 0 && string != NULL) { - int idx; - - // Either we are given a string or we are setting option - // to zero. - for (idx = 0; string[idx] == '0'; idx++) {} - if (string[idx] != NUL || idx == 0) { - // There's another character after zeros or the string - // is empty. In both cases, we are trying to set a - // num option using a string. - semsg(_("E521: Number required: &%s = '%s'"), - name, string); - return NULL; // do nothing as we hit an error - } - } - long numval = number; - if (opt_flags & OPT_CLEAR) { - if ((int *)varp == &curbuf->b_p_ar) { - numval = -1; - } else if ((long *)varp == &curbuf->b_p_ul) { - numval = NO_LOCAL_UNDOLEVEL; - } else if ((long *)varp == &curwin->w_p_so || (long *)varp == &curwin->w_p_siso) { - numval = -1; - } else { - char *s = NULL; - (void)get_option_value(name, &numval, &s, NULL, OPT_GLOBAL); - } - } - if (flags & P_NUM) { - return set_num_option(opt_idx, varp, numval, NULL, 0, opt_flags); - } - return set_bool_option(opt_idx, varp, (int)numval, opt_flags); + return set_string_option(opt_idx, s, opt_flags); + } + + char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); + if (varp == NULL) { + // hidden option is not changed + return NULL; + } + + if (number == 0 && string != NULL) { + int idx; + + // Either we are given a string or we are setting option + // to zero. + for (idx = 0; string[idx] == '0'; idx++) {} + if (string[idx] != NUL || idx == 0) { + // There's another character after zeros or the string + // is empty. In both cases, we are trying to set a + // num option using a string. + semsg(_("E521: Number required: &%s = '%s'"), + name, string); + return NULL; // do nothing as we hit an error + } + } + long numval = number; + if (opt_flags & OPT_CLEAR) { + if ((int *)varp == &curbuf->b_p_ar) { + numval = -1; + } else if ((long *)varp == &curbuf->b_p_ul) { + numval = NO_LOCAL_UNDOLEVEL; + } else if ((long *)varp == &curwin->w_p_so || (long *)varp == &curwin->w_p_siso) { + numval = -1; + } else { + char *s = NULL; + (void)get_option_value(name, &numval, &s, NULL, OPT_GLOBAL); } } - return NULL; + if (flags & P_NUM) { + return set_num_option(opt_idx, varp, numval, NULL, 0, opt_flags); + } + return set_bool_option(opt_idx, varp, (int)numval, opt_flags); } /// Call set_option_value() and when an error is returned report it. -- cgit From db87807983aa282aa6b7e4c5e6ceeb14d656d8c0 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 18 Jan 2023 15:04:11 +0000 Subject: refactor(option.c): use intermediate for options ref --- src/nvim/option.c | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 63661020eb..a2be81d6bc 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -335,24 +335,24 @@ void set_init_1(bool clean_arg) // Don't set the P_ALLOCED flag, because we don't want to free the // default. for (int opt_idx = 0; options[opt_idx].fullname; opt_idx++) { - if (options[opt_idx].flags & P_NO_DEF_EXP) { + vimoption_T *opt = &options[opt_idx]; + if (opt->flags & P_NO_DEF_EXP) { continue; } char *p; - if ((options[opt_idx].flags & P_GETTEXT) - && options[opt_idx].var != NULL) { - p = _(*(char **)options[opt_idx].var); + if ((opt->flags & P_GETTEXT) && opt->var != NULL) { + p = _(*(char **)opt->var); } else { p = option_expand(opt_idx, NULL); } if (p != NULL) { p = xstrdup(p); - *(char **)options[opt_idx].var = p; - if (options[opt_idx].flags & P_DEF_ALLOCED) { - xfree(options[opt_idx].def_val); + *(char **)opt->var = p; + if (opt->flags & P_DEF_ALLOCED) { + xfree(opt->def_val); } - options[opt_idx].def_val = p; - options[opt_idx].flags |= P_DEF_ALLOCED; + opt->def_val = p; + opt->flags |= P_DEF_ALLOCED; } } @@ -395,32 +395,32 @@ void set_init_1(bool clean_arg) /// This does not take care of side effects! /// /// @param opt_flags OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL -static void set_option_default(int opt_idx, int opt_flags) +static void set_option_default(const int opt_idx, int opt_flags) { int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; // pointer to variable for current option - char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags); - uint32_t flags = options[opt_idx].flags; + vimoption_T *opt = &options[opt_idx]; + char_u *varp = (char_u *)get_varp_scope(opt, both ? OPT_LOCAL : opt_flags); + uint32_t flags = opt->flags; if (varp != NULL) { // skip hidden option, nothing to do for it if (flags & P_STRING) { // Use set_string_option_direct() for local options to handle // freeing and allocating the value. - if (options[opt_idx].indir != PV_NONE) { - set_string_option_direct(NULL, opt_idx, - options[opt_idx].def_val, opt_flags, 0); + if (opt->indir != PV_NONE) { + set_string_option_direct(NULL, opt_idx, opt->def_val, opt_flags, 0); } else { if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) { free_string_option(*(char **)(varp)); } - *(char **)varp = options[opt_idx].def_val; - options[opt_idx].flags &= ~P_ALLOCED; + *(char **)varp = opt->def_val; + opt->flags &= ~P_ALLOCED; } } else if (flags & P_NUM) { - if (options[opt_idx].indir == PV_SCROLL) { + if (opt->indir == PV_SCROLL) { win_comp_scroll(curwin); } else { - long def_val = (long)options[opt_idx].def_val; + long def_val = (long)opt->def_val; if ((long *)varp == &curwin->w_p_so || (long *)varp == &curwin->w_p_siso) { // 'scrolloff' and 'sidescrolloff' local values have a @@ -431,21 +431,21 @@ static void set_option_default(int opt_idx, int opt_flags) } // May also set global value for local option. if (both) { - *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = + *(long *)get_varp_scope(opt, OPT_GLOBAL) = def_val; } } } else { // P_BOOL - *(int *)varp = (int)(intptr_t)options[opt_idx].def_val; + *(int *)varp = (int)(intptr_t)opt->def_val; #ifdef UNIX // 'modeline' defaults to off for root - if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID) { + if (opt->indir == PV_ML && getuid() == ROOT_UID) { *(int *)varp = false; } #endif // May also set global value for local option. if (both) { - *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = + *(int *)get_varp_scope(opt, OPT_GLOBAL) = *(int *)varp; } } @@ -488,12 +488,13 @@ static void set_string_default(const char *name, char *val, bool allocated) { int opt_idx = findoption(name); if (opt_idx >= 0) { - if (options[opt_idx].flags & P_DEF_ALLOCED) { - xfree(options[opt_idx].def_val); + vimoption_T *opt = &options[opt_idx]; + if (opt->flags & P_DEF_ALLOCED) { + xfree(opt->def_val); } - options[opt_idx].def_val = allocated ? val : xstrdup(val); - options[opt_idx].flags |= P_DEF_ALLOCED; + opt->def_val = allocated ? val : xstrdup(val); + opt->flags |= P_DEF_ALLOCED; } } -- cgit From a22702b5d551a5be0e656282e168f3ba2efeb552 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 19 Jan 2023 09:55:50 +0000 Subject: refactor(optionstr.c): break up did_set_string_option 7 --- src/nvim/option.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index a2be81d6bc..f5b172f4e0 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4508,15 +4508,15 @@ void reset_modifiable(void) } /// Set the global value for 'iminsert' to the local value. -void set_iminsert_global(void) +void set_iminsert_global(buf_T *buf) { - p_iminsert = curbuf->b_p_iminsert; + p_iminsert = buf->b_p_iminsert; } /// Set the global value for 'imsearch' to the local value. -void set_imsearch_global(void) +void set_imsearch_global(buf_T *buf) { - p_imsearch = curbuf->b_p_imsearch; + p_imsearch = buf->b_p_imsearch; } static int expand_option_idx = -1; -- cgit From 38ed4321646c8e167182c440ecd320ef12cadcad Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 24 Jan 2023 13:15:15 +0000 Subject: refactor(optionstr.c): add did_set_string_option_for --- src/nvim/option.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index f5b172f4e0..01a5c7677f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2582,7 +2582,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, } /// Called after an option changed: check if something needs to be redrawn. -void check_redraw(uint32_t flags) +void check_redraw_for(buf_T *buf, win_T *win, uint32_t flags) { // Careful: P_RALL is a combination of other P_ flags bool all = (flags & P_RALL) == P_RALL; @@ -2596,19 +2596,24 @@ void check_redraw(uint32_t flags) } if ((flags & P_RBUF) || (flags & P_RWIN) || all) { - changed_window_setting(); + changed_window_setting_win(win); } if (flags & P_RBUF) { - redraw_curbuf_later(UPD_NOT_VALID); + redraw_buf_later(buf, UPD_NOT_VALID); } if (flags & P_RWINONLY) { - redraw_later(curwin, UPD_NOT_VALID); + redraw_later(win, UPD_NOT_VALID); } if (all) { redraw_all_later(UPD_NOT_VALID); } } +void check_redraw(uint32_t flags) +{ + check_redraw_for(curbuf, curwin, flags); +} + /// Find index for named option /// /// @param[in] arg Option to find index for. -- cgit