blob: 4f73c0b21ec9c01e15798fe4488bb3a6b6f1c5fc [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000110#ifdef FEAT_EVAL
111# define PV_FEX OPT_BUF(BV_FEX)
112#endif
113#define PV_FF OPT_BUF(BV_FF)
114#define PV_FLP OPT_BUF(BV_FLP)
115#define PV_FO OPT_BUF(BV_FO)
116#ifdef FEAT_AUTOCMD
117# define PV_FT OPT_BUF(BV_FT)
118#endif
119#define PV_IMI OPT_BUF(BV_IMI)
120#define PV_IMS OPT_BUF(BV_IMS)
121#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
122# define PV_INDE OPT_BUF(BV_INDE)
123# define PV_INDK OPT_BUF(BV_INDK)
124#endif
125#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
126# define PV_INEX OPT_BUF(BV_INEX)
127#endif
128#define PV_INF OPT_BUF(BV_INF)
129#define PV_ISK OPT_BUF(BV_ISK)
130#ifdef FEAT_CRYPT
131# define PV_KEY OPT_BUF(BV_KEY)
132#endif
133#ifdef FEAT_KEYMAP
134# define PV_KMAP OPT_BUF(BV_KMAP)
135#endif
136#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
137#ifdef FEAT_LISP
138# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100139# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000140#endif
141#define PV_MA OPT_BUF(BV_MA)
142#define PV_ML OPT_BUF(BV_ML)
143#define PV_MOD OPT_BUF(BV_MOD)
144#define PV_MPS OPT_BUF(BV_MPS)
145#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
158#ifndef SHORT_FNAME
159# define PV_SN OPT_BUF(BV_SN)
160#endif
161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100177#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_TS OPT_BUF(BV_TS)
179#define PV_TW OPT_BUF(BV_TW)
180#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200181#ifdef FEAT_PERSISTENT_UNDO
182# define PV_UDF OPT_BUF(BV_UDF)
183#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185
186/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000187 * Definition of the PV_ values for window-local options.
188 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190#define PV_LIST OPT_WIN(WV_LIST)
191#ifdef FEAT_ARABIC
192# define PV_ARAB OPT_WIN(WV_ARAB)
193#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200194#ifdef FEAT_LINEBREAK
195# define PV_BRI OPT_WIN(WV_BRI)
196# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
197#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000198#ifdef FEAT_DIFF
199# define PV_DIFF OPT_WIN(WV_DIFF)
200#endif
201#ifdef FEAT_FOLDING
202# define PV_FDC OPT_WIN(WV_FDC)
203# define PV_FEN OPT_WIN(WV_FEN)
204# define PV_FDI OPT_WIN(WV_FDI)
205# define PV_FDL OPT_WIN(WV_FDL)
206# define PV_FDM OPT_WIN(WV_FDM)
207# define PV_FML OPT_WIN(WV_FML)
208# define PV_FDN OPT_WIN(WV_FDN)
209# ifdef FEAT_EVAL
210# define PV_FDE OPT_WIN(WV_FDE)
211# define PV_FDT OPT_WIN(WV_FDT)
212# endif
213# define PV_FMR OPT_WIN(WV_FMR)
214#endif
215#ifdef FEAT_LINEBREAK
216# define PV_LBR OPT_WIN(WV_LBR)
217#endif
218#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200219#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000220#ifdef FEAT_LINEBREAK
221# define PV_NUW OPT_WIN(WV_NUW)
222#endif
223#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
224# define PV_PVW OPT_WIN(WV_PVW)
225#endif
226#ifdef FEAT_RIGHTLEFT
227# define PV_RL OPT_WIN(WV_RL)
228# define PV_RLC OPT_WIN(WV_RLC)
229#endif
230#ifdef FEAT_SCROLLBIND
231# define PV_SCBIND OPT_WIN(WV_SCBIND)
232#endif
233#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000234#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000235# define PV_SPELL OPT_WIN(WV_SPELL)
236#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000237#ifdef FEAT_SYN_HL
238# define PV_CUC OPT_WIN(WV_CUC)
239# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200240# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000241#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000242#ifdef FEAT_STL_OPT
243# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
244#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100245#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#ifdef FEAT_WINDOWS
247# define PV_WFH OPT_WIN(WV_WFH)
248#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249#ifdef FEAT_VERTSPLIT
250# define PV_WFW OPT_WIN(WV_WFW)
251#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000252#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CURSORBIND
254# define PV_CRBIND OPT_WIN(WV_CRBIND)
255#endif
256#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200257# define PV_COCU OPT_WIN(WV_COCU)
258# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000260
261/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262typedef enum
263{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000264 PV_NONE = 0,
265 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266} idopt_T;
267
268/*
269 * Options local to a window have a value local to a buffer and global to all
270 * buffers. Indicate this by setting "var" to VAR_WIN.
271 */
272#define VAR_WIN ((char_u *)-1)
273
274/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000275 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 * Only to be used in option.c!
277 */
278static int p_ai;
279static int p_bin;
280#ifdef FEAT_MBYTE
281static int p_bomb;
282#endif
283#if defined(FEAT_QUICKFIX)
284static char_u *p_bh;
285static char_u *p_bt;
286#endif
287static int p_bl;
288static int p_ci;
289#ifdef FEAT_CINDENT
290static int p_cin;
291static char_u *p_cink;
292static char_u *p_cino;
293#endif
294#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
295static char_u *p_cinw;
296#endif
297#ifdef FEAT_COMMENTS
298static char_u *p_com;
299#endif
300#ifdef FEAT_FOLDING
301static char_u *p_cms;
302#endif
303#ifdef FEAT_INS_EXPAND
304static char_u *p_cpt;
305#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#ifdef FEAT_COMPL_FUNC
307static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000308static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200311static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312static int p_et;
313#ifdef FEAT_MBYTE
314static char_u *p_fenc;
315#endif
316static char_u *p_ff;
317static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000318static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319#ifdef FEAT_AUTOCMD
320static char_u *p_ft;
321#endif
322static long p_iminsert;
323static long p_imsearch;
324#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
325static char_u *p_inex;
326#endif
327#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
328static char_u *p_inde;
329static char_u *p_indk;
330#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000331#if defined(FEAT_EVAL)
332static char_u *p_fex;
333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334static int p_inf;
335static char_u *p_isk;
336#ifdef FEAT_CRYPT
337static char_u *p_key;
338#endif
339#ifdef FEAT_LISP
340static int p_lisp;
341#endif
342static int p_ml;
343static int p_ma;
344static int p_mod;
345static char_u *p_mps;
346static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000348#ifdef FEAT_TEXTOBJ
349static char_u *p_qe;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_ro;
352#ifdef FEAT_SMARTINDENT
353static int p_si;
354#endif
355#ifndef SHORT_FNAME
356static int p_sn;
357#endif
358static long p_sts;
359#if defined(FEAT_SEARCHPATH)
360static char_u *p_sua;
361#endif
362static long p_sw;
363static int p_swf;
364#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000365static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000367#endif
368#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000369static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000370static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000371static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000372#endif
373static long p_ts;
374static long p_tw;
375static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200376#ifdef FEAT_PERSISTENT_UNDO
377static int p_udf;
378#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000379static long p_wm;
380#ifdef FEAT_KEYMAP
381static char_u *p_keymap;
382#endif
383
384/* Saved values for when 'bin' is set. */
385static int p_et_nobin;
386static int p_ml_nobin;
387static long p_tw_nobin;
388static long p_wm_nobin;
389
390/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200391static int p_ai_nopaste;
392static int p_et_nopaste;
393static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394static long p_tw_nopaste;
395static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396
397struct vimoption
398{
399 char *fullname; /* full option name */
400 char *shortname; /* permissible abbreviation */
401 long_u flags; /* see below */
402 char_u *var; /* global option: pointer to variable;
403 * window-local option: VAR_WIN;
404 * buffer-local option: global value */
405 idopt_T indir; /* global option: PV_NONE;
406 * local option: indirect option index */
407 char_u *def_val[2]; /* default values for variable (vi and vim) */
408#ifdef FEAT_EVAL
409 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000410# define SCRIPTID_INIT , 0
411#else
412# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413#endif
414};
415
416#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
417#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
418
419/*
420 * Flags
421 */
422#define P_BOOL 0x01 /* the option is boolean */
423#define P_NUM 0x02 /* the option is numeric */
424#define P_STRING 0x04 /* the option is a string */
425#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000426 must use free_string_option() when
427 assigning new value. Not set if default is
428 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000429#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
430 never be used for local or hidden options! */
431#define P_NODEFAULT 0x40 /* don't set to default value */
432#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
433 use vim_free() when assigning new value */
434#define P_WAS_SET 0x100 /* option has been set/reset */
435#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
436#define P_VI_DEF 0x400 /* Use Vi default for Vim */
437#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
438
439 /* when option changed, what to display: */
440#define P_RSTAT 0x1000 /* redraw status lines */
441#define P_RWIN 0x2000 /* redraw current window */
442#define P_RBUF 0x4000 /* redraw current buffer */
443#define P_RALL 0x6000 /* redraw all windows */
444#define P_RCLR 0x7000 /* clear and redraw all */
445
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200446#define P_COMMA 0x8000 /* comma separated list */
447#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
448 * commas */
449#define P_NODUP 0x20000L /* don't allow duplicate strings */
450#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200452#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
453#define P_GETTEXT 0x100000L /* expand default value with _() */
454#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
455#define P_NFNAME 0x400000L /* only normal file name chars allowed */
456#define P_INSECURE 0x800000L /* option was set from a modeline */
457#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000458 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200459#define P_NO_ML 0x2000000L /* not allowed in modeline */
460#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200461 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000462
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000463#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
464
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000465/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
466 * for the currency sign. */
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100467#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000468# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000469#else
470# define ISP_LATIN1 (char_u *)"@,161-255"
471#endif
472
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000473/* The 16 bit MS-DOS version is low on space, make the string as short as
474 * possible when compiling with few features. */
475#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
476 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200477 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100478# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000479#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100480# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000481#endif
482
Bram Moolenaar071d4272004-06-13 20:20:40 +0000483/*
484 * options[] is initialized here.
485 * The order of the options MUST be alphabetic for ":set all" and findoption().
486 * All option names MUST start with a lowercase letter (for findoption()).
487 * Exception: "t_" options are at the end.
488 * The options with a NULL variable are 'hidden': a set command for them is
489 * ignored and they are not printed.
490 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100491static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200493 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494#ifdef FEAT_RIGHTLEFT
495 (char_u *)&p_aleph, PV_NONE,
496#else
497 (char_u *)NULL, PV_NONE,
498#endif
499 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100500#if (defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000501 (char_u *)128L,
502#else
503 (char_u *)224L,
504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000505 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
507#if defined(FEAT_GUI) && defined(MACOS_X)
508 (char_u *)&p_antialias, PV_NONE,
509 {(char_u *)FALSE, (char_u *)FALSE}
510#else
511 (char_u *)NULL, PV_NONE,
512 {(char_u *)FALSE, (char_u *)FALSE}
513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000514 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200515 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000516#ifdef FEAT_ARABIC
517 (char_u *)VAR_WIN, PV_ARAB,
518#else
519 (char_u *)NULL, PV_NONE,
520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
523#ifdef FEAT_ARABIC
524 (char_u *)&p_arshape, PV_NONE,
525#else
526 (char_u *)NULL, PV_NONE,
527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000528 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
530#ifdef FEAT_RIGHTLEFT
531 (char_u *)&p_ari, PV_NONE,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
537#ifdef FEAT_FKMAP
538 (char_u *)&p_altkeymap, PV_NONE,
539#else
540 (char_u *)NULL, PV_NONE,
541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000543 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
544#if defined(FEAT_MBYTE)
545 (char_u *)&p_ambw, PV_NONE,
546 {(char_u *)"single", (char_u *)0L}
547#else
548 (char_u *)NULL, PV_NONE,
549 {(char_u *)0L, (char_u *)0L}
550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000551 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000552#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autochdir", "acd", P_BOOL|P_VI_DEF,
554 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556#endif
557 {"autoindent", "ai", P_BOOL|P_VI_DEF,
558 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autoprint", "ap", P_BOOL|P_VI_DEF,
561 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000564 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autowrite", "aw", P_BOOL|P_VI_DEF,
567 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autowriteall","awa", P_BOOL|P_VI_DEF,
570 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
573 (char_u *)&p_bg, PV_NONE,
574 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100575#if (defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 (char_u *)"dark",
577#else
578 (char_u *)"light",
579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200581 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
585 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200587 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200588 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589#ifdef UNIX
590 {(char_u *)"yes", (char_u *)"auto"}
591#else
592 {(char_u *)"auto", (char_u *)"auto"}
593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000594 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200595 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
596 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000598 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000599 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600 (char_u *)&p_bex, PV_NONE,
601 {
602#ifdef VMS
603 (char_u *)"_",
604#else
605 (char_u *)"~",
606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000607 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200608 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609#ifdef FEAT_WILDIGN
610 (char_u *)&p_bsk, PV_NONE,
611 {(char_u *)"", (char_u *)0L}
612#else
613 (char_u *)NULL, PV_NONE,
614 {(char_u *)0L, (char_u *)0L}
615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617#ifdef FEAT_BEVAL
618 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
619 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
622 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000624# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000625 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000626 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000627 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000628# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629#endif
630 {"beautify", "bf", P_BOOL|P_VI_DEF,
631 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000632 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200633 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
634 (char_u *)&p_bo, PV_NONE,
635 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
637 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000638 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
640#ifdef MSDOS
641 (char_u *)&p_biosk, PV_NONE,
642#else
643 (char_u *)NULL, PV_NONE,
644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000645 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
647#ifdef FEAT_MBYTE
648 (char_u *)&p_bomb, PV_BOMB,
649#else
650 (char_u *)NULL, PV_NONE,
651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000652 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000653 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
654#ifdef FEAT_LINEBREAK
655 (char_u *)&p_breakat, PV_NONE,
656 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
657#else
658 (char_u *)NULL, PV_NONE,
659 {(char_u *)0L, (char_u *)0L}
660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000661 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200662 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
663#ifdef FEAT_LINEBREAK
664 (char_u *)VAR_WIN, PV_BRI,
665 {(char_u *)FALSE, (char_u *)0L}
666#else
667 (char_u *)NULL, PV_NONE,
668 {(char_u *)0L, (char_u *)0L}
669#endif
670 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200671 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
672 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200673#ifdef FEAT_LINEBREAK
674 (char_u *)VAR_WIN, PV_BRIOPT,
675 {(char_u *)"", (char_u *)NULL}
676#else
677 (char_u *)NULL, PV_NONE,
678 {(char_u *)"", (char_u *)NULL}
679#endif
680 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000681 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
682#ifdef FEAT_BROWSE
683 (char_u *)&p_bsdir, PV_NONE,
684 {(char_u *)"last", (char_u *)0L}
685#else
686 (char_u *)NULL, PV_NONE,
687 {(char_u *)0L, (char_u *)0L}
688#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000689 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000690 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
691#if defined(FEAT_QUICKFIX)
692 (char_u *)&p_bh, PV_BH,
693 {(char_u *)"", (char_u *)0L}
694#else
695 (char_u *)NULL, PV_NONE,
696 {(char_u *)0L, (char_u *)0L}
697#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000698 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
700 (char_u *)&p_bl, PV_BL,
701 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000702 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
704#if defined(FEAT_QUICKFIX)
705 (char_u *)&p_bt, PV_BT,
706 {(char_u *)"", (char_u *)0L}
707#else
708 (char_u *)NULL, PV_NONE,
709 {(char_u *)0L, (char_u *)0L}
710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000711 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200712 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000713#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 (char_u *)&p_cmp, PV_NONE,
715 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000716#else
717 (char_u *)NULL, PV_NONE,
718 {(char_u *)0L, (char_u *)0L}
719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000720 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
722#ifdef FEAT_SEARCHPATH
723 (char_u *)&p_cdpath, PV_NONE,
724 {(char_u *)",,", (char_u *)0L}
725#else
726 (char_u *)NULL, PV_NONE,
727 {(char_u *)0L, (char_u *)0L}
728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 {"cedit", NULL, P_STRING,
731#ifdef FEAT_CMDWIN
732 (char_u *)&p_cedit, PV_NONE,
733 {(char_u *)"", (char_u *)CTRL_F_STR}
734#else
735 (char_u *)NULL, PV_NONE,
736 {(char_u *)0L, (char_u *)0L}
737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000738 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
740#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
741 (char_u *)&p_ccv, PV_NONE,
742 {(char_u *)"", (char_u *)0L}
743#else
744 (char_u *)NULL, PV_NONE,
745 {(char_u *)0L, (char_u *)0L}
746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
749#ifdef FEAT_CINDENT
750 (char_u *)&p_cin, PV_CIN,
751#else
752 (char_u *)NULL, PV_NONE,
753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000754 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200755 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756#ifdef FEAT_CINDENT
757 (char_u *)&p_cink, PV_CINK,
758 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
759#else
760 (char_u *)NULL, PV_NONE,
761 {(char_u *)0L, (char_u *)0L}
762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000763 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200764 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765#ifdef FEAT_CINDENT
766 (char_u *)&p_cino, PV_CINO,
767#else
768 (char_u *)NULL, PV_NONE,
769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000770 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200771 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000772#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
773 (char_u *)&p_cinw, PV_CINW,
774 {(char_u *)"if,else,while,do,for,switch",
775 (char_u *)0L}
776#else
777 (char_u *)NULL, PV_NONE,
778 {(char_u *)0L, (char_u *)0L}
779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000780 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200781 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782#ifdef FEAT_CLIPBOARD
783 (char_u *)&p_cb, PV_NONE,
784# ifdef FEAT_XCLIPBOARD
785 {(char_u *)"autoselect,exclude:cons\\|linux",
786 (char_u *)0L}
787# else
788 {(char_u *)"", (char_u *)0L}
789# endif
790#else
791 (char_u *)NULL, PV_NONE,
792 {(char_u *)"", (char_u *)0L}
793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000794 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000795 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
796 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000797 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000798 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
799#ifdef FEAT_CMDWIN
800 (char_u *)&p_cwh, PV_NONE,
801#else
802 (char_u *)NULL, PV_NONE,
803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000804 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200805 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200806#ifdef FEAT_SYN_HL
807 (char_u *)VAR_WIN, PV_CC,
808#else
809 (char_u *)NULL, PV_NONE,
810#endif
811 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000812 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
813 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200815 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
816 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000817#ifdef FEAT_COMMENTS
818 (char_u *)&p_com, PV_COM,
819 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
820 (char_u *)0L}
821#else
822 (char_u *)NULL, PV_NONE,
823 {(char_u *)0L, (char_u *)0L}
824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200826 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827#ifdef FEAT_FOLDING
828 (char_u *)&p_cms, PV_CMS,
829 {(char_u *)"/*%s*/", (char_u *)0L}
830#else
831 (char_u *)NULL, PV_NONE,
832 {(char_u *)0L, (char_u *)0L}
833#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000834 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000835 /* P_PRI_MKRC isn't needed here, optval_default()
836 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837 {"compatible", "cp", P_BOOL|P_RALL,
838 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000839 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200840 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841#ifdef FEAT_INS_EXPAND
842 (char_u *)&p_cpt, PV_CPT,
843 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
844#else
845 (char_u *)NULL, PV_NONE,
846 {(char_u *)0L, (char_u *)0L}
847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000848 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200849 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200850#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200851 (char_u *)VAR_WIN, PV_COCU,
852 {(char_u *)"", (char_u *)NULL}
853#else
854 (char_u *)NULL, PV_NONE,
855 {(char_u *)NULL, (char_u *)0L}
856#endif
857 SCRIPTID_INIT},
858 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
859#ifdef FEAT_CONCEAL
860 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200861#else
862 (char_u *)NULL, PV_NONE,
863#endif
864 {(char_u *)0L, (char_u *)0L}
865 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000866 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
867#ifdef FEAT_COMPL_FUNC
868 (char_u *)&p_cfu, PV_CFU,
869 {(char_u *)"", (char_u *)0L}
870#else
871 (char_u *)NULL, PV_NONE,
872 {(char_u *)0L, (char_u *)0L}
873#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000874 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200875 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000876#ifdef FEAT_INS_EXPAND
877 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000878 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000879#else
880 (char_u *)NULL, PV_NONE,
881 {(char_u *)0L, (char_u *)0L}
882#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000883 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000884 {"confirm", "cf", P_BOOL|P_VI_DEF,
885#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
886 (char_u *)&p_confirm, PV_NONE,
887#else
888 (char_u *)NULL, PV_NONE,
889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000890 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000891 {"conskey", "consk",P_BOOL|P_VI_DEF,
892#ifdef MSDOS
893 (char_u *)&p_consk, PV_NONE,
894#else
895 (char_u *)NULL, PV_NONE,
896#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000897 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000898 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
899 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
902 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
904 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200905 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200906#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200907 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200908 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200909#else
910 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200911 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200912#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200913 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
915#ifdef FEAT_CSCOPE
916 (char_u *)&p_cspc, PV_NONE,
917#else
918 (char_u *)NULL, PV_NONE,
919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
922#ifdef FEAT_CSCOPE
923 (char_u *)&p_csprg, PV_NONE,
924 {(char_u *)"cscope", (char_u *)0L}
925#else
926 (char_u *)NULL, PV_NONE,
927 {(char_u *)0L, (char_u *)0L}
928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000929 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200930 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
932 (char_u *)&p_csqf, PV_NONE,
933 {(char_u *)"", (char_u *)0L}
934#else
935 (char_u *)NULL, PV_NONE,
936 {(char_u *)0L, (char_u *)0L}
937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000938 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200939 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
940#ifdef FEAT_CSCOPE
941 (char_u *)&p_csre, PV_NONE,
942#else
943 (char_u *)NULL, PV_NONE,
944#endif
945 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
947#ifdef FEAT_CSCOPE
948 (char_u *)&p_cst, PV_NONE,
949#else
950 (char_u *)NULL, PV_NONE,
951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000952 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
954#ifdef FEAT_CSCOPE
955 (char_u *)&p_csto, PV_NONE,
956#else
957 (char_u *)NULL, PV_NONE,
958#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000959 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
961#ifdef FEAT_CSCOPE
962 (char_u *)&p_csverbose, PV_NONE,
963#else
964 (char_u *)NULL, PV_NONE,
965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000966 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200967 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
968#ifdef FEAT_CURSORBIND
969 (char_u *)VAR_WIN, PV_CRBIND,
970#else
971 (char_u *)NULL, PV_NONE,
972#endif
973 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000974 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
975#ifdef FEAT_SYN_HL
976 (char_u *)VAR_WIN, PV_CUC,
977#else
978 (char_u *)NULL, PV_NONE,
979#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000980 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000981 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
982#ifdef FEAT_SYN_HL
983 (char_u *)VAR_WIN, PV_CUL,
984#else
985 (char_u *)NULL, PV_NONE,
986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000987 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988 {"debug", NULL, P_STRING|P_VI_DEF,
989 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200991 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000993 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000994 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#else
996 (char_u *)NULL, PV_NONE,
997 {(char_u *)NULL, (char_u *)0L}
998#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000999 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001000 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1001#ifdef FEAT_MBYTE
1002 (char_u *)&p_deco, PV_NONE,
1003#else
1004 (char_u *)NULL, PV_NONE,
1005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001006 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001007 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001009 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#else
1011 (char_u *)NULL, PV_NONE,
1012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001013 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1015#ifdef FEAT_DIFF
1016 (char_u *)VAR_WIN, PV_DIFF,
1017#else
1018 (char_u *)NULL, PV_NONE,
1019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001020 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001021 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1023 (char_u *)&p_dex, PV_NONE,
1024 {(char_u *)"", (char_u *)0L}
1025#else
1026 (char_u *)NULL, PV_NONE,
1027 {(char_u *)0L, (char_u *)0L}
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001030 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1031 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032#ifdef FEAT_DIFF
1033 (char_u *)&p_dip, PV_NONE,
1034 {(char_u *)"filler", (char_u *)NULL}
1035#else
1036 (char_u *)NULL, PV_NONE,
1037 {(char_u *)"", (char_u *)NULL}
1038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001039 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1041#ifdef FEAT_DIGRAPHS
1042 (char_u *)&p_dg, PV_NONE,
1043#else
1044 (char_u *)NULL, PV_NONE,
1045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001046 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001047 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1048 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001051 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 {"eadirection", "ead", P_STRING|P_VI_DEF,
1055#ifdef FEAT_VERTSPLIT
1056 (char_u *)&p_ead, PV_NONE,
1057 {(char_u *)"both", (char_u *)0L}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)NULL, (char_u *)0L}
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1064 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001065 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001066 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067#ifdef FEAT_MBYTE
1068 (char_u *)&p_enc, PV_NONE,
1069 {(char_u *)ENC_DFLT, (char_u *)0L}
1070#else
1071 (char_u *)NULL, PV_NONE,
1072 {(char_u *)0L, (char_u *)0L}
1073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1076 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1079 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001082 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001083 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1085 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001086 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1088#ifdef FEAT_QUICKFIX
1089 (char_u *)&p_ef, PV_NONE,
1090 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1091#else
1092 (char_u *)NULL, PV_NONE,
1093 {(char_u *)NULL, (char_u *)0L}
1094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001095 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001096 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001098 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100#else
1101 (char_u *)NULL, PV_NONE,
1102 {(char_u *)NULL, (char_u *)0L}
1103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 {"esckeys", "ek", P_BOOL|P_VIM,
1106 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001108 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109#ifdef FEAT_AUTOCMD
1110 (char_u *)&p_ei, PV_NONE,
1111#else
1112 (char_u *)NULL, PV_NONE,
1113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1116 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1119 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001120 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001121 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1122 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123#ifdef FEAT_MBYTE
1124 (char_u *)&p_fenc, PV_FENC,
1125 {(char_u *)"", (char_u *)0L}
1126#else
1127 (char_u *)NULL, PV_NONE,
1128 {(char_u *)0L, (char_u *)0L}
1129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001131 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132#ifdef FEAT_MBYTE
1133 (char_u *)&p_fencs, PV_NONE,
1134 {(char_u *)"ucs-bom", (char_u *)0L}
1135#else
1136 (char_u *)NULL, PV_NONE,
1137 {(char_u *)0L, (char_u *)0L}
1138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1141 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001144 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1147 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001148 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1149 (char_u *)&p_fic, PV_NONE,
1150 {
1151#ifdef CASE_INSENSITIVE_FILENAME
1152 (char_u *)TRUE,
1153#else
1154 (char_u *)FALSE,
1155#endif
1156 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001157 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158#ifdef FEAT_AUTOCMD
1159 (char_u *)&p_ft, PV_FT,
1160 {(char_u *)"", (char_u *)0L}
1161#else
1162 (char_u *)NULL, PV_NONE,
1163 {(char_u *)0L, (char_u *)0L}
1164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001166 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1168 (char_u *)&p_fcs, PV_NONE,
1169 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1170#else
1171 (char_u *)NULL, PV_NONE,
1172 {(char_u *)"", (char_u *)0L}
1173#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001174 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001175 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1176 (char_u *)&p_fixeol, PV_FIXEOL,
1177 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1179#ifdef FEAT_FKMAP
1180 (char_u *)&p_fkmap, PV_NONE,
1181#else
1182 (char_u *)NULL, PV_NONE,
1183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001185 {"flash", "fl", P_BOOL|P_VI_DEF,
1186 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001187 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001188#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001189 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1193 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1196 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1199# ifdef FEAT_EVAL
1200 (char_u *)VAR_WIN, PV_FDE,
1201 {(char_u *)"0", (char_u *)NULL}
1202# else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)NULL, (char_u *)0L}
1205# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1208 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1211 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001213 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001215 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001217 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)"{{{,}}}", (char_u *)NULL}
1220 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1225 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1228 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001229 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001230 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 (char_u *)&p_fdo, PV_NONE,
1232 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001233 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001234 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1235# ifdef FEAT_EVAL
1236 (char_u *)VAR_WIN, PV_FDT,
1237 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001238# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239 (char_u *)NULL, PV_NONE,
1240 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001241# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001242 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001244 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001245#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001246 (char_u *)&p_fex, PV_FEX,
1247 {(char_u *)"", (char_u *)0L}
1248#else
1249 (char_u *)NULL, PV_NONE,
1250 {(char_u *)0L, (char_u *)0L}
1251#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001252 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1254 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001255 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1256 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001257 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1258 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001259 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1260 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1262 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001264 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1265#ifdef HAVE_FSYNC
1266 (char_u *)&p_fs, PV_NONE,
1267 {(char_u *)TRUE, (char_u *)0L}
1268#else
1269 (char_u *)NULL, PV_NONE,
1270 {(char_u *)FALSE, (char_u *)0L}
1271#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1274 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"graphic", "gr", P_BOOL|P_VI_DEF,
1277 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001278 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001279 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280#ifdef FEAT_QUICKFIX
1281 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001282 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283#else
1284 (char_u *)NULL, PV_NONE,
1285 {(char_u *)NULL, (char_u *)0L}
1286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001287 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1289#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001290 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291 {
1292# ifdef WIN3264
1293 /* may be changed to "grep -n" in os_win32.c */
1294 (char_u *)"findstr /n",
1295# else
1296# ifdef UNIX
1297 /* Add an extra file name so that grep will always
1298 * insert a file name in the match line. */
1299 (char_u *)"grep -n $* /dev/null",
1300# else
1301# ifdef VMS
1302 (char_u *)"SEARCH/NUMBERS ",
1303# else
1304 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001305# endif
1306# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001308 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001313 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001314 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315#ifdef CURSOR_SHAPE
1316 (char_u *)&p_guicursor, PV_NONE,
1317 {
1318# ifdef FEAT_GUI
1319 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
1320# else /* MSDOS or Win32 console */
1321 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1322# endif
1323 (char_u *)0L}
1324#else
1325 (char_u *)NULL, PV_NONE,
1326 {(char_u *)NULL, (char_u *)0L}
1327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001328 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001329 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330#ifdef FEAT_GUI
1331 (char_u *)&p_guifont, PV_NONE,
1332 {(char_u *)"", (char_u *)0L}
1333#else
1334 (char_u *)NULL, PV_NONE,
1335 {(char_u *)NULL, (char_u *)0L}
1336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001337 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001338 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1340 (char_u *)&p_guifontset, PV_NONE,
1341 {(char_u *)"", (char_u *)0L}
1342#else
1343 (char_u *)NULL, PV_NONE,
1344 {(char_u *)NULL, (char_u *)0L}
1345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001347 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1349 (char_u *)&p_guifontwide, PV_NONE,
1350 {(char_u *)"", (char_u *)0L}
1351#else
1352 (char_u *)NULL, PV_NONE,
1353 {(char_u *)NULL, (char_u *)0L}
1354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001357#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358 (char_u *)&p_ghr, PV_NONE,
1359#else
1360 (char_u *)NULL, PV_NONE,
1361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001362 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001364#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 (char_u *)&p_go, PV_NONE,
1366# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001367 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001369 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370# endif
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001375 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 {"guipty", NULL, P_BOOL|P_VI_DEF,
1377#if defined(FEAT_GUI)
1378 (char_u *)&p_guipty, PV_NONE,
1379#else
1380 (char_u *)NULL, PV_NONE,
1381#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001383 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001384#if defined(FEAT_GUI_TABLINE)
1385 (char_u *)&p_gtl, PV_NONE,
1386 {(char_u *)"", (char_u *)0L}
1387#else
1388 (char_u *)NULL, PV_NONE,
1389 {(char_u *)NULL, (char_u *)0L}
1390#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001391 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001392 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001393#if defined(FEAT_GUI_TABLINE)
1394 (char_u *)&p_gtt, PV_NONE,
1395 {(char_u *)"", (char_u *)0L}
1396#else
1397 (char_u *)NULL, PV_NONE,
1398 {(char_u *)NULL, (char_u *)0L}
1399#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001401 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1402 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1405 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001406 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1407 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"helpheight", "hh", P_NUM|P_VI_DEF,
1409#ifdef FEAT_WINDOWS
1410 (char_u *)&p_hh, PV_NONE,
1411#else
1412 (char_u *)NULL, PV_NONE,
1413#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001415 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#ifdef FEAT_MULTI_LANG
1417 (char_u *)&p_hlg, PV_NONE,
1418 {(char_u *)"", (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)0L, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"hidden", "hid", P_BOOL|P_VI_DEF,
1425 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001427 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001429 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1430 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"history", "hi", P_NUM|P_VIM,
1432 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001433 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1435#ifdef FEAT_RIGHTLEFT
1436 (char_u *)&p_hkmap, PV_NONE,
1437#else
1438 (char_u *)NULL, PV_NONE,
1439#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001440 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1442#ifdef FEAT_RIGHTLEFT
1443 (char_u *)&p_hkmapp, PV_NONE,
1444#else
1445 (char_u *)NULL, PV_NONE,
1446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1449 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"icon", NULL, P_BOOL|P_VI_DEF,
1452#ifdef FEAT_TITLE
1453 (char_u *)&p_icon, PV_NONE,
1454#else
1455 (char_u *)NULL, PV_NONE,
1456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001457 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"iconstring", NULL, P_STRING|P_VI_DEF,
1459#ifdef FEAT_TITLE
1460 (char_u *)&p_iconstring, PV_NONE,
1461#else
1462 (char_u *)NULL, PV_NONE,
1463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1466 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001467 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001468 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1469# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1470 (char_u *)&p_imaf, PV_NONE,
1471 {(char_u *)"", (char_u *)NULL}
1472# else
1473 (char_u *)NULL, PV_NONE,
1474 {(char_u *)NULL, (char_u *)0L}
1475# endif
1476 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001478#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 (char_u *)&p_imak, PV_NONE,
1480#else
1481 (char_u *)NULL, PV_NONE,
1482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001483 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1485#ifdef USE_IM_CONTROL
1486 (char_u *)&p_imcmdline, PV_NONE,
1487#else
1488 (char_u *)NULL, PV_NONE,
1489#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1492#ifdef USE_IM_CONTROL
1493 (char_u *)&p_imdisable, PV_NONE,
1494#else
1495 (char_u *)NULL, PV_NONE,
1496#endif
1497#ifdef __sgi
1498 {(char_u *)TRUE, (char_u *)0L}
1499#else
1500 {(char_u *)FALSE, (char_u *)0L}
1501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"iminsert", "imi", P_NUM|P_VI_DEF,
1504 (char_u *)&p_iminsert, PV_IMI,
1505#ifdef B_IMODE_IM
1506 {(char_u *)B_IMODE_IM, (char_u *)0L}
1507#else
1508 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001510 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"imsearch", "ims", P_NUM|P_VI_DEF,
1512 (char_u *)&p_imsearch, PV_IMS,
1513#ifdef B_IMODE_IM
1514 {(char_u *)B_IMODE_IM, (char_u *)0L}
1515#else
1516 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001519 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001520# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1521 (char_u *)&p_imsf, PV_NONE,
1522 {(char_u *)"", (char_u *)NULL}
1523# else
1524 (char_u *)NULL, PV_NONE,
1525 {(char_u *)NULL, (char_u *)0L}
1526# endif
1527 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1529#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001530 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1532#else
1533 (char_u *)NULL, PV_NONE,
1534 {(char_u *)0L, (char_u *)0L}
1535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1538#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1539 (char_u *)&p_inex, PV_INEX,
1540 {(char_u *)"", (char_u *)0L}
1541#else
1542 (char_u *)NULL, PV_NONE,
1543 {(char_u *)0L, (char_u *)0L}
1544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1547 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1550#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1551 (char_u *)&p_inde, PV_INDE,
1552 {(char_u *)"", (char_u *)0L}
1553#else
1554 (char_u *)NULL, PV_NONE,
1555 {(char_u *)0L, (char_u *)0L}
1556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001557 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001558 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1560 (char_u *)&p_indk, PV_INDK,
1561 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1562#else
1563 (char_u *)NULL, PV_NONE,
1564 {(char_u *)0L, (char_u *)0L}
1565#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"infercase", "inf", P_BOOL|P_VI_DEF,
1568 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1571 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001573 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1574 (char_u *)&p_isf, PV_NONE,
1575 {
1576#ifdef BACKSLASH_IN_FILENAME
1577 /* Excluded are: & and ^ are special in cmd.exe
1578 * ( and ) are used in text separating fnames */
1579 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1580#else
1581# ifdef AMIGA
1582 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1583# else
1584# ifdef VMS
1585 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1586# else /* UNIX et al. */
1587# ifdef EBCDIC
1588 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1589# else
1590 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1591# endif
1592# endif
1593# endif
1594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001595 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1597 (char_u *)&p_isi, PV_NONE,
1598 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001599#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 (char_u *)"@,48-57,_,128-167,224-235",
1601#else
1602# ifdef EBCDIC
1603 /* TODO: EBCDIC Check this! @ == isalpha()*/
1604 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1605 "112-120,128,140-142,156,158,172,"
1606 "174,186,191,203-207,219-225,235-239,"
1607 "251-254",
1608# else
1609 (char_u *)"@,48-57,_,192-255",
1610# endif
1611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001612 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1614 (char_u *)&p_isk, PV_ISK,
1615 {
1616#ifdef EBCDIC
1617 (char_u *)"@,240-249,_",
1618 /* TODO: EBCDIC Check this! @ == isalpha()*/
1619 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1620 "112-120,128,140-142,156,158,172,"
1621 "174,186,191,203-207,219-225,235-239,"
1622 "251-254",
1623#else
1624 (char_u *)"@,48-57,_",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001625# if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 (char_u *)"@,48-57,_,128-167,224-235"
1627# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001628 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629# endif
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1633 (char_u *)&p_isp, PV_NONE,
1634 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001635#if defined(MSDOS) || defined(MSWIN) \
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001636 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001637 || defined(VMS)
1638 (char_u *)"@,~-255",
1639#else
1640# ifdef EBCDIC
1641 /* all chars above 63 are printable */
1642 (char_u *)"63-255",
1643# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001644 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645# endif
1646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001647 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001648 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1649 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001650 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1652#ifdef FEAT_CRYPT
1653 (char_u *)&p_key, PV_KEY,
1654 {(char_u *)"", (char_u *)0L}
1655#else
1656 (char_u *)NULL, PV_NONE,
1657 {(char_u *)0L, (char_u *)0L}
1658#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001659 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001660 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661#ifdef FEAT_KEYMAP
1662 (char_u *)&p_keymap, PV_KMAP,
1663 {(char_u *)"", (char_u *)0L}
1664#else
1665 (char_u *)NULL, PV_NONE,
1666 {(char_u *)"", (char_u *)0L}
1667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001668 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001669 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001671 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001673 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 {
1675#if defined(MSDOS) || defined(MSWIN)
1676 (char_u *)":help",
1677#else
1678#ifdef VMS
1679 (char_u *)"help",
1680#else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001681# ifdef USEMAN_S
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 (char_u *)"man -s",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001683# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001684 (char_u *)"man",
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685# endif
1686#endif
1687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001688 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001689 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001690#ifdef FEAT_LANGMAP
1691 (char_u *)&p_langmap, PV_NONE,
1692 {(char_u *)"", /* unmatched } */
1693#else
1694 (char_u *)NULL, PV_NONE,
1695 {(char_u *)NULL,
1696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001697 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001698 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1700 (char_u *)&p_lm, PV_NONE,
1701#else
1702 (char_u *)NULL, PV_NONE,
1703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001704 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001705 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1706#ifdef FEAT_LANGMAP
1707 (char_u *)&p_lnr, PV_NONE,
1708#else
1709 (char_u *)NULL, PV_NONE,
1710#endif
1711 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1713#ifdef FEAT_WINDOWS
1714 (char_u *)&p_ls, PV_NONE,
1715#else
1716 (char_u *)NULL, PV_NONE,
1717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001718 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1720 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1723#ifdef FEAT_LINEBREAK
1724 (char_u *)VAR_WIN, PV_LBR,
1725#else
1726 (char_u *)NULL, PV_NONE,
1727#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001728 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1730 (char_u *)&Rows, PV_NONE,
1731 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001732#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 (char_u *)25L,
1734#else
1735 (char_u *)24L,
1736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001737 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1739#ifdef FEAT_GUI
1740 (char_u *)&p_linespace, PV_NONE,
1741#else
1742 (char_u *)NULL, PV_NONE,
1743#endif
1744#ifdef FEAT_GUI_W32
1745 {(char_u *)1L, (char_u *)0L}
1746#else
1747 {(char_u *)0L, (char_u *)0L}
1748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"lisp", NULL, P_BOOL|P_VI_DEF,
1751#ifdef FEAT_LISP
1752 (char_u *)&p_lisp, PV_LISP,
1753#else
1754 (char_u *)NULL, PV_NONE,
1755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001757 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001759 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001760 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1761#else
1762 (char_u *)NULL, PV_NONE,
1763 {(char_u *)"", (char_u *)0L}
1764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001765 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1767 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001769 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1773 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001774 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001775#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001776 {"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1777 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001778 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1779 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001780#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001781#ifdef FEAT_GUI_MAC
1782 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1783 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001785#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"magic", NULL, P_BOOL|P_VI_DEF,
1787 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001789 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790#ifdef FEAT_QUICKFIX
1791 (char_u *)&p_mef, PV_NONE,
1792 {(char_u *)"", (char_u *)0L}
1793#else
1794 (char_u *)NULL, PV_NONE,
1795 {(char_u *)NULL, (char_u *)0L}
1796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001797 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001798 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1799#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001800 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001801# ifdef VMS
1802 {(char_u *)"MMS", (char_u *)0L}
1803# else
1804 {(char_u *)"make", (char_u *)0L}
1805# endif
1806#else
1807 (char_u *)NULL, PV_NONE,
1808 {(char_u *)NULL, (char_u *)0L}
1809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001811 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1814 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 {"matchtime", "mat", P_NUM|P_VI_DEF,
1816 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001818 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001819#ifdef FEAT_MBYTE
1820 (char_u *)&p_mco, PV_NONE,
1821#else
1822 (char_u *)NULL, PV_NONE,
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1826#ifdef FEAT_EVAL
1827 (char_u *)&p_mfd, PV_NONE,
1828#else
1829 (char_u *)NULL, PV_NONE,
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1833 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"maxmem", "mm", P_NUM|P_VI_DEF,
1836 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1838 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001839 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1840 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1843 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1845 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"menuitems", "mis", P_NUM|P_VI_DEF,
1847#ifdef FEAT_MENU
1848 (char_u *)&p_mis, PV_NONE,
1849#else
1850 (char_u *)NULL, PV_NONE,
1851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"mesg", NULL, P_BOOL|P_VI_DEF,
1854 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001856 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001857#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001858 (char_u *)&p_msm, PV_NONE,
1859 {(char_u *)"460000,2000,500", (char_u *)0L}
1860#else
1861 (char_u *)NULL, PV_NONE,
1862 {(char_u *)0L, (char_u *)0L}
1863#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001864 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 {"modeline", "ml", P_BOOL|P_VIM,
1866 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"modelines", "mls", P_NUM|P_VI_DEF,
1869 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1872 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001873 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1875 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"more", NULL, P_BOOL|P_VIM,
1878 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1881 (char_u *)&p_mouse, PV_NONE,
1882 {
1883#if defined(MSDOS) || defined(WIN3264)
1884 (char_u *)"a",
1885#else
1886 (char_u *)"",
1887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1890#ifdef FEAT_GUI
1891 (char_u *)&p_mousef, PV_NONE,
1892#else
1893 (char_u *)NULL, PV_NONE,
1894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1897#ifdef FEAT_GUI
1898 (char_u *)&p_mh, PV_NONE,
1899#else
1900 (char_u *)NULL, PV_NONE,
1901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1904 (char_u *)&p_mousem, PV_NONE,
1905 {
1906#if defined(MSDOS) || defined(MSWIN)
1907 (char_u *)"popup",
1908#else
1909# if defined(MACOS)
1910 (char_u *)"popup_setpos",
1911# else
1912 (char_u *)"extend",
1913# endif
1914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001916 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917#ifdef FEAT_MOUSESHAPE
1918 (char_u *)&p_mouseshape, PV_NONE,
1919 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1920#else
1921 (char_u *)NULL, PV_NONE,
1922 {(char_u *)NULL, (char_u *)0L}
1923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1926 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001928 {"mzquantum", "mzq", P_NUM,
1929#ifdef FEAT_MZSCHEME
1930 (char_u *)&p_mzq, PV_NONE,
1931#else
1932 (char_u *)NULL, PV_NONE,
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"novice", NULL, P_BOOL|P_VI_DEF,
1936 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001938 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001940 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1943 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001945 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1946#ifdef FEAT_LINEBREAK
1947 (char_u *)VAR_WIN, PV_NUW,
1948#else
1949 (char_u *)NULL, PV_NONE,
1950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001952 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001953#ifdef FEAT_COMPL_FUNC
1954 (char_u *)&p_ofu, PV_OFU,
1955 {(char_u *)"", (char_u *)0L}
1956#else
1957 (char_u *)NULL, PV_NONE,
1958 {(char_u *)0L, (char_u *)0L}
1959#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001960 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961 {"open", NULL, P_BOOL|P_VI_DEF,
1962 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001964 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001965#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001966 (char_u *)&p_odev, PV_NONE,
1967#else
1968 (char_u *)NULL, PV_NONE,
1969#endif
1970 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001971 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001972 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1973 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 {"optimize", "opt", P_BOOL|P_VI_DEF,
1976 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001980 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001981 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1982 |P_SECURE,
1983 (char_u *)&p_pp, PV_NONE,
1984 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
1985 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"paragraphs", "para", P_STRING|P_VI_DEF,
1987 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001988 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001989 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001990 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001992 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001993 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1994 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001995 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1997#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1998 (char_u *)&p_pex, PV_NONE,
1999 {(char_u *)"", (char_u *)0L}
2000#else
2001 (char_u *)NULL, PV_NONE,
2002 {(char_u *)0L, (char_u *)0L}
2003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002004 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002005 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002009 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010 {
2011#if defined AMIGA || defined MSDOS || defined MSWIN
2012 (char_u *)".,,",
2013#else
2014# if defined(__EMX__)
2015 (char_u *)".,/emx/include,,",
2016# else /* Unix, probably */
2017 (char_u *)".,/usr/include,,",
2018# endif
2019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002020 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002021#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002022 {"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2023 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002024 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2025 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002026#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2028 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002030 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2032 (char_u *)&p_pvh, PV_NONE,
2033#else
2034 (char_u *)NULL, PV_NONE,
2035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002036 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2038#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2039 (char_u *)VAR_WIN, PV_PVW,
2040#else
2041 (char_u *)NULL, PV_NONE,
2042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002043 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002044 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045#ifdef FEAT_PRINTER
2046 (char_u *)&p_pdev, PV_NONE,
2047 {(char_u *)"", (char_u *)0L}
2048#else
2049 (char_u *)NULL, PV_NONE,
2050 {(char_u *)NULL, (char_u *)0L}
2051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002052 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 {"printencoding", "penc", P_STRING|P_VI_DEF,
2054#ifdef FEAT_POSTSCRIPT
2055 (char_u *)&p_penc, PV_NONE,
2056 {(char_u *)"", (char_u *)0L}
2057#else
2058 (char_u *)NULL, PV_NONE,
2059 {(char_u *)NULL, (char_u *)0L}
2060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2063#ifdef FEAT_POSTSCRIPT
2064 (char_u *)&p_pexpr, PV_NONE,
2065 {(char_u *)"", (char_u *)0L}
2066#else
2067 (char_u *)NULL, PV_NONE,
2068 {(char_u *)NULL, (char_u *)0L}
2069#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002070 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 {"printfont", "pfn", P_STRING|P_VI_DEF,
2072#ifdef FEAT_PRINTER
2073 (char_u *)&p_pfn, PV_NONE,
2074 {
2075# ifdef MSWIN
2076 (char_u *)"Courier_New:h10",
2077# else
2078 (char_u *)"courier",
2079# endif
2080 (char_u *)0L}
2081#else
2082 (char_u *)NULL, PV_NONE,
2083 {(char_u *)NULL, (char_u *)0L}
2084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2087#ifdef FEAT_PRINTER
2088 (char_u *)&p_header, PV_NONE,
2089 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2090#else
2091 (char_u *)NULL, PV_NONE,
2092 {(char_u *)NULL, (char_u *)0L}
2093#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002094 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002095 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2096#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2097 (char_u *)&p_pmcs, PV_NONE,
2098 {(char_u *)"", (char_u *)0L}
2099#else
2100 (char_u *)NULL, PV_NONE,
2101 {(char_u *)NULL, (char_u *)0L}
2102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002103 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002104 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2105#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2106 (char_u *)&p_pmfn, PV_NONE,
2107 {(char_u *)"", (char_u *)0L}
2108#else
2109 (char_u *)NULL, PV_NONE,
2110 {(char_u *)NULL, (char_u *)0L}
2111#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002113 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002114#ifdef FEAT_PRINTER
2115 (char_u *)&p_popt, PV_NONE,
2116 {(char_u *)"", (char_u *)0L}
2117#else
2118 (char_u *)NULL, PV_NONE,
2119 {(char_u *)NULL, (char_u *)0L}
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002123 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002125 {"pumheight", "ph", P_NUM|P_VI_DEF,
2126#ifdef FEAT_INS_EXPAND
2127 (char_u *)&p_ph, PV_NONE,
2128#else
2129 (char_u *)NULL, PV_NONE,
2130#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002131 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002132#if defined(DYNAMIC_PYTHON3)
Bram Moolenaar0796c062015-11-10 19:41:37 +01002133 {"pythonthreedll", NULL, P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002134 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002135 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2136 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002137#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002138#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002139 {"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2140 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002141 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2142 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002143#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002144 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2145#ifdef FEAT_TEXTOBJ
2146 (char_u *)&p_qe, PV_QE,
2147 {(char_u *)"\\", (char_u *)0L}
2148#else
2149 (char_u *)NULL, PV_NONE,
2150 {(char_u *)NULL, (char_u *)0L}
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2154 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002155 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156 {"redraw", NULL, P_BOOL|P_VI_DEF,
2157 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002158 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002159 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2160#ifdef FEAT_RELTIME
2161 (char_u *)&p_rdt, PV_NONE,
2162#else
2163 (char_u *)NULL, PV_NONE,
2164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002165 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002166 {"regexpengine", "re", P_NUM|P_VI_DEF,
2167 (char_u *)&p_re, PV_NONE,
2168 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002169 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2170 (char_u *)VAR_WIN, PV_RNU,
2171 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 {"remap", NULL, P_BOOL|P_VI_DEF,
2173 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002174 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002175 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002176#ifdef FEAT_RENDER_OPTIONS
2177 (char_u *)&p_rop, PV_NONE,
2178 {(char_u *)"", (char_u *)0L}
2179#else
2180 (char_u *)NULL, PV_NONE,
2181 {(char_u *)NULL, (char_u *)0L}
2182#endif
2183 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002184 {"report", NULL, P_NUM|P_VI_DEF,
2185 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002186 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2188#ifdef WIN3264
2189 (char_u *)&p_rs, PV_NONE,
2190#else
2191 (char_u *)NULL, PV_NONE,
2192#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2195#ifdef FEAT_RIGHTLEFT
2196 (char_u *)&p_ri, PV_NONE,
2197#else
2198 (char_u *)NULL, PV_NONE,
2199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002200 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002201 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2202#ifdef FEAT_RIGHTLEFT
2203 (char_u *)VAR_WIN, PV_RL,
2204#else
2205 (char_u *)NULL, PV_NONE,
2206#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2209#ifdef FEAT_RIGHTLEFT
2210 (char_u *)VAR_WIN, PV_RLC,
2211 {(char_u *)"search", (char_u *)NULL}
2212#else
2213 (char_u *)NULL, PV_NONE,
2214 {(char_u *)NULL, (char_u *)0L}
2215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002216 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002217#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002218 {"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2219 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002220 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2221 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002222#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2224#ifdef FEAT_CMDL_INFO
2225 (char_u *)&p_ru, PV_NONE,
2226#else
2227 (char_u *)NULL, PV_NONE,
2228#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2231#ifdef FEAT_STL_OPT
2232 (char_u *)&p_ruf, PV_NONE,
2233#else
2234 (char_u *)NULL, PV_NONE,
2235#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002236 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002237 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2238 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002240 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2241 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2243 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002244 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002245 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2246#ifdef FEAT_SCROLLBIND
2247 (char_u *)VAR_WIN, PV_SCBIND,
2248#else
2249 (char_u *)NULL, PV_NONE,
2250#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002251 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002252 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2253 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002254 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002255 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2256 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002257 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002258 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002259#ifdef FEAT_SCROLLBIND
2260 (char_u *)&p_sbo, PV_NONE,
2261 {(char_u *)"ver,jump", (char_u *)0L}
2262#else
2263 (char_u *)NULL, PV_NONE,
2264 {(char_u *)0L, (char_u *)0L}
2265#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002266 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {"sections", "sect", P_STRING|P_VI_DEF,
2268 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002269 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2270 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2272 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002276 {(char_u *)"inclusive", (char_u *)0L}
2277 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002278 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002280 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002281 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282#ifdef FEAT_SESSION
2283 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002284 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285 (char_u *)0L}
2286#else
2287 (char_u *)NULL, PV_NONE,
2288 {(char_u *)0L, (char_u *)0L}
2289#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2292 (char_u *)&p_sh, PV_NONE,
2293 {
2294#ifdef VMS
2295 (char_u *)"-",
2296#else
2297# if defined(MSDOS)
2298 (char_u *)"command",
2299# else
Bram Moolenaarcf7164a2016-02-20 13:55:06 +01002300# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 (char_u *)"", /* set in set_init_1() */
Bram Moolenaarcf7164a2016-02-20 13:55:06 +01002302# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304# endif
2305# endif
2306#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002307 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2309 (char_u *)&p_shcf, PV_NONE,
2310 {
2311#if defined(MSDOS) || defined(MSWIN)
2312 (char_u *)"/c",
2313#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2318#ifdef FEAT_QUICKFIX
2319 (char_u *)&p_sp, PV_NONE,
2320 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002321#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323#else
2324 (char_u *)">",
2325#endif
2326 (char_u *)0L}
2327#else
2328 (char_u *)NULL, PV_NONE,
2329 {(char_u *)0L, (char_u *)0L}
2330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2333 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002334 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2336 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2339#ifdef BACKSLASH_IN_FILENAME
2340 (char_u *)&p_ssl, PV_NONE,
2341#else
2342 (char_u *)NULL, PV_NONE,
2343#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002344 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002345 {"shelltemp", "stmp", P_BOOL,
2346 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002347 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 {"shelltype", "st", P_NUM|P_VI_DEF,
2349#ifdef AMIGA
2350 (char_u *)&p_st, PV_NONE,
2351#else
2352 (char_u *)NULL, PV_NONE,
2353#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2356 (char_u *)&p_sxq, PV_NONE,
2357 {
2358#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2359 (char_u *)"\"",
2360#else
2361 (char_u *)"",
2362#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002363 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002364 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2365 (char_u *)&p_sxe, PV_NONE,
2366 {
Bram Moolenaarcf7164a2016-02-20 13:55:06 +01002367#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002368 (char_u *)"\"&|<>()@^",
2369#else
2370 (char_u *)"",
2371#endif
2372 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2374 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2377 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2380 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)"", (char_u *)"filnxtToO"}
2382 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 {"shortname", "sn", P_BOOL|P_VI_DEF,
2384#ifdef SHORT_FNAME
2385 (char_u *)NULL, PV_NONE,
2386#else
2387 (char_u *)&p_sn, PV_SN,
2388#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002389 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2391#ifdef FEAT_LINEBREAK
2392 (char_u *)&p_sbr, PV_NONE,
2393#else
2394 (char_u *)NULL, PV_NONE,
2395#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"showcmd", "sc", P_BOOL|P_VIM,
2398#ifdef FEAT_CMDL_INFO
2399 (char_u *)&p_sc, PV_NONE,
2400#else
2401 (char_u *)NULL, PV_NONE,
2402#endif
2403 {(char_u *)FALSE,
2404#ifdef UNIX
2405 (char_u *)FALSE
2406#else
2407 (char_u *)TRUE
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2411 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2414 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"showmode", "smd", P_BOOL|P_VIM,
2417 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002419 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2420#ifdef FEAT_WINDOWS
2421 (char_u *)&p_stal, PV_NONE,
2422#else
2423 (char_u *)NULL, PV_NONE,
2424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2427 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2430 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2433 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2436 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2439#ifdef FEAT_SMARTINDENT
2440 (char_u *)&p_si, PV_SI,
2441#else
2442 (char_u *)NULL, PV_NONE,
2443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2446 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002447 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2449 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2452 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002454 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002455#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002456 (char_u *)VAR_WIN, PV_SPELL,
2457#else
2458 (char_u *)NULL, PV_NONE,
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002461 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002462#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002463 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002464 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002465#else
2466 (char_u *)NULL, PV_NONE,
2467 {(char_u *)0L, (char_u *)0L}
2468#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002470 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2471 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002472#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002473 (char_u *)&p_spf, PV_SPF,
2474 {(char_u *)"", (char_u *)0L}
2475#else
2476 (char_u *)NULL, PV_NONE,
2477 {(char_u *)0L, (char_u *)0L}
2478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002479 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002480 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2481 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002482#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002483 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002484 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002485#else
2486 (char_u *)NULL, PV_NONE,
2487 {(char_u *)0L, (char_u *)0L}
2488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002490 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002491#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002492 (char_u *)&p_sps, PV_NONE,
2493 {(char_u *)"best", (char_u *)0L}
2494#else
2495 (char_u *)NULL, PV_NONE,
2496 {(char_u *)0L, (char_u *)0L}
2497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2500#ifdef FEAT_WINDOWS
2501 (char_u *)&p_sb, PV_NONE,
2502#else
2503 (char_u *)NULL, PV_NONE,
2504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"splitright", "spr", P_BOOL|P_VI_DEF,
2507#ifdef FEAT_VERTSPLIT
2508 (char_u *)&p_spr, PV_NONE,
2509#else
2510 (char_u *)NULL, PV_NONE,
2511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2514 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2517#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002518 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519#else
2520 (char_u *)NULL, PV_NONE,
2521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002523 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 (char_u *)&p_su, PV_NONE,
2525 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002527 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002528#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 (char_u *)&p_sua, PV_SUA,
2530 {(char_u *)"", (char_u *)0L}
2531#else
2532 (char_u *)NULL, PV_NONE,
2533 {(char_u *)0L, (char_u *)0L}
2534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002535 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002536 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2537 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"swapsync", "sws", P_STRING|P_VI_DEF,
2540 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002542 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002545 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2546#ifdef FEAT_SYN_HL
2547 (char_u *)&p_smc, PV_SMC,
2548 {(char_u *)3000L, (char_u *)0L}
2549#else
2550 (char_u *)NULL, PV_NONE,
2551 {(char_u *)0L, (char_u *)0L}
2552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002554 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555#ifdef FEAT_SYN_HL
2556 (char_u *)&p_syn, PV_SYN,
2557 {(char_u *)"", (char_u *)0L}
2558#else
2559 (char_u *)NULL, PV_NONE,
2560 {(char_u *)0L, (char_u *)0L}
2561#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002563 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2564#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002565 (char_u *)&p_tal, PV_NONE,
2566#else
2567 (char_u *)NULL, PV_NONE,
2568#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002570 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2571#ifdef FEAT_WINDOWS
2572 (char_u *)&p_tpm, PV_NONE,
2573#else
2574 (char_u *)NULL, PV_NONE,
2575#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2578 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2581 (char_u *)&p_tbs, PV_NONE,
2582#ifdef VMS /* binary searching doesn't appear to work on VMS */
2583 {(char_u *)0L, (char_u *)0L}
2584#else
2585 {(char_u *)TRUE, (char_u *)0L}
2586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002588 {"tagcase", "tc", P_STRING|P_VIM,
2589 (char_u *)&p_tc, PV_TC,
2590 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {"taglength", "tl", P_NUM|P_VI_DEF,
2592 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"tagrelative", "tr", P_BOOL|P_VIM,
2595 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002597 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002598 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {
2600#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2601 (char_u *)"./tags,./TAGS,tags,TAGS",
2602#else
2603 (char_u *)"./tags,tags",
2604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2607 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002608 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002609#if defined(DYNAMIC_TCL)
2610 {"tcldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2611 (char_u *)&p_tcldll, PV_NONE,
2612 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2613 SCRIPTID_INIT},
2614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2616 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2619#ifdef FEAT_ARABIC
2620 (char_u *)&p_tbidi, PV_NONE,
2621#else
2622 (char_u *)NULL, PV_NONE,
2623#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2626#ifdef FEAT_MBYTE
2627 (char_u *)&p_tenc, PV_NONE,
2628 {(char_u *)"", (char_u *)0L}
2629#else
2630 (char_u *)NULL, PV_NONE,
2631 {(char_u *)0L, (char_u *)0L}
2632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 {"terse", NULL, P_BOOL|P_VI_DEF,
2635 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"textauto", "ta", P_BOOL|P_VIM,
2638 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2642 (char_u *)&p_tx, PV_TX,
2643 {
2644#ifdef USE_CRNL
2645 (char_u *)TRUE,
2646#else
2647 (char_u *)FALSE,
2648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002650 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002653 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002655 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656#else
2657 (char_u *)NULL, PV_NONE,
2658#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2661 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002662 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 {"timeout", "to", P_BOOL|P_VI_DEF,
2664 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2667 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002668 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"title", NULL, P_BOOL|P_VI_DEF,
2670#ifdef FEAT_TITLE
2671 (char_u *)&p_title, PV_NONE,
2672#else
2673 (char_u *)NULL, PV_NONE,
2674#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002676 {"titlelen", NULL, P_NUM|P_VI_DEF,
2677#ifdef FEAT_TITLE
2678 (char_u *)&p_titlelen, PV_NONE,
2679#else
2680 (char_u *)NULL, PV_NONE,
2681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002683 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684#ifdef FEAT_TITLE
2685 (char_u *)&p_titleold, PV_NONE,
2686 {(char_u *)N_("Thanks for flying Vim"),
2687 (char_u *)0L}
2688#else
2689 (char_u *)NULL, PV_NONE,
2690 {(char_u *)0L, (char_u *)0L}
2691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002692 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693 {"titlestring", NULL, P_STRING|P_VI_DEF,
2694#ifdef FEAT_TITLE
2695 (char_u *)&p_titlestring, PV_NONE,
2696#else
2697 (char_u *)NULL, PV_NONE,
2698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002701 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)"icons,tooltips", (char_u *)0L}
2704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002706#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2708 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002709 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710#endif
2711 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2712 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2715 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2718 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002719 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2721 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2724#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2725 (char_u *)&p_ttym, PV_NONE,
2726#else
2727 (char_u *)NULL, PV_NONE,
2728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2731 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2734 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002736 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2737 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002738#ifdef FEAT_PERSISTENT_UNDO
2739 (char_u *)&p_udir, PV_NONE,
2740 {(char_u *)".", (char_u *)0L}
2741#else
2742 (char_u *)NULL, PV_NONE,
2743 {(char_u *)0L, (char_u *)0L}
2744#endif
2745 SCRIPTID_INIT},
2746 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2747#ifdef FEAT_PERSISTENT_UNDO
2748 (char_u *)&p_udf, PV_UDF,
2749#else
2750 (char_u *)NULL, PV_NONE,
2751#endif
2752 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002754 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002756#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 (char_u *)1000L,
2758#else
2759 (char_u *)100L,
2760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002762 {"undoreload", "ur", P_NUM|P_VI_DEF,
2763 (char_u *)&p_ur, PV_NONE,
2764 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"updatecount", "uc", P_NUM|P_VI_DEF,
2766 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"updatetime", "ut", P_NUM|P_VI_DEF,
2769 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"verbose", "vbs", P_NUM|P_VI_DEF,
2772 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002774 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2775 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002776 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2778#ifdef FEAT_SESSION
2779 (char_u *)&p_vdir, PV_NONE,
2780 {(char_u *)DFLT_VDIR, (char_u *)0L}
2781#else
2782 (char_u *)NULL, PV_NONE,
2783 {(char_u *)0L, (char_u *)0L}
2784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002786 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787#ifdef FEAT_SESSION
2788 (char_u *)&p_vop, PV_NONE,
2789 {(char_u *)"folds,options,cursor", (char_u *)0L}
2790#else
2791 (char_u *)NULL, PV_NONE,
2792 {(char_u *)0L, (char_u *)0L}
2793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002795 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796#ifdef FEAT_VIMINFO
2797 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002798#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002799 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800#else
2801# ifdef AMIGA
2802 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002803 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002805 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806# endif
2807#endif
2808#else
2809 (char_u *)NULL, PV_NONE,
2810 {(char_u *)0L, (char_u *)0L}
2811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002813 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2814 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815#ifdef FEAT_VIRTUALEDIT
2816 (char_u *)&p_ve, PV_NONE,
2817 {(char_u *)"", (char_u *)""}
2818#else
2819 (char_u *)NULL, PV_NONE,
2820 {(char_u *)0L, (char_u *)0L}
2821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2824 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"w300", NULL, P_NUM|P_VI_DEF,
2827 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"w1200", NULL, P_NUM|P_VI_DEF,
2830 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"w9600", NULL, P_NUM|P_VI_DEF,
2833 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"warn", NULL, P_BOOL|P_VI_DEF,
2836 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2839 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002841 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"wildchar", "wc", P_NUM|P_VIM,
2845 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2847 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002848 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002851 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852#ifdef FEAT_WILDIGN
2853 (char_u *)&p_wig, PV_NONE,
2854#else
2855 (char_u *)NULL, PV_NONE,
2856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002858 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2859 (char_u *)&p_wic, PV_NONE,
2860 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2862#ifdef FEAT_WILDMENU
2863 (char_u *)&p_wmnu, PV_NONE,
2864#else
2865 (char_u *)NULL, PV_NONE,
2866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002867 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002868 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002871 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2872#ifdef FEAT_CMDL_COMPL
2873 (char_u *)&p_wop, PV_NONE,
2874 {(char_u *)"", (char_u *)0L}
2875#else
2876 (char_u *)NULL, PV_NONE,
2877 {(char_u *)NULL, (char_u *)0L}
2878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2881#ifdef FEAT_WAK
2882 (char_u *)&p_wak, PV_NONE,
2883 {(char_u *)"menu", (char_u *)0L}
2884#else
2885 (char_u *)NULL, PV_NONE,
2886 {(char_u *)NULL, (char_u *)0L}
2887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002890 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"winheight", "wh", P_NUM|P_VI_DEF,
2893#ifdef FEAT_WINDOWS
2894 (char_u *)&p_wh, PV_NONE,
2895#else
2896 (char_u *)NULL, PV_NONE,
2897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002898 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002900#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 (char_u *)VAR_WIN, PV_WFH,
2902#else
2903 (char_u *)NULL, PV_NONE,
2904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002906 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2907#ifdef FEAT_VERTSPLIT
2908 (char_u *)VAR_WIN, PV_WFW,
2909#else
2910 (char_u *)NULL, PV_NONE,
2911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2914#ifdef FEAT_WINDOWS
2915 (char_u *)&p_wmh, PV_NONE,
2916#else
2917 (char_u *)NULL, PV_NONE,
2918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002919 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2921#ifdef FEAT_VERTSPLIT
2922 (char_u *)&p_wmw, PV_NONE,
2923#else
2924 (char_u *)NULL, PV_NONE,
2925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2928#ifdef FEAT_VERTSPLIT
2929 (char_u *)&p_wiw, PV_NONE,
2930#else
2931 (char_u *)NULL, PV_NONE,
2932#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002933 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2935 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002936 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2938 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2941 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002942 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943 {"write", NULL, P_BOOL|P_VI_DEF,
2944 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002945 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946 {"writeany", "wa", P_BOOL|P_VI_DEF,
2947 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2950 (char_u *)&p_wb, PV_NONE,
2951 {
2952#ifdef FEAT_WRITEBACKUP
2953 (char_u *)TRUE,
2954#else
2955 (char_u *)FALSE,
2956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"writedelay", "wd", P_NUM|P_VI_DEF,
2959 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002960 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961
2962/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002963#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002965 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966
2967 p_term("t_AB", T_CAB)
2968 p_term("t_AF", T_CAF)
2969 p_term("t_AL", T_CAL)
2970 p_term("t_al", T_AL)
2971 p_term("t_bc", T_BC)
2972 p_term("t_cd", T_CD)
2973 p_term("t_ce", T_CE)
2974 p_term("t_cl", T_CL)
2975 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002976 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 p_term("t_Co", T_CCO)
2978 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002979 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 p_term("t_cs", T_CS)
2981#ifdef FEAT_VERTSPLIT
2982 p_term("t_CV", T_CSV)
2983#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984 p_term("t_da", T_DA)
2985 p_term("t_db", T_DB)
2986 p_term("t_DL", T_CDL)
2987 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002988 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 p_term("t_fs", T_FS)
2990 p_term("t_IE", T_CIE)
2991 p_term("t_IS", T_CIS)
2992 p_term("t_ke", T_KE)
2993 p_term("t_ks", T_KS)
2994 p_term("t_le", T_LE)
2995 p_term("t_mb", T_MB)
2996 p_term("t_md", T_MD)
2997 p_term("t_me", T_ME)
2998 p_term("t_mr", T_MR)
2999 p_term("t_ms", T_MS)
3000 p_term("t_nd", T_ND)
3001 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003002 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 p_term("t_RI", T_CRI)
3004 p_term("t_RV", T_CRV)
3005 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003007 p_term("t_Sf", T_CSF)
3008 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003010 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 p_term("t_te", T_TE)
3013 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003014 p_term("t_ts", T_TS)
3015 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 p_term("t_ue", T_UE)
3017 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003018 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 p_term("t_vb", T_VB)
3020 p_term("t_ve", T_VE)
3021 p_term("t_vi", T_VI)
3022 p_term("t_vs", T_VS)
3023 p_term("t_WP", T_CWP)
3024 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003025 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 p_term("t_xs", T_XS)
3027 p_term("t_ZH", T_CZH)
3028 p_term("t_ZR", T_CZR)
3029
3030/* terminal key codes are not in here */
3031
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003032 /* end marker */
3033 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034};
3035
3036#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3037
3038#ifdef FEAT_MBYTE
3039static char *(p_ambw_values[]) = {"single", "double", NULL};
3040#endif
3041static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003042static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003044#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003045static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003046#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003047#ifdef FEAT_CMDL_COMPL
3048static char *(p_wop_values[]) = {"tagfile", NULL};
3049#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050#ifdef FEAT_WAK
3051static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3052#endif
3053static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3055static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057#ifdef FEAT_BROWSE
3058static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3059#endif
3060#ifdef FEAT_SCROLLBIND
3061static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3062#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003063static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064#ifdef FEAT_VERTSPLIT
3065static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3066#endif
3067#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003068# ifdef FEAT_AUTOCMD
3069static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3070# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003072# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3074#endif
3075static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3076#ifdef FEAT_FOLDING
3077static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003078# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003080# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 NULL};
3082static char *(p_fcl_values[]) = {"all", NULL};
3083#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003084#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003085static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003086#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003088static void set_option_default(int, int opt_flags, int compatible);
3089static void set_options_default(int opt_flags);
3090static char_u *term_bg_default(void);
3091static void did_set_option(int opt_idx, int opt_flags, int new_value);
3092static char_u *illegal_char(char_u *, int);
3093static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003095static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096#endif
3097#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003098static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003100static char_u *option_expand(int opt_idx, char_u *val);
3101static void didset_options(void);
3102static void didset_options2(void);
3103static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003104#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003105static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003106#else
3107# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3108#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003109static void set_string_option_global(int opt_idx, char_u **varp);
3110static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3111static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3112static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003113#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003114static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003115#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003117static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003119#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003120static char_u *did_set_spell_option(int is_spellfile);
3121static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003122#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003123#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003124static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003125#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003126static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3127static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3128static void check_redraw(long_u flags);
3129static int findoption(char_u *);
3130static int find_key_option(char_u *);
3131static void showoptions(int all, int opt_flags);
3132static int optval_default(struct vimoption *, char_u *varp);
3133static void showoneopt(struct vimoption *, int opt_flags);
3134static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3135static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3136static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3137static int istermoption(struct vimoption *);
3138static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3139static char_u *get_varp(struct vimoption *);
3140static void option_value2string(struct vimoption *, int opt_flags);
3141static void check_winopt(winopt_T *wop);
3142static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003144static void langmap_init(void);
3145static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003147static void paste_option_changed(void);
3148static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003150static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003152static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3153static int check_opt_strings(char_u *val, char **values, int);
3154static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003155#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003156static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158
3159/*
3160 * Initialize the options, first part.
3161 *
3162 * Called only once from main(), just after creating the first buffer.
3163 */
3164 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003165set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166{
3167 char_u *p;
3168 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003169 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170
3171#ifdef FEAT_LANGMAP
3172 langmap_init();
3173#endif
3174
3175 /* Be Vi compatible by default */
3176 p_cp = TRUE;
3177
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003178 /* Use POSIX compatibility when $VIM_POSIX is set. */
3179 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003180 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003181 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003182 set_string_default("shm", (char_u *)"A");
3183 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003184
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 /*
3186 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003187 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003189 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003190#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003192 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003194 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003196 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197# endif
3198#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003199 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 set_string_default("sh", p);
3201
3202#ifdef FEAT_WILDIGN
3203 /*
3204 * Set the default for 'backupskip' to include environment variables for
3205 * temp files.
3206 */
3207 {
3208# ifdef UNIX
3209 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3210# else
3211 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3212# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003213 int len;
3214 garray_T ga;
3215 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216
3217 ga_init2(&ga, 1, 100);
3218 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3219 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003220 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221# ifdef UNIX
3222 if (*names[n] == NUL)
3223 p = (char_u *)"/tmp";
3224 else
3225# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003226 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 if (p != NULL && *p != NUL)
3228 {
3229 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003230 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231 if (ga_grow(&ga, len) == OK)
3232 {
3233 if (ga.ga_len > 0)
3234 STRCAT(ga.ga_data, ",");
3235 STRCAT(ga.ga_data, p);
3236 add_pathsep(ga.ga_data);
3237 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 ga.ga_len += len;
3239 }
3240 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003241 if (mustfree)
3242 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243 }
3244 if (ga.ga_data != NULL)
3245 {
3246 set_string_default("bsk", ga.ga_data);
3247 vim_free(ga.ga_data);
3248 }
3249 }
3250#endif
3251
3252 /*
3253 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3254 */
3255 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003256 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003258#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3259 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3260#endif
3261 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003263 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003264 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265#else
3266# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003267 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003268 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003270 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003271# endif
3272#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003274 opt_idx = findoption((char_u *)"maxmem");
3275 if (opt_idx >= 0)
3276 {
3277#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003278 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3279 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003280#endif
3281 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3282 }
3283 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003284 }
3285
3286#ifdef FEAT_GUI_W32
3287 /* force 'shortname' for Win32s */
3288 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003289 {
3290 opt_idx = findoption((char_u *)"shortname");
3291 if (opt_idx >= 0)
3292 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3293 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294#endif
3295
3296#ifdef FEAT_SEARCHPATH
3297 {
3298 char_u *cdpath;
3299 char_u *buf;
3300 int i;
3301 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003302 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303
3304 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003305 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306 if (cdpath != NULL)
3307 {
3308 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3309 if (buf != NULL)
3310 {
3311 buf[0] = ','; /* start with ",", current dir first */
3312 j = 1;
3313 for (i = 0; cdpath[i] != NUL; ++i)
3314 {
3315 if (vim_ispathlistsep(cdpath[i]))
3316 buf[j++] = ',';
3317 else
3318 {
3319 if (cdpath[i] == ' ' || cdpath[i] == ',')
3320 buf[j++] = '\\';
3321 buf[j++] = cdpath[i];
3322 }
3323 }
3324 buf[j] = NUL;
3325 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003326 if (opt_idx >= 0)
3327 {
3328 options[opt_idx].def_val[VI_DEFAULT] = buf;
3329 options[opt_idx].flags |= P_DEF_ALLOCED;
3330 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003331 else
3332 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003334 if (mustfree)
3335 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 }
3337 }
3338#endif
3339
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003340#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341 /* Set print encoding on platforms that don't default to latin1 */
3342 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003343# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 (char_u *)"cp1252"
3345# else
3346# ifdef VMS
3347 (char_u *)"dec-mcs"
3348# else
3349# ifdef EBCDIC
3350 (char_u *)"ebcdic-uk"
3351# else
3352# ifdef MAC
3353 (char_u *)"mac-roman"
3354# else /* HPUX */
3355 (char_u *)"hp-roman8"
3356# endif
3357# endif
3358# endif
3359# endif
3360 );
3361#endif
3362
3363#ifdef FEAT_POSTSCRIPT
3364 /* 'printexpr' must be allocated to be able to evaluate it. */
3365 set_string_default("pexpr",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003366# if defined(MSWIN) || defined(MSDOS)
Bram Moolenaared203462004-06-16 11:19:22 +00003367 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368# else
3369# ifdef VMS
3370 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3371
3372# else
3373 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3374# endif
3375# endif
3376 );
3377#endif
3378
3379 /*
3380 * Set all the options (except the terminal options) to their default
3381 * value. Also set the global value for local options.
3382 */
3383 set_options_default(0);
3384
3385#ifdef FEAT_GUI
3386 if (found_reverse_arg)
3387 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3388#endif
3389
3390 curbuf->b_p_initialized = TRUE;
3391 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003392 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393 check_buf_options(curbuf);
3394 check_win_options(curwin);
3395 check_options();
3396
3397 /* Must be before option_expand(), because that one needs vim_isIDc() */
3398 didset_options();
3399
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003400#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003401 /* Use the current chartab for the generic chartab. This is not in
3402 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003403 init_spell_chartab();
3404#endif
3405
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406 /*
3407 * Expand environment variables and things like "~" for the defaults.
3408 * If option_expand() returns non-NULL the variable is expanded. This can
3409 * only happen for non-indirect options.
3410 * Also set the default to the expanded value, so ":set" does not list
3411 * them.
3412 * Don't set the P_ALLOCED flag, because we don't want to free the
3413 * default.
3414 */
3415 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3416 {
3417 if ((options[opt_idx].flags & P_GETTEXT)
3418 && options[opt_idx].var != NULL)
3419 p = (char_u *)_(*(char **)options[opt_idx].var);
3420 else
3421 p = option_expand(opt_idx, NULL);
3422 if (p != NULL && (p = vim_strsave(p)) != NULL)
3423 {
3424 *(char_u **)options[opt_idx].var = p;
3425 /* VIMEXP
3426 * Defaults for all expanded options are currently the same for Vi
3427 * and Vim. When this changes, add some code here! Also need to
3428 * split P_DEF_ALLOCED in two.
3429 */
3430 if (options[opt_idx].flags & P_DEF_ALLOCED)
3431 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3432 options[opt_idx].def_val[VI_DEFAULT] = p;
3433 options[opt_idx].flags |= P_DEF_ALLOCED;
3434 }
3435 }
3436
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 save_file_ff(curbuf); /* Buffer is unchanged */
3438
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439#if defined(FEAT_ARABIC)
3440 /* Detect use of mlterm.
3441 * Mlterm is a terminal emulator akin to xterm that has some special
3442 * abilities (bidi namely).
3443 * NOTE: mlterm's author is being asked to 'set' a variable
3444 * instead of an environment variable due to inheritance.
3445 */
3446 if (mch_getenv((char_u *)"MLTERM") != NULL)
3447 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3448#endif
3449
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003450 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003451
3452#ifdef FEAT_MBYTE
3453# if defined(WIN3264) && defined(FEAT_GETTEXT)
3454 /*
3455 * If $LANG isn't set, try to get a good value for it. This makes the
3456 * right language be used automatically. Don't do this for English.
3457 */
3458 if (mch_getenv((char_u *)"LANG") == NULL)
3459 {
3460 char buf[20];
3461
3462 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3463 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3464 * only the first two. */
3465 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3466 (LPTSTR)buf, 20);
3467 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3468 {
3469 /* There are a few exceptions (probably more) */
3470 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3471 STRCPY(buf, "zh_TW");
3472 else if (STRNICMP(buf, "chs", 3) == 0
3473 || STRNICMP(buf, "zhc", 3) == 0)
3474 STRCPY(buf, "zh_CN");
3475 else if (STRNICMP(buf, "jp", 2) == 0)
3476 STRCPY(buf, "ja");
3477 else
3478 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003479 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480 }
3481 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003482# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003483# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003484 /* Moved to os_mac_conv.c to avoid dependency problems. */
3485 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003486# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487# endif
3488
3489 /* enc_locale() will try to find the encoding of the current locale. */
3490 p = enc_locale();
3491 if (p != NULL)
3492 {
3493 char_u *save_enc;
3494
3495 /* Try setting 'encoding' and check if the value is valid.
3496 * If not, go back to the default "latin1". */
3497 save_enc = p_enc;
3498 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003499 if (STRCMP(p_enc, "gb18030") == 0)
3500 {
3501 /* We don't support "gb18030", but "cp936" is a good substitute
3502 * for practical purposes, thus use that. It's not an alias to
3503 * still support conversion between gb18030 and utf-8. */
3504 p_enc = vim_strsave((char_u *)"cp936");
3505 vim_free(p);
3506 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507 if (mb_init() == NULL)
3508 {
3509 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003510 if (opt_idx >= 0)
3511 {
3512 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3513 options[opt_idx].flags |= P_DEF_ALLOCED;
3514 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003516#if defined(MSDOS) || defined(MSWIN) || defined(MACOS) \
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003517 || defined(VMS)
3518 if (STRCMP(p_enc, "latin1") == 0
3519# ifdef FEAT_MBYTE
3520 || enc_utf8
3521# endif
3522 )
3523 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003524 /* Adjust the default for 'isprint' and 'iskeyword' to match
3525 * latin1. Also set the defaults for when 'nocompatible' is
3526 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003527 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003528 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003529 set_string_option_direct((char_u *)"isk", -1,
3530 ISK_LATIN1, OPT_FREE, SID_NONE);
3531 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003532 if (opt_idx >= 0)
3533 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003534 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003535 if (opt_idx >= 0)
3536 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003537 (void)init_chartab();
3538 }
3539#endif
3540
Bram Moolenaar071d4272004-06-13 20:20:40 +00003541# if defined(WIN3264) && !defined(FEAT_GUI)
3542 /* Win32 console: When GetACP() returns a different value from
3543 * GetConsoleCP() set 'termencoding'. */
3544 if (GetACP() != GetConsoleCP())
3545 {
3546 char buf[50];
3547
3548 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3549 p_tenc = vim_strsave((char_u *)buf);
3550 if (p_tenc != NULL)
3551 {
3552 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003553 if (opt_idx >= 0)
3554 {
3555 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3556 options[opt_idx].flags |= P_DEF_ALLOCED;
3557 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003558 convert_setup(&input_conv, p_tenc, p_enc);
3559 convert_setup(&output_conv, p_enc, p_tenc);
3560 }
3561 else
3562 p_tenc = empty_option;
3563 }
3564# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003565# if defined(WIN3264) && defined(FEAT_MBYTE)
3566 /* $HOME may have characters in active code page. */
3567 init_homedir();
3568# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003569 }
3570 else
3571 {
3572 vim_free(p_enc);
3573 p_enc = save_enc;
3574 }
3575 }
3576#endif
3577
3578#ifdef FEAT_MULTI_LANG
3579 /* Set the default for 'helplang'. */
3580 set_helplang_default(get_mess_lang());
3581#endif
3582}
3583
3584/*
3585 * Set an option to its default value.
3586 * This does not take care of side effects!
3587 */
3588 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003589set_option_default(
3590 int opt_idx,
3591 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3592 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593{
3594 char_u *varp; /* pointer to variable for current option */
3595 int dvi; /* index in def_val[] */
3596 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003597 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3599
3600 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3601 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003602 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603 {
3604 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3605 if (flags & P_STRING)
3606 {
3607 /* Use set_string_option_direct() for local options to handle
3608 * freeing and allocating the value. */
3609 if (options[opt_idx].indir != PV_NONE)
3610 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003611 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003612 else
3613 {
3614 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3615 free_string_option(*(char_u **)(varp));
3616 *(char_u **)varp = options[opt_idx].def_val[dvi];
3617 options[opt_idx].flags &= ~P_ALLOCED;
3618 }
3619 }
3620 else if (flags & P_NUM)
3621 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003622 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623 win_comp_scroll(curwin);
3624 else
3625 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003626 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 /* May also set global value for local option. */
3628 if (both)
3629 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3630 *(long *)varp;
3631 }
3632 }
3633 else /* P_BOOL */
3634 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003635 /* the cast to long is required for Manx C, long_i is needed for
3636 * MSVC */
3637 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003638#ifdef UNIX
3639 /* 'modeline' defaults to off for root */
3640 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3641 *(int *)varp = FALSE;
3642#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003643 /* May also set global value for local option. */
3644 if (both)
3645 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3646 *(int *)varp;
3647 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003648
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003649 /* The default value is not insecure. */
3650 flagsp = insecure_flag(opt_idx, opt_flags);
3651 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652 }
3653
3654#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003655 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003656#endif
3657}
3658
3659/*
3660 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003661 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662 */
3663 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003664set_options_default(
3665 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003666{
3667 int i;
3668#ifdef FEAT_WINDOWS
3669 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003670 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671#endif
3672
3673 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003674 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003675#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003676 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003677 || (TRUE
3678# if defined(FEAT_MBYTE)
3679 && options[i].var != (char_u *)&p_enc
3680# endif
3681# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003682 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003683 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003684# endif
3685 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003686#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003687 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003688 set_option_default(i, opt_flags, p_cp);
3689
3690#ifdef FEAT_WINDOWS
3691 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003692 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003693 win_comp_scroll(wp);
3694#else
3695 win_comp_scroll(curwin);
3696#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003697#ifdef FEAT_CINDENT
3698 parse_cino(curbuf);
3699#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700}
3701
3702/*
3703 * Set the Vi-default value of a string option.
3704 * Used for 'sh', 'backupskip' and 'term'.
3705 */
3706 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003707set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708{
3709 char_u *p;
3710 int opt_idx;
3711
3712 p = vim_strsave(val);
3713 if (p != NULL) /* we don't want a NULL */
3714 {
3715 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003716 if (opt_idx >= 0)
3717 {
3718 if (options[opt_idx].flags & P_DEF_ALLOCED)
3719 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3720 options[opt_idx].def_val[VI_DEFAULT] = p;
3721 options[opt_idx].flags |= P_DEF_ALLOCED;
3722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723 }
3724}
3725
3726/*
3727 * Set the Vi-default value of a number option.
3728 * Used for 'lines' and 'columns'.
3729 */
3730 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003731set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003733 int opt_idx;
3734
3735 opt_idx = findoption((char_u *)name);
3736 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003737 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738}
3739
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003740#if defined(EXITFREE) || defined(PROTO)
3741/*
3742 * Free all options.
3743 */
3744 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003745free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003746{
3747 int i;
3748
3749 for (i = 0; !istermoption(&options[i]); i++)
3750 {
3751 if (options[i].indir == PV_NONE)
3752 {
3753 /* global option: free value and default value. */
3754 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3755 free_string_option(*(char_u **)options[i].var);
3756 if (options[i].flags & P_DEF_ALLOCED)
3757 free_string_option(options[i].def_val[VI_DEFAULT]);
3758 }
3759 else if (options[i].var != VAR_WIN
3760 && (options[i].flags & P_STRING))
3761 /* buffer-local option: free global value */
3762 free_string_option(*(char_u **)options[i].var);
3763 }
3764}
3765#endif
3766
3767
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768/*
3769 * Initialize the options, part two: After getting Rows and Columns and
3770 * setting 'term'.
3771 */
3772 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003773set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003774{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003775 int idx;
3776
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 /*
3778 * 'scroll' defaults to half the window height. Note that this default is
3779 * wrong when the window height changes.
3780 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003781 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003782 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003783 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003784 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 comp_col();
3786
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003787 /*
3788 * 'window' is only for backwards compatibility with Vi.
3789 * Default is Rows - 1.
3790 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003791 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003792 p_window = Rows - 1;
3793 set_number_default("window", Rows - 1);
3794
Bram Moolenaarf740b292006-02-16 22:11:02 +00003795 /* For DOS console the default is always black. */
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003796#if !((defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003797 /*
3798 * If 'background' wasn't set by the user, try guessing the value,
3799 * depending on the terminal name. Only need to check for terminals
3800 * with a dark background, that can handle color.
3801 */
3802 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003803 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3804 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003806 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003807 /* don't mark it as set, when starting the GUI it may be
3808 * changed again */
3809 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 }
3811#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003812
3813#ifdef CURSOR_SHAPE
3814 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3815#endif
3816#ifdef FEAT_MOUSESHAPE
3817 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3818#endif
3819#ifdef FEAT_PRINTER
3820 (void)parse_printoptions(); /* parse 'printoptions' default value */
3821#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822}
3823
3824/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003825 * Return "dark" or "light" depending on the kind of terminal.
3826 * This is just guessing! Recognized are:
3827 * "linux" Linux console
3828 * "screen.linux" Linux console with screen
3829 * "cygwin" Cygwin shell
3830 * "putty" Putty program
3831 * We also check the COLORFGBG environment variable, which is set by
3832 * rxvt and derivatives. This variable contains either two or three
3833 * values separated by semicolons; we want the last value in either
3834 * case. If this value is 0-6 or 8, our background is dark.
3835 */
3836 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003837term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003838{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003839#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003840 /* DOS console nearly always black */
3841 return (char_u *)"dark";
3842#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003843 char_u *p;
3844
Bram Moolenaarf740b292006-02-16 22:11:02 +00003845 if (STRCMP(T_NAME, "linux") == 0
3846 || STRCMP(T_NAME, "screen.linux") == 0
3847 || STRCMP(T_NAME, "cygwin") == 0
3848 || STRCMP(T_NAME, "putty") == 0
3849 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3850 && (p = vim_strrchr(p, ';')) != NULL
3851 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3852 && p[2] == NUL))
3853 return (char_u *)"dark";
3854 return (char_u *)"light";
3855#endif
3856}
3857
3858/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003859 * Initialize the options, part three: After reading the .vimrc
3860 */
3861 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003862set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003864#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865/*
3866 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3867 * This is done after other initializations, where 'shell' might have been
3868 * set, but only if they have not been set before.
3869 */
3870 char_u *p;
3871 int idx_srr;
3872 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003873# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003874 int idx_sp;
3875 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003876# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877
3878 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003879 if (idx_srr < 0)
3880 do_srr = FALSE;
3881 else
3882 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003883# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003885 if (idx_sp < 0)
3886 do_sp = FALSE;
3887 else
3888 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003889# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003890 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891 if (p != NULL)
3892 {
3893 /*
3894 * Default for p_sp is "| tee", for p_srr is ">".
3895 * For known shells it is changed here to include stderr.
3896 */
3897 if ( fnamecmp(p, "csh") == 0
3898 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003899# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003900 || fnamecmp(p, "csh.exe") == 0
3901 || fnamecmp(p, "tcsh.exe") == 0
3902# endif
3903 )
3904 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003905# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906 if (do_sp)
3907 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003908# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003910# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003912# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3914 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003915# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 if (do_srr)
3917 {
3918 p_srr = (char_u *)">&";
3919 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3920 }
3921 }
3922 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003923 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 if ( fnamecmp(p, "sh") == 0
3925 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003926 || fnamecmp(p, "mksh") == 0
3927 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003929 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003931 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003932# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 || fnamecmp(p, "cmd") == 0
3934 || fnamecmp(p, "sh.exe") == 0
3935 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003936 || fnamecmp(p, "mksh.exe") == 0
3937 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003939 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 || fnamecmp(p, "bash.exe") == 0
3941 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003943 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003945# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946 if (do_sp)
3947 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003948# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003950# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003952# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003953 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3954 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003955# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 if (do_srr)
3957 {
3958 p_srr = (char_u *)">%s 2>&1";
3959 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3960 }
3961 }
3962 vim_free(p);
3963 }
3964#endif
3965
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003966#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003967 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003968 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3969 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970 * This is done after other initializations, where 'shell' might have been
3971 * set, but only if they have not been set before. Default for p_shcf is
3972 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3973 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3974 * command.com. And for Win32 we need to set p_sxq instead.
3975 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003976 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 {
3978 int idx3;
3979
3980 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003981 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003982 {
3983 p_shcf = (char_u *)"-c";
3984 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3985 }
3986
3987# ifndef DJGPP
3988# ifdef WIN3264
3989 /* Somehow Win32 requires the quotes around the redirection too */
3990 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003991 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003992 {
3993 p_sxq = (char_u *)"\"";
3994 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3995 }
3996# else
3997 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003998 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003999 {
4000 p_shq = (char_u *)"\"";
4001 options[idx3].def_val[VI_DEFAULT] = p_shq;
4002 }
4003# endif
4004# endif
4005 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004006 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4007 {
4008 int idx3;
4009
4010 /*
4011 * cmd.exe on Windows will strip the first and last double quote given
4012 * on the command line, e.g. most of the time things like:
4013 * cmd /c "my path/to/echo" "my args to echo"
4014 * become:
4015 * my path/to/echo" "my args to echo
4016 * when executed.
4017 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004018 * To avoid this, set shellxquote to surround the command in
4019 * parenthesis. This appears to make most commands work, without
4020 * breaking commands that worked previously, such as
4021 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004022 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004023 idx3 = findoption((char_u *)"sxq");
4024 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4025 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004026 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004027 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4028 }
4029
Bram Moolenaara64ba222012-02-12 23:23:31 +01004030 idx3 = findoption((char_u *)"shcf");
4031 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4032 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004033 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004034 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4035 }
4036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037#endif
4038
4039#ifdef FEAT_TITLE
4040 set_title_defaults();
4041#endif
4042}
4043
4044#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4045/*
4046 * When 'helplang' is still at its default value, set it to "lang".
4047 * Only the first two characters of "lang" are used.
4048 */
4049 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004050set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004051{
4052 int idx;
4053
4054 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4055 return;
4056 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004057 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 {
4059 if (options[idx].flags & P_ALLOCED)
4060 free_string_option(p_hlg);
4061 p_hlg = vim_strsave(lang);
4062 if (p_hlg == NULL)
4063 p_hlg = empty_option;
4064 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004065 {
4066 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4067 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4068 {
4069 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4070 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4071 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004073 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 options[idx].flags |= P_ALLOCED;
4075 }
4076}
4077#endif
4078
4079#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004080static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081
4082 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004083gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084{
4085 if (gui_get_lightness(gui.back_pixel) < 127)
4086 return (char_u *)"dark";
4087 return (char_u *)"light";
4088}
4089
4090/*
4091 * Option initializations that can only be done after opening the GUI window.
4092 */
4093 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004094init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095{
4096 /* Set the 'background' option according to the lightness of the
4097 * background color, unless the user has set it already. */
4098 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4099 {
4100 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4101 highlight_changed();
4102 }
4103}
4104#endif
4105
4106#ifdef FEAT_TITLE
4107/*
4108 * 'title' and 'icon' only default to true if they have not been set or reset
4109 * in .vimrc and we can read the old value.
4110 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4111 * they can be reset. This reduces startup time when using X on a remote
4112 * machine.
4113 */
4114 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004115set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116{
4117 int idx1;
4118 long val;
4119
4120 /*
4121 * If GUI is (going to be) used, we can always set the window title and
4122 * icon name. Saves a bit of time, because the X11 display server does
4123 * not need to be contacted.
4124 */
4125 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004126 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 {
4128#ifdef FEAT_GUI
4129 if (gui.starting || gui.in_use)
4130 val = TRUE;
4131 else
4132#endif
4133 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004134 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 p_title = val;
4136 }
4137 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004138 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 {
4140#ifdef FEAT_GUI
4141 if (gui.starting || gui.in_use)
4142 val = TRUE;
4143 else
4144#endif
4145 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004146 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 p_icon = val;
4148 }
4149}
4150#endif
4151
4152/*
4153 * Parse 'arg' for option settings.
4154 *
4155 * 'arg' may be IObuff, but only when no errors can be present and option
4156 * does not need to be expanded with option_expand().
4157 * "opt_flags":
4158 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004159 * OPT_GLOBAL for ":setglobal"
4160 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004162 * OPT_WINONLY to only set window-local options
4163 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004164 *
4165 * returns FAIL if an error is detected, OK otherwise
4166 */
4167 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004168do_set(
4169 char_u *arg, /* option string (may be written to!) */
4170 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171{
4172 int opt_idx;
4173 char_u *errmsg;
4174 char_u errbuf[80];
4175 char_u *startarg;
4176 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4177 int nextchar; /* next non-white char after option name */
4178 int afterchar; /* character just after option name */
4179 int len;
4180 int i;
4181 long value;
4182 int key;
4183 long_u flags; /* flags for current option */
4184 char_u *varp = NULL; /* pointer to variable for current option */
4185 int did_show = FALSE; /* already showed one value */
4186 int adding; /* "opt+=arg" */
4187 int prepending; /* "opt^=arg" */
4188 int removing; /* "opt-=arg" */
4189 int cp_val = 0;
4190 char_u key_name[2];
4191
4192 if (*arg == NUL)
4193 {
4194 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004195 did_show = TRUE;
4196 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004197 }
4198
4199 while (*arg != NUL) /* loop to process all options */
4200 {
4201 errmsg = NULL;
4202 startarg = arg; /* remember for error message */
4203
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004204 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4205 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206 {
4207 /*
4208 * ":set all" show all options.
4209 * ":set all&" set all options to their default value.
4210 */
4211 arg += 3;
4212 if (*arg == '&')
4213 {
4214 ++arg;
4215 /* Only for :set command set global value of local options. */
4216 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004217 didset_options();
4218 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004219 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004220 }
4221 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004222 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004223 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004224 did_show = TRUE;
4225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004227 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004228 {
4229 showoptions(2, opt_flags);
4230 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004231 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004232 arg += 7;
4233 }
4234 else
4235 {
4236 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004237 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238 {
4239 prefix = 0;
4240 arg += 2;
4241 }
4242 else if (STRNCMP(arg, "inv", 3) == 0)
4243 {
4244 prefix = 2;
4245 arg += 3;
4246 }
4247
4248 /* find end of name */
4249 key = 0;
4250 if (*arg == '<')
4251 {
4252 nextchar = 0;
4253 opt_idx = -1;
4254 /* look out for <t_>;> */
4255 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4256 len = 5;
4257 else
4258 {
4259 len = 1;
4260 while (arg[len] != NUL && arg[len] != '>')
4261 ++len;
4262 }
4263 if (arg[len] != '>')
4264 {
4265 errmsg = e_invarg;
4266 goto skip;
4267 }
4268 arg[len] = NUL; /* put NUL after name */
4269 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4270 opt_idx = findoption(arg + 1);
4271 arg[len++] = '>'; /* restore '>' */
4272 if (opt_idx == -1)
4273 key = find_key_option(arg + 1);
4274 }
4275 else
4276 {
4277 len = 0;
4278 /*
4279 * The two characters after "t_" may not be alphanumeric.
4280 */
4281 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4282 len = 4;
4283 else
4284 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4285 ++len;
4286 nextchar = arg[len];
4287 arg[len] = NUL; /* put NUL after name */
4288 opt_idx = findoption(arg);
4289 arg[len] = nextchar; /* restore nextchar */
4290 if (opt_idx == -1)
4291 key = find_key_option(arg);
4292 }
4293
4294 /* remember character after option name */
4295 afterchar = arg[len];
4296
4297 /* skip white space, allow ":set ai ?" */
4298 while (vim_iswhite(arg[len]))
4299 ++len;
4300
4301 adding = FALSE;
4302 prepending = FALSE;
4303 removing = FALSE;
4304 if (arg[len] != NUL && arg[len + 1] == '=')
4305 {
4306 if (arg[len] == '+')
4307 {
4308 adding = TRUE; /* "+=" */
4309 ++len;
4310 }
4311 else if (arg[len] == '^')
4312 {
4313 prepending = TRUE; /* "^=" */
4314 ++len;
4315 }
4316 else if (arg[len] == '-')
4317 {
4318 removing = TRUE; /* "-=" */
4319 ++len;
4320 }
4321 }
4322 nextchar = arg[len];
4323
4324 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4325 {
4326 errmsg = (char_u *)N_("E518: Unknown option");
4327 goto skip;
4328 }
4329
4330 if (opt_idx >= 0)
4331 {
4332 if (options[opt_idx].var == NULL) /* hidden option: skip */
4333 {
4334 /* Only give an error message when requesting the value of
4335 * a hidden option, ignore setting it. */
4336 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4337 && (!(options[opt_idx].flags & P_BOOL)
4338 || nextchar == '?'))
4339 errmsg = (char_u *)N_("E519: Option not supported");
4340 goto skip;
4341 }
4342
4343 flags = options[opt_idx].flags;
4344 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4345 }
4346 else
4347 {
4348 flags = P_STRING;
4349 if (key < 0)
4350 {
4351 key_name[0] = KEY2TERMCAP0(key);
4352 key_name[1] = KEY2TERMCAP1(key);
4353 }
4354 else
4355 {
4356 key_name[0] = KS_KEY;
4357 key_name[1] = (key & 0xff);
4358 }
4359 }
4360
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004361 /* Skip all options that are not window-local (used when showing
4362 * an already loaded buffer in a window). */
4363 if ((opt_flags & OPT_WINONLY)
4364 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4365 goto skip;
4366
Bram Moolenaara3227e22006-03-08 21:32:40 +00004367 /* Skip all options that are window-local (used for :vimgrep). */
4368 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4369 && options[opt_idx].var == VAR_WIN)
4370 goto skip;
4371
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004372 /* Disallow changing some options from modelines. */
4373 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004374 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004375 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004376 {
4377 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4378 goto skip;
4379 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004380#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004381 /* In diff mode some options are overruled. This avoids that
4382 * 'foldmethod' becomes "marker" instead of "diff" and that
4383 * "wrap" gets set. */
4384 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004385 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004386 && (options[opt_idx].indir == PV_FDM
4387 || options[opt_idx].indir == PV_WRAP))
4388 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004389#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004390 }
4391
4392#ifdef HAVE_SANDBOX
4393 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004394 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004395 {
4396 errmsg = (char_u *)_(e_sandbox);
4397 goto skip;
4398 }
4399#endif
4400
4401 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4402 {
4403 arg += len;
4404 cp_val = p_cp;
4405 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4406 {
4407 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4408 {
4409 cp_val = FALSE;
4410 arg += 3;
4411 }
4412 else /* "opt&vi": set to Vi default */
4413 {
4414 cp_val = TRUE;
4415 arg += 2;
4416 }
4417 }
4418 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4419 && arg[1] != NUL && !vim_iswhite(arg[1]))
4420 {
4421 errmsg = e_trailing;
4422 goto skip;
4423 }
4424 }
4425
4426 /*
4427 * allow '=' and ':' as MSDOS command.com allows only one
4428 * '=' character per "set" command line. grrr. (jw)
4429 */
4430 if (nextchar == '?'
4431 || (prefix == 1
4432 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4433 && !(flags & P_BOOL)))
4434 {
4435 /*
4436 * print value
4437 */
4438 if (did_show)
4439 msg_putchar('\n'); /* cursor below last one */
4440 else
4441 {
4442 gotocmdline(TRUE); /* cursor at status line */
4443 did_show = TRUE; /* remember that we did a line */
4444 }
4445 if (opt_idx >= 0)
4446 {
4447 showoneopt(&options[opt_idx], opt_flags);
4448#ifdef FEAT_EVAL
4449 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004450 {
4451 /* Mention where the option was last set. */
4452 if (varp == options[opt_idx].var)
4453 last_set_msg(options[opt_idx].scriptID);
4454 else if ((int)options[opt_idx].indir & PV_WIN)
4455 last_set_msg(curwin->w_p_scriptID[
4456 (int)options[opt_idx].indir & PV_MASK]);
4457 else if ((int)options[opt_idx].indir & PV_BUF)
4458 last_set_msg(curbuf->b_p_scriptID[
4459 (int)options[opt_idx].indir & PV_MASK]);
4460 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004461#endif
4462 }
4463 else
4464 {
4465 char_u *p;
4466
4467 p = find_termcode(key_name);
4468 if (p == NULL)
4469 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004470 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004471 goto skip;
4472 }
4473 else
4474 (void)show_one_termcode(key_name, p, TRUE);
4475 }
4476 if (nextchar != '?'
4477 && nextchar != NUL && !vim_iswhite(afterchar))
4478 errmsg = e_trailing;
4479 }
4480 else
4481 {
4482 if (flags & P_BOOL) /* boolean */
4483 {
4484 if (nextchar == '=' || nextchar == ':')
4485 {
4486 errmsg = e_invarg;
4487 goto skip;
4488 }
4489
4490 /*
4491 * ":set opt!": invert
4492 * ":set opt&": reset to default value
4493 * ":set opt<": reset to global value
4494 */
4495 if (nextchar == '!')
4496 value = *(int *)(varp) ^ 1;
4497 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004498 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004499 ((flags & P_VI_DEF) || cp_val)
4500 ? VI_DEFAULT : VIM_DEFAULT];
4501 else if (nextchar == '<')
4502 {
4503 /* For 'autoread' -1 means to use global value. */
4504 if ((int *)varp == &curbuf->b_p_ar
4505 && opt_flags == OPT_LOCAL)
4506 value = -1;
4507 else
4508 value = *(int *)get_varp_scope(&(options[opt_idx]),
4509 OPT_GLOBAL);
4510 }
4511 else
4512 {
4513 /*
4514 * ":set invopt": invert
4515 * ":set opt" or ":set noopt": set or reset
4516 */
4517 if (nextchar != NUL && !vim_iswhite(afterchar))
4518 {
4519 errmsg = e_trailing;
4520 goto skip;
4521 }
4522 if (prefix == 2) /* inv */
4523 value = *(int *)(varp) ^ 1;
4524 else
4525 value = prefix;
4526 }
4527
4528 errmsg = set_bool_option(opt_idx, varp, (int)value,
4529 opt_flags);
4530 }
4531 else /* numeric or string */
4532 {
4533 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4534 || prefix != 1)
4535 {
4536 errmsg = e_invarg;
4537 goto skip;
4538 }
4539
4540 if (flags & P_NUM) /* numeric */
4541 {
4542 /*
4543 * Different ways to set a number option:
4544 * & set to default value
4545 * < set to global value
4546 * <xx> accept special key codes for 'wildchar'
4547 * c accept any non-digit for 'wildchar'
4548 * [-]0-9 set number
4549 * other error
4550 */
4551 ++arg;
4552 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004553 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004554 ((flags & P_VI_DEF) || cp_val)
4555 ? VI_DEFAULT : VIM_DEFAULT];
4556 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004557 {
4558 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4559 * use the global value. */
4560 if ((long *)varp == &curbuf->b_p_ul
4561 && opt_flags == OPT_LOCAL)
4562 value = NO_LOCAL_UNDOLEVEL;
4563 else
4564 value = *(long *)get_varp_scope(
4565 &(options[opt_idx]), OPT_GLOBAL);
4566 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004567 else if (((long *)varp == &p_wc
4568 || (long *)varp == &p_wcm)
4569 && (*arg == '<'
4570 || *arg == '^'
4571 || ((!arg[1] || vim_iswhite(arg[1]))
4572 && !VIM_ISDIGIT(*arg))))
4573 {
4574 value = string_to_key(arg);
4575 if (value == 0 && (long *)varp != &p_wcm)
4576 {
4577 errmsg = e_invarg;
4578 goto skip;
4579 }
4580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4582 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004583 /* Allow negative (for 'undolevels'), octal and
4584 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004585 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4586 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004587 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4588 {
4589 errmsg = e_invarg;
4590 goto skip;
4591 }
4592 }
4593 else
4594 {
4595 errmsg = (char_u *)N_("E521: Number required after =");
4596 goto skip;
4597 }
4598
4599 if (adding)
4600 value = *(long *)varp + value;
4601 if (prepending)
4602 value = *(long *)varp * value;
4603 if (removing)
4604 value = *(long *)varp - value;
4605 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004606 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004607 }
4608 else if (opt_idx >= 0) /* string */
4609 {
4610 char_u *save_arg = NULL;
4611 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004612 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004613 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004614 char_u *origval = NULL;
4615#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4616 char_u *saved_origval = NULL;
4617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004618 unsigned newlen;
4619 int comma;
4620 int bs;
4621 int new_value_alloced; /* new string option
4622 was allocated */
4623
4624 /* When using ":set opt=val" for a global option
4625 * with a local value the local value will be
4626 * reset, use the global value here. */
4627 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004628 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004629 varp = options[opt_idx].var;
4630
4631 /* The old value is kept until we are sure that the
4632 * new value is valid. */
4633 oldval = *(char_u **)varp;
4634 if (nextchar == '&') /* set to default val */
4635 {
4636 newval = options[opt_idx].def_val[
4637 ((flags & P_VI_DEF) || cp_val)
4638 ? VI_DEFAULT : VIM_DEFAULT];
4639 if ((char_u **)varp == &p_bg)
4640 {
4641 /* guess the value of 'background' */
4642#ifdef FEAT_GUI
4643 if (gui.in_use)
4644 newval = gui_bg_default();
4645 else
4646#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004647 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004648 }
4649
4650 /* expand environment variables and ~ (since the
4651 * default value was already expanded, only
4652 * required when an environment variable was set
4653 * later */
4654 if (newval == NULL)
4655 newval = empty_option;
4656 else
4657 {
4658 s = option_expand(opt_idx, newval);
4659 if (s == NULL)
4660 s = newval;
4661 newval = vim_strsave(s);
4662 }
4663 new_value_alloced = TRUE;
4664 }
4665 else if (nextchar == '<') /* set to global val */
4666 {
4667 newval = vim_strsave(*(char_u **)get_varp_scope(
4668 &(options[opt_idx]), OPT_GLOBAL));
4669 new_value_alloced = TRUE;
4670 }
4671 else
4672 {
4673 ++arg; /* jump to after the '=' or ':' */
4674
4675 /*
4676 * Set 'keywordprg' to ":help" if an empty
4677 * value was passed to :set by the user.
4678 * Misuse errbuf[] for the resulting string.
4679 */
4680 if (varp == (char_u *)&p_kp
4681 && (*arg == NUL || *arg == ' '))
4682 {
4683 STRCPY(errbuf, ":help");
4684 save_arg = arg;
4685 arg = errbuf;
4686 }
4687 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004688 * Convert 'backspace' number to string, for
4689 * adding, prepending and removing string.
4690 */
4691 else if (varp == (char_u *)&p_bs
4692 && VIM_ISDIGIT(**(char_u **)varp))
4693 {
4694 i = getdigits((char_u **)varp);
4695 switch (i)
4696 {
4697 case 0:
4698 *(char_u **)varp = empty_option;
4699 break;
4700 case 1:
4701 *(char_u **)varp = vim_strsave(
4702 (char_u *)"indent,eol");
4703 break;
4704 case 2:
4705 *(char_u **)varp = vim_strsave(
4706 (char_u *)"indent,eol,start");
4707 break;
4708 }
4709 vim_free(oldval);
4710 oldval = *(char_u **)varp;
4711 }
4712 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004713 * Convert 'whichwrap' number to string, for
4714 * backwards compatibility with Vim 3.0.
4715 * Misuse errbuf[] for the resulting string.
4716 */
4717 else if (varp == (char_u *)&p_ww
4718 && VIM_ISDIGIT(*arg))
4719 {
4720 *errbuf = NUL;
4721 i = getdigits(&arg);
4722 if (i & 1)
4723 STRCAT(errbuf, "b,");
4724 if (i & 2)
4725 STRCAT(errbuf, "s,");
4726 if (i & 4)
4727 STRCAT(errbuf, "h,l,");
4728 if (i & 8)
4729 STRCAT(errbuf, "<,>,");
4730 if (i & 16)
4731 STRCAT(errbuf, "[,],");
4732 if (*errbuf != NUL) /* remove trailing , */
4733 errbuf[STRLEN(errbuf) - 1] = NUL;
4734 save_arg = arg;
4735 arg = errbuf;
4736 }
4737 /*
4738 * Remove '>' before 'dir' and 'bdir', for
4739 * backwards compatibility with version 3.0
4740 */
4741 else if ( *arg == '>'
4742 && (varp == (char_u *)&p_dir
4743 || varp == (char_u *)&p_bdir))
4744 {
4745 ++arg;
4746 }
4747
4748 /* When setting the local value of a global
4749 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004750 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004751 && (opt_flags & OPT_LOCAL))
4752 origval = *(char_u **)get_varp(
4753 &options[opt_idx]);
4754 else
4755 origval = oldval;
4756
4757 /*
4758 * Copy the new string into allocated memory.
4759 * Can't use set_string_option_direct(), because
4760 * we need to remove the backslashes.
4761 */
4762 /* get a bit too much */
4763 newlen = (unsigned)STRLEN(arg) + 1;
4764 if (adding || prepending || removing)
4765 newlen += (unsigned)STRLEN(origval) + 1;
4766 newval = alloc(newlen);
4767 if (newval == NULL) /* out of mem, don't change */
4768 break;
4769 s = newval;
4770
4771 /*
4772 * Copy the string, skip over escaped chars.
4773 * For MS-DOS and WIN32 backslashes before normal
4774 * file name characters are not removed, and keep
4775 * backslash at start, for "\\machine\path", but
4776 * do remove it for "\\\\machine\\path".
4777 * The reverse is found in ExpandOldSetting().
4778 */
4779 while (*arg && !vim_iswhite(*arg))
4780 {
4781 if (*arg == '\\' && arg[1] != NUL
4782#ifdef BACKSLASH_IN_FILENAME
4783 && !((flags & P_EXPAND)
4784 && vim_isfilec(arg[1])
4785 && (arg[1] != '\\'
4786 || (s == newval
4787 && arg[2] != '\\')))
4788#endif
4789 )
4790 ++arg; /* remove backslash */
4791#ifdef FEAT_MBYTE
4792 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004793 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004794 {
4795 /* copy multibyte char */
4796 mch_memmove(s, arg, (size_t)i);
4797 arg += i;
4798 s += i;
4799 }
4800 else
4801#endif
4802 *s++ = *arg++;
4803 }
4804 *s = NUL;
4805
4806 /*
4807 * Expand environment variables and ~.
4808 * Don't do it when adding without inserting a
4809 * comma.
4810 */
4811 if (!(adding || prepending || removing)
4812 || (flags & P_COMMA))
4813 {
4814 s = option_expand(opt_idx, newval);
4815 if (s != NULL)
4816 {
4817 vim_free(newval);
4818 newlen = (unsigned)STRLEN(s) + 1;
4819 if (adding || prepending || removing)
4820 newlen += (unsigned)STRLEN(origval) + 1;
4821 newval = alloc(newlen);
4822 if (newval == NULL)
4823 break;
4824 STRCPY(newval, s);
4825 }
4826 }
4827
4828 /* locate newval[] in origval[] when removing it
4829 * and when adding to avoid duplicates */
4830 i = 0; /* init for GCC */
4831 if (removing || (flags & P_NODUP))
4832 {
4833 i = (int)STRLEN(newval);
4834 bs = 0;
4835 for (s = origval; *s; ++s)
4836 {
4837 if ((!(flags & P_COMMA)
4838 || s == origval
4839 || (s[-1] == ',' && !(bs & 1)))
4840 && STRNCMP(s, newval, i) == 0
4841 && (!(flags & P_COMMA)
4842 || s[i] == ','
4843 || s[i] == NUL))
4844 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004845 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004846 * even number of backslashes or a single
4847 * backslash preceded by a comma before it
4848 * is recognized as a separator */
4849 if ((s > origval + 1
4850 && s[-1] == '\\'
4851 && s[-2] != ',')
4852 || (s == origval + 1
4853 && s[-1] == '\\'))
4854
Bram Moolenaar071d4272004-06-13 20:20:40 +00004855 ++bs;
4856 else
4857 bs = 0;
4858 }
4859
4860 /* do not add if already there */
4861 if ((adding || prepending) && *s)
4862 {
4863 prepending = FALSE;
4864 adding = FALSE;
4865 STRCPY(newval, origval);
4866 }
4867 }
4868
4869 /* concatenate the two strings; add a ',' if
4870 * needed */
4871 if (adding || prepending)
4872 {
4873 comma = ((flags & P_COMMA) && *origval != NUL
4874 && *newval != NUL);
4875 if (adding)
4876 {
4877 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004878 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004879 if (comma && i > 1
4880 && (flags & P_ONECOMMA) == P_ONECOMMA
4881 && origval[i - 1] == ','
4882 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004883 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004884 mch_memmove(newval + i + comma, newval,
4885 STRLEN(newval) + 1);
4886 mch_memmove(newval, origval, (size_t)i);
4887 }
4888 else
4889 {
4890 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004891 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004892 }
4893 if (comma)
4894 newval[i] = ',';
4895 }
4896
4897 /* Remove newval[] from origval[]. (Note: "i" has
4898 * been set above and is used here). */
4899 if (removing)
4900 {
4901 STRCPY(newval, origval);
4902 if (*s)
4903 {
4904 /* may need to remove a comma */
4905 if (flags & P_COMMA)
4906 {
4907 if (s == origval)
4908 {
4909 /* include comma after string */
4910 if (s[i] == ',')
4911 ++i;
4912 }
4913 else
4914 {
4915 /* include comma before string */
4916 --s;
4917 ++i;
4918 }
4919 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004920 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004921 }
4922 }
4923
4924 if (flags & P_FLAGLIST)
4925 {
4926 /* Remove flags that appear twice. */
4927 for (s = newval; *s; ++s)
4928 if ((!(flags & P_COMMA) || *s != ',')
4929 && vim_strchr(s + 1, *s) != NULL)
4930 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004931 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004932 --s;
4933 }
4934 }
4935
4936 if (save_arg != NULL) /* number for 'whichwrap' */
4937 arg = save_arg;
4938 new_value_alloced = TRUE;
4939 }
4940
4941 /* Set the new value. */
4942 *(char_u **)(varp) = newval;
4943
Bram Moolenaar53744302015-07-17 17:38:22 +02004944#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004945 if (!starting
4946# ifdef FEAT_CRYPT
4947 && options[opt_idx].indir != PV_KEY
4948# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004949 && origval != NULL)
4950 /* origval may be freed by
4951 * did_set_string_option(), make a copy. */
4952 saved_origval = vim_strsave(origval);
4953#endif
4954
Bram Moolenaar071d4272004-06-13 20:20:40 +00004955 /* Handle side effects, and set the global value for
4956 * ":set" on local options. */
4957 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4958 new_value_alloced, oldval, errbuf, opt_flags);
4959
4960 /* If error detected, print the error message. */
4961 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004962 {
4963#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4964 vim_free(saved_origval);
4965#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004966 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004967 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004968#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4969 if (saved_origval != NULL)
4970 {
4971 char_u buf_type[7];
4972
4973 sprintf((char *)buf_type, "%s",
4974 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004975 set_vim_var_string(VV_OPTION_NEW,
4976 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004977 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4978 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4979 apply_autocmds(EVENT_OPTIONSET,
4980 (char_u *)options[opt_idx].fullname,
4981 NULL, FALSE, NULL);
4982 reset_v_option_vars();
4983 vim_free(saved_origval);
4984 }
4985#endif
4986
Bram Moolenaar071d4272004-06-13 20:20:40 +00004987 }
4988 else /* key code option */
4989 {
4990 char_u *p;
4991
4992 if (nextchar == '&')
4993 {
4994 if (add_termcap_entry(key_name, TRUE) == FAIL)
4995 errmsg = (char_u *)N_("E522: Not found in termcap");
4996 }
4997 else
4998 {
4999 ++arg; /* jump to after the '=' or ':' */
5000 for (p = arg; *p && !vim_iswhite(*p); ++p)
5001 if (*p == '\\' && p[1] != NUL)
5002 ++p;
5003 nextchar = *p;
5004 *p = NUL;
5005 add_termcode(key_name, arg, FALSE);
5006 *p = nextchar;
5007 }
5008 if (full_screen)
5009 ttest(FALSE);
5010 redraw_all_later(CLEAR);
5011 }
5012 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005013
Bram Moolenaar071d4272004-06-13 20:20:40 +00005014 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005015 did_set_option(opt_idx, opt_flags,
5016 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005017 }
5018
5019skip:
5020 /*
5021 * Advance to next argument.
5022 * - skip until a blank found, taking care of backslashes
5023 * - skip blanks
5024 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5025 */
5026 for (i = 0; i < 2 ; ++i)
5027 {
5028 while (*arg != NUL && !vim_iswhite(*arg))
5029 if (*arg++ == '\\' && *arg != NUL)
5030 ++arg;
5031 arg = skipwhite(arg);
5032 if (*arg != '=')
5033 break;
5034 }
5035 }
5036
5037 if (errmsg != NULL)
5038 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005039 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005040 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005041 if (i + (arg - startarg) < IOSIZE)
5042 {
5043 /* append the argument with the error */
5044 STRCAT(IObuff, ": ");
5045 mch_memmove(IObuff + i, startarg, (arg - startarg));
5046 IObuff[i + (arg - startarg)] = NUL;
5047 }
5048 /* make sure all characters are printable */
5049 trans_characters(IObuff, IOSIZE);
5050
5051 ++no_wait_return; /* wait_return done later */
5052 emsg(IObuff); /* show error highlighted */
5053 --no_wait_return;
5054
5055 return FAIL;
5056 }
5057
5058 arg = skipwhite(arg);
5059 }
5060
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005061theend:
5062 if (silent_mode && did_show)
5063 {
5064 /* After displaying option values in silent mode. */
5065 silent_mode = FALSE;
5066 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5067 msg_putchar('\n');
5068 cursor_on(); /* msg_start() switches it off */
5069 out_flush();
5070 silent_mode = TRUE;
5071 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5072 }
5073
Bram Moolenaar071d4272004-06-13 20:20:40 +00005074 return OK;
5075}
5076
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005077/*
5078 * Call this when an option has been given a new value through a user command.
5079 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5080 */
5081 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005082did_set_option(
5083 int opt_idx,
5084 int opt_flags, /* possibly with OPT_MODELINE */
5085 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005086{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005087 long_u *p;
5088
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005089 options[opt_idx].flags |= P_WAS_SET;
5090
5091 /* When an option is set in the sandbox, from a modeline or in secure mode
5092 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005093 * flag. */
5094 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005095 if (secure
5096#ifdef HAVE_SANDBOX
5097 || sandbox != 0
5098#endif
5099 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005100 *p = *p | P_INSECURE;
5101 else if (new_value)
5102 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005103}
5104
Bram Moolenaar071d4272004-06-13 20:20:40 +00005105 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005106illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005107{
5108 if (errbuf == NULL)
5109 return (char_u *)"";
5110 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005111 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005112 return errbuf;
5113}
5114
5115/*
5116 * Convert a key name or string into a key value.
5117 * Used for 'wildchar' and 'cedit' options.
5118 */
5119 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005120string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005121{
5122 if (*arg == '<')
5123 return find_key_option(arg + 1);
5124 if (*arg == '^')
5125 return Ctrl_chr(arg[1]);
5126 return *arg;
5127}
5128
5129#ifdef FEAT_CMDWIN
5130/*
5131 * Check value of 'cedit' and set cedit_key.
5132 * Returns NULL if value is OK, error message otherwise.
5133 */
5134 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005135check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005136{
5137 int n;
5138
5139 if (*p_cedit == NUL)
5140 cedit_key = -1;
5141 else
5142 {
5143 n = string_to_key(p_cedit);
5144 if (vim_isprintc(n))
5145 return e_invarg;
5146 cedit_key = n;
5147 }
5148 return NULL;
5149}
5150#endif
5151
5152#ifdef FEAT_TITLE
5153/*
5154 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5155 * maketitle() to create and display it.
5156 * When switching the title or icon off, call mch_restore_title() to get
5157 * the old value back.
5158 */
5159 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005160did_set_title(
5161 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005162{
5163 if (starting != NO_SCREEN
5164#ifdef FEAT_GUI
5165 && !gui.starting
5166#endif
5167 )
5168 {
5169 maketitle();
5170 if (icon)
5171 {
5172 if (!p_icon)
5173 mch_restore_title(2);
5174 }
5175 else
5176 {
5177 if (!p_title)
5178 mch_restore_title(1);
5179 }
5180 }
5181}
5182#endif
5183
5184/*
5185 * set_options_bin - called when 'bin' changes value.
5186 */
5187 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005188set_options_bin(
5189 int oldval,
5190 int newval,
5191 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192{
5193 /*
5194 * The option values that are changed when 'bin' changes are
5195 * copied when 'bin is set and restored when 'bin' is reset.
5196 */
5197 if (newval)
5198 {
5199 if (!oldval) /* switched on */
5200 {
5201 if (!(opt_flags & OPT_GLOBAL))
5202 {
5203 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5204 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5205 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5206 curbuf->b_p_et_nobin = curbuf->b_p_et;
5207 }
5208 if (!(opt_flags & OPT_LOCAL))
5209 {
5210 p_tw_nobin = p_tw;
5211 p_wm_nobin = p_wm;
5212 p_ml_nobin = p_ml;
5213 p_et_nobin = p_et;
5214 }
5215 }
5216
5217 if (!(opt_flags & OPT_GLOBAL))
5218 {
5219 curbuf->b_p_tw = 0; /* no automatic line wrap */
5220 curbuf->b_p_wm = 0; /* no automatic line wrap */
5221 curbuf->b_p_ml = 0; /* no modelines */
5222 curbuf->b_p_et = 0; /* no expandtab */
5223 }
5224 if (!(opt_flags & OPT_LOCAL))
5225 {
5226 p_tw = 0;
5227 p_wm = 0;
5228 p_ml = FALSE;
5229 p_et = FALSE;
5230 p_bin = TRUE; /* needed when called for the "-b" argument */
5231 }
5232 }
5233 else if (oldval) /* switched off */
5234 {
5235 if (!(opt_flags & OPT_GLOBAL))
5236 {
5237 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5238 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5239 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5240 curbuf->b_p_et = curbuf->b_p_et_nobin;
5241 }
5242 if (!(opt_flags & OPT_LOCAL))
5243 {
5244 p_tw = p_tw_nobin;
5245 p_wm = p_wm_nobin;
5246 p_ml = p_ml_nobin;
5247 p_et = p_et_nobin;
5248 }
5249 }
5250}
5251
5252#ifdef FEAT_VIMINFO
5253/*
5254 * Find the parameter represented by the given character (eg ', :, ", or /),
5255 * and return its associated value in the 'viminfo' string.
5256 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005257 * If the parameter is not specified in the string or there is no following
5258 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005259 */
5260 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005261get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005262{
5263 char_u *p;
5264
5265 p = find_viminfo_parameter(type);
5266 if (p != NULL && VIM_ISDIGIT(*p))
5267 return atoi((char *)p);
5268 return -1;
5269}
5270
5271/*
5272 * Find the parameter represented by the given character (eg ''', ':', '"', or
5273 * '/') in the 'viminfo' option and return a pointer to the string after it.
5274 * Return NULL if the parameter is not specified in the string.
5275 */
5276 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005277find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005278{
5279 char_u *p;
5280
5281 for (p = p_viminfo; *p; ++p)
5282 {
5283 if (*p == type)
5284 return p + 1;
5285 if (*p == 'n') /* 'n' is always the last one */
5286 break;
5287 p = vim_strchr(p, ','); /* skip until next ',' */
5288 if (p == NULL) /* hit the end without finding parameter */
5289 break;
5290 }
5291 return NULL;
5292}
5293#endif
5294
5295/*
5296 * Expand environment variables for some string options.
5297 * These string options cannot be indirect!
5298 * If "val" is NULL expand the current value of the option.
5299 * Return pointer to NameBuff, or NULL when not expanded.
5300 */
5301 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005302option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005303{
5304 /* if option doesn't need expansion nothing to do */
5305 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5306 return NULL;
5307
5308 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5309 * expand_env() would truncate the string. */
5310 if (val != NULL && STRLEN(val) > MAXPATHL)
5311 return NULL;
5312
5313 if (val == NULL)
5314 val = *(char_u **)options[opt_idx].var;
5315
5316 /*
5317 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5318 * Escape spaces when expanding 'tags', they are used to separate file
5319 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005320 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005321 */
5322 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005323 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005324#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005325 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5326#endif
5327 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005328 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5329 return NULL;
5330
5331 return NameBuff;
5332}
5333
5334/*
5335 * After setting various option values: recompute variables that depend on
5336 * option values.
5337 */
5338 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005339didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005340{
5341 /* initialize the table for 'iskeyword' et.al. */
5342 (void)init_chartab();
5343
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005344#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005345 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005347 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005348 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349#ifdef FEAT_SESSION
5350 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5351 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5352#endif
5353#ifdef FEAT_FOLDING
5354 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5355#endif
5356 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005357 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005358#ifdef FEAT_VIRTUALEDIT
5359 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5360#endif
5361#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5362 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5363#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005364#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005365 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005366 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005367 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005368 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005369#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005370#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5371 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5372#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005373#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5375#endif
5376#ifdef FEAT_CMDWIN
5377 /* set cedit_key */
5378 (void)check_cedit();
5379#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005380#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005381 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005382#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005383#ifdef FEAT_LINEBREAK
5384 /* initialize the table for 'breakat'. */
5385 fill_breakat_flags();
5386#endif
5387
5388}
5389
5390/*
5391 * More side effects of setting options.
5392 */
5393 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005394didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005395{
5396 /* Initialize the highlight_attr[] table. */
5397 (void)highlight_changed();
5398
5399 /* Parse default for 'wildmode' */
5400 check_opt_wim();
5401
5402 (void)set_chars_option(&p_lcs);
5403#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5404 /* Parse default for 'fillchars'. */
5405 (void)set_chars_option(&p_fcs);
5406#endif
5407
5408#ifdef FEAT_CLIPBOARD
5409 /* Parse default for 'clipboard' */
5410 (void)check_clipboard_option();
5411#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005412}
5413
5414/*
5415 * Check for string options that are NULL (normally only termcap options).
5416 */
5417 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005418check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005419{
5420 int opt_idx;
5421
5422 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5423 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5424 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5425}
5426
5427/*
5428 * Check string options in a buffer for NULL value.
5429 */
5430 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005431check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005432{
5433#if defined(FEAT_QUICKFIX)
5434 check_string_option(&buf->b_p_bh);
5435 check_string_option(&buf->b_p_bt);
5436#endif
5437#ifdef FEAT_MBYTE
5438 check_string_option(&buf->b_p_fenc);
5439#endif
5440 check_string_option(&buf->b_p_ff);
5441#ifdef FEAT_FIND_ID
5442 check_string_option(&buf->b_p_def);
5443 check_string_option(&buf->b_p_inc);
5444# ifdef FEAT_EVAL
5445 check_string_option(&buf->b_p_inex);
5446# endif
5447#endif
5448#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5449 check_string_option(&buf->b_p_inde);
5450 check_string_option(&buf->b_p_indk);
5451#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005452#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5453 check_string_option(&buf->b_p_bexpr);
5454#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005455#if defined(FEAT_CRYPT)
5456 check_string_option(&buf->b_p_cm);
5457#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005458#if defined(FEAT_EVAL)
5459 check_string_option(&buf->b_p_fex);
5460#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005461#ifdef FEAT_CRYPT
5462 check_string_option(&buf->b_p_key);
5463#endif
5464 check_string_option(&buf->b_p_kp);
5465 check_string_option(&buf->b_p_mps);
5466 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005467 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005468 check_string_option(&buf->b_p_isk);
5469#ifdef FEAT_COMMENTS
5470 check_string_option(&buf->b_p_com);
5471#endif
5472#ifdef FEAT_FOLDING
5473 check_string_option(&buf->b_p_cms);
5474#endif
5475 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005476#ifdef FEAT_TEXTOBJ
5477 check_string_option(&buf->b_p_qe);
5478#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005479#ifdef FEAT_SYN_HL
5480 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005481 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005482#endif
5483#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005484 check_string_option(&buf->b_s.b_p_spc);
5485 check_string_option(&buf->b_s.b_p_spf);
5486 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005487#endif
5488#ifdef FEAT_SEARCHPATH
5489 check_string_option(&buf->b_p_sua);
5490#endif
5491#ifdef FEAT_CINDENT
5492 check_string_option(&buf->b_p_cink);
5493 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005494 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495#endif
5496#ifdef FEAT_AUTOCMD
5497 check_string_option(&buf->b_p_ft);
5498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5500 check_string_option(&buf->b_p_cinw);
5501#endif
5502#ifdef FEAT_INS_EXPAND
5503 check_string_option(&buf->b_p_cpt);
5504#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005505#ifdef FEAT_COMPL_FUNC
5506 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005507 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005508#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509#ifdef FEAT_KEYMAP
5510 check_string_option(&buf->b_p_keymap);
5511#endif
5512#ifdef FEAT_QUICKFIX
5513 check_string_option(&buf->b_p_gp);
5514 check_string_option(&buf->b_p_mp);
5515 check_string_option(&buf->b_p_efm);
5516#endif
5517 check_string_option(&buf->b_p_ep);
5518 check_string_option(&buf->b_p_path);
5519 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005520 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005521#ifdef FEAT_INS_EXPAND
5522 check_string_option(&buf->b_p_dict);
5523 check_string_option(&buf->b_p_tsr);
5524#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005525#ifdef FEAT_LISP
5526 check_string_option(&buf->b_p_lw);
5527#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005528 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529}
5530
5531/*
5532 * Free the string allocated for an option.
5533 * Checks for the string being empty_option. This may happen if we're out of
5534 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5535 * check_options().
5536 * Does NOT check for P_ALLOCED flag!
5537 */
5538 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005539free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540{
5541 if (p != empty_option)
5542 vim_free(p);
5543}
5544
5545 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005546clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547{
5548 if (*pp != empty_option)
5549 vim_free(*pp);
5550 *pp = empty_option;
5551}
5552
5553 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005554check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555{
5556 if (*pp == NULL)
5557 *pp = empty_option;
5558}
5559
5560/*
5561 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5562 */
5563 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005564set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005565{
5566 int opt_idx;
5567
5568 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5569 if (options[opt_idx].var == (char_u *)p)
5570 {
5571 options[opt_idx].flags |= P_ALLOCED;
5572 return;
5573 }
5574 return; /* cannot happen: didn't find it! */
5575}
5576
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005577#if defined(FEAT_EVAL) || defined(PROTO)
5578/*
5579 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5580 * Return FALSE when it wasn't.
5581 * Return -1 for an unknown option.
5582 */
5583 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005584was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005585{
5586 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005587 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005588
5589 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005590 {
5591 flagp = insecure_flag(idx, opt_flags);
5592 return (*flagp & P_INSECURE) != 0;
5593 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005594 EMSG2(_(e_intern2), "was_set_insecurely()");
5595 return -1;
5596}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005597
5598/*
5599 * Get a pointer to the flags used for the P_INSECURE flag of option
5600 * "opt_idx". For some local options a local flags field is used.
5601 */
5602 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005603insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005604{
5605 if (opt_flags & OPT_LOCAL)
5606 switch ((int)options[opt_idx].indir)
5607 {
5608#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005609 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005610#endif
5611#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005612# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005613 case PV_FDE: return &curwin->w_p_fde_flags;
5614 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005615# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005616# ifdef FEAT_BEVAL
5617 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5618# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005619# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005620 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005621# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005622 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005623# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005624 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005625# endif
5626#endif
5627 }
5628
5629 /* Nothing special, return global flags field. */
5630 return &options[opt_idx].flags;
5631}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005632#endif
5633
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005634#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005635static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005636
5637/*
5638 * Redraw the window title and/or tab page text later.
5639 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005640static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005641{
5642 need_maketitle = TRUE;
5643# ifdef FEAT_WINDOWS
5644 redraw_tabline = TRUE;
5645# endif
5646}
5647#endif
5648
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649/*
5650 * Set a string option to a new value (without checking the effect).
5651 * The string is copied into allocated memory.
5652 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005653 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005654 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005655 */
5656 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005657set_string_option_direct(
5658 char_u *name,
5659 int opt_idx,
5660 char_u *val,
5661 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5662 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663{
5664 char_u *s;
5665 char_u **varp;
5666 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005667 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668
Bram Moolenaar89d40322006-08-29 15:30:07 +00005669 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005671 idx = findoption(name);
5672 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005673 {
5674 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005675 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005677 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005678 }
5679
Bram Moolenaar89d40322006-08-29 15:30:07 +00005680 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681 return;
5682
5683 s = vim_strsave(val);
5684 if (s != NULL)
5685 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005686 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005687 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005688 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689 free_string_option(*varp);
5690 *varp = s;
5691
5692 /* For buffer/window local option may also set the global value. */
5693 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005694 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695
Bram Moolenaar89d40322006-08-29 15:30:07 +00005696 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697
5698 /* When setting both values of a global option with a local value,
5699 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005700 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701 {
5702 free_string_option(*varp);
5703 *varp = empty_option;
5704 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005705# ifdef FEAT_EVAL
5706 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005707 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005708 set_sid == 0 ? current_SID : set_sid);
5709# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710 }
5711}
5712
5713/*
5714 * Set global value for string option when it's a local option.
5715 */
5716 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005717set_string_option_global(
5718 int opt_idx, /* option index */
5719 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005720{
5721 char_u **p, *s;
5722
5723 /* the global value is always allocated */
5724 if (options[opt_idx].var == VAR_WIN)
5725 p = (char_u **)GLOBAL_WO(varp);
5726 else
5727 p = (char_u **)options[opt_idx].var;
5728 if (options[opt_idx].indir != PV_NONE
5729 && p != varp
5730 && (s = vim_strsave(*varp)) != NULL)
5731 {
5732 free_string_option(*p);
5733 *p = s;
5734 }
5735}
5736
5737/*
5738 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005739 *
5740 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005741 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005742 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005743set_string_option(
5744 int opt_idx,
5745 char_u *value,
5746 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005747{
5748 char_u *s;
5749 char_u **varp;
5750 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005751#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5752 char_u *saved_oldval = NULL;
5753#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005754 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005755
5756 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005757 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005758
5759 s = vim_strsave(value);
5760 if (s != NULL)
5761 {
5762 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5763 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005764 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005765 ? OPT_GLOBAL : OPT_LOCAL)
5766 : opt_flags);
5767 oldval = *varp;
5768 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005769
5770#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005771 if (!starting
5772# ifdef FEAT_CRYPT
5773 && options[opt_idx].indir != PV_KEY
5774# endif
5775 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005776 saved_oldval = vim_strsave(oldval);
5777#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005778 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5779 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005780 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005781
5782 /* call autocomamnd after handling side effects */
5783#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5784 if (saved_oldval != NULL)
5785 {
5786 char_u buf_type[7];
5787 sprintf((char *)buf_type, "%s",
5788 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005789 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5790 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005791 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5792 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5793 reset_v_option_vars();
5794 vim_free(saved_oldval);
5795 }
5796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005797 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005798 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005799}
5800
5801/*
5802 * Handle string options that need some action to perform when changed.
5803 * Returns NULL for success, or an error message for an error.
5804 */
5805 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005806did_set_string_option(
5807 int opt_idx, /* index in options[] table */
5808 char_u **varp, /* pointer to the option variable */
5809 int new_value_alloced, /* new value was allocated */
5810 char_u *oldval, /* previous value of the option */
5811 char_u *errbuf, /* buffer for errors, or NULL */
5812 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005813{
5814 char_u *errmsg = NULL;
5815 char_u *s, *p;
5816 int did_chartab = FALSE;
5817 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005818 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005819#ifdef FEAT_GUI
5820 /* set when changing an option that only requires a redraw in the GUI */
5821 int redraw_gui_only = FALSE;
5822#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005823
5824 /* Get the global option to compare with, otherwise we would have to check
5825 * two values for all local options. */
5826 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5827
5828 /* Disallow changing some options from secure mode */
5829 if ((secure
5830#ifdef HAVE_SANDBOX
5831 || sandbox != 0
5832#endif
5833 ) && (options[opt_idx].flags & P_SECURE))
5834 {
5835 errmsg = e_secure;
5836 }
5837
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005838 /* Check for a "normal" file name in some options. Disallow a path
5839 * separator (slash and/or backslash), wildcards and characters that are
5840 * often illegal in a file name. */
5841 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005842 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005843 {
5844 errmsg = e_invarg;
5845 }
5846
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 /* 'term' */
5848 else if (varp == &T_NAME)
5849 {
5850 if (T_NAME[0] == NUL)
5851 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5852#ifdef FEAT_GUI
5853 if (gui.in_use)
5854 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5855 else if (term_is_gui(T_NAME))
5856 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5857#endif
5858 else if (set_termname(T_NAME) == FAIL)
5859 errmsg = (char_u *)N_("E522: Not found in termcap");
5860 else
5861 /* Screen colors may have changed. */
5862 redraw_later_clear();
5863 }
5864
5865 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005866 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005868 char_u *bkc = p_bkc;
5869 unsigned int *flags = &bkc_flags;
5870
5871 if (opt_flags & OPT_LOCAL)
5872 {
5873 bkc = curbuf->b_p_bkc;
5874 flags = &curbuf->b_bkc_flags;
5875 }
5876
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005877 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5878 /* make the local value empty: use the global value */
5879 *flags = 0;
5880 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005881 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005882 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5883 errmsg = e_invarg;
5884 if ((((int)*flags & BKC_AUTO) != 0)
5885 + (((int)*flags & BKC_YES) != 0)
5886 + (((int)*flags & BKC_NO) != 0) != 1)
5887 {
5888 /* Must have exactly one of "auto", "yes" and "no". */
5889 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5890 errmsg = e_invarg;
5891 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892 }
5893 }
5894
5895 /* 'backupext' and 'patchmode' */
5896 else if (varp == &p_bex || varp == &p_pm)
5897 {
5898 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5899 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5900 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5901 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005902#ifdef FEAT_LINEBREAK
5903 /* 'breakindentopt' */
5904 else if (varp == &curwin->w_p_briopt)
5905 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005906 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005907 errmsg = e_invarg;
5908 }
5909#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910
5911 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005912 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005914 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005915 */
5916 else if ( varp == &p_isi
5917 || varp == &(curbuf->b_p_isk)
5918 || varp == &p_isp
5919 || varp == &p_isf)
5920 {
5921 if (init_chartab() == FAIL)
5922 {
5923 did_chartab = TRUE; /* need to restore it below */
5924 errmsg = e_invarg; /* error in value */
5925 }
5926 }
5927
5928 /* 'helpfile' */
5929 else if (varp == &p_hf)
5930 {
5931 /* May compute new values for $VIM and $VIMRUNTIME */
5932 if (didset_vim)
5933 {
5934 vim_setenv((char_u *)"VIM", (char_u *)"");
5935 didset_vim = FALSE;
5936 }
5937 if (didset_vimruntime)
5938 {
5939 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5940 didset_vimruntime = FALSE;
5941 }
5942 }
5943
Bram Moolenaar1a384422010-07-14 19:53:30 +02005944#ifdef FEAT_SYN_HL
5945 /* 'colorcolumn' */
5946 else if (varp == &curwin->w_p_cc)
5947 errmsg = check_colorcolumn(curwin);
5948#endif
5949
Bram Moolenaar071d4272004-06-13 20:20:40 +00005950#ifdef FEAT_MULTI_LANG
5951 /* 'helplang' */
5952 else if (varp == &p_hlg)
5953 {
5954 /* Check for "", "ab", "ab,cd", etc. */
5955 for (s = p_hlg; *s != NUL; s += 3)
5956 {
5957 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5958 {
5959 errmsg = e_invarg;
5960 break;
5961 }
5962 if (s[2] == NUL)
5963 break;
5964 }
5965 }
5966#endif
5967
5968 /* 'highlight' */
5969 else if (varp == &p_hl)
5970 {
5971 if (highlight_changed() == FAIL)
5972 errmsg = e_invarg; /* invalid flags */
5973 }
5974
5975 /* 'nrformats' */
5976 else if (gvarp == &p_nf)
5977 {
5978 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5979 errmsg = e_invarg;
5980 }
5981
5982#ifdef FEAT_SESSION
5983 /* 'sessionoptions' */
5984 else if (varp == &p_ssop)
5985 {
5986 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5987 errmsg = e_invarg;
5988 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5989 {
5990 /* Don't allow both "sesdir" and "curdir". */
5991 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5992 errmsg = e_invarg;
5993 }
5994 }
5995 /* 'viewoptions' */
5996 else if (varp == &p_vop)
5997 {
5998 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5999 errmsg = e_invarg;
6000 }
6001#endif
6002
6003 /* 'scrollopt' */
6004#ifdef FEAT_SCROLLBIND
6005 else if (varp == &p_sbo)
6006 {
6007 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6008 errmsg = e_invarg;
6009 }
6010#endif
6011
6012 /* 'ambiwidth' */
6013#ifdef FEAT_MBYTE
6014 else if (varp == &p_ambw)
6015 {
6016 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6017 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006018 else if (set_chars_option(&p_lcs) != NULL)
6019 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6020# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6021 else if (set_chars_option(&p_fcs) != NULL)
6022 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6023# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006024 }
6025#endif
6026
6027 /* 'background' */
6028 else if (varp == &p_bg)
6029 {
6030 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6031 {
6032#ifdef FEAT_EVAL
6033 int dark = (*p_bg == 'd');
6034#endif
6035
6036 init_highlight(FALSE, FALSE);
6037
6038#ifdef FEAT_EVAL
6039 if (dark != (*p_bg == 'd')
6040 && get_var_value((char_u *)"g:colors_name") != NULL)
6041 {
6042 /* The color scheme must have set 'background' back to another
6043 * value, that's not what we want here. Disable the color
6044 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006045 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006046 free_string_option(p_bg);
6047 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6048 check_string_option(&p_bg);
6049 init_highlight(FALSE, FALSE);
6050 }
6051#endif
6052 }
6053 else
6054 errmsg = e_invarg;
6055 }
6056
6057 /* 'wildmode' */
6058 else if (varp == &p_wim)
6059 {
6060 if (check_opt_wim() == FAIL)
6061 errmsg = e_invarg;
6062 }
6063
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006064#ifdef FEAT_CMDL_COMPL
6065 /* 'wildoptions' */
6066 else if (varp == &p_wop)
6067 {
6068 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6069 errmsg = e_invarg;
6070 }
6071#endif
6072
Bram Moolenaar071d4272004-06-13 20:20:40 +00006073#ifdef FEAT_WAK
6074 /* 'winaltkeys' */
6075 else if (varp == &p_wak)
6076 {
6077 if (*p_wak == NUL
6078 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6079 errmsg = e_invarg;
6080# ifdef FEAT_MENU
6081# ifdef FEAT_GUI_MOTIF
6082 else if (gui.in_use)
6083 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6084# else
6085# ifdef FEAT_GUI_GTK
6086 else if (gui.in_use)
6087 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6088# endif
6089# endif
6090# endif
6091 }
6092#endif
6093
6094#ifdef FEAT_AUTOCMD
6095 /* 'eventignore' */
6096 else if (varp == &p_ei)
6097 {
6098 if (check_ei() == FAIL)
6099 errmsg = e_invarg;
6100 }
6101#endif
6102
6103#ifdef FEAT_MBYTE
6104 /* 'encoding' and 'fileencoding' */
6105 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6106 {
6107 if (gvarp == &p_fenc)
6108 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006109 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006110 errmsg = e_modifiable;
6111 else if (vim_strchr(*varp, ',') != NULL)
6112 /* No comma allowed in 'fileencoding'; catches confusing it
6113 * with 'fileencodings'. */
6114 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006115 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006116 {
6117# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006118 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006119 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006120# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006121 /* Add 'fileencoding' to the swap file. */
6122 ml_setflags(curbuf);
6123 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 }
6125 if (errmsg == NULL)
6126 {
6127 /* canonize the value, so that STRCMP() can be used on it */
6128 p = enc_canonize(*varp);
6129 if (p != NULL)
6130 {
6131 vim_free(*varp);
6132 *varp = p;
6133 }
6134 if (varp == &p_enc)
6135 {
6136 errmsg = mb_init();
6137# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006138 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139# endif
6140 }
6141 }
6142
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006143# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6145 {
6146 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6147 if (STRCMP(p_tenc, "utf-8") != 0)
6148 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6149 }
6150# endif
6151
6152 if (errmsg == NULL)
6153 {
6154# ifdef FEAT_KEYMAP
6155 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6156 * (with another encoding). */
6157 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6158 (void)keymap_init();
6159# endif
6160
6161 /* When 'termencoding' is not empty and 'encoding' changes or when
6162 * 'termencoding' changes, need to setup for keyboard input and
6163 * display output conversion. */
6164 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6165 {
6166 convert_setup(&input_conv, p_tenc, p_enc);
6167 convert_setup(&output_conv, p_enc, p_tenc);
6168 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006169
6170# if defined(WIN3264) && defined(FEAT_MBYTE)
6171 /* $HOME may have characters in active code page. */
6172 if (varp == &p_enc)
6173 init_homedir();
6174# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006175 }
6176 }
6177#endif
6178
6179#if defined(FEAT_POSTSCRIPT)
6180 else if (varp == &p_penc)
6181 {
6182 /* Canonize printencoding if VIM standard one */
6183 p = enc_canonize(p_penc);
6184 if (p != NULL)
6185 {
6186 vim_free(p_penc);
6187 p_penc = p;
6188 }
6189 else
6190 {
6191 /* Ensure lower case and '-' for '_' */
6192 for (s = p_penc; *s != NUL; s++)
6193 {
6194 if (*s == '_')
6195 *s = '-';
6196 else
6197 *s = TOLOWER_ASC(*s);
6198 }
6199 }
6200 }
6201#endif
6202
Bram Moolenaar9372a112005-12-06 19:59:18 +00006203#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006204 else if (varp == &p_imak)
6205 {
6206 if (gui.in_use && !im_xim_isvalid_imactivate())
6207 errmsg = e_invarg;
6208 }
6209#endif
6210
6211#ifdef FEAT_KEYMAP
6212 else if (varp == &curbuf->b_p_keymap)
6213 {
6214 /* load or unload key mapping tables */
6215 errmsg = keymap_init();
6216
Bram Moolenaarfab06232009-03-04 03:13:35 +00006217 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006218 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006219 if (*curbuf->b_p_keymap != NUL)
6220 {
6221 /* Installed a new keymap, switch on using it. */
6222 curbuf->b_p_iminsert = B_IMODE_LMAP;
6223 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6224 curbuf->b_p_imsearch = B_IMODE_LMAP;
6225 }
6226 else
6227 {
6228 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6229 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6230 curbuf->b_p_iminsert = B_IMODE_NONE;
6231 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6232 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6233 }
6234 if ((opt_flags & OPT_LOCAL) == 0)
6235 {
6236 set_iminsert_global();
6237 set_imsearch_global();
6238 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006239# ifdef FEAT_WINDOWS
6240 status_redraw_curbuf();
6241# endif
6242 }
6243 }
6244#endif
6245
6246 /* 'fileformat' */
6247 else if (gvarp == &p_ff)
6248 {
6249 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6250 errmsg = e_modifiable;
6251 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6252 errmsg = e_invarg;
6253 else
6254 {
6255 /* may also change 'textmode' */
6256 if (get_fileformat(curbuf) == EOL_DOS)
6257 curbuf->b_p_tx = TRUE;
6258 else
6259 curbuf->b_p_tx = FALSE;
6260#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006261 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006262#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006263 /* update flag in swap file */
6264 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006265 /* Redraw needed when switching to/from "mac": a CR in the text
6266 * will be displayed differently. */
6267 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6268 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006269 }
6270 }
6271
6272 /* 'fileformats' */
6273 else if (varp == &p_ffs)
6274 {
6275 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6276 errmsg = e_invarg;
6277 else
6278 {
6279 /* also change 'textauto' */
6280 if (*p_ffs == NUL)
6281 p_ta = FALSE;
6282 else
6283 p_ta = TRUE;
6284 }
6285 }
6286
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006287#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006288 /* 'cryptkey' */
6289 else if (gvarp == &p_key)
6290 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006291# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006292 /* Make sure the ":set" command doesn't show the new value in the
6293 * history. */
6294 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006295# endif
6296 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6297 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006298 ml_set_crypt_key(curbuf, oldval,
6299 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006300 }
6301
6302 else if (gvarp == &p_cm)
6303 {
6304 if (opt_flags & OPT_LOCAL)
6305 p = curbuf->b_p_cm;
6306 else
6307 p = p_cm;
6308 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6309 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006310 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006311 errmsg = e_invarg;
6312 else
6313 {
6314 /* When setting the global value to empty, make it "zip". */
6315 if (*p_cm == NUL)
6316 {
6317 if (new_value_alloced)
6318 free_string_option(p_cm);
6319 p_cm = vim_strsave((char_u *)"zip");
6320 new_value_alloced = TRUE;
6321 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006322 /* When using ":set cm=name" the local value is going to be empty.
6323 * Do that here, otherwise the crypt functions will still use the
6324 * local value. */
6325 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6326 {
6327 free_string_option(curbuf->b_p_cm);
6328 curbuf->b_p_cm = empty_option;
6329 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006330
6331 /* Need to update the swapfile when the effective method changed.
6332 * Set "s" to the effective old value, "p" to the effective new
6333 * method and compare. */
6334 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6335 s = p_cm; /* was previously using the global value */
6336 else
6337 s = oldval;
6338 if (*curbuf->b_p_cm == NUL)
6339 p = p_cm; /* is now using the global value */
6340 else
6341 p = curbuf->b_p_cm;
6342 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006343 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006344
6345 /* If the global value changes need to update the swapfile for all
6346 * buffers using that value. */
6347 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6348 {
6349 buf_T *buf;
6350
6351 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6352 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006353 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006354 }
6355 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006356 }
6357#endif
6358
6359 /* 'matchpairs' */
6360 else if (gvarp == &p_mps)
6361 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006362#ifdef FEAT_MBYTE
6363 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006364 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006365 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006366 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006367 int x2 = -1;
6368 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006369
6370 if (*p != NUL)
6371 p += mb_ptr2len(p);
6372 if (*p != NUL)
6373 x2 = *p++;
6374 if (*p != NUL)
6375 {
6376 x3 = mb_ptr2char(p);
6377 p += mb_ptr2len(p);
6378 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006379 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006380 {
6381 errmsg = e_invarg;
6382 break;
6383 }
6384 if (*p == NUL)
6385 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006387 }
6388 else
6389#endif
6390 {
6391 /* Check for "x:y,x:y" */
6392 for (p = *varp; *p != NUL; p += 4)
6393 {
6394 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6395 {
6396 errmsg = e_invarg;
6397 break;
6398 }
6399 if (p[3] == NUL)
6400 break;
6401 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006402 }
6403 }
6404
6405#ifdef FEAT_COMMENTS
6406 /* 'comments' */
6407 else if (gvarp == &p_com)
6408 {
6409 for (s = *varp; *s; )
6410 {
6411 while (*s && *s != ':')
6412 {
6413 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6414 && !VIM_ISDIGIT(*s) && *s != '-')
6415 {
6416 errmsg = illegal_char(errbuf, *s);
6417 break;
6418 }
6419 ++s;
6420 }
6421 if (*s++ == NUL)
6422 errmsg = (char_u *)N_("E524: Missing colon");
6423 else if (*s == ',' || *s == NUL)
6424 errmsg = (char_u *)N_("E525: Zero length string");
6425 if (errmsg != NULL)
6426 break;
6427 while (*s && *s != ',')
6428 {
6429 if (*s == '\\' && s[1] != NUL)
6430 ++s;
6431 ++s;
6432 }
6433 s = skip_to_option_part(s);
6434 }
6435 }
6436#endif
6437
6438 /* 'listchars' */
6439 else if (varp == &p_lcs)
6440 {
6441 errmsg = set_chars_option(varp);
6442 }
6443
6444#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6445 /* 'fillchars' */
6446 else if (varp == &p_fcs)
6447 {
6448 errmsg = set_chars_option(varp);
6449 }
6450#endif
6451
6452#ifdef FEAT_CMDWIN
6453 /* 'cedit' */
6454 else if (varp == &p_cedit)
6455 {
6456 errmsg = check_cedit();
6457 }
6458#endif
6459
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006460 /* 'verbosefile' */
6461 else if (varp == &p_vfile)
6462 {
6463 verbose_stop();
6464 if (*p_vfile != NUL && verbose_open() == FAIL)
6465 errmsg = e_invarg;
6466 }
6467
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468#ifdef FEAT_VIMINFO
6469 /* 'viminfo' */
6470 else if (varp == &p_viminfo)
6471 {
6472 for (s = p_viminfo; *s;)
6473 {
6474 /* Check it's a valid character */
6475 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6476 {
6477 errmsg = illegal_char(errbuf, *s);
6478 break;
6479 }
6480 if (*s == 'n') /* name is always last one */
6481 {
6482 break;
6483 }
6484 else if (*s == 'r') /* skip until next ',' */
6485 {
6486 while (*++s && *s != ',')
6487 ;
6488 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006489 else if (*s == '%')
6490 {
6491 /* optional number */
6492 while (vim_isdigit(*++s))
6493 ;
6494 }
6495 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006496 ++s; /* no extra chars */
6497 else /* must have a number */
6498 {
6499 while (vim_isdigit(*++s))
6500 ;
6501
6502 if (!VIM_ISDIGIT(*(s - 1)))
6503 {
6504 if (errbuf != NULL)
6505 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006506 sprintf((char *)errbuf,
6507 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006508 transchar_byte(*(s - 1)));
6509 errmsg = errbuf;
6510 }
6511 else
6512 errmsg = (char_u *)"";
6513 break;
6514 }
6515 }
6516 if (*s == ',')
6517 ++s;
6518 else if (*s)
6519 {
6520 if (errbuf != NULL)
6521 errmsg = (char_u *)N_("E527: Missing comma");
6522 else
6523 errmsg = (char_u *)"";
6524 break;
6525 }
6526 }
6527 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6528 errmsg = (char_u *)N_("E528: Must specify a ' value");
6529 }
6530#endif /* FEAT_VIMINFO */
6531
6532 /* terminal options */
6533 else if (istermoption(&options[opt_idx]) && full_screen)
6534 {
6535 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6536 if (varp == &T_CCO)
6537 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006538 int colors = atoi((char *)T_CCO);
6539
6540 /* Only reinitialize colors if t_Co value has really changed to
6541 * avoid expensive reload of colorscheme if t_Co is set to the
6542 * same value multiple times. */
6543 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006544 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006545 t_colors = colors;
6546 if (t_colors <= 1)
6547 {
6548 if (new_value_alloced)
6549 vim_free(T_CCO);
6550 T_CCO = empty_option;
6551 }
6552 /* We now have a different color setup, initialize it again. */
6553 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006554 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555 }
6556 ttest(FALSE);
6557 if (varp == &T_ME)
6558 {
6559 out_str(T_ME);
6560 redraw_later(CLEAR);
6561#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6562 /* Since t_me has been set, this probably means that the user
6563 * wants to use this as default colors. Need to reset default
6564 * background/foreground colors. */
6565 mch_set_normal_colors();
6566#endif
6567 }
6568 }
6569
6570#ifdef FEAT_LINEBREAK
6571 /* 'showbreak' */
6572 else if (varp == &p_sbr)
6573 {
6574 for (s = p_sbr; *s; )
6575 {
6576 if (ptr2cells(s) != 1)
6577 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006578 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006579 }
6580 }
6581#endif
6582
6583#ifdef FEAT_GUI
6584 /* 'guifont' */
6585 else if (varp == &p_guifont)
6586 {
6587 if (gui.in_use)
6588 {
6589 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006590# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006591 /*
6592 * Put up a font dialog and let the user select a new value.
6593 * If this is cancelled go back to the old value but don't
6594 * give an error message.
6595 */
6596 if (STRCMP(p, "*") == 0)
6597 {
6598 p = gui_mch_font_dialog(oldval);
6599
6600 if (new_value_alloced)
6601 free_string_option(p_guifont);
6602
6603 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6604 new_value_alloced = TRUE;
6605 }
6606# endif
6607 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6608 {
6609# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6610 if (STRCMP(p_guifont, "*") == 0)
6611 {
6612 /* Dialog was cancelled: Keep the old value without giving
6613 * an error message. */
6614 if (new_value_alloced)
6615 free_string_option(p_guifont);
6616 p_guifont = vim_strsave(oldval);
6617 new_value_alloced = TRUE;
6618 }
6619 else
6620# endif
6621 errmsg = (char_u *)N_("E596: Invalid font(s)");
6622 }
6623 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006624 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006625 }
6626# ifdef FEAT_XFONTSET
6627 else if (varp == &p_guifontset)
6628 {
6629 if (STRCMP(p_guifontset, "*") == 0)
6630 errmsg = (char_u *)N_("E597: can't select fontset");
6631 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6632 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006633 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006634 }
6635# endif
6636# ifdef FEAT_MBYTE
6637 else if (varp == &p_guifontwide)
6638 {
6639 if (STRCMP(p_guifontwide, "*") == 0)
6640 errmsg = (char_u *)N_("E533: can't select wide font");
6641 else if (gui_get_wide_font() == FAIL)
6642 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006643 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006644 }
6645# endif
6646#endif
6647
6648#ifdef CURSOR_SHAPE
6649 /* 'guicursor' */
6650 else if (varp == &p_guicursor)
6651 errmsg = parse_shape_opt(SHAPE_CURSOR);
6652#endif
6653
6654#ifdef FEAT_MOUSESHAPE
6655 /* 'mouseshape' */
6656 else if (varp == &p_mouseshape)
6657 {
6658 errmsg = parse_shape_opt(SHAPE_MOUSE);
6659 update_mouseshape(-1);
6660 }
6661#endif
6662
6663#ifdef FEAT_PRINTER
6664 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006665 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006666# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006667 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006668 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006669# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006670#endif
6671
6672#ifdef FEAT_LANGMAP
6673 /* 'langmap' */
6674 else if (varp == &p_langmap)
6675 langmap_set();
6676#endif
6677
6678#ifdef FEAT_LINEBREAK
6679 /* 'breakat' */
6680 else if (varp == &p_breakat)
6681 fill_breakat_flags();
6682#endif
6683
6684#ifdef FEAT_TITLE
6685 /* 'titlestring' and 'iconstring' */
6686 else if (varp == &p_titlestring || varp == &p_iconstring)
6687 {
6688# ifdef FEAT_STL_OPT
6689 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6690
6691 /* NULL => statusline syntax */
6692 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6693 stl_syntax |= flagval;
6694 else
6695 stl_syntax &= ~flagval;
6696# endif
6697 did_set_title(varp == &p_iconstring);
6698
6699 }
6700#endif
6701
6702#ifdef FEAT_GUI
6703 /* 'guioptions' */
6704 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006705 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006706 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006707 redraw_gui_only = TRUE;
6708 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006709#endif
6710
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006711#if defined(FEAT_GUI_TABLINE)
6712 /* 'guitablabel' */
6713 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006714 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006715 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006716 redraw_gui_only = TRUE;
6717 }
6718 /* 'guitabtooltip' */
6719 else if (varp == &p_gtt)
6720 {
6721 redraw_gui_only = TRUE;
6722 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006723#endif
6724
Bram Moolenaar071d4272004-06-13 20:20:40 +00006725#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6726 /* 'ttymouse' */
6727 else if (varp == &p_ttym)
6728 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006729 /* Switch the mouse off before changing the escape sequences used for
6730 * that. */
6731 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006732 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6733 errmsg = e_invarg;
6734 else
6735 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006736 if (termcap_active)
6737 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006738 }
6739#endif
6740
Bram Moolenaar071d4272004-06-13 20:20:40 +00006741 /* 'selection' */
6742 else if (varp == &p_sel)
6743 {
6744 if (*p_sel == NUL
6745 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6746 errmsg = e_invarg;
6747 }
6748
6749 /* 'selectmode' */
6750 else if (varp == &p_slm)
6751 {
6752 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6753 errmsg = e_invarg;
6754 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006755
6756#ifdef FEAT_BROWSE
6757 /* 'browsedir' */
6758 else if (varp == &p_bsdir)
6759 {
6760 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6761 && !mch_isdir(p_bsdir))
6762 errmsg = e_invarg;
6763 }
6764#endif
6765
Bram Moolenaar071d4272004-06-13 20:20:40 +00006766 /* 'keymodel' */
6767 else if (varp == &p_km)
6768 {
6769 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6770 errmsg = e_invarg;
6771 else
6772 {
6773 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6774 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6775 }
6776 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777
6778 /* 'mousemodel' */
6779 else if (varp == &p_mousem)
6780 {
6781 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6782 errmsg = e_invarg;
6783#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6784 else if (*p_mousem != *oldval)
6785 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6786 * to create or delete the popup menus. */
6787 gui_motif_update_mousemodel(root_menu);
6788#endif
6789 }
6790
6791 /* 'switchbuf' */
6792 else if (varp == &p_swb)
6793 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006794 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 errmsg = e_invarg;
6796 }
6797
6798 /* 'debug' */
6799 else if (varp == &p_debug)
6800 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006801 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006802 errmsg = e_invarg;
6803 }
6804
6805 /* 'display' */
6806 else if (varp == &p_dy)
6807 {
6808 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6809 errmsg = e_invarg;
6810 else
6811 (void)init_chartab();
6812
6813 }
6814
6815#ifdef FEAT_VERTSPLIT
6816 /* 'eadirection' */
6817 else if (varp == &p_ead)
6818 {
6819 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6820 errmsg = e_invarg;
6821 }
6822#endif
6823
6824#ifdef FEAT_CLIPBOARD
6825 /* 'clipboard' */
6826 else if (varp == &p_cb)
6827 errmsg = check_clipboard_option();
6828#endif
6829
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006830#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006831 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6832 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006833 else if (varp == &(curwin->w_s->b_p_spl)
6834 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006835 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006836 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006837 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006838 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006839 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006840 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006841 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006842 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006843 /* 'spellsuggest' */
6844 else if (varp == &p_sps)
6845 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006846 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006847 errmsg = e_invarg;
6848 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006849 /* 'mkspellmem' */
6850 else if (varp == &p_msm)
6851 {
6852 if (spell_check_msm() != OK)
6853 errmsg = e_invarg;
6854 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006855#endif
6856
Bram Moolenaar071d4272004-06-13 20:20:40 +00006857#ifdef FEAT_QUICKFIX
6858 /* When 'bufhidden' is set, check for valid value. */
6859 else if (gvarp == &p_bh)
6860 {
6861 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6862 errmsg = e_invarg;
6863 }
6864
6865 /* When 'buftype' is set, check for valid value. */
6866 else if (gvarp == &p_bt)
6867 {
6868 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6869 errmsg = e_invarg;
6870 else
6871 {
6872# ifdef FEAT_WINDOWS
6873 if (curwin->w_status_height)
6874 {
6875 curwin->w_redr_status = TRUE;
6876 redraw_later(VALID);
6877 }
6878# endif
6879 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006880# ifdef FEAT_TITLE
6881 redraw_titles();
6882# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883 }
6884 }
6885#endif
6886
6887#ifdef FEAT_STL_OPT
6888 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006889 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006890 {
6891 int wid;
6892
6893 if (varp == &p_ruf) /* reset ru_wid first */
6894 ru_wid = 0;
6895 s = *varp;
6896 if (varp == &p_ruf && *s == '%')
6897 {
6898 /* set ru_wid if 'ruf' starts with "%99(" */
6899 if (*++s == '-') /* ignore a '-' */
6900 s++;
6901 wid = getdigits(&s);
6902 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6903 ru_wid = wid;
6904 else
6905 errmsg = check_stl_option(p_ruf);
6906 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006907 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006908 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006909 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006910 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006911 comp_col();
6912 }
6913#endif
6914
6915#ifdef FEAT_INS_EXPAND
6916 /* check if it is a valid value for 'complete' -- Acevedo */
6917 else if (gvarp == &p_cpt)
6918 {
6919 for (s = *varp; *s;)
6920 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006921 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006922 s++;
6923 if (!*s)
6924 break;
6925 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6926 {
6927 errmsg = illegal_char(errbuf, *s);
6928 break;
6929 }
6930 if (*++s != NUL && *s != ',' && *s != ' ')
6931 {
6932 if (s[-1] == 'k' || s[-1] == 's')
6933 {
6934 /* skip optional filename after 'k' and 's' */
6935 while (*s && *s != ',' && *s != ' ')
6936 {
6937 if (*s == '\\')
6938 ++s;
6939 ++s;
6940 }
6941 }
6942 else
6943 {
6944 if (errbuf != NULL)
6945 {
6946 sprintf((char *)errbuf,
6947 _("E535: Illegal character after <%c>"),
6948 *--s);
6949 errmsg = errbuf;
6950 }
6951 else
6952 errmsg = (char_u *)"";
6953 break;
6954 }
6955 }
6956 }
6957 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006958
6959 /* 'completeopt' */
6960 else if (varp == &p_cot)
6961 {
6962 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6963 errmsg = e_invarg;
6964 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965#endif /* FEAT_INS_EXPAND */
6966
6967
6968#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6969 else if (varp == &p_toolbar)
6970 {
6971 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6972 &toolbar_flags, TRUE) != OK)
6973 errmsg = e_invarg;
6974 else
6975 {
6976 out_flush();
6977 gui_mch_show_toolbar((toolbar_flags &
6978 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6979 }
6980 }
6981#endif
6982
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006983#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006984 /* 'toolbariconsize': GTK+ 2 only */
6985 else if (varp == &p_tbis)
6986 {
6987 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6988 errmsg = e_invarg;
6989 else
6990 {
6991 out_flush();
6992 gui_mch_show_toolbar((toolbar_flags &
6993 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6994 }
6995 }
6996#endif
6997
6998 /* 'pastetoggle': translate key codes like in a mapping */
6999 else if (varp == &p_pt)
7000 {
7001 if (*p_pt)
7002 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007003 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007004 if (p != NULL)
7005 {
7006 if (new_value_alloced)
7007 free_string_option(p_pt);
7008 p_pt = p;
7009 new_value_alloced = TRUE;
7010 }
7011 }
7012 }
7013
7014 /* 'backspace' */
7015 else if (varp == &p_bs)
7016 {
7017 if (VIM_ISDIGIT(*p_bs))
7018 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007019 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007020 errmsg = e_invarg;
7021 }
7022 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7023 errmsg = e_invarg;
7024 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007025 else if (varp == &p_bo)
7026 {
7027 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7028 errmsg = e_invarg;
7029 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007030
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007031 /* 'tagcase' */
7032 else if (gvarp == &p_tc)
7033 {
7034 unsigned int *flags;
7035
7036 if (opt_flags & OPT_LOCAL)
7037 {
7038 p = curbuf->b_p_tc;
7039 flags = &curbuf->b_tc_flags;
7040 }
7041 else
7042 {
7043 p = p_tc;
7044 flags = &tc_flags;
7045 }
7046
7047 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7048 /* make the local value empty: use the global value */
7049 *flags = 0;
7050 else if (*p == NUL
7051 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7052 errmsg = e_invarg;
7053 }
7054
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007055#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007056 /* 'casemap' */
7057 else if (varp == &p_cmp)
7058 {
7059 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7060 errmsg = e_invarg;
7061 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007062#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063
7064#ifdef FEAT_DIFF
7065 /* 'diffopt' */
7066 else if (varp == &p_dip)
7067 {
7068 if (diffopt_changed() == FAIL)
7069 errmsg = e_invarg;
7070 }
7071#endif
7072
7073#ifdef FEAT_FOLDING
7074 /* 'foldmethod' */
7075 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7076 {
7077 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7078 || *curwin->w_p_fdm == NUL)
7079 errmsg = e_invarg;
7080 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007081 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007082 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007083 if (foldmethodIsDiff(curwin))
7084 newFoldLevel();
7085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007086 }
7087# ifdef FEAT_EVAL
7088 /* 'foldexpr' */
7089 else if (varp == &curwin->w_p_fde)
7090 {
7091 if (foldmethodIsExpr(curwin))
7092 foldUpdateAll(curwin);
7093 }
7094# endif
7095 /* 'foldmarker' */
7096 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7097 {
7098 p = vim_strchr(*varp, ',');
7099 if (p == NULL)
7100 errmsg = (char_u *)N_("E536: comma required");
7101 else if (p == *varp || p[1] == NUL)
7102 errmsg = e_invarg;
7103 else if (foldmethodIsMarker(curwin))
7104 foldUpdateAll(curwin);
7105 }
7106 /* 'commentstring' */
7107 else if (gvarp == &p_cms)
7108 {
7109 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7110 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7111 }
7112 /* 'foldopen' */
7113 else if (varp == &p_fdo)
7114 {
7115 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7116 errmsg = e_invarg;
7117 }
7118 /* 'foldclose' */
7119 else if (varp == &p_fcl)
7120 {
7121 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7122 errmsg = e_invarg;
7123 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007124 /* 'foldignore' */
7125 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7126 {
7127 if (foldmethodIsIndent(curwin))
7128 foldUpdateAll(curwin);
7129 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007130#endif
7131
7132#ifdef FEAT_VIRTUALEDIT
7133 /* 'virtualedit' */
7134 else if (varp == &p_ve)
7135 {
7136 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7137 errmsg = e_invarg;
7138 else if (STRCMP(p_ve, oldval) != 0)
7139 {
7140 /* Recompute cursor position in case the new 've' setting
7141 * changes something. */
7142 validate_virtcol();
7143 coladvance(curwin->w_virtcol);
7144 }
7145 }
7146#endif
7147
7148#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7149 else if (varp == &p_csqf)
7150 {
7151 if (p_csqf != NULL)
7152 {
7153 p = p_csqf;
7154 while (*p != NUL)
7155 {
7156 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7157 || p[1] == NUL
7158 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7159 || (p[2] != NUL && p[2] != ','))
7160 {
7161 errmsg = e_invarg;
7162 break;
7163 }
7164 else if (p[2] == NUL)
7165 break;
7166 else
7167 p += 3;
7168 }
7169 }
7170 }
7171#endif
7172
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007173#ifdef FEAT_CINDENT
7174 /* 'cinoptions' */
7175 else if (gvarp == &p_cino)
7176 {
7177 /* TODO: recognize errors */
7178 parse_cino(curbuf);
7179 }
7180#endif
7181
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007182#if defined(FEAT_RENDER_OPTIONS)
7183 else if (varp == &p_rop && gui.in_use)
7184 {
7185 if (!gui_mch_set_rendering_options(p_rop))
7186 errmsg = e_invarg;
7187 }
7188#endif
7189
Bram Moolenaar071d4272004-06-13 20:20:40 +00007190 /* Options that are a list of flags. */
7191 else
7192 {
7193 p = NULL;
7194 if (varp == &p_ww)
7195 p = (char_u *)WW_ALL;
7196 if (varp == &p_shm)
7197 p = (char_u *)SHM_ALL;
7198 else if (varp == &(p_cpo))
7199 p = (char_u *)CPO_ALL;
7200 else if (varp == &(curbuf->b_p_fo))
7201 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007202#ifdef FEAT_CONCEAL
7203 else if (varp == &curwin->w_p_cocu)
7204 p = (char_u *)COCU_ALL;
7205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007206 else if (varp == &p_mouse)
7207 {
7208#ifdef FEAT_MOUSE
7209 p = (char_u *)MOUSE_ALL;
7210#else
7211 if (*p_mouse != NUL)
7212 errmsg = (char_u *)N_("E538: No mouse support");
7213#endif
7214 }
7215#if defined(FEAT_GUI)
7216 else if (varp == &p_go)
7217 p = (char_u *)GO_ALL;
7218#endif
7219 if (p != NULL)
7220 {
7221 for (s = *varp; *s; ++s)
7222 if (vim_strchr(p, *s) == NULL)
7223 {
7224 errmsg = illegal_char(errbuf, *s);
7225 break;
7226 }
7227 }
7228 }
7229
7230 /*
7231 * If error detected, restore the previous value.
7232 */
7233 if (errmsg != NULL)
7234 {
7235 if (new_value_alloced)
7236 free_string_option(*varp);
7237 *varp = oldval;
7238 /*
7239 * When resetting some values, need to act on it.
7240 */
7241 if (did_chartab)
7242 (void)init_chartab();
7243 if (varp == &p_hl)
7244 (void)highlight_changed();
7245 }
7246 else
7247 {
7248#ifdef FEAT_EVAL
7249 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007250 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251#endif
7252 /*
7253 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007254 * Use "free_oldval", because recursiveness may change the flags under
7255 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007256 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007257 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007258 free_string_option(oldval);
7259 if (new_value_alloced)
7260 options[opt_idx].flags |= P_ALLOCED;
7261 else
7262 options[opt_idx].flags &= ~P_ALLOCED;
7263
7264 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007265 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007266 {
7267 /* global option with local value set to use global value; free
7268 * the local value and make it empty */
7269 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7270 free_string_option(*(char_u **)p);
7271 *(char_u **)p = empty_option;
7272 }
7273
7274 /* May set global value for local option. */
7275 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7276 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007277
7278#ifdef FEAT_AUTOCMD
7279 /*
7280 * Trigger the autocommand only after setting the flags.
7281 */
7282# ifdef FEAT_SYN_HL
7283 /* When 'syntax' is set, load the syntax of that name */
7284 if (varp == &(curbuf->b_p_syn))
7285 {
7286 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7287 curbuf->b_fname, TRUE, curbuf);
7288 }
7289# endif
7290 else if (varp == &(curbuf->b_p_ft))
7291 {
7292 /* 'filetype' is set, trigger the FileType autocommand */
7293 did_filetype = TRUE;
7294 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7295 curbuf->b_fname, TRUE, curbuf);
7296 }
7297#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007298#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007299 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007300 {
7301 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007302 char_u *q = curwin->w_s->b_p_spl;
7303
7304 /* Skip the first name if it is "cjk". */
7305 if (STRNCMP(q, "cjk,", 4) == 0)
7306 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007307
7308 /*
7309 * Source the spell/LANG.vim in 'runtimepath'.
7310 * They could set 'spellcapcheck' depending on the language.
7311 * Use the first name in 'spelllang' up to '_region' or
7312 * '.encoding'.
7313 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007314 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007315 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7316 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007317 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007318 source_runtime(fname, TRUE);
7319 }
7320#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007321 }
7322
7323#ifdef FEAT_MOUSE
7324 if (varp == &p_mouse)
7325 {
7326# ifdef FEAT_MOUSE_TTY
7327 if (*p_mouse == NUL)
7328 mch_setmouse(FALSE); /* switch mouse off */
7329 else
7330# endif
7331 setmouse(); /* in case 'mouse' changed */
7332 }
7333#endif
7334
Bram Moolenaar913077c2012-03-28 19:59:04 +02007335 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007336 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007337 curwin->w_set_curswant = TRUE;
7338
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007339#ifdef FEAT_GUI
7340 /* check redraw when it's not a GUI option or the GUI is active. */
7341 if (!redraw_gui_only || gui.in_use)
7342#endif
7343 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007344
7345 return errmsg;
7346}
7347
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007348#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007349/*
7350 * Simple int comparison function for use with qsort()
7351 */
7352 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007353int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007354{
7355 return *(const int *)a - *(const int *)b;
7356}
7357
7358/*
7359 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7360 * Returns error message, NULL if it's OK.
7361 */
7362 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007363check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007364{
7365 char_u *s;
7366 int col;
7367 int count = 0;
7368 int color_cols[256];
7369 int i;
7370 int j = 0;
7371
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007372 if (wp->w_buffer == NULL)
7373 return NULL; /* buffer was closed */
7374
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007375 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007376 {
7377 if (*s == '-' || *s == '+')
7378 {
7379 /* -N and +N: add to 'textwidth' */
7380 col = (*s == '-') ? -1 : 1;
7381 ++s;
7382 if (!VIM_ISDIGIT(*s))
7383 return e_invarg;
7384 col = col * getdigits(&s);
7385 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007386 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007387 col += wp->w_buffer->b_p_tw;
7388 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007389 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007390 }
7391 else if (VIM_ISDIGIT(*s))
7392 col = getdigits(&s);
7393 else
7394 return e_invarg;
7395 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007396skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007397 if (*s == NUL)
7398 break;
7399 if (*s != ',')
7400 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007401 if (*++s == NUL)
7402 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007403 }
7404
7405 vim_free(wp->w_p_cc_cols);
7406 if (count == 0)
7407 wp->w_p_cc_cols = NULL;
7408 else
7409 {
7410 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7411 if (wp->w_p_cc_cols != NULL)
7412 {
7413 /* sort the columns for faster usage on screen redraw inside
7414 * win_line() */
7415 qsort(color_cols, count, sizeof(int), int_cmp);
7416
7417 for (i = 0; i < count; ++i)
7418 /* skip duplicates */
7419 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7420 wp->w_p_cc_cols[j++] = color_cols[i];
7421 wp->w_p_cc_cols[j] = -1; /* end marker */
7422 }
7423 }
7424
7425 return NULL; /* no error */
7426}
7427#endif
7428
Bram Moolenaar071d4272004-06-13 20:20:40 +00007429/*
7430 * Handle setting 'listchars' or 'fillchars'.
7431 * Returns error message, NULL if it's OK.
7432 */
7433 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007434set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007435{
7436 int round, i, len, entries;
7437 char_u *p, *s;
7438 int c1, c2 = 0;
7439 struct charstab
7440 {
7441 int *cp;
7442 char *name;
7443 };
7444#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7445 static struct charstab filltab[] =
7446 {
7447 {&fill_stl, "stl"},
7448 {&fill_stlnc, "stlnc"},
7449 {&fill_vert, "vert"},
7450 {&fill_fold, "fold"},
7451 {&fill_diff, "diff"},
7452 };
7453#endif
7454 static struct charstab lcstab[] =
7455 {
7456 {&lcs_eol, "eol"},
7457 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007458 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007459 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007460 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007461 {&lcs_tab2, "tab"},
7462 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007463#ifdef FEAT_CONCEAL
7464 {&lcs_conceal, "conceal"},
7465#else
7466 {NULL, "conceal"},
7467#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007468 };
7469 struct charstab *tab;
7470
7471#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7472 if (varp == &p_lcs)
7473#endif
7474 {
7475 tab = lcstab;
7476 entries = sizeof(lcstab) / sizeof(struct charstab);
7477 }
7478#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7479 else
7480 {
7481 tab = filltab;
7482 entries = sizeof(filltab) / sizeof(struct charstab);
7483 }
7484#endif
7485
7486 /* first round: check for valid value, second round: assign values */
7487 for (round = 0; round <= 1; ++round)
7488 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007489 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007490 {
7491 /* After checking that the value is valid: set defaults: space for
7492 * 'fillchars', NUL for 'listchars' */
7493 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007494 if (tab[i].cp != NULL)
7495 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 if (varp == &p_lcs)
7497 lcs_tab1 = NUL;
7498#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7499 else
7500 fill_diff = '-';
7501#endif
7502 }
7503 p = *varp;
7504 while (*p)
7505 {
7506 for (i = 0; i < entries; ++i)
7507 {
7508 len = (int)STRLEN(tab[i].name);
7509 if (STRNCMP(p, tab[i].name, len) == 0
7510 && p[len] == ':'
7511 && p[len + 1] != NUL)
7512 {
7513 s = p + len + 1;
7514#ifdef FEAT_MBYTE
7515 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007516 if (mb_char2cells(c1) > 1)
7517 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518#else
7519 c1 = *s++;
7520#endif
7521 if (tab[i].cp == &lcs_tab2)
7522 {
7523 if (*s == NUL)
7524 continue;
7525#ifdef FEAT_MBYTE
7526 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007527 if (mb_char2cells(c2) > 1)
7528 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007529#else
7530 c2 = *s++;
7531#endif
7532 }
7533 if (*s == ',' || *s == NUL)
7534 {
7535 if (round)
7536 {
7537 if (tab[i].cp == &lcs_tab2)
7538 {
7539 lcs_tab1 = c1;
7540 lcs_tab2 = c2;
7541 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007542 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543 *(tab[i].cp) = c1;
7544
7545 }
7546 p = s;
7547 break;
7548 }
7549 }
7550 }
7551
7552 if (i == entries)
7553 return e_invarg;
7554 if (*p == ',')
7555 ++p;
7556 }
7557 }
7558
7559 return NULL; /* no error */
7560}
7561
7562#ifdef FEAT_STL_OPT
7563/*
7564 * Check validity of options with the 'statusline' format.
7565 * Return error message or NULL.
7566 */
7567 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007568check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007569{
7570 int itemcnt = 0;
7571 int groupdepth = 0;
7572 static char_u errbuf[80];
7573
7574 while (*s && itemcnt < STL_MAX_ITEM)
7575 {
7576 /* Check for valid keys after % sequences */
7577 while (*s && *s != '%')
7578 s++;
7579 if (!*s)
7580 break;
7581 s++;
7582 if (*s != '%' && *s != ')')
7583 ++itemcnt;
7584 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7585 {
7586 s++;
7587 continue;
7588 }
7589 if (*s == ')')
7590 {
7591 s++;
7592 if (--groupdepth < 0)
7593 break;
7594 continue;
7595 }
7596 if (*s == '-')
7597 s++;
7598 while (VIM_ISDIGIT(*s))
7599 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007600 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601 continue;
7602 if (*s == '.')
7603 {
7604 s++;
7605 while (*s && VIM_ISDIGIT(*s))
7606 s++;
7607 }
7608 if (*s == '(')
7609 {
7610 groupdepth++;
7611 continue;
7612 }
7613 if (vim_strchr(STL_ALL, *s) == NULL)
7614 {
7615 return illegal_char(errbuf, *s);
7616 }
7617 if (*s == '{')
7618 {
7619 s++;
7620 while (*s != '}' && *s)
7621 s++;
7622 if (*s != '}')
7623 return (char_u *)N_("E540: Unclosed expression sequence");
7624 }
7625 }
7626 if (itemcnt >= STL_MAX_ITEM)
7627 return (char_u *)N_("E541: too many items");
7628 if (groupdepth != 0)
7629 return (char_u *)N_("E542: unbalanced groups");
7630 return NULL;
7631}
7632#endif
7633
7634#ifdef FEAT_CLIPBOARD
7635/*
7636 * Extract the items in the 'clipboard' option and set global values.
7637 */
7638 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007639check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007640{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007641 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007642 int new_autoselect_star = FALSE;
7643 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007644 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007645 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007646 regprog_T *new_exclude_prog = NULL;
7647 char_u *errmsg = NULL;
7648 char_u *p;
7649
7650 for (p = p_cb; *p != NUL; )
7651 {
7652 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7653 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007654 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007655 p += 7;
7656 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007657 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007658 && (p[11] == ',' || p[11] == NUL))
7659 {
7660 new_unnamed |= CLIP_UNNAMED_PLUS;
7661 p += 11;
7662 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007663 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007664 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007665 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007666 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007667 p += 10;
7668 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007669 else if (STRNCMP(p, "autoselectplus", 14) == 0
7670 && (p[14] == ',' || p[14] == NUL))
7671 {
7672 new_autoselect_plus = TRUE;
7673 p += 14;
7674 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007675 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007676 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007677 {
7678 new_autoselectml = TRUE;
7679 p += 12;
7680 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007681 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7682 {
7683 new_html = TRUE;
7684 p += 4;
7685 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007686 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7687 {
7688 p += 8;
7689 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7690 if (new_exclude_prog == NULL)
7691 errmsg = e_invarg;
7692 break;
7693 }
7694 else
7695 {
7696 errmsg = e_invarg;
7697 break;
7698 }
7699 if (*p == ',')
7700 ++p;
7701 }
7702 if (errmsg == NULL)
7703 {
7704 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007705 clip_autoselect_star = new_autoselect_star;
7706 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007707 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007708 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007709 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007711#ifdef FEAT_GUI_GTK
7712 if (gui.in_use)
7713 {
7714 gui_gtk_set_selection_targets();
7715 gui_gtk_set_dnd_targets();
7716 }
7717#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007718 }
7719 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007720 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007721
7722 return errmsg;
7723}
7724#endif
7725
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007726#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007727 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007728did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007729{
7730 char_u *errmsg = NULL;
7731 win_T *wp;
7732 int l;
7733
7734 if (is_spellfile)
7735 {
7736 l = (int)STRLEN(curwin->w_s->b_p_spf);
7737 if (l > 0 && (l < 4
7738 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7739 errmsg = e_invarg;
7740 }
7741
7742 if (errmsg == NULL)
7743 {
7744 FOR_ALL_WINDOWS(wp)
7745 if (wp->w_buffer == curbuf && wp->w_p_spell)
7746 {
7747 errmsg = did_set_spelllang(wp);
7748# ifdef FEAT_WINDOWS
7749 break;
7750# endif
7751 }
7752 }
7753 return errmsg;
7754}
7755
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007756/*
7757 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7758 * Return error message when failed, NULL when OK.
7759 */
7760 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007761compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007762{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007763 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007764 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007765
Bram Moolenaar860cae12010-06-05 23:22:07 +02007766 if (*synblock->b_p_spc == NUL)
7767 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007768 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007769 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007770 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007771 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007772 if (re != NULL)
7773 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007774 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007775 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007776 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007777 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007778 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007779 return e_invarg;
7780 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007781 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007782 }
7783
Bram Moolenaar473de612013-06-08 18:19:48 +02007784 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007785 return NULL;
7786}
7787#endif
7788
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007789#if defined(FEAT_EVAL) || defined(PROTO)
7790/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007791 * Set the scriptID for an option, taking care of setting the buffer- or
7792 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007793 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007794 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007795set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007796{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007797 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7798 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007799
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007800 /* Remember where the option was set. For local options need to do that
7801 * in the buffer or window structure. */
7802 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007803 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007804 if (both || (opt_flags & OPT_LOCAL))
7805 {
7806 if (indir & PV_BUF)
7807 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7808 else if (indir & PV_WIN)
7809 curwin->w_p_scriptID[indir & PV_MASK] = id;
7810 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007811}
7812#endif
7813
Bram Moolenaar071d4272004-06-13 20:20:40 +00007814/*
7815 * Set the value of a boolean option, and take care of side effects.
7816 * Returns NULL for success, or an error message for an error.
7817 */
7818 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007819set_bool_option(
7820 int opt_idx, /* index in options[] table */
7821 char_u *varp, /* pointer to the option variable */
7822 int value, /* new value */
7823 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007824{
7825 int old_value = *(int *)varp;
7826
Bram Moolenaar071d4272004-06-13 20:20:40 +00007827 /* Disallow changing some options from secure mode */
7828 if ((secure
7829#ifdef HAVE_SANDBOX
7830 || sandbox != 0
7831#endif
7832 ) && (options[opt_idx].flags & P_SECURE))
7833 return e_secure;
7834
7835 *(int *)varp = value; /* set the new value */
7836#ifdef FEAT_EVAL
7837 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007838 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007839#endif
7840
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007841#ifdef FEAT_GUI
7842 need_mouse_correct = TRUE;
7843#endif
7844
Bram Moolenaar071d4272004-06-13 20:20:40 +00007845 /* May set global value for local option. */
7846 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7847 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7848
7849 /*
7850 * Handle side effects of changing a bool option.
7851 */
7852
7853 /* 'compatible' */
7854 if ((int *)varp == &p_cp)
7855 {
7856 compatible_set();
7857 }
7858
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007859#ifdef FEAT_PERSISTENT_UNDO
7860 /* 'undofile' */
7861 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7862 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007863 /* Only take action when the option was set. When reset we do not
7864 * delete the undo file, the option may be set again without making
7865 * any changes in between. */
7866 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007867 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007868 char_u hash[UNDO_HASH_SIZE];
7869 buf_T *save_curbuf = curbuf;
7870
7871 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007872 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007873 /* When 'undofile' is set globally: for every buffer, otherwise
7874 * only for the current buffer: Try to read in the undofile,
7875 * if one exists, the buffer wasn't changed and the buffer was
7876 * loaded */
7877 if ((curbuf == save_curbuf
7878 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7879 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7880 {
7881 u_compute_hash(hash);
7882 u_read_undo(NULL, hash, curbuf->b_fname);
7883 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007884 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007885 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007886 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007887 }
7888#endif
7889
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890 else if ((int *)varp == &curbuf->b_p_ro)
7891 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007892 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007893 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7894 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007895
7896 /* when 'readonly' is set may give W10 again */
7897 if (curbuf->b_p_ro)
7898 curbuf->b_did_warn = FALSE;
7899
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007901 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902#endif
7903 }
7904
Bram Moolenaar9c449722010-07-20 18:44:27 +02007905#ifdef FEAT_GUI
7906 else if ((int *)varp == &p_mh)
7907 {
7908 if (!p_mh)
7909 gui_mch_mousehide(FALSE);
7910 }
7911#endif
7912
Bram Moolenaara539df02010-08-01 14:35:05 +02007913#ifdef FEAT_TITLE
7914 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007916 {
7917 redraw_titles();
7918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919 /* when 'endofline' is changed, redraw the window title */
7920 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007921 {
7922 redraw_titles();
7923 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007924 /* when 'fixeol' is changed, redraw the window title */
7925 else if ((int *)varp == &curbuf->b_p_fixeol)
7926 {
7927 redraw_titles();
7928 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007929# ifdef FEAT_MBYTE
7930 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007931 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007932 {
7933 redraw_titles();
7934 }
7935# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936#endif
7937
7938 /* when 'bin' is set also set some other options */
7939 else if ((int *)varp == &curbuf->b_p_bin)
7940 {
7941 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7942#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007943 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944#endif
7945 }
7946
7947#ifdef FEAT_AUTOCMD
7948 /* when 'buflisted' changes, trigger autocommands */
7949 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7950 {
7951 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7952 NULL, NULL, TRUE, curbuf);
7953 }
7954#endif
7955
7956 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7957 else if ((int *)varp == &curbuf->b_p_swf)
7958 {
7959 if (curbuf->b_p_swf && p_uc)
7960 ml_open_file(curbuf); /* create the swap file */
7961 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007962 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7963 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 mf_close_file(curbuf, TRUE); /* remove the swap file */
7965 }
7966
7967 /* when 'terse' is set change 'shortmess' */
7968 else if ((int *)varp == &p_terse)
7969 {
7970 char_u *p;
7971
7972 p = vim_strchr(p_shm, SHM_SEARCH);
7973
7974 /* insert 's' in p_shm */
7975 if (p_terse && p == NULL)
7976 {
7977 STRCPY(IObuff, p_shm);
7978 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007979 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980 }
7981 /* remove 's' from p_shm */
7982 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007983 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007984 }
7985
7986 /* when 'paste' is set or reset also change other options */
7987 else if ((int *)varp == &p_paste)
7988 {
7989 paste_option_changed();
7990 }
7991
7992 /* when 'insertmode' is set from an autocommand need to do work here */
7993 else if ((int *)varp == &p_im)
7994 {
7995 if (p_im)
7996 {
7997 if ((State & INSERT) == 0)
7998 need_start_insertmode = TRUE;
7999 stop_insert_mode = FALSE;
8000 }
8001 else
8002 {
8003 need_start_insertmode = FALSE;
8004 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008005 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008006 clear_cmdline = TRUE; /* remove "(insert)" */
8007 restart_edit = 0;
8008 }
8009 }
8010
8011 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8012 else if ((int *)varp == &p_ic && p_hls)
8013 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008014 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008015 }
8016
8017#ifdef FEAT_SEARCH_EXTRA
8018 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8019 else if ((int *)varp == &p_hls)
8020 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008021 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008022 }
8023#endif
8024
8025#ifdef FEAT_SCROLLBIND
8026 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8027 * at the end of normal_cmd() */
8028 else if ((int *)varp == &curwin->w_p_scb)
8029 {
8030 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008031 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008032 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008033 curwin->w_scbind_pos = curwin->w_topline;
8034 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008035 }
8036#endif
8037
8038#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8039 /* There can be only one window with 'previewwindow' set. */
8040 else if ((int *)varp == &curwin->w_p_pvw)
8041 {
8042 if (curwin->w_p_pvw)
8043 {
8044 win_T *win;
8045
8046 for (win = firstwin; win != NULL; win = win->w_next)
8047 if (win->w_p_pvw && win != curwin)
8048 {
8049 curwin->w_p_pvw = FALSE;
8050 return (char_u *)N_("E590: A preview window already exists");
8051 }
8052 }
8053 }
8054#endif
8055
8056 /* when 'textmode' is set or reset also change 'fileformat' */
8057 else if ((int *)varp == &curbuf->b_p_tx)
8058 {
8059 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8060 }
8061
8062 /* when 'textauto' is set or reset also change 'fileformats' */
8063 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064 set_string_option_direct((char_u *)"ffs", -1,
8065 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008066 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008067
8068 /*
8069 * When 'lisp' option changes include/exclude '-' in
8070 * keyword characters.
8071 */
8072#ifdef FEAT_LISP
8073 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8074 {
8075 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8076 }
8077#endif
8078
8079#ifdef FEAT_TITLE
8080 /* when 'title' changed, may need to change the title; same for 'icon' */
8081 else if ((int *)varp == &p_title)
8082 {
8083 did_set_title(FALSE);
8084 }
8085
8086 else if ((int *)varp == &p_icon)
8087 {
8088 did_set_title(TRUE);
8089 }
8090#endif
8091
8092 else if ((int *)varp == &curbuf->b_changed)
8093 {
8094 if (!value)
8095 save_file_ff(curbuf); /* Buffer is unchanged */
8096#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008097 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008098#endif
8099#ifdef FEAT_AUTOCMD
8100 modified_was_set = value;
8101#endif
8102 }
8103
8104#ifdef BACKSLASH_IN_FILENAME
8105 else if ((int *)varp == &p_ssl)
8106 {
8107 if (p_ssl)
8108 {
8109 psepc = '/';
8110 psepcN = '\\';
8111 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008112 }
8113 else
8114 {
8115 psepc = '\\';
8116 psepcN = '/';
8117 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118 }
8119
8120 /* need to adjust the file name arguments and buffer names. */
8121 buflist_slash_adjust();
8122 alist_slash_adjust();
8123# ifdef FEAT_EVAL
8124 scriptnames_slash_adjust();
8125# endif
8126 }
8127#endif
8128
8129 /* If 'wrap' is set, set w_leftcol to zero. */
8130 else if ((int *)varp == &curwin->w_p_wrap)
8131 {
8132 if (curwin->w_p_wrap)
8133 curwin->w_leftcol = 0;
8134 }
8135
8136#ifdef FEAT_WINDOWS
8137 else if ((int *)varp == &p_ea)
8138 {
8139 if (p_ea && !old_value)
8140 win_equal(curwin, FALSE, 0);
8141 }
8142#endif
8143
8144 else if ((int *)varp == &p_wiv)
8145 {
8146 /*
8147 * When 'weirdinvert' changed, set/reset 't_xs'.
8148 * Then set 'weirdinvert' according to value of 't_xs'.
8149 */
8150 if (p_wiv && !old_value)
8151 T_XS = (char_u *)"y";
8152 else if (!p_wiv && old_value)
8153 T_XS = empty_option;
8154 p_wiv = (*T_XS != NUL);
8155 }
8156
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008157#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 else if ((int *)varp == &p_beval)
8159 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008160 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008162 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 gui_mch_disable_beval_area(balloonEval);
8164 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008165#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008166
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008167#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008168 else if ((int *)varp == &p_acd)
8169 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008170 /* Change directories when the 'acd' option is set now. */
8171 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008172 }
8173#endif
8174
8175#ifdef FEAT_DIFF
8176 /* 'diff' */
8177 else if ((int *)varp == &curwin->w_p_diff)
8178 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008179 /* May add or remove the buffer from the list of diff buffers. */
8180 diff_buf_adjust(curwin);
8181# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008182 if (foldmethodIsDiff(curwin))
8183 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008184# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008185 }
8186#endif
8187
8188#ifdef USE_IM_CONTROL
8189 /* 'imdisable' */
8190 else if ((int *)varp == &p_imdisable)
8191 {
8192 /* Only de-activate it here, it will be enabled when changing mode. */
8193 if (p_imdisable)
8194 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008195 else if (State & INSERT)
8196 /* When the option is set from an autocommand, it may need to take
8197 * effect right away. */
8198 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008199 }
8200#endif
8201
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008202#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008203 /* 'spell' */
8204 else if ((int *)varp == &curwin->w_p_spell)
8205 {
8206 if (curwin->w_p_spell)
8207 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008208 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008209 if (errmsg != NULL)
8210 EMSG(_(errmsg));
8211 }
8212 }
8213#endif
8214
Bram Moolenaar071d4272004-06-13 20:20:40 +00008215#ifdef FEAT_FKMAP
8216 else if ((int *)varp == &p_altkeymap)
8217 {
8218 if (old_value != p_altkeymap)
8219 {
8220 if (!p_altkeymap)
8221 {
8222 p_hkmap = p_fkmap;
8223 p_fkmap = 0;
8224 }
8225 else
8226 {
8227 p_fkmap = p_hkmap;
8228 p_hkmap = 0;
8229 }
8230 (void)init_chartab();
8231 }
8232 }
8233
8234 /*
8235 * In case some second language keymapping options have changed, check
8236 * and correct the setting in a consistent way.
8237 */
8238
8239 /*
8240 * If hkmap or fkmap are set, reset Arabic keymapping.
8241 */
8242 if ((p_hkmap || p_fkmap) && p_altkeymap)
8243 {
8244 p_altkeymap = p_fkmap;
8245# ifdef FEAT_ARABIC
8246 curwin->w_p_arab = FALSE;
8247# endif
8248 (void)init_chartab();
8249 }
8250
8251 /*
8252 * If hkmap set, reset Farsi keymapping.
8253 */
8254 if (p_hkmap && p_altkeymap)
8255 {
8256 p_altkeymap = 0;
8257 p_fkmap = 0;
8258# ifdef FEAT_ARABIC
8259 curwin->w_p_arab = FALSE;
8260# endif
8261 (void)init_chartab();
8262 }
8263
8264 /*
8265 * If fkmap set, reset Hebrew keymapping.
8266 */
8267 if (p_fkmap && !p_altkeymap)
8268 {
8269 p_altkeymap = 1;
8270 p_hkmap = 0;
8271# ifdef FEAT_ARABIC
8272 curwin->w_p_arab = FALSE;
8273# endif
8274 (void)init_chartab();
8275 }
8276#endif
8277
8278#ifdef FEAT_ARABIC
8279 if ((int *)varp == &curwin->w_p_arab)
8280 {
8281 if (curwin->w_p_arab)
8282 {
8283 /*
8284 * 'arabic' is set, handle various sub-settings.
8285 */
8286 if (!p_tbidi)
8287 {
8288 /* set rightleft mode */
8289 if (!curwin->w_p_rl)
8290 {
8291 curwin->w_p_rl = TRUE;
8292 changed_window_setting();
8293 }
8294
8295 /* Enable Arabic shaping (major part of what Arabic requires) */
8296 if (!p_arshape)
8297 {
8298 p_arshape = TRUE;
8299 redraw_later_clear();
8300 }
8301 }
8302
8303 /* Arabic requires a utf-8 encoding, inform the user if its not
8304 * set. */
8305 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008306 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008307 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8308
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008309 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008310 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8311#ifdef FEAT_EVAL
8312 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8313#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008314 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008315
8316# ifdef FEAT_MBYTE
8317 /* set 'delcombine' */
8318 p_deco = TRUE;
8319# endif
8320
8321# ifdef FEAT_KEYMAP
8322 /* Force-set the necessary keymap for arabic */
8323 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8324 OPT_LOCAL);
8325# endif
8326# ifdef FEAT_FKMAP
8327 p_altkeymap = 0;
8328 p_hkmap = 0;
8329 p_fkmap = 0;
8330 (void)init_chartab();
8331# endif
8332 }
8333 else
8334 {
8335 /*
8336 * 'arabic' is reset, handle various sub-settings.
8337 */
8338 if (!p_tbidi)
8339 {
8340 /* reset rightleft mode */
8341 if (curwin->w_p_rl)
8342 {
8343 curwin->w_p_rl = FALSE;
8344 changed_window_setting();
8345 }
8346
8347 /* 'arabicshape' isn't reset, it is a global option and
8348 * another window may still need it "on". */
8349 }
8350
8351 /* 'delcombine' isn't reset, it is a global option and another
8352 * window may still want it "on". */
8353
8354# ifdef FEAT_KEYMAP
8355 /* Revert to the default keymap */
8356 curbuf->b_p_iminsert = B_IMODE_NONE;
8357 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8358# endif
8359 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008360 }
8361
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008362#endif
8363
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 /*
8365 * End of handling side effects for bool options.
8366 */
8367
Bram Moolenaar53744302015-07-17 17:38:22 +02008368 /* after handling side effects, call autocommand */
8369
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370 options[opt_idx].flags |= P_WAS_SET;
8371
Bram Moolenaar53744302015-07-17 17:38:22 +02008372#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8373 if (!starting)
8374 {
8375 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008376 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8377 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8378 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008379 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8380 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8381 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8382 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8383 reset_v_option_vars();
8384 }
8385#endif
8386
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008388 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008389 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008390 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008391 check_redraw(options[opt_idx].flags);
8392
8393 return NULL;
8394}
8395
8396/*
8397 * Set the value of a number option, and take care of side effects.
8398 * Returns NULL for success, or an error message for an error.
8399 */
8400 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008401set_num_option(
8402 int opt_idx, /* index in options[] table */
8403 char_u *varp, /* pointer to the option variable */
8404 long value, /* new value */
8405 char_u *errbuf, /* buffer for error messages */
8406 size_t errbuflen, /* length of "errbuf" */
8407 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408 OPT_MODELINE */
8409{
8410 char_u *errmsg = NULL;
8411 long old_value = *(long *)varp;
8412 long old_Rows = Rows; /* remember old Rows */
8413 long old_Columns = Columns; /* remember old Columns */
8414 long *pp = (long *)varp;
8415
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008416 /* Disallow changing some options from secure mode. */
8417 if ((secure
8418#ifdef HAVE_SANDBOX
8419 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008420#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008421 ) && (options[opt_idx].flags & P_SECURE))
8422 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423
8424 *pp = value;
8425#ifdef FEAT_EVAL
8426 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008427 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008429#ifdef FEAT_GUI
8430 need_mouse_correct = TRUE;
8431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008432
Bram Moolenaar14f24742012-08-08 18:01:05 +02008433 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 {
8435 errmsg = e_positive;
8436 curbuf->b_p_sw = curbuf->b_p_ts;
8437 }
8438
8439 /*
8440 * Number options that need some action when changed
8441 */
8442#ifdef FEAT_WINDOWS
8443 if (pp == &p_wh || pp == &p_hh)
8444 {
8445 if (p_wh < 1)
8446 {
8447 errmsg = e_positive;
8448 p_wh = 1;
8449 }
8450 if (p_wmh > p_wh)
8451 {
8452 errmsg = e_winheight;
8453 p_wh = p_wmh;
8454 }
8455 if (p_hh < 0)
8456 {
8457 errmsg = e_positive;
8458 p_hh = 0;
8459 }
8460
8461 /* Change window height NOW */
8462 if (lastwin != firstwin)
8463 {
8464 if (pp == &p_wh && curwin->w_height < p_wh)
8465 win_setheight((int)p_wh);
8466 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8467 win_setheight((int)p_hh);
8468 }
8469 }
8470
8471 /* 'winminheight' */
8472 else if (pp == &p_wmh)
8473 {
8474 if (p_wmh < 0)
8475 {
8476 errmsg = e_positive;
8477 p_wmh = 0;
8478 }
8479 if (p_wmh > p_wh)
8480 {
8481 errmsg = e_winheight;
8482 p_wmh = p_wh;
8483 }
8484 win_setminheight();
8485 }
8486
8487# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008488 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008489 {
8490 if (p_wiw < 1)
8491 {
8492 errmsg = e_positive;
8493 p_wiw = 1;
8494 }
8495 if (p_wmw > p_wiw)
8496 {
8497 errmsg = e_winwidth;
8498 p_wiw = p_wmw;
8499 }
8500
8501 /* Change window width NOW */
8502 if (lastwin != firstwin && curwin->w_width < p_wiw)
8503 win_setwidth((int)p_wiw);
8504 }
8505
8506 /* 'winminwidth' */
8507 else if (pp == &p_wmw)
8508 {
8509 if (p_wmw < 0)
8510 {
8511 errmsg = e_positive;
8512 p_wmw = 0;
8513 }
8514 if (p_wmw > p_wiw)
8515 {
8516 errmsg = e_winwidth;
8517 p_wmw = p_wiw;
8518 }
8519 win_setminheight();
8520 }
8521# endif
8522
8523#endif
8524
8525#ifdef FEAT_WINDOWS
8526 /* (re)set last window status line */
8527 else if (pp == &p_ls)
8528 {
8529 last_status(FALSE);
8530 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008531
8532 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008533 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008534 {
8535 shell_new_rows(); /* recompute window positions and heights */
8536 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008537#endif
8538
8539#ifdef FEAT_GUI
8540 else if (pp == &p_linespace)
8541 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008542 /* Recompute gui.char_height and resize the Vim window to keep the
8543 * same number of lines. */
8544 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008545 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008546 }
8547#endif
8548
8549#ifdef FEAT_FOLDING
8550 /* 'foldlevel' */
8551 else if (pp == &curwin->w_p_fdl)
8552 {
8553 if (curwin->w_p_fdl < 0)
8554 curwin->w_p_fdl = 0;
8555 newFoldLevel();
8556 }
8557
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008558 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008559 else if (pp == &curwin->w_p_fml)
8560 {
8561 foldUpdateAll(curwin);
8562 }
8563
8564 /* 'foldnestmax' */
8565 else if (pp == &curwin->w_p_fdn)
8566 {
8567 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8568 foldUpdateAll(curwin);
8569 }
8570
8571 /* 'foldcolumn' */
8572 else if (pp == &curwin->w_p_fdc)
8573 {
8574 if (curwin->w_p_fdc < 0)
8575 {
8576 errmsg = e_positive;
8577 curwin->w_p_fdc = 0;
8578 }
8579 else if (curwin->w_p_fdc > 12)
8580 {
8581 errmsg = e_invarg;
8582 curwin->w_p_fdc = 12;
8583 }
8584 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008585#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008587#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588 /* 'shiftwidth' or 'tabstop' */
8589 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8590 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008591# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008592 if (foldmethodIsIndent(curwin))
8593 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008594# endif
8595# ifdef FEAT_CINDENT
8596 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8597 * parse 'cinoptions'. */
8598 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8599 parse_cino(curbuf);
8600# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008601 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008602#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008603
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008604#ifdef FEAT_MBYTE
8605 /* 'maxcombine' */
8606 else if (pp == &p_mco)
8607 {
8608 if (p_mco > MAX_MCO)
8609 p_mco = MAX_MCO;
8610 else if (p_mco < 0)
8611 p_mco = 0;
8612 screenclear(); /* will re-allocate the screen */
8613 }
8614#endif
8615
Bram Moolenaar071d4272004-06-13 20:20:40 +00008616 else if (pp == &curbuf->b_p_iminsert)
8617 {
8618 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8619 {
8620 errmsg = e_invarg;
8621 curbuf->b_p_iminsert = B_IMODE_NONE;
8622 }
8623 p_iminsert = curbuf->b_p_iminsert;
8624 if (termcap_active) /* don't do this in the alternate screen */
8625 showmode();
8626#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8627 /* Show/unshow value of 'keymap' in status lines. */
8628 status_redraw_curbuf();
8629#endif
8630 }
8631
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008632 else if (pp == &p_window)
8633 {
8634 if (p_window < 1)
8635 p_window = 1;
8636 else if (p_window >= Rows)
8637 p_window = Rows - 1;
8638 }
8639
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640 else if (pp == &curbuf->b_p_imsearch)
8641 {
8642 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8643 {
8644 errmsg = e_invarg;
8645 curbuf->b_p_imsearch = B_IMODE_NONE;
8646 }
8647 p_imsearch = curbuf->b_p_imsearch;
8648 }
8649
8650#ifdef FEAT_TITLE
8651 /* if 'titlelen' has changed, redraw the title */
8652 else if (pp == &p_titlelen)
8653 {
8654 if (p_titlelen < 0)
8655 {
8656 errmsg = e_positive;
8657 p_titlelen = 85;
8658 }
8659 if (starting != NO_SCREEN && old_value != p_titlelen)
8660 need_maketitle = TRUE;
8661 }
8662#endif
8663
8664 /* if p_ch changed value, change the command line height */
8665 else if (pp == &p_ch)
8666 {
8667 if (p_ch < 1)
8668 {
8669 errmsg = e_positive;
8670 p_ch = 1;
8671 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008672 if (p_ch > Rows - min_rows() + 1)
8673 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008674
8675 /* Only compute the new window layout when startup has been
8676 * completed. Otherwise the frame sizes may be wrong. */
8677 if (p_ch != old_value && full_screen
8678#ifdef FEAT_GUI
8679 && !gui.starting
8680#endif
8681 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008682 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008683 }
8684
8685 /* when 'updatecount' changes from zero to non-zero, open swap files */
8686 else if (pp == &p_uc)
8687 {
8688 if (p_uc < 0)
8689 {
8690 errmsg = e_positive;
8691 p_uc = 100;
8692 }
8693 if (p_uc && !old_value)
8694 ml_open_files();
8695 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008696#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008697 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008698 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008699 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008700 {
8701 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008702 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008703 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008704 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008705 {
8706 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008707 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008708 }
8709 }
8710#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008711#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008712 else if (pp == &p_mzq)
8713 mzvim_reset_timer();
8714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008715
8716 /* sync undo before 'undolevels' changes */
8717 else if (pp == &p_ul)
8718 {
8719 /* use the old value, otherwise u_sync() may not work properly */
8720 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008721 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008722 p_ul = value;
8723 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008724 else if (pp == &curbuf->b_p_ul)
8725 {
8726 /* use the old value, otherwise u_sync() may not work properly */
8727 curbuf->b_p_ul = old_value;
8728 u_sync(TRUE);
8729 curbuf->b_p_ul = value;
8730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008731
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008732#ifdef FEAT_LINEBREAK
8733 /* 'numberwidth' must be positive */
8734 else if (pp == &curwin->w_p_nuw)
8735 {
8736 if (curwin->w_p_nuw < 1)
8737 {
8738 errmsg = e_positive;
8739 curwin->w_p_nuw = 1;
8740 }
8741 if (curwin->w_p_nuw > 10)
8742 {
8743 errmsg = e_invarg;
8744 curwin->w_p_nuw = 10;
8745 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008746 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008747 }
8748#endif
8749
Bram Moolenaar1a384422010-07-14 19:53:30 +02008750 else if (pp == &curbuf->b_p_tw)
8751 {
8752 if (curbuf->b_p_tw < 0)
8753 {
8754 errmsg = e_positive;
8755 curbuf->b_p_tw = 0;
8756 }
8757#ifdef FEAT_SYN_HL
8758# ifdef FEAT_WINDOWS
8759 {
8760 win_T *wp;
8761 tabpage_T *tp;
8762
8763 FOR_ALL_TAB_WINDOWS(tp, wp)
8764 check_colorcolumn(wp);
8765 }
8766# else
8767 check_colorcolumn(curwin);
8768# endif
8769#endif
8770 }
8771
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 /*
8773 * Check the bounds for numeric options here
8774 */
8775 if (Rows < min_rows() && full_screen)
8776 {
8777 if (errbuf != NULL)
8778 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008779 vim_snprintf((char *)errbuf, errbuflen,
8780 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008781 errmsg = errbuf;
8782 }
8783 Rows = min_rows();
8784 }
8785 if (Columns < MIN_COLUMNS && full_screen)
8786 {
8787 if (errbuf != NULL)
8788 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008789 vim_snprintf((char *)errbuf, errbuflen,
8790 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008791 errmsg = errbuf;
8792 }
8793 Columns = MIN_COLUMNS;
8794 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008795 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796
8797#ifdef DJGPP
8798 /* avoid a crash by checking for a too large value of 'columns' */
8799 if (old_Columns != Columns && full_screen && term_console)
8800 mch_check_columns();
8801#endif
8802
8803 /*
8804 * If the screen (shell) height has been changed, assume it is the
8805 * physical screenheight.
8806 */
8807 if (old_Rows != Rows || old_Columns != Columns)
8808 {
8809 /* Changing the screen size is not allowed while updating the screen. */
8810 if (updating_screen)
8811 *pp = old_value;
8812 else if (full_screen
8813#ifdef FEAT_GUI
8814 && !gui.starting
8815#endif
8816 )
8817 set_shellsize((int)Columns, (int)Rows, TRUE);
8818 else
8819 {
8820 /* Postpone the resizing; check the size and cmdline position for
8821 * messages. */
8822 check_shellsize();
8823 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8824 cmdline_row = Rows - p_ch;
8825 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008826 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008827 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828 }
8829
Bram Moolenaar071d4272004-06-13 20:20:40 +00008830 if (curbuf->b_p_ts <= 0)
8831 {
8832 errmsg = e_positive;
8833 curbuf->b_p_ts = 8;
8834 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008835 if (p_tm < 0)
8836 {
8837 errmsg = e_positive;
8838 p_tm = 0;
8839 }
8840 if ((curwin->w_p_scr <= 0
8841 || (curwin->w_p_scr > curwin->w_height
8842 && curwin->w_height > 0))
8843 && full_screen)
8844 {
8845 if (pp == &(curwin->w_p_scr))
8846 {
8847 if (curwin->w_p_scr != 0)
8848 errmsg = e_scroll;
8849 win_comp_scroll(curwin);
8850 }
8851 /* If 'scroll' became invalid because of a side effect silently adjust
8852 * it. */
8853 else if (curwin->w_p_scr <= 0)
8854 curwin->w_p_scr = 1;
8855 else /* curwin->w_p_scr > curwin->w_height */
8856 curwin->w_p_scr = curwin->w_height;
8857 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008858 if (p_hi < 0)
8859 {
8860 errmsg = e_positive;
8861 p_hi = 0;
8862 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008863 else if (p_hi > 10000)
8864 {
8865 errmsg = e_invarg;
8866 p_hi = 10000;
8867 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008868 if (p_re < 0 || p_re > 2)
8869 {
8870 errmsg = e_invarg;
8871 p_re = 0;
8872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008873 if (p_report < 0)
8874 {
8875 errmsg = e_positive;
8876 p_report = 1;
8877 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008878 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008879 {
8880 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8881 p_sj = Rows / 2;
8882 else
8883 {
8884 errmsg = e_scroll;
8885 p_sj = 1;
8886 }
8887 }
8888 if (p_so < 0 && full_screen)
8889 {
8890 errmsg = e_scroll;
8891 p_so = 0;
8892 }
8893 if (p_siso < 0 && full_screen)
8894 {
8895 errmsg = e_positive;
8896 p_siso = 0;
8897 }
8898#ifdef FEAT_CMDWIN
8899 if (p_cwh < 1)
8900 {
8901 errmsg = e_positive;
8902 p_cwh = 1;
8903 }
8904#endif
8905 if (p_ut < 0)
8906 {
8907 errmsg = e_positive;
8908 p_ut = 2000;
8909 }
8910 if (p_ss < 0)
8911 {
8912 errmsg = e_positive;
8913 p_ss = 0;
8914 }
8915
8916 /* May set global value for local option. */
8917 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8918 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8919
8920 options[opt_idx].flags |= P_WAS_SET;
8921
Bram Moolenaar53744302015-07-17 17:38:22 +02008922#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8923 if (!starting && errmsg == NULL)
8924 {
8925 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008926 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8927 vim_snprintf((char *)buf_new, 10, "%ld", value);
8928 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008929 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8930 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8931 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8932 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8933 reset_v_option_vars();
8934 }
8935#endif
8936
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008938 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008939 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008940 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008941 check_redraw(options[opt_idx].flags);
8942
8943 return errmsg;
8944}
8945
8946/*
8947 * Called after an option changed: check if something needs to be redrawn.
8948 */
8949 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008950check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008951{
8952 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008953 int doclear = (flags & P_RCLR) == P_RCLR;
8954 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008955
8956#ifdef FEAT_WINDOWS
8957 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8958 status_redraw_all();
8959#endif
8960
8961 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8962 changed_window_setting();
8963 if (flags & P_RBUF)
8964 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008965 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008966 redraw_all_later(CLEAR);
8967 else if (all)
8968 redraw_all_later(NOT_VALID);
8969}
8970
8971/*
8972 * Find index for option 'arg'.
8973 * Return -1 if not found.
8974 */
8975 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008976findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008977{
8978 int opt_idx;
8979 char *s, *p;
8980 static short quick_tab[27] = {0, 0}; /* quick access table */
8981 int is_term_opt;
8982
8983 /*
8984 * For first call: Initialize the quick-access table.
8985 * It contains the index for the first option that starts with a certain
8986 * letter. There are 26 letters, plus the first "t_" option.
8987 */
8988 if (quick_tab[1] == 0)
8989 {
8990 p = options[0].fullname;
8991 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8992 {
8993 if (s[0] != p[0])
8994 {
8995 if (s[0] == 't' && s[1] == '_')
8996 quick_tab[26] = opt_idx;
8997 else
8998 quick_tab[CharOrdLow(s[0])] = opt_idx;
8999 }
9000 p = s;
9001 }
9002 }
9003
9004 /*
9005 * Check for name starting with an illegal character.
9006 */
9007#ifdef EBCDIC
9008 if (!islower(arg[0]))
9009#else
9010 if (arg[0] < 'a' || arg[0] > 'z')
9011#endif
9012 return -1;
9013
9014 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9015 if (is_term_opt)
9016 opt_idx = quick_tab[26];
9017 else
9018 opt_idx = quick_tab[CharOrdLow(arg[0])];
9019 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9020 {
9021 if (STRCMP(arg, s) == 0) /* match full name */
9022 break;
9023 }
9024 if (s == NULL && !is_term_opt)
9025 {
9026 opt_idx = quick_tab[CharOrdLow(arg[0])];
9027 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9028 {
9029 s = options[opt_idx].shortname;
9030 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9031 break;
9032 s = NULL;
9033 }
9034 }
9035 if (s == NULL)
9036 opt_idx = -1;
9037 return opt_idx;
9038}
9039
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009040#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009041/*
9042 * Get the value for an option.
9043 *
9044 * Returns:
9045 * Number or Toggle option: 1, *numval gets value.
9046 * String option: 0, *stringval gets allocated string.
9047 * Hidden Number or Toggle option: -1.
9048 * hidden String option: -2.
9049 * unknown option: -3.
9050 */
9051 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009052get_option_value(
9053 char_u *name,
9054 long *numval,
9055 char_u **stringval, /* NULL when only checking existence */
9056 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009057{
9058 int opt_idx;
9059 char_u *varp;
9060
9061 opt_idx = findoption(name);
9062 if (opt_idx < 0) /* unknown option */
9063 return -3;
9064
9065 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9066
9067 if (options[opt_idx].flags & P_STRING)
9068 {
9069 if (varp == NULL) /* hidden option */
9070 return -2;
9071 if (stringval != NULL)
9072 {
9073#ifdef FEAT_CRYPT
9074 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009075 if ((char_u **)varp == &curbuf->b_p_key
9076 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009077 *stringval = vim_strsave((char_u *)"*****");
9078 else
9079#endif
9080 *stringval = vim_strsave(*(char_u **)(varp));
9081 }
9082 return 0;
9083 }
9084
9085 if (varp == NULL) /* hidden option */
9086 return -1;
9087 if (options[opt_idx].flags & P_NUM)
9088 *numval = *(long *)varp;
9089 else
9090 {
9091 /* Special case: 'modified' is b_changed, but we also want to consider
9092 * it set when 'ff' or 'fenc' changed. */
9093 if ((int *)varp == &curbuf->b_changed)
9094 *numval = curbufIsChanged();
9095 else
9096 *numval = *(int *)varp;
9097 }
9098 return 1;
9099}
9100#endif
9101
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009102#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009103/*
9104 * Returns the option attributes and its value. Unlike the above function it
9105 * will return either global value or local value of the option depending on
9106 * what was requested, but it will never return global value if it was
9107 * requested to return local one and vice versa. Neither it will return
9108 * buffer-local value if it was requested to return window-local one.
9109 *
9110 * Pretends that option is absent if it is not present in the requested scope
9111 * (i.e. has no global, window-local or buffer-local value depending on
9112 * opt_type). Uses
9113 *
9114 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009115 * 0 hidden or unknown option, also option that does not have requested
9116 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009117 * see SOPT_* in vim.h for other flags
9118 *
9119 * Possible opt_type values: see SREQ_* in vim.h
9120 */
9121 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009122get_option_value_strict(
9123 char_u *name,
9124 long *numval,
9125 char_u **stringval, /* NULL when only obtaining attributes */
9126 int opt_type,
9127 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009128{
9129 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009130 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009131 struct vimoption *p;
9132 int r = 0;
9133
9134 opt_idx = findoption(name);
9135 if (opt_idx < 0)
9136 return 0;
9137
9138 p = &(options[opt_idx]);
9139
9140 /* Hidden option */
9141 if (p->var == NULL)
9142 return 0;
9143
9144 if (p->flags & P_BOOL)
9145 r |= SOPT_BOOL;
9146 else if (p->flags & P_NUM)
9147 r |= SOPT_NUM;
9148 else if (p->flags & P_STRING)
9149 r |= SOPT_STRING;
9150
9151 if (p->indir == PV_NONE)
9152 {
9153 if (opt_type == SREQ_GLOBAL)
9154 r |= SOPT_GLOBAL;
9155 else
9156 return 0; /* Did not request global-only option */
9157 }
9158 else
9159 {
9160 if (p->indir & PV_BOTH)
9161 r |= SOPT_GLOBAL;
9162 else if (opt_type == SREQ_GLOBAL)
9163 return 0; /* Requested global option */
9164
9165 if (p->indir & PV_WIN)
9166 {
9167 if (opt_type == SREQ_BUF)
9168 return 0; /* Did not request window-local option */
9169 else
9170 r |= SOPT_WIN;
9171 }
9172 else if (p->indir & PV_BUF)
9173 {
9174 if (opt_type == SREQ_WIN)
9175 return 0; /* Did not request buffer-local option */
9176 else
9177 r |= SOPT_BUF;
9178 }
9179 }
9180
9181 if (stringval == NULL)
9182 return r;
9183
9184 if (opt_type == SREQ_GLOBAL)
9185 varp = p->var;
9186 else
9187 {
9188 if (opt_type == SREQ_BUF)
9189 {
9190 /* Special case: 'modified' is b_changed, but we also want to
9191 * consider it set when 'ff' or 'fenc' changed. */
9192 if (p->indir == PV_MOD)
9193 {
9194 *numval = bufIsChanged((buf_T *) from);
9195 varp = NULL;
9196 }
9197#ifdef FEAT_CRYPT
9198 else if (p->indir == PV_KEY)
9199 {
9200 /* never return the value of the crypt key */
9201 *stringval = NULL;
9202 varp = NULL;
9203 }
9204#endif
9205 else
9206 {
9207 aco_save_T aco;
9208 aucmd_prepbuf(&aco, (buf_T *) from);
9209 varp = get_varp(p);
9210 aucmd_restbuf(&aco);
9211 }
9212 }
9213 else if (opt_type == SREQ_WIN)
9214 {
9215 win_T *save_curwin;
9216 save_curwin = curwin;
9217 curwin = (win_T *) from;
9218 curbuf = curwin->w_buffer;
9219 varp = get_varp(p);
9220 curwin = save_curwin;
9221 curbuf = curwin->w_buffer;
9222 }
9223 if (varp == p->var)
9224 return (r | SOPT_UNSET);
9225 }
9226
9227 if (varp != NULL)
9228 {
9229 if (p->flags & P_STRING)
9230 *stringval = vim_strsave(*(char_u **)(varp));
9231 else if (p->flags & P_NUM)
9232 *numval = *(long *) varp;
9233 else
9234 *numval = *(int *)varp;
9235 }
9236
9237 return r;
9238}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009239
9240/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009241 * Iterate over options. First argument is a pointer to a pointer to a
9242 * structure inside options[] array, second is option type like in the above
9243 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009244 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009245 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009246 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009247 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009248 * first argument to NULL.
9249 *
9250 * Returns full option name for current option on each call.
9251 */
9252 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009253option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009254{
9255 struct vimoption *ret = NULL;
9256 do
9257 {
9258 if (*option == NULL)
9259 *option = (void *) options;
9260 else if (((struct vimoption *) (*option))->fullname == NULL)
9261 {
9262 *option = NULL;
9263 return NULL;
9264 }
9265 else
9266 *option = (void *) (((struct vimoption *) (*option)) + 1);
9267
9268 ret = ((struct vimoption *) (*option));
9269
9270 /* Hidden option */
9271 if (ret->var == NULL)
9272 {
9273 ret = NULL;
9274 continue;
9275 }
9276
9277 switch (opt_type)
9278 {
9279 case SREQ_GLOBAL:
9280 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9281 ret = NULL;
9282 break;
9283 case SREQ_BUF:
9284 if (!(ret->indir & PV_BUF))
9285 ret = NULL;
9286 break;
9287 case SREQ_WIN:
9288 if (!(ret->indir & PV_WIN))
9289 ret = NULL;
9290 break;
9291 default:
9292 EMSG2(_(e_intern2), "option_iter_next()");
9293 return NULL;
9294 }
9295 }
9296 while (ret == NULL);
9297
9298 return (char_u *)ret->fullname;
9299}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009300#endif
9301
Bram Moolenaar071d4272004-06-13 20:20:40 +00009302/*
9303 * Set the value of option "name".
9304 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009305 *
9306 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009307 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009308 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009309set_option_value(
9310 char_u *name,
9311 long number,
9312 char_u *string,
9313 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009314{
9315 int opt_idx;
9316 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009317 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009318
9319 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009320 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009321 EMSG2(_("E355: Unknown option: %s"), name);
9322 else
9323 {
9324 flags = options[opt_idx].flags;
9325#ifdef HAVE_SANDBOX
9326 /* Disallow changing some options in the sandbox */
9327 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009328 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009329 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009330 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009331 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009332#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009333 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009334 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335 else
9336 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009337 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338 if (varp != NULL) /* hidden option is not changed */
9339 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009340 if (number == 0 && string != NULL)
9341 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009342 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009343
9344 /* Either we are given a string or we are setting option
9345 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009346 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009347 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009348 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009349 {
9350 /* There's another character after zeros or the string
9351 * is empty. In both cases, we are trying to set a
9352 * num option using a string. */
9353 EMSG3(_("E521: Number required: &%s = '%s'"),
9354 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009355 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009356
9357 }
9358 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009359 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009360 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009361 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009363 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009364 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009365 }
9366 }
9367 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009368 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009369}
9370
9371/*
9372 * Get the terminal code for a terminal option.
9373 * Returns NULL when not found.
9374 */
9375 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009376get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009377{
9378 int opt_idx;
9379 char_u *varp;
9380
9381 if (tname[0] != 't' || tname[1] != '_' ||
9382 tname[2] == NUL || tname[3] == NUL)
9383 return NULL;
9384 if ((opt_idx = findoption(tname)) >= 0)
9385 {
9386 varp = get_varp(&(options[opt_idx]));
9387 if (varp != NULL)
9388 varp = *(char_u **)(varp);
9389 return varp;
9390 }
9391 return find_termcode(tname + 2);
9392}
9393
9394 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009395get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396{
9397 int i;
9398
9399 i = findoption((char_u *)"hl");
9400 if (i >= 0)
9401 return options[i].def_val[VI_DEFAULT];
9402 return (char_u *)NULL;
9403}
9404
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009405#if defined(FEAT_MBYTE) || defined(PROTO)
9406 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009407get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009408{
9409 int i;
9410
9411 i = findoption((char_u *)"enc");
9412 if (i >= 0)
9413 return options[i].def_val[VI_DEFAULT];
9414 return (char_u *)NULL;
9415}
9416#endif
9417
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418/*
9419 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9420 */
9421 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009422find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423{
9424 int key;
9425 int modifiers;
9426
9427 /*
9428 * Don't use get_special_key_code() for t_xx, we don't want it to call
9429 * add_termcap_entry().
9430 */
9431 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9432 key = TERMCAP2KEY(arg[2], arg[3]);
9433 else
9434 {
9435 --arg; /* put arg at the '<' */
9436 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009437 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009438 if (modifiers) /* can't handle modifiers here */
9439 key = 0;
9440 }
9441 return key;
9442}
9443
9444/*
9445 * if 'all' == 0: show changed options
9446 * if 'all' == 1: show all normal options
9447 * if 'all' == 2: show all terminal options
9448 */
9449 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009450showoptions(
9451 int all,
9452 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009453{
9454 struct vimoption *p;
9455 int col;
9456 int isterm;
9457 char_u *varp;
9458 struct vimoption **items;
9459 int item_count;
9460 int run;
9461 int row, rows;
9462 int cols;
9463 int i;
9464 int len;
9465
9466#define INC 20
9467#define GAP 3
9468
9469 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9470 PARAM_COUNT));
9471 if (items == NULL)
9472 return;
9473
9474 /* Highlight title */
9475 if (all == 2)
9476 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9477 else if (opt_flags & OPT_GLOBAL)
9478 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9479 else if (opt_flags & OPT_LOCAL)
9480 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9481 else
9482 MSG_PUTS_TITLE(_("\n--- Options ---"));
9483
9484 /*
9485 * do the loop two times:
9486 * 1. display the short items
9487 * 2. display the long items (only strings and numbers)
9488 */
9489 for (run = 1; run <= 2 && !got_int; ++run)
9490 {
9491 /*
9492 * collect the items in items[]
9493 */
9494 item_count = 0;
9495 for (p = &options[0]; p->fullname != NULL; p++)
9496 {
9497 varp = NULL;
9498 isterm = istermoption(p);
9499 if (opt_flags != 0)
9500 {
9501 if (p->indir != PV_NONE && !isterm)
9502 varp = get_varp_scope(p, opt_flags);
9503 }
9504 else
9505 varp = get_varp(p);
9506 if (varp != NULL
9507 && ((all == 2 && isterm)
9508 || (all == 1 && !isterm)
9509 || (all == 0 && !optval_default(p, varp))))
9510 {
9511 if (p->flags & P_BOOL)
9512 len = 1; /* a toggle option fits always */
9513 else
9514 {
9515 option_value2string(p, opt_flags);
9516 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9517 }
9518 if ((len <= INC - GAP && run == 1) ||
9519 (len > INC - GAP && run == 2))
9520 items[item_count++] = p;
9521 }
9522 }
9523
9524 /*
9525 * display the items
9526 */
9527 if (run == 1)
9528 {
9529 cols = (Columns + GAP - 3) / INC;
9530 if (cols == 0)
9531 cols = 1;
9532 rows = (item_count + cols - 1) / cols;
9533 }
9534 else /* run == 2 */
9535 rows = item_count;
9536 for (row = 0; row < rows && !got_int; ++row)
9537 {
9538 msg_putchar('\n'); /* go to next line */
9539 if (got_int) /* 'q' typed in more */
9540 break;
9541 col = 0;
9542 for (i = row; i < item_count; i += rows)
9543 {
9544 msg_col = col; /* make columns */
9545 showoneopt(items[i], opt_flags);
9546 col += INC;
9547 }
9548 out_flush();
9549 ui_breakcheck();
9550 }
9551 }
9552 vim_free(items);
9553}
9554
9555/*
9556 * Return TRUE if option "p" has its default value.
9557 */
9558 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009559optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009560{
9561 int dvi;
9562
9563 if (varp == NULL)
9564 return TRUE; /* hidden option is always at default */
9565 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9566 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009567 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009569 /* the cast to long is required for Manx C, long_i is
9570 * needed for MSVC */
9571 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009572 /* P_STRING */
9573 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9574}
9575
9576/*
9577 * showoneopt: show the value of one option
9578 * must not be called with a hidden option!
9579 */
9580 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009581showoneopt(
9582 struct vimoption *p,
9583 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009584{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009585 char_u *varp;
9586 int save_silent = silent_mode;
9587
9588 silent_mode = FALSE;
9589 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009590
9591 varp = get_varp_scope(p, opt_flags);
9592
9593 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9594 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9595 ? !curbufIsChanged() : !*(int *)varp))
9596 MSG_PUTS("no");
9597 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9598 MSG_PUTS("--");
9599 else
9600 MSG_PUTS(" ");
9601 MSG_PUTS(p->fullname);
9602 if (!(p->flags & P_BOOL))
9603 {
9604 msg_putchar('=');
9605 /* put value string in NameBuff */
9606 option_value2string(p, opt_flags);
9607 msg_outtrans(NameBuff);
9608 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009609
9610 silent_mode = save_silent;
9611 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009612}
9613
9614/*
9615 * Write modified options as ":set" commands to a file.
9616 *
9617 * There are three values for "opt_flags":
9618 * OPT_GLOBAL: Write global option values and fresh values of
9619 * buffer-local options (used for start of a session
9620 * file).
9621 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9622 * curwin (used for a vimrc file).
9623 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9624 * and local values for window-local options of
9625 * curwin. Local values are also written when at the
9626 * default value, because a modeline or autocommand
9627 * may have set them when doing ":edit file" and the
9628 * user has set them back at the default or fresh
9629 * value.
9630 * When "local_only" is TRUE, don't write fresh
9631 * values, only local values (for ":mkview").
9632 * (fresh value = value used for a new buffer or window for a local option).
9633 *
9634 * Return FAIL on error, OK otherwise.
9635 */
9636 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009637makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009638{
9639 struct vimoption *p;
9640 char_u *varp; /* currently used value */
9641 char_u *varp_fresh; /* local value */
9642 char_u *varp_local = NULL; /* fresh value */
9643 char *cmd;
9644 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009645 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009646
9647 /*
9648 * The options that don't have a default (terminal name, columns, lines)
9649 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009650 * Do the loop over "options[]" twice: once for options with the
9651 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009652 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009653 for (pri = 1; pri >= 0; --pri)
9654 {
9655 for (p = &options[0]; !istermoption(p); p++)
9656 if (!(p->flags & P_NO_MKRC)
9657 && !istermoption(p)
9658 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009659 {
9660 /* skip global option when only doing locals */
9661 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9662 continue;
9663
9664 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9665 * file, they are always buffer-specific. */
9666 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9667 continue;
9668
9669 /* Global values are only written when not at the default value. */
9670 varp = get_varp_scope(p, opt_flags);
9671 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9672 continue;
9673
9674 round = 2;
9675 if (p->indir != PV_NONE)
9676 {
9677 if (p->var == VAR_WIN)
9678 {
9679 /* skip window-local option when only doing globals */
9680 if (!(opt_flags & OPT_LOCAL))
9681 continue;
9682 /* When fresh value of window-local option is not at the
9683 * default, need to write it too. */
9684 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9685 {
9686 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9687 if (!optval_default(p, varp_fresh))
9688 {
9689 round = 1;
9690 varp_local = varp;
9691 varp = varp_fresh;
9692 }
9693 }
9694 }
9695 }
9696
9697 /* Round 1: fresh value for window-local options.
9698 * Round 2: other values */
9699 for ( ; round <= 2; varp = varp_local, ++round)
9700 {
9701 if (round == 1 || (opt_flags & OPT_GLOBAL))
9702 cmd = "set";
9703 else
9704 cmd = "setlocal";
9705
9706 if (p->flags & P_BOOL)
9707 {
9708 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9709 return FAIL;
9710 }
9711 else if (p->flags & P_NUM)
9712 {
9713 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9714 return FAIL;
9715 }
9716 else /* P_STRING */
9717 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009718#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9719 int do_endif = FALSE;
9720
Bram Moolenaar071d4272004-06-13 20:20:40 +00009721 /* Don't set 'syntax' and 'filetype' again if the value is
9722 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009723 if (
9724# if defined(FEAT_SYN_HL)
9725 p->indir == PV_SYN
9726# if defined(FEAT_AUTOCMD)
9727 ||
9728# endif
9729# endif
9730# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009731 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009732# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009733 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 {
9735 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9736 *(char_u **)(varp)) < 0
9737 || put_eol(fd) < 0)
9738 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009739 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009741#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9743 (p->flags & P_EXPAND) != 0) == FAIL)
9744 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009745#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9746 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009747 {
9748 if (put_line(fd, "endif") == FAIL)
9749 return FAIL;
9750 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009751#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752 }
9753 }
9754 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009755 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009756 return OK;
9757}
9758
9759#if defined(FEAT_FOLDING) || defined(PROTO)
9760/*
9761 * Generate set commands for the local fold options only. Used when
9762 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9763 */
9764 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009765makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009766{
9767 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9768# ifdef FEAT_EVAL
9769 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9770 == FAIL
9771# endif
9772 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9773 == FAIL
9774 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9775 == FAIL
9776 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9777 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9778 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9779 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9780 )
9781 return FAIL;
9782
9783 return OK;
9784}
9785#endif
9786
9787 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009788put_setstring(
9789 FILE *fd,
9790 char *cmd,
9791 char *name,
9792 char_u **valuep,
9793 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009794{
9795 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009796 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009797
9798 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9799 return FAIL;
9800 if (*valuep != NULL)
9801 {
9802 /* Output 'pastetoggle' as key names. For other
9803 * options some characters have to be escaped with
9804 * CTRL-V or backslash */
9805 if (valuep == &p_pt)
9806 {
9807 s = *valuep;
9808 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009809 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810 return FAIL;
9811 }
9812 else if (expand)
9813 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009814 buf = alloc(MAXPATHL);
9815 if (buf == NULL)
9816 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009817 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9818 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009819 {
9820 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009821 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009822 }
9823 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009824 }
9825 else if (put_escstr(fd, *valuep, 2) == FAIL)
9826 return FAIL;
9827 }
9828 if (put_eol(fd) < 0)
9829 return FAIL;
9830 return OK;
9831}
9832
9833 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009834put_setnum(
9835 FILE *fd,
9836 char *cmd,
9837 char *name,
9838 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009839{
9840 long wc;
9841
9842 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9843 return FAIL;
9844 if (wc_use_keyname((char_u *)valuep, &wc))
9845 {
9846 /* print 'wildchar' and 'wildcharm' as a key name */
9847 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9848 return FAIL;
9849 }
9850 else if (fprintf(fd, "%ld", *valuep) < 0)
9851 return FAIL;
9852 if (put_eol(fd) < 0)
9853 return FAIL;
9854 return OK;
9855}
9856
9857 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009858put_setbool(
9859 FILE *fd,
9860 char *cmd,
9861 char *name,
9862 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009863{
Bram Moolenaar893de922007-10-02 18:40:57 +00009864 if (value < 0) /* global/local option using global value */
9865 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009866 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9867 || put_eol(fd) < 0)
9868 return FAIL;
9869 return OK;
9870}
9871
9872/*
9873 * Clear all the terminal options.
9874 * If the option has been allocated, free the memory.
9875 * Terminal options are never hidden or indirect.
9876 */
9877 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009878clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009879{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009880 /*
9881 * Reset a few things before clearing the old options. This may cause
9882 * outputting a few things that the terminal doesn't understand, but the
9883 * screen will be cleared later, so this is OK.
9884 */
9885#ifdef FEAT_MOUSE_TTY
9886 mch_setmouse(FALSE); /* switch mouse off */
9887#endif
9888#ifdef FEAT_TITLE
9889 mch_restore_title(3); /* restore window titles */
9890#endif
9891#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9892 /* When starting the GUI close the display opened for the clipboard.
9893 * After restoring the title, because that will need the display. */
9894 if (gui.starting)
9895 clear_xterm_clip();
9896#endif
9897#ifdef WIN3264
9898 /*
9899 * Check if this is allowed now.
9900 */
9901 if (can_end_termcap_mode(FALSE) == TRUE)
9902#endif
9903 stoptermcap(); /* stop termcap mode */
9904
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009905 free_termoptions();
9906}
9907
9908 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009909free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009910{
9911 struct vimoption *p;
9912
Bram Moolenaar071d4272004-06-13 20:20:40 +00009913 for (p = &options[0]; p->fullname != NULL; p++)
9914 if (istermoption(p))
9915 {
9916 if (p->flags & P_ALLOCED)
9917 free_string_option(*(char_u **)(p->var));
9918 if (p->flags & P_DEF_ALLOCED)
9919 free_string_option(p->def_val[VI_DEFAULT]);
9920 *(char_u **)(p->var) = empty_option;
9921 p->def_val[VI_DEFAULT] = empty_option;
9922 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9923 }
9924 clear_termcodes();
9925}
9926
9927/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009928 * Free the string for one term option, if it was allocated.
9929 * Set the string to empty_option and clear allocated flag.
9930 * "var" points to the option value.
9931 */
9932 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009933free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009934{
9935 struct vimoption *p;
9936
9937 for (p = &options[0]; p->fullname != NULL; p++)
9938 if (p->var == var)
9939 {
9940 if (p->flags & P_ALLOCED)
9941 free_string_option(*(char_u **)(p->var));
9942 *(char_u **)(p->var) = empty_option;
9943 p->flags &= ~P_ALLOCED;
9944 break;
9945 }
9946}
9947
9948/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009949 * Set the terminal option defaults to the current value.
9950 * Used after setting the terminal name.
9951 */
9952 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009953set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009954{
9955 struct vimoption *p;
9956
9957 for (p = &options[0]; p->fullname != NULL; p++)
9958 {
9959 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9960 {
9961 if (p->flags & P_DEF_ALLOCED)
9962 {
9963 free_string_option(p->def_val[VI_DEFAULT]);
9964 p->flags &= ~P_DEF_ALLOCED;
9965 }
9966 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9967 if (p->flags & P_ALLOCED)
9968 {
9969 p->flags |= P_DEF_ALLOCED;
9970 p->flags &= ~P_ALLOCED; /* don't free the value now */
9971 }
9972 }
9973 }
9974}
9975
9976/*
9977 * return TRUE if 'p' starts with 't_'
9978 */
9979 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009980istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009981{
9982 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9983}
9984
9985/*
9986 * Compute columns for ruler and shown command. 'sc_col' is also used to
9987 * decide what the maximum length of a message on the status line can be.
9988 * If there is a status line for the last window, 'sc_col' is independent
9989 * of 'ru_col'.
9990 */
9991
9992#define COL_RULER 17 /* columns needed by standard ruler */
9993
9994 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009995comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009996{
9997#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9998 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9999
10000 sc_col = 0;
10001 ru_col = 0;
10002 if (p_ru)
10003 {
10004#ifdef FEAT_STL_OPT
10005 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10006#else
10007 ru_col = COL_RULER + 1;
10008#endif
10009 /* no last status line, adjust sc_col */
10010 if (!last_has_status)
10011 sc_col = ru_col;
10012 }
10013 if (p_sc)
10014 {
10015 sc_col += SHOWCMD_COLS;
10016 if (!p_ru || last_has_status) /* no need for separating space */
10017 ++sc_col;
10018 }
10019 sc_col = Columns - sc_col;
10020 ru_col = Columns - ru_col;
10021 if (sc_col <= 0) /* screen too narrow, will become a mess */
10022 sc_col = 1;
10023 if (ru_col <= 0)
10024 ru_col = 1;
10025#else
10026 sc_col = Columns;
10027 ru_col = Columns;
10028#endif
10029}
10030
10031/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010032 * Unset local option value, similar to ":set opt<".
10033 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010034 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010035unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010036{
10037 struct vimoption *p;
10038 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010039 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010040
10041 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010042 if (opt_idx < 0)
10043 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010044 p = &(options[opt_idx]);
10045
10046 switch ((int)p->indir)
10047 {
10048 /* global option with local value: use local value if it's been set */
10049 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010050 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010051 break;
10052 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010053 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010054 break;
10055 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010056 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010057 break;
10058 case PV_AR:
10059 buf->b_p_ar = -1;
10060 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010061 case PV_BKC:
10062 clear_string_option(&buf->b_p_bkc);
10063 buf->b_bkc_flags = 0;
10064 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010065 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010066 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010067 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010068 case PV_TC:
10069 clear_string_option(&buf->b_p_tc);
10070 buf->b_tc_flags = 0;
10071 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010072#ifdef FEAT_FIND_ID
10073 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010074 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010075 break;
10076 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010077 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010078 break;
10079#endif
10080#ifdef FEAT_INS_EXPAND
10081 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010082 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010083 break;
10084 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010085 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010086 break;
10087#endif
10088#ifdef FEAT_QUICKFIX
10089 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010090 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010091 break;
10092 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010093 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010094 break;
10095 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010096 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010097 break;
10098#endif
10099#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10100 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010101 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010102 break;
10103#endif
10104#if defined(FEAT_CRYPT)
10105 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010106 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010107 break;
10108#endif
10109#ifdef FEAT_STL_OPT
10110 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010111 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010112 break;
10113#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010114 case PV_UL:
10115 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10116 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010117#ifdef FEAT_LISP
10118 case PV_LW:
10119 clear_string_option(&buf->b_p_lw);
10120 break;
10121#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010122 }
10123}
10124
10125/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010126 * Get pointer to option variable, depending on local or global scope.
10127 */
10128 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010129get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010130{
10131 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10132 {
10133 if (p->var == VAR_WIN)
10134 return (char_u *)GLOBAL_WO(get_varp(p));
10135 return p->var;
10136 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010137 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010138 {
10139 switch ((int)p->indir)
10140 {
10141#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010142 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10143 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10144 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010146 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10147 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10148 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010149 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010150 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010151 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010152#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010153 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10154 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010155#endif
10156#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010157 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10158 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010160#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10161 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10162#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010163#if defined(FEAT_CRYPT)
10164 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10165#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010166#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010167 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010168#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010169 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010170#ifdef FEAT_LISP
10171 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10172#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010173 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174 }
10175 return NULL; /* "cannot happen" */
10176 }
10177 return get_varp(p);
10178}
10179
10180/*
10181 * Get pointer to option variable.
10182 */
10183 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010184get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185{
10186 /* hidden option, always return NULL */
10187 if (p->var == NULL)
10188 return NULL;
10189
10190 switch ((int)p->indir)
10191 {
10192 case PV_NONE: return p->var;
10193
10194 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010195 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010197 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010199 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010201 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010203 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010205 case PV_TC: return *curbuf->b_p_tc != NUL
10206 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010207 case PV_BKC: return *curbuf->b_p_bkc != NUL
10208 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010209#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010210 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010212 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010213 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10214#endif
10215#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010216 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010217 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010218 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010219 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10220#endif
10221#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010222 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010223 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010224 case PV_GP: return *curbuf->b_p_gp != NUL
10225 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10226 case PV_MP: return *curbuf->b_p_mp != NUL
10227 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010229#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10230 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10231 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10232#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010233#if defined(FEAT_CRYPT)
10234 case PV_CM: return *curbuf->b_p_cm != NUL
10235 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10236#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010237#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010238 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010239 ? (char_u *)&(curwin->w_p_stl) : p->var;
10240#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010241 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10242 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010243#ifdef FEAT_LISP
10244 case PV_LW: return *curbuf->b_p_lw != NUL
10245 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10246#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247
10248#ifdef FEAT_ARABIC
10249 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10250#endif
10251 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010252#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010253 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10254#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010255#ifdef FEAT_SYN_HL
10256 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10257 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010258 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010259#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260#ifdef FEAT_DIFF
10261 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10262#endif
10263#ifdef FEAT_FOLDING
10264 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10265 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10266 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10267 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10268 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10269 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10270 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10271# ifdef FEAT_EVAL
10272 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10273 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10274# endif
10275 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10276#endif
10277 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010278 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010279#ifdef FEAT_LINEBREAK
10280 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10281#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010282#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010283 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10284#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010285#ifdef FEAT_VERTSPLIT
10286 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010288#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10289 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10290#endif
10291#ifdef FEAT_RIGHTLEFT
10292 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10293 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10294#endif
10295 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10296 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10297#ifdef FEAT_LINEBREAK
10298 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010299 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10300 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301#endif
10302#ifdef FEAT_SCROLLBIND
10303 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10304#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010305#ifdef FEAT_CURSORBIND
10306 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10307#endif
10308#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010309 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10310 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010311#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312
10313 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10314 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10315#ifdef FEAT_MBYTE
10316 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10317#endif
10318#if defined(FEAT_QUICKFIX)
10319 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10320 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10321#endif
10322 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10323 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10324#ifdef FEAT_CINDENT
10325 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10326 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10327 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10328#endif
10329#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10330 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10331#endif
10332#ifdef FEAT_COMMENTS
10333 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10334#endif
10335#ifdef FEAT_FOLDING
10336 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10337#endif
10338#ifdef FEAT_INS_EXPAND
10339 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10340#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010341#ifdef FEAT_COMPL_FUNC
10342 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010343 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010346 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010347 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10348#ifdef FEAT_MBYTE
10349 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10350#endif
10351 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10352#ifdef FEAT_AUTOCMD
10353 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10354#endif
10355 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010356 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10358 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10359 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10360 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10361#ifdef FEAT_FIND_ID
10362# ifdef FEAT_EVAL
10363 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10364# endif
10365#endif
10366#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10367 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10368 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10369#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010370#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010371 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010373#ifdef FEAT_CRYPT
10374 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10375#endif
10376#ifdef FEAT_LISP
10377 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10378#endif
10379 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10380 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10381 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10382 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10383 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010385#ifdef FEAT_TEXTOBJ
10386 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10389#ifdef FEAT_SMARTINDENT
10390 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10391#endif
10392#ifndef SHORT_FNAME
10393 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10394#endif
10395 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10396#ifdef FEAT_SEARCHPATH
10397 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10398#endif
10399 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10400#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010401 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010402 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10403#endif
10404#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010405 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10406 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10407 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408#endif
10409 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10410 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10411 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10412 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010413#ifdef FEAT_PERSISTENT_UNDO
10414 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10415#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010416 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10417#ifdef FEAT_KEYMAP
10418 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10419#endif
10420 default: EMSG(_("E356: get_varp ERROR"));
10421 }
10422 /* always return a valid pointer to avoid a crash! */
10423 return (char_u *)&(curbuf->b_p_wm);
10424}
10425
10426/*
10427 * Get the value of 'equalprg', either the buffer-local one or the global one.
10428 */
10429 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010430get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431{
10432 if (*curbuf->b_p_ep == NUL)
10433 return p_ep;
10434 return curbuf->b_p_ep;
10435}
10436
10437#if defined(FEAT_WINDOWS) || defined(PROTO)
10438/*
10439 * Copy options from one window to another.
10440 * Used when splitting a window.
10441 */
10442 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010443win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010444{
10445 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10446 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10447# ifdef FEAT_RIGHTLEFT
10448# ifdef FEAT_FKMAP
10449 /* Is this right? */
10450 wp_to->w_farsi = wp_from->w_farsi;
10451# endif
10452# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010453#if defined(FEAT_LINEBREAK)
10454 briopt_check(wp_to);
10455#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010456}
10457#endif
10458
10459/*
10460 * Copy the options from one winopt_T to another.
10461 * Doesn't free the old option values in "to", use clear_winopt() for that.
10462 * The 'scroll' option is not copied, because it depends on the window height.
10463 * The 'previewwindow' option is reset, there can be only one preview window.
10464 */
10465 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010466copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010467{
10468#ifdef FEAT_ARABIC
10469 to->wo_arab = from->wo_arab;
10470#endif
10471 to->wo_list = from->wo_list;
10472 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010473 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010474#ifdef FEAT_LINEBREAK
10475 to->wo_nuw = from->wo_nuw;
10476#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010477#ifdef FEAT_RIGHTLEFT
10478 to->wo_rl = from->wo_rl;
10479 to->wo_rlc = vim_strsave(from->wo_rlc);
10480#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010481#ifdef FEAT_STL_OPT
10482 to->wo_stl = vim_strsave(from->wo_stl);
10483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010484 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010485#ifdef FEAT_DIFF
10486 to->wo_wrap_save = from->wo_wrap_save;
10487#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010488#ifdef FEAT_LINEBREAK
10489 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010490 to->wo_bri = from->wo_bri;
10491 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010492#endif
10493#ifdef FEAT_SCROLLBIND
10494 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010495 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010496#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010497#ifdef FEAT_CURSORBIND
10498 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010499 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010500#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010501#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010502 to->wo_spell = from->wo_spell;
10503#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010504#ifdef FEAT_SYN_HL
10505 to->wo_cuc = from->wo_cuc;
10506 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010507 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010508#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010509#ifdef FEAT_DIFF
10510 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010511 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010513#ifdef FEAT_CONCEAL
10514 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010515 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010516#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010517#ifdef FEAT_FOLDING
10518 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010519 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010521 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010522 to->wo_fdi = vim_strsave(from->wo_fdi);
10523 to->wo_fml = from->wo_fml;
10524 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010525 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010527 to->wo_fdm_save = from->wo_diff_saved
10528 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529 to->wo_fdn = from->wo_fdn;
10530# ifdef FEAT_EVAL
10531 to->wo_fde = vim_strsave(from->wo_fde);
10532 to->wo_fdt = vim_strsave(from->wo_fdt);
10533# endif
10534 to->wo_fmr = vim_strsave(from->wo_fmr);
10535#endif
10536 check_winopt(to); /* don't want NULL pointers */
10537}
10538
10539/*
10540 * Check string options in a window for a NULL value.
10541 */
10542 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010543check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544{
10545 check_winopt(&win->w_onebuf_opt);
10546 check_winopt(&win->w_allbuf_opt);
10547}
10548
10549/*
10550 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10551 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010552 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010553check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554{
10555#ifdef FEAT_FOLDING
10556 check_string_option(&wop->wo_fdi);
10557 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010558 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010559# ifdef FEAT_EVAL
10560 check_string_option(&wop->wo_fde);
10561 check_string_option(&wop->wo_fdt);
10562# endif
10563 check_string_option(&wop->wo_fmr);
10564#endif
10565#ifdef FEAT_RIGHTLEFT
10566 check_string_option(&wop->wo_rlc);
10567#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010568#ifdef FEAT_STL_OPT
10569 check_string_option(&wop->wo_stl);
10570#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010571#ifdef FEAT_SYN_HL
10572 check_string_option(&wop->wo_cc);
10573#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010574#ifdef FEAT_CONCEAL
10575 check_string_option(&wop->wo_cocu);
10576#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010577#ifdef FEAT_LINEBREAK
10578 check_string_option(&wop->wo_briopt);
10579#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580}
10581
10582/*
10583 * Free the allocated memory inside a winopt_T.
10584 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010586clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587{
10588#ifdef FEAT_FOLDING
10589 clear_string_option(&wop->wo_fdi);
10590 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010591 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592# ifdef FEAT_EVAL
10593 clear_string_option(&wop->wo_fde);
10594 clear_string_option(&wop->wo_fdt);
10595# endif
10596 clear_string_option(&wop->wo_fmr);
10597#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010598#ifdef FEAT_LINEBREAK
10599 clear_string_option(&wop->wo_briopt);
10600#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601#ifdef FEAT_RIGHTLEFT
10602 clear_string_option(&wop->wo_rlc);
10603#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010604#ifdef FEAT_STL_OPT
10605 clear_string_option(&wop->wo_stl);
10606#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010607#ifdef FEAT_SYN_HL
10608 clear_string_option(&wop->wo_cc);
10609#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010610#ifdef FEAT_CONCEAL
10611 clear_string_option(&wop->wo_cocu);
10612#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010613}
10614
10615/*
10616 * Copy global option values to local options for one buffer.
10617 * Used when creating a new buffer and sometimes when entering a buffer.
10618 * flags:
10619 * BCO_ENTER We will enter the buf buffer.
10620 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10621 * appropriate.
10622 * BCO_NOHELP Don't copy the values to a help buffer.
10623 */
10624 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010625buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010626{
10627 int should_copy = TRUE;
10628 char_u *save_p_isk = NULL; /* init for GCC */
10629 int dont_do_help;
10630 int did_isk = FALSE;
10631
10632 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010633 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634 */
10635 if (buf == NULL || !buf_valid(buf))
10636 return;
10637
10638 /*
10639 * Skip this when the option defaults have not been set yet. Happens when
10640 * main() allocates the first buffer.
10641 */
10642 if (p_cpo != NULL)
10643 {
10644 /*
10645 * Always copy when entering and 'cpo' contains 'S'.
10646 * Don't copy when already initialized.
10647 * Don't copy when 'cpo' contains 's' and not entering.
10648 * 'S' BCO_ENTER initialized 's' should_copy
10649 * yes yes X X TRUE
10650 * yes no yes X FALSE
10651 * no X yes X FALSE
10652 * X no no yes FALSE
10653 * X no no no TRUE
10654 * no yes no X TRUE
10655 */
10656 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10657 && (buf->b_p_initialized
10658 || (!(flags & BCO_ENTER)
10659 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10660 should_copy = FALSE;
10661
10662 if (should_copy || (flags & BCO_ALWAYS))
10663 {
10664 /* Don't copy the options specific to a help buffer when
10665 * BCO_NOHELP is given or the options were initialized already
10666 * (jumping back to a help file with CTRL-T or CTRL-O) */
10667 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10668 || buf->b_p_initialized;
10669 if (dont_do_help) /* don't free b_p_isk */
10670 {
10671 save_p_isk = buf->b_p_isk;
10672 buf->b_p_isk = NULL;
10673 }
10674 /*
10675 * Always free the allocated strings.
10676 * If not already initialized, set 'readonly' and copy 'fileformat'.
10677 */
10678 if (!buf->b_p_initialized)
10679 {
10680 free_buf_options(buf, TRUE);
10681 buf->b_p_ro = FALSE; /* don't copy readonly */
10682 buf->b_p_tx = p_tx;
10683#ifdef FEAT_MBYTE
10684 buf->b_p_fenc = vim_strsave(p_fenc);
10685#endif
10686 buf->b_p_ff = vim_strsave(p_ff);
10687#if defined(FEAT_QUICKFIX)
10688 buf->b_p_bh = empty_option;
10689 buf->b_p_bt = empty_option;
10690#endif
10691 }
10692 else
10693 free_buf_options(buf, FALSE);
10694
10695 buf->b_p_ai = p_ai;
10696 buf->b_p_ai_nopaste = p_ai_nopaste;
10697 buf->b_p_sw = p_sw;
10698 buf->b_p_tw = p_tw;
10699 buf->b_p_tw_nopaste = p_tw_nopaste;
10700 buf->b_p_tw_nobin = p_tw_nobin;
10701 buf->b_p_wm = p_wm;
10702 buf->b_p_wm_nopaste = p_wm_nopaste;
10703 buf->b_p_wm_nobin = p_wm_nobin;
10704 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010705#ifdef FEAT_MBYTE
10706 buf->b_p_bomb = p_bomb;
10707#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010708 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709 buf->b_p_et = p_et;
10710 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010711 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010712 buf->b_p_ml = p_ml;
10713 buf->b_p_ml_nobin = p_ml_nobin;
10714 buf->b_p_inf = p_inf;
10715 buf->b_p_swf = p_swf;
10716#ifdef FEAT_INS_EXPAND
10717 buf->b_p_cpt = vim_strsave(p_cpt);
10718#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010719#ifdef FEAT_COMPL_FUNC
10720 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010721 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010722#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010723 buf->b_p_sts = p_sts;
10724 buf->b_p_sts_nopaste = p_sts_nopaste;
10725#ifndef SHORT_FNAME
10726 buf->b_p_sn = p_sn;
10727#endif
10728#ifdef FEAT_COMMENTS
10729 buf->b_p_com = vim_strsave(p_com);
10730#endif
10731#ifdef FEAT_FOLDING
10732 buf->b_p_cms = vim_strsave(p_cms);
10733#endif
10734 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010735 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010736 buf->b_p_nf = vim_strsave(p_nf);
10737 buf->b_p_mps = vim_strsave(p_mps);
10738#ifdef FEAT_SMARTINDENT
10739 buf->b_p_si = p_si;
10740#endif
10741 buf->b_p_ci = p_ci;
10742#ifdef FEAT_CINDENT
10743 buf->b_p_cin = p_cin;
10744 buf->b_p_cink = vim_strsave(p_cink);
10745 buf->b_p_cino = vim_strsave(p_cino);
10746#endif
10747#ifdef FEAT_AUTOCMD
10748 /* Don't copy 'filetype', it must be detected */
10749 buf->b_p_ft = empty_option;
10750#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751 buf->b_p_pi = p_pi;
10752#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10753 buf->b_p_cinw = vim_strsave(p_cinw);
10754#endif
10755#ifdef FEAT_LISP
10756 buf->b_p_lisp = p_lisp;
10757#endif
10758#ifdef FEAT_SYN_HL
10759 /* Don't copy 'syntax', it must be set */
10760 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010761 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010762 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010763#endif
10764#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010765 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010766 (void)compile_cap_prog(&buf->b_s);
10767 buf->b_s.b_p_spf = vim_strsave(p_spf);
10768 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010769#endif
10770#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10771 buf->b_p_inde = vim_strsave(p_inde);
10772 buf->b_p_indk = vim_strsave(p_indk);
10773#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010774#if defined(FEAT_EVAL)
10775 buf->b_p_fex = vim_strsave(p_fex);
10776#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777#ifdef FEAT_CRYPT
10778 buf->b_p_key = vim_strsave(p_key);
10779#endif
10780#ifdef FEAT_SEARCHPATH
10781 buf->b_p_sua = vim_strsave(p_sua);
10782#endif
10783#ifdef FEAT_KEYMAP
10784 buf->b_p_keymap = vim_strsave(p_keymap);
10785 buf->b_kmap_state |= KEYMAP_INIT;
10786#endif
10787 /* This isn't really an option, but copying the langmap and IME
10788 * state from the current buffer is better than resetting it. */
10789 buf->b_p_iminsert = p_iminsert;
10790 buf->b_p_imsearch = p_imsearch;
10791
10792 /* options that are normally global but also have a local value
10793 * are not copied, start using the global value */
10794 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010795 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010796 buf->b_p_bkc = empty_option;
10797 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798#ifdef FEAT_QUICKFIX
10799 buf->b_p_gp = empty_option;
10800 buf->b_p_mp = empty_option;
10801 buf->b_p_efm = empty_option;
10802#endif
10803 buf->b_p_ep = empty_option;
10804 buf->b_p_kp = empty_option;
10805 buf->b_p_path = empty_option;
10806 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010807 buf->b_p_tc = empty_option;
10808 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010809#ifdef FEAT_FIND_ID
10810 buf->b_p_def = empty_option;
10811 buf->b_p_inc = empty_option;
10812# ifdef FEAT_EVAL
10813 buf->b_p_inex = vim_strsave(p_inex);
10814# endif
10815#endif
10816#ifdef FEAT_INS_EXPAND
10817 buf->b_p_dict = empty_option;
10818 buf->b_p_tsr = empty_option;
10819#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010820#ifdef FEAT_TEXTOBJ
10821 buf->b_p_qe = vim_strsave(p_qe);
10822#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010823#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10824 buf->b_p_bexpr = empty_option;
10825#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010826#if defined(FEAT_CRYPT)
10827 buf->b_p_cm = empty_option;
10828#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010829#ifdef FEAT_PERSISTENT_UNDO
10830 buf->b_p_udf = p_udf;
10831#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010832#ifdef FEAT_LISP
10833 buf->b_p_lw = empty_option;
10834#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835
10836 /*
10837 * Don't copy the options set by ex_help(), use the saved values,
10838 * when going from a help buffer to a non-help buffer.
10839 * Don't touch these at all when BCO_NOHELP is used and going from
10840 * or to a help buffer.
10841 */
10842 if (dont_do_help)
10843 buf->b_p_isk = save_p_isk;
10844 else
10845 {
10846 buf->b_p_isk = vim_strsave(p_isk);
10847 did_isk = TRUE;
10848 buf->b_p_ts = p_ts;
10849 buf->b_help = FALSE;
10850#ifdef FEAT_QUICKFIX
10851 if (buf->b_p_bt[0] == 'h')
10852 clear_string_option(&buf->b_p_bt);
10853#endif
10854 buf->b_p_ma = p_ma;
10855 }
10856 }
10857
10858 /*
10859 * When the options should be copied (ignoring BCO_ALWAYS), set the
10860 * flag that indicates that the options have been initialized.
10861 */
10862 if (should_copy)
10863 buf->b_p_initialized = TRUE;
10864 }
10865
10866 check_buf_options(buf); /* make sure we don't have NULLs */
10867 if (did_isk)
10868 (void)buf_init_chartab(buf, FALSE);
10869}
10870
10871/*
10872 * Reset the 'modifiable' option and its default value.
10873 */
10874 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010875reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876{
10877 int opt_idx;
10878
10879 curbuf->b_p_ma = FALSE;
10880 p_ma = FALSE;
10881 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010882 if (opt_idx >= 0)
10883 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884}
10885
10886/*
10887 * Set the global value for 'iminsert' to the local value.
10888 */
10889 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010890set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891{
10892 p_iminsert = curbuf->b_p_iminsert;
10893}
10894
10895/*
10896 * Set the global value for 'imsearch' to the local value.
10897 */
10898 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010899set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900{
10901 p_imsearch = curbuf->b_p_imsearch;
10902}
10903
10904#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10905static int expand_option_idx = -1;
10906static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10907static int expand_option_flags = 0;
10908
10909 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010910set_context_in_set_cmd(
10911 expand_T *xp,
10912 char_u *arg,
10913 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914{
10915 int nextchar;
10916 long_u flags = 0; /* init for GCC */
10917 int opt_idx = 0; /* init for GCC */
10918 char_u *p;
10919 char_u *s;
10920 int is_term_option = FALSE;
10921 int key;
10922
10923 expand_option_flags = opt_flags;
10924
10925 xp->xp_context = EXPAND_SETTINGS;
10926 if (*arg == NUL)
10927 {
10928 xp->xp_pattern = arg;
10929 return;
10930 }
10931 p = arg + STRLEN(arg) - 1;
10932 if (*p == ' ' && *(p - 1) != '\\')
10933 {
10934 xp->xp_pattern = p + 1;
10935 return;
10936 }
10937 while (p > arg)
10938 {
10939 s = p;
10940 /* count number of backslashes before ' ' or ',' */
10941 if (*p == ' ' || *p == ',')
10942 {
10943 while (s > arg && *(s - 1) == '\\')
10944 --s;
10945 }
10946 /* break at a space with an even number of backslashes */
10947 if (*p == ' ' && ((p - s) & 1) == 0)
10948 {
10949 ++p;
10950 break;
10951 }
10952 --p;
10953 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010954 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010955 {
10956 xp->xp_context = EXPAND_BOOL_SETTINGS;
10957 p += 2;
10958 }
10959 if (STRNCMP(p, "inv", 3) == 0)
10960 {
10961 xp->xp_context = EXPAND_BOOL_SETTINGS;
10962 p += 3;
10963 }
10964 xp->xp_pattern = arg = p;
10965 if (*arg == '<')
10966 {
10967 while (*p != '>')
10968 if (*p++ == NUL) /* expand terminal option name */
10969 return;
10970 key = get_special_key_code(arg + 1);
10971 if (key == 0) /* unknown name */
10972 {
10973 xp->xp_context = EXPAND_NOTHING;
10974 return;
10975 }
10976 nextchar = *++p;
10977 is_term_option = TRUE;
10978 expand_option_name[2] = KEY2TERMCAP0(key);
10979 expand_option_name[3] = KEY2TERMCAP1(key);
10980 }
10981 else
10982 {
10983 if (p[0] == 't' && p[1] == '_')
10984 {
10985 p += 2;
10986 if (*p != NUL)
10987 ++p;
10988 if (*p == NUL)
10989 return; /* expand option name */
10990 nextchar = *++p;
10991 is_term_option = TRUE;
10992 expand_option_name[2] = p[-2];
10993 expand_option_name[3] = p[-1];
10994 }
10995 else
10996 {
10997 /* Allow * wildcard */
10998 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10999 p++;
11000 if (*p == NUL)
11001 return;
11002 nextchar = *p;
11003 *p = NUL;
11004 opt_idx = findoption(arg);
11005 *p = nextchar;
11006 if (opt_idx == -1 || options[opt_idx].var == NULL)
11007 {
11008 xp->xp_context = EXPAND_NOTHING;
11009 return;
11010 }
11011 flags = options[opt_idx].flags;
11012 if (flags & P_BOOL)
11013 {
11014 xp->xp_context = EXPAND_NOTHING;
11015 return;
11016 }
11017 }
11018 }
11019 /* handle "-=" and "+=" */
11020 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11021 {
11022 ++p;
11023 nextchar = '=';
11024 }
11025 if ((nextchar != '=' && nextchar != ':')
11026 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11027 {
11028 xp->xp_context = EXPAND_UNSUCCESSFUL;
11029 return;
11030 }
11031 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11032 {
11033 xp->xp_context = EXPAND_OLD_SETTING;
11034 if (is_term_option)
11035 expand_option_idx = -1;
11036 else
11037 expand_option_idx = opt_idx;
11038 xp->xp_pattern = p + 1;
11039 return;
11040 }
11041 xp->xp_context = EXPAND_NOTHING;
11042 if (is_term_option || (flags & P_NUM))
11043 return;
11044
11045 xp->xp_pattern = p + 1;
11046
11047 if (flags & P_EXPAND)
11048 {
11049 p = options[opt_idx].var;
11050 if (p == (char_u *)&p_bdir
11051 || p == (char_u *)&p_dir
11052 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011053 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054 || p == (char_u *)&p_rtp
11055#ifdef FEAT_SEARCHPATH
11056 || p == (char_u *)&p_cdpath
11057#endif
11058#ifdef FEAT_SESSION
11059 || p == (char_u *)&p_vdir
11060#endif
11061 )
11062 {
11063 xp->xp_context = EXPAND_DIRECTORIES;
11064 if (p == (char_u *)&p_path
11065#ifdef FEAT_SEARCHPATH
11066 || p == (char_u *)&p_cdpath
11067#endif
11068 )
11069 xp->xp_backslash = XP_BS_THREE;
11070 else
11071 xp->xp_backslash = XP_BS_ONE;
11072 }
11073 else
11074 {
11075 xp->xp_context = EXPAND_FILES;
11076 /* for 'tags' need three backslashes for a space */
11077 if (p == (char_u *)&p_tags)
11078 xp->xp_backslash = XP_BS_THREE;
11079 else
11080 xp->xp_backslash = XP_BS_ONE;
11081 }
11082 }
11083
11084 /* For an option that is a list of file names, find the start of the
11085 * last file name. */
11086 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11087 {
11088 /* count number of backslashes before ' ' or ',' */
11089 if (*p == ' ' || *p == ',')
11090 {
11091 s = p;
11092 while (s > xp->xp_pattern && *(s - 1) == '\\')
11093 --s;
11094 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11095 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11096 {
11097 xp->xp_pattern = p + 1;
11098 break;
11099 }
11100 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011101
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011102#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011103 /* for 'spellsuggest' start at "file:" */
11104 if (options[opt_idx].var == (char_u *)&p_sps
11105 && STRNCMP(p, "file:", 5) == 0)
11106 {
11107 xp->xp_pattern = p + 5;
11108 break;
11109 }
11110#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011111 }
11112
11113 return;
11114}
11115
11116 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011117ExpandSettings(
11118 expand_T *xp,
11119 regmatch_T *regmatch,
11120 int *num_file,
11121 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122{
11123 int num_normal = 0; /* Nr of matching non-term-code settings */
11124 int num_term = 0; /* Nr of matching terminal code settings */
11125 int opt_idx;
11126 int match;
11127 int count = 0;
11128 char_u *str;
11129 int loop;
11130 int is_term_opt;
11131 char_u name_buf[MAX_KEY_NAME_LEN];
11132 static char *(names[]) = {"all", "termcap"};
11133 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11134
11135 /* do this loop twice:
11136 * loop == 0: count the number of matching options
11137 * loop == 1: copy the matching options into allocated memory
11138 */
11139 for (loop = 0; loop <= 1; ++loop)
11140 {
11141 regmatch->rm_ic = ic;
11142 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11143 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011144 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11145 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011146 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11147 {
11148 if (loop == 0)
11149 num_normal++;
11150 else
11151 (*file)[count++] = vim_strsave((char_u *)names[match]);
11152 }
11153 }
11154 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11155 opt_idx++)
11156 {
11157 if (options[opt_idx].var == NULL)
11158 continue;
11159 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11160 && !(options[opt_idx].flags & P_BOOL))
11161 continue;
11162 is_term_opt = istermoption(&options[opt_idx]);
11163 if (is_term_opt && num_normal > 0)
11164 continue;
11165 match = FALSE;
11166 if (vim_regexec(regmatch, str, (colnr_T)0)
11167 || (options[opt_idx].shortname != NULL
11168 && vim_regexec(regmatch,
11169 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11170 match = TRUE;
11171 else if (is_term_opt)
11172 {
11173 name_buf[0] = '<';
11174 name_buf[1] = 't';
11175 name_buf[2] = '_';
11176 name_buf[3] = str[2];
11177 name_buf[4] = str[3];
11178 name_buf[5] = '>';
11179 name_buf[6] = NUL;
11180 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11181 {
11182 match = TRUE;
11183 str = name_buf;
11184 }
11185 }
11186 if (match)
11187 {
11188 if (loop == 0)
11189 {
11190 if (is_term_opt)
11191 num_term++;
11192 else
11193 num_normal++;
11194 }
11195 else
11196 (*file)[count++] = vim_strsave(str);
11197 }
11198 }
11199 /*
11200 * Check terminal key codes, these are not in the option table
11201 */
11202 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11203 {
11204 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11205 {
11206 if (!isprint(str[0]) || !isprint(str[1]))
11207 continue;
11208
11209 name_buf[0] = 't';
11210 name_buf[1] = '_';
11211 name_buf[2] = str[0];
11212 name_buf[3] = str[1];
11213 name_buf[4] = NUL;
11214
11215 match = FALSE;
11216 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11217 match = TRUE;
11218 else
11219 {
11220 name_buf[0] = '<';
11221 name_buf[1] = 't';
11222 name_buf[2] = '_';
11223 name_buf[3] = str[0];
11224 name_buf[4] = str[1];
11225 name_buf[5] = '>';
11226 name_buf[6] = NUL;
11227
11228 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11229 match = TRUE;
11230 }
11231 if (match)
11232 {
11233 if (loop == 0)
11234 num_term++;
11235 else
11236 (*file)[count++] = vim_strsave(name_buf);
11237 }
11238 }
11239
11240 /*
11241 * Check special key names.
11242 */
11243 regmatch->rm_ic = TRUE; /* ignore case here */
11244 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11245 {
11246 name_buf[0] = '<';
11247 STRCPY(name_buf + 1, str);
11248 STRCAT(name_buf, ">");
11249
11250 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11251 {
11252 if (loop == 0)
11253 num_term++;
11254 else
11255 (*file)[count++] = vim_strsave(name_buf);
11256 }
11257 }
11258 }
11259 if (loop == 0)
11260 {
11261 if (num_normal > 0)
11262 *num_file = num_normal;
11263 else if (num_term > 0)
11264 *num_file = num_term;
11265 else
11266 return OK;
11267 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11268 if (*file == NULL)
11269 {
11270 *file = (char_u **)"";
11271 return FAIL;
11272 }
11273 }
11274 }
11275 return OK;
11276}
11277
11278 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011279ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011280{
11281 char_u *var = NULL; /* init for GCC */
11282 char_u *buf;
11283
11284 *num_file = 0;
11285 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11286 if (*file == NULL)
11287 return FAIL;
11288
11289 /*
11290 * For a terminal key code expand_option_idx is < 0.
11291 */
11292 if (expand_option_idx < 0)
11293 {
11294 var = find_termcode(expand_option_name + 2);
11295 if (var == NULL)
11296 expand_option_idx = findoption(expand_option_name);
11297 }
11298
11299 if (expand_option_idx >= 0)
11300 {
11301 /* put string of option value in NameBuff */
11302 option_value2string(&options[expand_option_idx], expand_option_flags);
11303 var = NameBuff;
11304 }
11305 else if (var == NULL)
11306 var = (char_u *)"";
11307
11308 /* A backslash is required before some characters. This is the reverse of
11309 * what happens in do_set(). */
11310 buf = vim_strsave_escaped(var, escape_chars);
11311
11312 if (buf == NULL)
11313 {
11314 vim_free(*file);
11315 *file = NULL;
11316 return FAIL;
11317 }
11318
11319#ifdef BACKSLASH_IN_FILENAME
11320 /* For MS-Windows et al. we don't double backslashes at the start and
11321 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011322 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323 if (var[0] == '\\' && var[1] == '\\'
11324 && expand_option_idx >= 0
11325 && (options[expand_option_idx].flags & P_EXPAND)
11326 && vim_isfilec(var[2])
11327 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011328 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011329#endif
11330
11331 *file[0] = buf;
11332 *num_file = 1;
11333 return OK;
11334}
11335#endif
11336
11337/*
11338 * Get the value for the numeric or string option *opp in a nice format into
11339 * NameBuff[]. Must not be called with a hidden option!
11340 */
11341 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011342option_value2string(
11343 struct vimoption *opp,
11344 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011345{
11346 char_u *varp;
11347
11348 varp = get_varp_scope(opp, opt_flags);
11349
11350 if (opp->flags & P_NUM)
11351 {
11352 long wc = 0;
11353
11354 if (wc_use_keyname(varp, &wc))
11355 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11356 else if (wc != 0)
11357 STRCPY(NameBuff, transchar((int)wc));
11358 else
11359 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11360 }
11361 else /* P_STRING */
11362 {
11363 varp = *(char_u **)(varp);
11364 if (varp == NULL) /* just in case */
11365 NameBuff[0] = NUL;
11366#ifdef FEAT_CRYPT
11367 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011368 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011369 STRCPY(NameBuff, "*****");
11370#endif
11371 else if (opp->flags & P_EXPAND)
11372 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11373 /* Translate 'pastetoggle' into special key names */
11374 else if ((char_u **)opp->var == &p_pt)
11375 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11376 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011377 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011378 }
11379}
11380
11381/*
11382 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11383 * printed as a keyname.
11384 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11385 */
11386 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011387wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388{
11389 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11390 {
11391 *wcp = *(long *)varp;
11392 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11393 return TRUE;
11394 }
11395 return FALSE;
11396}
11397
Bram Moolenaar01615492015-02-03 13:00:38 +010011398#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011399/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011400 * Any character has an equivalent 'langmap' character. This is used for
11401 * keyboards that have a special language mode that sends characters above
11402 * 128 (although other characters can be translated too). The "to" field is a
11403 * Vim command character. This avoids having to switch the keyboard back to
11404 * ASCII mode when leaving Insert mode.
11405 *
11406 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11407 * commands.
11408 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11409 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11410 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011411 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011412# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011413/*
11414 * With multi-byte support use growarray for 'langmap' chars >= 256
11415 */
11416typedef struct
11417{
11418 int from;
11419 int to;
11420} langmap_entry_T;
11421
11422static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011423static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011424
11425/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011426 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11427 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011428 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011429 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011430langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011431{
11432 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011433 int a = 0;
11434 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011435
11436 /* Do a binary search for an existing entry. */
11437 while (a != b)
11438 {
11439 int i = (a + b) / 2;
11440 int d = entries[i].from - from;
11441
11442 if (d == 0)
11443 {
11444 entries[i].to = to;
11445 return;
11446 }
11447 if (d < 0)
11448 a = i + 1;
11449 else
11450 b = i;
11451 }
11452
11453 if (ga_grow(&langmap_mapga, 1) != OK)
11454 return; /* out of memory */
11455
11456 /* insert new entry at position "a" */
11457 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11458 mch_memmove(entries + 1, entries,
11459 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11460 ++langmap_mapga.ga_len;
11461 entries[0].from = from;
11462 entries[0].to = to;
11463}
11464
11465/*
11466 * Apply 'langmap' to multi-byte character "c" and return the result.
11467 */
11468 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011469langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011470{
11471 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11472 int a = 0;
11473 int b = langmap_mapga.ga_len;
11474
11475 while (a != b)
11476 {
11477 int i = (a + b) / 2;
11478 int d = entries[i].from - c;
11479
11480 if (d == 0)
11481 return entries[i].to; /* found matching entry */
11482 if (d < 0)
11483 a = i + 1;
11484 else
11485 b = i;
11486 }
11487 return c; /* no entry found, return "c" unmodified */
11488}
11489# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011490
11491 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011492langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011493{
11494 int i;
11495
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011496 for (i = 0; i < 256; i++)
11497 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11498# ifdef FEAT_MBYTE
11499 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11500# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011501}
11502
11503/*
11504 * Called when langmap option is set; the language map can be
11505 * changed at any time!
11506 */
11507 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011508langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011509{
11510 char_u *p;
11511 char_u *p2;
11512 int from, to;
11513
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011514#ifdef FEAT_MBYTE
11515 ga_clear(&langmap_mapga); /* clear the previous map first */
11516#endif
11517 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011518
11519 for (p = p_langmap; p[0] != NUL; )
11520 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011521 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11522 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011523 {
11524 if (p2[0] == '\\' && p2[1] != NUL)
11525 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526 }
11527 if (p2[0] == ';')
11528 ++p2; /* abcd;ABCD form, p2 points to A */
11529 else
11530 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11531 while (p[0])
11532 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011533 if (p[0] == ',')
11534 {
11535 ++p;
11536 break;
11537 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011538 if (p[0] == '\\' && p[1] != NUL)
11539 ++p;
11540#ifdef FEAT_MBYTE
11541 from = (*mb_ptr2char)(p);
11542#else
11543 from = p[0];
11544#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011545 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546 if (p2 == NULL)
11547 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011548 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011549 if (p[0] != ',')
11550 {
11551 if (p[0] == '\\')
11552 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011553#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011554 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011556 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011557#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011558 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011559 }
11560 else
11561 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011562 if (p2[0] != ',')
11563 {
11564 if (p2[0] == '\\')
11565 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011566#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011567 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011568#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011569 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011570#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011571 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011572 }
11573 if (to == NUL)
11574 {
11575 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11576 transchar(from));
11577 return;
11578 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011579
11580#ifdef FEAT_MBYTE
11581 if (from >= 256)
11582 langmap_set_entry(from, to);
11583 else
11584#endif
11585 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011586
11587 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011588 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011589 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011590 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011591 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011592 if (*p == ';')
11593 {
11594 p = p2;
11595 if (p[0] != NUL)
11596 {
11597 if (p[0] != ',')
11598 {
11599 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11600 return;
11601 }
11602 ++p;
11603 }
11604 break;
11605 }
11606 }
11607 }
11608 }
11609}
11610#endif
11611
11612/*
11613 * Return TRUE if format option 'x' is in effect.
11614 * Take care of no formatting when 'paste' is set.
11615 */
11616 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011617has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011618{
11619 if (p_paste)
11620 return FALSE;
11621 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11622}
11623
11624/*
11625 * Return TRUE if "x" is present in 'shortmess' option, or
11626 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11627 */
11628 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011629shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011630{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011631 return p_shm != NULL &&
11632 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633 || (vim_strchr(p_shm, 'a') != NULL
11634 && vim_strchr((char_u *)SHM_A, x) != NULL));
11635}
11636
11637/*
11638 * paste_option_changed() - Called after p_paste was set or reset.
11639 */
11640 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011641paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011642{
11643 static int old_p_paste = FALSE;
11644 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011645 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011646#ifdef FEAT_CMDL_INFO
11647 static int save_ru = 0;
11648#endif
11649#ifdef FEAT_RIGHTLEFT
11650 static int save_ri = 0;
11651 static int save_hkmap = 0;
11652#endif
11653 buf_T *buf;
11654
11655 if (p_paste)
11656 {
11657 /*
11658 * Paste switched from off to on.
11659 * Save the current values, so they can be restored later.
11660 */
11661 if (!old_p_paste)
11662 {
11663 /* save options for each buffer */
11664 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11665 {
11666 buf->b_p_tw_nopaste = buf->b_p_tw;
11667 buf->b_p_wm_nopaste = buf->b_p_wm;
11668 buf->b_p_sts_nopaste = buf->b_p_sts;
11669 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011670 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011671 }
11672
11673 /* save global options */
11674 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011675 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011676#ifdef FEAT_CMDL_INFO
11677 save_ru = p_ru;
11678#endif
11679#ifdef FEAT_RIGHTLEFT
11680 save_ri = p_ri;
11681 save_hkmap = p_hkmap;
11682#endif
11683 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011684 p_ai_nopaste = p_ai;
11685 p_et_nopaste = p_et;
11686 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011687 p_tw_nopaste = p_tw;
11688 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689 }
11690
11691 /*
11692 * Always set the option values, also when 'paste' is set when it is
11693 * already on.
11694 */
11695 /* set options for each buffer */
11696 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11697 {
11698 buf->b_p_tw = 0; /* textwidth is 0 */
11699 buf->b_p_wm = 0; /* wrapmargin is 0 */
11700 buf->b_p_sts = 0; /* softtabstop is 0 */
11701 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011702 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011703 }
11704
11705 /* set global options */
11706 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011707 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011708#ifdef FEAT_CMDL_INFO
11709# ifdef FEAT_WINDOWS
11710 if (p_ru)
11711 status_redraw_all(); /* redraw to remove the ruler */
11712# endif
11713 p_ru = 0; /* no ruler */
11714#endif
11715#ifdef FEAT_RIGHTLEFT
11716 p_ri = 0; /* no reverse insert */
11717 p_hkmap = 0; /* no Hebrew keyboard */
11718#endif
11719 /* set global values for local buffer options */
11720 p_tw = 0;
11721 p_wm = 0;
11722 p_sts = 0;
11723 p_ai = 0;
11724 }
11725
11726 /*
11727 * Paste switched from on to off: Restore saved values.
11728 */
11729 else if (old_p_paste)
11730 {
11731 /* restore options for each buffer */
11732 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11733 {
11734 buf->b_p_tw = buf->b_p_tw_nopaste;
11735 buf->b_p_wm = buf->b_p_wm_nopaste;
11736 buf->b_p_sts = buf->b_p_sts_nopaste;
11737 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011738 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011739 }
11740
11741 /* restore global options */
11742 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011743 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011744#ifdef FEAT_CMDL_INFO
11745# ifdef FEAT_WINDOWS
11746 if (p_ru != save_ru)
11747 status_redraw_all(); /* redraw to draw the ruler */
11748# endif
11749 p_ru = save_ru;
11750#endif
11751#ifdef FEAT_RIGHTLEFT
11752 p_ri = save_ri;
11753 p_hkmap = save_hkmap;
11754#endif
11755 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011756 p_ai = p_ai_nopaste;
11757 p_et = p_et_nopaste;
11758 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011759 p_tw = p_tw_nopaste;
11760 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 }
11762
11763 old_p_paste = p_paste;
11764}
11765
11766/*
11767 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11768 *
11769 * Reset 'compatible' and set the values for options that didn't get set yet
11770 * to the Vim defaults.
11771 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011772 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011773 */
11774 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011775vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011777 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011778 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011779 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011780
11781 if (!option_was_set((char_u *)"cp"))
11782 {
11783 p_cp = FALSE;
11784 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11785 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11786 set_option_default(opt_idx, OPT_FREE, FALSE);
11787 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011788 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011789 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011790
11791 if (fname != NULL)
11792 {
11793 p = vim_getenv(envname, &dofree);
11794 if (p == NULL)
11795 {
11796 /* Set $MYVIMRC to the first vimrc file found. */
11797 p = FullName_save(fname, FALSE);
11798 if (p != NULL)
11799 {
11800 vim_setenv(envname, p);
11801 vim_free(p);
11802 }
11803 }
11804 else if (dofree)
11805 vim_free(p);
11806 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807}
11808
11809/*
11810 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11811 */
11812 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011813change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011814{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011815 int opt_idx;
11816
Bram Moolenaar071d4272004-06-13 20:20:40 +000011817 if (p_cp != on)
11818 {
11819 p_cp = on;
11820 compatible_set();
11821 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011822 opt_idx = findoption((char_u *)"cp");
11823 if (opt_idx >= 0)
11824 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011825}
11826
11827/*
11828 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011829 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011830 */
11831 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011832option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011833{
11834 int idx;
11835
11836 idx = findoption(name);
11837 if (idx < 0) /* unknown option */
11838 return FALSE;
11839 if (options[idx].flags & P_WAS_SET)
11840 return TRUE;
11841 return FALSE;
11842}
11843
11844/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011845 * Reset the flag indicating option "name" was set.
11846 */
11847 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011848reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011849{
11850 int idx = findoption(name);
11851
11852 if (idx >= 0)
11853 options[idx].flags &= ~P_WAS_SET;
11854}
11855
11856/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011857 * compatible_set() - Called when 'compatible' has been set or unset.
11858 *
11859 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11860 * flag) to a Vi compatible value.
11861 * When 'compatible' is unset: Set all options that have a different default
11862 * for Vim (without the P_VI_DEF flag) to that default.
11863 */
11864 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011865compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011866{
11867 int opt_idx;
11868
11869 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11870 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11871 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11872 set_option_default(opt_idx, OPT_FREE, p_cp);
11873 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011874 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011875}
11876
11877#ifdef FEAT_LINEBREAK
11878
11879# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11880 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011881 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011882# endif
11883
11884/*
11885 * fill_breakat_flags() -- called when 'breakat' changes value.
11886 */
11887 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011888fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011890 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011891 int i;
11892
11893 for (i = 0; i < 256; i++)
11894 breakat_flags[i] = FALSE;
11895
11896 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011897 for (p = p_breakat; *p; p++)
11898 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011899}
11900
11901# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011902 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011903# endif
11904
11905#endif
11906
11907/*
11908 * Check an option that can be a range of string values.
11909 *
11910 * Return OK for correct value, FAIL otherwise.
11911 * Empty is always OK.
11912 */
11913 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011914check_opt_strings(
11915 char_u *val,
11916 char **values,
11917 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011918{
11919 return opt_strings_flags(val, values, NULL, list);
11920}
11921
11922/*
11923 * Handle an option that can be a range of string values.
11924 * Set a flag in "*flagp" for each string present.
11925 *
11926 * Return OK for correct value, FAIL otherwise.
11927 * Empty is always OK.
11928 */
11929 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011930opt_strings_flags(
11931 char_u *val, /* new value */
11932 char **values, /* array of valid string values */
11933 unsigned *flagp,
11934 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011935{
11936 int i;
11937 int len;
11938 unsigned new_flags = 0;
11939
11940 while (*val)
11941 {
11942 for (i = 0; ; ++i)
11943 {
11944 if (values[i] == NULL) /* val not found in values[] */
11945 return FAIL;
11946
11947 len = (int)STRLEN(values[i]);
11948 if (STRNCMP(values[i], val, len) == 0
11949 && ((list && val[len] == ',') || val[len] == NUL))
11950 {
11951 val += len + (val[len] == ',');
11952 new_flags |= (1 << i);
11953 break; /* check next item in val list */
11954 }
11955 }
11956 }
11957 if (flagp != NULL)
11958 *flagp = new_flags;
11959
11960 return OK;
11961}
11962
11963/*
11964 * Read the 'wildmode' option, fill wim_flags[].
11965 */
11966 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011967check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011968{
11969 char_u new_wim_flags[4];
11970 char_u *p;
11971 int i;
11972 int idx = 0;
11973
11974 for (i = 0; i < 4; ++i)
11975 new_wim_flags[i] = 0;
11976
11977 for (p = p_wim; *p; ++p)
11978 {
11979 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11980 ;
11981 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11982 return FAIL;
11983 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11984 new_wim_flags[idx] |= WIM_LONGEST;
11985 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11986 new_wim_flags[idx] |= WIM_FULL;
11987 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11988 new_wim_flags[idx] |= WIM_LIST;
11989 else
11990 return FAIL;
11991 p += i;
11992 if (*p == NUL)
11993 break;
11994 if (*p == ',')
11995 {
11996 if (idx == 3)
11997 return FAIL;
11998 ++idx;
11999 }
12000 }
12001
12002 /* fill remaining entries with last flag */
12003 while (idx < 3)
12004 {
12005 new_wim_flags[idx + 1] = new_wim_flags[idx];
12006 ++idx;
12007 }
12008
12009 /* only when there are no errors, wim_flags[] is changed */
12010 for (i = 0; i < 4; ++i)
12011 wim_flags[i] = new_wim_flags[i];
12012 return OK;
12013}
12014
12015/*
12016 * Check if backspacing over something is allowed.
12017 */
12018 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012019can_bs(
12020 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012021{
12022 switch (*p_bs)
12023 {
12024 case '2': return TRUE;
12025 case '1': return (what != BS_START);
12026 case '0': return FALSE;
12027 }
12028 return vim_strchr(p_bs, what) != NULL;
12029}
12030
12031/*
12032 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12033 * the file must be considered changed when the value is different.
12034 */
12035 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012036save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012037{
12038 buf->b_start_ffc = *buf->b_p_ff;
12039 buf->b_start_eol = buf->b_p_eol;
12040#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012041 buf->b_start_bomb = buf->b_p_bomb;
12042
Bram Moolenaar071d4272004-06-13 20:20:40 +000012043 /* Only use free/alloc when necessary, they take time. */
12044 if (buf->b_start_fenc == NULL
12045 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12046 {
12047 vim_free(buf->b_start_fenc);
12048 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12049 }
12050#endif
12051}
12052
12053/*
12054 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12055 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012056 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12057 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012058 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012059 * When "ignore_empty" is true don't consider a new, empty buffer to be
12060 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012061 */
12062 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012063file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012064{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012065 /* In a buffer that was never loaded the options are not valid. */
12066 if (buf->b_flags & BF_NEVERLOADED)
12067 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012068 if (ignore_empty
12069 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070 && buf->b_ml.ml_line_count == 1
12071 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12072 return FALSE;
12073 if (buf->b_start_ffc != *buf->b_p_ff)
12074 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012075 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012076 return TRUE;
12077#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012078 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12079 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012080 if (buf->b_start_fenc == NULL)
12081 return (*buf->b_p_fenc != NUL);
12082 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12083#else
12084 return FALSE;
12085#endif
12086}
12087
12088/*
12089 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12090 */
12091 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012092check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012093{
12094 return check_opt_strings(p, p_ff_values, FALSE);
12095}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012096
12097/*
12098 * Return the effective shiftwidth value for current buffer, using the
12099 * 'tabstop' value when 'shiftwidth' is zero.
12100 */
12101 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012102get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012103{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012104 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012105}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012106
12107/*
12108 * Return the effective softtabstop value for the current buffer, using the
12109 * 'tabstop' value when 'softtabstop' is negative.
12110 */
12111 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012112get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012113{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012114 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012115}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012116
12117/*
12118 * Check matchpairs option for "*initc".
12119 * If there is a match set "*initc" to the matching character and "*findc" to
12120 * the opposite character. Set "*backwards" to the direction.
12121 * When "switchit" is TRUE swap the direction.
12122 */
12123 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012124find_mps_values(
12125 int *initc,
12126 int *findc,
12127 int *backwards,
12128 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012129{
12130 char_u *ptr;
12131
12132 ptr = curbuf->b_p_mps;
12133 while (*ptr != NUL)
12134 {
12135#ifdef FEAT_MBYTE
12136 if (has_mbyte)
12137 {
12138 char_u *prev;
12139
12140 if (mb_ptr2char(ptr) == *initc)
12141 {
12142 if (switchit)
12143 {
12144 *findc = *initc;
12145 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12146 *backwards = TRUE;
12147 }
12148 else
12149 {
12150 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12151 *backwards = FALSE;
12152 }
12153 return;
12154 }
12155 prev = ptr;
12156 ptr += mb_ptr2len(ptr) + 1;
12157 if (mb_ptr2char(ptr) == *initc)
12158 {
12159 if (switchit)
12160 {
12161 *findc = *initc;
12162 *initc = mb_ptr2char(prev);
12163 *backwards = FALSE;
12164 }
12165 else
12166 {
12167 *findc = mb_ptr2char(prev);
12168 *backwards = TRUE;
12169 }
12170 return;
12171 }
12172 ptr += mb_ptr2len(ptr);
12173 }
12174 else
12175#endif
12176 {
12177 if (*ptr == *initc)
12178 {
12179 if (switchit)
12180 {
12181 *backwards = TRUE;
12182 *findc = *initc;
12183 *initc = ptr[2];
12184 }
12185 else
12186 {
12187 *backwards = FALSE;
12188 *findc = ptr[2];
12189 }
12190 return;
12191 }
12192 ptr += 2;
12193 if (*ptr == *initc)
12194 {
12195 if (switchit)
12196 {
12197 *backwards = FALSE;
12198 *findc = *initc;
12199 *initc = ptr[-2];
12200 }
12201 else
12202 {
12203 *backwards = TRUE;
12204 *findc = ptr[-2];
12205 }
12206 return;
12207 }
12208 ++ptr;
12209 }
12210 if (*ptr == ',')
12211 ++ptr;
12212 }
12213}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012214
12215#if defined(FEAT_LINEBREAK) || defined(PROTO)
12216/*
12217 * This is called when 'breakindentopt' is changed and when a window is
12218 * initialized.
12219 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012220 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012221briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012222{
12223 char_u *p;
12224 int bri_shift = 0;
12225 long bri_min = 20;
12226 int bri_sbr = FALSE;
12227
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012228 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012229 while (*p != NUL)
12230 {
12231 if (STRNCMP(p, "shift:", 6) == 0
12232 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12233 {
12234 p += 6;
12235 bri_shift = getdigits(&p);
12236 }
12237 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12238 {
12239 p += 4;
12240 bri_min = getdigits(&p);
12241 }
12242 else if (STRNCMP(p, "sbr", 3) == 0)
12243 {
12244 p += 3;
12245 bri_sbr = TRUE;
12246 }
12247 if (*p != ',' && *p != NUL)
12248 return FAIL;
12249 if (*p == ',')
12250 ++p;
12251 }
12252
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012253 wp->w_p_brishift = bri_shift;
12254 wp->w_p_brimin = bri_min;
12255 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012256
12257 return OK;
12258}
12259#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012260
12261/*
12262 * Get the local or global value of 'backupcopy'.
12263 */
12264 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012265get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012266{
12267 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12268}