diff options
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r-- | src/nvim/option.c | 1451 |
1 files changed, 780 insertions, 671 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 4073ab08d9..310f382db7 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -22,50 +22,50 @@ #define IN_OPTION_C #include <assert.h> #include <inttypes.h> +#include <limits.h> #include <stdbool.h> -#include <string.h> #include <stdlib.h> -#include <limits.h> +#include <string.h> -#include "nvim/vim.h" -#include "nvim/macros.h" #include "nvim/ascii.h" -#include "nvim/edit.h" -#include "nvim/option.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/cursor.h" +#include "nvim/cursor_shape.h" #include "nvim/diff.h" #include "nvim/digraph.h" +#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" #include "nvim/fileio.h" #include "nvim/fold.h" +#include "nvim/garray.h" #include "nvim/getchar.h" #include "nvim/hardcopy.h" #include "nvim/highlight.h" #include "nvim/indent_c.h" +#include "nvim/keymap.h" +#include "nvim/macros.h" #include "nvim/mbyte.h" #include "nvim/memfile.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/misc1.h" -#include "nvim/runtime.h" -#include "nvim/keymap.h" -#include "nvim/garray.h" -#include "nvim/cursor_shape.h" -#include "nvim/move.h" #include "nvim/mouse.h" +#include "nvim/move.h" #include "nvim/normal.h" +#include "nvim/option.h" +#include "nvim/os/os.h" #include "nvim/os_unix.h" #include "nvim/path.h" #include "nvim/popupmnu.h" #include "nvim/regexp.h" -#include "nvim/ex_session.h" +#include "nvim/runtime.h" #include "nvim/screen.h" #include "nvim/spell.h" #include "nvim/spellfile.h" @@ -74,13 +74,13 @@ #include "nvim/ui.h" #include "nvim/ui_compositor.h" #include "nvim/undo.h" +#include "nvim/vim.h" #include "nvim/window.h" -#include "nvim/os/os.h" #ifdef WIN32 # include "nvim/os/pty_conpty_win.h" #endif -#include "nvim/lua/executor.h" #include "nvim/api/private/helpers.h" +#include "nvim/lua/executor.h" #include "nvim/os/input.h" #include "nvim/os/lang.h" #include "nvim/quickfix.h" @@ -124,64 +124,64 @@ static char *p_ttytype = NULL; static int p_ai; static int p_bin; static int p_bomb; -static char_u *p_bh; -static char_u *p_bt; +static char_u *p_bh; +static char_u *p_bt; static int p_bl; static long p_channel; static int p_ci; static int p_cin; -static char_u *p_cink; -static char_u *p_cino; -static char_u *p_cinw; -static char_u *p_com; -static char_u *p_cms; -static char_u *p_cpt; -static char_u *p_cfu; -static char_u *p_ofu; -static char_u *p_tfu; +static char_u *p_cink; +static char_u *p_cino; +static char_u *p_cinw; +static char_u *p_com; +static char_u *p_cms; +static char_u *p_cpt; +static char_u *p_cfu; +static char_u *p_ofu; +static char_u *p_tfu; static int p_eol; static int p_fixeol; static int p_et; -static char_u *p_fenc; -static char_u *p_ff; -static char_u *p_fo; -static char_u *p_flp; -static char_u *p_ft; +static char_u *p_fenc; +static char_u *p_ff; +static char_u *p_fo; +static char_u *p_flp; +static char_u *p_ft; static long p_iminsert; static long p_imsearch; -static char_u *p_inex; -static char_u *p_inde; -static char_u *p_indk; -static char_u *p_fex; +static char_u *p_inex; +static char_u *p_inde; +static char_u *p_indk; +static char_u *p_fex; static int p_inf; -static char_u *p_isk; +static char_u *p_isk; static int p_lisp; static int p_ml; static int p_ma; static int p_mod; -static char_u *p_mps; -static char_u *p_nf; +static char_u *p_mps; +static char_u *p_nf; static int p_pi; -static char_u *p_qe; +static char_u *p_qe; static int p_ro; static int p_si; static long p_sts; -static char_u *p_sua; +static char_u *p_sua; static long p_sw; static int p_swf; static long p_smc; -static char_u *p_syn; -static char_u *p_spc; -static char_u *p_spf; -static char_u *p_spl; -static char_u *p_spo; +static char_u *p_syn; +static char_u *p_spc; +static char_u *p_spf; +static char_u *p_spl; +static char_u *p_spo; static long p_ts; static long p_tw; static int p_udf; static long p_wm; static char_u *p_vsts; static char_u *p_vts; -static char_u *p_keymap; +static char_u *p_keymap; // Saved values for when 'bin' is set. static int p_et_nobin; @@ -198,15 +198,15 @@ static long p_wm_nopaste; static char_u *p_vsts_nopaste; typedef struct vimoption { - char *fullname; // full option name - char *shortname; // permissible abbreviation + 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 + 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_u *def_val; // default values for variable (neovim!!) + char_u *def_val; // default values for variable (neovim!!) LastSet last_set; // script in which the option was last set } vimoption_T; @@ -314,12 +314,15 @@ static char *(p_csl_values[]) = { "slash", "backslash", NULL }; #endif static char *(p_icm_values[]) = { "nosplit", "split", NULL }; static char *(p_scl_values[]) = { "yes", "no", "auto", "auto:1", "auto:2", - "auto:3", "auto:4", "auto:5", "auto:6", "auto:7", "auto:8", "auto:9", - "yes:1", "yes:2", "yes:3", "yes:4", "yes:5", "yes:6", "yes:7", "yes:8", - "yes:9", "number", NULL }; + "auto:3", "auto:4", "auto:5", "auto:6", "auto:7", "auto:8", + "auto:9", + "yes:1", "yes:2", "yes:3", "yes:4", "yes:5", "yes:6", + "yes:7", "yes:8", + "yes:9", "number", NULL }; static char *(p_fdc_values[]) = { "auto", "auto:1", "auto:2", - "auto:3", "auto:4", "auto:5", "auto:6", "auto:7", "auto:8", "auto:9", - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; + "auto:3", "auto:4", "auto:5", "auto:6", "auto:7", "auto:8", + "auto:9", + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; /// All possible flags for 'shm'. static char_u SHM_ALL[] = { @@ -372,9 +375,9 @@ void set_init_1(bool clean_arg) */ { # ifdef UNIX - static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"}; + static char *(names[4]) = { "", "TMPDIR", "TEMP", "TMP" }; # else - static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"}; + static char *(names[3]) = { "TMPDIR", "TEMP", "TMP" }; # endif garray_T ga; opt_idx = findoption("backupskip"); @@ -426,8 +429,8 @@ void set_init_1(bool clean_arg) } { - char_u *cdpath; - char_u *buf; + char_u *cdpath; + char_u *buf; int i; int j; @@ -470,13 +473,13 @@ void set_init_1(bool clean_arg) set_string_default("printexpr", #ifdef UNIX "system(['lpr'] " - "+ (empty(&printdevice)?[]:['-P', &printdevice]) " - "+ [v:fname_in])" + "+ (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])" + "empty(&printdevice)?'LPT1':&printdevice])" ". delete(v:fname_in)", #else "", @@ -550,7 +553,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 = (char *)option_expand(opt_idx, NULL); } if (p != NULL) { p = xstrdup(p); @@ -584,8 +587,8 @@ void set_init_1(bool clean_arg) // in 'fileencodings' char_u *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")); + // use utf-8 as 'default' if locale encoding can't be detected. + p = (char_u *)xmemdupz(S_LEN("utf-8")); } fenc_default = p; @@ -605,7 +608,7 @@ 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 + 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); @@ -624,7 +627,7 @@ static void set_option_default(int opt_idx, int opt_flags) *(char_u **)varp = options[opt_idx].def_val; options[opt_idx].flags &= ~P_ALLOCED; } - } else if (flags & P_NUM) { + } else if (flags & P_NUM) { if (options[opt_idx].indir == PV_SCROLL) { win_comp_scroll(curwin); } else { @@ -667,10 +670,9 @@ static void set_option_default(int opt_idx, int opt_flags) } /// Set all options (except terminal options) to their default value. -static void -set_options_default( - int opt_flags // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL -) +/// +/// @param opt_flags OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL +static void set_options_default(int opt_flags) { for (int i = 0; options[i].fullname; i++) { if (!(options[i].flags & P_NODEFAULT)) { @@ -710,8 +712,7 @@ 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) +static char_u *find_dup_item(char_u *origval, const char_u *newval, uint32_t flags) FUNC_ATTR_NONNULL_ARG(2) { int bs = 0; @@ -827,9 +828,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 (fnamecmp(p, "csh") == 0 + || fnamecmp(p, "tcsh") == 0) { if (do_sp) { p_sp = (char_u *)"|& tee"; options[idx_sp].def_val = p_sp; @@ -847,8 +847,7 @@ void set_init_3(void) || fnamecmp(p, "bash") == 0 || fnamecmp(p, "fish") == 0 || fnamecmp(p, "ash") == 0 - || fnamecmp(p, "dash") == 0 - ) { + || fnamecmp(p, "dash") == 0) { // Always use POSIX shell style redirection if we reach this if (do_sp) { p_sp = (char_u *)"2>&1| tee"; @@ -933,28 +932,27 @@ void set_title_defaults(void) } } -// Parse 'arg' for option settings. -// -// 'arg' may be IObuff, but only when no errors can be present and option -// does not need to be expanded with option_expand(). -// "opt_flags": -// 0 for ":set" -// OPT_GLOBAL for ":setglobal" -// OPT_LOCAL for ":setlocal" and a modeline -// OPT_MODELINE for a modeline -// OPT_WINONLY to only set window-local options -// OPT_NOWIN to skip setting window-local options -// -// returns FAIL if an error is detected, OK otherwise -int do_set( - char_u *arg, // option string (may be written to!) - int opt_flags -) +/// Parse 'arg' for option settings. +/// +/// 'arg' may be IObuff, but only when no errors can be present and option +/// does not need to be expanded with option_expand(). +/// "opt_flags": +/// 0 for ":set" +/// OPT_GLOBAL for ":setglobal" +/// OPT_LOCAL for ":setlocal" and a modeline +/// OPT_MODELINE for a modeline +/// OPT_WINONLY to only set window-local options +/// OPT_NOWIN to skip setting window-local options +/// +/// @param arg option string (may be written to!) +/// +/// @return FAIL if an error is detected, OK otherwise +int do_set(char_u *arg, int opt_flags) { int opt_idx; - char_u *errmsg; + char_u *errmsg; char_u errbuf[80]; - char_u *startarg; + char_u *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 @@ -963,7 +961,7 @@ int do_set( varnumber_T value; int key; uint32_t flags; // flags for current option - char_u *varp = NULL; // pointer to variable for current option + char_u *varp = NULL; // pointer to variable for current option int did_show = false; // already showed one value int adding; // "opt+=arg" int prepending; // "opt^=arg" @@ -1099,8 +1097,9 @@ int do_set( /* Skip all options that are not window-local (used when showing * an already loaded buffer in a window). */ if ((opt_flags & OPT_WINONLY) - && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) + && (opt_idx < 0 || options[opt_idx].var != VAR_WIN)) { goto skip; + } // Skip all options that are window-local (used for :vimgrep). if ((opt_flags & OPT_NOWIN) && opt_idx >= 0 @@ -1115,8 +1114,7 @@ int do_set( goto skip; } if ((flags & P_MLE) && !p_mle) { - errmsg = (char_u *)N_( - "E992: Not allowed in a modeline when 'modelineexpr' is off"); + errmsg = (char_u *)N_("E992: Not allowed in a modeline when 'modelineexpr' is off"); goto skip; } // In diff mode some options are overruled. This avoids that @@ -1177,10 +1175,10 @@ int do_set( option_last_set_msg(options[opt_idx].last_set); } else if ((int)options[opt_idx].indir & PV_WIN) { option_last_set_msg(curwin->w_p_script_ctx[ - (int)options[opt_idx].indir & PV_MASK]); + (int)options[opt_idx].indir & PV_MASK]); } else if ((int)options[opt_idx].indir & PV_BUF) { option_last_set_msg(curbuf->b_p_script_ctx[ - (int)options[opt_idx].indir & PV_MASK]); + (int)options[opt_idx].indir & PV_MASK]); } } } else { @@ -1188,8 +1186,9 @@ int do_set( goto skip; } if (nextchar != '?' - && nextchar != NUL && !ascii_iswhite(afterchar)) + && nextchar != NUL && !ascii_iswhite(afterchar)) { errmsg = e_trailing; + } } else { int value_is_replaced = !prepending && !adding && !removing; int value_checked = false; @@ -1260,8 +1259,7 @@ int do_set( if ((long *)varp == &curbuf->b_p_ul && opt_flags == OPT_LOCAL) { value = NO_LOCAL_UNDOLEVEL; } else { - value = *(long *)get_varp_scope( - &(options[opt_idx]), OPT_GLOBAL); + value = *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); } } else if (((long *)varp == &p_wc || (long *)varp == &p_wcm) @@ -1299,11 +1297,11 @@ int do_set( errbuf, sizeof(errbuf), opt_flags); } else if (opt_idx >= 0) { // String. - char_u *save_arg = NULL; - char_u *s = NULL; - char_u *oldval = NULL; // previous value if *varp - char_u *newval; - char_u *origval = NULL; + char_u *save_arg = NULL; + char_u *s = NULL; + char_u *oldval = NULL; // previous value if *varp + char_u *newval; + char_u *origval = NULL; char *saved_origval = NULL; char *saved_newval = NULL; unsigned newlen; @@ -1314,8 +1312,9 @@ int do_set( * 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)) + && ((int)options[opt_idx].indir & PV_BOTH)) { varp = options[opt_idx].var; + } /* The old value is kept until we are sure that the * new value is valid. */ @@ -1349,8 +1348,7 @@ int do_set( newval = (char_u *)xstrdup((char *)newval); } } else if (nextchar == '<') { // set to global val - newval = vim_strsave(*(char_u **)get_varp_scope( - &(options[opt_idx]), OPT_GLOBAL)); + newval = vim_strsave(*(char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL)); new_value_alloced = true; } else { arg++; // jump to after the '=' or ':' @@ -1378,16 +1376,13 @@ int do_set( *(char_u **)varp = empty_option; break; case 1: - *(char_u **)varp = vim_strsave( - (char_u *)"indent,eol"); + *(char_u **)varp = vim_strsave((char_u *)"indent,eol"); break; case 2: - *(char_u **)varp = vim_strsave( - (char_u *)"indent,eol,start"); + *(char_u **)varp = vim_strsave((char_u *)"indent,eol,start"); break; case 3: - *(char_u **)varp = vim_strsave( - (char_u *)"indent,eol,nostop"); + *(char_u **)varp = vim_strsave((char_u *)"indent,eol,nostop"); break; } xfree(oldval); @@ -1427,9 +1422,9 @@ int do_set( * Remove '>' before 'dir' and 'bdir', for * backwards compatibility with version 3.0 */ - else if ( *arg == '>' - && (varp == (char_u *)&p_dir - || varp == (char_u *)&p_bdir)) { + else if (*arg == '>' + && (varp == (char_u *)&p_dir + || varp == (char_u *)&p_bdir)) { arg++; } @@ -1464,8 +1459,9 @@ int do_set( || (s == newval && arg[2] != '\\'))) #endif - ) + ) { arg++; // remove backslash + } i = utfc_ptr2len(arg); if (i > 1) { // copy multibyte char @@ -1533,7 +1529,7 @@ int do_set( i--; } memmove(newval + i + comma, newval, - STRLEN(newval) + 1); + STRLEN(newval) + 1); memmove(newval, origval, (size_t)i); } else { i = (int)STRLEN(newval); @@ -1650,7 +1646,6 @@ int do_set( if (errmsg != NULL) { goto skip; } - } else { // key code option(FIXME(tarruda): Show a warning or something // similar) @@ -1719,15 +1714,13 @@ theend: return OK; } -// Call this when an option has been given a new value through a user command. -// Sets the P_WAS_SET flag and takes care of the P_INSECURE flag. -static void did_set_option( - int opt_idx, - int opt_flags, // possibly with OPT_MODELINE - int new_value, // value was replaced completely - int value_checked // value was checked to be safe, no need to - // set P_INSECURE -) +/// Call this when an option has been given a new value through a user command. +/// Sets the P_WAS_SET flag and takes care of the P_INSECURE flag. +/// +/// @param opt_flags possibly with OPT_MODELINE +/// @param new_value value was replaced completely +/// @param value_checked value was checked to be safe, no need to set P_INSECURE +static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked) { options[opt_idx].flags |= P_WAS_SET; @@ -1796,12 +1789,10 @@ static void did_set_title(void) } } -// set_options_bin - called when 'bin' changes value. -void set_options_bin( - int oldval, - int newval, - int opt_flags // OPT_LOCAL and/or OPT_GLOBAL -) +/// set_options_bin - called when 'bin' changes value. +/// +/// @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 @@ -1859,7 +1850,7 @@ void set_options_bin( /// number, return -1. int get_shada_parameter(int type) { - char_u *p; + char_u *p; p = find_shada_parameter(type); if (p != NULL && ascii_isdigit(*p)) { @@ -1873,7 +1864,7 @@ 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; + char_u *p; for (p = p_shada; *p; p++) { if (*p == type) { @@ -2102,12 +2093,18 @@ static uint32_t *insecure_flag(win_T *const wp, int opt_idx, int opt_flags) if (opt_flags & OPT_LOCAL) { assert(wp != NULL); switch ((int)options[opt_idx].indir) { - case PV_STL: return &wp->w_p_stl_flags; - case PV_FDE: return &wp->w_p_fde_flags; - case PV_FDT: return &wp->w_p_fdt_flags; - case PV_INDE: return &wp->w_buffer->b_p_inde_flags; - case PV_FEX: return &wp->w_buffer->b_p_fex_flags; - case PV_INEX: return &wp->w_buffer->b_p_inex_flags; + case PV_STL: + return &wp->w_p_stl_flags; + case PV_FDE: + return &wp->w_p_fde_flags; + case PV_FDT: + return &wp->w_p_fdt_flags; + case PV_INDE: + return &wp->w_buffer->b_p_inde_flags; + case PV_FEX: + return &wp->w_buffer->b_p_fex_flags; + case PV_INEX: + return &wp->w_buffer->b_p_inex_flags; } } @@ -2125,23 +2122,19 @@ static void redraw_titles(void) static int shada_idx = -1; -// Set a string option to a new value (without checking the effect). -// The string is copied into allocated memory. -// if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used. -// When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When -// "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to -// "set_sid". -void -set_string_option_direct( - const char *name, - int opt_idx, - const char_u *val, - int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL - int set_sid -) -{ - char_u *s; - char_u **varp; +/// Set a string option to a new value (without checking the effect). +/// The string is copied into allocated memory. +/// if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used. +/// When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When +/// "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to +/// "set_sid". +/// +/// @param opt_flags OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL +void set_string_option_direct(const char *name, int opt_idx, const char_u *val, int opt_flags, + int set_sid) +{ + char_u *s; + char_u **varp; int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; int idx = opt_idx; @@ -2158,7 +2151,7 @@ set_string_option_direct( return; } - assert((void *) options[idx].var != (void *) &p_shada); + assert((void *)options[idx].var != (void *)&p_shada); s = vim_strsave(val); { @@ -2198,13 +2191,12 @@ set_string_option_direct( } /// Set global value for string option when it's a local option. -static void -set_string_option_global( - int opt_idx, // option index - char_u **varp // pointer to option variable -) +/// +/// @param opt_idx option index +/// @param varp pointer to option variable +static void set_string_option_global(int opt_idx, char_u **varp) { - char_u **p, *s; + char_u **p, *s; // the global value is always allocated if (options[opt_idx].var == VAR_WIN) { @@ -2227,8 +2219,7 @@ set_string_option_global( /// #OPT_GLOBAL. /// /// @return NULL on success, error message on error. -static char *set_string_option(const int opt_idx, const char *const value, - const int opt_flags) +static char *set_string_option(const int opt_idx, const char *const value, const int opt_flags) FUNC_ATTR_NONNULL_ARG(2) FUNC_ATTR_WARN_UNUSED_RESULT { if (options[opt_idx].var == NULL) { // don't set hidden option @@ -2236,12 +2227,11 @@ static char *set_string_option(const int opt_idx, const char *const value, } char *const s = xstrdup(value); - char **const varp = (char **)get_varp_scope( - &(options[opt_idx]), - ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 + char **const varp = (char **)get_varp_scope(&(options[opt_idx]), + ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 ? (((int)options[opt_idx].indir & PV_BOTH) ? OPT_GLOBAL : OPT_LOCAL) - : opt_flags)); + : opt_flags)); char *const oldval = *varp; *varp = s; @@ -2249,9 +2239,9 @@ static char *set_string_option(const int opt_idx, const char *const value, char *const saved_newval = xstrdup(s); int value_checked = false; - char *const r = (char *)did_set_string_option( - opt_idx, (char_u **)varp, (int)true, (char_u *)oldval, - NULL, 0, opt_flags, &value_checked); + char *const r = (char *)did_set_string_option(opt_idx, (char_u **)varp, (int)true, + (char_u *)oldval, + NULL, 0, opt_flags, &value_checked); if (r == NULL) { did_set_option(opt_idx, opt_flags, true, value_checked); } @@ -2315,23 +2305,23 @@ static bool valid_spellfile(const char_u *val) /// Handle string options that need some action to perform when changed. /// Returns NULL for success, or an error message for an error. -static char_u * -did_set_string_option( - int opt_idx, // index in options[] table - char_u **varp, // pointer to the option variable - bool new_value_alloced, // new value was allocated - char_u *oldval, // previous value of the option - char_u *errbuf, // buffer for errors, or NULL - size_t errbuflen, // length of errors buffer - int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL - int *value_checked // value was checked to be safe, no - // need to set P_INSECURE -) -{ - char_u *errmsg = NULL; - char_u *s, *p; +/// +/// @param opt_idx index in options[] table +/// @param varp pointer to the option variable +/// @param new_value_alloced new value was allocated +/// @param oldval previous value of the option +/// @param errbuf buffer for errors, or NULL +/// @param errbuflen length of errors buffer +/// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL +/// @param value_checked value was checked to be safe, no need to set P_INSECURE +static char_u *did_set_string_option(int opt_idx, char_u **varp, bool new_value_alloced, + char_u *oldval, char_u *errbuf, size_t errbuflen, + int opt_flags, int *value_checked) +{ + char_u *errmsg = NULL; + char_u *s, *p; int did_chartab = false; - char_u **gvarp; + char_u **gvarp; bool free_oldval = (options[opt_idx].flags & P_ALLOCED); bool value_changed = false; @@ -2345,7 +2335,7 @@ did_set_string_option( errmsg = e_secure; } else if (((options[opt_idx].flags & P_NFNAME) && vim_strpbrk(*varp, (char_u *)(secure ? "/\\*?[|;&<>\r\n" - : "/\\*?[<>\r\n")) != NULL) + : "/\\*?[<>\r\n")) != NULL) || ((options[opt_idx].flags & P_NDNAME) && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL)) { // Check for a "normal" directory or file name in some options. Disallow a @@ -2353,7 +2343,7 @@ did_set_string_option( // are often illegal in a file name. Be more permissive if "secure" is off. errmsg = e_invarg; } else if (gvarp == &p_bkc) { // 'backupcopy' - char_u *bkc = p_bkc; + char_u *bkc = p_bkc; unsigned int *flags = &bkc_flags; if (opt_flags & OPT_LOCAL) { @@ -2493,13 +2483,14 @@ ambw_end: check_string_option(&p_bg); init_highlight(false, false); } - } else + } else { errmsg = e_invarg; + } } else if (varp == &p_wim) { // 'wildmode' if (check_opt_wim() == FAIL) { errmsg = e_invarg; } - // 'wildoptions' + // 'wildoptions' } else if (varp == &p_wop) { if (opt_strings_flags(p_wop, p_wop_values, &wop_flags, true) != OK) { errmsg = e_invarg; @@ -2513,7 +2504,7 @@ ambw_end: if (check_ei() == FAIL) { errmsg = e_invarg; } - // 'encoding', 'fileencoding' and 'makeencoding' + // 'encoding', 'fileencoding' and 'makeencoding' } else if (varp == &p_enc || gvarp == &p_fenc || gvarp == &p_menc) { if (gvarp == &p_fenc) { if (!MODIFIABLE(curbuf) && opt_flags != OPT_GLOBAL) { @@ -2684,7 +2675,7 @@ ambw_end: if (*p_vfile != NUL && verbose_open() == FAIL) { errmsg = e_invarg; } - // 'shada' + // 'shada' } else if (varp == &p_shada) { // TODO(ZyX-I): Remove this code in the future, alongside with &viminfo // option. @@ -2692,7 +2683,7 @@ ambw_end: ? (shada_idx == -1 ? ((shada_idx = findoption("shada"))) : shada_idx) - : opt_idx); + : opt_idx); // Update free_oldval now that we have the opt_idx for 'shada', otherwise // there would be a disconnect between the check for P_ALLOCED at the start // of the function and the set of P_ALLOCED at the end of the function. @@ -2721,8 +2712,9 @@ ambw_end: _("E526: Missing number after <%s>"), transchar_byte(*(s - 1))); errmsg = errbuf; - } else + } else { errmsg = (char_u *)""; + } break; } } @@ -2743,8 +2735,7 @@ ambw_end: } else if (gvarp == &p_sbr) { // 'showbreak' for (s = *varp; *s; ) { if (ptr2cells(s) != 1) { - errmsg = (char_u *)N_( - "E595: 'showbreak' contains unprintable or wide character"); + errmsg = (char_u *)N_("E595: 'showbreak' contains unprintable or wide character"); } MB_PTR_ADV(s); } @@ -2769,7 +2760,6 @@ ambw_end: stl_syntax &= ~flagval; } did_set_title(); - } else if (varp == &p_sel) { // 'selection' if (*p_sel == NUL || check_opt_strings(p_sel, p_sel_values, false) != OK) { @@ -2888,8 +2878,9 @@ ambw_end: } else if (gvarp == &p_cpt) { // check if it is a valid value for 'complete' -- Acevedo for (s = *varp; *s; ) { - while (*s == ',' || *s == ' ') + while (*s == ',' || *s == ' ') { s++; + } if (!*s) { break; } @@ -2912,8 +2903,9 @@ ambw_end: _("E535: Illegal character after <%c>"), *--s); errmsg = errbuf; - } else + } else { errmsg = (char_u *)""; + } break; } } @@ -3024,8 +3016,7 @@ ambw_end: } } else if (gvarp == &p_cms) { // 'commentstring' if (**varp != NUL && strstr((char *)(*varp), "%s") == NULL) { - errmsg = (char_u *)N_( - "E537: 'commentstring' must be empty or contain %s"); + errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s"); } } else if (varp == &p_fdo) { // 'foldopen' if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, true) != OK) { @@ -3068,11 +3059,11 @@ ambw_end: } else if (gvarp == &p_cino) { // 'cinoptions' // TODO(vim): recognize errors parse_cino(curbuf); - // inccommand + // inccommand } else if (varp == &p_icm) { - if (check_opt_strings(p_icm, p_icm_values, false) != OK) { - errmsg = e_invarg; - } + if (check_opt_strings(p_icm, p_icm_values, false) != OK) { + errmsg = e_invarg; + } } else if (gvarp == &p_ft) { if (!valid_filetype(*varp)) { errmsg = e_invarg; @@ -3274,7 +3265,7 @@ ambw_end: } if (varp == &(curwin->w_s->b_p_spl)) { char_u fname[200]; - char_u *q = curwin->w_s->b_p_spl; + char_u *q = curwin->w_s->b_p_spl; // Skip the first name if it is "cjk". if (STRNCMP(q, "cjk,", 4) == 0) { @@ -3305,8 +3296,9 @@ ambw_end: } if (curwin->w_curswant != MAXCOL - && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) + && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) { curwin->w_set_curswant = true; + } check_redraw(options[opt_idx].flags); @@ -3334,8 +3326,7 @@ int check_signcolumn(char_u *val) && !STRNCMP(val, "auto:", 5) && ascii_isdigit(val[5]) && val[6] == '-' - && ascii_isdigit(val[7]) - ) { + && ascii_isdigit(val[7])) { int min = val[5] - '0'; int max = val[7] - '0'; if (min < 1 || max < 2 || min > 8 || max > 9 || min >= max) { @@ -3352,7 +3343,7 @@ int check_signcolumn(char_u *val) /// @return error message, NULL if it's OK. char_u *check_colorcolumn(win_T *wp) { - char_u *s; + char_u *s; int col; unsigned int count = 0; int color_cols[256]; @@ -3446,8 +3437,8 @@ static char_u *set_chars_option(win_T *wp, char_u **varp, bool set) int multispace_len = 0; // Length of lcs-multispace string struct chars_tab { - int *cp; ///< char value - char *name; ///< char id + int *cp; ///< char value + char *name; ///< char id int def; ///< default value }; struct chars_tab *tab; @@ -3658,8 +3649,9 @@ char_u *check_stl_option(char_u *s) } if (*s == '.') { s++; - while (*s && ascii_isdigit(*s)) + while (*s && ascii_isdigit(*s)) { s++; + } } if (*s == '(') { groupdepth++; @@ -3687,7 +3679,7 @@ char_u *check_stl_option(char_u *s) static char_u *did_set_spell_option(bool is_spellfile) { - char_u *errmsg = NULL; + char_u *errmsg = NULL; if (is_spellfile) { int l = (int)STRLEN(curwin->w_s->b_p_spf); @@ -3714,8 +3706,8 @@ static char_u *did_set_spell_option(bool is_spellfile) static char_u *compile_cap_prog(synblock_T *synblock) FUNC_ATTR_NONNULL_ALL { - regprog_T *rp = synblock->b_cap_prog; - char_u *re; + regprog_T *rp = synblock->b_cap_prog; + char_u *re; if (synblock->b_p_spc == NULL || *synblock->b_p_spc == NUL) { synblock->b_cap_prog = NULL; @@ -3814,8 +3806,7 @@ static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx) /// @param[in] opt_flags OPT_LOCAL and/or OPT_GLOBAL. /// /// @return NULL on success, error message on error. -static char *set_bool_option(const int opt_idx, char_u *const varp, - const int value, +static char *set_bool_option(const int opt_idx, char_u *const varp, const int value, const int opt_flags) { int old_value = *(int *)varp; @@ -3840,7 +3831,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, if ((int *)varp == &p_force_on && p_force_on == false) { p_force_on = true; return (char *)e_unsupportedoption; - // Ensure that options set to p_force_off cannot be enabled. + // Ensure that options set to p_force_off cannot be enabled. } else if ((int *)varp == &p_force_off && p_force_off == true) { p_force_off = false; return (char *)e_unsupportedoption; @@ -3853,7 +3844,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, } else if ((int *)varp == &curwin->w_p_cul && !value && old_value) { // 'cursorline' reset_cursorline(); - // 'undofile' + // 'undofile' } else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf) { // Only take action when the option was set. When reset we do not // delete the undo file, the option may be set again without making @@ -3917,7 +3908,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, } } else if ((int *)varp == &p_terse) { // when 'terse' is set change 'shortmess' - char_u *p; + char_u *p; p = vim_strchr(p_shm, SHM_SEARCH); @@ -3954,8 +3945,8 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, // when 'hlsearch' is set or reset: reset no_hlsearch set_no_hlsearch(false); } else if ((int *)varp == &curwin->w_p_scb) { - // when 'scrollbind' is set: snapshot the current position to avoid a jump - // at the end of normal_cmd() + // when 'scrollbind' is set: snapshot the current position to avoid a jump + // at the end of normal_cmd() if (curwin->w_p_scb) { do_check_scrollbind(false); curwin->w_scbind_pos = curwin->w_topline; @@ -4025,7 +4016,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, } } else if ((int *)varp == &curwin->w_p_spell) { // 'spell' if (curwin->w_p_spell) { - char_u *errmsg = did_set_spelllang(curwin); + char_u *errmsg = did_set_spelllang(curwin); if (errmsg != NULL) { EMSG(_(errmsg)); } @@ -4054,8 +4045,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, /* Arabic requires a utf-8 encoding, inform the user if its not * set. */ if (STRCMP(p_enc, "utf-8") != 0) { - static char *w_arabic = N_( - "W17: Arabic requires UTF-8, do ':set encoding=utf-8'"); + static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'"); msg_source(HL_ATTR(HLF_W)); msg_attr(_(w_arabic), HL_ATTR(HLF_W)); @@ -4115,7 +4105,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, set_vim_var_string(VV_OPTION_OLD, buf_old, -1); set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); apply_autocmds(EVENT_OPTIONSET, - (char_u *) options[opt_idx].fullname, + (char_u *)options[opt_idx].fullname, NULL, false, NULL); reset_v_option_vars(); } @@ -4145,13 +4135,13 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, /// @param[in] opt_flags OPT_LOCAL, OPT_GLOBAL or OPT_MODELINE. /// /// @return NULL on success, error message on error. -static char *set_num_option(int opt_idx, char_u *varp, long value, - char_u *errbuf, size_t errbuflen, int opt_flags) +static char *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, + int opt_flags) { - char_u *errmsg = NULL; + char_u *errmsg = NULL; long old_value = *(long *)varp; long old_Rows = Rows; // remember old Rows - long *pp = (long *)varp; + long *pp = (long *)varp; // Disallow changing some options from secure mode. if ((secure || sandbox != 0) @@ -4161,7 +4151,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, // Many number options assume their value is in the signed int range. if (value < INT_MIN || value > INT_MAX) { - return (char *)e_invarg; + return (char *)e_invarg; } // Options that need some validation. @@ -4425,7 +4415,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (p_lines < min_rows() && full_screen) { if (errbuf != NULL) { vim_snprintf((char *)errbuf, errbuflen, - _("E593: Need at least %d lines"), min_rows()); + _("E593: Need at least %d lines"), min_rows()); errmsg = errbuf; } p_lines = min_rows(); @@ -4433,7 +4423,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (p_columns < MIN_COLUMNS && full_screen) { if (errbuf != NULL) { vim_snprintf((char *)errbuf, errbuflen, - _("E594: Need at least %d columns"), MIN_COLUMNS); + _("E594: Need at least %d columns"), MIN_COLUMNS); errmsg = errbuf; } p_columns = MIN_COLUMNS; @@ -4478,7 +4468,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } win_comp_scroll(curwin); } else if (curwin->w_p_scr <= 0) { - // If 'scroll' became invalid because of a side effect silently adjust it. + // If 'scroll' became invalid because of a side effect silently adjust it. curwin->w_p_scr = 1; } else { // curwin->w_p_scr > curwin->w_height curwin->w_p_scr = curwin->w_height; @@ -4514,7 +4504,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, set_vim_var_string(VV_OPTION_OLD, buf_old, -1); set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); apply_autocmds(EVENT_OPTIONSET, - (char_u *) options[opt_idx].fullname, + (char_u *)options[opt_idx].fullname, NULL, false, NULL); reset_v_option_vars(); } @@ -4534,8 +4524,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, return (char *)errmsg; } -static void trigger_optionsset_string(int opt_idx, int opt_flags, - char *oldval, char *newval) +static void trigger_optionsset_string(int opt_idx, int opt_flags, char *oldval, char *newval) { // Don't do this recursively. if (oldval != NULL @@ -4658,8 +4647,8 @@ bool is_tty_option(const char *name) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { return (name[0] == 't' && name[1] == '_') - || strequal(name, "term") - || strequal(name, "ttytype"); + || strequal(name, "term") + || strequal(name, "ttytype"); } #define TCO_BUFFER_SIZE 8 @@ -4738,18 +4727,15 @@ static int findoption(const char *const arg) /// Gets the value for an option. /// +/// @param stringval NULL when only checking existence +/// /// @returns: /// Number or Toggle option: 1, *numval gets value. /// String option: 0, *stringval gets allocated string. /// Hidden Number or Toggle option: -1. /// hidden String option: -2. /// unknown option: -3. -int get_option_value( - const char *name, - long *numval, - char_u **stringval, ///< NULL when only checking existence - int opt_flags -) +int get_option_value(const char *name, long *numval, char_u **stringval, int opt_flags) { if (get_tty_option(name, (char **)stringval)) { return 0; @@ -4783,7 +4769,7 @@ int get_option_value( if ((int *)varp == &curbuf->b_changed) { *numval = curbufIsChanged(); } else { - *numval = (long) *(int *)varp; // NOLINT(whitespace/cast) + *numval = (long)*(int *)varp; // NOLINT(whitespace/cast) } } return 1; @@ -4805,11 +4791,7 @@ int get_option_value( // see SOPT_* in option_defs.h for other flags // // Possible opt_type values: see SREQ_* in option_defs.h -int get_option_value_strict(char *name, - int64_t *numval, - char **stringval, - int opt_type, - void *from) +int get_option_value_strict(char *name, int64_t *numval, char **stringval, int opt_type, void *from) { if (get_tty_option(name, stringval)) { return SOPT_STRING | SOPT_GLOBAL; @@ -4925,8 +4907,8 @@ int get_option_value_strict(char *name, /// @param[in] opt_flags Flags: OPT_LOCAL, OPT_GLOBAL, or 0 (both). /// /// @return NULL on success, error message on error. -char *set_option_value(const char *const name, const long number, - const char *const string, const int opt_flags) +char *set_option_value(const char *const name, const long number, const char *const string, + const int opt_flags) FUNC_ATTR_NONNULL_ARG(1) { if (is_tty_option(name)) { @@ -4934,7 +4916,7 @@ char *set_option_value(const char *const name, const long number, } int opt_idx; - char_u *varp; + char_u *varp; opt_idx = findoption(name); if (opt_idx < 0) { @@ -4994,7 +4976,7 @@ int find_key_option_len(const char_u *arg_arg, size_t len, bool has_lt) // add_termcap_entry(). if (len >= 4 && arg[0] == 't' && arg[1] == '_') { key = TERMCAP2KEY(arg[2], arg[3]); - } else if (has_lt) { + } else if (has_lt) { arg--; // put arg at the '<' modifiers = 0; key = find_special_key(&arg, len + 1, &modifiers, true, true, false); @@ -5012,15 +4994,13 @@ static int find_key_option(const char_u *arg, bool has_lt) /// if 'all' == 0: show changed options /// if 'all' == 1: show all normal options -static void -showoptions( - int all, - int opt_flags // OPT_LOCAL and/or OPT_GLOBAL -) +/// +/// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL +static void showoptions(int all, int opt_flags) { - vimoption_T *p; + vimoption_T *p; int col; - char_u *varp; + char_u *varp; int item_count; int run; int row, rows; @@ -5155,13 +5135,11 @@ void ui_refresh_options(void) /// showoneopt: show the value of one option /// must not be called with a hidden option! -static void -showoneopt( - vimoption_T *p, - int opt_flags // OPT_LOCAL or OPT_GLOBAL -) +/// +/// @param opt_flags OPT_LOCAL or OPT_GLOBAL +static void showoneopt(vimoption_T *p, int opt_flags) { - char_u *varp; + char_u *varp; int save_silent = silent_mode; silent_mode = false; @@ -5212,11 +5190,11 @@ showoneopt( /// Return FAIL on error, OK otherwise. int makeset(FILE *fd, int opt_flags, int local_only) { - vimoption_T *p; - char_u *varp; // currently used value - char_u *varp_fresh; // local value - char_u *varp_local = NULL; // fresh value - char *cmd; + vimoption_T *p; + char_u *varp; // currently used value + char_u *varp_fresh; // local value + char_u *varp_local = NULL; // fresh value + char *cmd; int round; int pri; @@ -5340,21 +5318,20 @@ int makefoldset(FILE *fd) || 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_u **valuep, uint64_t flags) { - char_u *s; - char_u *buf = NULL; - char_u *part = NULL; - char_u *p; + char_u *s; + char_u *buf = NULL; + char_u *part = NULL; + char_u *p; if (fprintf(fd, "%s %s=", cmd, name) < 0) { return FAIL; @@ -5392,15 +5369,15 @@ static int put_setstring(FILE *fd, char *cmd, char *name, } p = buf; while (*p != NUL) { - // for each comma separated option part, append value to - // the option, :set rtp+=value - if (fprintf(fd, "%s %s+=", cmd, name) < 0) { - goto fail; - } - (void)copy_option_part(&p, part, size, ","); - if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL) { - goto fail; - } + // for each comma separated option part, append value to + // the option, :set rtp+=value + if (fprintf(fd, "%s %s+=", cmd, name) < 0) { + goto fail; + } + (void)copy_option_part(&p, part, size, ","); + if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL) { + goto fail; + } } xfree(buf); xfree(part); @@ -5516,124 +5493,149 @@ void unset_global_local_option(char *name, void *from) switch ((int)p->indir) { - // global option with local value: use local value if it's been set + // global option with local value: use local value if it's been set + case PV_EP: + clear_string_option(&buf->b_p_ep); + break; + case PV_KP: + clear_string_option(&buf->b_p_kp); + break; + case PV_PATH: + clear_string_option(&buf->b_p_path); + break; + case PV_AR: + buf->b_p_ar = -1; + break; + case PV_BKC: + clear_string_option(&buf->b_p_bkc); + buf->b_bkc_flags = 0; + break; + case PV_TAGS: + clear_string_option(&buf->b_p_tags); + break; + case PV_TC: + clear_string_option(&buf->b_p_tc); + buf->b_tc_flags = 0; + break; + case PV_SISO: + curwin->w_p_siso = -1; + break; + case PV_SO: + curwin->w_p_so = -1; + break; + case PV_DEF: + clear_string_option(&buf->b_p_def); + break; + case PV_INC: + clear_string_option(&buf->b_p_inc); + break; + case PV_DICT: + clear_string_option(&buf->b_p_dict); + break; + case PV_TSR: + clear_string_option(&buf->b_p_tsr); + break; + case PV_FP: + clear_string_option(&buf->b_p_fp); + break; + case PV_EFM: + clear_string_option(&buf->b_p_efm); + break; + case PV_GP: + clear_string_option(&buf->b_p_gp); + break; + case PV_MP: + clear_string_option(&buf->b_p_mp); + break; + case PV_SBR: + clear_string_option(&((win_T *)from)->w_p_sbr); + break; + case PV_STL: + clear_string_option(&((win_T *)from)->w_p_stl); + break; + case PV_UL: + buf->b_p_ul = NO_LOCAL_UNDOLEVEL; + break; + case PV_LW: + clear_string_option(&buf->b_p_lw); + break; + case PV_MENC: + clear_string_option(&buf->b_p_menc); + 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); + redraw_later((win_T *)from, 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); + break; + } +} + +/// Get pointer to option variable, depending on local or global scope. +static char_u *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 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); + case PV_EFM: + return (char_u *)&(curbuf->b_p_efm); + case PV_GP: + return (char_u *)&(curbuf->b_p_gp); + case PV_MP: + return (char_u *)&(curbuf->b_p_mp); case PV_EP: - clear_string_option(&buf->b_p_ep); - break; + return (char_u *)&(curbuf->b_p_ep); case PV_KP: - clear_string_option(&buf->b_p_kp); - break; + return (char_u *)&(curbuf->b_p_kp); case PV_PATH: - clear_string_option(&buf->b_p_path); - break; + return (char_u *)&(curbuf->b_p_path); case PV_AR: - buf->b_p_ar = -1; - break; - case PV_BKC: - clear_string_option(&buf->b_p_bkc); - buf->b_bkc_flags = 0; - break; + return (char_u *)&(curbuf->b_p_ar); case PV_TAGS: - clear_string_option(&buf->b_p_tags); - break; + return (char_u *)&(curbuf->b_p_tags); case PV_TC: - clear_string_option(&buf->b_p_tc); - buf->b_tc_flags = 0; - break; + return (char_u *)&(curbuf->b_p_tc); case PV_SISO: - curwin->w_p_siso = -1; - break; + return (char_u *)&(curwin->w_p_siso); case PV_SO: - curwin->w_p_so = -1; - break; + return (char_u *)&(curwin->w_p_so); case PV_DEF: - clear_string_option(&buf->b_p_def); - break; + return (char_u *)&(curbuf->b_p_def); case PV_INC: - clear_string_option(&buf->b_p_inc); - break; + return (char_u *)&(curbuf->b_p_inc); case PV_DICT: - clear_string_option(&buf->b_p_dict); - break; + return (char_u *)&(curbuf->b_p_dict); case PV_TSR: - clear_string_option(&buf->b_p_tsr); - break; - case PV_FP: - clear_string_option(&buf->b_p_fp); - break; - case PV_EFM: - clear_string_option(&buf->b_p_efm); - break; - case PV_GP: - clear_string_option(&buf->b_p_gp); - break; - case PV_MP: - clear_string_option(&buf->b_p_mp); - break; + return (char_u *)&(curbuf->b_p_tsr); + case PV_TFU: + return (char_u *)&(curbuf->b_p_tfu); case PV_SBR: - clear_string_option(&((win_T *)from)->w_p_sbr); - break; + return (char_u *)&(curwin->w_p_sbr); case PV_STL: - clear_string_option(&((win_T *)from)->w_p_stl); - break; + return (char_u *)&(curwin->w_p_stl); case PV_UL: - buf->b_p_ul = NO_LOCAL_UNDOLEVEL; - break; + return (char_u *)&(curbuf->b_p_ul); case PV_LW: - clear_string_option(&buf->b_p_lw); - break; + return (char_u *)&(curbuf->b_p_lw); + case PV_BKC: + return (char_u *)&(curbuf->b_p_bkc); case PV_MENC: - clear_string_option(&buf->b_p_menc); - 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); - redraw_later((win_T *)from, NOT_VALID); - break; + return (char_u *)&(curbuf->b_p_menc); 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); - break; - } -} - -/// Get pointer to option variable, depending on local or global scope. -static char_u *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 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); - case PV_EFM: return (char_u *)&(curbuf->b_p_efm); - case PV_GP: return (char_u *)&(curbuf->b_p_gp); - case PV_MP: return (char_u *)&(curbuf->b_p_mp); - case PV_EP: return (char_u *)&(curbuf->b_p_ep); - case PV_KP: return (char_u *)&(curbuf->b_p_kp); - case PV_PATH: return (char_u *)&(curbuf->b_p_path); - case PV_AR: return (char_u *)&(curbuf->b_p_ar); - case PV_TAGS: return (char_u *)&(curbuf->b_p_tags); - case PV_TC: return (char_u *)&(curbuf->b_p_tc); - case PV_SISO: return (char_u *)&(curwin->w_p_siso); - case PV_SO: return (char_u *)&(curwin->w_p_so); - case PV_DEF: return (char_u *)&(curbuf->b_p_def); - case PV_INC: return (char_u *)&(curbuf->b_p_inc); - case PV_DICT: return (char_u *)&(curbuf->b_p_dict); - case PV_TSR: return (char_u *)&(curbuf->b_p_tsr); - case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); - case PV_SBR: return (char_u *)&(curwin->w_p_sbr); - case PV_STL: return (char_u *)&(curwin->w_p_stl); - case PV_UL: return (char_u *)&(curbuf->b_p_ul); - case PV_LW: return (char_u *)&(curbuf->b_p_lw); - case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); - case PV_MENC: return (char_u *)&(curbuf->b_p_menc); - case PV_FCS: return (char_u *)&(curwin->w_p_fcs); - case PV_LCS: return (char_u *)&(curwin->w_p_lcs); + return (char_u *)&(curwin->w_p_fcs); + case PV_LCS: + return (char_u *)&(curwin->w_p_lcs); } return NULL; // "cannot happen" } @@ -5649,163 +5651,290 @@ static char_u *get_varp(vimoption_T *p) } switch ((int)p->indir) { - case PV_NONE: return p->var; + case PV_NONE: + return p->var; // global option with local value: use local value if it's been set - case PV_EP: return *curbuf->b_p_ep != NUL + case PV_EP: + return *curbuf->b_p_ep != NUL ? (char_u *)&curbuf->b_p_ep : p->var; - case PV_KP: return *curbuf->b_p_kp != NUL + case PV_KP: + return *curbuf->b_p_kp != NUL ? (char_u *)&curbuf->b_p_kp : p->var; - case PV_PATH: return *curbuf->b_p_path != NUL + case PV_PATH: + return *curbuf->b_p_path != NUL ? (char_u *)&(curbuf->b_p_path) : p->var; - case PV_AR: return curbuf->b_p_ar >= 0 + case PV_AR: + return curbuf->b_p_ar >= 0 ? (char_u *)&(curbuf->b_p_ar) : p->var; - case PV_TAGS: return *curbuf->b_p_tags != NUL + case PV_TAGS: + return *curbuf->b_p_tags != NUL ? (char_u *)&(curbuf->b_p_tags) : p->var; - case PV_TC: return *curbuf->b_p_tc != NUL + case PV_TC: + return *curbuf->b_p_tc != NUL ? (char_u *)&(curbuf->b_p_tc) : p->var; - case PV_SISO: return curwin->w_p_siso >= 0 + case PV_SISO: + return curwin->w_p_siso >= 0 ? (char_u *)&(curwin->w_p_siso) : p->var; - case PV_SO: return curwin->w_p_so >= 0 + case PV_SO: + return curwin->w_p_so >= 0 ? (char_u *)&(curwin->w_p_so) : p->var; - case PV_BKC: return *curbuf->b_p_bkc != NUL + case PV_BKC: + return *curbuf->b_p_bkc != NUL ? (char_u *)&(curbuf->b_p_bkc) : p->var; - case PV_DEF: return *curbuf->b_p_def != NUL + case PV_DEF: + return *curbuf->b_p_def != NUL ? (char_u *)&(curbuf->b_p_def) : p->var; - case PV_INC: return *curbuf->b_p_inc != NUL + case PV_INC: + return *curbuf->b_p_inc != NUL ? (char_u *)&(curbuf->b_p_inc) : p->var; - case PV_DICT: return *curbuf->b_p_dict != NUL + case PV_DICT: + return *curbuf->b_p_dict != NUL ? (char_u *)&(curbuf->b_p_dict) : p->var; - case PV_TSR: return *curbuf->b_p_tsr != NUL + case PV_TSR: + return *curbuf->b_p_tsr != NUL ? (char_u *)&(curbuf->b_p_tsr) : p->var; - case PV_FP: return *curbuf->b_p_fp != NUL + case PV_FP: + return *curbuf->b_p_fp != NUL ? (char_u *)&(curbuf->b_p_fp) : p->var; - case PV_EFM: return *curbuf->b_p_efm != NUL + case PV_EFM: + return *curbuf->b_p_efm != NUL ? (char_u *)&(curbuf->b_p_efm) : p->var; - case PV_GP: return *curbuf->b_p_gp != NUL + case PV_GP: + return *curbuf->b_p_gp != NUL ? (char_u *)&(curbuf->b_p_gp) : p->var; - case PV_MP: return *curbuf->b_p_mp != NUL + case PV_MP: + return *curbuf->b_p_mp != NUL ? (char_u *)&(curbuf->b_p_mp) : p->var; - case PV_SBR: return *curwin->w_p_sbr != NUL + case PV_SBR: + return *curwin->w_p_sbr != NUL ? (char_u *)&(curwin->w_p_sbr) : p->var; - case PV_STL: return *curwin->w_p_stl != NUL + case PV_STL: + return *curwin->w_p_stl != NUL ? (char_u *)&(curwin->w_p_stl) : p->var; - case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL + case PV_UL: + return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL ? (char_u *)&(curbuf->b_p_ul) : p->var; - case PV_LW: return *curbuf->b_p_lw != NUL + case PV_LW: + return *curbuf->b_p_lw != NUL ? (char_u *)&(curbuf->b_p_lw) : p->var; - case PV_MENC: return *curbuf->b_p_menc != NUL + case PV_MENC: + return *curbuf->b_p_menc != NUL ? (char_u *)&(curbuf->b_p_menc) : p->var; - case PV_FCS: return *curwin->w_p_fcs != NUL + case PV_FCS: + return *curwin->w_p_fcs != NUL ? (char_u *)&(curwin->w_p_fcs) : p->var; - case PV_LCS: return *curwin->w_p_lcs != NUL + case PV_LCS: + return *curwin->w_p_lcs != NUL ? (char_u *)&(curwin->w_p_lcs) : p->var; - case PV_ARAB: return (char_u *)&(curwin->w_p_arab); - case PV_LIST: return (char_u *)&(curwin->w_p_list); - case PV_SPELL: return (char_u *)&(curwin->w_p_spell); - case PV_CUC: return (char_u *)&(curwin->w_p_cuc); - case PV_CUL: return (char_u *)&(curwin->w_p_cul); - case PV_CULOPT: return (char_u *)&(curwin->w_p_culopt); - case PV_CC: return (char_u *)&(curwin->w_p_cc); - case PV_DIFF: return (char_u *)&(curwin->w_p_diff); - case PV_FDC: return (char_u *)&(curwin->w_p_fdc); - case PV_FEN: return (char_u *)&(curwin->w_p_fen); - case PV_FDI: return (char_u *)&(curwin->w_p_fdi); - case PV_FDL: return (char_u *)&(curwin->w_p_fdl); - case PV_FDM: return (char_u *)&(curwin->w_p_fdm); - case PV_FML: return (char_u *)&(curwin->w_p_fml); - case PV_FDN: return (char_u *)&(curwin->w_p_fdn); - case PV_FDE: return (char_u *)&(curwin->w_p_fde); - case PV_FDT: return (char_u *)&(curwin->w_p_fdt); - case PV_FMR: return (char_u *)&(curwin->w_p_fmr); - case PV_NU: return (char_u *)&(curwin->w_p_nu); - case PV_RNU: return (char_u *)&(curwin->w_p_rnu); - case PV_NUW: return (char_u *)&(curwin->w_p_nuw); - case PV_WFH: return (char_u *)&(curwin->w_p_wfh); - case PV_WFW: return (char_u *)&(curwin->w_p_wfw); - case PV_PVW: return (char_u *)&(curwin->w_p_pvw); - case PV_RL: return (char_u *)&(curwin->w_p_rl); - case PV_RLC: return (char_u *)&(curwin->w_p_rlc); - case PV_SCROLL: return (char_u *)&(curwin->w_p_scr); - case PV_WRAP: return (char_u *)&(curwin->w_p_wrap); - case PV_LBR: return (char_u *)&(curwin->w_p_lbr); - case PV_BRI: return (char_u *)&(curwin->w_p_bri); - case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt); - case PV_SCBIND: return (char_u *)&(curwin->w_p_scb); - case PV_CRBIND: return (char_u *)&(curwin->w_p_crb); - case PV_COCU: return (char_u *)&(curwin->w_p_cocu); - case PV_COLE: return (char_u *)&(curwin->w_p_cole); - - case PV_AI: return (char_u *)&(curbuf->b_p_ai); - case PV_BIN: return (char_u *)&(curbuf->b_p_bin); - case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb); - case PV_BH: return (char_u *)&(curbuf->b_p_bh); - case PV_BT: return (char_u *)&(curbuf->b_p_bt); - case PV_BL: return (char_u *)&(curbuf->b_p_bl); - case PV_CHANNEL:return (char_u *)&(curbuf->b_p_channel); - case PV_CI: return (char_u *)&(curbuf->b_p_ci); - case PV_CIN: return (char_u *)&(curbuf->b_p_cin); - case PV_CINK: return (char_u *)&(curbuf->b_p_cink); - case PV_CINO: return (char_u *)&(curbuf->b_p_cino); - case PV_CINW: return (char_u *)&(curbuf->b_p_cinw); - case PV_COM: return (char_u *)&(curbuf->b_p_com); - case PV_CMS: return (char_u *)&(curbuf->b_p_cms); - case PV_CPT: return (char_u *)&(curbuf->b_p_cpt); + case PV_ARAB: + return (char_u *)&(curwin->w_p_arab); + case PV_LIST: + return (char_u *)&(curwin->w_p_list); + case PV_SPELL: + return (char_u *)&(curwin->w_p_spell); + case PV_CUC: + return (char_u *)&(curwin->w_p_cuc); + case PV_CUL: + return (char_u *)&(curwin->w_p_cul); + case PV_CULOPT: + return (char_u *)&(curwin->w_p_culopt); + case PV_CC: + return (char_u *)&(curwin->w_p_cc); + case PV_DIFF: + return (char_u *)&(curwin->w_p_diff); + case PV_FDC: + return (char_u *)&(curwin->w_p_fdc); + case PV_FEN: + return (char_u *)&(curwin->w_p_fen); + case PV_FDI: + return (char_u *)&(curwin->w_p_fdi); + case PV_FDL: + return (char_u *)&(curwin->w_p_fdl); + case PV_FDM: + return (char_u *)&(curwin->w_p_fdm); + case PV_FML: + return (char_u *)&(curwin->w_p_fml); + case PV_FDN: + return (char_u *)&(curwin->w_p_fdn); + case PV_FDE: + return (char_u *)&(curwin->w_p_fde); + case PV_FDT: + return (char_u *)&(curwin->w_p_fdt); + case PV_FMR: + return (char_u *)&(curwin->w_p_fmr); + case PV_NU: + return (char_u *)&(curwin->w_p_nu); + case PV_RNU: + return (char_u *)&(curwin->w_p_rnu); + case PV_NUW: + return (char_u *)&(curwin->w_p_nuw); + case PV_WFH: + return (char_u *)&(curwin->w_p_wfh); + case PV_WFW: + return (char_u *)&(curwin->w_p_wfw); + case PV_PVW: + return (char_u *)&(curwin->w_p_pvw); + case PV_RL: + return (char_u *)&(curwin->w_p_rl); + case PV_RLC: + return (char_u *)&(curwin->w_p_rlc); + case PV_SCROLL: + return (char_u *)&(curwin->w_p_scr); + case PV_WRAP: + return (char_u *)&(curwin->w_p_wrap); + case PV_LBR: + return (char_u *)&(curwin->w_p_lbr); + case PV_BRI: + return (char_u *)&(curwin->w_p_bri); + case PV_BRIOPT: + return (char_u *)&(curwin->w_p_briopt); + case PV_SCBIND: + return (char_u *)&(curwin->w_p_scb); + case PV_CRBIND: + return (char_u *)&(curwin->w_p_crb); + case PV_COCU: + return (char_u *)&(curwin->w_p_cocu); + case PV_COLE: + return (char_u *)&(curwin->w_p_cole); + + case PV_AI: + return (char_u *)&(curbuf->b_p_ai); + case PV_BIN: + return (char_u *)&(curbuf->b_p_bin); + case PV_BOMB: + return (char_u *)&(curbuf->b_p_bomb); + case PV_BH: + return (char_u *)&(curbuf->b_p_bh); + case PV_BT: + return (char_u *)&(curbuf->b_p_bt); + case PV_BL: + return (char_u *)&(curbuf->b_p_bl); + case PV_CHANNEL: + return (char_u *)&(curbuf->b_p_channel); + case PV_CI: + return (char_u *)&(curbuf->b_p_ci); + case PV_CIN: + return (char_u *)&(curbuf->b_p_cin); + case PV_CINK: + return (char_u *)&(curbuf->b_p_cink); + case PV_CINO: + return (char_u *)&(curbuf->b_p_cino); + case PV_CINW: + return (char_u *)&(curbuf->b_p_cinw); + case PV_COM: + return (char_u *)&(curbuf->b_p_com); + case PV_CMS: + return (char_u *)&(curbuf->b_p_cms); + case PV_CPT: + return (char_u *)&(curbuf->b_p_cpt); # ifdef BACKSLASH_IN_FILENAME - case PV_CSL: return (char_u *)&(curbuf->b_p_csl); + case PV_CSL: + return (char_u *)&(curbuf->b_p_csl); # endif - case PV_CFU: return (char_u *)&(curbuf->b_p_cfu); - case PV_OFU: return (char_u *)&(curbuf->b_p_ofu); - case PV_EOL: return (char_u *)&(curbuf->b_p_eol); - case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol); - case PV_ET: return (char_u *)&(curbuf->b_p_et); - case PV_FENC: return (char_u *)&(curbuf->b_p_fenc); - case PV_FF: return (char_u *)&(curbuf->b_p_ff); - case PV_FT: return (char_u *)&(curbuf->b_p_ft); - case PV_FO: return (char_u *)&(curbuf->b_p_fo); - case PV_FLP: return (char_u *)&(curbuf->b_p_flp); - case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert); - case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch); - case PV_INF: return (char_u *)&(curbuf->b_p_inf); - case PV_ISK: return (char_u *)&(curbuf->b_p_isk); - case PV_INEX: return (char_u *)&(curbuf->b_p_inex); - case PV_INDE: return (char_u *)&(curbuf->b_p_inde); - case PV_INDK: return (char_u *)&(curbuf->b_p_indk); - case PV_FEX: return (char_u *)&(curbuf->b_p_fex); - case PV_LISP: return (char_u *)&(curbuf->b_p_lisp); - case PV_ML: return (char_u *)&(curbuf->b_p_ml); - case PV_MPS: return (char_u *)&(curbuf->b_p_mps); - case PV_MA: return (char_u *)&(curbuf->b_p_ma); - case PV_MOD: return (char_u *)&(curbuf->b_changed); - case PV_NF: return (char_u *)&(curbuf->b_p_nf); - case PV_PI: return (char_u *)&(curbuf->b_p_pi); - case PV_QE: return (char_u *)&(curbuf->b_p_qe); - case PV_RO: return (char_u *)&(curbuf->b_p_ro); - case PV_SCBK: return (char_u *)&(curbuf->b_p_scbk); - case PV_SI: return (char_u *)&(curbuf->b_p_si); - case PV_STS: return (char_u *)&(curbuf->b_p_sts); - case PV_SUA: return (char_u *)&(curbuf->b_p_sua); - case PV_SWF: return (char_u *)&(curbuf->b_p_swf); - case PV_SMC: return (char_u *)&(curbuf->b_p_smc); - case PV_SYN: return (char_u *)&(curbuf->b_p_syn); - case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc); - case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf); - case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl); - case PV_SPO: return (char_u *)&(curwin->w_s->b_p_spo); - case PV_SW: return (char_u *)&(curbuf->b_p_sw); - case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); - case PV_TS: return (char_u *)&(curbuf->b_p_ts); - case PV_TW: return (char_u *)&(curbuf->b_p_tw); - case PV_UDF: return (char_u *)&(curbuf->b_p_udf); - case PV_WM: return (char_u *)&(curbuf->b_p_wm); - case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts); - case PV_VTS: return (char_u *)&(curbuf->b_p_vts); - case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap); - case PV_SCL: return (char_u *)&(curwin->w_p_scl); - case PV_WINHL: return (char_u *)&(curwin->w_p_winhl); - case PV_WINBL: return (char_u *)&(curwin->w_p_winbl); - default: IEMSG(_("E356: get_varp ERROR")); + case PV_CFU: + return (char_u *)&(curbuf->b_p_cfu); + case PV_OFU: + return (char_u *)&(curbuf->b_p_ofu); + case PV_EOL: + return (char_u *)&(curbuf->b_p_eol); + case PV_FIXEOL: + return (char_u *)&(curbuf->b_p_fixeol); + case PV_ET: + return (char_u *)&(curbuf->b_p_et); + case PV_FENC: + return (char_u *)&(curbuf->b_p_fenc); + case PV_FF: + return (char_u *)&(curbuf->b_p_ff); + case PV_FT: + return (char_u *)&(curbuf->b_p_ft); + case PV_FO: + return (char_u *)&(curbuf->b_p_fo); + case PV_FLP: + return (char_u *)&(curbuf->b_p_flp); + case PV_IMI: + return (char_u *)&(curbuf->b_p_iminsert); + case PV_IMS: + return (char_u *)&(curbuf->b_p_imsearch); + case PV_INF: + return (char_u *)&(curbuf->b_p_inf); + case PV_ISK: + return (char_u *)&(curbuf->b_p_isk); + case PV_INEX: + return (char_u *)&(curbuf->b_p_inex); + case PV_INDE: + return (char_u *)&(curbuf->b_p_inde); + case PV_INDK: + return (char_u *)&(curbuf->b_p_indk); + case PV_FEX: + return (char_u *)&(curbuf->b_p_fex); + case PV_LISP: + return (char_u *)&(curbuf->b_p_lisp); + case PV_ML: + return (char_u *)&(curbuf->b_p_ml); + case PV_MPS: + return (char_u *)&(curbuf->b_p_mps); + case PV_MA: + return (char_u *)&(curbuf->b_p_ma); + case PV_MOD: + return (char_u *)&(curbuf->b_changed); + case PV_NF: + return (char_u *)&(curbuf->b_p_nf); + case PV_PI: + return (char_u *)&(curbuf->b_p_pi); + case PV_QE: + return (char_u *)&(curbuf->b_p_qe); + case PV_RO: + return (char_u *)&(curbuf->b_p_ro); + case PV_SCBK: + return (char_u *)&(curbuf->b_p_scbk); + case PV_SI: + return (char_u *)&(curbuf->b_p_si); + case PV_STS: + return (char_u *)&(curbuf->b_p_sts); + case PV_SUA: + return (char_u *)&(curbuf->b_p_sua); + case PV_SWF: + return (char_u *)&(curbuf->b_p_swf); + case PV_SMC: + return (char_u *)&(curbuf->b_p_smc); + case PV_SYN: + return (char_u *)&(curbuf->b_p_syn); + case PV_SPC: + return (char_u *)&(curwin->w_s->b_p_spc); + case PV_SPF: + return (char_u *)&(curwin->w_s->b_p_spf); + case PV_SPL: + return (char_u *)&(curwin->w_s->b_p_spl); + case PV_SPO: + return (char_u *)&(curwin->w_s->b_p_spo); + case PV_SW: + return (char_u *)&(curbuf->b_p_sw); + case PV_TFU: + return (char_u *)&(curbuf->b_p_tfu); + case PV_TS: + return (char_u *)&(curbuf->b_p_ts); + case PV_TW: + return (char_u *)&(curbuf->b_p_tw); + case PV_UDF: + return (char_u *)&(curbuf->b_p_udf); + case PV_WM: + return (char_u *)&(curbuf->b_p_wm); + case PV_VSTS: + return (char_u *)&(curbuf->b_p_vsts); + case PV_VTS: + return (char_u *)&(curbuf->b_p_vts); + case PV_KMAP: + return (char_u *)&(curbuf->b_p_keymap); + case PV_SCL: + return (char_u *)&(curwin->w_p_scl); + case PV_WINHL: + return (char_u *)&(curwin->w_p_winhl); + case PV_WINBL: + return (char_u *)&(curwin->w_p_winbl); + default: + IEMSG(_("E356: get_varp ERROR")); } // always return a valid pointer to avoid a crash! return (char_u *)&(curbuf->b_p_wm); @@ -5963,7 +6092,7 @@ void didset_window_options(win_T *wp) void buf_copy_options(buf_T *buf, int flags) { int should_copy = true; - char_u *save_p_isk = NULL; // init for GCC + char_u *save_p_isk = NULL; // init for GCC int dont_do_help; int did_isk = false; @@ -6008,22 +6137,18 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_ro = false; // don't copy readonly buf->b_p_fenc = vim_strsave(p_fenc); switch (*p_ffs) { - case 'm': { - buf->b_p_ff = vim_strsave((char_u *)FF_MAC); - break; - } - case 'd': { - buf->b_p_ff = vim_strsave((char_u *)FF_DOS); - break; - } - case 'u': { - buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); - break; - } - default: { - buf->b_p_ff = vim_strsave(p_ff); - break; - } + case 'm': + buf->b_p_ff = vim_strsave((char_u *)FF_MAC); + break; + case 'd': + buf->b_p_ff = vim_strsave((char_u *)FF_DOS); + break; + case 'u': + buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); + break; + default: + buf->b_p_ff = vim_strsave(p_ff); + break; } buf->b_p_bh = empty_option; buf->b_p_bt = empty_option; @@ -6204,21 +6329,17 @@ void set_imsearch_global(void) } static int expand_option_idx = -1; -static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL}; +static char_u expand_option_name[5] = { 't', '_', NUL, NUL, NUL }; static int expand_option_flags = 0; -void -set_context_in_set_cmd( - expand_T *xp, - char_u *arg, - int opt_flags // OPT_GLOBAL and/or OPT_LOCAL -) +/// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL +void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags) { char_u nextchar; uint32_t flags = 0; // init for GCC int opt_idx = 0; // init for GCC - char_u *p; - char_u *s; + char_u *p; + char_u *s; int is_term_option = false; int key; @@ -6342,15 +6463,14 @@ set_context_in_set_cmd( || p == (char_u *)&p_pp || p == (char_u *)&p_rtp || p == (char_u *)&p_cdpath - || p == (char_u *)&p_vdir - ) { + || p == (char_u *)&p_vdir) { xp->xp_context = EXPAND_DIRECTORIES; if (p == (char_u *)&p_path - || p == (char_u *)&p_cdpath - ) + || p == (char_u *)&p_cdpath) { xp->xp_backslash = XP_BS_THREE; - else + } else { xp->xp_backslash = XP_BS_ONE; + } } else if (p == (char_u *)&p_ft) { xp->xp_context = EXPAND_FILETYPE; } else { @@ -6396,7 +6516,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u *** int num_normal = 0; // Nr of matching non-term-code settings int match; int count = 0; - char_u *str; + char_u *str; int loop; static char *(names[]) = { "all" }; int ic = regmatch->rm_ic; // remember the ignore-case flag @@ -6440,8 +6560,9 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u *** if (match) { if (loop == 0) { num_normal++; - } else + } else { (*file)[count++] = vim_strsave(str); + } } } @@ -6503,13 +6624,11 @@ void ExpandOldSetting(int *num_file, char_u ***file) /// Get the value for the numeric or string option///opp in a nice format into /// NameBuff[]. Must not be called with a hidden option! -static void -option_value2string( - vimoption_T *opp, - int opt_flags // OPT_GLOBAL and/or OPT_LOCAL -) +/// +/// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL +static void option_value2string(vimoption_T *opp, int opt_flags) { - char_u *varp; + char_u *varp; varp = get_varp_scope(opp, opt_flags); @@ -6532,7 +6651,7 @@ option_value2string( NameBuff[0] = NUL; } else if (opp->flags & P_EXPAND) { home_replace(NULL, varp, NameBuff, MAXPATHL, false); - // Translate 'pastetoggle' into special key names. + // Translate 'pastetoggle' into special key names. } else if ((char_u **)opp->var == &p_pt) { str2specialbuf((const char *)p_pt, (char *)NameBuff, MAXPATHL); } else { @@ -6645,8 +6764,8 @@ static void langmap_init(void) /// changed at any time! static void langmap_set(void) { - char_u *p; - char_u *p2; + char_u *p; + char_u *p2; int from, to; ga_clear(&langmap_mapga); // clear the previous map first @@ -6692,7 +6811,7 @@ static void langmap_set(void) } if (to == NUL) { EMSG2(_("E357: 'langmap': Matching character missing for %s"), - transchar(from)); + transchar(from)); return; } @@ -6711,9 +6830,8 @@ static void langmap_set(void) p = p2; if (p[0] != NUL) { if (p[0] != ',') { - EMSG2(_( - "E358: 'langmap': Extra characters after semicolon: %s"), - p); + EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), + p); return; } p++; @@ -6938,7 +7056,7 @@ void reset_option_was_set(const char *name) /// fill_breakat_flags() -- called when 'breakat' changes value. static void fill_breakat_flags(void) { - char_u *p; + char_u *p; int i; for (i = 0; i < 256; i++) { @@ -6997,13 +7115,10 @@ static int fill_culopt_flags(char_u *val, win_T *wp) /// Check an option that can be a range of string values. /// -/// Return OK for correct value, FAIL otherwise. -/// Empty is always OK. -static int check_opt_strings( - char_u *val, - char **values, - int list // when true: accept a list of values -) +/// @param list when true: accept a list of values +/// +/// @return OK for correct value, FAIL otherwise. Empty is always OK. +static int check_opt_strings(char_u *val, char **values, int list) { return opt_strings_flags(val, values, NULL, list); } @@ -7011,14 +7126,12 @@ static int check_opt_strings( /// Handle an option that can be a range of string values. /// Set a flag in "*flagp" for each string present. /// -/// Return OK for correct value, FAIL otherwise. -/// Empty is always OK. -static int opt_strings_flags( - char_u *val, // new value - char **values, // array of valid string values - unsigned *flagp, - bool list // when true: accept a list of values -) +/// @param val new value +/// @param values array of valid string values +/// @param list when true: accept a list of values +/// +/// @return OK for correct value, FAIL otherwise. Empty is always OK. +static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, bool list) { unsigned int new_flags = 0; @@ -7049,7 +7162,7 @@ static int opt_strings_flags( static int check_opt_wim(void) { char_u new_wim_flags[4]; - char_u *p; + char_u *p; int i; int idx = 0; @@ -7106,10 +7219,14 @@ bool can_bs(int what) return false; } switch (*p_bs) { - case '3': return true; - case '2': return what != BS_NOSTOP; - case '1': return what != BS_START; - case '0': return false; + case '3': + return true; + case '2': + return what != BS_NOSTOP; + case '1': + return what != BS_START; + case '0': + return false; } return vim_strchr(p_bs, what) != NULL; } @@ -7306,11 +7423,7 @@ colnr_T tabstop_start(colnr_T col, long ts, long *vts) // Find the number of tabs and spaces necessary to get from one column // to another. -void tabstop_fromto(colnr_T start_col, - colnr_T end_col, - long ts_arg, - long *vts, - int *ntabs, +void tabstop_fromto(colnr_T start_col, colnr_T end_col, long ts_arg, long *vts, int *ntabs, int *nspcs) { int spaces = end_col - start_col; @@ -7486,18 +7599,13 @@ static bool briopt_check(win_T *wp) while (*p != NUL) { if (STRNCMP(p, "shift:", 6) == 0 - && ((p[6] == '-' && ascii_isdigit(p[7])) || ascii_isdigit(p[6]))) - { + && ((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])) - { + } 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) - { + } else if (STRNCMP(p, "sbr", 3) == 0) { p += 3; bri_sbr = true; } else if (STRNCMP(p, "list:", 5) == 0) { @@ -7590,8 +7698,10 @@ int get_fileformat_force(const buf_T *buf, const exarg_T *eap) int default_fileformat(void) { switch (*p_ffs) { - case 'm': return EOL_MAC; - case 'd': return EOL_DOS; + case 'm': + return EOL_MAC; + case 'd': + return EOL_DOS; } return EOL_UNIX; } @@ -7607,15 +7717,15 @@ void set_fileformat(int eol_style, int opt_flags) char *p = NULL; switch (eol_style) { - case EOL_UNIX: - p = FF_UNIX; - break; - case EOL_MAC: - p = FF_MAC; - break; - case EOL_DOS: - p = FF_DOS; - break; + case EOL_UNIX: + p = FF_UNIX; + break; + case EOL_MAC: + p = FF_MAC; + break; + case EOL_DOS: + p = FF_DOS; + break; } // p is NULL if "eol_style" is EOL_UNKNOWN. @@ -7653,11 +7763,10 @@ char_u *skip_to_option_part(const char_u *p) /// @param[in] sep_chars chars that separate the option parts /// /// @return length of `*option` -size_t copy_option_part(char_u **option, char_u *buf, size_t maxlen, - char *sep_chars) +size_t copy_option_part(char_u **option, char_u *buf, size_t maxlen, char *sep_chars) { size_t len = 0; - char_u *p = *option; + char_u *p = *option; // skip '.' at start of option part, for 'suffixes' if (*p == '.') { @@ -7820,52 +7929,52 @@ Dictionary get_all_vimoptions(void) static Dictionary vimoption2dict(vimoption_T *opt) { - Dictionary dict = ARRAY_DICT_INIT; + Dictionary dict = ARRAY_DICT_INIT; - PUT(dict, "name", CSTR_TO_OBJ(opt->fullname)); - PUT(dict, "shortname", CSTR_TO_OBJ(opt->shortname)); + PUT(dict, "name", CSTR_TO_OBJ(opt->fullname)); + PUT(dict, "shortname", CSTR_TO_OBJ(opt->shortname)); - const char *scope; - if (opt->indir & PV_BUF) { - scope = "buf"; - } else if (opt->indir & PV_WIN) { - scope = "win"; - } else { - scope = "global"; - } - - PUT(dict, "scope", CSTR_TO_OBJ(scope)); - - // welcome to the jungle - PUT(dict, "global_local", BOOL(opt->indir & PV_BOTH)); - PUT(dict, "commalist", BOOL(opt->flags & P_COMMA)); - PUT(dict, "flaglist", BOOL(opt->flags & P_FLAGLIST)); - - PUT(dict, "was_set", BOOL(opt->flags & P_WAS_SET)); - - PUT(dict, "last_set_sid", INTEGER_OBJ(opt->last_set.script_ctx.sc_sid)); - PUT(dict, "last_set_linenr", INTEGER_OBJ(opt->last_set.script_ctx.sc_lnum)); - PUT(dict, "last_set_chan", INTEGER_OBJ((int64_t)opt->last_set.channel_id)); - - const char *type; - Object def; - // TODO(bfredl): do you even nocp? - char_u *def_val = opt->def_val; - if (opt->flags & P_STRING) { - type = "string"; - def = CSTR_TO_OBJ(def_val ? (char *)def_val : ""); - } else if (opt->flags & P_NUM) { - type = "number"; - def = INTEGER_OBJ((Integer)(intptr_t)def_val); - } else if (opt->flags & P_BOOL) { - type = "boolean"; - def = BOOL((intptr_t)def_val); - } else { - type = ""; def = NIL; - } - PUT(dict, "type", CSTR_TO_OBJ(type)); - PUT(dict, "default", def); - PUT(dict, "allows_duplicates", BOOL(!(opt->flags & P_NODUP))); + const char *scope; + if (opt->indir & PV_BUF) { + scope = "buf"; + } else if (opt->indir & PV_WIN) { + scope = "win"; + } else { + scope = "global"; + } + + PUT(dict, "scope", CSTR_TO_OBJ(scope)); + + // welcome to the jungle + PUT(dict, "global_local", BOOL(opt->indir & PV_BOTH)); + PUT(dict, "commalist", BOOL(opt->flags & P_COMMA)); + PUT(dict, "flaglist", BOOL(opt->flags & P_FLAGLIST)); + + PUT(dict, "was_set", BOOL(opt->flags & P_WAS_SET)); + + PUT(dict, "last_set_sid", INTEGER_OBJ(opt->last_set.script_ctx.sc_sid)); + PUT(dict, "last_set_linenr", INTEGER_OBJ(opt->last_set.script_ctx.sc_lnum)); + PUT(dict, "last_set_chan", INTEGER_OBJ((int64_t)opt->last_set.channel_id)); + + const char *type; + Object def; + // TODO(bfredl): do you even nocp? + char_u *def_val = opt->def_val; + if (opt->flags & P_STRING) { + type = "string"; + def = CSTR_TO_OBJ(def_val ? (char *)def_val : ""); + } else if (opt->flags & P_NUM) { + type = "number"; + def = INTEGER_OBJ((Integer)(intptr_t)def_val); + } else if (opt->flags & P_BOOL) { + type = "boolean"; + def = BOOL((intptr_t)def_val); + } else { + type = ""; def = NIL; + } + PUT(dict, "type", CSTR_TO_OBJ(type)); + PUT(dict, "default", def); + PUT(dict, "allows_duplicates", BOOL(!(opt->flags & P_NODUP))); - return dict; + return dict; } |