diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-09-16 21:06:21 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-09-16 21:06:21 +0200 |
commit | dac1347b4d9c1a1aef6aa73fdea08a9d1077d6ea (patch) | |
tree | 4c9124f2de51bedb339bc5cdb47a3086c0e92af9 | |
parent | 8aeec40207b5adcd3a155277dc4f29189343b963 (diff) | |
download | vim-git-dac1347b4d9c1a1aef6aa73fdea08a9d1077d6ea.tar.gz |
patch 8.1.2045: the option.c file is too bigv8.1.2045
Problem: The option.c file is too big.
Solution: Split off the code dealing with strings. (Yegappan Lakshmanan,
closes #4937)
-rw-r--r-- | Filelist | 2 | ||||
-rw-r--r-- | src/Make_cyg_ming.mak | 1 | ||||
-rw-r--r-- | src/Make_morph.mak | 1 | ||||
-rw-r--r-- | src/Make_mvc.mak | 4 | ||||
-rw-r--r-- | src/Make_vms.mms | 12 | ||||
-rw-r--r-- | src/Makefile | 10 | ||||
-rw-r--r-- | src/README.md | 1 | ||||
-rw-r--r-- | src/ops.c | 52 | ||||
-rw-r--r-- | src/option.c | 2599 | ||||
-rw-r--r-- | src/option.h | 203 | ||||
-rw-r--r-- | src/optiondefs.h | 197 | ||||
-rw-r--r-- | src/optionstr.c | 2491 | ||||
-rw-r--r-- | src/os_unix.c | 8 | ||||
-rw-r--r-- | src/proto.h | 1 | ||||
-rw-r--r-- | src/proto/option.pro | 31 | ||||
-rw-r--r-- | src/proto/optionstr.pro | 14 | ||||
-rw-r--r-- | src/version.c | 2 |
17 files changed, 2882 insertions, 2747 deletions
@@ -88,6 +88,7 @@ SRC_ALL = \ src/option.c \ src/option.h \ src/optiondefs.h \ + src/optionstr.c \ src/popupmnu.c \ src/popupwin.c \ src/profiler.c \ @@ -231,6 +232,7 @@ SRC_ALL = \ src/proto/normal.pro \ src/proto/ops.pro \ src/proto/option.pro \ + src/proto/optionstr.pro \ src/proto/popupmnu.pro \ src/proto/popupwin.pro \ src/proto/profiler.pro \ diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak index f9c5367e9..9d8abf8be 100644 --- a/src/Make_cyg_ming.mak +++ b/src/Make_cyg_ming.mak @@ -757,6 +757,7 @@ OBJ = \ $(OUTDIR)/normal.o \ $(OUTDIR)/ops.o \ $(OUTDIR)/option.o \ + $(OUTDIR)/optionstr.o \ $(OUTDIR)/os_mswin.o \ $(OUTDIR)/os_win32.o \ $(OUTDIR)/pathdef.o \ diff --git a/src/Make_morph.mak b/src/Make_morph.mak index 3f896da5b..87b7e45cc 100644 --- a/src/Make_morph.mak +++ b/src/Make_morph.mak @@ -76,6 +76,7 @@ SRC = arabic.c \ normal.c \ ops.c \ option.c \ + optionstr.c \ os_amiga.c \ popupmnu.c \ profiler.c \ diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak index 7aa7ef83d..1205a6e23 100644 --- a/src/Make_mvc.mak +++ b/src/Make_mvc.mak @@ -764,6 +764,7 @@ OBJ = \ $(OUTDIR)\normal.obj \ $(OUTDIR)\ops.obj \ $(OUTDIR)\option.obj \ + $(OUTDIR)\optionstr.obj \ $(OUTDIR)\os_mswin.obj \ $(OUTDIR)\os_win32.obj \ $(OUTDIR)\pathdef.obj \ @@ -1606,6 +1607,8 @@ $(OUTDIR)/normal.obj: $(OUTDIR) normal.c $(INCL) $(OUTDIR)/option.obj: $(OUTDIR) option.c $(INCL) optiondefs.h +$(OUTDIR)/optionstr.obj: $(OUTDIR) optionstr.c $(INCL) + $(OUTDIR)/ops.obj: $(OUTDIR) ops.c $(INCL) $(OUTDIR)/os_mswin.obj: $(OUTDIR) os_mswin.c $(INCL) @@ -1816,6 +1819,7 @@ proto.h: \ proto/normal.pro \ proto/ops.pro \ proto/option.pro \ + proto/optionstr.pro \ proto/os_mswin.pro \ proto/winclip.pro \ proto/os_win32.pro \ diff --git a/src/Make_vms.mms b/src/Make_vms.mms index c3b795820..42adcb8d1 100644 --- a/src/Make_vms.mms +++ b/src/Make_vms.mms @@ -317,8 +317,8 @@ SRC = arabic.c arglist.c autocmd.c beval.c blob.c blowfish.c buffer.c \ getchar.c hardcopy.c hashtab.c highlight.c \ indent.c insexpand.c json.c list.c main.c map.c mark.c menu.c mbyte.c \ memfile.c memline.c message.c misc1.c misc2.c move.c normal.c ops.c \ - option.c popupmnu.c popupwin.c profiler.c quickfix.c regexp.c \ - scriptfile.c \ + option.c optionstr.c popupmnu.c popupwin.c profiler.c quickfix.c \ + regexp.c scriptfile.c \ search.c session.c sha256.c sign.c spell.c spellfile.c syntax.c tag.c \ term.c termlib.c testing.c textprop.c ui.c undo.c usercmd.c \ userfunc.c version.c viminfo.c screen.c window.c os_unix.c os_vms.c \ @@ -337,8 +337,8 @@ OBJ = arabic.obj arglist.obj autocmd.obj beval.obj blob.obj blowfish.obj \ highlight.obj indent.obj insexpand.obj json.obj list.obj main.obj \ map.obj mark.obj menu.obj memfile.obj memline.obj message.obj \ misc1.obj misc2.obj move.obj mbyte.obj normal.obj ops.obj option.obj \ - popupmnu.obj popupwin.obj profiler.obj quickfix.obj regexp.obj \ - scriptfile.obj \ + optionstr.obj popupmnu.obj popupwin.obj profiler.obj quickfix.obj \ + regexp.obj scriptfile.obj \ search.obj session.obj sha256.obj sign.obj spell.obj spellfile.obj \ syntax.obj tag.obj term.obj termlib.obj testing.obj textprop.obj \ ui.obj undo.obj usercmd.obj userfunc.obj screen.obj version.obj \ @@ -715,6 +715,10 @@ option.obj : option.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ globals.h optiondefs.h +optionstr.obj : optionstr.c vim.h [.auto]config.h feature.h os_unix.h \ + ascii.h keymap.h term.h macros.h structs.h regexp.h \ + gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ + globals.h os_unix.obj : os_unix.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ diff --git a/src/Makefile b/src/Makefile index 0efd88f70..c89fdb135 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1632,6 +1632,7 @@ BASIC_SRC = \ normal.c \ ops.c \ option.c \ + optionstr.c \ os_unix.c \ auto/pathdef.c \ popupmnu.c \ @@ -1762,6 +1763,7 @@ OBJ_COMMON = \ objects/normal.o \ objects/ops.o \ objects/option.o \ + objects/optionstr.o \ objects/os_unix.o \ objects/pathdef.o \ objects/popupmnu.o \ @@ -1917,6 +1919,7 @@ PRO_AUTO = \ normal.pro \ ops.pro \ option.pro \ + optionstr.pro \ os_mac_conv.pro \ os_unix.pro \ popupmnu.pro \ @@ -3287,6 +3290,9 @@ objects/ops.o: ops.c objects/option.o: option.c optiondefs.h $(CCC_NF) $(LUA_CFLAGS) $(PERL_CFLAGS) $(PYTHON_CFLAGS) $(PYTHON3_CFLAGS) $(RUBY_CFLAGS) $(TCL_CFLAGS) $(ALL_CFLAGS) -o $@ option.c +objects/optionstr.o: optionstr.c + $(CCC_NF) $(LUA_CFLAGS) $(PERL_CFLAGS) $(PYTHON_CFLAGS) $(PYTHON3_CFLAGS) $(RUBY_CFLAGS) $(TCL_CFLAGS) $(ALL_CFLAGS) -o $@ optionstr.c + objects/os_beos.o: os_beos.c $(CCC) -o $@ os_beos.c @@ -3763,6 +3769,10 @@ objects/option.o: option.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto.h globals.h optiondefs.h +objects/optionstr.o: optionstr.c vim.h protodef.h auto/config.h feature.h os_unix.h \ + auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ + proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ + proto.h globals.h objects/os_unix.o: os_unix.c vim.h protodef.h auto/config.h feature.h os_unix.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ diff --git a/src/README.md b/src/README.md index 6ba83910e..f4f9df1f4 100644 --- a/src/README.md +++ b/src/README.md @@ -54,6 +54,7 @@ menu.c | menus message.c | (error) messages ops.c | handling operators ("d", "y", "p") option.c | options +optionstr.c | handling string options popupmnu.c | popup menu popupwin.c | popup window profiler.c | vim script profiler @@ -315,14 +315,14 @@ shift_line( { int count; int i, j; - int p_sw = (int)get_sw_value_indent(curbuf); + int sw_val = (int)get_sw_value_indent(curbuf); count = get_indent(); /* get current indent */ if (round) /* round off indent */ { - i = count / p_sw; /* number of p_sw rounded down */ - j = count % p_sw; /* extra spaces */ + i = count / sw_val; /* number of p_sw rounded down */ + j = count % sw_val; /* extra spaces */ if (j && left) /* first remove extra spaces */ --amount; if (left) @@ -333,18 +333,18 @@ shift_line( } else i += amount; - count = i * p_sw; + count = i * sw_val; } else /* original vi indent */ { if (left) { - count -= p_sw * amount; + count -= sw_val * amount; if (count < 0) count = 0; } else - count += p_sw * amount; + count += sw_val * amount; } /* Set new indent */ @@ -366,11 +366,8 @@ shift_block(oparg_T *oap, int amount) int total; char_u *newp, *oldp; int oldcol = curwin->w_cursor.col; - int p_sw = (int)get_sw_value_indent(curbuf); -#ifdef FEAT_VARTABS - int *p_vts = curbuf->b_p_vts_array; -#endif - int p_ts = (int)curbuf->b_p_ts; + int sw_val = (int)get_sw_value_indent(curbuf); + int ts_val = (int)curbuf->b_p_ts; struct block_def bd; int incr; colnr_T ws_vcol; @@ -388,8 +385,8 @@ shift_block(oparg_T *oap, int amount) return; /* total is number of screen columns to be inserted/removed */ - total = (int)((unsigned)amount * (unsigned)p_sw); - if ((total / p_sw) != amount) + total = (int)((unsigned)amount * (unsigned)sw_val); + if ((total / sw_val) != amount) return; /* multiplication overflow */ oldp = ml_get_curline(); @@ -431,14 +428,15 @@ shift_block(oparg_T *oap, int amount) * non-ws char in the block. */ #ifdef FEAT_VARTABS if (!curbuf->b_p_et) - tabstop_fromto(ws_vcol, ws_vcol + total, p_ts, p_vts, &i, &j); + tabstop_fromto(ws_vcol, ws_vcol + total, + ts_val, curbuf->b_p_vts_array, &i, &j); else j = total; #else if (!curbuf->b_p_et) - i = ((ws_vcol % p_ts) + total) / p_ts; /* number of tabs */ + i = ((ws_vcol % ts_val) + total) / ts_val; /* number of tabs */ if (i) - j = ((ws_vcol % p_ts) + total) % p_ts; /* number of spp */ + j = ((ws_vcol % ts_val) + total) % ts_val; /* number of spp */ else j = total; #endif @@ -567,7 +565,7 @@ block_insert( int b_insert, struct block_def *bdp) { - int p_ts; + int ts_val; int count = 0; /* extra spaces to replace a cut TAB */ int spaces = 0; /* non-zero if cutting a TAB */ colnr_T offset; /* pointer along new line */ @@ -589,20 +587,20 @@ block_insert( if (b_insert) { - p_ts = bdp->start_char_vcols; + ts_val = bdp->start_char_vcols; spaces = bdp->startspaces; if (spaces != 0) - count = p_ts - 1; /* we're cutting a TAB */ + count = ts_val - 1; /* we're cutting a TAB */ offset = bdp->textcol; } else /* append */ { - p_ts = bdp->end_char_vcols; + ts_val = bdp->end_char_vcols; if (!bdp->is_short) /* spaces = padding after block */ { - spaces = (bdp->endspaces ? p_ts - bdp->endspaces : 0); + spaces = (bdp->endspaces ? ts_val - bdp->endspaces : 0); if (spaces != 0) - count = p_ts - 1; /* we're cutting a TAB */ + count = ts_val - 1; /* we're cutting a TAB */ offset = bdp->textcol + bdp->textlen - (spaces != 0); } else /* spaces = padding to block edge */ @@ -651,7 +649,7 @@ block_insert( if (spaces && !bdp->is_short) { /* insert post-padding */ - vim_memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces)); + vim_memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces)); /* We're splitting a TAB, don't copy it. */ oldp++; /* We allowed for that TAB, remember this now */ @@ -5591,10 +5589,10 @@ do_addsub( pos_T startpos; pos_T endpos; - dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ - dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */ - dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */ - doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ + dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX" + dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal" + dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); // "Bin" + doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); // "alPha" curwin->w_cursor = *pos; ptr = ml_get(pos->lnum); diff --git a/src/option.c b/src/option.c index 99e046f3f..1ffa11d12 100644 --- a/src/option.c +++ b/src/option.c @@ -38,31 +38,16 @@ static void set_options_default(int opt_flags); static void set_string_default_esc(char *name, char_u *val, int escape); static char_u *term_bg_default(void); -static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked); static char_u *option_expand(int opt_idx, char_u *val); static void didset_options(void); static void didset_options2(void); -static void check_string_option(char_u **pp); #if defined(FEAT_EVAL) || defined(PROTO) static long_u *insecure_flag(int opt_idx, int opt_flags); #else # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags) #endif -static void set_string_option_global(int opt_idx, char_u **varp); -static char *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char *errbuf, int opt_flags, int *value_checked); -#ifdef FEAT_STL_OPT -static char *check_stl_option(char_u *s); -#endif -#ifdef FEAT_CLIPBOARD -static char *check_clipboard_option(void); -#endif -#ifdef FEAT_EVAL -static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx); -#endif static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags); static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags); -static void check_redraw(long_u flags); -static int findoption(char_u *); static int find_key_option(char_u *arg_arg, int has_lt); static void showoptions(int all, int opt_flags); static int optval_default(struct vimoption *, char_u *varp, int compatible); @@ -70,7 +55,7 @@ static void showoneopt(struct vimoption *, int opt_flags); static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags); static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep); static int put_setbool(FILE *fd, char *cmd, char *name, int value); -static int istermoption(struct vimoption *); +static int istermoption(struct vimoption *p); static char_u *get_varp_scope(struct vimoption *p, int opt_flags); static char_u *get_varp(struct vimoption *); static void check_win_options(win_T *win); @@ -79,18 +64,6 @@ static void check_winopt(winopt_T *wop); static int wc_use_keyname(char_u *varp, long *wcp); static void paste_option_changed(void); static void compatible_set(void); -#ifdef FEAT_LINEBREAK -static void fill_breakat_flags(void); -#endif -static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list); -static int check_opt_strings(char_u *val, char **values, int); -static int check_opt_wim(void); -#ifdef FEAT_LINEBREAK -static int briopt_check(win_T *wp); -#endif -#ifdef FEAT_SYN_HL -static int fill_culopt_flags(char_u *val, win_T *wp); -#endif /* * Initialize the options, first part. @@ -356,7 +329,7 @@ set_init_1(int clean_arg) * Don't set the P_ALLOCED flag, because we don't want to free the * default. */ - for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) + for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) { if ((options[opt_idx].flags & P_GETTEXT) && options[opt_idx].var != NULL) @@ -622,7 +595,7 @@ set_options_default( win_T *wp; tabpage_T *tp; - for (i = 0; !istermoption(&options[i]); i++) + for (i = 0; !istermoption_idx(i); i++) if (!(options[i].flags & P_NODEFAULT) && (opt_flags == 0 || (options[i].var != (char_u *)&p_enc @@ -704,7 +677,7 @@ set_local_options_default(win_T *wp, int do_buffer) curbuf = curwin->w_buffer; block_autocmds(); - for (i = 0; !istermoption(&options[i]); i++) + for (i = 0; !istermoption_idx(i); i++) { struct vimoption *p = &(options[i]); char_u *varp = get_varp_scope(p, OPT_LOCAL); @@ -730,7 +703,7 @@ free_all_options(void) { int i; - for (i = 0; !istermoption(&options[i]); i++) + for (i = 0; !istermoption_idx(i); i++) { if (options[i].indir == PV_NONE) { @@ -1133,66 +1106,6 @@ set_title_defaults(void) } #endif -#if defined(FEAT_EVAL) -/* - * Trigger the OptionSet autocommand. - * "opt_idx" is the index of the option being set. - * "opt_flags" can be OPT_LOCAL etc. - * "oldval" the old value - * "oldval_l" the old local value (only non-NULL if global and local value - * are set) - * "oldval_g" the old global value (only non-NULL if global and local value - * are set) - * "newval" the new value - */ - static void -trigger_optionsset_string( - int opt_idx, - int opt_flags, - char_u *oldval, - char_u *oldval_l, - char_u *oldval_g, - char_u *newval) -{ - // Don't do this recursively. - if (oldval != NULL && newval != NULL - && *get_vim_var_str(VV_OPTION_TYPE) == NUL) - { - char_u buf_type[7]; - - sprintf((char *)buf_type, "%s", - (opt_flags & OPT_LOCAL) ? "local" : "global"); - set_vim_var_string(VV_OPTION_OLD, oldval, -1); - set_vim_var_string(VV_OPTION_NEW, newval, -1); - set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); - if (opt_flags & OPT_LOCAL) - { - set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1); - set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); - } - if (opt_flags & OPT_GLOBAL) - { - set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1); - set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1); - } - if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) - { - set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1); - set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1); - set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1); - } - if (opt_flags & OPT_MODELINE) - { - set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1); - set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); - } - apply_autocmds(EVENT_OPTIONSET, - (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL); - reset_v_option_vars(); - } -} -#endif - /* * Parse 'arg' for option settings. * @@ -2199,7 +2112,7 @@ theend: * 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 + void did_set_option( int opt_idx, int opt_flags, // possibly with OPT_MODELINE @@ -2225,16 +2138,6 @@ did_set_option( *p = *p & ~P_INSECURE; } - static char * -illegal_char(char *errbuf, int c) -{ - if (errbuf == NULL) - return ""; - sprintf((char *)errbuf, _("E539: Illegal character <%s>"), - (char *)transchar(c)); - return errbuf; -} - /* * Convert a key name or string into a key value. * Used for 'wildchar' and 'cedit' options. @@ -2252,12 +2155,12 @@ string_to_key(char_u *arg, int multi_byte) return *arg; } -#ifdef FEAT_CMDWIN +#if defined(FEAT_CMDWIN) || defined(PROTO) /* * Check value of 'cedit' and set cedit_key. * Returns NULL if value is OK, error message otherwise. */ - static char * + char * check_cedit(void) { int n; @@ -2282,7 +2185,7 @@ check_cedit(void) * When switching the title or icon off, call mch_restore_title() to get * the old value back. */ - static void + void did_set_title(void) { if (starting != NO_SCREEN @@ -2411,34 +2314,14 @@ didset_options(void) /* initialize the table for 'iskeyword' et.al. */ (void)init_chartab(); - (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE); - (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE); - (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE); -#ifdef FEAT_SESSION - (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE); - (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE); -#endif -#ifdef FEAT_FOLDING - (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE); -#endif - (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE); - (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE); - (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE); -#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS)) - (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE); -#endif + didset_string_options(); + #ifdef FEAT_SPELL (void)spell_check_msm(); (void)spell_check_sps(); (void)compile_cap_prog(curwin->w_s); (void)did_set_spell_option(TRUE); #endif -#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) - (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE); -#endif -#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) - (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE); -#endif #ifdef FEAT_CMDWIN /* set cedit_key */ (void)check_cedit(); @@ -2497,138 +2380,6 @@ check_options(void) } /* - * Check string options in a buffer for NULL value. - */ - void -check_buf_options(buf_T *buf) -{ - check_string_option(&buf->b_p_bh); - check_string_option(&buf->b_p_bt); - check_string_option(&buf->b_p_fenc); - check_string_option(&buf->b_p_ff); -#ifdef FEAT_FIND_ID - check_string_option(&buf->b_p_def); - check_string_option(&buf->b_p_inc); -# ifdef FEAT_EVAL - check_string_option(&buf->b_p_inex); -# endif -#endif -#if defined(FEAT_CINDENT) && defined(FEAT_EVAL) - check_string_option(&buf->b_p_inde); - check_string_option(&buf->b_p_indk); -#endif -#if defined(FEAT_BEVAL) && defined(FEAT_EVAL) - check_string_option(&buf->b_p_bexpr); -#endif -#if defined(FEAT_CRYPT) - check_string_option(&buf->b_p_cm); -#endif - check_string_option(&buf->b_p_fp); -#if defined(FEAT_EVAL) - check_string_option(&buf->b_p_fex); -#endif -#ifdef FEAT_CRYPT - check_string_option(&buf->b_p_key); -#endif - check_string_option(&buf->b_p_kp); - check_string_option(&buf->b_p_mps); - check_string_option(&buf->b_p_fo); - check_string_option(&buf->b_p_flp); - check_string_option(&buf->b_p_isk); -#ifdef FEAT_COMMENTS - check_string_option(&buf->b_p_com); -#endif -#ifdef FEAT_FOLDING - check_string_option(&buf->b_p_cms); -#endif - check_string_option(&buf->b_p_nf); -#ifdef FEAT_TEXTOBJ - check_string_option(&buf->b_p_qe); -#endif -#ifdef FEAT_SYN_HL - check_string_option(&buf->b_p_syn); - check_string_option(&buf->b_s.b_syn_isk); -#endif -#ifdef FEAT_SPELL - check_string_option(&buf->b_s.b_p_spc); - check_string_option(&buf->b_s.b_p_spf); - check_string_option(&buf->b_s.b_p_spl); -#endif -#ifdef FEAT_SEARCHPATH - check_string_option(&buf->b_p_sua); -#endif -#ifdef FEAT_CINDENT - check_string_option(&buf->b_p_cink); - check_string_option(&buf->b_p_cino); - parse_cino(buf); -#endif - check_string_option(&buf->b_p_ft); -#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) - check_string_option(&buf->b_p_cinw); -#endif - check_string_option(&buf->b_p_cpt); -#ifdef FEAT_COMPL_FUNC - check_string_option(&buf->b_p_cfu); - check_string_option(&buf->b_p_ofu); -#endif -#ifdef FEAT_EVAL - check_string_option(&buf->b_p_tfu); -#endif -#ifdef FEAT_KEYMAP - check_string_option(&buf->b_p_keymap); -#endif -#ifdef FEAT_QUICKFIX - check_string_option(&buf->b_p_gp); - check_string_option(&buf->b_p_mp); - check_string_option(&buf->b_p_efm); -#endif - check_string_option(&buf->b_p_ep); - check_string_option(&buf->b_p_path); - check_string_option(&buf->b_p_tags); - check_string_option(&buf->b_p_tc); - check_string_option(&buf->b_p_dict); - check_string_option(&buf->b_p_tsr); -#ifdef FEAT_LISP - check_string_option(&buf->b_p_lw); -#endif - check_string_option(&buf->b_p_bkc); - check_string_option(&buf->b_p_menc); -#ifdef FEAT_VARTABS - check_string_option(&buf->b_p_vsts); - check_string_option(&buf->b_p_vts); -#endif -} - -/* - * Free the string allocated for an option. - * Checks for the string being empty_option. This may happen if we're out of - * memory, vim_strsave() returned NULL, which was replaced by empty_option by - * check_options(). - * Does NOT check for P_ALLOCED flag! - */ - void -free_string_option(char_u *p) -{ - if (p != empty_option) - vim_free(p); -} - - void -clear_string_option(char_u **pp) -{ - if (*pp != empty_option) - vim_free(*pp); - *pp = empty_option; -} - - static void -check_string_option(char_u **pp) -{ - if (*pp == NULL) - *pp = empty_option; -} - -/* * Return the option index found by a pointer into term_strings[]. * Return -1 if not found. */ @@ -2714,11 +2465,11 @@ insecure_flag(int opt_idx, int opt_flags) } #endif -#ifdef FEAT_TITLE +#if defined(FEAT_TITLE) || defined(PROTO) /* * Redraw the window title and/or tab page text later. */ -static void redraw_titles(void) +void redraw_titles(void) { need_maketitle = TRUE; redraw_tabline = TRUE; @@ -2726,237 +2477,6 @@ static void redraw_titles(void) #endif /* - * 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( - char_u *name, - int opt_idx, - char_u *val, - int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */ - int set_sid UNUSED) -{ - char_u *s; - char_u **varp; - int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; - int idx = opt_idx; - - if (idx == -1) /* use name */ - { - idx = findoption(name); - if (idx < 0) /* not found (should not happen) */ - { - semsg(_(e_intern2), "set_string_option_direct()"); - siemsg(_("For option %s"), name); - return; - } - } - - if (options[idx].var == NULL) /* can't set hidden option */ - return; - - s = vim_strsave(val); - if (s != NULL) - { - varp = (char_u **)get_varp_scope(&(options[idx]), - both ? OPT_LOCAL : opt_flags); - if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED)) - free_string_option(*varp); - *varp = s; - - /* For buffer/window local option may also set the global value. */ - if (both) - set_string_option_global(idx, varp); - - options[idx].flags |= P_ALLOCED; - - /* When setting both values of a global option with a local value, - * make the local value empty, so that the global value is used. */ - if (((int)options[idx].indir & PV_BOTH) && both) - { - free_string_option(*varp); - *varp = empty_option; - } -# ifdef FEAT_EVAL - if (set_sid != SID_NONE) - { - sctx_T script_ctx; - - if (set_sid == 0) - script_ctx = current_sctx; - else - { - script_ctx.sc_sid = set_sid; - script_ctx.sc_seq = 0; - script_ctx.sc_lnum = 0; - script_ctx.sc_version = 1; - } - set_option_sctx_idx(idx, opt_flags, script_ctx); - } -# endif - } -} - -/* - * Like set_string_option_direct(), but for a window-local option in "wp". - * Blocks autocommands to avoid the old curwin becoming invalid. - */ - void -set_string_option_direct_in_win( - win_T *wp, - char_u *name, - int opt_idx, - char_u *val, - int opt_flags, - int set_sid) -{ - win_T *save_curwin = curwin; - - block_autocmds(); - curwin = wp; - curbuf = curwin->w_buffer; - set_string_option_direct(name, opt_idx, val, opt_flags, set_sid); - curwin = save_curwin; - curbuf = curwin->w_buffer; - unblock_autocmds(); -} - -/* - * Like set_string_option_direct(), but for a buffer-local option in "buf". - * Blocks autocommands to avoid the old curbuf becoming invalid. - */ - void -set_string_option_direct_in_buf( - buf_T *buf, - char_u *name, - int opt_idx, - char_u *val, - int opt_flags, - int set_sid) -{ - buf_T *save_curbuf = curbuf; - - block_autocmds(); - curbuf = buf; - curwin->w_buffer = curbuf; - set_string_option_direct(name, opt_idx, val, opt_flags, set_sid); - curbuf = save_curbuf; - curwin->w_buffer = curbuf; - unblock_autocmds(); -} - -/* - * 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 */ -{ - char_u **p, *s; - - /* the global value is always allocated */ - if (options[opt_idx].var == VAR_WIN) - p = (char_u **)GLOBAL_WO(varp); - else - p = (char_u **)options[opt_idx].var; - if (options[opt_idx].indir != PV_NONE - && p != varp - && (s = vim_strsave(*varp)) != NULL) - { - free_string_option(*p); - *p = s; - } -} - -/* - * Set a string option to a new value, and handle the effects. - * - * Returns NULL on success or error message on error. - */ - static char * -set_string_option( - int opt_idx, - char_u *value, - int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */ -{ - char_u *s; - char_u **varp; - char_u *oldval; -#if defined(FEAT_EVAL) - char_u *oldval_l = NULL; - char_u *oldval_g = NULL; - char_u *saved_oldval = NULL; - char_u *saved_oldval_l = NULL; - char_u *saved_oldval_g = NULL; - char_u *saved_newval = NULL; -#endif - char *r = NULL; - int value_checked = FALSE; - - if (options[opt_idx].var == NULL) /* don't set hidden option */ - return NULL; - - s = vim_strsave(value); - if (s != NULL) - { - varp = (char_u **)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); - oldval = *varp; -#if defined(FEAT_EVAL) - if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) - { - oldval_l = *(char_u **)get_varp_scope(&(options[opt_idx]), - OPT_LOCAL); - oldval_g = *(char_u **)get_varp_scope(&(options[opt_idx]), - OPT_GLOBAL); - } -#endif - *varp = s; - -#if defined(FEAT_EVAL) - if (!starting -# ifdef FEAT_CRYPT - && options[opt_idx].indir != PV_KEY -# endif - ) - { - if (oldval_l != NULL) - saved_oldval_l = vim_strsave(oldval_l); - if (oldval_g != NULL) - saved_oldval_g = vim_strsave(oldval_g); - saved_oldval = vim_strsave(oldval); - saved_newval = vim_strsave(s); - } -#endif - if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, - opt_flags, &value_checked)) == NULL) - did_set_option(opt_idx, opt_flags, TRUE, value_checked); - -#if defined(FEAT_EVAL) - /* call autocommand after handling side effects */ - if (r == NULL) - trigger_optionsset_string(opt_idx, opt_flags, - saved_oldval, saved_oldval_l, - saved_oldval_g, saved_newval); - vim_free(saved_oldval); - vim_free(saved_oldval_l); - vim_free(saved_oldval_g); - vim_free(saved_newval); -#endif - } - return r; -} - -/* * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII * characters or characters in "allowed". */ @@ -2971,1898 +2491,12 @@ valid_name(char_u *val, char *allowed) return TRUE; } -/* - * Return TRUE if "val" is a valid 'filetype' name. - * Also used for 'syntax' and 'keymap'. - */ - static int -valid_filetype(char_u *val) -{ - return valid_name(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 * -did_set_string_option( - int opt_idx, // index in options[] table - char_u **varp, // pointer to the option variable - int new_value_alloced, // new value was allocated - char_u *oldval, // previous value of the option - char *errbuf, // buffer for errors, or NULL - int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL - int *value_checked) // value was checked to be save, no - // need to set P_INSECURE -{ - char *errmsg = NULL; - char_u *s, *p; - int did_chartab = FALSE; - char_u **gvarp; - long_u free_oldval = (options[opt_idx].flags & P_ALLOCED); -#ifdef FEAT_GUI - /* set when changing an option that only requires a redraw in the GUI */ - int redraw_gui_only = FALSE; -#endif - int value_changed = FALSE; -#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) - int did_swaptcap = FALSE; -#endif - - /* Get the global option to compare with, otherwise we would have to check - * two values for all local options. */ - gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL); - - /* Disallow changing some options from secure mode */ - if ((secure -#ifdef HAVE_SANDBOX - || sandbox != 0 -#endif - ) && (options[opt_idx].flags & P_SECURE)) - errmsg = e_secure; - - // Check for a "normal" directory or file name in some options. Disallow a - // path separator (slash and/or backslash), wildcards and characters that - // are often illegal in a file name. Be more permissive if "secure" is off. - else if (((options[opt_idx].flags & P_NFNAME) - && vim_strpbrk(*varp, (char_u *)(secure - ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL) - || ((options[opt_idx].flags & P_NDNAME) - && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL)) - errmsg = e_invarg; - - /* 'term' */ - else if (varp == &T_NAME) - { - if (T_NAME[0] == NUL) - errmsg = N_("E529: Cannot set 'term' to empty string"); -#ifdef FEAT_GUI - if (gui.in_use) - errmsg = N_("E530: Cannot change term in GUI"); - else if (term_is_gui(T_NAME)) - errmsg = N_("E531: Use \":gui\" to start the GUI"); -#endif - else if (set_termname(T_NAME) == FAIL) - errmsg = N_("E522: Not found in termcap"); - else - { - /* Screen colors may have changed. */ - redraw_later_clear(); - - /* Both 'term' and 'ttytype' point to T_NAME, only set the - * P_ALLOCED flag on 'term'. */ - opt_idx = findoption((char_u *)"term"); - free_oldval = (options[opt_idx].flags & P_ALLOCED); - } - } - - /* 'backupcopy' */ - else if (gvarp == &p_bkc) - { - char_u *bkc = p_bkc; - unsigned int *flags = &bkc_flags; - - if (opt_flags & OPT_LOCAL) - { - bkc = curbuf->b_p_bkc; - flags = &curbuf->b_bkc_flags; - } - - if ((opt_flags & OPT_LOCAL) && *bkc == NUL) - /* make the local value empty: use the global value */ - *flags = 0; - else - { - if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK) - errmsg = e_invarg; - if ((((int)*flags & BKC_AUTO) != 0) - + (((int)*flags & BKC_YES) != 0) - + (((int)*flags & BKC_NO) != 0) != 1) - { - /* Must have exactly one of "auto", "yes" and "no". */ - (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE); - errmsg = e_invarg; - } - } - } - - /* 'backupext' and 'patchmode' */ - else if (varp == &p_bex || varp == &p_pm) - { - if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex, - *p_pm == '.' ? p_pm + 1 : p_pm) == 0) - errmsg = N_("E589: 'backupext' and 'patchmode' are equal"); - } -#ifdef FEAT_LINEBREAK - /* 'breakindentopt' */ - else if (varp == &curwin->w_p_briopt) - { - if (briopt_check(curwin) == FAIL) - errmsg = e_invarg; - } -#endif - - /* - * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[] - * If the new option is invalid, use old value. 'lisp' option: refill - * g_chartab[] for '-' char - */ - else if ( varp == &p_isi - || varp == &(curbuf->b_p_isk) - || varp == &p_isp - || varp == &p_isf) - { - if (init_chartab() == FAIL) - { - did_chartab = TRUE; /* need to restore it below */ - errmsg = e_invarg; /* error in value */ - } - } - - /* 'helpfile' */ - else if (varp == &p_hf) - { - /* May compute new values for $VIM and $VIMRUNTIME */ - if (didset_vim) - { - vim_setenv((char_u *)"VIM", (char_u *)""); - didset_vim = FALSE; - } - if (didset_vimruntime) - { - vim_setenv((char_u *)"VIMRUNTIME", (char_u *)""); - didset_vimruntime = FALSE; - } - } - -#ifdef FEAT_SYN_HL - /* 'cursorlineopt' */ - else if (varp == &curwin->w_p_culopt - || gvarp == &curwin->w_allbuf_opt.wo_culopt) - { - if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK) - errmsg = e_invarg; - } - - /* 'colorcolumn' */ - else if (varp == &curwin->w_p_cc) - errmsg = check_colorcolumn(curwin); -#endif - -#ifdef FEAT_MULTI_LANG - /* 'helplang' */ - else if (varp == &p_hlg) - { - /* Check for "", "ab", "ab,cd", etc. */ - for (s = p_hlg; *s != NUL; s += 3) - { - if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL)) - { - errmsg = e_invarg; - break; - } - if (s[2] == NUL) - break; - } - } -#endif - - /* 'highlight' */ - else if (varp == &p_hl) - { - if (highlight_changed() == FAIL) - errmsg = e_invarg; /* invalid flags */ - } - - /* 'nrformats' */ - else if (gvarp == &p_nf) - { - if (check_opt_strings(*varp, p_nf_values, TRUE) != OK) - errmsg = e_invarg; - } - -#ifdef FEAT_SESSION - /* 'sessionoptions' */ - else if (varp == &p_ssop) - { - if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK) - errmsg = e_invarg; - if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR)) - { - /* Don't allow both "sesdir" and "curdir". */ - (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE); - errmsg = e_invarg; - } - } - /* 'viewoptions' */ - else if (varp == &p_vop) - { - if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK) - errmsg = e_invarg; - } -#endif - - /* 'scrollopt' */ - else if (varp == &p_sbo) - { - if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK) - errmsg = e_invarg; - } - - /* 'ambiwidth' */ - else if (varp == &p_ambw || varp == &p_emoji) - { - if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) - errmsg = e_invarg; - else if (set_chars_option(&p_lcs) != NULL) - errmsg = _("E834: Conflicts with value of 'listchars'"); - else if (set_chars_option(&p_fcs) != NULL) - errmsg = _("E835: Conflicts with value of 'fillchars'"); - } - - /* 'background' */ - else if (varp == &p_bg) - { - if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK) - { -#ifdef FEAT_EVAL - int dark = (*p_bg == 'd'); -#endif - - init_highlight(FALSE, FALSE); - -#ifdef FEAT_EVAL - if (dark != (*p_bg == 'd') - && get_var_value((char_u *)"g:colors_name") != NULL) - { - /* The color scheme must have set 'background' back to another - * value, that's not what we want here. Disable the color - * scheme and set the colors again. */ - do_unlet((char_u *)"g:colors_name", TRUE); - free_string_option(p_bg); - p_bg = vim_strsave((char_u *)(dark ? "dark" : "light")); - check_string_option(&p_bg); - init_highlight(FALSE, FALSE); - } -#endif - } - else - errmsg = e_invarg; - } - - /* 'wildmode' */ - else if (varp == &p_wim) - { - if (check_opt_wim() == FAIL) - errmsg = e_invarg; - } - - /* 'wildoptions' */ - else if (varp == &p_wop) - { - if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK) - errmsg = e_invarg; - } - -#ifdef FEAT_WAK - /* 'winaltkeys' */ - else if (varp == &p_wak) - { - if (*p_wak == NUL - || check_opt_strings(p_wak, p_wak_values, FALSE) != OK) - errmsg = e_invarg; -# ifdef FEAT_MENU -# ifdef FEAT_GUI_MOTIF - else if (gui.in_use) - gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); -# else -# ifdef FEAT_GUI_GTK - else if (gui.in_use) - gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); -# endif -# endif -# endif - } -#endif - - /* 'eventignore' */ - else if (varp == &p_ei) - { - if (check_ei() == FAIL) - errmsg = e_invarg; - } - - /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */ - else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc - || gvarp == &p_menc) - { - if (gvarp == &p_fenc) - { - if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL) - errmsg = e_modifiable; - else if (vim_strchr(*varp, ',') != NULL) - /* No comma allowed in 'fileencoding'; catches confusing it - * with 'fileencodings'. */ - errmsg = e_invarg; - else - { -#ifdef FEAT_TITLE - /* May show a "+" in the title now. */ - redraw_titles(); -#endif - /* Add 'fileencoding' to the swap file. */ - ml_setflags(curbuf); - } - } - if (errmsg == NULL) - { - /* canonize the value, so that STRCMP() can be used on it */ - p = enc_canonize(*varp); - if (p != NULL) - { - vim_free(*varp); - *varp = p; - } - if (varp == &p_enc) - { - errmsg = mb_init(); -#ifdef FEAT_TITLE - redraw_titles(); -#endif - } - } - -#if defined(FEAT_GUI_GTK) - if (errmsg == NULL && varp == &p_tenc && gui.in_use) - { - /* GTK+ 2 uses only a single encoding, and that is UTF-8. */ - if (STRCMP(p_tenc, "utf-8") != 0) - errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI"); - } -#endif - - if (errmsg == NULL) - { -#ifdef FEAT_KEYMAP - /* When 'keymap' is used and 'encoding' changes, reload the keymap - * (with another encoding). */ - if (varp == &p_enc && *curbuf->b_p_keymap != NUL) - (void)keymap_init(); -#endif - - /* When 'termencoding' is not empty and 'encoding' changes or when - * 'termencoding' changes, need to setup for keyboard input and - * display output conversion. */ - if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc)) - { - if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL - || convert_setup(&output_conv, p_enc, p_tenc) == FAIL) - { - semsg(_("E950: Cannot convert between %s and %s"), - p_tenc, p_enc); - errmsg = e_invarg; - } - } - -#if defined(MSWIN) - /* $HOME may have characters in active code page. */ - if (varp == &p_enc) - init_homedir(); -#endif - } - } - -#if defined(FEAT_POSTSCRIPT) - else if (varp == &p_penc) - { - /* Canonize printencoding if VIM standard one */ - p = enc_canonize(p_penc); - if (p != NULL) - { - vim_free(p_penc); - p_penc = p; - } - else - { - /* Ensure lower case and '-' for '_' */ - for (s = p_penc; *s != NUL; s++) - { - if (*s == '_') - *s = '-'; - else - *s = TOLOWER_ASC(*s); - } - } - } -#endif - -#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) - else if (varp == &p_imak) - { - if (!im_xim_isvalid_imactivate()) - errmsg = e_invarg; - } -#endif - -#ifdef FEAT_KEYMAP - else if (varp == &curbuf->b_p_keymap) - { - if (!valid_filetype(*varp)) - errmsg = e_invarg; - else - { - int secure_save = secure; - - // Reset the secure flag, since the value of 'keymap' has - // been checked to be safe. - secure = 0; - - // load or unload key mapping tables - errmsg = keymap_init(); - - secure = secure_save; - - // Since we check the value, there is no need to set P_INSECURE, - // even when the value comes from a modeline. - *value_checked = TRUE; - } - - if (errmsg == NULL) - { - if (*curbuf->b_p_keymap != NUL) - { - /* Installed a new keymap, switch on using it. */ - curbuf->b_p_iminsert = B_IMODE_LMAP; - if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT) - curbuf->b_p_imsearch = B_IMODE_LMAP; - } - else - { - /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */ - if (curbuf->b_p_iminsert == B_IMODE_LMAP) - curbuf->b_p_iminsert = B_IMODE_NONE; - if (curbuf->b_p_imsearch == B_IMODE_LMAP) - curbuf->b_p_imsearch = B_IMODE_USE_INSERT; - } - if ((opt_flags & OPT_LOCAL) == 0) - { - set_iminsert_global(); - set_imsearch_global(); - } - status_redraw_curbuf(); - } - } -#endif - - /* 'fileformat' */ - else if (gvarp == &p_ff) - { - if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL)) - errmsg = e_modifiable; - else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK) - errmsg = e_invarg; - else - { - /* may also change 'textmode' */ - if (get_fileformat(curbuf) == EOL_DOS) - curbuf->b_p_tx = TRUE; - else - curbuf->b_p_tx = FALSE; -#ifdef FEAT_TITLE - redraw_titles(); -#endif - /* update flag in swap file */ - ml_setflags(curbuf); - /* Redraw needed when switching to/from "mac": a CR in the text - * will be displayed differently. */ - if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm') - redraw_curbuf_later(NOT_VALID); - } - } - - /* 'fileformats' */ - else if (varp == &p_ffs) - { - if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK) - errmsg = e_invarg; - else - { - /* also change 'textauto' */ - if (*p_ffs == NUL) - p_ta = FALSE; - else - p_ta = TRUE; - } - } - -#if defined(FEAT_CRYPT) - /* 'cryptkey' */ - else if (gvarp == &p_key) - { - // Make sure the ":set" command doesn't show the new value in the - // history. - remove_key_from_history(); - - if (STRCMP(curbuf->b_p_key, oldval) != 0) - /* Need to update the swapfile. */ - ml_set_crypt_key(curbuf, oldval, - *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm); - } - - else if (gvarp == &p_cm) - { - if (opt_flags & OPT_LOCAL) - p = curbuf->b_p_cm; - else - p = p_cm; - if (check_opt_strings(p, p_cm_values, TRUE) != OK) - errmsg = e_invarg; - else if (crypt_self_test() == FAIL) - errmsg = e_invarg; - else - { - /* When setting the global value to empty, make it "zip". */ - if (*p_cm == NUL) - { - if (new_value_alloced) - free_string_option(p_cm); - p_cm = vim_strsave((char_u *)"zip"); - new_value_alloced = TRUE; - } - /* When using ":set cm=name" the local value is going to be empty. - * Do that here, otherwise the crypt functions will still use the - * local value. */ - if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) - { - free_string_option(curbuf->b_p_cm); - curbuf->b_p_cm = empty_option; - } - - /* Need to update the swapfile when the effective method changed. - * Set "s" to the effective old value, "p" to the effective new - * method and compare. */ - if ((opt_flags & OPT_LOCAL) && *oldval == NUL) - s = p_cm; /* was previously using the global value */ - else - s = oldval; - if (*curbuf->b_p_cm == NUL) - p = p_cm; /* is now using the global value */ - else - p = curbuf->b_p_cm; - if (STRCMP(s, p) != 0) - ml_set_crypt_key(curbuf, curbuf->b_p_key, s); - - /* If the global value changes need to update the swapfile for all - * buffers using that value. */ - if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0) - { - buf_T *buf; - - FOR_ALL_BUFFERS(buf) - if (buf != curbuf && *buf->b_p_cm == NUL) - ml_set_crypt_key(buf, buf->b_p_key, oldval); - } - } - } -#endif - - /* 'matchpairs' */ - else if (gvarp == &p_mps) - { - if (has_mbyte) - { - for (p = *varp; *p != NUL; ++p) - { - int x2 = -1; - int x3 = -1; - - if (*p != NUL) - p += mb_ptr2len(p); - if (*p != NUL) - x2 = *p++; - if (*p != NUL) - { - x3 = mb_ptr2char(p); - p += mb_ptr2len(p); - } - if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) - { - errmsg = e_invarg; - break; - } - if (*p == NUL) - break; - } - } - else - { - /* Check for "x:y,x:y" */ - for (p = *varp; *p != NUL; p += 4) - { - if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ',')) - { - errmsg = e_invarg; - break; - } - if (p[3] == NUL) - break; - } - } - } - -#ifdef FEAT_COMMENTS - /* 'comments' */ - else if (gvarp == &p_com) - { - for (s = *varp; *s; ) - { - while (*s && *s != ':') - { - if (vim_strchr((char_u *)COM_ALL, *s) == NULL - && !VIM_ISDIGIT(*s) && *s != '-') - { - errmsg = illegal_char(errbuf, *s); - break; - } - ++s; - } - if (*s++ == NUL) - errmsg = N_("E524: Missing colon"); - else if (*s == ',' || *s == NUL) - errmsg = N_("E525: Zero length string"); - if (errmsg != NULL) - break; - while (*s && *s != ',') - { - if (*s == '\\' && s[1] != NUL) - ++s; - ++s; - } - s = skip_to_option_part(s); - } - } -#endif - - /* 'listchars' */ - else if (varp == &p_lcs) - { - errmsg = set_chars_option(varp); - } - - /* 'fillchars' */ - else if (varp == &p_fcs) - { - errmsg = set_chars_option(varp); - } - -#ifdef FEAT_CMDWIN - /* 'cedit' */ - else if (varp == &p_cedit) - { - errmsg = check_cedit(); - } -#endif - - /* 'verbosefile' */ - else if (varp == &p_vfile) - { - verbose_stop(); - if (*p_vfile != NUL && verbose_open() == FAIL) - errmsg = e_invarg; - } - -#ifdef FEAT_VIMINFO - /* 'viminfo' */ - else if (varp == &p_viminfo) - { - for (s = p_viminfo; *s;) - { - /* Check it's a valid character */ - if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL) - { - errmsg = illegal_char(errbuf, *s); - break; - } - if (*s == 'n') /* name is always last one */ - break; - else if (*s == 'r') /* skip until next ',' */ - { - while (*++s && *s != ',') - ; - } - else if (*s == '%') - { - /* optional number */ - while (vim_isdigit(*++s)) - ; - } - else if (*s == '!' || *s == 'h' || *s == 'c') - ++s; /* no extra chars */ - else /* must have a number */ - { - while (vim_isdigit(*++s)) - ; - - if (!VIM_ISDIGIT(*(s - 1))) - { - if (errbuf != NULL) - { - sprintf(errbuf, _("E526: Missing number after <%s>"), - transchar_byte(*(s - 1))); - errmsg = errbuf; - } - else - errmsg = ""; - break; - } - } - if (*s == ',') - ++s; - else if (*s) - { - if (errbuf != NULL) - errmsg = N_("E527: Missing comma"); - else - errmsg = ""; - break; - } - } - if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0) - errmsg = N_("E528: Must specify a ' value"); - } -#endif /* FEAT_VIMINFO */ - - /* terminal options */ - else if (istermoption(&options[opt_idx]) && full_screen) - { - /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */ - if (varp == &T_CCO) - { - int colors = atoi((char *)T_CCO); - - /* Only reinitialize colors if t_Co value has really changed to - * avoid expensive reload of colorscheme if t_Co is set to the - * same value multiple times. */ - if (colors != t_colors) - { - t_colors = colors; - if (t_colors <= 1) - { - if (new_value_alloced) - vim_free(T_CCO); - T_CCO = empty_option; - } -#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) - if (is_term_win32()) - { - swap_tcap(); - did_swaptcap = TRUE; - } -#endif - /* We now have a different color setup, initialize it again. */ - init_highlight(TRUE, FALSE); - } - } - ttest(FALSE); - if (varp == &T_ME) - { - out_str(T_ME); - redraw_later(CLEAR); -#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) - /* Since t_me has been set, this probably means that the user - * wants to use this as default colors. Need to reset default - * background/foreground colors. */ -# ifdef VIMDLL - if (!gui.in_use && !gui.starting) -# endif - mch_set_normal_colors(); -#endif - } - if (varp == &T_BE && termcap_active) - { - if (*T_BE == NUL) - /* When clearing t_BE we assume the user no longer wants - * bracketed paste, thus disable it by writing t_BD. */ - out_str(T_BD); - else - out_str(T_BE); - } - } - -#ifdef FEAT_LINEBREAK - /* 'showbreak' */ - else if (varp == &p_sbr) - { - for (s = p_sbr; *s; ) - { - if (ptr2cells(s) != 1) - errmsg = N_("E595: contains unprintable or wide character"); - MB_PTR_ADV(s); - } - } -#endif - -#ifdef FEAT_GUI - /* 'guifont' */ - else if (varp == &p_guifont) - { - if (gui.in_use) - { - p = p_guifont; -# if defined(FEAT_GUI_GTK) - /* - * Put up a font dialog and let the user select a new value. - * If this is cancelled go back to the old value but don't - * give an error message. - */ - if (STRCMP(p, "*") == 0) - { - p = gui_mch_font_dialog(oldval); - - if (new_value_alloced) - free_string_option(p_guifont); - - p_guifont = (p != NULL) ? p : vim_strsave(oldval); - new_value_alloced = TRUE; - } -# endif - if (p != NULL && gui_init_font(p_guifont, FALSE) != OK) - { -# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON) - if (STRCMP(p_guifont, "*") == 0) - { - /* Dialog was cancelled: Keep the old value without giving - * an error message. */ - if (new_value_alloced) - free_string_option(p_guifont); - p_guifont = vim_strsave(oldval); - new_value_alloced = TRUE; - } - else -# endif - errmsg = N_("E596: Invalid font(s)"); - } - } - redraw_gui_only = TRUE; - } -# ifdef FEAT_XFONTSET - else if (varp == &p_guifontset) - { - if (STRCMP(p_guifontset, "*") == 0) - errmsg = N_("E597: can't select fontset"); - else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK) - errmsg = N_("E598: Invalid fontset"); - redraw_gui_only = TRUE; - } -# endif - else if (varp == &p_guifontwide) - { - if (STRCMP(p_guifontwide, "*") == 0) - errmsg = N_("E533: can't select wide font"); - else if (gui_get_wide_font() == FAIL) - errmsg = N_("E534: Invalid wide font"); - redraw_gui_only = TRUE; - } -#endif - -#ifdef CURSOR_SHAPE - /* 'guicursor' */ - else if (varp == &p_guicursor) - errmsg = parse_shape_opt(SHAPE_CURSOR); -#endif - -#ifdef FEAT_MOUSESHAPE - /* 'mouseshape' */ - else if (varp == &p_mouseshape) - { - errmsg = parse_shape_opt(SHAPE_MOUSE); - update_mouseshape(-1); - } -#endif - -#ifdef FEAT_PRINTER - else if (varp == &p_popt) - errmsg = parse_printoptions(); -# if defined(FEAT_POSTSCRIPT) - else if (varp == &p_pmfn) - errmsg = parse_printmbfont(); -# endif -#endif - -#ifdef FEAT_LANGMAP - /* 'langmap' */ - else if (varp == &p_langmap) - langmap_set(); -#endif - -#ifdef FEAT_LINEBREAK - /* 'breakat' */ - else if (varp == &p_breakat) - fill_breakat_flags(); -#endif - -#ifdef FEAT_TITLE - /* 'titlestring' and 'iconstring' */ - else if (varp == &p_titlestring || varp == &p_iconstring) - { -# ifdef FEAT_STL_OPT - int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON; - - /* NULL => statusline syntax */ - if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL) - stl_syntax |= flagval; - else - stl_syntax &= ~flagval; -# endif - did_set_title(); - } -#endif - -#ifdef FEAT_GUI - /* 'guioptions' */ - else if (varp == &p_go) - { - gui_init_which_components(oldval); - redraw_gui_only = TRUE; - } -#endif - -#if defined(FEAT_GUI_TABLINE) - /* 'guitablabel' */ - else if (varp == &p_gtl) - { - redraw_tabline = TRUE; - redraw_gui_only = TRUE; - } - /* 'guitabtooltip' */ - else if (varp == &p_gtt) - { - redraw_gui_only = TRUE; - } -#endif - -#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS)) - /* 'ttymouse' */ - else if (varp == &p_ttym) - { - /* Switch the mouse off before changing the escape sequences used for - * that. */ - mch_setmouse(FALSE); - if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK) - errmsg = e_invarg; - else - check_mouse_termcode(); - if (termcap_active) - setmouse(); /* may switch it on again */ - } -#endif - - /* 'selection' */ - else if (varp == &p_sel) - { - if (*p_sel == NUL - || check_opt_strings(p_sel, p_sel_values, FALSE) != OK) - errmsg = e_invarg; - } - - /* 'selectmode' */ - else if (varp == &p_slm) - { - if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK) - errmsg = e_invarg; - } - -#ifdef FEAT_BROWSE - /* 'browsedir' */ - else if (varp == &p_bsdir) - { - if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK - && !mch_isdir(p_bsdir)) - errmsg = e_invarg; - } -#endif - - /* 'keymodel' */ - else if (varp == &p_km) - { - if (check_opt_strings(p_km, p_km_values, TRUE) != OK) - errmsg = e_invarg; - else - { - km_stopsel = (vim_strchr(p_km, 'o') != NULL); - km_startsel = (vim_strchr(p_km, 'a') != NULL); - } - } - - /* 'mousemodel' */ - else if (varp == &p_mousem) - { - if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK) - errmsg = e_invarg; -#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002) - else if (*p_mousem != *oldval) - /* Changed from "extend" to "popup" or "popup_setpos" or vv: need - * to create or delete the popup menus. */ - gui_motif_update_mousemodel(root_menu); -#endif - } - - /* 'switchbuf' */ - else if (varp == &p_swb) - { - if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK) - errmsg = e_invarg; - } - - /* 'debug' */ - else if (varp == &p_debug) - { - if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK) - errmsg = e_invarg; - } - - /* 'display' */ - else if (varp == &p_dy) - { - if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK) - errmsg = e_invarg; - else - (void)init_chartab(); - - } - - /* 'eadirection' */ - else if (varp == &p_ead) - { - if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK) - errmsg = e_invarg; - } - -#ifdef FEAT_CLIPBOARD - /* 'clipboard' */ - else if (varp == &p_cb) - errmsg = check_clipboard_option(); -#endif - -#ifdef FEAT_SPELL - /* When 'spelllang' or 'spellfile' is set and there is a window for this - * buffer in which 'spell' is set load the wordlists. */ - else if (varp == &(curwin->w_s->b_p_spl) - || varp == &(curwin->w_s->b_p_spf)) - { - int is_spellfile = varp == &(curwin->w_s->b_p_spf); - - if ((is_spellfile && !valid_spellfile(*varp)) - || (!is_spellfile && !valid_spellang(*varp))) - errmsg = e_invarg; - else - errmsg = did_set_spell_option(is_spellfile); - } - /* When 'spellcapcheck' is set compile the regexp program. */ - else if (varp == &(curwin->w_s->b_p_spc)) - { - errmsg = compile_cap_prog(curwin->w_s); - } - /* 'spellsuggest' */ - else if (varp == &p_sps) - { - if (spell_check_sps() != OK) - errmsg = e_invarg; - } - /* 'mkspellmem' */ - else if (varp == &p_msm) - { - if (spell_check_msm() != OK) - errmsg = e_invarg; - } -#endif - - /* When 'bufhidden' is set, check for valid value. */ - else if (gvarp == &p_bh) - { - if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK) - errmsg = e_invarg; - } - - /* When 'buftype' is set, check for valid value. */ - else if (gvarp == &p_bt) - { - if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK) - errmsg = e_invarg; - else - { - if (curwin->w_status_height) - { - curwin->w_redr_status = TRUE; - redraw_later(VALID); - } - curbuf->b_help = (curbuf->b_p_bt[0] == 'h'); -#ifdef FEAT_TITLE - redraw_titles(); -#endif - } - } - -#ifdef FEAT_STL_OPT - /* 'statusline' or 'rulerformat' */ - else if (gvarp == &p_stl || varp == &p_ruf) - { - int wid; - - if (varp == &p_ruf) /* reset ru_wid first */ - ru_wid = 0; - s = *varp; - if (varp == &p_ruf && *s == '%') - { - /* set ru_wid if 'ruf' starts with "%99(" */ - if (*++s == '-') /* ignore a '-' */ - s++; - wid = getdigits(&s); - if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL) - ru_wid = wid; - else - errmsg = check_stl_option(p_ruf); - } - /* check 'statusline' only if it doesn't start with "%!" */ - else if (varp == &p_ruf || s[0] != '%' || s[1] != '!') - errmsg = check_stl_option(s); - if (varp == &p_ruf && errmsg == NULL) - comp_col(); - } -#endif - - /* check if it is a valid value for 'complete' -- Acevedo */ - else if (gvarp == &p_cpt) - { - for (s = *varp; *s;) - { - while (*s == ',' || *s == ' ') - s++; - if (!*s) - break; - if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL) - { - errmsg = illegal_char(errbuf, *s); - break; - } - if (*++s != NUL && *s != ',' && *s != ' ') - { - if (s[-1] == 'k' || s[-1] == 's') - { - /* skip optional filename after 'k' and 's' */ - while (*s && *s != ',' && *s != ' ') - { - if (*s == '\\' && s[1] != NUL) - ++s; - ++s; - } - } - else - { - if (errbuf != NULL) - { - sprintf((char *)errbuf, - _("E535: Illegal character after <%c>"), - *--s); - errmsg = errbuf; - } - else - errmsg = ""; - break; - } - } - } - } - - // 'completeopt' - else if (varp == &p_cot) - { - if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK) - errmsg = e_invarg; - else - completeopt_was_set(); - } - -#ifdef BACKSLASH_IN_FILENAME - // 'completeslash' - else if (gvarp == &p_csl) - { - if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK - || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK) - errmsg = e_invarg; - } -#endif - -#ifdef FEAT_SIGNS - // 'signcolumn' - else if (varp == &curwin->w_p_scl) - { - if (check_opt_strings(*varp, p_scl_values, FALSE) != OK) - errmsg = e_invarg; - // When changing the 'signcolumn' to or from 'number', recompute the - // width of the number column if 'number' or 'relativenumber' is set. - if (((*oldval == 'n' && *(oldval + 1) == 'u') - || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u')) - && (curwin->w_p_nu || curwin->w_p_rnu)) - curwin->w_nrwidth_line_count = 0; - } -#endif - - -#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) - /* 'toolbar' */ - else if (varp == &p_toolbar) - { - if (opt_strings_flags(p_toolbar, p_toolbar_values, - &toolbar_flags, TRUE) != OK) - errmsg = e_invarg; - else - { - out_flush(); - gui_mch_show_toolbar((toolbar_flags & - (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); - } - } -#endif - -#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) - /* 'toolbariconsize': GTK+ 2 only */ - else if (varp == &p_tbis) - { - if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK) - errmsg = e_invarg; - else - { - out_flush(); - gui_mch_show_toolbar((toolbar_flags & - (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); - } - } -#endif - - /* 'pastetoggle': translate key codes like in a mapping */ - else if (varp == &p_pt) - { - if (*p_pt) - { - (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE); - if (p != NULL) - { - if (new_value_alloced) - free_string_option(p_pt); - p_pt = p; - new_value_alloced = TRUE; - } - } - } - - /* 'backspace' */ - else if (varp == &p_bs) - { - if (VIM_ISDIGIT(*p_bs)) - { - if (*p_bs > '2' || p_bs[1] != NUL) - errmsg = e_invarg; - } - else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK) - errmsg = e_invarg; - } - else if (varp == &p_bo) - { - if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK) - errmsg = e_invarg; - } - - /* 'tagcase' */ - else if (gvarp == &p_tc) - { - unsigned int *flags; - - if (opt_flags & OPT_LOCAL) - { - p = curbuf->b_p_tc; - flags = &curbuf->b_tc_flags; - } - else - { - p = p_tc; - flags = &tc_flags; - } - - if ((opt_flags & OPT_LOCAL) && *p == NUL) - /* make the local value empty: use the global value */ - *flags = 0; - else if (*p == NUL - || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK) - errmsg = e_invarg; - } - - /* 'casemap' */ - else if (varp == &p_cmp) - { - if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK) - errmsg = e_invarg; - } - -#ifdef FEAT_DIFF - /* 'diffopt' */ - else if (varp == &p_dip) - { - if (diffopt_changed() == FAIL) - errmsg = e_invarg; - } -#endif - -#ifdef FEAT_FOLDING - /* 'foldmethod' */ - else if (gvarp == &curwin->w_allbuf_opt.wo_fdm) - { - if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK - || *curwin->w_p_fdm == NUL) - errmsg = e_invarg; - else - { - foldUpdateAll(curwin); - if (foldmethodIsDiff(curwin)) - newFoldLevel(); - } - } -# ifdef FEAT_EVAL - /* 'foldexpr' */ - else if (varp == &curwin->w_p_fde) - { - if (foldmethodIsExpr(curwin)) - foldUpdateAll(curwin); - } -# endif - /* 'foldmarker' */ - else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) - { - p = vim_strchr(*varp, ','); - if (p == NULL) - errmsg = N_("E536: comma required"); - else if (p == *varp || p[1] == NUL) - errmsg = e_invarg; - else if (foldmethodIsMarker(curwin)) - foldUpdateAll(curwin); - } - /* 'commentstring' */ - else if (gvarp == &p_cms) - { - if (**varp != NUL && strstr((char *)*varp, "%s") == NULL) - errmsg = N_("E537: 'commentstring' must be empty or contain %s"); - } - /* 'foldopen' */ - else if (varp == &p_fdo) - { - if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK) - errmsg = e_invarg; - } - /* 'foldclose' */ - else if (varp == &p_fcl) - { - if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK) - errmsg = e_invarg; - } - /* 'foldignore' */ - else if (gvarp == &curwin->w_allbuf_opt.wo_fdi) - { - if (foldmethodIsIndent(curwin)) - foldUpdateAll(curwin); - } -#endif - - /* 'virtualedit' */ - else if (varp == &p_ve) - { - if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK) - errmsg = e_invarg; - else if (STRCMP(p_ve, oldval) != 0) - { - /* Recompute cursor position in case the new 've' setting - * changes something. */ - validate_virtcol(); - coladvance(curwin->w_virtcol); - } - } - -#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX) - else if (varp == &p_csqf) - { - if (p_csqf != NULL) - { - p = p_csqf; - while (*p != NUL) - { - if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL - || p[1] == NUL - || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL - || (p[2] != NUL && p[2] != ',')) - { - errmsg = e_invarg; - break; - } - else if (p[2] == NUL) - break; - else - p += 3; - } - } - } -#endif - -#ifdef FEAT_CINDENT - /* 'cinoptions' */ - else if (gvarp == &p_cino) - { - /* TODO: recognize errors */ - parse_cino(curbuf); - } -#endif - -#if defined(FEAT_RENDER_OPTIONS) - /* 'renderoptions' */ - else if (varp == &p_rop) - { - if (!gui_mch_set_rendering_options(p_rop)) - errmsg = e_invarg; - } -#endif - - else if (gvarp == &p_ft) - { - if (!valid_filetype(*varp)) - errmsg = e_invarg; - else - { - value_changed = STRCMP(oldval, *varp) != 0; - - // Since we check the value, there is no need to set P_INSECURE, - // even when the value comes from a modeline. - *value_checked = TRUE; - } - } - -#ifdef FEAT_SYN_HL - else if (gvarp == &p_syn) - { - if (!valid_filetype(*varp)) - errmsg = e_invarg; - else - { - value_changed = STRCMP(oldval, *varp) != 0; - - // Since we check the value, there is no need to set P_INSECURE, - // even when the value comes from a modeline. - *value_checked = TRUE; - } - } -#endif - -#ifdef FEAT_TERMINAL - // 'termwinkey' - else if (varp == &curwin->w_p_twk) - { - if (*curwin->w_p_twk != NUL - && string_to_key(curwin->w_p_twk, TRUE) == 0) - errmsg = e_invarg; - } - // 'termwinsize' - else if (varp == &curwin->w_p_tws) - { - if (*curwin->w_p_tws != NUL) - { - p = skipdigits(curwin->w_p_tws); - if (p == curwin->w_p_tws - || (*p != 'x' && *p != '*') - || *skipdigits(p + 1) != NUL) - errmsg = e_invarg; - } - } -# if defined(MSWIN) - // 'termwintype' - else if (varp == &p_twt) - { - if (check_opt_strings(*varp, p_twt_values, FALSE) != OK) - errmsg = e_invarg; - } -# endif -#endif - -#ifdef FEAT_VARTABS - /* 'varsofttabstop' */ - else if (varp == &(curbuf->b_p_vsts)) - { - char_u *cp; - - if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) - { - if (curbuf->b_p_vsts_array) - { - vim_free(curbuf->b_p_vsts_array); - curbuf->b_p_vsts_array = 0; - } - } - else - { - for (cp = *varp; *cp; ++cp) - { - if (vim_isdigit(*cp)) - continue; - if (*cp == ',' && cp > *varp && *(cp-1) != ',') - continue; - errmsg = e_invarg; - break; - } - if (errmsg == NULL) - { - int *oldarray = curbuf->b_p_vsts_array; - if (tabstop_set(*varp, &(curbuf->b_p_vsts_array))) - { - if (oldarray) - vim_free(oldarray); - } - else - errmsg = e_invarg; - } - } - } - - /* 'vartabstop' */ - else if (varp == &(curbuf->b_p_vts)) - { - char_u *cp; - - if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) - { - if (curbuf->b_p_vts_array) - { - vim_free(curbuf->b_p_vts_array); - curbuf->b_p_vts_array = NULL; - } - } - else - { - for (cp = *varp; *cp; ++cp) - { - if (vim_isdigit(*cp)) - continue; - if (*cp == ',' && cp > *varp && *(cp-1) != ',') - continue; - errmsg = e_invarg; - break; - } - if (errmsg == NULL) - { - int *oldarray = curbuf->b_p_vts_array; - - if (tabstop_set(*varp, &(curbuf->b_p_vts_array))) - { - vim_free(oldarray); -#ifdef FEAT_FOLDING - if (foldmethodIsIndent(curwin)) - foldUpdateAll(curwin); -#endif - } - else - errmsg = e_invarg; - } - } - } -#endif - -#ifdef FEAT_TEXT_PROP - // 'previewpopup' - else if (varp == &p_pvp) - { - if (parse_previewpopup(NULL) == FAIL) - errmsg = e_invarg; - } -# ifdef FEAT_QUICKFIX - // 'completepopup' - else if (varp == &p_cpp) - { - if (parse_completepopup(NULL) == FAIL) - errmsg = e_invarg; - } -# endif -#endif - - /* Options that are a list of flags. */ - else - { - p = NULL; - if (varp == &p_ww) /* 'whichwrap' */ - p = (char_u *)WW_ALL; - if (varp == &p_shm) /* 'shortmess' */ - p = (char_u *)SHM_ALL; - else if (varp == &(p_cpo)) /* 'cpoptions' */ - p = (char_u *)CPO_ALL; - else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */ - p = (char_u *)FO_ALL; -#ifdef FEAT_CONCEAL - else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */ - p = (char_u *)COCU_ALL; -#endif - else if (varp == &p_mouse) /* 'mouse' */ - { -#ifdef FEAT_MOUSE - p = (char_u *)MOUSE_ALL; -#else - if (*p_mouse != NUL) - errmsg = N_("E538: No mouse support"); -#endif - } -#if defined(FEAT_GUI) - else if (varp == &p_go) /* 'guioptions' */ - p = (char_u *)GO_ALL; -#endif - if (p != NULL) - { - for (s = *varp; *s; ++s) - if (vim_strchr(p, *s) == NULL) - { - errmsg = illegal_char(errbuf, *s); - break; - } - } - } - - /* - * If error detected, restore the previous value. - */ - if (errmsg != NULL) - { - if (new_value_alloced) - free_string_option(*varp); - *varp = oldval; - /* - * When resetting some values, need to act on it. - */ - if (did_chartab) - (void)init_chartab(); - if (varp == &p_hl) - (void)highlight_changed(); - } - else - { -#ifdef FEAT_EVAL - /* Remember where the option was set. */ - set_option_sctx_idx(opt_idx, opt_flags, current_sctx); -#endif - /* - * Free string options that are in allocated memory. - * Use "free_oldval", because recursiveness may change the flags under - * our fingers (esp. init_highlight()). - */ - if (free_oldval) - free_string_option(oldval); - if (new_value_alloced) - options[opt_idx].flags |= P_ALLOCED; - else - options[opt_idx].flags &= ~P_ALLOCED; - - if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 - && ((int)options[opt_idx].indir & PV_BOTH)) - { - /* global option with local value set to use global value; free - * the local value and make it empty */ - p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL); - free_string_option(*(char_u **)p); - *(char_u **)p = empty_option; - } - - /* May set global value for local option. */ - else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL) - set_string_option_global(opt_idx, varp); - - /* - * Trigger the autocommand only after setting the flags. - */ -#ifdef FEAT_SYN_HL - /* When 'syntax' is set, load the syntax of that name */ - if (varp == &(curbuf->b_p_syn)) - { - static int syn_recursive = 0; - - ++syn_recursive; - // Only pass TRUE for "force" when the value changed or not used - // recursively, to avoid endless recurrence. - apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname, - value_changed || syn_recursive == 1, curbuf); - curbuf->b_flags |= BF_SYN_SET; - --syn_recursive; - } -#endif - else if (varp == &(curbuf->b_p_ft)) - { - /* 'filetype' is set, trigger the FileType autocommand. - * Skip this when called from a modeline and the filetype was - * already set to this value. */ - if (!(opt_flags & OPT_MODELINE) || value_changed) - { - static int ft_recursive = 0; - int secure_save = secure; - - // Reset the secure flag, since the value of 'filetype' has - // been checked to be safe. - secure = 0; - - ++ft_recursive; - did_filetype = TRUE; - // Only pass TRUE for "force" when the value changed or not - // used recursively, to avoid endless recurrence. - apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname, - value_changed || ft_recursive == 1, curbuf); - --ft_recursive; - /* Just in case the old "curbuf" is now invalid. */ - if (varp != &(curbuf->b_p_ft)) - varp = NULL; - - secure = secure_save; - } - } -#ifdef FEAT_SPELL - if (varp == &(curwin->w_s->b_p_spl)) - { - char_u fname[200]; - char_u *q = curwin->w_s->b_p_spl; - - /* Skip the first name if it is "cjk". */ - if (STRNCMP(q, "cjk,", 4) == 0) - q += 4; - - /* - * Source the spell/LANG.vim in 'runtimepath'. - * They could set 'spellcapcheck' depending on the language. - * Use the first name in 'spelllang' up to '_region' or - * '.encoding'. - */ - for (p = q; *p != NUL; ++p) - if (!ASCII_ISALNUM(*p) && *p != '-') - break; - if (p > q) - { - vim_snprintf((char *)fname, 200, "spell/%.*s.vim", - (int)(p - q), q); - source_runtime(fname, DIP_ALL); - } - } -#endif - } - -#ifdef FEAT_MOUSE - if (varp == &p_mouse) - { -# ifdef FEAT_MOUSE_TTY - if (*p_mouse == NUL) - mch_setmouse(FALSE); /* switch mouse off */ - else -# endif - setmouse(); /* in case 'mouse' changed */ - } -#endif - - if (curwin->w_curswant != MAXCOL - && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) - curwin->w_set_curswant = TRUE; - -#ifdef FEAT_GUI - /* check redraw when it's not a GUI option or the GUI is active. */ - if (!redraw_gui_only || gui.in_use) -#endif - check_redraw(options[opt_idx].flags); - -#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) - if (did_swaptcap) - { - set_termname((char_u *)"win32"); - init_highlight(TRUE, FALSE); - } -#endif - - return errmsg; -} - -#ifdef FEAT_STL_OPT -/* - * Check validity of options with the 'statusline' format. - * Return error message or NULL. - */ - static char * -check_stl_option(char_u *s) -{ - int itemcnt = 0; - int groupdepth = 0; - static char errbuf[80]; - - while (*s && itemcnt < STL_MAX_ITEM) - { - /* Check for valid keys after % sequences */ - while (*s && *s != '%') - s++; - if (!*s) - break; - s++; - if (*s != '%' && *s != ')') - ++itemcnt; - if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK) - { - s++; - continue; - } - if (*s == ')') - { - s++; - if (--groupdepth < 0) - break; - continue; - } - if (*s == '-') - s++; - while (VIM_ISDIGIT(*s)) - s++; - if (*s == STL_USER_HL) - continue; - if (*s == '.') - { - s++; - while (*s && VIM_ISDIGIT(*s)) - s++; - } - if (*s == '(') - { - groupdepth++; - continue; - } - if (vim_strchr(STL_ALL, *s) == NULL) - { - return illegal_char(errbuf, *s); - } - if (*s == '{') - { - s++; - while (*s != '}' && *s) - s++; - if (*s != '}') - return N_("E540: Unclosed expression sequence"); - } - } - if (itemcnt >= STL_MAX_ITEM) - return N_("E541: too many items"); - if (groupdepth != 0) - return N_("E542: unbalanced groups"); - return NULL; -} -#endif - -#ifdef FEAT_CLIPBOARD +#if defined(FEAT_CLIPBOARD) || defined(PROTO) /* * Extract the items in the 'clipboard' option and set global values. * Return an error message or NULL for success. */ - static char * + char * check_clipboard_option(void) { int new_unnamed = 0; @@ -4955,7 +2589,7 @@ check_clipboard_option(void) * Set the script_ctx for an option, taking care of setting the buffer- or * window-local value. */ - static void + void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx) { int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; @@ -6222,7 +3856,7 @@ set_num_option( /* * Called after an option changed: check if something needs to be redrawn. */ - static void + void check_redraw(long_u flags) { /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */ @@ -6248,7 +3882,7 @@ check_redraw(long_u flags) * Find index for option 'arg'. * Return -1 if not found. */ - static int + int findoption(char_u *arg) { int opt_idx; @@ -6608,6 +4242,81 @@ option_iter_next(void **option, int opt_type) #endif /* + * Return the flags for the option at 'opt_idx'. + */ + long_u +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, long_u flag) +{ + options[opt_idx].flags |= flag; +} + +/* + * Clear a flag for the option at 'opt_idx'. + */ + void +clear_option_flag(int opt_idx, long_u flag) +{ + options[opt_idx].flags &= ~flag; +} + +/* + * Returns TRUE if the option at 'opt_idx' is a global option + */ + int +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 options[opt_idx].indir & PV_BOTH; +} + +/* + * Returns TRUE if the option at 'opt_idx' is a window-local option + */ + int +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 + */ + int +is_hidden_option(int opt_idx) +{ + return options[opt_idx].var == NULL; +} + +#if defined(FEAT_CRYPT) || defined(PROTO) +/* + * Returns TRUE if the option at 'opt_idx' is a crypt key option + */ + int +is_crypt_key_option(int opt_idx) +{ + return options[opt_idx].indir == PV_KEY; +} +#endif + +/* * Set the value of option "name". * Use "string" for string options, use "number" for other options. * @@ -7348,6 +5057,15 @@ istermoption(struct vimoption *p) return (p->fullname[0] == 't' && p->fullname[1] == '_'); } +/* + * Returns TRUE if the option at 'opt_idx' starts with 't_' + */ + int +istermoption_idx(int opt_idx) +{ + return istermoption(&options[opt_idx]); +} + #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) /* * Unset local option value, similar to ":set opt<". @@ -7512,6 +5230,16 @@ get_varp_scope(struct vimoption *p, int opt_flags) } /* + * 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) +{ + return get_varp_scope(&(options[opt_idx]), opt_flags); +} + +/* * Get pointer to option variable. */ static char_u * @@ -7763,6 +5491,24 @@ get_varp(struct vimoption *p) } /* + * 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_u * +get_option_fullname(int opt_idx) +{ + return (char_u *)options[opt_idx].fullname; +} + +/* * Get the value of 'equalprg', either the buffer-local one or the global one. */ char_u * @@ -8540,7 +6286,7 @@ ExpandSettings( if (xp->xp_context == EXPAND_BOOL_SETTINGS && !(options[opt_idx].flags & P_BOOL)) continue; - is_term_opt = istermoption(&options[opt_idx]); + is_term_opt = istermoption_idx(opt_idx); if (is_term_opt && num_normal > 0) continue; match = FALSE; @@ -8983,7 +6729,7 @@ vimrc_found(char_u *fname, char_u *envname) if (!option_was_set((char_u *)"cp")) { p_cp = FALSE; - for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) + for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF))) set_option_default(opt_idx, OPT_FREE, FALSE); didset_options(); @@ -9072,7 +6818,7 @@ compatible_set(void) { int opt_idx; - for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) + for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) if ( ((options[opt_idx].flags & P_VIM) && p_cp) || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp)) set_option_default(opt_idx, OPT_FREE, p_cp); @@ -9080,12 +6826,12 @@ compatible_set(void) didset_options2(); } -#ifdef FEAT_LINEBREAK +#if defined(FEAT_LINEBREAK) || defined(PROTO) /* * fill_breakat_flags() -- called when 'breakat' changes value. */ - static void + void fill_breakat_flags(void) { char_u *p; @@ -9101,65 +6847,9 @@ fill_breakat_flags(void) #endif /* - * 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 */ -{ - return opt_strings_flags(val, values, NULL, list); -} - -/* - * 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, - int list) /* when TRUE: accept a list of values */ -{ - int i; - int len; - unsigned new_flags = 0; - - while (*val) - { - for (i = 0; ; ++i) - { - if (values[i] == NULL) /* val not found in values[] */ - return FAIL; - - len = (int)STRLEN(values[i]); - if (STRNCMP(values[i], val, len) == 0 - && ((list && val[len] == ',') || val[len] == NUL)) - { - val += len + (val[len] == ','); - new_flags |= (1 << i); - break; /* check next item in val list */ - } - } - } - if (flagp != NULL) - *flagp = new_flags; - - return OK; -} - -/* * Read the 'wildmode' option, fill wim_flags[]. */ - static int + int check_opt_wim(void) { char_u new_wim_flags[4]; @@ -9280,15 +6970,6 @@ file_ff_differs(buf_T *buf, int ignore_empty) } /* - * return OK if "p" is a valid fileformat name, FAIL otherwise. - */ - int -check_ff_value(char_u *p) -{ - return check_opt_strings(p, p_ff_values, FALSE); -} - -/* * Return the effective 'scrolloff' value for the current window, using the * global value when appropriate. */ @@ -9409,7 +7090,7 @@ find_mps_values( * This is called when 'breakindentopt' is changed and when a window is * initialized. */ - static int + int briopt_check(win_T *wp) { char_u *p; @@ -9498,7 +7179,7 @@ get_winbuf_options(int bufopt) if (d == NULL) return NULL; - for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++) + for (opt_idx = 0; !istermoption_idx(opt_idx); opt_idx++) { struct vimoption *opt = &options[opt_idx]; @@ -9523,11 +7204,11 @@ get_winbuf_options(int bufopt) } #endif -#ifdef FEAT_SYN_HL +#if defined(FEAT_SYN_HL) || defined(PROTO) /* * This is called when 'culopt' is changed */ - static int + int fill_culopt_flags(char_u *val, win_T *wp) { char_u *p; diff --git a/src/option.h b/src/option.h index 1d85843d5..35efcabf3 100644 --- a/src/option.h +++ b/src/option.h @@ -10,6 +10,53 @@ * option.h: definition of global variables for settable options */ +// +// Flags +// +#define P_BOOL 0x01 // the option is boolean +#define P_NUM 0x02 // the option is numeric +#define P_STRING 0x04 // the option is a string +#define P_ALLOCED 0x08 // the string option is in allocated memory, + // must use free_string_option() when + // assigning new value. Not set if default is + // the same. +#define P_EXPAND 0x10 // environment expansion. NOTE: P_EXPAND can + // never be used for local or hidden options! +#define P_NODEFAULT 0x40 // don't set to default value +#define P_DEF_ALLOCED 0x80 // default value is in allocated memory, must + // use vim_free() when assigning new value +#define P_WAS_SET 0x100 // option has been set/reset +#define P_NO_MKRC 0x200 // don't include in :mkvimrc output +#define P_VI_DEF 0x400 // Use Vi default for Vim +#define P_VIM 0x800 // Vim option, reset when 'cp' set + + // when option changed, what to display: +#define P_RSTAT 0x1000 // redraw status lines +#define P_RWIN 0x2000 // redraw current window and recompute text +#define P_RBUF 0x4000 // redraw current buffer and recompute text +#define P_RALL 0x6000 // redraw all windows +#define P_RCLR 0x7000 // clear and redraw all + +#define P_COMMA 0x8000 // comma separated list +#define P_ONECOMMA 0x18000L // P_COMMA and cannot have two consecutive + // commas +#define P_NODUP 0x20000L // don't allow duplicate strings +#define P_FLAGLIST 0x40000L // list of single-char flags + +#define P_SECURE 0x80000L // cannot change in modeline or secure mode +#define P_GETTEXT 0x100000L // expand default value with _() +#define P_NOGLOB 0x200000L // do not use local value for global vimrc +#define P_NFNAME 0x400000L // only normal file name chars allowed +#define P_INSECURE 0x800000L // option was set from a modeline +#define P_PRI_MKRC 0x1000000L // priority for :mkvimrc (setting option has + // side effects) +#define P_NO_ML 0x2000000L // not allowed in modeline +#define P_CURSWANT 0x4000000L // update curswant required; not needed when + // there is a redraw flag +#define P_NDNAME 0x8000000L // only normal dir name chars allowed +#define P_RWINONLY 0x10000000L // only redraw current window +#define P_MLE 0x20000000L // under control of 'modelineexpr' + /* * Default values for 'errorformat'. * The "%f|%l| %m" one is used for when the contents of the quickfix window is @@ -311,11 +358,26 @@ #ifdef FEAT_RIGHTLEFT EXTERN long p_aleph; // 'aleph' #endif +EXTERN char_u *p_ambw; // 'ambiwidth' #ifdef FEAT_AUTOCHDIR EXTERN int p_acd; // 'autochdir' #endif -EXTERN char_u *p_ambw; // 'ambiwidth' -EXTERN char_u *p_emoji; // 'emoji' +EXTERN int p_ai; // 'autoindent' +EXTERN int p_bin; // 'binary' +EXTERN int p_bomb; // 'bomb' +EXTERN int p_bl; // 'buflisted' +#ifdef FEAT_CINDENT +EXTERN int p_cin; // 'cindent' +EXTERN char_u *p_cink; // 'cinkeys' +#endif +#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) +EXTERN char_u *p_cinw; // 'cinwords' +#endif +#ifdef FEAT_COMPL_FUNC +EXTERN char_u *p_cfu; // 'completefunc' +EXTERN char_u *p_ofu; // 'omnifunc' +#endif +EXTERN int p_ci; // 'copyindent' #if defined(FEAT_GUI) && defined(MACOS_X) EXTERN int *p_antialias; // 'antialias' #endif @@ -327,9 +389,6 @@ EXTERN char_u *p_bg; // 'background' EXTERN int p_bk; // 'backup' EXTERN char_u *p_bkc; // 'backupcopy' EXTERN unsigned bkc_flags; // flags from 'backupcopy' -#ifdef IN_OPTION_C -static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL}; -#endif # define BKC_YES 0x001 # define BKC_AUTO 0x002 # define BKC_NO 0x004 @@ -339,13 +398,6 @@ EXTERN char_u *p_bdir; // 'backupdir' EXTERN char_u *p_bex; // 'backupext' EXTERN char_u *p_bo; // 'belloff' EXTERN unsigned bo_flags; -# ifdef IN_OPTION_C -static char *(p_bo_values[]) = {"all", "backspace", "cursor", "complete", - "copy", "ctrlg", "error", "esc", "ex", - "hangul", "insertmode", "lang", "mess", - "showmatch", "operator", "register", "shell", - "spell", "wildmode", NULL}; -# endif // values for the 'beepon' option #define BO_ALL 0x0001 @@ -392,11 +444,10 @@ EXTERN char_u *p_bsdir; // 'browsedir' #ifdef FEAT_LINEBREAK EXTERN char_u *p_breakat; // 'breakat' #endif +EXTERN char_u *p_bh; // 'bufhidden' +EXTERN char_u *p_bt; // 'buftype' EXTERN char_u *p_cmp; // 'casemap' EXTERN unsigned cmp_flags; -#ifdef IN_OPTION_C -static char *(p_cmp_values[]) = {"internal", "keepascii", NULL}; -#endif #define CMP_INTERNAL 0x001 #define CMP_KEEPASCII 0x002 EXTERN char_u *p_enc; // 'encoding' @@ -404,6 +455,7 @@ EXTERN int p_deco; // 'delcombine' #ifdef FEAT_EVAL EXTERN char_u *p_ccv; // 'charconvert' #endif +EXTERN char_u *p_cino; // 'cinoptions' #ifdef FEAT_CMDWIN EXTERN char_u *p_cedit; // 'cedit' EXTERN long p_cwh; // 'cmdwinheight' @@ -412,6 +464,10 @@ EXTERN long p_cwh; // 'cmdwinheight' EXTERN char_u *p_cb; // 'clipboard' #endif EXTERN long p_ch; // 'cmdheight' +#ifdef FEAT_FOLDING +EXTERN char_u *p_cms; // 'commentstring' +#endif +EXTERN char_u *p_cpt; // 'complete' #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) EXTERN int p_confirm; // 'confirm' #endif @@ -422,6 +478,9 @@ EXTERN char_u *p_csl; // 'completeslash' #endif EXTERN long p_ph; // 'pumheight' EXTERN long p_pw; // 'pumwidth' +#ifdef FEAT_COMMENTS +EXTERN char_u *p_com; // 'comments' +#endif EXTERN char_u *p_cpo; // 'cpoptions' #ifdef FEAT_CSCOPE EXTERN char_u *p_csprg; // 'cscopeprg' @@ -454,14 +513,12 @@ EXTERN int p_dg; // 'digraph' EXTERN char_u *p_dir; // 'directory' EXTERN char_u *p_dy; // 'display' EXTERN unsigned dy_flags; -#ifdef IN_OPTION_C -static char *(p_dy_values[]) = {"lastline", "truncate", "uhex", NULL}; -#endif #define DY_LASTLINE 0x001 #define DY_TRUNCATE 0x002 #define DY_UHEX 0x004 EXTERN int p_ed; // 'edcompatible' EXTERN char_u *p_ead; // 'eadirection' +EXTERN char_u *p_emoji; // 'emoji' EXTERN int p_ea; // 'equalalways' EXTERN char_u *p_ep; // 'equalprg' EXTERN int p_eb; // 'errorbells' @@ -471,22 +528,24 @@ EXTERN char_u *p_efm; // 'errorformat' EXTERN char_u *p_gefm; // 'grepformat' EXTERN char_u *p_gp; // 'grepprg' #endif -EXTERN char_u *p_ei; // 'eventignore' +EXTERN int p_eol; // 'endofline' EXTERN int p_ek; // 'esckeys' +EXTERN char_u *p_ei; // 'eventignore' +EXTERN int p_et; // 'expandtab' EXTERN int p_exrc; // 'exrc' +EXTERN char_u *p_fenc; // 'fileencoding' EXTERN char_u *p_fencs; // 'fileencodings' +EXTERN char_u *p_ff; // 'fileformat' EXTERN char_u *p_ffs; // 'fileformats' EXTERN long p_fic; // 'fileignorecase' +EXTERN char_u *p_ft; // 'filetype' +EXTERN char_u *p_fcs; // 'fillchar' +EXTERN int p_fixeol; // 'fixendofline' #ifdef FEAT_FOLDING EXTERN char_u *p_fcl; // 'foldclose' EXTERN long p_fdls; // 'foldlevelstart' EXTERN char_u *p_fdo; // 'foldopen' EXTERN unsigned fdo_flags; -# ifdef IN_OPTION_C -static char *(p_fdo_values[]) = {"all", "block", "hor", "mark", "percent", - "quickfix", "search", "tag", "insert", - "undo", "jump", NULL}; -# endif # define FDO_ALL 0x001 # define FDO_BLOCK 0x002 # define FDO_HOR 0x004 @@ -499,6 +558,11 @@ static char *(p_fdo_values[]) = {"all", "block", "hor", "mark", "percent", # define FDO_UNDO 0x200 # define FDO_JUMP 0x400 #endif +#if defined(FEAT_EVAL) +EXTERN char_u *p_fex; // 'formatexpr' +#endif +EXTERN char_u *p_flp; // 'formatlistpat' +EXTERN char_u *p_fo; // 'formatoptions' EXTERN char_u *p_fp; // 'formatprg' #ifdef HAVE_FSYNC EXTERN int p_fs; // 'fsync' @@ -580,12 +644,29 @@ EXTERN char_u *p_imsf; // 'imstatusfunc' #endif EXTERN int p_imcmdline; // 'imcmdline' EXTERN int p_imdisable; // 'imdisable' +EXTERN long p_iminsert; // 'iminsert' +EXTERN long p_imsearch; // 'imsearch' +EXTERN int p_inf; // 'infercase' +#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) +EXTERN char_u *p_inex; // 'includeexpr' +#endif EXTERN int p_is; // 'incsearch' +#if defined(FEAT_CINDENT) && defined(FEAT_EVAL) +EXTERN char_u *p_inde; // 'indentexpr' +EXTERN char_u *p_indk; // 'indentkeys' +#endif EXTERN int p_im; // 'insertmode' EXTERN char_u *p_isf; // 'isfname' EXTERN char_u *p_isi; // 'isident' +EXTERN char_u *p_isk; // 'iskeyword' EXTERN char_u *p_isp; // 'isprint' EXTERN int p_js; // 'joinspaces' +#ifdef FEAT_CRYPT +EXTERN char_u *p_key; // 'key' +#endif +#ifdef FEAT_KEYMAP +EXTERN char_u *p_keymap; // 'keymap' +#endif EXTERN char_u *p_kp; // 'keywordprg' EXTERN char_u *p_km; // 'keymodel' #ifdef FEAT_LANGMAP @@ -600,6 +681,7 @@ EXTERN char_u *p_lm; // 'langmenu' EXTERN long p_linespace; // 'linespace' #endif #ifdef FEAT_LISP +EXTERN int p_lisp; // 'lisp' EXTERN char_u *p_lispwords; // 'lispwords' #endif EXTERN long p_ls; // 'laststatus' @@ -620,6 +702,7 @@ EXTERN char_u *p_menc; // 'makeencoding' EXTERN char_u *p_mef; // 'makeef' EXTERN char_u *p_mp; // 'makeprg' #endif +EXTERN char_u *p_mps; // 'matchpairs' #ifdef FEAT_SIGNS EXTERN char_u *p_scl; // signcolumn #endif @@ -642,8 +725,11 @@ EXTERN long p_mis; // 'menuitems' #ifdef FEAT_SPELL EXTERN char_u *p_msm; // 'mkspellmem' #endif +EXTERN int p_ml; // 'modeline' EXTERN long p_mle; // 'modelineexpr' EXTERN long p_mls; // 'modelines' +EXTERN int p_ma; // 'modifiable' +EXTERN int p_mod; // 'modified' EXTERN char_u *p_mouse; // 'mouse' #ifdef FEAT_GUI EXTERN int p_mousef; // 'mousefocus' @@ -659,6 +745,7 @@ EXTERN char_u *p_mzschemedll; // 'mzschemedll' EXTERN char_u *p_mzschemegcdll; // 'mzschemegcdll' # endif #endif +EXTERN char_u *p_nf; // 'nrformats' #if defined(MSWIN) EXTERN int p_odev; // 'opendevice' #endif @@ -677,6 +764,7 @@ EXTERN char_u *p_cdpath; // 'cdpath' #if defined(DYNAMIC_PERL) EXTERN char_u *p_perldll; // 'perldll' #endif +EXTERN int p_pi; // 'preserveindent' #if defined(DYNAMIC_PYTHON3) EXTERN char_u *p_py3dll; // 'pythonthreedll' #endif @@ -692,6 +780,10 @@ EXTERN char_u *p_pyhome; // 'pythonhome' #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) EXTERN long p_pyx; // 'pyxversion' #endif +#ifdef FEAT_TEXTOBJ +EXTERN char_u *p_qe; // 'quoteescape' +#endif +EXTERN int p_ro; // 'readonly' #ifdef FEAT_RELTIME EXTERN long p_rdt; // 'redrawtime' #endif @@ -732,12 +824,6 @@ EXTERN char_u *p_slm; // 'selectmode' #ifdef FEAT_SESSION EXTERN char_u *p_ssop; // 'sessionoptions' EXTERN unsigned ssop_flags; -# ifdef IN_OPTION_C -// Also used for 'viewoptions'! -static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize", - "localoptions", "options", "help", "blank", "globals", "slash", "unix", - "sesdir", "curdir", "folds", "cursor", "tabpages", "terminal", NULL}; -# endif # define SSOP_BUFFERS 0x001 # define SSOP_WINPOS 0x002 # define SSOP_RESIZE 0x004 @@ -776,7 +862,9 @@ EXTERN int p_ssl; // 'shellslash' EXTERN char_u *p_stl; // 'statusline' #endif EXTERN int p_sr; // 'shiftround' +EXTERN long p_sw; // 'shiftwidth' EXTERN char_u *p_shm; // 'shortmess' +EXTERN int p_sn; // 'shortname' #ifdef FEAT_LINEBREAK EXTERN char_u *p_sbr; // 'showbreak' #endif @@ -789,13 +877,30 @@ EXTERN int p_smd; // 'showmode' EXTERN long p_ss; // 'sidescroll' EXTERN long p_siso; // 'sidescrolloff' EXTERN int p_scs; // 'smartcase' +#ifdef FEAT_SMARTINDENT +EXTERN int p_si; // 'smartindent' +#endif EXTERN int p_sta; // 'smarttab' +EXTERN long p_sts; // 'softtabstop' EXTERN int p_sb; // 'splitbelow' +#if defined(FEAT_SEARCHPATH) +EXTERN char_u *p_sua; // 'suffixesadd' +#endif +EXTERN int p_swf; // 'swapfile' +#ifdef FEAT_SYN_HL +EXTERN long p_smc; // 'synmaxcol' +#endif EXTERN long p_tpm; // 'tabpagemax' -# if defined(FEAT_STL_OPT) +#ifdef FEAT_STL_OPT EXTERN char_u *p_tal; // 'tabline' -# endif +#endif +#ifdef FEAT_EVAL +EXTERN char_u *p_tfu; // 'tagfunc' +#endif #ifdef FEAT_SPELL +EXTERN char_u *p_spc; // 'spellcapcheck' +EXTERN char_u *p_spf; // 'spellfile' +EXTERN char_u *p_spl; // 'spelllang' EXTERN char_u *p_sps; // 'spellsuggest' #endif EXTERN int p_spr; // 'splitright' @@ -804,20 +909,16 @@ EXTERN char_u *p_su; // 'suffixes' EXTERN char_u *p_sws; // 'swapsync' EXTERN char_u *p_swb; // 'switchbuf' EXTERN unsigned swb_flags; -#ifdef IN_OPTION_C -static char *(p_swb_values[]) = {"useopen", "usetab", "split", "newtab", "vsplit", NULL}; -#endif #define SWB_USEOPEN 0x001 #define SWB_USETAB 0x002 #define SWB_SPLIT 0x004 #define SWB_NEWTAB 0x008 #define SWB_VSPLIT 0x010 +EXTERN char_u *p_syn; // 'syntax' +EXTERN long p_ts; // 'tabstop' EXTERN int p_tbs; // 'tagbsearch' EXTERN char_u *p_tc; // 'tagcase' EXTERN unsigned tc_flags; // flags from 'tagcase' -#ifdef IN_OPTION_C -static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL}; -#endif #define TC_FOLLOWIC 0x01 #define TC_IGNORE 0x02 #define TC_MATCH 0x04 @@ -837,11 +938,16 @@ EXTERN char_u *p_tenc; // 'termencoding' #ifdef FEAT_TERMGUICOLORS EXTERN int p_tgc; // 'termguicolors' #endif +#ifdef FEAT_TERMINAL +EXTERN long p_twsl; // 'termwinscroll' +#endif #if defined(MSWIN) && defined(FEAT_TERMINAL) EXTERN char_u *p_twt; // 'termwintype' #endif EXTERN int p_terse; // 'terse' EXTERN int p_ta; // 'textauto' +EXTERN int p_tx; // 'textmode' +EXTERN long p_tw; // 'textwidth' EXTERN int p_to; // 'tildeop' EXTERN int p_timeout; // 'timeout' EXTERN long p_tm; // 'timeoutlen' @@ -859,9 +965,6 @@ EXTERN int p_tf; // 'ttyfast' #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) EXTERN char_u *p_toolbar; // 'toolbar' EXTERN unsigned toolbar_flags; -# ifdef IN_OPTION_C -static char *(p_toolbar_values[]) = {"text", "icons", "tooltips", "horiz", NULL}; -# endif # define TOOLBAR_TEXT 0x01 # define TOOLBAR_ICONS 0x02 # define TOOLBAR_TOOLTIPS 0x04 @@ -870,9 +973,6 @@ static char *(p_toolbar_values[]) = {"text", "icons", "tooltips", "horiz", NULL} #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) EXTERN char_u *p_tbis; // 'toolbariconsize' EXTERN unsigned tbis_flags; -# ifdef IN_OPTION_C -static char *(p_tbis_values[]) = {"tiny", "small", "medium", "large", "huge", "giant", NULL}; -# endif # define TBIS_TINY 0x01 # define TBIS_SMALL 0x02 # define TBIS_MEDIUM 0x04 @@ -884,9 +984,6 @@ EXTERN long p_ttyscroll; // 'ttyscroll' #if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS)) EXTERN char_u *p_ttym; // 'ttymouse' EXTERN unsigned ttym_flags; -# ifdef IN_OPTION_C -static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", "sgr", NULL}; -# endif # define TTYM_XTERM 0x01 # define TTYM_XTERM2 0x02 # define TTYM_DEC 0x04 @@ -897,11 +994,17 @@ static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm" # define TTYM_SGR 0x80 #endif EXTERN char_u *p_udir; // 'undodir' +#ifdef FEAT_PERSISTENT_UNDO +EXTERN int p_udf; // 'undofile' +#endif EXTERN long p_ul; // 'undolevels' EXTERN long p_ur; // 'undoreload' EXTERN long p_uc; // 'updatecount' EXTERN long p_ut; // 'updatetime' -EXTERN char_u *p_fcs; // 'fillchar' +#ifdef FEAT_VARTABS +EXTERN char_u *p_vsts; // 'varsofttabstop' +EXTERN char_u *p_vts; // 'vartabstop' +#endif #ifdef FEAT_VIMINFO EXTERN char_u *p_viminfo; // 'viminfo' EXTERN char_u *p_viminfofile; // 'viminfofile' @@ -914,9 +1017,6 @@ EXTERN unsigned vop_flags; // uses SSOP_ flags EXTERN int p_vb; // 'visualbell' EXTERN char_u *p_ve; // 'virtualedit' EXTERN unsigned ve_flags; -#ifdef IN_OPTION_C -static char *(p_ve_values[]) = {"block", "insert", "all", "onemore", NULL}; -#endif #define VE_BLOCK 5 // includes "all" #define VE_INSERT 6 // includes "all" #define VE_ALL 4 @@ -954,6 +1054,7 @@ EXTERN long p_wiw; // 'winwidth' #if defined(MSWIN) && defined(FEAT_TERMINAL) EXTERN char_u *p_winptydll; // 'winptydll' #endif +EXTERN long p_wm; // 'wrapmargin' EXTERN int p_ws; // 'wrapscan' EXTERN int p_write; // 'write' EXTERN int p_wa; // 'writeany' diff --git a/src/optiondefs.h b/src/optiondefs.h index 8e9d3f932..c21c8f6a9 100644 --- a/src/optiondefs.h +++ b/src/optiondefs.h @@ -243,112 +243,6 @@ typedef enum // buffers. Indicate this by setting "var" to VAR_WIN. #define VAR_WIN ((char_u *)-1) -// These are the global values for options which are also local to a buffer. -// Only to be used in option.c! -static int p_ai; -static int p_bin; -static int p_bomb; -static char_u *p_bh; -static char_u *p_bt; -static int p_bl; -static int p_ci; -#ifdef FEAT_CINDENT -static int p_cin; -static char_u *p_cink; -static char_u *p_cino; -#endif -#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) -static char_u *p_cinw; -#endif -#ifdef FEAT_COMMENTS -static char_u *p_com; -#endif -#ifdef FEAT_FOLDING -static char_u *p_cms; -#endif -static char_u *p_cpt; -#ifdef FEAT_COMPL_FUNC -static char_u *p_cfu; -static char_u *p_ofu; -#endif -#ifdef FEAT_EVAL -static char_u *p_tfu; -#endif -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 long p_iminsert; -static long p_imsearch; -#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL) -static char_u *p_inex; -#endif -#if defined(FEAT_CINDENT) && defined(FEAT_EVAL) -static char_u *p_inde; -static char_u *p_indk; -#endif -#if defined(FEAT_EVAL) -static char_u *p_fex; -#endif -static int p_inf; -static char_u *p_isk; -#ifdef FEAT_CRYPT -static char_u *p_key; -#endif -#ifdef FEAT_LISP -static int p_lisp; -#endif -static int p_ml; -static int p_ma; -static int p_mod; -static char_u *p_mps; -static char_u *p_nf; -static int p_pi; -#ifdef FEAT_TEXTOBJ -static char_u *p_qe; -#endif -static int p_ro; -#ifdef FEAT_SMARTINDENT -static int p_si; -#endif -static int p_sn; -static long p_sts; -#if defined(FEAT_SEARCHPATH) -static char_u *p_sua; -#endif -static long p_sw; -static int p_swf; -#ifdef FEAT_SYN_HL -static long p_smc; -static char_u *p_syn; -#endif -#ifdef FEAT_SPELL -static char_u *p_spc; -static char_u *p_spf; -static char_u *p_spl; -#endif -static long p_ts; -static long p_tw; -static int p_tx; -#ifdef FEAT_PERSISTENT_UNDO -static int p_udf; -#endif -static long p_wm; -#ifdef FEAT_VARTABS -static char_u *p_vsts; -static char_u *p_vts; -#endif -#ifdef FEAT_KEYMAP -static char_u *p_keymap; -#endif -#ifdef FEAT_TERMINAL -static long p_twsl; // 'termwinscroll' -#endif - // Saved values for when 'bin' is set. static int p_et_nobin; static int p_ml_nobin; @@ -387,53 +281,6 @@ struct vimoption #define VI_DEFAULT 0 // def_val[VI_DEFAULT] is Vi default value #define VIM_DEFAULT 1 // def_val[VIM_DEFAULT] is Vim default value -// -// Flags -// -#define P_BOOL 0x01 // the option is boolean -#define P_NUM 0x02 // the option is numeric -#define P_STRING 0x04 // the option is a string -#define P_ALLOCED 0x08 // the string option is in allocated memory, - // must use free_string_option() when - // assigning new value. Not set if default is - // the same. -#define P_EXPAND 0x10 // environment expansion. NOTE: P_EXPAND can - // never be used for local or hidden options! -#define P_NODEFAULT 0x40 // don't set to default value -#define P_DEF_ALLOCED 0x80 // default value is in allocated memory, must - // use vim_free() when assigning new value -#define P_WAS_SET 0x100 // option has been set/reset -#define P_NO_MKRC 0x200 // don't include in :mkvimrc output -#define P_VI_DEF 0x400 // Use Vi default for Vim -#define P_VIM 0x800 // Vim option, reset when 'cp' set - - // when option changed, what to display: -#define P_RSTAT 0x1000 // redraw status lines -#define P_RWIN 0x2000 // redraw current window and recompute text -#define P_RBUF 0x4000 // redraw current buffer and recompute text -#define P_RALL 0x6000 // redraw all windows -#define P_RCLR 0x7000 // clear and redraw all - -#define P_COMMA 0x8000 // comma separated list -#define P_ONECOMMA 0x18000L // P_COMMA and cannot have two consecutive - // commas -#define P_NODUP 0x20000L // don't allow duplicate strings -#define P_FLAGLIST 0x40000L // list of single-char flags - -#define P_SECURE 0x80000L // cannot change in modeline or secure mode -#define P_GETTEXT 0x100000L // expand default value with _() -#define P_NOGLOB 0x200000L // do not use local value for global vimrc -#define P_NFNAME 0x400000L // only normal file name chars allowed -#define P_INSECURE 0x800000L // option was set from a modeline -#define P_PRI_MKRC 0x1000000L // priority for :mkvimrc (setting option has - // side effects) -#define P_NO_ML 0x2000000L // not allowed in modeline -#define P_CURSWANT 0x4000000L // update curswant required; not needed when - // there is a redraw flag -#define P_NDNAME 0x8000000L // only normal dir name chars allowed -#define P_RWINONLY 0x10000000L // only redraw current window -#define P_MLE 0x20000000L // under control of 'modelineexpr' - #define ISK_LATIN1 (char_u *)"@,48-57,_,192-255" // 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used @@ -3158,45 +3005,5 @@ static struct vimoption options[] = #define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption)) -static char *(p_ambw_values[]) = {"single", "double", NULL}; -static char *(p_bg_values[]) = {"light", "dark", NULL}; -static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL}; -static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL}; -#ifdef FEAT_CRYPT -static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL}; -#endif -static char *(p_wop_values[]) = {"tagfile", NULL}; -#ifdef FEAT_WAK -static char *(p_wak_values[]) = {"yes", "menu", "no", NULL}; -#endif -static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL}; -static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL}; -static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL}; -static char *(p_km_values[]) = {"startsel", "stopsel", NULL}; -#ifdef FEAT_BROWSE -static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL}; -#endif -static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL}; -static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL}; -static char *(p_ead_values[]) = {"both", "ver", "hor", NULL}; -static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL}; -static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL}; -static char *(p_bs_values[]) = {"indent", "eol", "start", NULL}; -#ifdef FEAT_FOLDING -static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax", -# ifdef FEAT_DIFF - "diff", -# endif - NULL}; -static char *(p_fcl_values[]) = {"all", NULL}; -#endif -static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "noinsert", "noselect", NULL}; -#ifdef BACKSLASH_IN_FILENAME -static char *(p_csl_values[]) = {"slash", "backslash", NULL}; -#endif -#ifdef FEAT_SIGNS -static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL}; -#endif -#if defined(MSWIN) && defined(FEAT_TERMINAL) -static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL}; -#endif +// The following is needed to make the gen_opt_test.vim script work. +// {" diff --git a/src/optionstr.c b/src/optionstr.c new file mode 100644 index 000000000..44f0759a9 --- /dev/null +++ b/src/optionstr.c @@ -0,0 +1,2491 @@ +/* vi:set ts=8 sts=4 sw=4 noet: + * + * VIM - Vi IMproved by Bram Moolenaar + * + * Do ":help uganda" in Vim to read copying and usage conditions. + * Do ":help credits" in Vim to see a list of people who contributed. + * See README.txt for an overview of the Vim source code. + */ + +/* + * optionstr.c: Functions related to string options + */ + +#include "vim.h" + +static char *(p_ambw_values[]) = {"single", "double", NULL}; +static char *(p_bg_values[]) = {"light", "dark", NULL}; +static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL}; +static char *(p_bo_values[]) = {"all", "backspace", "cursor", "complete", + "copy", "ctrlg", "error", "esc", "ex", + "hangul", "insertmode", "lang", "mess", + "showmatch", "operator", "register", "shell", + "spell", "wildmode", NULL}; +static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL}; +static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL}; +#ifdef FEAT_CRYPT +static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL}; +#endif +static char *(p_cmp_values[]) = {"internal", "keepascii", NULL}; +static char *(p_dy_values[]) = {"lastline", "truncate", "uhex", NULL}; +#ifdef FEAT_FOLDING +static char *(p_fdo_values[]) = {"all", "block", "hor", "mark", "percent", + "quickfix", "search", "tag", "insert", + "undo", "jump", NULL}; +#endif +#ifdef FEAT_SESSION +// Also used for 'viewoptions'! +static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize", + "localoptions", "options", "help", "blank", "globals", "slash", "unix", + "sesdir", "curdir", "folds", "cursor", "tabpages", "terminal", NULL}; +#endif +static char *(p_swb_values[]) = {"useopen", "usetab", "split", "newtab", "vsplit", NULL}; +static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL}; +#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) +static char *(p_toolbar_values[]) = {"text", "icons", "tooltips", "horiz", NULL}; +#endif +#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) +static char *(p_tbis_values[]) = {"tiny", "small", "medium", "large", "huge", "giant", NULL}; +#endif +#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS)) +static char *(p_ttym_values[]) = {"xterm", "xterm2", "dec", "netterm", "jsbterm", "pterm", "urxvt", "sgr", NULL}; +#endif +static char *(p_ve_values[]) = {"block", "insert", "all", "onemore", NULL}; +static char *(p_wop_values[]) = {"tagfile", NULL}; +#ifdef FEAT_WAK +static char *(p_wak_values[]) = {"yes", "menu", "no", NULL}; +#endif +static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL}; +static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL}; +static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL}; +static char *(p_km_values[]) = {"startsel", "stopsel", NULL}; +#ifdef FEAT_BROWSE +static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL}; +#endif +static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL}; +static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL}; +static char *(p_ead_values[]) = {"both", "ver", "hor", NULL}; +static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL}; +static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL}; +static char *(p_bs_values[]) = {"indent", "eol", "start", NULL}; +#ifdef FEAT_FOLDING +static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax", +# ifdef FEAT_DIFF + "diff", +# endif + NULL}; +static char *(p_fcl_values[]) = {"all", NULL}; +#endif +static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "noinsert", "noselect", NULL}; +#ifdef BACKSLASH_IN_FILENAME +static char *(p_csl_values[]) = {"slash", "backslash", NULL}; +#endif +#ifdef FEAT_SIGNS +static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL}; +#endif +#if defined(MSWIN) && defined(FEAT_TERMINAL) +static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL}; +#endif + +static int check_opt_strings(char_u *val, char **values, int list); +static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list); + +/* + * After setting various option values: recompute variables that depend on + * option values. + */ + void +didset_string_options(void) +{ + (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE); + (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE); + (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE); +#ifdef FEAT_SESSION + (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE); + (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE); +#endif +#ifdef FEAT_FOLDING + (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE); +#endif + (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE); + (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE); + (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE); +#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS)) + (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE); +#endif +#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) + (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE); +#endif +#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) + (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE); +#endif +} + +#if defined(FEAT_EVAL) +/* + * Trigger the OptionSet autocommand. + * "opt_idx" is the index of the option being set. + * "opt_flags" can be OPT_LOCAL etc. + * "oldval" the old value + * "oldval_l" the old local value (only non-NULL if global and local value + * are set) + * "oldval_g" the old global value (only non-NULL if global and local value + * are set) + * "newval" the new value + */ + void +trigger_optionsset_string( + int opt_idx, + int opt_flags, + char_u *oldval, + char_u *oldval_l, + char_u *oldval_g, + char_u *newval) +{ + // Don't do this recursively. + if (oldval != NULL && newval != NULL + && *get_vim_var_str(VV_OPTION_TYPE) == NUL) + { + char_u buf_type[7]; + + sprintf((char *)buf_type, "%s", + (opt_flags & OPT_LOCAL) ? "local" : "global"); + set_vim_var_string(VV_OPTION_OLD, oldval, -1); + set_vim_var_string(VV_OPTION_NEW, newval, -1); + set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); + if (opt_flags & OPT_LOCAL) + { + set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1); + set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); + } + if (opt_flags & OPT_GLOBAL) + { + set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1); + set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1); + } + if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) + { + set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1); + set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1); + set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1); + } + if (opt_flags & OPT_MODELINE) + { + set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1); + set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1); + } + apply_autocmds(EVENT_OPTIONSET, + (char_u *)get_option_fullname(opt_idx), NULL, FALSE, + NULL); + reset_v_option_vars(); + } +} +#endif + + static char * +illegal_char(char *errbuf, int c) +{ + if (errbuf == NULL) + return ""; + sprintf((char *)errbuf, _("E539: Illegal character <%s>"), + (char *)transchar(c)); + return errbuf; +} + +/* + * Check string options in a buffer for NULL value. + */ + void +check_buf_options(buf_T *buf) +{ + check_string_option(&buf->b_p_bh); + check_string_option(&buf->b_p_bt); + check_string_option(&buf->b_p_fenc); + check_string_option(&buf->b_p_ff); +#ifdef FEAT_FIND_ID + check_string_option(&buf->b_p_def); + check_string_option(&buf->b_p_inc); +# ifdef FEAT_EVAL + check_string_option(&buf->b_p_inex); +# endif +#endif +#if defined(FEAT_CINDENT) && defined(FEAT_EVAL) + check_string_option(&buf->b_p_inde); + check_string_option(&buf->b_p_indk); +#endif +#if defined(FEAT_BEVAL) && defined(FEAT_EVAL) + check_string_option(&buf->b_p_bexpr); +#endif +#if defined(FEAT_CRYPT) + check_string_option(&buf->b_p_cm); +#endif + check_string_option(&buf->b_p_fp); +#if defined(FEAT_EVAL) + check_string_option(&buf->b_p_fex); +#endif +#ifdef FEAT_CRYPT + check_string_option(&buf->b_p_key); +#endif + check_string_option(&buf->b_p_kp); + check_string_option(&buf->b_p_mps); + check_string_option(&buf->b_p_fo); + check_string_option(&buf->b_p_flp); + check_string_option(&buf->b_p_isk); +#ifdef FEAT_COMMENTS + check_string_option(&buf->b_p_com); +#endif +#ifdef FEAT_FOLDING + check_string_option(&buf->b_p_cms); +#endif + check_string_option(&buf->b_p_nf); +#ifdef FEAT_TEXTOBJ + check_string_option(&buf->b_p_qe); +#endif +#ifdef FEAT_SYN_HL + check_string_option(&buf->b_p_syn); + check_string_option(&buf->b_s.b_syn_isk); +#endif +#ifdef FEAT_SPELL + check_string_option(&buf->b_s.b_p_spc); + check_string_option(&buf->b_s.b_p_spf); + check_string_option(&buf->b_s.b_p_spl); +#endif +#ifdef FEAT_SEARCHPATH + check_string_option(&buf->b_p_sua); +#endif +#ifdef FEAT_CINDENT + check_string_option(&buf->b_p_cink); + check_string_option(&buf->b_p_cino); + parse_cino(buf); +#endif + check_string_option(&buf->b_p_ft); +#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) + check_string_option(&buf->b_p_cinw); +#endif + check_string_option(&buf->b_p_cpt); +#ifdef FEAT_COMPL_FUNC + check_string_option(&buf->b_p_cfu); + check_string_option(&buf->b_p_ofu); +#endif +#ifdef FEAT_EVAL + check_string_option(&buf->b_p_tfu); +#endif +#ifdef FEAT_KEYMAP + check_string_option(&buf->b_p_keymap); +#endif +#ifdef FEAT_QUICKFIX + check_string_option(&buf->b_p_gp); + check_string_option(&buf->b_p_mp); + check_string_option(&buf->b_p_efm); +#endif + check_string_option(&buf->b_p_ep); + check_string_option(&buf->b_p_path); + check_string_option(&buf->b_p_tags); + check_string_option(&buf->b_p_tc); + check_string_option(&buf->b_p_dict); + check_string_option(&buf->b_p_tsr); +#ifdef FEAT_LISP + check_string_option(&buf->b_p_lw); +#endif + check_string_option(&buf->b_p_bkc); + check_string_option(&buf->b_p_menc); +#ifdef FEAT_VARTABS + check_string_option(&buf->b_p_vsts); + check_string_option(&buf->b_p_vts); +#endif +} + +/* + * Free the string allocated for an option. + * Checks for the string being empty_option. This may happen if we're out of + * memory, vim_strsave() returned NULL, which was replaced by empty_option by + * check_options(). + * Does NOT check for P_ALLOCED flag! + */ + void +free_string_option(char_u *p) +{ + if (p != empty_option) + vim_free(p); +} + + void +clear_string_option(char_u **pp) +{ + if (*pp != empty_option) + vim_free(*pp); + *pp = empty_option; +} + + void +check_string_option(char_u **pp) +{ + if (*pp == NULL) + *pp = empty_option; +} + +/* + * 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 +{ + char_u **p, *s; + + // the global value is always allocated + if (is_window_local_option(opt_idx)) + p = (char_u **)GLOBAL_WO(varp); + else + p = (char_u **)get_option_var(opt_idx); + if (!is_global_option(opt_idx) + && p != varp + && (s = vim_strsave(*varp)) != NULL) + { + free_string_option(*p); + *p = s; + } +} + +/* + * 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( + char_u *name, + int opt_idx, + char_u *val, + int opt_flags, // OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL + int set_sid UNUSED) +{ + char_u *s; + char_u **varp; + int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0; + int idx = opt_idx; + + if (idx == -1) // use name + { + idx = findoption(name); + if (idx < 0) // not found (should not happen) + { + semsg(_(e_intern2), "set_string_option_direct()"); + siemsg(_("For option %s"), name); + return; + } + } + + if (is_hidden_option(idx)) // can't set hidden option + return; + + s = vim_strsave(val); + if (s != NULL) + { + varp = (char_u **)get_option_varp_scope(idx, + both ? OPT_LOCAL : opt_flags); + if ((opt_flags & OPT_FREE) && (get_option_flags(idx) & P_ALLOCED)) + free_string_option(*varp); + *varp = s; + + // For buffer/window local option may also set the global value. + if (both) + set_string_option_global(idx, varp); + + set_option_flag(idx, P_ALLOCED); + + // When setting both values of a global option with a local value, + // make the local value empty, so that the global value is used. + if (is_global_local_option(idx) && both) + { + free_string_option(*varp); + *varp = empty_option; + } +# ifdef FEAT_EVAL + if (set_sid != SID_NONE) + { + sctx_T script_ctx; + + if (set_sid == 0) + script_ctx = current_sctx; + else + { + script_ctx.sc_sid = set_sid; + script_ctx.sc_seq = 0; + script_ctx.sc_lnum = 0; + script_ctx.sc_version = 1; + } + set_option_sctx_idx(idx, opt_flags, script_ctx); + } +# endif + } +} + +/* + * Like set_string_option_direct(), but for a window-local option in "wp". + * Blocks autocommands to avoid the old curwin becoming invalid. + */ + void +set_string_option_direct_in_win( + win_T *wp, + char_u *name, + int opt_idx, + char_u *val, + int opt_flags, + int set_sid) +{ + win_T *save_curwin = curwin; + + block_autocmds(); + curwin = wp; + curbuf = curwin->w_buffer; + set_string_option_direct(name, opt_idx, val, opt_flags, set_sid); + curwin = save_curwin; + curbuf = curwin->w_buffer; + unblock_autocmds(); +} + +/* + * Like set_string_option_direct(), but for a buffer-local option in "buf". + * Blocks autocommands to avoid the old curbuf becoming invalid. + */ + void +set_string_option_direct_in_buf( + buf_T *buf, + char_u *name, + int opt_idx, + char_u *val, + int opt_flags, + int set_sid) +{ + buf_T *save_curbuf = curbuf; + + block_autocmds(); + curbuf = buf; + curwin->w_buffer = curbuf; + set_string_option_direct(name, opt_idx, val, opt_flags, set_sid); + curbuf = save_curbuf; + curwin->w_buffer = curbuf; + unblock_autocmds(); +} + +/* + * Set a string option to a new value, and handle the effects. + * + * Returns NULL on success or error message on error. + */ + char * +set_string_option( + int opt_idx, + char_u *value, + int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL +{ + char_u *s; + char_u **varp; + char_u *oldval; +#if defined(FEAT_EVAL) + char_u *oldval_l = NULL; + char_u *oldval_g = NULL; + char_u *saved_oldval = NULL; + char_u *saved_oldval_l = NULL; + char_u *saved_oldval_g = NULL; + char_u *saved_newval = NULL; +#endif + char *r = NULL; + int value_checked = FALSE; + + if (is_hidden_option(opt_idx)) // don't set hidden option + return NULL; + + s = vim_strsave(value); + if (s != NULL) + { + varp = (char_u **)get_option_varp_scope(opt_idx, + (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 + ? (is_global_local_option(opt_idx) + ? OPT_GLOBAL : OPT_LOCAL) + : opt_flags); + oldval = *varp; +#if defined(FEAT_EVAL) + if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) + { + oldval_l = *(char_u **)get_option_varp_scope(opt_idx, OPT_LOCAL); + oldval_g = *(char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL); + } +#endif + *varp = s; + +#if defined(FEAT_EVAL) + if (!starting +# ifdef FEAT_CRYPT + && !is_crypt_key_option(opt_idx) +# endif + ) + { + if (oldval_l != NULL) + saved_oldval_l = vim_strsave(oldval_l); + if (oldval_g != NULL) + saved_oldval_g = vim_strsave(oldval_g); + saved_oldval = vim_strsave(oldval); + saved_newval = vim_strsave(s); + } +#endif + if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, + opt_flags, &value_checked)) == NULL) + did_set_option(opt_idx, opt_flags, TRUE, value_checked); + +#if defined(FEAT_EVAL) + // call autocommand after handling side effects + if (r == NULL) + trigger_optionsset_string(opt_idx, opt_flags, + saved_oldval, saved_oldval_l, + saved_oldval_g, saved_newval); + vim_free(saved_oldval); + vim_free(saved_oldval_l); + vim_free(saved_oldval_g); + vim_free(saved_newval); +#endif + } + return r; +} + +/* + * Return TRUE if "val" is a valid 'filetype' name. + * Also used for 'syntax' and 'keymap'. + */ + static int +valid_filetype(char_u *val) +{ + return valid_name(val, ".-_"); +} + +#ifdef FEAT_STL_OPT +/* + * Check validity of options with the 'statusline' format. + * Return error message or NULL. + */ + static char * +check_stl_option(char_u *s) +{ + int itemcnt = 0; + int groupdepth = 0; + static char errbuf[80]; + + while (*s && itemcnt < STL_MAX_ITEM) + { + // Check for valid keys after % sequences + while (*s && *s != '%') + s++; + if (!*s) + break; + s++; + if (*s != '%' && *s != ')') + ++itemcnt; + if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK) + { + s++; + continue; + } + if (*s == ')') + { + s++; + if (--groupdepth < 0) + break; + continue; + } + if (*s == '-') + s++; + while (VIM_ISDIGIT(*s)) + s++; + if (*s == STL_USER_HL) + continue; + if (*s == '.') + { + s++; + while (*s && VIM_ISDIGIT(*s)) + s++; + } + if (*s == '(') + { + groupdepth++; + continue; + } + if (vim_strchr(STL_ALL, *s) == NULL) + { + return illegal_char(errbuf, *s); + } + if (*s == '{') + { + s++; + while (*s != '}' && *s) + s++; + if (*s != '}') + return N_("E540: Unclosed expression sequence"); + } + } + if (itemcnt >= STL_MAX_ITEM) + return N_("E541: too many items"); + if (groupdepth != 0) + return N_("E542: unbalanced groups"); + return NULL; +} +#endif + +/* + * Handle string options that need some action to perform when changed. + * Returns NULL for success, or an error message for an error. + */ + char * +did_set_string_option( + int opt_idx, // index in options[] table + char_u **varp, // pointer to the option variable + int new_value_alloced, // new value was allocated + char_u *oldval, // previous value of the option + char *errbuf, // buffer for errors, or NULL + int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL + int *value_checked) // value was checked to be save, no + // need to set P_INSECURE +{ + char *errmsg = NULL; + char_u *s, *p; + int did_chartab = FALSE; + char_u **gvarp; + long_u free_oldval = (get_option_flags(opt_idx) & P_ALLOCED); +#ifdef FEAT_GUI + // set when changing an option that only requires a redraw in the GUI + int redraw_gui_only = FALSE; +#endif + int value_changed = FALSE; +#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) + int did_swaptcap = FALSE; +#endif + + // Get the global option to compare with, otherwise we would have to check + // two values for all local options. + gvarp = (char_u **)get_option_varp_scope(opt_idx, OPT_GLOBAL); + + // Disallow changing some options from secure mode + if ((secure +#ifdef HAVE_SANDBOX + || sandbox != 0 +#endif + ) && (get_option_flags(opt_idx) & P_SECURE)) + errmsg = e_secure; + + // Check for a "normal" directory or file name in some options. Disallow a + // path separator (slash and/or backslash), wildcards and characters that + // are often illegal in a file name. Be more permissive if "secure" is off. + else if (((get_option_flags(opt_idx) & P_NFNAME) + && vim_strpbrk(*varp, (char_u *)(secure + ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL) + || ((get_option_flags(opt_idx) & P_NDNAME) + && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL)) + errmsg = e_invarg; + + // 'term' + else if (varp == &T_NAME) + { + if (T_NAME[0] == NUL) + errmsg = N_("E529: Cannot set 'term' to empty string"); +#ifdef FEAT_GUI + if (gui.in_use) + errmsg = N_("E530: Cannot change term in GUI"); + else if (term_is_gui(T_NAME)) + errmsg = N_("E531: Use \":gui\" to start the GUI"); +#endif + else if (set_termname(T_NAME) == FAIL) + errmsg = N_("E522: Not found in termcap"); + else + { + // Screen colors may have changed. + redraw_later_clear(); + + // Both 'term' and 'ttytype' point to T_NAME, only set the + // P_ALLOCED flag on 'term'. + opt_idx = findoption((char_u *)"term"); + free_oldval = (get_option_flags(opt_idx) & P_ALLOCED); + } + } + + // 'backupcopy' + else if (gvarp == &p_bkc) + { + char_u *bkc = p_bkc; + unsigned int *flags = &bkc_flags; + + if (opt_flags & OPT_LOCAL) + { + bkc = curbuf->b_p_bkc; + flags = &curbuf->b_bkc_flags; + } + + if ((opt_flags & OPT_LOCAL) && *bkc == NUL) + // make the local value empty: use the global value + *flags = 0; + else + { + if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK) + errmsg = e_invarg; + if ((((int)*flags & BKC_AUTO) != 0) + + (((int)*flags & BKC_YES) != 0) + + (((int)*flags & BKC_NO) != 0) != 1) + { + // Must have exactly one of "auto", "yes" and "no". + (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE); + errmsg = e_invarg; + } + } + } + + // 'backupext' and 'patchmode' + else if (varp == &p_bex || varp == &p_pm) + { + if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex, + *p_pm == '.' ? p_pm + 1 : p_pm) == 0) + errmsg = N_("E589: 'backupext' and 'patchmode' are equal"); + } +#ifdef FEAT_LINEBREAK + // 'breakindentopt' + else if (varp == &curwin->w_p_briopt) + { + if (briopt_check(curwin) == FAIL) + errmsg = e_invarg; + } +#endif + + // 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[] + // If the new option is invalid, use old value. 'lisp' option: refill + // g_chartab[] for '-' char + else if ( varp == &p_isi + || varp == &(curbuf->b_p_isk) + || varp == &p_isp + || varp == &p_isf) + { + if (init_chartab() == FAIL) + { + did_chartab = TRUE; // need to restore it below + errmsg = e_invarg; // error in value + } + } + + // 'helpfile' + else if (varp == &p_hf) + { + // May compute new values for $VIM and $VIMRUNTIME + if (didset_vim) + { + vim_setenv((char_u *)"VIM", (char_u *)""); + didset_vim = FALSE; + } + if (didset_vimruntime) + { + vim_setenv((char_u *)"VIMRUNTIME", (char_u *)""); + didset_vimruntime = FALSE; + } + } + +#ifdef FEAT_SYN_HL + // 'cursorlineopt' + else if (varp == &curwin->w_p_culopt + || gvarp == &curwin->w_allbuf_opt.wo_culopt) + { + if (**varp == NUL || fill_culopt_flags(*varp, curwin) != OK) + errmsg = e_invarg; + } + + // 'colorcolumn' + else if (varp == &curwin->w_p_cc) + errmsg = check_colorcolumn(curwin); +#endif + +#ifdef FEAT_MULTI_LANG + // 'helplang' + else if (varp == &p_hlg) + { + // Check for "", "ab", "ab,cd", etc. + for (s = p_hlg; *s != NUL; s += 3) + { + if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL)) + { + errmsg = e_invarg; + break; + } + if (s[2] == NUL) + break; + } + } +#endif + + // 'highlight' + else if (varp == &p_hl) + { + if (highlight_changed() == FAIL) + errmsg = e_invarg; // invalid flags + } + + // 'nrformats' + else if (gvarp == &p_nf) + { + if (check_opt_strings(*varp, p_nf_values, TRUE) != OK) + errmsg = e_invarg; + } + +#ifdef FEAT_SESSION + // 'sessionoptions' + else if (varp == &p_ssop) + { + if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK) + errmsg = e_invarg; + if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR)) + { + // Don't allow both "sesdir" and "curdir". + (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE); + errmsg = e_invarg; + } + } + // 'viewoptions' + else if (varp == &p_vop) + { + if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK) + errmsg = e_invarg; + } +#endif + + // 'scrollopt' + else if (varp == &p_sbo) + { + if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK) + errmsg = e_invarg; + } + + // 'ambiwidth' + else if (varp == &p_ambw || varp == &p_emoji) + { + if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) + errmsg = e_invarg; + else if (set_chars_option(&p_lcs) != NULL) + errmsg = _("E834: Conflicts with value of 'listchars'"); + else if (set_chars_option(&p_fcs) != NULL) + errmsg = _("E835: Conflicts with value of 'fillchars'"); + } + + // 'background' + else if (varp == &p_bg) + { + if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK) + { +#ifdef FEAT_EVAL + int dark = (*p_bg == 'd'); +#endif + + init_highlight(FALSE, FALSE); + +#ifdef FEAT_EVAL + if (dark != (*p_bg == 'd') + && get_var_value((char_u *)"g:colors_name") != NULL) + { + // The color scheme must have set 'background' back to another + // value, that's not what we want here. Disable the color + // scheme and set the colors again. + do_unlet((char_u *)"g:colors_name", TRUE); + free_string_option(p_bg); + p_bg = vim_strsave((char_u *)(dark ? "dark" : "light")); + check_string_option(&p_bg); + init_highlight(FALSE, FALSE); + } +#endif + } + else + errmsg = e_invarg; + } + + // 'wildmode' + else if (varp == &p_wim) + { + if (check_opt_wim() == FAIL) + errmsg = e_invarg; + } + + // 'wildoptions' + else if (varp == &p_wop) + { + if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK) + errmsg = e_invarg; + } + +#ifdef FEAT_WAK + // 'winaltkeys' + else if (varp == &p_wak) + { + if (*p_wak == NUL + || check_opt_strings(p_wak, p_wak_values, FALSE) != OK) + errmsg = e_invarg; +# ifdef FEAT_MENU +# ifdef FEAT_GUI_MOTIF + else if (gui.in_use) + gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); +# else +# ifdef FEAT_GUI_GTK + else if (gui.in_use) + gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm'); +# endif +# endif +# endif + } +#endif + + // 'eventignore' + else if (varp == &p_ei) + { + if (check_ei() == FAIL) + errmsg = e_invarg; + } + + // 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' + else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc + || gvarp == &p_menc) + { + if (gvarp == &p_fenc) + { + if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL) + errmsg = e_modifiable; + else if (vim_strchr(*varp, ',') != NULL) + // No comma allowed in 'fileencoding'; catches confusing it + // with 'fileencodings'. + errmsg = e_invarg; + else + { +#ifdef FEAT_TITLE + // May show a "+" in the title now. + redraw_titles(); +#endif + // Add 'fileencoding' to the swap file. + ml_setflags(curbuf); + } + } + if (errmsg == NULL) + { + // canonize the value, so that STRCMP() can be used on it + p = enc_canonize(*varp); + if (p != NULL) + { + vim_free(*varp); + *varp = p; + } + if (varp == &p_enc) + { + errmsg = mb_init(); +#ifdef FEAT_TITLE + redraw_titles(); +#endif + } + } + +#if defined(FEAT_GUI_GTK) + if (errmsg == NULL && varp == &p_tenc && gui.in_use) + { + // GTK+ 2 uses only a single encoding, and that is UTF-8. + if (STRCMP(p_tenc, "utf-8") != 0) + errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI"); + } +#endif + + if (errmsg == NULL) + { +#ifdef FEAT_KEYMAP + // When 'keymap' is used and 'encoding' changes, reload the keymap + // (with another encoding). + if (varp == &p_enc && *curbuf->b_p_keymap != NUL) + (void)keymap_init(); +#endif + + // When 'termencoding' is not empty and 'encoding' changes or when + // 'termencoding' changes, need to setup for keyboard input and + // display output conversion. + if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc)) + { + if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL + || convert_setup(&output_conv, p_enc, p_tenc) == FAIL) + { + semsg(_("E950: Cannot convert between %s and %s"), + p_tenc, p_enc); + errmsg = e_invarg; + } + } + +#if defined(MSWIN) + // $HOME may have characters in active code page. + if (varp == &p_enc) + init_homedir(); +#endif + } + } + +#if defined(FEAT_POSTSCRIPT) + else if (varp == &p_penc) + { + // Canonize printencoding if VIM standard one + p = enc_canonize(p_penc); + if (p != NULL) + { + vim_free(p_penc); + p_penc = p; + } + else + { + // Ensure lower case and '-' for '_' + for (s = p_penc; *s != NUL; s++) + { + if (*s == '_') + *s = '-'; + else + *s = TOLOWER_ASC(*s); + } + } + } +#endif + +#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) + else if (varp == &p_imak) + { + if (!im_xim_isvalid_imactivate()) + errmsg = e_invarg; + } +#endif + +#ifdef FEAT_KEYMAP + else if (varp == &curbuf->b_p_keymap) + { + if (!valid_filetype(*varp)) + errmsg = e_invarg; + else + { + int secure_save = secure; + + // Reset the secure flag, since the value of 'keymap' has + // been checked to be safe. + secure = 0; + + // load or unload key mapping tables + errmsg = keymap_init(); + + secure = secure_save; + + // Since we check the value, there is no need to set P_INSECURE, + // even when the value comes from a modeline. + *value_checked = TRUE; + } + + if (errmsg == NULL) + { + if (*curbuf->b_p_keymap != NUL) + { + // Installed a new keymap, switch on using it. + curbuf->b_p_iminsert = B_IMODE_LMAP; + if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT) + curbuf->b_p_imsearch = B_IMODE_LMAP; + } + else + { + // Cleared the keymap, may reset 'iminsert' and 'imsearch'. + if (curbuf->b_p_iminsert == B_IMODE_LMAP) + curbuf->b_p_iminsert = B_IMODE_NONE; + if (curbuf->b_p_imsearch == B_IMODE_LMAP) + curbuf->b_p_imsearch = B_IMODE_USE_INSERT; + } + if ((opt_flags & OPT_LOCAL) == 0) + { + set_iminsert_global(); + set_imsearch_global(); + } + status_redraw_curbuf(); + } + } +#endif + + // 'fileformat' + else if (gvarp == &p_ff) + { + if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL)) + errmsg = e_modifiable; + else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK) + errmsg = e_invarg; + else + { + // may also change 'textmode' + if (get_fileformat(curbuf) == EOL_DOS) + curbuf->b_p_tx = TRUE; + else + curbuf->b_p_tx = FALSE; +#ifdef FEAT_TITLE + redraw_titles(); +#endif + // update flag in swap file + ml_setflags(curbuf); + // Redraw needed when switching to/from "mac": a CR in the text + // will be displayed differently. + if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm') + redraw_curbuf_later(NOT_VALID); + } + } + + // 'fileformats' + else if (varp == &p_ffs) + { + if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK) + errmsg = e_invarg; + else + { + // also change 'textauto' + if (*p_ffs == NUL) + p_ta = FALSE; + else + p_ta = TRUE; + } + } + +#if defined(FEAT_CRYPT) + // 'cryptkey' + else if (gvarp == &p_key) + { + // Make sure the ":set" command doesn't show the new value in the + // history. + remove_key_from_history(); + + if (STRCMP(curbuf->b_p_key, oldval) != 0) + // Need to update the swapfile. + ml_set_crypt_key(curbuf, oldval, + *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm); + } + + else if (gvarp == &p_cm) + { + if (opt_flags & OPT_LOCAL) + p = curbuf->b_p_cm; + else + p = p_cm; + if (check_opt_strings(p, p_cm_values, TRUE) != OK) + errmsg = e_invarg; + else if (crypt_self_test() == FAIL) + errmsg = e_invarg; + else + { + // When setting the global value to empty, make it "zip". + if (*p_cm == NUL) + { + if (new_value_alloced) + free_string_option(p_cm); + p_cm = vim_strsave((char_u *)"zip"); + new_value_alloced = TRUE; + } + // When using ":set cm=name" the local value is going to be empty. + // Do that here, otherwise the crypt functions will still use the + // local value. + if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) + { + free_string_option(curbuf->b_p_cm); + curbuf->b_p_cm = empty_option; + } + + // Need to update the swapfile when the effective method changed. + // Set "s" to the effective old value, "p" to the effective new + // method and compare. + if ((opt_flags & OPT_LOCAL) && *oldval == NUL) + s = p_cm; // was previously using the global value + else + s = oldval; + if (*curbuf->b_p_cm == NUL) + p = p_cm; // is now using the global value + else + p = curbuf->b_p_cm; + if (STRCMP(s, p) != 0) + ml_set_crypt_key(curbuf, curbuf->b_p_key, s); + + // If the global value changes need to update the swapfile for all + // buffers using that value. + if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0) + { + buf_T *buf; + + FOR_ALL_BUFFERS(buf) + if (buf != curbuf && *buf->b_p_cm == NUL) + ml_set_crypt_key(buf, buf->b_p_key, oldval); + } + } + } +#endif + + // 'matchpairs' + else if (gvarp == &p_mps) + { + if (has_mbyte) + { + for (p = *varp; *p != NUL; ++p) + { + int x2 = -1; + int x3 = -1; + + if (*p != NUL) + p += mb_ptr2len(p); + if (*p != NUL) + x2 = *p++; + if (*p != NUL) + { + x3 = mb_ptr2char(p); + p += mb_ptr2len(p); + } + if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) + { + errmsg = e_invarg; + break; + } + if (*p == NUL) + break; + } + } + else + { + // Check for "x:y,x:y" + for (p = *varp; *p != NUL; p += 4) + { + if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ',')) + { + errmsg = e_invarg; + break; + } + if (p[3] == NUL) + break; + } + } + } + +#ifdef FEAT_COMMENTS + // 'comments' + else if (gvarp == &p_com) + { + for (s = *varp; *s; ) + { + while (*s && *s != ':') + { + if (vim_strchr((char_u *)COM_ALL, *s) == NULL + && !VIM_ISDIGIT(*s) && *s != '-') + { + errmsg = illegal_char(errbuf, *s); + break; + } + ++s; + } + if (*s++ == NUL) + errmsg = N_("E524: Missing colon"); + else if (*s == ',' || *s == NUL) + errmsg = N_("E525: Zero length string"); + if (errmsg != NULL) + break; + while (*s && *s != ',') + { + if (*s == '\\' && s[1] != NUL) + ++s; + ++s; + } + s = skip_to_option_part(s); + } + } +#endif + + // 'listchars' + else if (varp == &p_lcs) + { + errmsg = set_chars_option(varp); + } + + // 'fillchars' + else if (varp == &p_fcs) + { + errmsg = set_chars_option(varp); + } + +#ifdef FEAT_CMDWIN + // 'cedit' + else if (varp == &p_cedit) + { + errmsg = check_cedit(); + } +#endif + + // 'verbosefile' + else if (varp == &p_vfile) + { + verbose_stop(); + if (*p_vfile != NUL && verbose_open() == FAIL) + errmsg = e_invarg; + } + +#ifdef FEAT_VIMINFO + // 'viminfo' + else if (varp == &p_viminfo) + { + for (s = p_viminfo; *s;) + { + // Check it's a valid character + if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL) + { + errmsg = illegal_char(errbuf, *s); + break; + } + if (*s == 'n') // name is always last one + break; + else if (*s == 'r') // skip until next ',' + { + while (*++s && *s != ',') + ; + } + else if (*s == '%') + { + // optional number + while (vim_isdigit(*++s)) + ; + } + else if (*s == '!' || *s == 'h' || *s == 'c') + ++s; // no extra chars + else // must have a number + { + while (vim_isdigit(*++s)) + ; + + if (!VIM_ISDIGIT(*(s - 1))) + { + if (errbuf != NULL) + { + sprintf(errbuf, _("E526: Missing number after <%s>"), + transchar_byte(*(s - 1))); + errmsg = errbuf; + } + else + errmsg = ""; + break; + } + } + if (*s == ',') + ++s; + else if (*s) + { + if (errbuf != NULL) + errmsg = N_("E527: Missing comma"); + else + errmsg = ""; + break; + } + } + if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0) + errmsg = N_("E528: Must specify a ' value"); + } +#endif // FEAT_VIMINFO + + // terminal options + else if (istermoption_idx(opt_idx) && full_screen) + { + // ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" + if (varp == &T_CCO) + { + int colors = atoi((char *)T_CCO); + + // Only reinitialize colors if t_Co value has really changed to + // avoid expensive reload of colorscheme if t_Co is set to the + // same value multiple times. + if (colors != t_colors) + { + t_colors = colors; + if (t_colors <= 1) + { + if (new_value_alloced) + vim_free(T_CCO); + T_CCO = empty_option; + } +#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) + if (is_term_win32()) + { + swap_tcap(); + did_swaptcap = TRUE; + } +#endif + // We now have a different color setup, initialize it again. + init_highlight(TRUE, FALSE); + } + } + ttest(FALSE); + if (varp == &T_ME) + { + out_str(T_ME); + redraw_later(CLEAR); +#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) + // Since t_me has been set, this probably means that the user + // wants to use this as default colors. Need to reset default + // background/foreground colors. +# ifdef VIMDLL + if (!gui.in_use && !gui.starting) +# endif + mch_set_normal_colors(); +#endif + } + if (varp == &T_BE && termcap_active) + { + if (*T_BE == NUL) + // When clearing t_BE we assume the user no longer wants + // bracketed paste, thus disable it by writing t_BD. + out_str(T_BD); + else + out_str(T_BE); + } + } + +#ifdef FEAT_LINEBREAK + // 'showbreak' + else if (varp == &p_sbr) + { + for (s = p_sbr; *s; ) + { + if (ptr2cells(s) != 1) + errmsg = N_("E595: contains unprintable or wide character"); + MB_PTR_ADV(s); + } + } +#endif + +#ifdef FEAT_GUI + // 'guifont' + else if (varp == &p_guifont) + { + if (gui.in_use) + { + p = p_guifont; +# if defined(FEAT_GUI_GTK) + // Put up a font dialog and let the user select a new value. + // If this is cancelled go back to the old value but don't + // give an error message. + if (STRCMP(p, "*") == 0) + { + p = gui_mch_font_dialog(oldval); + + if (new_value_alloced) + free_string_option(p_guifont); + + p_guifont = (p != NULL) ? p : vim_strsave(oldval); + new_value_alloced = TRUE; + } +# endif + if (p != NULL && gui_init_font(p_guifont, FALSE) != OK) + { +# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON) + if (STRCMP(p_guifont, "*") == 0) + { + // Dialog was cancelled: Keep the old value without giving + // an error message. + if (new_value_alloced) + free_string_option(p_guifont); + p_guifont = vim_strsave(oldval); + new_value_alloced = TRUE; + } + else +# endif + errmsg = N_("E596: Invalid font(s)"); + } + } + redraw_gui_only = TRUE; + } +# ifdef FEAT_XFONTSET + else if (varp == &p_guifontset) + { + if (STRCMP(p_guifontset, "*") == 0) + errmsg = N_("E597: can't select fontset"); + else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK) + errmsg = N_("E598: Invalid fontset"); + redraw_gui_only = TRUE; + } +# endif + else if (varp == &p_guifontwide) + { + if (STRCMP(p_guifontwide, "*") == 0) + errmsg = N_("E533: can't select wide font"); + else if (gui_get_wide_font() == FAIL) + errmsg = N_("E534: Invalid wide font"); + redraw_gui_only = TRUE; + } +#endif + +#ifdef CURSOR_SHAPE + // 'guicursor' + else if (varp == &p_guicursor) + errmsg = parse_shape_opt(SHAPE_CURSOR); +#endif + +#ifdef FEAT_MOUSESHAPE + // 'mouseshape' + else if (varp == &p_mouseshape) + { + errmsg = parse_shape_opt(SHAPE_MOUSE); + update_mouseshape(-1); + } +#endif + +#ifdef FEAT_PRINTER + else if (varp == &p_popt) + errmsg = parse_printoptions(); +# if defined(FEAT_POSTSCRIPT) + else if (varp == &p_pmfn) + errmsg = parse_printmbfont(); +# endif +#endif + +#ifdef FEAT_LANGMAP + // 'langmap' + else if (varp == &p_langmap) + langmap_set(); +#endif + +#ifdef FEAT_LINEBREAK + // 'breakat' + else if (varp == &p_breakat) + fill_breakat_flags(); +#endif + +#ifdef FEAT_TITLE + // 'titlestring' and 'iconstring' + else if (varp == &p_titlestring || varp == &p_iconstring) + { +# ifdef FEAT_STL_OPT + int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON; + + // NULL => statusline syntax + if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL) + stl_syntax |= flagval; + else + stl_syntax &= ~flagval; +# endif + did_set_title(); + } +#endif + +#ifdef FEAT_GUI + // 'guioptions' + else if (varp == &p_go) + { + gui_init_which_components(oldval); + redraw_gui_only = TRUE; + } +#endif + +#if defined(FEAT_GUI_TABLINE) + // 'guitablabel' + else if (varp == &p_gtl) + { + redraw_tabline = TRUE; + redraw_gui_only = TRUE; + } + // 'guitabtooltip' + else if (varp == &p_gtt) + { + redraw_gui_only = TRUE; + } +#endif + +#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS)) + // 'ttymouse' + else if (varp == &p_ttym) + { + // Switch the mouse off before changing the escape sequences used for + // that. + mch_setmouse(FALSE); + if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK) + errmsg = e_invarg; + else + check_mouse_termcode(); + if (termcap_active) + setmouse(); // may switch it on again + } +#endif + + // 'selection' + else if (varp == &p_sel) + { + if (*p_sel == NUL + || check_opt_strings(p_sel, p_sel_values, FALSE) != OK) + errmsg = e_invarg; + } + + // 'selectmode' + else if (varp == &p_slm) + { + if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK) + errmsg = e_invarg; + } + +#ifdef FEAT_BROWSE + // 'browsedir' + else if (varp == &p_bsdir) + { + if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK + && !mch_isdir(p_bsdir)) + errmsg = e_invarg; + } +#endif + + // 'keymodel' + else if (varp == &p_km) + { + if (check_opt_strings(p_km, p_km_values, TRUE) != OK) + errmsg = e_invarg; + else + { + km_stopsel = (vim_strchr(p_km, 'o') != NULL); + km_startsel = (vim_strchr(p_km, 'a') != NULL); + } + } + + // 'mousemodel' + else if (varp == &p_mousem) + { + if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK) + errmsg = e_invarg; +#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002) + else if (*p_mousem != *oldval) + // Changed from "extend" to "popup" or "popup_setpos" or vv: need + // to create or delete the popup menus. + gui_motif_update_mousemodel(root_menu); +#endif + } + + // 'switchbuf' + else if (varp == &p_swb) + { + if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK) + errmsg = e_invarg; + } + + // 'debug' + else if (varp == &p_debug) + { + if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK) + errmsg = e_invarg; + } + + // 'display' + else if (varp == &p_dy) + { + if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK) + errmsg = e_invarg; + else + (void)init_chartab(); + + } + + // 'eadirection' + else if (varp == &p_ead) + { + if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK) + errmsg = e_invarg; + } + +#ifdef FEAT_CLIPBOARD + // 'clipboard' + else if (varp == &p_cb) + errmsg = check_clipboard_option(); +#endif + +#ifdef FEAT_SPELL + // When 'spelllang' or 'spellfile' is set and there is a window for this + // buffer in which 'spell' is set load the wordlists. + else if (varp == &(curwin->w_s->b_p_spl) + || varp == &(curwin->w_s->b_p_spf)) + { + int is_spellfile = varp == &(curwin->w_s->b_p_spf); + + if ((is_spellfile && !valid_spellfile(*varp)) + || (!is_spellfile && !valid_spellang(*varp))) + errmsg = e_invarg; + else + errmsg = did_set_spell_option(is_spellfile); + } + // When 'spellcapcheck' is set compile the regexp program. + else if (varp == &(curwin->w_s->b_p_spc)) + { + errmsg = compile_cap_prog(curwin->w_s); + } + // 'spellsuggest' + else if (varp == &p_sps) + { + if (spell_check_sps() != OK) + errmsg = e_invarg; + } + // 'mkspellmem' + else if (varp == &p_msm) + { + if (spell_check_msm() != OK) + errmsg = e_invarg; + } +#endif + + // When 'bufhidden' is set, check for valid value. + else if (gvarp == &p_bh) + { + if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK) + errmsg = e_invarg; + } + + // When 'buftype' is set, check for valid value. + else if (gvarp == &p_bt) + { + if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK) + errmsg = e_invarg; + else + { + if (curwin->w_status_height) + { + curwin->w_redr_status = TRUE; + redraw_later(VALID); + } + curbuf->b_help = (curbuf->b_p_bt[0] == 'h'); +#ifdef FEAT_TITLE + redraw_titles(); +#endif + } + } + +#ifdef FEAT_STL_OPT + // 'statusline' or 'rulerformat' + else if (gvarp == &p_stl || varp == &p_ruf) + { + int wid; + + if (varp == &p_ruf) // reset ru_wid first + ru_wid = 0; + s = *varp; + if (varp == &p_ruf && *s == '%') + { + // set ru_wid if 'ruf' starts with "%99(" + if (*++s == '-') // ignore a '-' + s++; + wid = getdigits(&s); + if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL) + ru_wid = wid; + else + errmsg = check_stl_option(p_ruf); + } + // check 'statusline' only if it doesn't start with "%!" + else if (varp == &p_ruf || s[0] != '%' || s[1] != '!') + errmsg = check_stl_option(s); + if (varp == &p_ruf && errmsg == NULL) + comp_col(); + } +#endif + + // check if it is a valid value for 'complete' -- Acevedo + else if (gvarp == &p_cpt) + { + for (s = *varp; *s;) + { + while (*s == ',' || *s == ' ') + s++; + if (!*s) + break; + if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL) + { + errmsg = illegal_char(errbuf, *s); + break; + } + if (*++s != NUL && *s != ',' && *s != ' ') + { + if (s[-1] == 'k' || s[-1] == 's') + { + // skip optional filename after 'k' and 's' + while (*s && *s != ',' && *s != ' ') + { + if (*s == '\\' && s[1] != NUL) + ++s; + ++s; + } + } + else + { + if (errbuf != NULL) + { + sprintf((char *)errbuf, + _("E535: Illegal character after <%c>"), + *--s); + errmsg = errbuf; + } + else + errmsg = ""; + break; + } + } + } + } + + // 'completeopt' + else if (varp == &p_cot) + { + if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK) + errmsg = e_invarg; + else + completeopt_was_set(); + } + +#ifdef BACKSLASH_IN_FILENAME + // 'completeslash' + else if (gvarp == &p_csl) + { + if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK + || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK) + errmsg = e_invarg; + } +#endif + +#ifdef FEAT_SIGNS + // 'signcolumn' + else if (varp == &curwin->w_p_scl) + { + if (check_opt_strings(*varp, p_scl_values, FALSE) != OK) + errmsg = e_invarg; + // When changing the 'signcolumn' to or from 'number', recompute the + // width of the number column if 'number' or 'relativenumber' is set. + if (((*oldval == 'n' && *(oldval + 1) == 'u') + || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u')) + && (curwin->w_p_nu || curwin->w_p_rnu)) + curwin->w_nrwidth_line_count = 0; + } +#endif + + +#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) + // 'toolbar' + else if (varp == &p_toolbar) + { + if (opt_strings_flags(p_toolbar, p_toolbar_values, + &toolbar_flags, TRUE) != OK) + errmsg = e_invarg; + else + { + out_flush(); + gui_mch_show_toolbar((toolbar_flags & + (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); + } + } +#endif + +#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK) + // 'toolbariconsize': GTK+ 2 only + else if (varp == &p_tbis) + { + if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK) + errmsg = e_invarg; + else + { + out_flush(); + gui_mch_show_toolbar((toolbar_flags & + (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0); + } + } +#endif + + // 'pastetoggle': translate key codes like in a mapping + else if (varp == &p_pt) + { + if (*p_pt) + { + (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE); + if (p != NULL) + { + if (new_value_alloced) + free_string_option(p_pt); + p_pt = p; + new_value_alloced = TRUE; + } + } + } + + // 'backspace' + else if (varp == &p_bs) + { + if (VIM_ISDIGIT(*p_bs)) + { + if (*p_bs > '2' || p_bs[1] != NUL) + errmsg = e_invarg; + } + else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK) + errmsg = e_invarg; + } + else if (varp == &p_bo) + { + if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK) + errmsg = e_invarg; + } + + // 'tagcase' + else if (gvarp == &p_tc) + { + unsigned int *flags; + + if (opt_flags & OPT_LOCAL) + { + p = curbuf->b_p_tc; + flags = &curbuf->b_tc_flags; + } + else + { + p = p_tc; + flags = &tc_flags; + } + + if ((opt_flags & OPT_LOCAL) && *p == NUL) + // make the local value empty: use the global value + *flags = 0; + else if (*p == NUL + || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK) + errmsg = e_invarg; + } + + // 'casemap' + else if (varp == &p_cmp) + { + if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK) + errmsg = e_invarg; + } + +#ifdef FEAT_DIFF + // 'diffopt' + else if (varp == &p_dip) + { + if (diffopt_changed() == FAIL) + errmsg = e_invarg; + } +#endif + +#ifdef FEAT_FOLDING + // 'foldmethod' + else if (gvarp == &curwin->w_allbuf_opt.wo_fdm) + { + if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK + || *curwin->w_p_fdm == NUL) + errmsg = e_invarg; + else + { + foldUpdateAll(curwin); + if (foldmethodIsDiff(curwin)) + newFoldLevel(); + } + } +# ifdef FEAT_EVAL + // 'foldexpr' + else if (varp == &curwin->w_p_fde) + { + if (foldmethodIsExpr(curwin)) + foldUpdateAll(curwin); + } +# endif + // 'foldmarker' + else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) + { + p = vim_strchr(*varp, ','); + if (p == NULL) + errmsg = N_("E536: comma required"); + else if (p == *varp || p[1] == NUL) + errmsg = e_invarg; + else if (foldmethodIsMarker(curwin)) + foldUpdateAll(curwin); + } + // 'commentstring' + else if (gvarp == &p_cms) + { + if (**varp != NUL && strstr((char *)*varp, "%s") == NULL) + errmsg = N_("E537: 'commentstring' must be empty or contain %s"); + } + // 'foldopen' + else if (varp == &p_fdo) + { + if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK) + errmsg = e_invarg; + } + // 'foldclose' + else if (varp == &p_fcl) + { + if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK) + errmsg = e_invarg; + } + // 'foldignore' + else if (gvarp == &curwin->w_allbuf_opt.wo_fdi) + { + if (foldmethodIsIndent(curwin)) + foldUpdateAll(curwin); + } +#endif + + // 'virtualedit' + else if (varp == &p_ve) + { + if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK) + errmsg = e_invarg; + else if (STRCMP(p_ve, oldval) != 0) + { + // Recompute cursor position in case the new 've' setting + // changes something. + validate_virtcol(); + coladvance(curwin->w_virtcol); + } + } + +#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX) + else if (varp == &p_csqf) + { + if (p_csqf != NULL) + { + p = p_csqf; + while (*p != NUL) + { + if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL + || p[1] == NUL + || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL + || (p[2] != NUL && p[2] != ',')) + { + errmsg = e_invarg; + break; + } + else if (p[2] == NUL) + break; + else + p += 3; + } + } + } +#endif + +#ifdef FEAT_CINDENT + // 'cinoptions' + else if (gvarp == &p_cino) + { + // TODO: recognize errors + parse_cino(curbuf); + } +#endif + +#if defined(FEAT_RENDER_OPTIONS) + // 'renderoptions' + else if (varp == &p_rop) + { + if (!gui_mch_set_rendering_options(p_rop)) + errmsg = e_invarg; + } +#endif + + else if (gvarp == &p_ft) + { + if (!valid_filetype(*varp)) + errmsg = e_invarg; + else + { + value_changed = STRCMP(oldval, *varp) != 0; + + // Since we check the value, there is no need to set P_INSECURE, + // even when the value comes from a modeline. + *value_checked = TRUE; + } + } + +#ifdef FEAT_SYN_HL + else if (gvarp == &p_syn) + { + if (!valid_filetype(*varp)) + errmsg = e_invarg; + else + { + value_changed = STRCMP(oldval, *varp) != 0; + + // Since we check the value, there is no need to set P_INSECURE, + // even when the value comes from a modeline. + *value_checked = TRUE; + } + } +#endif + +#ifdef FEAT_TERMINAL + // 'termwinkey' + else if (varp == &curwin->w_p_twk) + { + if (*curwin->w_p_twk != NUL + && string_to_key(curwin->w_p_twk, TRUE) == 0) + errmsg = e_invarg; + } + // 'termwinsize' + else if (varp == &curwin->w_p_tws) + { + if (*curwin->w_p_tws != NUL) + { + p = skipdigits(curwin->w_p_tws); + if (p == curwin->w_p_tws + || (*p != 'x' && *p != '*') + || *skipdigits(p + 1) != NUL) + errmsg = e_invarg; + } + } +# if defined(MSWIN) + // 'termwintype' + else if (varp == &p_twt) + { + if (check_opt_strings(*varp, p_twt_values, FALSE) != OK) + errmsg = e_invarg; + } +# endif +#endif + +#ifdef FEAT_VARTABS + // 'varsofttabstop' + else if (varp == &(curbuf->b_p_vsts)) + { + char_u *cp; + + if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) + { + if (curbuf->b_p_vsts_array) + { + vim_free(curbuf->b_p_vsts_array); + curbuf->b_p_vsts_array = 0; + } + } + else + { + for (cp = *varp; *cp; ++cp) + { + if (vim_isdigit(*cp)) + continue; + if (*cp == ',' && cp > *varp && *(cp-1) != ',') + continue; + errmsg = e_invarg; + break; + } + if (errmsg == NULL) + { + int *oldarray = curbuf->b_p_vsts_array; + if (tabstop_set(*varp, &(curbuf->b_p_vsts_array))) + { + if (oldarray) + vim_free(oldarray); + } + else + errmsg = e_invarg; + } + } + } + + // 'vartabstop' + else if (varp == &(curbuf->b_p_vts)) + { + char_u *cp; + + if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1])) + { + if (curbuf->b_p_vts_array) + { + vim_free(curbuf->b_p_vts_array); + curbuf->b_p_vts_array = NULL; + } + } + else + { + for (cp = *varp; *cp; ++cp) + { + if (vim_isdigit(*cp)) + continue; + if (*cp == ',' && cp > *varp && *(cp-1) != ',') + continue; + errmsg = e_invarg; + break; + } + if (errmsg == NULL) + { + int *oldarray = curbuf->b_p_vts_array; + + if (tabstop_set(*varp, &(curbuf->b_p_vts_array))) + { + vim_free(oldarray); +#ifdef FEAT_FOLDING + if (foldmethodIsIndent(curwin)) + foldUpdateAll(curwin); +#endif + } + else + errmsg = e_invarg; + } + } + } +#endif + +#ifdef FEAT_TEXT_PROP + // 'previewpopup' + else if (varp == &p_pvp) + { + if (parse_previewpopup(NULL) == FAIL) + errmsg = e_invarg; + } +# ifdef FEAT_QUICKFIX + // 'completepopup' + else if (varp == &p_cpp) + { + if (parse_completepopup(NULL) == FAIL) + errmsg = e_invarg; + } +# endif +#endif + + // Options that are a list of flags. + else + { + p = NULL; + if (varp == &p_ww) // 'whichwrap' + p = (char_u *)WW_ALL; + if (varp == &p_shm) // 'shortmess' + p = (char_u *)SHM_ALL; + else if (varp == &(p_cpo)) // 'cpoptions' + p = (char_u *)CPO_ALL; + else if (varp == &(curbuf->b_p_fo)) // 'formatoptions' + p = (char_u *)FO_ALL; +#ifdef FEAT_CONCEAL + else if (varp == &curwin->w_p_cocu) // 'concealcursor' + p = (char_u *)COCU_ALL; +#endif + else if (varp == &p_mouse) // 'mouse' + { +#ifdef FEAT_MOUSE + p = (char_u *)MOUSE_ALL; +#else + if (*p_mouse != NUL) + errmsg = N_("E538: No mouse support"); +#endif + } +#if defined(FEAT_GUI) + else if (varp == &p_go) // 'guioptions' + p = (char_u *)GO_ALL; +#endif + if (p != NULL) + { + for (s = *varp; *s; ++s) + if (vim_strchr(p, *s) == NULL) + { + errmsg = illegal_char(errbuf, *s); + break; + } + } + } + + // If error detected, restore the previous value. + if (errmsg != NULL) + { + if (new_value_alloced) + free_string_option(*varp); + *varp = oldval; + // When resetting some values, need to act on it. + if (did_chartab) + (void)init_chartab(); + if (varp == &p_hl) + (void)highlight_changed(); + } + else + { +#ifdef FEAT_EVAL + // Remember where the option was set. + set_option_sctx_idx(opt_idx, opt_flags, current_sctx); +#endif + // Free string options that are in allocated memory. + // Use "free_oldval", because recursiveness may change the flags under + // our fingers (esp. init_highlight()). + if (free_oldval) + free_string_option(oldval); + if (new_value_alloced) + set_option_flag(opt_idx, P_ALLOCED); + else + clear_option_flag(opt_idx, P_ALLOCED); + + if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 + && is_global_local_option(opt_idx)) + { + // global option with local value set to use global value; free + // the local value and make it empty + p = get_option_varp_scope(opt_idx, OPT_LOCAL); + free_string_option(*(char_u **)p); + *(char_u **)p = empty_option; + } + + // May set global value for local option. + else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL) + set_string_option_global(opt_idx, varp); + + // Trigger the autocommand only after setting the flags. +#ifdef FEAT_SYN_HL + // When 'syntax' is set, load the syntax of that name + if (varp == &(curbuf->b_p_syn)) + { + static int syn_recursive = 0; + + ++syn_recursive; + // Only pass TRUE for "force" when the value changed or not used + // recursively, to avoid endless recurrence. + apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname, + value_changed || syn_recursive == 1, curbuf); + curbuf->b_flags |= BF_SYN_SET; + --syn_recursive; + } +#endif + else if (varp == &(curbuf->b_p_ft)) + { + // 'filetype' is set, trigger the FileType autocommand. + // Skip this when called from a modeline and the filetype was + // already set to this value. + if (!(opt_flags & OPT_MODELINE) || value_changed) + { + static int ft_recursive = 0; + int secure_save = secure; + + // Reset the secure flag, since the value of 'filetype' has + // been checked to be safe. + secure = 0; + + ++ft_recursive; + did_filetype = TRUE; + // Only pass TRUE for "force" when the value changed or not + // used recursively, to avoid endless recurrence. + apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname, + value_changed || ft_recursive == 1, curbuf); + --ft_recursive; + // Just in case the old "curbuf" is now invalid. + if (varp != &(curbuf->b_p_ft)) + varp = NULL; + + secure = secure_save; + } + } +#ifdef FEAT_SPELL + if (varp == &(curwin->w_s->b_p_spl)) + { + char_u fname[200]; + char_u *q = curwin->w_s->b_p_spl; + + // Skip the first name if it is "cjk". + if (STRNCMP(q, "cjk,", 4) == 0) + q += 4; + + // Source the spell/LANG.vim in 'runtimepath'. + // They could set 'spellcapcheck' depending on the language. + // Use the first name in 'spelllang' up to '_region' or + // '.encoding'. + for (p = q; *p != NUL; ++p) + if (!ASCII_ISALNUM(*p) && *p != '-') + break; + if (p > q) + { + vim_snprintf((char *)fname, 200, "spell/%.*s.vim", + (int)(p - q), q); + source_runtime(fname, DIP_ALL); + } + } +#endif + } + +#ifdef FEAT_MOUSE + if (varp == &p_mouse) + { +# ifdef FEAT_MOUSE_TTY + if (*p_mouse == NUL) + mch_setmouse(FALSE); // switch mouse off + else +# endif + setmouse(); // in case 'mouse' changed + } +#endif + + if (curwin->w_curswant != MAXCOL + && (get_option_flags(opt_idx) & (P_CURSWANT | P_RALL)) != 0) + curwin->w_set_curswant = TRUE; + +#ifdef FEAT_GUI + // check redraw when it's not a GUI option or the GUI is active. + if (!redraw_gui_only || gui.in_use) +#endif + check_redraw(get_option_flags(opt_idx)); + +#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) + if (did_swaptcap) + { + set_termname((char_u *)"win32"); + init_highlight(TRUE, FALSE); + } +#endif + + return errmsg; +} + +/* + * 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 +{ + return opt_strings_flags(val, values, NULL, list); +} + +/* + * 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, + int list) // when TRUE: accept a list of values +{ + int i; + int len; + unsigned new_flags = 0; + + while (*val) + { + for (i = 0; ; ++i) + { + if (values[i] == NULL) // val not found in values[] + return FAIL; + + len = (int)STRLEN(values[i]); + if (STRNCMP(values[i], val, len) == 0 + && ((list && val[len] == ',') || val[len] == NUL)) + { + val += len + (val[len] == ','); + new_flags |= (1 << i); + break; // check next item in val list + } + } + } + if (flagp != NULL) + *flagp = new_flags; + + return OK; +} + +/* + * return OK if "p" is a valid fileformat name, FAIL otherwise. + */ + int +check_ff_value(char_u *p) +{ + return check_opt_strings(p, p_ff_values, FALSE); +} diff --git a/src/os_unix.c b/src/os_unix.c index 2851459e4..54989af88 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -135,7 +135,7 @@ static int get_x11_title(int); static char_u *oldtitle = NULL; static volatile sig_atomic_t oldtitle_outdated = FALSE; -static int did_set_title = FALSE; +static int unix_did_set_title = FALSE; static char_u *oldicon = NULL; static int did_set_icon = FALSE; #endif @@ -2187,7 +2187,7 @@ mch_settitle(char_u *title, char_u *icon) else gui_mch_settitle(title, icon); #endif - did_set_title = TRUE; + unix_did_set_title = TRUE; } if ((type || *T_CIS != NUL) && icon != NULL) @@ -2228,10 +2228,10 @@ mch_settitle(char_u *title, char_u *icon) void mch_restore_title(int which) { - int do_push_pop = did_set_title || did_set_icon; + int do_push_pop = unix_did_set_title || did_set_icon; /* only restore the title or icon when it has been set */ - mch_settitle(((which & SAVE_RESTORE_TITLE) && did_set_title) ? + mch_settitle(((which & SAVE_RESTORE_TITLE) && unix_did_set_title) ? (oldtitle ? oldtitle : p_titleold) : NULL, ((which & SAVE_RESTORE_ICON) && did_set_icon) ? oldicon : NULL); diff --git a/src/proto.h b/src/proto.h index c3018574c..842d89131 100644 --- a/src/proto.h +++ b/src/proto.h @@ -178,6 +178,7 @@ void qsort(void *base, size_t elm_count, size_t elm_size, int (*cmp)(const void # include "normal.pro" # include "ops.pro" # include "option.pro" +# include "optionstr.pro" # include "popupmnu.pro" # if defined(FEAT_PROFILE) || defined(FEAT_RELTIME) # include "profiler.pro" diff --git a/src/proto/option.pro b/src/proto/option.pro index e84248478..d6c855854 100644 --- a/src/proto/option.pro +++ b/src/proto/option.pro @@ -10,22 +10,32 @@ void set_helplang_default(char_u *lang); void init_gui_options(void); void set_title_defaults(void); int do_set(char_u *arg, int opt_flags); +void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked); int string_to_key(char_u *arg, int multi_byte); +char *check_cedit(void); +void did_set_title(void); void set_options_bin(int oldval, int newval, int opt_flags); void check_options(void); -void check_buf_options(buf_T *buf); -void free_string_option(char_u *p); -void clear_string_option(char_u **pp); int get_term_opt_idx(char_u **p); int set_term_option_alloced(char_u **p); int was_set_insecurely(char_u *opt, int opt_flags); -void set_string_option_direct(char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); -void set_string_option_direct_in_win(win_T *wp, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); -void set_string_option_direct_in_buf(buf_T *buf, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); +void redraw_titles(void); int valid_name(char_u *val, char *allowed); +char *check_clipboard_option(void); +void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx); void set_term_option_sctx_idx(char *name, int opt_idx); +void check_redraw(long_u flags); +int findoption(char_u *arg); int get_option_value(char_u *name, long *numval, char_u **stringval, int opt_flags); int get_option_value_strict(char_u *name, long *numval, char_u **stringval, int opt_type, void *from); +long_u get_option_flags(int opt_idx); +void set_option_flag(int opt_idx, long_u flag); +void clear_option_flag(int opt_idx, long_u flag); +int is_global_option(int opt_idx); +int is_global_local_option(int opt_idx); +int is_window_local_option(int opt_idx); +int is_hidden_option(int opt_idx); +int is_crypt_key_option(int opt_idx); char_u *option_iter_next(void **option, int opt_type); char *set_option_value(char_u *name, long number, char_u *string, int opt_flags); char_u *get_term_code(char_u *tname); @@ -37,7 +47,11 @@ void clear_termoptions(void); void free_termoptions(void); void free_one_termoption(char_u *var); void set_term_defaults(void); +int istermoption_idx(int opt_idx); void unset_global_local_option(char_u *name, void *from); +char_u *get_option_varp_scope(int opt_idx, int opt_flags); +char_u *get_option_var(int opt_idx); +char_u *get_option_fullname(int opt_idx); char_u *get_equalprg(void); void win_copy_options(win_T *wp_from, win_T *wp_to); void copy_winopt(winopt_T *from, winopt_T *to); @@ -55,10 +69,11 @@ void vimrc_found(char_u *fname, char_u *envname); void change_compatible(int on); int option_was_set(char_u *name); int reset_option_was_set(char_u *name); +void fill_breakat_flags(void); +int check_opt_wim(void); int can_bs(int what); void save_file_ff(buf_T *buf); int file_ff_differs(buf_T *buf, int ignore_empty); -int check_ff_value(char_u *p); int tabstop_set(char_u *var, int **array); int tabstop_padding(colnr_T col, int ts_arg, int *vts); int tabstop_at(colnr_T col, int ts, int *vts); @@ -75,7 +90,9 @@ long get_sts_value(void); long get_scrolloff_value(void); long get_sidescrolloff_value(void); void find_mps_values(int *initc, int *findc, int *backwards, int switchit); +int briopt_check(win_T *wp); unsigned int get_bkc_value(buf_T *buf); int signcolumn_on(win_T *wp); dict_T *get_winbuf_options(int bufopt); +int fill_culopt_flags(char_u *val, win_T *wp); /* vim: set ft=c : */ diff --git a/src/proto/optionstr.pro b/src/proto/optionstr.pro new file mode 100644 index 000000000..dc1079ea3 --- /dev/null +++ b/src/proto/optionstr.pro @@ -0,0 +1,14 @@ +/* optionstr.c */ +void didset_string_options(void); +void trigger_optionsset_string(int opt_idx, int opt_flags, char_u *oldval, char_u *oldval_l, char_u *oldval_g, char_u *newval); +char *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char *errbuf, int opt_flags, int *value_checked); +void check_buf_options(buf_T *buf); +void free_string_option(char_u *p); +void clear_string_option(char_u **pp); +void check_string_option(char_u **pp); +void set_string_option_direct(char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); +void set_string_option_direct_in_win(win_T *wp, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); +void set_string_option_direct_in_buf(buf_T *buf, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); +char *set_string_option(int opt_idx, char_u *value, int opt_flags); +int check_ff_value(char_u *p); +/* vim: set ft=c : */ diff --git a/src/version.c b/src/version.c index c23fc839b..34e3e6bdf 100644 --- a/src/version.c +++ b/src/version.c @@ -758,6 +758,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2045, +/**/ 2044, /**/ 2043, |