blob: bc88d455474e5d783f589d52ac21b602ada1f4cb [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 */
491static struct vimoption
492#ifdef FEAT_GUI_W16
493 _far
494#endif
495 options[] =
496{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200497 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498#ifdef FEAT_RIGHTLEFT
499 (char_u *)&p_aleph, PV_NONE,
500#else
501 (char_u *)NULL, PV_NONE,
502#endif
503 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100504#if (defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505 (char_u *)128L,
506#else
507 (char_u *)224L,
508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000509 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
511#if defined(FEAT_GUI) && defined(MACOS_X)
512 (char_u *)&p_antialias, PV_NONE,
513 {(char_u *)FALSE, (char_u *)FALSE}
514#else
515 (char_u *)NULL, PV_NONE,
516 {(char_u *)FALSE, (char_u *)FALSE}
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200519 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520#ifdef FEAT_ARABIC
521 (char_u *)VAR_WIN, PV_ARAB,
522#else
523 (char_u *)NULL, PV_NONE,
524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000525 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
527#ifdef FEAT_ARABIC
528 (char_u *)&p_arshape, PV_NONE,
529#else
530 (char_u *)NULL, PV_NONE,
531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000532 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
534#ifdef FEAT_RIGHTLEFT
535 (char_u *)&p_ari, PV_NONE,
536#else
537 (char_u *)NULL, PV_NONE,
538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000540 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
541#ifdef FEAT_FKMAP
542 (char_u *)&p_altkeymap, PV_NONE,
543#else
544 (char_u *)NULL, PV_NONE,
545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
548#if defined(FEAT_MBYTE)
549 (char_u *)&p_ambw, PV_NONE,
550 {(char_u *)"single", (char_u *)0L}
551#else
552 (char_u *)NULL, PV_NONE,
553 {(char_u *)0L, (char_u *)0L}
554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000556#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autochdir", "acd", P_BOOL|P_VI_DEF,
558 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560#endif
561 {"autoindent", "ai", P_BOOL|P_VI_DEF,
562 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564 {"autoprint", "ap", P_BOOL|P_VI_DEF,
565 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000568 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autowrite", "aw", P_BOOL|P_VI_DEF,
571 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autowriteall","awa", P_BOOL|P_VI_DEF,
574 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
577 (char_u *)&p_bg, PV_NONE,
578 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100579#if (defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 (char_u *)"dark",
581#else
582 (char_u *)"light",
583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000584 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200585 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000587 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
589 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200592 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593#ifdef UNIX
594 {(char_u *)"yes", (char_u *)"auto"}
595#else
596 {(char_u *)"auto", (char_u *)"auto"}
597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000598 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200599 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
600 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000602 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000603 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 (char_u *)&p_bex, PV_NONE,
605 {
606#ifdef VMS
607 (char_u *)"_",
608#else
609 (char_u *)"~",
610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000611 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200612 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613#ifdef FEAT_WILDIGN
614 (char_u *)&p_bsk, PV_NONE,
615 {(char_u *)"", (char_u *)0L}
616#else
617 (char_u *)NULL, PV_NONE,
618 {(char_u *)0L, (char_u *)0L}
619#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621#ifdef FEAT_BEVAL
622 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
623 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
626 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000628# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000629 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000630 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000632# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633#endif
634 {"beautify", "bf", P_BOOL|P_VI_DEF,
635 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200637 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
638 (char_u *)&p_bo, PV_NONE,
639 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
641 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000642 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000643 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
644#ifdef MSDOS
645 (char_u *)&p_biosk, PV_NONE,
646#else
647 (char_u *)NULL, PV_NONE,
648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000650 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
651#ifdef FEAT_MBYTE
652 (char_u *)&p_bomb, PV_BOMB,
653#else
654 (char_u *)NULL, PV_NONE,
655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000656 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000657 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
658#ifdef FEAT_LINEBREAK
659 (char_u *)&p_breakat, PV_NONE,
660 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
661#else
662 (char_u *)NULL, PV_NONE,
663 {(char_u *)0L, (char_u *)0L}
664#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200666 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
667#ifdef FEAT_LINEBREAK
668 (char_u *)VAR_WIN, PV_BRI,
669 {(char_u *)FALSE, (char_u *)0L}
670#else
671 (char_u *)NULL, PV_NONE,
672 {(char_u *)0L, (char_u *)0L}
673#endif
674 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200675 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
676 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200677#ifdef FEAT_LINEBREAK
678 (char_u *)VAR_WIN, PV_BRIOPT,
679 {(char_u *)"", (char_u *)NULL}
680#else
681 (char_u *)NULL, PV_NONE,
682 {(char_u *)"", (char_u *)NULL}
683#endif
684 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000685 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
686#ifdef FEAT_BROWSE
687 (char_u *)&p_bsdir, PV_NONE,
688 {(char_u *)"last", (char_u *)0L}
689#else
690 (char_u *)NULL, PV_NONE,
691 {(char_u *)0L, (char_u *)0L}
692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000693 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000694 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
695#if defined(FEAT_QUICKFIX)
696 (char_u *)&p_bh, PV_BH,
697 {(char_u *)"", (char_u *)0L}
698#else
699 (char_u *)NULL, PV_NONE,
700 {(char_u *)0L, (char_u *)0L}
701#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000702 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
704 (char_u *)&p_bl, PV_BL,
705 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000706 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
708#if defined(FEAT_QUICKFIX)
709 (char_u *)&p_bt, PV_BT,
710 {(char_u *)"", (char_u *)0L}
711#else
712 (char_u *)NULL, PV_NONE,
713 {(char_u *)0L, (char_u *)0L}
714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000715 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200716 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000717#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 (char_u *)&p_cmp, PV_NONE,
719 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000720#else
721 (char_u *)NULL, PV_NONE,
722 {(char_u *)0L, (char_u *)0L}
723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
726#ifdef FEAT_SEARCHPATH
727 (char_u *)&p_cdpath, PV_NONE,
728 {(char_u *)",,", (char_u *)0L}
729#else
730 (char_u *)NULL, PV_NONE,
731 {(char_u *)0L, (char_u *)0L}
732#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000733 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734 {"cedit", NULL, P_STRING,
735#ifdef FEAT_CMDWIN
736 (char_u *)&p_cedit, PV_NONE,
737 {(char_u *)"", (char_u *)CTRL_F_STR}
738#else
739 (char_u *)NULL, PV_NONE,
740 {(char_u *)0L, (char_u *)0L}
741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000742 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000743 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
744#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
745 (char_u *)&p_ccv, PV_NONE,
746 {(char_u *)"", (char_u *)0L}
747#else
748 (char_u *)NULL, PV_NONE,
749 {(char_u *)0L, (char_u *)0L}
750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000751 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000752 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
753#ifdef FEAT_CINDENT
754 (char_u *)&p_cin, PV_CIN,
755#else
756 (char_u *)NULL, PV_NONE,
757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000758 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200759 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760#ifdef FEAT_CINDENT
761 (char_u *)&p_cink, PV_CINK,
762 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
763#else
764 (char_u *)NULL, PV_NONE,
765 {(char_u *)0L, (char_u *)0L}
766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000767 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200768 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769#ifdef FEAT_CINDENT
770 (char_u *)&p_cino, PV_CINO,
771#else
772 (char_u *)NULL, PV_NONE,
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200775 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
777 (char_u *)&p_cinw, PV_CINW,
778 {(char_u *)"if,else,while,do,for,switch",
779 (char_u *)0L}
780#else
781 (char_u *)NULL, PV_NONE,
782 {(char_u *)0L, (char_u *)0L}
783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000784 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200785 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786#ifdef FEAT_CLIPBOARD
787 (char_u *)&p_cb, PV_NONE,
788# ifdef FEAT_XCLIPBOARD
789 {(char_u *)"autoselect,exclude:cons\\|linux",
790 (char_u *)0L}
791# else
792 {(char_u *)"", (char_u *)0L}
793# endif
794#else
795 (char_u *)NULL, PV_NONE,
796 {(char_u *)"", (char_u *)0L}
797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000798 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000799 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
800 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000801 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000802 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
803#ifdef FEAT_CMDWIN
804 (char_u *)&p_cwh, PV_NONE,
805#else
806 (char_u *)NULL, PV_NONE,
807#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000808 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200809 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200810#ifdef FEAT_SYN_HL
811 (char_u *)VAR_WIN, PV_CC,
812#else
813 (char_u *)NULL, PV_NONE,
814#endif
815 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
817 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000818 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200819 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
820 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000821#ifdef FEAT_COMMENTS
822 (char_u *)&p_com, PV_COM,
823 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
824 (char_u *)0L}
825#else
826 (char_u *)NULL, PV_NONE,
827 {(char_u *)0L, (char_u *)0L}
828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000829 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200830 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831#ifdef FEAT_FOLDING
832 (char_u *)&p_cms, PV_CMS,
833 {(char_u *)"/*%s*/", (char_u *)0L}
834#else
835 (char_u *)NULL, PV_NONE,
836 {(char_u *)0L, (char_u *)0L}
837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000838 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000839 /* P_PRI_MKRC isn't needed here, optval_default()
840 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841 {"compatible", "cp", P_BOOL|P_RALL,
842 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000843 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200844 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000845#ifdef FEAT_INS_EXPAND
846 (char_u *)&p_cpt, PV_CPT,
847 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
848#else
849 (char_u *)NULL, PV_NONE,
850 {(char_u *)0L, (char_u *)0L}
851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000852 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200853 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200854#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200855 (char_u *)VAR_WIN, PV_COCU,
856 {(char_u *)"", (char_u *)NULL}
857#else
858 (char_u *)NULL, PV_NONE,
859 {(char_u *)NULL, (char_u *)0L}
860#endif
861 SCRIPTID_INIT},
862 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
863#ifdef FEAT_CONCEAL
864 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200865#else
866 (char_u *)NULL, PV_NONE,
867#endif
868 {(char_u *)0L, (char_u *)0L}
869 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000870 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
871#ifdef FEAT_COMPL_FUNC
872 (char_u *)&p_cfu, PV_CFU,
873 {(char_u *)"", (char_u *)0L}
874#else
875 (char_u *)NULL, PV_NONE,
876 {(char_u *)0L, (char_u *)0L}
877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000878 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200879 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000880#ifdef FEAT_INS_EXPAND
881 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000882 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000883#else
884 (char_u *)NULL, PV_NONE,
885 {(char_u *)0L, (char_u *)0L}
886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000887 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000888 {"confirm", "cf", P_BOOL|P_VI_DEF,
889#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
890 (char_u *)&p_confirm, PV_NONE,
891#else
892 (char_u *)NULL, PV_NONE,
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"conskey", "consk",P_BOOL|P_VI_DEF,
896#ifdef MSDOS
897 (char_u *)&p_consk, PV_NONE,
898#else
899 (char_u *)NULL, PV_NONE,
900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
903 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
906 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
908 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200909 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200910#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200911 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200912 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200913#else
914 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200915 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200916#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
919#ifdef FEAT_CSCOPE
920 (char_u *)&p_cspc, PV_NONE,
921#else
922 (char_u *)NULL, PV_NONE,
923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000924 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
926#ifdef FEAT_CSCOPE
927 (char_u *)&p_csprg, PV_NONE,
928 {(char_u *)"cscope", (char_u *)0L}
929#else
930 (char_u *)NULL, PV_NONE,
931 {(char_u *)0L, (char_u *)0L}
932#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000933 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200934 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000935#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
936 (char_u *)&p_csqf, PV_NONE,
937 {(char_u *)"", (char_u *)0L}
938#else
939 (char_u *)NULL, PV_NONE,
940 {(char_u *)0L, (char_u *)0L}
941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000942 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200943 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
944#ifdef FEAT_CSCOPE
945 (char_u *)&p_csre, PV_NONE,
946#else
947 (char_u *)NULL, PV_NONE,
948#endif
949 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000950 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
951#ifdef FEAT_CSCOPE
952 (char_u *)&p_cst, PV_NONE,
953#else
954 (char_u *)NULL, PV_NONE,
955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000956 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
958#ifdef FEAT_CSCOPE
959 (char_u *)&p_csto, PV_NONE,
960#else
961 (char_u *)NULL, PV_NONE,
962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000963 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
965#ifdef FEAT_CSCOPE
966 (char_u *)&p_csverbose, PV_NONE,
967#else
968 (char_u *)NULL, PV_NONE,
969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000970 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200971 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
972#ifdef FEAT_CURSORBIND
973 (char_u *)VAR_WIN, PV_CRBIND,
974#else
975 (char_u *)NULL, PV_NONE,
976#endif
977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000978 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
979#ifdef FEAT_SYN_HL
980 (char_u *)VAR_WIN, PV_CUC,
981#else
982 (char_u *)NULL, PV_NONE,
983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000985 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
986#ifdef FEAT_SYN_HL
987 (char_u *)VAR_WIN, PV_CUL,
988#else
989 (char_u *)NULL, PV_NONE,
990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992 {"debug", NULL, P_STRING|P_VI_DEF,
993 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000994 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200995 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000997 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000998 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999#else
1000 (char_u *)NULL, PV_NONE,
1001 {(char_u *)NULL, (char_u *)0L}
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1005#ifdef FEAT_MBYTE
1006 (char_u *)&p_deco, PV_NONE,
1007#else
1008 (char_u *)NULL, PV_NONE,
1009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001011 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001013 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#else
1015 (char_u *)NULL, PV_NONE,
1016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1019#ifdef FEAT_DIFF
1020 (char_u *)VAR_WIN, PV_DIFF,
1021#else
1022 (char_u *)NULL, PV_NONE,
1023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001024 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001025 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1027 (char_u *)&p_dex, PV_NONE,
1028 {(char_u *)"", (char_u *)0L}
1029#else
1030 (char_u *)NULL, PV_NONE,
1031 {(char_u *)0L, (char_u *)0L}
1032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001033 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001034 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1035 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036#ifdef FEAT_DIFF
1037 (char_u *)&p_dip, PV_NONE,
1038 {(char_u *)"filler", (char_u *)NULL}
1039#else
1040 (char_u *)NULL, PV_NONE,
1041 {(char_u *)"", (char_u *)NULL}
1042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1045#ifdef FEAT_DIGRAPHS
1046 (char_u *)&p_dg, PV_NONE,
1047#else
1048 (char_u *)NULL, PV_NONE,
1049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001051 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1052 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001054 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001055 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001057 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 {"eadirection", "ead", P_STRING|P_VI_DEF,
1059#ifdef FEAT_VERTSPLIT
1060 (char_u *)&p_ead, PV_NONE,
1061 {(char_u *)"both", (char_u *)0L}
1062#else
1063 (char_u *)NULL, PV_NONE,
1064 {(char_u *)NULL, (char_u *)0L}
1065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1068 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001070 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071#ifdef FEAT_MBYTE
1072 (char_u *)&p_enc, PV_NONE,
1073 {(char_u *)ENC_DFLT, (char_u *)0L}
1074#else
1075 (char_u *)NULL, PV_NONE,
1076 {(char_u *)0L, (char_u *)0L}
1077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001078 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001079 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1080 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1083 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001086 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1089 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1092#ifdef FEAT_QUICKFIX
1093 (char_u *)&p_ef, PV_NONE,
1094 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1095#else
1096 (char_u *)NULL, PV_NONE,
1097 {(char_u *)NULL, (char_u *)0L}
1098#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001100 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001102 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104#else
1105 (char_u *)NULL, PV_NONE,
1106 {(char_u *)NULL, (char_u *)0L}
1107#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"esckeys", "ek", P_BOOL|P_VIM,
1110 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001112 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113#ifdef FEAT_AUTOCMD
1114 (char_u *)&p_ei, PV_NONE,
1115#else
1116 (char_u *)NULL, PV_NONE,
1117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1120 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1123 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001125 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1126 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001127#ifdef FEAT_MBYTE
1128 (char_u *)&p_fenc, PV_FENC,
1129 {(char_u *)"", (char_u *)0L}
1130#else
1131 (char_u *)NULL, PV_NONE,
1132 {(char_u *)0L, (char_u *)0L}
1133#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001134 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001135 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136#ifdef FEAT_MBYTE
1137 (char_u *)&p_fencs, PV_NONE,
1138 {(char_u *)"ucs-bom", (char_u *)0L}
1139#else
1140 (char_u *)NULL, PV_NONE,
1141 {(char_u *)0L, (char_u *)0L}
1142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001144 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1145 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001147 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001148 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1151 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001152 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1153 (char_u *)&p_fic, PV_NONE,
1154 {
1155#ifdef CASE_INSENSITIVE_FILENAME
1156 (char_u *)TRUE,
1157#else
1158 (char_u *)FALSE,
1159#endif
1160 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001161 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162#ifdef FEAT_AUTOCMD
1163 (char_u *)&p_ft, PV_FT,
1164 {(char_u *)"", (char_u *)0L}
1165#else
1166 (char_u *)NULL, PV_NONE,
1167 {(char_u *)0L, (char_u *)0L}
1168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001170 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1172 (char_u *)&p_fcs, PV_NONE,
1173 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1174#else
1175 (char_u *)NULL, PV_NONE,
1176 {(char_u *)"", (char_u *)0L}
1177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001179 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1180 (char_u *)&p_fixeol, PV_FIXEOL,
1181 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1183#ifdef FEAT_FKMAP
1184 (char_u *)&p_fkmap, PV_NONE,
1185#else
1186 (char_u *)NULL, PV_NONE,
1187#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"flash", "fl", P_BOOL|P_VI_DEF,
1190 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001193 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001195 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1197 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1200 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001202 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1203# ifdef FEAT_EVAL
1204 (char_u *)VAR_WIN, PV_FDE,
1205 {(char_u *)"0", (char_u *)NULL}
1206# else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
1209# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1212 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1215 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001217 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001221 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)"{{{,}}}", (char_u *)NULL}
1224 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1226 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001227 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1229 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1232 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001233 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001234 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001235 (char_u *)&p_fdo, PV_NONE,
1236 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1239# ifdef FEAT_EVAL
1240 (char_u *)VAR_WIN, PV_FDT,
1241 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001242# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001245# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001248 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001249#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001250 (char_u *)&p_fex, PV_FEX,
1251 {(char_u *)"", (char_u *)0L}
1252#else
1253 (char_u *)NULL, PV_NONE,
1254 {(char_u *)0L, (char_u *)0L}
1255#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001257 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1258 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001259 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1260 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001261 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1262 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1264 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1266 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001267 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001268 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1269#ifdef HAVE_FSYNC
1270 (char_u *)&p_fs, PV_NONE,
1271 {(char_u *)TRUE, (char_u *)0L}
1272#else
1273 (char_u *)NULL, PV_NONE,
1274 {(char_u *)FALSE, (char_u *)0L}
1275#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1278 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001279 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 {"graphic", "gr", P_BOOL|P_VI_DEF,
1281 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001282 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001283 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001284#ifdef FEAT_QUICKFIX
1285 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001286 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287#else
1288 (char_u *)NULL, PV_NONE,
1289 {(char_u *)NULL, (char_u *)0L}
1290#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001291 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001292 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1293#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001294 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295 {
1296# ifdef WIN3264
1297 /* may be changed to "grep -n" in os_win32.c */
1298 (char_u *)"findstr /n",
1299# else
1300# ifdef UNIX
1301 /* Add an extra file name so that grep will always
1302 * insert a file name in the match line. */
1303 (char_u *)"grep -n $* /dev/null",
1304# else
1305# ifdef VMS
1306 (char_u *)"SEARCH/NUMBERS ",
1307# else
1308 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001309# endif
1310# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313#else
1314 (char_u *)NULL, PV_NONE,
1315 {(char_u *)NULL, (char_u *)0L}
1316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001317 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001318 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319#ifdef CURSOR_SHAPE
1320 (char_u *)&p_guicursor, PV_NONE,
1321 {
1322# ifdef FEAT_GUI
1323 (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",
1324# else /* MSDOS or Win32 console */
1325 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1326# endif
1327 (char_u *)0L}
1328#else
1329 (char_u *)NULL, PV_NONE,
1330 {(char_u *)NULL, (char_u *)0L}
1331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001332 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001333 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334#ifdef FEAT_GUI
1335 (char_u *)&p_guifont, PV_NONE,
1336 {(char_u *)"", (char_u *)0L}
1337#else
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)NULL, (char_u *)0L}
1340#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001341 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001342 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1344 (char_u *)&p_guifontset, PV_NONE,
1345 {(char_u *)"", (char_u *)0L}
1346#else
1347 (char_u *)NULL, PV_NONE,
1348 {(char_u *)NULL, (char_u *)0L}
1349#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001351 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1353 (char_u *)&p_guifontwide, PV_NONE,
1354 {(char_u *)"", (char_u *)0L}
1355#else
1356 (char_u *)NULL, PV_NONE,
1357 {(char_u *)NULL, (char_u *)0L}
1358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001361#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 (char_u *)&p_ghr, PV_NONE,
1363#else
1364 (char_u *)NULL, PV_NONE,
1365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001366 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001368#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 (char_u *)&p_go, PV_NONE,
1370# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001371 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001373 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001374# endif
1375#else
1376 (char_u *)NULL, PV_NONE,
1377 {(char_u *)NULL, (char_u *)0L}
1378#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001379 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {"guipty", NULL, P_BOOL|P_VI_DEF,
1381#if defined(FEAT_GUI)
1382 (char_u *)&p_guipty, PV_NONE,
1383#else
1384 (char_u *)NULL, PV_NONE,
1385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001386 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001387 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001388#if defined(FEAT_GUI_TABLINE)
1389 (char_u *)&p_gtl, PV_NONE,
1390 {(char_u *)"", (char_u *)0L}
1391#else
1392 (char_u *)NULL, PV_NONE,
1393 {(char_u *)NULL, (char_u *)0L}
1394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001395 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001396 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001397#if defined(FEAT_GUI_TABLINE)
1398 (char_u *)&p_gtt, PV_NONE,
1399 {(char_u *)"", (char_u *)0L}
1400#else
1401 (char_u *)NULL, PV_NONE,
1402 {(char_u *)NULL, (char_u *)0L}
1403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001404 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1406 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001407 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1409 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001410 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"helpheight", "hh", P_NUM|P_VI_DEF,
1413#ifdef FEAT_WINDOWS
1414 (char_u *)&p_hh, PV_NONE,
1415#else
1416 (char_u *)NULL, PV_NONE,
1417#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001418 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001419 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420#ifdef FEAT_MULTI_LANG
1421 (char_u *)&p_hlg, PV_NONE,
1422 {(char_u *)"", (char_u *)0L}
1423#else
1424 (char_u *)NULL, PV_NONE,
1425 {(char_u *)0L, (char_u *)0L}
1426#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001427 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"hidden", "hid", P_BOOL|P_VI_DEF,
1429 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001430 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001431 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001433 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1434 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"history", "hi", P_NUM|P_VIM,
1436 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001437 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1439#ifdef FEAT_RIGHTLEFT
1440 (char_u *)&p_hkmap, PV_NONE,
1441#else
1442 (char_u *)NULL, PV_NONE,
1443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1446#ifdef FEAT_RIGHTLEFT
1447 (char_u *)&p_hkmapp, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1453 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001454 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"icon", NULL, P_BOOL|P_VI_DEF,
1456#ifdef FEAT_TITLE
1457 (char_u *)&p_icon, PV_NONE,
1458#else
1459 (char_u *)NULL, PV_NONE,
1460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"iconstring", NULL, P_STRING|P_VI_DEF,
1463#ifdef FEAT_TITLE
1464 (char_u *)&p_iconstring, PV_NONE,
1465#else
1466 (char_u *)NULL, PV_NONE,
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1470 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001472 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1473# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1474 (char_u *)&p_imaf, PV_NONE,
1475 {(char_u *)"", (char_u *)NULL}
1476# else
1477 (char_u *)NULL, PV_NONE,
1478 {(char_u *)NULL, (char_u *)0L}
1479# endif
1480 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001482#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483 (char_u *)&p_imak, PV_NONE,
1484#else
1485 (char_u *)NULL, PV_NONE,
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1489#ifdef USE_IM_CONTROL
1490 (char_u *)&p_imcmdline, PV_NONE,
1491#else
1492 (char_u *)NULL, PV_NONE,
1493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001494 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1496#ifdef USE_IM_CONTROL
1497 (char_u *)&p_imdisable, PV_NONE,
1498#else
1499 (char_u *)NULL, PV_NONE,
1500#endif
1501#ifdef __sgi
1502 {(char_u *)TRUE, (char_u *)0L}
1503#else
1504 {(char_u *)FALSE, (char_u *)0L}
1505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001506 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"iminsert", "imi", P_NUM|P_VI_DEF,
1508 (char_u *)&p_iminsert, PV_IMI,
1509#ifdef B_IMODE_IM
1510 {(char_u *)B_IMODE_IM, (char_u *)0L}
1511#else
1512 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001514 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {"imsearch", "ims", P_NUM|P_VI_DEF,
1516 (char_u *)&p_imsearch, PV_IMS,
1517#ifdef B_IMODE_IM
1518 {(char_u *)B_IMODE_IM, (char_u *)0L}
1519#else
1520 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001522 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001523 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001524# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1525 (char_u *)&p_imsf, PV_NONE,
1526 {(char_u *)"", (char_u *)NULL}
1527# else
1528 (char_u *)NULL, PV_NONE,
1529 {(char_u *)NULL, (char_u *)0L}
1530# endif
1531 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1533#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001534 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001535 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1536#else
1537 (char_u *)NULL, PV_NONE,
1538 {(char_u *)0L, (char_u *)0L}
1539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001540 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1542#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1543 (char_u *)&p_inex, PV_INEX,
1544 {(char_u *)"", (char_u *)0L}
1545#else
1546 (char_u *)NULL, PV_NONE,
1547 {(char_u *)0L, (char_u *)0L}
1548#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001549 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1551 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1554#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1555 (char_u *)&p_inde, PV_INDE,
1556 {(char_u *)"", (char_u *)0L}
1557#else
1558 (char_u *)NULL, PV_NONE,
1559 {(char_u *)0L, (char_u *)0L}
1560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001561 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001562 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001563#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1564 (char_u *)&p_indk, PV_INDK,
1565 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1566#else
1567 (char_u *)NULL, PV_NONE,
1568 {(char_u *)0L, (char_u *)0L}
1569#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 {"infercase", "inf", P_BOOL|P_VI_DEF,
1572 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1575 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1578 (char_u *)&p_isf, PV_NONE,
1579 {
1580#ifdef BACKSLASH_IN_FILENAME
1581 /* Excluded are: & and ^ are special in cmd.exe
1582 * ( and ) are used in text separating fnames */
1583 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1584#else
1585# ifdef AMIGA
1586 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1587# else
1588# ifdef VMS
1589 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1590# else /* UNIX et al. */
1591# ifdef EBCDIC
1592 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1593# else
1594 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1595# endif
1596# endif
1597# endif
1598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001599 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1601 (char_u *)&p_isi, PV_NONE,
1602 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001603#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001604 (char_u *)"@,48-57,_,128-167,224-235",
1605#else
1606# ifdef EBCDIC
1607 /* TODO: EBCDIC Check this! @ == isalpha()*/
1608 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1609 "112-120,128,140-142,156,158,172,"
1610 "174,186,191,203-207,219-225,235-239,"
1611 "251-254",
1612# else
1613 (char_u *)"@,48-57,_,192-255",
1614# endif
1615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001616 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1618 (char_u *)&p_isk, PV_ISK,
1619 {
1620#ifdef EBCDIC
1621 (char_u *)"@,240-249,_",
1622 /* TODO: EBCDIC Check this! @ == isalpha()*/
1623 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1624 "112-120,128,140-142,156,158,172,"
1625 "174,186,191,203-207,219-225,235-239,"
1626 "251-254",
1627#else
1628 (char_u *)"@,48-57,_",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001629# if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 (char_u *)"@,48-57,_,128-167,224-235"
1631# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001632 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633# endif
1634#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001635 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1637 (char_u *)&p_isp, PV_NONE,
1638 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001639#if defined(MSDOS) || defined(MSWIN) \
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001640 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 || defined(VMS)
1642 (char_u *)"@,~-255",
1643#else
1644# ifdef EBCDIC
1645 /* all chars above 63 are printable */
1646 (char_u *)"63-255",
1647# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001648 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649# endif
1650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001651 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001652 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1653 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001654 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1656#ifdef FEAT_CRYPT
1657 (char_u *)&p_key, PV_KEY,
1658 {(char_u *)"", (char_u *)0L}
1659#else
1660 (char_u *)NULL, PV_NONE,
1661 {(char_u *)0L, (char_u *)0L}
1662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001663 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001664 {"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 +00001665#ifdef FEAT_KEYMAP
1666 (char_u *)&p_keymap, PV_KMAP,
1667 {(char_u *)"", (char_u *)0L}
1668#else
1669 (char_u *)NULL, PV_NONE,
1670 {(char_u *)"", (char_u *)0L}
1671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001672 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001673 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001675 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001676 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001677 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {
1679#if defined(MSDOS) || defined(MSWIN)
1680 (char_u *)":help",
1681#else
1682#ifdef VMS
1683 (char_u *)"help",
1684#else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001685# ifdef USEMAN_S
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 (char_u *)"man -s",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001687# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 (char_u *)"man",
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689# endif
1690#endif
1691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001693 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694#ifdef FEAT_LANGMAP
1695 (char_u *)&p_langmap, PV_NONE,
1696 {(char_u *)"", /* unmatched } */
1697#else
1698 (char_u *)NULL, PV_NONE,
1699 {(char_u *)NULL,
1700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001701 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001702 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1704 (char_u *)&p_lm, PV_NONE,
1705#else
1706 (char_u *)NULL, PV_NONE,
1707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001708 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001709 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1710#ifdef FEAT_LANGMAP
1711 (char_u *)&p_lnr, PV_NONE,
1712#else
1713 (char_u *)NULL, PV_NONE,
1714#endif
1715 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1717#ifdef FEAT_WINDOWS
1718 (char_u *)&p_ls, PV_NONE,
1719#else
1720 (char_u *)NULL, PV_NONE,
1721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1724 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001725 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1727#ifdef FEAT_LINEBREAK
1728 (char_u *)VAR_WIN, PV_LBR,
1729#else
1730 (char_u *)NULL, PV_NONE,
1731#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001732 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1734 (char_u *)&Rows, PV_NONE,
1735 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001736#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 (char_u *)25L,
1738#else
1739 (char_u *)24L,
1740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1743#ifdef FEAT_GUI
1744 (char_u *)&p_linespace, PV_NONE,
1745#else
1746 (char_u *)NULL, PV_NONE,
1747#endif
1748#ifdef FEAT_GUI_W32
1749 {(char_u *)1L, (char_u *)0L}
1750#else
1751 {(char_u *)0L, (char_u *)0L}
1752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001753 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754 {"lisp", NULL, P_BOOL|P_VI_DEF,
1755#ifdef FEAT_LISP
1756 (char_u *)&p_lisp, PV_LISP,
1757#else
1758 (char_u *)NULL, PV_NONE,
1759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001761 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001763 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1765#else
1766 (char_u *)NULL, PV_NONE,
1767 {(char_u *)"", (char_u *)0L}
1768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001769 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1771 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001773 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001775 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1777 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001778 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001779#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001780 {"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1781 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001782 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1783 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001784#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001785#ifdef FEAT_GUI_MAC
1786 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1787 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001789#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"magic", NULL, P_BOOL|P_VI_DEF,
1791 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001793 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794#ifdef FEAT_QUICKFIX
1795 (char_u *)&p_mef, PV_NONE,
1796 {(char_u *)"", (char_u *)0L}
1797#else
1798 (char_u *)NULL, PV_NONE,
1799 {(char_u *)NULL, (char_u *)0L}
1800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001801 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001802 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1803#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001804 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805# ifdef VMS
1806 {(char_u *)"MMS", (char_u *)0L}
1807# else
1808 {(char_u *)"make", (char_u *)0L}
1809# endif
1810#else
1811 (char_u *)NULL, PV_NONE,
1812 {(char_u *)NULL, (char_u *)0L}
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001815 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1818 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819 {"matchtime", "mat", P_NUM|P_VI_DEF,
1820 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001821 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001822 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001823#ifdef FEAT_MBYTE
1824 (char_u *)&p_mco, PV_NONE,
1825#else
1826 (char_u *)NULL, PV_NONE,
1827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001828 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1830#ifdef FEAT_EVAL
1831 (char_u *)&p_mfd, PV_NONE,
1832#else
1833 (char_u *)NULL, PV_NONE,
1834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001835 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1837 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"maxmem", "mm", P_NUM|P_VI_DEF,
1840 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1842 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001843 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1844 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1847 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1849 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"menuitems", "mis", P_NUM|P_VI_DEF,
1851#ifdef FEAT_MENU
1852 (char_u *)&p_mis, PV_NONE,
1853#else
1854 (char_u *)NULL, PV_NONE,
1855#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001856 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"mesg", NULL, P_BOOL|P_VI_DEF,
1858 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001860 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001861#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001862 (char_u *)&p_msm, PV_NONE,
1863 {(char_u *)"460000,2000,500", (char_u *)0L}
1864#else
1865 (char_u *)NULL, PV_NONE,
1866 {(char_u *)0L, (char_u *)0L}
1867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001868 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"modeline", "ml", P_BOOL|P_VIM,
1870 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"modelines", "mls", P_NUM|P_VI_DEF,
1873 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001874 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001875 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1876 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1879 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 {"more", NULL, P_BOOL|P_VIM,
1882 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001883 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1885 (char_u *)&p_mouse, PV_NONE,
1886 {
1887#if defined(MSDOS) || defined(WIN3264)
1888 (char_u *)"a",
1889#else
1890 (char_u *)"",
1891#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001892 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1894#ifdef FEAT_GUI
1895 (char_u *)&p_mousef, PV_NONE,
1896#else
1897 (char_u *)NULL, PV_NONE,
1898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1901#ifdef FEAT_GUI
1902 (char_u *)&p_mh, PV_NONE,
1903#else
1904 (char_u *)NULL, PV_NONE,
1905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001906 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1908 (char_u *)&p_mousem, PV_NONE,
1909 {
1910#if defined(MSDOS) || defined(MSWIN)
1911 (char_u *)"popup",
1912#else
1913# if defined(MACOS)
1914 (char_u *)"popup_setpos",
1915# else
1916 (char_u *)"extend",
1917# endif
1918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001920 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921#ifdef FEAT_MOUSESHAPE
1922 (char_u *)&p_mouseshape, PV_NONE,
1923 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1924#else
1925 (char_u *)NULL, PV_NONE,
1926 {(char_u *)NULL, (char_u *)0L}
1927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1930 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001931 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001932 {"mzquantum", "mzq", P_NUM,
1933#ifdef FEAT_MZSCHEME
1934 (char_u *)&p_mzq, PV_NONE,
1935#else
1936 (char_u *)NULL, PV_NONE,
1937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 {"novice", NULL, P_BOOL|P_VI_DEF,
1940 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001942 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001944 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001945 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001946 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1947 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001948 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001949 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1950#ifdef FEAT_LINEBREAK
1951 (char_u *)VAR_WIN, PV_NUW,
1952#else
1953 (char_u *)NULL, PV_NONE,
1954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001956 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001957#ifdef FEAT_COMPL_FUNC
1958 (char_u *)&p_ofu, PV_OFU,
1959 {(char_u *)"", (char_u *)0L}
1960#else
1961 (char_u *)NULL, PV_NONE,
1962 {(char_u *)0L, (char_u *)0L}
1963#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001965 {"open", NULL, P_BOOL|P_VI_DEF,
1966 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001968 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001969#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001970 (char_u *)&p_odev, PV_NONE,
1971#else
1972 (char_u *)NULL, PV_NONE,
1973#endif
1974 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001975 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001976 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1977 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"optimize", "opt", P_BOOL|P_VI_DEF,
1980 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001984 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"paragraphs", "para", P_STRING|P_VI_DEF,
1986 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001987 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001989 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001990 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1993 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1996#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1997 (char_u *)&p_pex, PV_NONE,
1998 {(char_u *)"", (char_u *)0L}
1999#else
2000 (char_u *)NULL, PV_NONE,
2001 {(char_u *)0L, (char_u *)0L}
2002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002003 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002004 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002005 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002008 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 {
2010#if defined AMIGA || defined MSDOS || defined MSWIN
2011 (char_u *)".,,",
2012#else
2013# if defined(__EMX__)
2014 (char_u *)".,/emx/include,,",
2015# else /* Unix, probably */
2016 (char_u *)".,/usr/include,,",
2017# endif
2018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002019 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002020#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002021 {"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2022 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002023 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2024 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2027 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002028 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002029 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2031 (char_u *)&p_pvh, PV_NONE,
2032#else
2033 (char_u *)NULL, PV_NONE,
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2037#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2038 (char_u *)VAR_WIN, PV_PVW,
2039#else
2040 (char_u *)NULL, PV_NONE,
2041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002043 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044#ifdef FEAT_PRINTER
2045 (char_u *)&p_pdev, PV_NONE,
2046 {(char_u *)"", (char_u *)0L}
2047#else
2048 (char_u *)NULL, PV_NONE,
2049 {(char_u *)NULL, (char_u *)0L}
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"printencoding", "penc", P_STRING|P_VI_DEF,
2053#ifdef FEAT_POSTSCRIPT
2054 (char_u *)&p_penc, PV_NONE,
2055 {(char_u *)"", (char_u *)0L}
2056#else
2057 (char_u *)NULL, PV_NONE,
2058 {(char_u *)NULL, (char_u *)0L}
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2062#ifdef FEAT_POSTSCRIPT
2063 (char_u *)&p_pexpr, PV_NONE,
2064 {(char_u *)"", (char_u *)0L}
2065#else
2066 (char_u *)NULL, PV_NONE,
2067 {(char_u *)NULL, (char_u *)0L}
2068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"printfont", "pfn", P_STRING|P_VI_DEF,
2071#ifdef FEAT_PRINTER
2072 (char_u *)&p_pfn, PV_NONE,
2073 {
2074# ifdef MSWIN
2075 (char_u *)"Courier_New:h10",
2076# else
2077 (char_u *)"courier",
2078# endif
2079 (char_u *)0L}
2080#else
2081 (char_u *)NULL, PV_NONE,
2082 {(char_u *)NULL, (char_u *)0L}
2083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2086#ifdef FEAT_PRINTER
2087 (char_u *)&p_header, PV_NONE,
2088 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2089#else
2090 (char_u *)NULL, PV_NONE,
2091 {(char_u *)NULL, (char_u *)0L}
2092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002094 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2095#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2096 (char_u *)&p_pmcs, PV_NONE,
2097 {(char_u *)"", (char_u *)0L}
2098#else
2099 (char_u *)NULL, PV_NONE,
2100 {(char_u *)NULL, (char_u *)0L}
2101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002102 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002103 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2104#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2105 (char_u *)&p_pmfn, PV_NONE,
2106 {(char_u *)"", (char_u *)0L}
2107#else
2108 (char_u *)NULL, PV_NONE,
2109 {(char_u *)NULL, (char_u *)0L}
2110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002112 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113#ifdef FEAT_PRINTER
2114 (char_u *)&p_popt, PV_NONE,
2115 {(char_u *)"", (char_u *)0L}
2116#else
2117 (char_u *)NULL, PV_NONE,
2118 {(char_u *)NULL, (char_u *)0L}
2119#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002122 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002123 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002124 {"pumheight", "ph", P_NUM|P_VI_DEF,
2125#ifdef FEAT_INS_EXPAND
2126 (char_u *)&p_ph, PV_NONE,
2127#else
2128 (char_u *)NULL, PV_NONE,
2129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002130 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002131#if defined(DYNAMIC_PYTHON3)
Bram Moolenaar0796c062015-11-10 19:41:37 +01002132 {"pythonthreedll", NULL, P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002134 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2135 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002136#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002137#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002138 {"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2139 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002140 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2141 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002142#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002143 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2144#ifdef FEAT_TEXTOBJ
2145 (char_u *)&p_qe, PV_QE,
2146 {(char_u *)"\\", (char_u *)0L}
2147#else
2148 (char_u *)NULL, PV_NONE,
2149 {(char_u *)NULL, (char_u *)0L}
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2153 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002154 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155 {"redraw", NULL, P_BOOL|P_VI_DEF,
2156 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002158 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2159#ifdef FEAT_RELTIME
2160 (char_u *)&p_rdt, PV_NONE,
2161#else
2162 (char_u *)NULL, PV_NONE,
2163#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002164 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002165 {"regexpengine", "re", P_NUM|P_VI_DEF,
2166 (char_u *)&p_re, PV_NONE,
2167 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002168 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2169 (char_u *)VAR_WIN, PV_RNU,
2170 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 {"remap", NULL, P_BOOL|P_VI_DEF,
2172 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002173 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002174 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002175#ifdef FEAT_RENDER_OPTIONS
2176 (char_u *)&p_rop, PV_NONE,
2177 {(char_u *)"", (char_u *)0L}
2178#else
2179 (char_u *)NULL, PV_NONE,
2180 {(char_u *)NULL, (char_u *)0L}
2181#endif
2182 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 {"report", NULL, P_NUM|P_VI_DEF,
2184 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2187#ifdef WIN3264
2188 (char_u *)&p_rs, PV_NONE,
2189#else
2190 (char_u *)NULL, PV_NONE,
2191#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002192 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2194#ifdef FEAT_RIGHTLEFT
2195 (char_u *)&p_ri, PV_NONE,
2196#else
2197 (char_u *)NULL, PV_NONE,
2198#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002199 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2201#ifdef FEAT_RIGHTLEFT
2202 (char_u *)VAR_WIN, PV_RL,
2203#else
2204 (char_u *)NULL, PV_NONE,
2205#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002206 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2208#ifdef FEAT_RIGHTLEFT
2209 (char_u *)VAR_WIN, PV_RLC,
2210 {(char_u *)"search", (char_u *)NULL}
2211#else
2212 (char_u *)NULL, PV_NONE,
2213 {(char_u *)NULL, (char_u *)0L}
2214#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002215 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002216#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002217 {"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2218 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002219 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2220 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2223#ifdef FEAT_CMDL_INFO
2224 (char_u *)&p_ru, PV_NONE,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002229 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2230#ifdef FEAT_STL_OPT
2231 (char_u *)&p_ruf, PV_NONE,
2232#else
2233 (char_u *)NULL, PV_NONE,
2234#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002235 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002236 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2237 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002239 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2240 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2242 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2245#ifdef FEAT_SCROLLBIND
2246 (char_u *)VAR_WIN, PV_SCBIND,
2247#else
2248 (char_u *)NULL, PV_NONE,
2249#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002250 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2252 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002253 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2255 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002256 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002257 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258#ifdef FEAT_SCROLLBIND
2259 (char_u *)&p_sbo, PV_NONE,
2260 {(char_u *)"ver,jump", (char_u *)0L}
2261#else
2262 (char_u *)NULL, PV_NONE,
2263 {(char_u *)0L, (char_u *)0L}
2264#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"sections", "sect", P_STRING|P_VI_DEF,
2267 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2269 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2271 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002275 {(char_u *)"inclusive", (char_u *)0L}
2276 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002277 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002280 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281#ifdef FEAT_SESSION
2282 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002283 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 (char_u *)0L}
2285#else
2286 (char_u *)NULL, PV_NONE,
2287 {(char_u *)0L, (char_u *)0L}
2288#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2291 (char_u *)&p_sh, PV_NONE,
2292 {
2293#ifdef VMS
2294 (char_u *)"-",
2295#else
2296# if defined(MSDOS)
2297 (char_u *)"command",
2298# else
2299# if defined(WIN16)
2300 (char_u *)"command.com",
2301# else
2302# if defined(WIN3264)
2303 (char_u *)"", /* set in set_init_1() */
2304# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306# endif
2307# endif
2308# endif
2309#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2312 (char_u *)&p_shcf, PV_NONE,
2313 {
2314#if defined(MSDOS) || defined(MSWIN)
2315 (char_u *)"/c",
2316#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002319 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2321#ifdef FEAT_QUICKFIX
2322 (char_u *)&p_sp, PV_NONE,
2323 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002324#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326#else
2327 (char_u *)">",
2328#endif
2329 (char_u *)0L}
2330#else
2331 (char_u *)NULL, PV_NONE,
2332 {(char_u *)0L, (char_u *)0L}
2333#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002334 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2336 (char_u *)&p_shq, 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 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2339 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2342#ifdef BACKSLASH_IN_FILENAME
2343 (char_u *)&p_ssl, PV_NONE,
2344#else
2345 (char_u *)NULL, PV_NONE,
2346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002347 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002348 {"shelltemp", "stmp", P_BOOL,
2349 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002350 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 {"shelltype", "st", P_NUM|P_VI_DEF,
2352#ifdef AMIGA
2353 (char_u *)&p_st, PV_NONE,
2354#else
2355 (char_u *)NULL, PV_NONE,
2356#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002357 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2359 (char_u *)&p_sxq, PV_NONE,
2360 {
2361#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2362 (char_u *)"\"",
2363#else
2364 (char_u *)"",
2365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002367 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2368 (char_u *)&p_sxe, PV_NONE,
2369 {
2370#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2371 (char_u *)"\"&|<>()@^",
2372#else
2373 (char_u *)"",
2374#endif
2375 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2377 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2380 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2383 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)"", (char_u *)"filnxtToO"}
2385 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 {"shortname", "sn", P_BOOL|P_VI_DEF,
2387#ifdef SHORT_FNAME
2388 (char_u *)NULL, PV_NONE,
2389#else
2390 (char_u *)&p_sn, PV_SN,
2391#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2394#ifdef FEAT_LINEBREAK
2395 (char_u *)&p_sbr, PV_NONE,
2396#else
2397 (char_u *)NULL, PV_NONE,
2398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"showcmd", "sc", P_BOOL|P_VIM,
2401#ifdef FEAT_CMDL_INFO
2402 (char_u *)&p_sc, PV_NONE,
2403#else
2404 (char_u *)NULL, PV_NONE,
2405#endif
2406 {(char_u *)FALSE,
2407#ifdef UNIX
2408 (char_u *)FALSE
2409#else
2410 (char_u *)TRUE
2411#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2414 (char_u *)&p_sft, 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 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2417 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"showmode", "smd", P_BOOL|P_VIM,
2420 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002421 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002422 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2423#ifdef FEAT_WINDOWS
2424 (char_u *)&p_stal, PV_NONE,
2425#else
2426 (char_u *)NULL, PV_NONE,
2427#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2430 (char_u *)&p_ss, 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 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2433 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2436 (char_u *)NULL, 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 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2439 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002440 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2442#ifdef FEAT_SMARTINDENT
2443 (char_u *)&p_si, PV_SI,
2444#else
2445 (char_u *)NULL, PV_NONE,
2446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002447 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2449 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2452 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2455 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002456 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002457 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002458#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002459 (char_u *)VAR_WIN, PV_SPELL,
2460#else
2461 (char_u *)NULL, PV_NONE,
2462#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002463 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002464 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002465#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002466 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002467 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002468#else
2469 (char_u *)NULL, PV_NONE,
2470 {(char_u *)0L, (char_u *)0L}
2471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002473 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2474 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002475#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002476 (char_u *)&p_spf, PV_SPF,
2477 {(char_u *)"", (char_u *)0L}
2478#else
2479 (char_u *)NULL, PV_NONE,
2480 {(char_u *)0L, (char_u *)0L}
2481#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002482 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002483 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2484 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002485#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002486 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002487 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002488#else
2489 (char_u *)NULL, PV_NONE,
2490 {(char_u *)0L, (char_u *)0L}
2491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002493 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002494#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002495 (char_u *)&p_sps, PV_NONE,
2496 {(char_u *)"best", (char_u *)0L}
2497#else
2498 (char_u *)NULL, PV_NONE,
2499 {(char_u *)0L, (char_u *)0L}
2500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2503#ifdef FEAT_WINDOWS
2504 (char_u *)&p_sb, PV_NONE,
2505#else
2506 (char_u *)NULL, PV_NONE,
2507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"splitright", "spr", P_BOOL|P_VI_DEF,
2510#ifdef FEAT_VERTSPLIT
2511 (char_u *)&p_spr, PV_NONE,
2512#else
2513 (char_u *)NULL, PV_NONE,
2514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2517 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2520#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002521 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522#else
2523 (char_u *)NULL, PV_NONE,
2524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002526 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 (char_u *)&p_su, PV_NONE,
2528 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002530 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002531#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 (char_u *)&p_sua, PV_SUA,
2533 {(char_u *)"", (char_u *)0L}
2534#else
2535 (char_u *)NULL, PV_NONE,
2536 {(char_u *)0L, (char_u *)0L}
2537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2540 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"swapsync", "sws", P_STRING|P_VI_DEF,
2543 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002545 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002548 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2549#ifdef FEAT_SYN_HL
2550 (char_u *)&p_smc, PV_SMC,
2551 {(char_u *)3000L, (char_u *)0L}
2552#else
2553 (char_u *)NULL, PV_NONE,
2554 {(char_u *)0L, (char_u *)0L}
2555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002557 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558#ifdef FEAT_SYN_HL
2559 (char_u *)&p_syn, PV_SYN,
2560 {(char_u *)"", (char_u *)0L}
2561#else
2562 (char_u *)NULL, PV_NONE,
2563 {(char_u *)0L, (char_u *)0L}
2564#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002566 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2567#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002568 (char_u *)&p_tal, PV_NONE,
2569#else
2570 (char_u *)NULL, PV_NONE,
2571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002573 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2574#ifdef FEAT_WINDOWS
2575 (char_u *)&p_tpm, PV_NONE,
2576#else
2577 (char_u *)NULL, PV_NONE,
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2581 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2584 (char_u *)&p_tbs, PV_NONE,
2585#ifdef VMS /* binary searching doesn't appear to work on VMS */
2586 {(char_u *)0L, (char_u *)0L}
2587#else
2588 {(char_u *)TRUE, (char_u *)0L}
2589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002591 {"tagcase", "tc", P_STRING|P_VIM,
2592 (char_u *)&p_tc, PV_TC,
2593 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"taglength", "tl", P_NUM|P_VI_DEF,
2595 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"tagrelative", "tr", P_BOOL|P_VIM,
2598 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002599 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002600 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002601 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 {
2603#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2604 (char_u *)"./tags,./TAGS,tags,TAGS",
2605#else
2606 (char_u *)"./tags,tags",
2607#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002608 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002609 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2610 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002611 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002612#if defined(DYNAMIC_TCL)
2613 {"tcldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2614 (char_u *)&p_tcldll, PV_NONE,
2615 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2616 SCRIPTID_INIT},
2617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2619 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2622#ifdef FEAT_ARABIC
2623 (char_u *)&p_tbidi, PV_NONE,
2624#else
2625 (char_u *)NULL, PV_NONE,
2626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2629#ifdef FEAT_MBYTE
2630 (char_u *)&p_tenc, PV_NONE,
2631 {(char_u *)"", (char_u *)0L}
2632#else
2633 (char_u *)NULL, PV_NONE,
2634 {(char_u *)0L, (char_u *)0L}
2635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"terse", NULL, P_BOOL|P_VI_DEF,
2638 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"textauto", "ta", P_BOOL|P_VIM,
2641 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2643 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2645 (char_u *)&p_tx, PV_TX,
2646 {
2647#ifdef USE_CRNL
2648 (char_u *)TRUE,
2649#else
2650 (char_u *)FALSE,
2651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002653 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002655 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002656 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002657#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002658 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659#else
2660 (char_u *)NULL, PV_NONE,
2661#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002662 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2664 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666 {"timeout", "to", P_BOOL|P_VI_DEF,
2667 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002668 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2670 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"title", NULL, P_BOOL|P_VI_DEF,
2673#ifdef FEAT_TITLE
2674 (char_u *)&p_title, PV_NONE,
2675#else
2676 (char_u *)NULL, PV_NONE,
2677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679 {"titlelen", NULL, P_NUM|P_VI_DEF,
2680#ifdef FEAT_TITLE
2681 (char_u *)&p_titlelen, PV_NONE,
2682#else
2683 (char_u *)NULL, PV_NONE,
2684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002685 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002686 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687#ifdef FEAT_TITLE
2688 (char_u *)&p_titleold, PV_NONE,
2689 {(char_u *)N_("Thanks for flying Vim"),
2690 (char_u *)0L}
2691#else
2692 (char_u *)NULL, PV_NONE,
2693 {(char_u *)0L, (char_u *)0L}
2694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 {"titlestring", NULL, P_STRING|P_VI_DEF,
2697#ifdef FEAT_TITLE
2698 (char_u *)&p_titlestring, PV_NONE,
2699#else
2700 (char_u *)NULL, PV_NONE,
2701#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002702 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002704 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002706 {(char_u *)"icons,tooltips", (char_u *)0L}
2707 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002709#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2711 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002712 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713#endif
2714 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2715 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2718 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002719 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2721 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2724 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002725 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2727#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2728 (char_u *)&p_ttym, PV_NONE,
2729#else
2730 (char_u *)NULL, PV_NONE,
2731#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2734 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2737 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002739 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2740 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002741#ifdef FEAT_PERSISTENT_UNDO
2742 (char_u *)&p_udir, PV_NONE,
2743 {(char_u *)".", (char_u *)0L}
2744#else
2745 (char_u *)NULL, PV_NONE,
2746 {(char_u *)0L, (char_u *)0L}
2747#endif
2748 SCRIPTID_INIT},
2749 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2750#ifdef FEAT_PERSISTENT_UNDO
2751 (char_u *)&p_udf, PV_UDF,
2752#else
2753 (char_u *)NULL, PV_NONE,
2754#endif
2755 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002757 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002759#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 (char_u *)1000L,
2761#else
2762 (char_u *)100L,
2763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002765 {"undoreload", "ur", P_NUM|P_VI_DEF,
2766 (char_u *)&p_ur, PV_NONE,
2767 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"updatecount", "uc", P_NUM|P_VI_DEF,
2769 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"updatetime", "ut", P_NUM|P_VI_DEF,
2772 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 {"verbose", "vbs", P_NUM|P_VI_DEF,
2775 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002776 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002777 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2778 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002779 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2781#ifdef FEAT_SESSION
2782 (char_u *)&p_vdir, PV_NONE,
2783 {(char_u *)DFLT_VDIR, (char_u *)0L}
2784#else
2785 (char_u *)NULL, PV_NONE,
2786 {(char_u *)0L, (char_u *)0L}
2787#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002789 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790#ifdef FEAT_SESSION
2791 (char_u *)&p_vop, PV_NONE,
2792 {(char_u *)"folds,options,cursor", (char_u *)0L}
2793#else
2794 (char_u *)NULL, PV_NONE,
2795 {(char_u *)0L, (char_u *)0L}
2796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002798 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799#ifdef FEAT_VIMINFO
2800 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002801#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002802 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803#else
2804# ifdef AMIGA
2805 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002806 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002808 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809# endif
2810#endif
2811#else
2812 (char_u *)NULL, PV_NONE,
2813 {(char_u *)0L, (char_u *)0L}
2814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002816 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2817 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818#ifdef FEAT_VIRTUALEDIT
2819 (char_u *)&p_ve, PV_NONE,
2820 {(char_u *)"", (char_u *)""}
2821#else
2822 (char_u *)NULL, PV_NONE,
2823 {(char_u *)0L, (char_u *)0L}
2824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2827 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"w300", 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 {"w1200", 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 {"w9600", NULL, P_NUM|P_VI_DEF,
2836 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"warn", NULL, P_BOOL|P_VI_DEF,
2839 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2842 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002844 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 {"wildchar", "wc", P_NUM|P_VIM,
2848 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2850 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002851 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002853 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002854 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855#ifdef FEAT_WILDIGN
2856 (char_u *)&p_wig, PV_NONE,
2857#else
2858 (char_u *)NULL, PV_NONE,
2859#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002861 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2862 (char_u *)&p_wic, PV_NONE,
2863 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2865#ifdef FEAT_WILDMENU
2866 (char_u *)&p_wmnu, PV_NONE,
2867#else
2868 (char_u *)NULL, PV_NONE,
2869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002871 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002874 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2875#ifdef FEAT_CMDL_COMPL
2876 (char_u *)&p_wop, PV_NONE,
2877 {(char_u *)"", (char_u *)0L}
2878#else
2879 (char_u *)NULL, PV_NONE,
2880 {(char_u *)NULL, (char_u *)0L}
2881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002882 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2884#ifdef FEAT_WAK
2885 (char_u *)&p_wak, PV_NONE,
2886 {(char_u *)"menu", (char_u *)0L}
2887#else
2888 (char_u *)NULL, PV_NONE,
2889 {(char_u *)NULL, (char_u *)0L}
2890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002893 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002894 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895 {"winheight", "wh", P_NUM|P_VI_DEF,
2896#ifdef FEAT_WINDOWS
2897 (char_u *)&p_wh, PV_NONE,
2898#else
2899 (char_u *)NULL, PV_NONE,
2900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002901 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002903#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002904 (char_u *)VAR_WIN, PV_WFH,
2905#else
2906 (char_u *)NULL, PV_NONE,
2907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002908 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002909 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2910#ifdef FEAT_VERTSPLIT
2911 (char_u *)VAR_WIN, PV_WFW,
2912#else
2913 (char_u *)NULL, PV_NONE,
2914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002915 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2917#ifdef FEAT_WINDOWS
2918 (char_u *)&p_wmh, PV_NONE,
2919#else
2920 (char_u *)NULL, PV_NONE,
2921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002922 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2924#ifdef FEAT_VERTSPLIT
2925 (char_u *)&p_wmw, PV_NONE,
2926#else
2927 (char_u *)NULL, PV_NONE,
2928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2931#ifdef FEAT_VERTSPLIT
2932 (char_u *)&p_wiw, PV_NONE,
2933#else
2934 (char_u *)NULL, PV_NONE,
2935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002936 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2938 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2941 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002942 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2944 (char_u *)&p_ws, 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 {"write", NULL, P_BOOL|P_VI_DEF,
2947 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949 {"writeany", "wa", P_BOOL|P_VI_DEF,
2950 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002951 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2953 (char_u *)&p_wb, PV_NONE,
2954 {
2955#ifdef FEAT_WRITEBACKUP
2956 (char_u *)TRUE,
2957#else
2958 (char_u *)FALSE,
2959#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002960 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961 {"writedelay", "wd", P_NUM|P_VI_DEF,
2962 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002963 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964
2965/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002966#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002968 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969
2970 p_term("t_AB", T_CAB)
2971 p_term("t_AF", T_CAF)
2972 p_term("t_AL", T_CAL)
2973 p_term("t_al", T_AL)
2974 p_term("t_bc", T_BC)
2975 p_term("t_cd", T_CD)
2976 p_term("t_ce", T_CE)
2977 p_term("t_cl", T_CL)
2978 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002979 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 p_term("t_Co", T_CCO)
2981 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002982 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 p_term("t_cs", T_CS)
2984#ifdef FEAT_VERTSPLIT
2985 p_term("t_CV", T_CSV)
2986#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987 p_term("t_da", T_DA)
2988 p_term("t_db", T_DB)
2989 p_term("t_DL", T_CDL)
2990 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002991 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 p_term("t_fs", T_FS)
2993 p_term("t_IE", T_CIE)
2994 p_term("t_IS", T_CIS)
2995 p_term("t_ke", T_KE)
2996 p_term("t_ks", T_KS)
2997 p_term("t_le", T_LE)
2998 p_term("t_mb", T_MB)
2999 p_term("t_md", T_MD)
3000 p_term("t_me", T_ME)
3001 p_term("t_mr", T_MR)
3002 p_term("t_ms", T_MS)
3003 p_term("t_nd", T_ND)
3004 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003005 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 p_term("t_RI", T_CRI)
3007 p_term("t_RV", T_CRV)
3008 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003010 p_term("t_Sf", T_CSF)
3011 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003013 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 p_term("t_te", T_TE)
3016 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003017 p_term("t_ts", T_TS)
3018 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 p_term("t_ue", T_UE)
3020 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003021 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 p_term("t_vb", T_VB)
3023 p_term("t_ve", T_VE)
3024 p_term("t_vi", T_VI)
3025 p_term("t_vs", T_VS)
3026 p_term("t_WP", T_CWP)
3027 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003028 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 p_term("t_xs", T_XS)
3030 p_term("t_ZH", T_CZH)
3031 p_term("t_ZR", T_CZR)
3032
3033/* terminal key codes are not in here */
3034
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003035 /* end marker */
3036 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037};
3038
3039#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3040
3041#ifdef FEAT_MBYTE
3042static char *(p_ambw_values[]) = {"single", "double", NULL};
3043#endif
3044static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003045static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003047#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003048static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003049#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003050#ifdef FEAT_CMDL_COMPL
3051static char *(p_wop_values[]) = {"tagfile", NULL};
3052#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053#ifdef FEAT_WAK
3054static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3055#endif
3056static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3058static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060#ifdef FEAT_BROWSE
3061static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3062#endif
3063#ifdef FEAT_SCROLLBIND
3064static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3065#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003066static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067#ifdef FEAT_VERTSPLIT
3068static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3069#endif
3070#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003071# ifdef FEAT_AUTOCMD
3072static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3073# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003075# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3077#endif
3078static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3079#ifdef FEAT_FOLDING
3080static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003081# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003083# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 NULL};
3085static char *(p_fcl_values[]) = {"all", NULL};
3086#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003087#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003088static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003089#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090
3091static void set_option_default __ARGS((int, int opt_flags, int compatible));
3092static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003093static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003094static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095static char_u *illegal_char __ARGS((char_u *, int));
3096static int string_to_key __ARGS((char_u *arg));
3097#ifdef FEAT_CMDWIN
3098static char_u *check_cedit __ARGS((void));
3099#endif
3100#ifdef FEAT_TITLE
3101static void did_set_title __ARGS((int icon));
3102#endif
3103static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3104static void didset_options __ARGS((void));
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003105static void didset_options2 __ARGS((void));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003107#if defined(FEAT_EVAL) || defined(PROTO)
3108static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3109#else
3110# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3111#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003113static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
3115static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003116#ifdef FEAT_SYN_HL
3117static int int_cmp __ARGS((const void *a, const void *b));
3118#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119#ifdef FEAT_CLIPBOARD
3120static char_u *check_clipboard_option __ARGS((void));
3121#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003122#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003123static char_u *did_set_spell_option __ARGS((int is_spellfile));
Bram Moolenaar860cae12010-06-05 23:22:07 +02003124static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003125#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003126#ifdef FEAT_EVAL
3127static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3128#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003130static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131static void check_redraw __ARGS((long_u flags));
3132static int findoption __ARGS((char_u *));
3133static int find_key_option __ARGS((char_u *));
3134static void showoptions __ARGS((int all, int opt_flags));
3135static int optval_default __ARGS((struct vimoption *, char_u *varp));
3136static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3137static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3138static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3139static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3140static int istermoption __ARGS((struct vimoption *));
3141static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3142static char_u *get_varp __ARGS((struct vimoption *));
3143static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003144static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3146#ifdef FEAT_LANGMAP
3147static void langmap_init __ARGS((void));
3148static void langmap_set __ARGS((void));
3149#endif
3150static void paste_option_changed __ARGS((void));
3151static void compatible_set __ARGS((void));
3152#ifdef FEAT_LINEBREAK
3153static void fill_breakat_flags __ARGS((void));
3154#endif
3155static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3156static int check_opt_strings __ARGS((char_u *val, char **values, int));
3157static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003158#ifdef FEAT_LINEBREAK
3159static int briopt_check __ARGS((win_T *wp));
3160#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161
3162/*
3163 * Initialize the options, first part.
3164 *
3165 * Called only once from main(), just after creating the first buffer.
3166 */
3167 void
3168set_init_1()
3169{
3170 char_u *p;
3171 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003172 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173
3174#ifdef FEAT_LANGMAP
3175 langmap_init();
3176#endif
3177
3178 /* Be Vi compatible by default */
3179 p_cp = TRUE;
3180
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003181 /* Use POSIX compatibility when $VIM_POSIX is set. */
3182 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003183 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003184 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003185 set_string_default("shm", (char_u *)"A");
3186 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003187
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188 /*
3189 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003190 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003192 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003193#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003195 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003197 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003199 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200# endif
3201#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003202 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203 set_string_default("sh", p);
3204
3205#ifdef FEAT_WILDIGN
3206 /*
3207 * Set the default for 'backupskip' to include environment variables for
3208 * temp files.
3209 */
3210 {
3211# ifdef UNIX
3212 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3213# else
3214 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3215# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003216 int len;
3217 garray_T ga;
3218 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219
3220 ga_init2(&ga, 1, 100);
3221 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3222 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003223 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224# ifdef UNIX
3225 if (*names[n] == NUL)
3226 p = (char_u *)"/tmp";
3227 else
3228# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003229 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230 if (p != NULL && *p != NUL)
3231 {
3232 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003233 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234 if (ga_grow(&ga, len) == OK)
3235 {
3236 if (ga.ga_len > 0)
3237 STRCAT(ga.ga_data, ",");
3238 STRCAT(ga.ga_data, p);
3239 add_pathsep(ga.ga_data);
3240 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003241 ga.ga_len += len;
3242 }
3243 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003244 if (mustfree)
3245 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246 }
3247 if (ga.ga_data != NULL)
3248 {
3249 set_string_default("bsk", ga.ga_data);
3250 vim_free(ga.ga_data);
3251 }
3252 }
3253#endif
3254
3255 /*
3256 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3257 */
3258 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003261#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3262 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3263#endif
3264 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003266 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003267 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268#else
3269# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003270 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003271 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003273 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274# endif
3275#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003277 opt_idx = findoption((char_u *)"maxmem");
3278 if (opt_idx >= 0)
3279 {
3280#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003281 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3282 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003283#endif
3284 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3285 }
3286 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287 }
3288
3289#ifdef FEAT_GUI_W32
3290 /* force 'shortname' for Win32s */
3291 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003292 {
3293 opt_idx = findoption((char_u *)"shortname");
3294 if (opt_idx >= 0)
3295 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3296 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297#endif
3298
3299#ifdef FEAT_SEARCHPATH
3300 {
3301 char_u *cdpath;
3302 char_u *buf;
3303 int i;
3304 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003305 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306
3307 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003308 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309 if (cdpath != NULL)
3310 {
3311 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3312 if (buf != NULL)
3313 {
3314 buf[0] = ','; /* start with ",", current dir first */
3315 j = 1;
3316 for (i = 0; cdpath[i] != NUL; ++i)
3317 {
3318 if (vim_ispathlistsep(cdpath[i]))
3319 buf[j++] = ',';
3320 else
3321 {
3322 if (cdpath[i] == ' ' || cdpath[i] == ',')
3323 buf[j++] = '\\';
3324 buf[j++] = cdpath[i];
3325 }
3326 }
3327 buf[j] = NUL;
3328 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003329 if (opt_idx >= 0)
3330 {
3331 options[opt_idx].def_val[VI_DEFAULT] = buf;
3332 options[opt_idx].flags |= P_DEF_ALLOCED;
3333 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003334 else
3335 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003337 if (mustfree)
3338 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339 }
3340 }
3341#endif
3342
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003343#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 /* Set print encoding on platforms that don't default to latin1 */
3345 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003346# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 (char_u *)"cp1252"
3348# else
3349# ifdef VMS
3350 (char_u *)"dec-mcs"
3351# else
3352# ifdef EBCDIC
3353 (char_u *)"ebcdic-uk"
3354# else
3355# ifdef MAC
3356 (char_u *)"mac-roman"
3357# else /* HPUX */
3358 (char_u *)"hp-roman8"
3359# endif
3360# endif
3361# endif
3362# endif
3363 );
3364#endif
3365
3366#ifdef FEAT_POSTSCRIPT
3367 /* 'printexpr' must be allocated to be able to evaluate it. */
3368 set_string_default("pexpr",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003369# if defined(MSWIN) || defined(MSDOS)
Bram Moolenaared203462004-06-16 11:19:22 +00003370 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371# else
3372# ifdef VMS
3373 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3374
3375# else
3376 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3377# endif
3378# endif
3379 );
3380#endif
3381
3382 /*
3383 * Set all the options (except the terminal options) to their default
3384 * value. Also set the global value for local options.
3385 */
3386 set_options_default(0);
3387
3388#ifdef FEAT_GUI
3389 if (found_reverse_arg)
3390 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3391#endif
3392
3393 curbuf->b_p_initialized = TRUE;
3394 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003395 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396 check_buf_options(curbuf);
3397 check_win_options(curwin);
3398 check_options();
3399
3400 /* Must be before option_expand(), because that one needs vim_isIDc() */
3401 didset_options();
3402
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003403#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003404 /* Use the current chartab for the generic chartab. This is not in
3405 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003406 init_spell_chartab();
3407#endif
3408
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409 /*
3410 * Expand environment variables and things like "~" for the defaults.
3411 * If option_expand() returns non-NULL the variable is expanded. This can
3412 * only happen for non-indirect options.
3413 * Also set the default to the expanded value, so ":set" does not list
3414 * them.
3415 * Don't set the P_ALLOCED flag, because we don't want to free the
3416 * default.
3417 */
3418 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3419 {
3420 if ((options[opt_idx].flags & P_GETTEXT)
3421 && options[opt_idx].var != NULL)
3422 p = (char_u *)_(*(char **)options[opt_idx].var);
3423 else
3424 p = option_expand(opt_idx, NULL);
3425 if (p != NULL && (p = vim_strsave(p)) != NULL)
3426 {
3427 *(char_u **)options[opt_idx].var = p;
3428 /* VIMEXP
3429 * Defaults for all expanded options are currently the same for Vi
3430 * and Vim. When this changes, add some code here! Also need to
3431 * split P_DEF_ALLOCED in two.
3432 */
3433 if (options[opt_idx].flags & P_DEF_ALLOCED)
3434 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3435 options[opt_idx].def_val[VI_DEFAULT] = p;
3436 options[opt_idx].flags |= P_DEF_ALLOCED;
3437 }
3438 }
3439
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440 save_file_ff(curbuf); /* Buffer is unchanged */
3441
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442#if defined(FEAT_ARABIC)
3443 /* Detect use of mlterm.
3444 * Mlterm is a terminal emulator akin to xterm that has some special
3445 * abilities (bidi namely).
3446 * NOTE: mlterm's author is being asked to 'set' a variable
3447 * instead of an environment variable due to inheritance.
3448 */
3449 if (mch_getenv((char_u *)"MLTERM") != NULL)
3450 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3451#endif
3452
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003453 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454
3455#ifdef FEAT_MBYTE
3456# if defined(WIN3264) && defined(FEAT_GETTEXT)
3457 /*
3458 * If $LANG isn't set, try to get a good value for it. This makes the
3459 * right language be used automatically. Don't do this for English.
3460 */
3461 if (mch_getenv((char_u *)"LANG") == NULL)
3462 {
3463 char buf[20];
3464
3465 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3466 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3467 * only the first two. */
3468 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3469 (LPTSTR)buf, 20);
3470 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3471 {
3472 /* There are a few exceptions (probably more) */
3473 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3474 STRCPY(buf, "zh_TW");
3475 else if (STRNICMP(buf, "chs", 3) == 0
3476 || STRNICMP(buf, "zhc", 3) == 0)
3477 STRCPY(buf, "zh_CN");
3478 else if (STRNICMP(buf, "jp", 2) == 0)
3479 STRCPY(buf, "ja");
3480 else
3481 buf[2] = NUL; /* truncate to two-letter code */
3482 vim_setenv("LANG", buf);
3483 }
3484 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003485# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003486# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003487 /* Moved to os_mac_conv.c to avoid dependency problems. */
3488 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003489# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490# endif
3491
3492 /* enc_locale() will try to find the encoding of the current locale. */
3493 p = enc_locale();
3494 if (p != NULL)
3495 {
3496 char_u *save_enc;
3497
3498 /* Try setting 'encoding' and check if the value is valid.
3499 * If not, go back to the default "latin1". */
3500 save_enc = p_enc;
3501 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003502 if (STRCMP(p_enc, "gb18030") == 0)
3503 {
3504 /* We don't support "gb18030", but "cp936" is a good substitute
3505 * for practical purposes, thus use that. It's not an alias to
3506 * still support conversion between gb18030 and utf-8. */
3507 p_enc = vim_strsave((char_u *)"cp936");
3508 vim_free(p);
3509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510 if (mb_init() == NULL)
3511 {
3512 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003513 if (opt_idx >= 0)
3514 {
3515 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3516 options[opt_idx].flags |= P_DEF_ALLOCED;
3517 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003518
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003519#if defined(MSDOS) || defined(MSWIN) || defined(MACOS) \
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003520 || defined(VMS)
3521 if (STRCMP(p_enc, "latin1") == 0
3522# ifdef FEAT_MBYTE
3523 || enc_utf8
3524# endif
3525 )
3526 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003527 /* Adjust the default for 'isprint' and 'iskeyword' to match
3528 * latin1. Also set the defaults for when 'nocompatible' is
3529 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003530 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003531 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003532 set_string_option_direct((char_u *)"isk", -1,
3533 ISK_LATIN1, OPT_FREE, SID_NONE);
3534 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003535 if (opt_idx >= 0)
3536 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003537 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003538 if (opt_idx >= 0)
3539 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003540 (void)init_chartab();
3541 }
3542#endif
3543
Bram Moolenaar071d4272004-06-13 20:20:40 +00003544# if defined(WIN3264) && !defined(FEAT_GUI)
3545 /* Win32 console: When GetACP() returns a different value from
3546 * GetConsoleCP() set 'termencoding'. */
3547 if (GetACP() != GetConsoleCP())
3548 {
3549 char buf[50];
3550
3551 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3552 p_tenc = vim_strsave((char_u *)buf);
3553 if (p_tenc != NULL)
3554 {
3555 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003556 if (opt_idx >= 0)
3557 {
3558 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3559 options[opt_idx].flags |= P_DEF_ALLOCED;
3560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561 convert_setup(&input_conv, p_tenc, p_enc);
3562 convert_setup(&output_conv, p_enc, p_tenc);
3563 }
3564 else
3565 p_tenc = empty_option;
3566 }
3567# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003568# if defined(WIN3264) && defined(FEAT_MBYTE)
3569 /* $HOME may have characters in active code page. */
3570 init_homedir();
3571# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572 }
3573 else
3574 {
3575 vim_free(p_enc);
3576 p_enc = save_enc;
3577 }
3578 }
3579#endif
3580
3581#ifdef FEAT_MULTI_LANG
3582 /* Set the default for 'helplang'. */
3583 set_helplang_default(get_mess_lang());
3584#endif
3585}
3586
3587/*
3588 * Set an option to its default value.
3589 * This does not take care of side effects!
3590 */
3591 static void
3592set_option_default(opt_idx, opt_flags, compatible)
3593 int opt_idx;
3594 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3595 int compatible; /* use Vi default value */
3596{
3597 char_u *varp; /* pointer to variable for current option */
3598 int dvi; /* index in def_val[] */
3599 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003600 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3602
3603 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3604 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003605 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003606 {
3607 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3608 if (flags & P_STRING)
3609 {
3610 /* Use set_string_option_direct() for local options to handle
3611 * freeing and allocating the value. */
3612 if (options[opt_idx].indir != PV_NONE)
3613 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003614 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615 else
3616 {
3617 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3618 free_string_option(*(char_u **)(varp));
3619 *(char_u **)varp = options[opt_idx].def_val[dvi];
3620 options[opt_idx].flags &= ~P_ALLOCED;
3621 }
3622 }
3623 else if (flags & P_NUM)
3624 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003625 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626 win_comp_scroll(curwin);
3627 else
3628 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003629 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630 /* May also set global value for local option. */
3631 if (both)
3632 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3633 *(long *)varp;
3634 }
3635 }
3636 else /* P_BOOL */
3637 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003638 /* the cast to long is required for Manx C, long_i is needed for
3639 * MSVC */
3640 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003641#ifdef UNIX
3642 /* 'modeline' defaults to off for root */
3643 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3644 *(int *)varp = FALSE;
3645#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 /* May also set global value for local option. */
3647 if (both)
3648 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3649 *(int *)varp;
3650 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003651
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003652 /* The default value is not insecure. */
3653 flagsp = insecure_flag(opt_idx, opt_flags);
3654 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655 }
3656
3657#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003658 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003659#endif
3660}
3661
3662/*
3663 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003664 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003665 */
3666 static void
3667set_options_default(opt_flags)
3668 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3669{
3670 int i;
3671#ifdef FEAT_WINDOWS
3672 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003673 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674#endif
3675
3676 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003677 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003678#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003679 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003680 || (TRUE
3681# if defined(FEAT_MBYTE)
3682 && options[i].var != (char_u *)&p_enc
3683# endif
3684# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003685 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003686 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003687# endif
3688 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003689#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003690 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691 set_option_default(i, opt_flags, p_cp);
3692
3693#ifdef FEAT_WINDOWS
3694 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003695 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696 win_comp_scroll(wp);
3697#else
3698 win_comp_scroll(curwin);
3699#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003700#ifdef FEAT_CINDENT
3701 parse_cino(curbuf);
3702#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703}
3704
3705/*
3706 * Set the Vi-default value of a string option.
3707 * Used for 'sh', 'backupskip' and 'term'.
3708 */
3709 void
3710set_string_default(name, val)
3711 char *name;
3712 char_u *val;
3713{
3714 char_u *p;
3715 int opt_idx;
3716
3717 p = vim_strsave(val);
3718 if (p != NULL) /* we don't want a NULL */
3719 {
3720 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003721 if (opt_idx >= 0)
3722 {
3723 if (options[opt_idx].flags & P_DEF_ALLOCED)
3724 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3725 options[opt_idx].def_val[VI_DEFAULT] = p;
3726 options[opt_idx].flags |= P_DEF_ALLOCED;
3727 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 }
3729}
3730
3731/*
3732 * Set the Vi-default value of a number option.
3733 * Used for 'lines' and 'columns'.
3734 */
3735 void
3736set_number_default(name, val)
3737 char *name;
3738 long val;
3739{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003740 int opt_idx;
3741
3742 opt_idx = findoption((char_u *)name);
3743 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003744 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003745}
3746
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003747#if defined(EXITFREE) || defined(PROTO)
3748/*
3749 * Free all options.
3750 */
3751 void
3752free_all_options()
3753{
3754 int i;
3755
3756 for (i = 0; !istermoption(&options[i]); i++)
3757 {
3758 if (options[i].indir == PV_NONE)
3759 {
3760 /* global option: free value and default value. */
3761 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3762 free_string_option(*(char_u **)options[i].var);
3763 if (options[i].flags & P_DEF_ALLOCED)
3764 free_string_option(options[i].def_val[VI_DEFAULT]);
3765 }
3766 else if (options[i].var != VAR_WIN
3767 && (options[i].flags & P_STRING))
3768 /* buffer-local option: free global value */
3769 free_string_option(*(char_u **)options[i].var);
3770 }
3771}
3772#endif
3773
3774
Bram Moolenaar071d4272004-06-13 20:20:40 +00003775/*
3776 * Initialize the options, part two: After getting Rows and Columns and
3777 * setting 'term'.
3778 */
3779 void
3780set_init_2()
3781{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003782 int idx;
3783
Bram Moolenaar071d4272004-06-13 20:20:40 +00003784 /*
3785 * 'scroll' defaults to half the window height. Note that this default is
3786 * wrong when the window height changes.
3787 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003788 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003789 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003790 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003791 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792 comp_col();
3793
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003794 /*
3795 * 'window' is only for backwards compatibility with Vi.
3796 * Default is Rows - 1.
3797 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003798 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003799 p_window = Rows - 1;
3800 set_number_default("window", Rows - 1);
3801
Bram Moolenaarf740b292006-02-16 22:11:02 +00003802 /* For DOS console the default is always black. */
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003803#if !((defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003804 /*
3805 * If 'background' wasn't set by the user, try guessing the value,
3806 * depending on the terminal name. Only need to check for terminals
3807 * with a dark background, that can handle color.
3808 */
3809 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003810 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3811 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003813 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003814 /* don't mark it as set, when starting the GUI it may be
3815 * changed again */
3816 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817 }
3818#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003819
3820#ifdef CURSOR_SHAPE
3821 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3822#endif
3823#ifdef FEAT_MOUSESHAPE
3824 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3825#endif
3826#ifdef FEAT_PRINTER
3827 (void)parse_printoptions(); /* parse 'printoptions' default value */
3828#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829}
3830
3831/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003832 * Return "dark" or "light" depending on the kind of terminal.
3833 * This is just guessing! Recognized are:
3834 * "linux" Linux console
3835 * "screen.linux" Linux console with screen
3836 * "cygwin" Cygwin shell
3837 * "putty" Putty program
3838 * We also check the COLORFGBG environment variable, which is set by
3839 * rxvt and derivatives. This variable contains either two or three
3840 * values separated by semicolons; we want the last value in either
3841 * case. If this value is 0-6 or 8, our background is dark.
3842 */
3843 static char_u *
3844term_bg_default()
3845{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003846#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003847 /* DOS console nearly always black */
3848 return (char_u *)"dark";
3849#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003850 char_u *p;
3851
Bram Moolenaarf740b292006-02-16 22:11:02 +00003852 if (STRCMP(T_NAME, "linux") == 0
3853 || STRCMP(T_NAME, "screen.linux") == 0
3854 || STRCMP(T_NAME, "cygwin") == 0
3855 || STRCMP(T_NAME, "putty") == 0
3856 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3857 && (p = vim_strrchr(p, ';')) != NULL
3858 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3859 && p[2] == NUL))
3860 return (char_u *)"dark";
3861 return (char_u *)"light";
3862#endif
3863}
3864
3865/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003866 * Initialize the options, part three: After reading the .vimrc
3867 */
3868 void
3869set_init_3()
3870{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003871#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872/*
3873 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3874 * This is done after other initializations, where 'shell' might have been
3875 * set, but only if they have not been set before.
3876 */
3877 char_u *p;
3878 int idx_srr;
3879 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003880# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003881 int idx_sp;
3882 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003883# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884
3885 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003886 if (idx_srr < 0)
3887 do_srr = FALSE;
3888 else
3889 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003890# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003892 if (idx_sp < 0)
3893 do_sp = FALSE;
3894 else
3895 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003896# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003897 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898 if (p != NULL)
3899 {
3900 /*
3901 * Default for p_sp is "| tee", for p_srr is ">".
3902 * For known shells it is changed here to include stderr.
3903 */
3904 if ( fnamecmp(p, "csh") == 0
3905 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003906# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907 || fnamecmp(p, "csh.exe") == 0
3908 || fnamecmp(p, "tcsh.exe") == 0
3909# endif
3910 )
3911 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003912# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913 if (do_sp)
3914 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003915# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003917# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003919# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3921 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003922# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 if (do_srr)
3924 {
3925 p_srr = (char_u *)">&";
3926 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3927 }
3928 }
3929 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003930 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 if ( fnamecmp(p, "sh") == 0
3932 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003933 || fnamecmp(p, "mksh") == 0
3934 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003936 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003938 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003939# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 || fnamecmp(p, "cmd") == 0
3941 || fnamecmp(p, "sh.exe") == 0
3942 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003943 || fnamecmp(p, "mksh.exe") == 0
3944 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003946 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947 || fnamecmp(p, "bash.exe") == 0
3948 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003950 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003952# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003953 if (do_sp)
3954 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003955# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003957# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003959# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3961 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003962# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 if (do_srr)
3964 {
3965 p_srr = (char_u *)">%s 2>&1";
3966 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3967 }
3968 }
3969 vim_free(p);
3970 }
3971#endif
3972
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003973#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003975 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3976 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 * This is done after other initializations, where 'shell' might have been
3978 * set, but only if they have not been set before. Default for p_shcf is
3979 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3980 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3981 * command.com. And for Win32 we need to set p_sxq instead.
3982 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003983 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 {
3985 int idx3;
3986
3987 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003988 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989 {
3990 p_shcf = (char_u *)"-c";
3991 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3992 }
3993
3994# ifndef DJGPP
3995# ifdef WIN3264
3996 /* Somehow Win32 requires the quotes around the redirection too */
3997 idx3 = findoption((char_u *)"sxq");
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_sxq = (char_u *)"\"";
4001 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4002 }
4003# else
4004 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004005 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004006 {
4007 p_shq = (char_u *)"\"";
4008 options[idx3].def_val[VI_DEFAULT] = p_shq;
4009 }
4010# endif
4011# endif
4012 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004013 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4014 {
4015 int idx3;
4016
4017 /*
4018 * cmd.exe on Windows will strip the first and last double quote given
4019 * on the command line, e.g. most of the time things like:
4020 * cmd /c "my path/to/echo" "my args to echo"
4021 * become:
4022 * my path/to/echo" "my args to echo
4023 * when executed.
4024 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004025 * To avoid this, set shellxquote to surround the command in
4026 * parenthesis. This appears to make most commands work, without
4027 * breaking commands that worked previously, such as
4028 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004029 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004030 idx3 = findoption((char_u *)"sxq");
4031 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4032 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004033 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004034 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4035 }
4036
Bram Moolenaara64ba222012-02-12 23:23:31 +01004037 idx3 = findoption((char_u *)"shcf");
4038 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4039 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004040 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004041 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4042 }
4043 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044#endif
4045
4046#ifdef FEAT_TITLE
4047 set_title_defaults();
4048#endif
4049}
4050
4051#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4052/*
4053 * When 'helplang' is still at its default value, set it to "lang".
4054 * Only the first two characters of "lang" are used.
4055 */
4056 void
4057set_helplang_default(lang)
4058 char_u *lang;
4059{
4060 int idx;
4061
4062 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4063 return;
4064 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004065 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 {
4067 if (options[idx].flags & P_ALLOCED)
4068 free_string_option(p_hlg);
4069 p_hlg = vim_strsave(lang);
4070 if (p_hlg == NULL)
4071 p_hlg = empty_option;
4072 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004073 {
4074 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4075 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4076 {
4077 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4078 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4079 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004081 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 options[idx].flags |= P_ALLOCED;
4083 }
4084}
4085#endif
4086
4087#ifdef FEAT_GUI
4088static char_u *gui_bg_default __ARGS((void));
4089
4090 static char_u *
4091gui_bg_default()
4092{
4093 if (gui_get_lightness(gui.back_pixel) < 127)
4094 return (char_u *)"dark";
4095 return (char_u *)"light";
4096}
4097
4098/*
4099 * Option initializations that can only be done after opening the GUI window.
4100 */
4101 void
4102init_gui_options()
4103{
4104 /* Set the 'background' option according to the lightness of the
4105 * background color, unless the user has set it already. */
4106 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4107 {
4108 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4109 highlight_changed();
4110 }
4111}
4112#endif
4113
4114#ifdef FEAT_TITLE
4115/*
4116 * 'title' and 'icon' only default to true if they have not been set or reset
4117 * in .vimrc and we can read the old value.
4118 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4119 * they can be reset. This reduces startup time when using X on a remote
4120 * machine.
4121 */
4122 void
4123set_title_defaults()
4124{
4125 int idx1;
4126 long val;
4127
4128 /*
4129 * If GUI is (going to be) used, we can always set the window title and
4130 * icon name. Saves a bit of time, because the X11 display server does
4131 * not need to be contacted.
4132 */
4133 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004134 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 {
4136#ifdef FEAT_GUI
4137 if (gui.starting || gui.in_use)
4138 val = TRUE;
4139 else
4140#endif
4141 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004142 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 p_title = val;
4144 }
4145 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004146 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 {
4148#ifdef FEAT_GUI
4149 if (gui.starting || gui.in_use)
4150 val = TRUE;
4151 else
4152#endif
4153 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004154 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 p_icon = val;
4156 }
4157}
4158#endif
4159
4160/*
4161 * Parse 'arg' for option settings.
4162 *
4163 * 'arg' may be IObuff, but only when no errors can be present and option
4164 * does not need to be expanded with option_expand().
4165 * "opt_flags":
4166 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004167 * OPT_GLOBAL for ":setglobal"
4168 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004170 * OPT_WINONLY to only set window-local options
4171 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 *
4173 * returns FAIL if an error is detected, OK otherwise
4174 */
4175 int
4176do_set(arg, opt_flags)
4177 char_u *arg; /* option string (may be written to!) */
4178 int opt_flags;
4179{
4180 int opt_idx;
4181 char_u *errmsg;
4182 char_u errbuf[80];
4183 char_u *startarg;
4184 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4185 int nextchar; /* next non-white char after option name */
4186 int afterchar; /* character just after option name */
4187 int len;
4188 int i;
4189 long value;
4190 int key;
4191 long_u flags; /* flags for current option */
4192 char_u *varp = NULL; /* pointer to variable for current option */
4193 int did_show = FALSE; /* already showed one value */
4194 int adding; /* "opt+=arg" */
4195 int prepending; /* "opt^=arg" */
4196 int removing; /* "opt-=arg" */
4197 int cp_val = 0;
4198 char_u key_name[2];
4199
4200 if (*arg == NUL)
4201 {
4202 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004203 did_show = TRUE;
4204 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004205 }
4206
4207 while (*arg != NUL) /* loop to process all options */
4208 {
4209 errmsg = NULL;
4210 startarg = arg; /* remember for error message */
4211
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004212 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4213 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004214 {
4215 /*
4216 * ":set all" show all options.
4217 * ":set all&" set all options to their default value.
4218 */
4219 arg += 3;
4220 if (*arg == '&')
4221 {
4222 ++arg;
4223 /* Only for :set command set global value of local options. */
4224 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004225 didset_options();
4226 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004227 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004228 }
4229 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004230 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004231 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004232 did_show = TRUE;
4233 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004235 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236 {
4237 showoptions(2, opt_flags);
4238 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004239 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240 arg += 7;
4241 }
4242 else
4243 {
4244 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004245 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246 {
4247 prefix = 0;
4248 arg += 2;
4249 }
4250 else if (STRNCMP(arg, "inv", 3) == 0)
4251 {
4252 prefix = 2;
4253 arg += 3;
4254 }
4255
4256 /* find end of name */
4257 key = 0;
4258 if (*arg == '<')
4259 {
4260 nextchar = 0;
4261 opt_idx = -1;
4262 /* look out for <t_>;> */
4263 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4264 len = 5;
4265 else
4266 {
4267 len = 1;
4268 while (arg[len] != NUL && arg[len] != '>')
4269 ++len;
4270 }
4271 if (arg[len] != '>')
4272 {
4273 errmsg = e_invarg;
4274 goto skip;
4275 }
4276 arg[len] = NUL; /* put NUL after name */
4277 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4278 opt_idx = findoption(arg + 1);
4279 arg[len++] = '>'; /* restore '>' */
4280 if (opt_idx == -1)
4281 key = find_key_option(arg + 1);
4282 }
4283 else
4284 {
4285 len = 0;
4286 /*
4287 * The two characters after "t_" may not be alphanumeric.
4288 */
4289 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4290 len = 4;
4291 else
4292 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4293 ++len;
4294 nextchar = arg[len];
4295 arg[len] = NUL; /* put NUL after name */
4296 opt_idx = findoption(arg);
4297 arg[len] = nextchar; /* restore nextchar */
4298 if (opt_idx == -1)
4299 key = find_key_option(arg);
4300 }
4301
4302 /* remember character after option name */
4303 afterchar = arg[len];
4304
4305 /* skip white space, allow ":set ai ?" */
4306 while (vim_iswhite(arg[len]))
4307 ++len;
4308
4309 adding = FALSE;
4310 prepending = FALSE;
4311 removing = FALSE;
4312 if (arg[len] != NUL && arg[len + 1] == '=')
4313 {
4314 if (arg[len] == '+')
4315 {
4316 adding = TRUE; /* "+=" */
4317 ++len;
4318 }
4319 else if (arg[len] == '^')
4320 {
4321 prepending = TRUE; /* "^=" */
4322 ++len;
4323 }
4324 else if (arg[len] == '-')
4325 {
4326 removing = TRUE; /* "-=" */
4327 ++len;
4328 }
4329 }
4330 nextchar = arg[len];
4331
4332 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4333 {
4334 errmsg = (char_u *)N_("E518: Unknown option");
4335 goto skip;
4336 }
4337
4338 if (opt_idx >= 0)
4339 {
4340 if (options[opt_idx].var == NULL) /* hidden option: skip */
4341 {
4342 /* Only give an error message when requesting the value of
4343 * a hidden option, ignore setting it. */
4344 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4345 && (!(options[opt_idx].flags & P_BOOL)
4346 || nextchar == '?'))
4347 errmsg = (char_u *)N_("E519: Option not supported");
4348 goto skip;
4349 }
4350
4351 flags = options[opt_idx].flags;
4352 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4353 }
4354 else
4355 {
4356 flags = P_STRING;
4357 if (key < 0)
4358 {
4359 key_name[0] = KEY2TERMCAP0(key);
4360 key_name[1] = KEY2TERMCAP1(key);
4361 }
4362 else
4363 {
4364 key_name[0] = KS_KEY;
4365 key_name[1] = (key & 0xff);
4366 }
4367 }
4368
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004369 /* Skip all options that are not window-local (used when showing
4370 * an already loaded buffer in a window). */
4371 if ((opt_flags & OPT_WINONLY)
4372 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4373 goto skip;
4374
Bram Moolenaara3227e22006-03-08 21:32:40 +00004375 /* Skip all options that are window-local (used for :vimgrep). */
4376 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4377 && options[opt_idx].var == VAR_WIN)
4378 goto skip;
4379
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004380 /* Disallow changing some options from modelines. */
4381 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004382 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004383 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004384 {
4385 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4386 goto skip;
4387 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004388#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004389 /* In diff mode some options are overruled. This avoids that
4390 * 'foldmethod' becomes "marker" instead of "diff" and that
4391 * "wrap" gets set. */
4392 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004393 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004394 && (options[opt_idx].indir == PV_FDM
4395 || options[opt_idx].indir == PV_WRAP))
4396 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004397#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004398 }
4399
4400#ifdef HAVE_SANDBOX
4401 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004402 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403 {
4404 errmsg = (char_u *)_(e_sandbox);
4405 goto skip;
4406 }
4407#endif
4408
4409 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4410 {
4411 arg += len;
4412 cp_val = p_cp;
4413 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4414 {
4415 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4416 {
4417 cp_val = FALSE;
4418 arg += 3;
4419 }
4420 else /* "opt&vi": set to Vi default */
4421 {
4422 cp_val = TRUE;
4423 arg += 2;
4424 }
4425 }
4426 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4427 && arg[1] != NUL && !vim_iswhite(arg[1]))
4428 {
4429 errmsg = e_trailing;
4430 goto skip;
4431 }
4432 }
4433
4434 /*
4435 * allow '=' and ':' as MSDOS command.com allows only one
4436 * '=' character per "set" command line. grrr. (jw)
4437 */
4438 if (nextchar == '?'
4439 || (prefix == 1
4440 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4441 && !(flags & P_BOOL)))
4442 {
4443 /*
4444 * print value
4445 */
4446 if (did_show)
4447 msg_putchar('\n'); /* cursor below last one */
4448 else
4449 {
4450 gotocmdline(TRUE); /* cursor at status line */
4451 did_show = TRUE; /* remember that we did a line */
4452 }
4453 if (opt_idx >= 0)
4454 {
4455 showoneopt(&options[opt_idx], opt_flags);
4456#ifdef FEAT_EVAL
4457 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004458 {
4459 /* Mention where the option was last set. */
4460 if (varp == options[opt_idx].var)
4461 last_set_msg(options[opt_idx].scriptID);
4462 else if ((int)options[opt_idx].indir & PV_WIN)
4463 last_set_msg(curwin->w_p_scriptID[
4464 (int)options[opt_idx].indir & PV_MASK]);
4465 else if ((int)options[opt_idx].indir & PV_BUF)
4466 last_set_msg(curbuf->b_p_scriptID[
4467 (int)options[opt_idx].indir & PV_MASK]);
4468 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004469#endif
4470 }
4471 else
4472 {
4473 char_u *p;
4474
4475 p = find_termcode(key_name);
4476 if (p == NULL)
4477 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004478 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004479 goto skip;
4480 }
4481 else
4482 (void)show_one_termcode(key_name, p, TRUE);
4483 }
4484 if (nextchar != '?'
4485 && nextchar != NUL && !vim_iswhite(afterchar))
4486 errmsg = e_trailing;
4487 }
4488 else
4489 {
4490 if (flags & P_BOOL) /* boolean */
4491 {
4492 if (nextchar == '=' || nextchar == ':')
4493 {
4494 errmsg = e_invarg;
4495 goto skip;
4496 }
4497
4498 /*
4499 * ":set opt!": invert
4500 * ":set opt&": reset to default value
4501 * ":set opt<": reset to global value
4502 */
4503 if (nextchar == '!')
4504 value = *(int *)(varp) ^ 1;
4505 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004506 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004507 ((flags & P_VI_DEF) || cp_val)
4508 ? VI_DEFAULT : VIM_DEFAULT];
4509 else if (nextchar == '<')
4510 {
4511 /* For 'autoread' -1 means to use global value. */
4512 if ((int *)varp == &curbuf->b_p_ar
4513 && opt_flags == OPT_LOCAL)
4514 value = -1;
4515 else
4516 value = *(int *)get_varp_scope(&(options[opt_idx]),
4517 OPT_GLOBAL);
4518 }
4519 else
4520 {
4521 /*
4522 * ":set invopt": invert
4523 * ":set opt" or ":set noopt": set or reset
4524 */
4525 if (nextchar != NUL && !vim_iswhite(afterchar))
4526 {
4527 errmsg = e_trailing;
4528 goto skip;
4529 }
4530 if (prefix == 2) /* inv */
4531 value = *(int *)(varp) ^ 1;
4532 else
4533 value = prefix;
4534 }
4535
4536 errmsg = set_bool_option(opt_idx, varp, (int)value,
4537 opt_flags);
4538 }
4539 else /* numeric or string */
4540 {
4541 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4542 || prefix != 1)
4543 {
4544 errmsg = e_invarg;
4545 goto skip;
4546 }
4547
4548 if (flags & P_NUM) /* numeric */
4549 {
4550 /*
4551 * Different ways to set a number option:
4552 * & set to default value
4553 * < set to global value
4554 * <xx> accept special key codes for 'wildchar'
4555 * c accept any non-digit for 'wildchar'
4556 * [-]0-9 set number
4557 * other error
4558 */
4559 ++arg;
4560 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004561 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 ((flags & P_VI_DEF) || cp_val)
4563 ? VI_DEFAULT : VIM_DEFAULT];
4564 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004565 {
4566 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4567 * use the global value. */
4568 if ((long *)varp == &curbuf->b_p_ul
4569 && opt_flags == OPT_LOCAL)
4570 value = NO_LOCAL_UNDOLEVEL;
4571 else
4572 value = *(long *)get_varp_scope(
4573 &(options[opt_idx]), OPT_GLOBAL);
4574 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004575 else if (((long *)varp == &p_wc
4576 || (long *)varp == &p_wcm)
4577 && (*arg == '<'
4578 || *arg == '^'
4579 || ((!arg[1] || vim_iswhite(arg[1]))
4580 && !VIM_ISDIGIT(*arg))))
4581 {
4582 value = string_to_key(arg);
4583 if (value == 0 && (long *)varp != &p_wcm)
4584 {
4585 errmsg = e_invarg;
4586 goto skip;
4587 }
4588 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004589 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4590 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004591 /* Allow negative (for 'undolevels'), octal and
4592 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004593 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4594 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004595 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4596 {
4597 errmsg = e_invarg;
4598 goto skip;
4599 }
4600 }
4601 else
4602 {
4603 errmsg = (char_u *)N_("E521: Number required after =");
4604 goto skip;
4605 }
4606
4607 if (adding)
4608 value = *(long *)varp + value;
4609 if (prepending)
4610 value = *(long *)varp * value;
4611 if (removing)
4612 value = *(long *)varp - value;
4613 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004614 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615 }
4616 else if (opt_idx >= 0) /* string */
4617 {
4618 char_u *save_arg = NULL;
4619 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004620 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004621 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004622 char_u *origval = NULL;
4623#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4624 char_u *saved_origval = NULL;
4625#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004626 unsigned newlen;
4627 int comma;
4628 int bs;
4629 int new_value_alloced; /* new string option
4630 was allocated */
4631
4632 /* When using ":set opt=val" for a global option
4633 * with a local value the local value will be
4634 * reset, use the global value here. */
4635 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004636 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004637 varp = options[opt_idx].var;
4638
4639 /* The old value is kept until we are sure that the
4640 * new value is valid. */
4641 oldval = *(char_u **)varp;
4642 if (nextchar == '&') /* set to default val */
4643 {
4644 newval = options[opt_idx].def_val[
4645 ((flags & P_VI_DEF) || cp_val)
4646 ? VI_DEFAULT : VIM_DEFAULT];
4647 if ((char_u **)varp == &p_bg)
4648 {
4649 /* guess the value of 'background' */
4650#ifdef FEAT_GUI
4651 if (gui.in_use)
4652 newval = gui_bg_default();
4653 else
4654#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004655 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004656 }
4657
4658 /* expand environment variables and ~ (since the
4659 * default value was already expanded, only
4660 * required when an environment variable was set
4661 * later */
4662 if (newval == NULL)
4663 newval = empty_option;
4664 else
4665 {
4666 s = option_expand(opt_idx, newval);
4667 if (s == NULL)
4668 s = newval;
4669 newval = vim_strsave(s);
4670 }
4671 new_value_alloced = TRUE;
4672 }
4673 else if (nextchar == '<') /* set to global val */
4674 {
4675 newval = vim_strsave(*(char_u **)get_varp_scope(
4676 &(options[opt_idx]), OPT_GLOBAL));
4677 new_value_alloced = TRUE;
4678 }
4679 else
4680 {
4681 ++arg; /* jump to after the '=' or ':' */
4682
4683 /*
4684 * Set 'keywordprg' to ":help" if an empty
4685 * value was passed to :set by the user.
4686 * Misuse errbuf[] for the resulting string.
4687 */
4688 if (varp == (char_u *)&p_kp
4689 && (*arg == NUL || *arg == ' '))
4690 {
4691 STRCPY(errbuf, ":help");
4692 save_arg = arg;
4693 arg = errbuf;
4694 }
4695 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004696 * Convert 'backspace' number to string, for
4697 * adding, prepending and removing string.
4698 */
4699 else if (varp == (char_u *)&p_bs
4700 && VIM_ISDIGIT(**(char_u **)varp))
4701 {
4702 i = getdigits((char_u **)varp);
4703 switch (i)
4704 {
4705 case 0:
4706 *(char_u **)varp = empty_option;
4707 break;
4708 case 1:
4709 *(char_u **)varp = vim_strsave(
4710 (char_u *)"indent,eol");
4711 break;
4712 case 2:
4713 *(char_u **)varp = vim_strsave(
4714 (char_u *)"indent,eol,start");
4715 break;
4716 }
4717 vim_free(oldval);
4718 oldval = *(char_u **)varp;
4719 }
4720 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004721 * Convert 'whichwrap' number to string, for
4722 * backwards compatibility with Vim 3.0.
4723 * Misuse errbuf[] for the resulting string.
4724 */
4725 else if (varp == (char_u *)&p_ww
4726 && VIM_ISDIGIT(*arg))
4727 {
4728 *errbuf = NUL;
4729 i = getdigits(&arg);
4730 if (i & 1)
4731 STRCAT(errbuf, "b,");
4732 if (i & 2)
4733 STRCAT(errbuf, "s,");
4734 if (i & 4)
4735 STRCAT(errbuf, "h,l,");
4736 if (i & 8)
4737 STRCAT(errbuf, "<,>,");
4738 if (i & 16)
4739 STRCAT(errbuf, "[,],");
4740 if (*errbuf != NUL) /* remove trailing , */
4741 errbuf[STRLEN(errbuf) - 1] = NUL;
4742 save_arg = arg;
4743 arg = errbuf;
4744 }
4745 /*
4746 * Remove '>' before 'dir' and 'bdir', for
4747 * backwards compatibility with version 3.0
4748 */
4749 else if ( *arg == '>'
4750 && (varp == (char_u *)&p_dir
4751 || varp == (char_u *)&p_bdir))
4752 {
4753 ++arg;
4754 }
4755
4756 /* When setting the local value of a global
4757 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004758 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 && (opt_flags & OPT_LOCAL))
4760 origval = *(char_u **)get_varp(
4761 &options[opt_idx]);
4762 else
4763 origval = oldval;
4764
4765 /*
4766 * Copy the new string into allocated memory.
4767 * Can't use set_string_option_direct(), because
4768 * we need to remove the backslashes.
4769 */
4770 /* get a bit too much */
4771 newlen = (unsigned)STRLEN(arg) + 1;
4772 if (adding || prepending || removing)
4773 newlen += (unsigned)STRLEN(origval) + 1;
4774 newval = alloc(newlen);
4775 if (newval == NULL) /* out of mem, don't change */
4776 break;
4777 s = newval;
4778
4779 /*
4780 * Copy the string, skip over escaped chars.
4781 * For MS-DOS and WIN32 backslashes before normal
4782 * file name characters are not removed, and keep
4783 * backslash at start, for "\\machine\path", but
4784 * do remove it for "\\\\machine\\path".
4785 * The reverse is found in ExpandOldSetting().
4786 */
4787 while (*arg && !vim_iswhite(*arg))
4788 {
4789 if (*arg == '\\' && arg[1] != NUL
4790#ifdef BACKSLASH_IN_FILENAME
4791 && !((flags & P_EXPAND)
4792 && vim_isfilec(arg[1])
4793 && (arg[1] != '\\'
4794 || (s == newval
4795 && arg[2] != '\\')))
4796#endif
4797 )
4798 ++arg; /* remove backslash */
4799#ifdef FEAT_MBYTE
4800 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004801 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004802 {
4803 /* copy multibyte char */
4804 mch_memmove(s, arg, (size_t)i);
4805 arg += i;
4806 s += i;
4807 }
4808 else
4809#endif
4810 *s++ = *arg++;
4811 }
4812 *s = NUL;
4813
4814 /*
4815 * Expand environment variables and ~.
4816 * Don't do it when adding without inserting a
4817 * comma.
4818 */
4819 if (!(adding || prepending || removing)
4820 || (flags & P_COMMA))
4821 {
4822 s = option_expand(opt_idx, newval);
4823 if (s != NULL)
4824 {
4825 vim_free(newval);
4826 newlen = (unsigned)STRLEN(s) + 1;
4827 if (adding || prepending || removing)
4828 newlen += (unsigned)STRLEN(origval) + 1;
4829 newval = alloc(newlen);
4830 if (newval == NULL)
4831 break;
4832 STRCPY(newval, s);
4833 }
4834 }
4835
4836 /* locate newval[] in origval[] when removing it
4837 * and when adding to avoid duplicates */
4838 i = 0; /* init for GCC */
4839 if (removing || (flags & P_NODUP))
4840 {
4841 i = (int)STRLEN(newval);
4842 bs = 0;
4843 for (s = origval; *s; ++s)
4844 {
4845 if ((!(flags & P_COMMA)
4846 || s == origval
4847 || (s[-1] == ',' && !(bs & 1)))
4848 && STRNCMP(s, newval, i) == 0
4849 && (!(flags & P_COMMA)
4850 || s[i] == ','
4851 || s[i] == NUL))
4852 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004853 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004854 * even number of backslashes or a single
4855 * backslash preceded by a comma before it
4856 * is recognized as a separator */
4857 if ((s > origval + 1
4858 && s[-1] == '\\'
4859 && s[-2] != ',')
4860 || (s == origval + 1
4861 && s[-1] == '\\'))
4862
Bram Moolenaar071d4272004-06-13 20:20:40 +00004863 ++bs;
4864 else
4865 bs = 0;
4866 }
4867
4868 /* do not add if already there */
4869 if ((adding || prepending) && *s)
4870 {
4871 prepending = FALSE;
4872 adding = FALSE;
4873 STRCPY(newval, origval);
4874 }
4875 }
4876
4877 /* concatenate the two strings; add a ',' if
4878 * needed */
4879 if (adding || prepending)
4880 {
4881 comma = ((flags & P_COMMA) && *origval != NUL
4882 && *newval != NUL);
4883 if (adding)
4884 {
4885 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004886 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004887 if (comma && i > 1
4888 && (flags & P_ONECOMMA) == P_ONECOMMA
4889 && origval[i - 1] == ','
4890 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004891 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004892 mch_memmove(newval + i + comma, newval,
4893 STRLEN(newval) + 1);
4894 mch_memmove(newval, origval, (size_t)i);
4895 }
4896 else
4897 {
4898 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004899 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004900 }
4901 if (comma)
4902 newval[i] = ',';
4903 }
4904
4905 /* Remove newval[] from origval[]. (Note: "i" has
4906 * been set above and is used here). */
4907 if (removing)
4908 {
4909 STRCPY(newval, origval);
4910 if (*s)
4911 {
4912 /* may need to remove a comma */
4913 if (flags & P_COMMA)
4914 {
4915 if (s == origval)
4916 {
4917 /* include comma after string */
4918 if (s[i] == ',')
4919 ++i;
4920 }
4921 else
4922 {
4923 /* include comma before string */
4924 --s;
4925 ++i;
4926 }
4927 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004928 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004929 }
4930 }
4931
4932 if (flags & P_FLAGLIST)
4933 {
4934 /* Remove flags that appear twice. */
4935 for (s = newval; *s; ++s)
4936 if ((!(flags & P_COMMA) || *s != ',')
4937 && vim_strchr(s + 1, *s) != NULL)
4938 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004939 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004940 --s;
4941 }
4942 }
4943
4944 if (save_arg != NULL) /* number for 'whichwrap' */
4945 arg = save_arg;
4946 new_value_alloced = TRUE;
4947 }
4948
4949 /* Set the new value. */
4950 *(char_u **)(varp) = newval;
4951
Bram Moolenaar53744302015-07-17 17:38:22 +02004952#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004953 if (!starting
4954# ifdef FEAT_CRYPT
4955 && options[opt_idx].indir != PV_KEY
4956# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004957 && origval != NULL)
4958 /* origval may be freed by
4959 * did_set_string_option(), make a copy. */
4960 saved_origval = vim_strsave(origval);
4961#endif
4962
Bram Moolenaar071d4272004-06-13 20:20:40 +00004963 /* Handle side effects, and set the global value for
4964 * ":set" on local options. */
4965 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4966 new_value_alloced, oldval, errbuf, opt_flags);
4967
4968 /* If error detected, print the error message. */
4969 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004970 {
4971#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4972 vim_free(saved_origval);
4973#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004974 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004975 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004976#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4977 if (saved_origval != NULL)
4978 {
4979 char_u buf_type[7];
4980
4981 sprintf((char *)buf_type, "%s",
4982 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004983 set_vim_var_string(VV_OPTION_NEW,
4984 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004985 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4986 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4987 apply_autocmds(EVENT_OPTIONSET,
4988 (char_u *)options[opt_idx].fullname,
4989 NULL, FALSE, NULL);
4990 reset_v_option_vars();
4991 vim_free(saved_origval);
4992 }
4993#endif
4994
Bram Moolenaar071d4272004-06-13 20:20:40 +00004995 }
4996 else /* key code option */
4997 {
4998 char_u *p;
4999
5000 if (nextchar == '&')
5001 {
5002 if (add_termcap_entry(key_name, TRUE) == FAIL)
5003 errmsg = (char_u *)N_("E522: Not found in termcap");
5004 }
5005 else
5006 {
5007 ++arg; /* jump to after the '=' or ':' */
5008 for (p = arg; *p && !vim_iswhite(*p); ++p)
5009 if (*p == '\\' && p[1] != NUL)
5010 ++p;
5011 nextchar = *p;
5012 *p = NUL;
5013 add_termcode(key_name, arg, FALSE);
5014 *p = nextchar;
5015 }
5016 if (full_screen)
5017 ttest(FALSE);
5018 redraw_all_later(CLEAR);
5019 }
5020 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005021
Bram Moolenaar071d4272004-06-13 20:20:40 +00005022 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005023 did_set_option(opt_idx, opt_flags,
5024 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005025 }
5026
5027skip:
5028 /*
5029 * Advance to next argument.
5030 * - skip until a blank found, taking care of backslashes
5031 * - skip blanks
5032 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5033 */
5034 for (i = 0; i < 2 ; ++i)
5035 {
5036 while (*arg != NUL && !vim_iswhite(*arg))
5037 if (*arg++ == '\\' && *arg != NUL)
5038 ++arg;
5039 arg = skipwhite(arg);
5040 if (*arg != '=')
5041 break;
5042 }
5043 }
5044
5045 if (errmsg != NULL)
5046 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005047 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005048 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005049 if (i + (arg - startarg) < IOSIZE)
5050 {
5051 /* append the argument with the error */
5052 STRCAT(IObuff, ": ");
5053 mch_memmove(IObuff + i, startarg, (arg - startarg));
5054 IObuff[i + (arg - startarg)] = NUL;
5055 }
5056 /* make sure all characters are printable */
5057 trans_characters(IObuff, IOSIZE);
5058
5059 ++no_wait_return; /* wait_return done later */
5060 emsg(IObuff); /* show error highlighted */
5061 --no_wait_return;
5062
5063 return FAIL;
5064 }
5065
5066 arg = skipwhite(arg);
5067 }
5068
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005069theend:
5070 if (silent_mode && did_show)
5071 {
5072 /* After displaying option values in silent mode. */
5073 silent_mode = FALSE;
5074 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5075 msg_putchar('\n');
5076 cursor_on(); /* msg_start() switches it off */
5077 out_flush();
5078 silent_mode = TRUE;
5079 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5080 }
5081
Bram Moolenaar071d4272004-06-13 20:20:40 +00005082 return OK;
5083}
5084
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005085/*
5086 * Call this when an option has been given a new value through a user command.
5087 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5088 */
5089 static void
5090did_set_option(opt_idx, opt_flags, new_value)
5091 int opt_idx;
5092 int opt_flags; /* possibly with OPT_MODELINE */
5093 int new_value; /* value was replaced completely */
5094{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005095 long_u *p;
5096
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005097 options[opt_idx].flags |= P_WAS_SET;
5098
5099 /* When an option is set in the sandbox, from a modeline or in secure mode
5100 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005101 * flag. */
5102 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005103 if (secure
5104#ifdef HAVE_SANDBOX
5105 || sandbox != 0
5106#endif
5107 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005108 *p = *p | P_INSECURE;
5109 else if (new_value)
5110 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005111}
5112
Bram Moolenaar071d4272004-06-13 20:20:40 +00005113 static char_u *
5114illegal_char(errbuf, c)
5115 char_u *errbuf;
5116 int c;
5117{
5118 if (errbuf == NULL)
5119 return (char_u *)"";
5120 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005121 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005122 return errbuf;
5123}
5124
5125/*
5126 * Convert a key name or string into a key value.
5127 * Used for 'wildchar' and 'cedit' options.
5128 */
5129 static int
5130string_to_key(arg)
5131 char_u *arg;
5132{
5133 if (*arg == '<')
5134 return find_key_option(arg + 1);
5135 if (*arg == '^')
5136 return Ctrl_chr(arg[1]);
5137 return *arg;
5138}
5139
5140#ifdef FEAT_CMDWIN
5141/*
5142 * Check value of 'cedit' and set cedit_key.
5143 * Returns NULL if value is OK, error message otherwise.
5144 */
5145 static char_u *
5146check_cedit()
5147{
5148 int n;
5149
5150 if (*p_cedit == NUL)
5151 cedit_key = -1;
5152 else
5153 {
5154 n = string_to_key(p_cedit);
5155 if (vim_isprintc(n))
5156 return e_invarg;
5157 cedit_key = n;
5158 }
5159 return NULL;
5160}
5161#endif
5162
5163#ifdef FEAT_TITLE
5164/*
5165 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5166 * maketitle() to create and display it.
5167 * When switching the title or icon off, call mch_restore_title() to get
5168 * the old value back.
5169 */
5170 static void
5171did_set_title(icon)
5172 int icon; /* Did set icon instead of title */
5173{
5174 if (starting != NO_SCREEN
5175#ifdef FEAT_GUI
5176 && !gui.starting
5177#endif
5178 )
5179 {
5180 maketitle();
5181 if (icon)
5182 {
5183 if (!p_icon)
5184 mch_restore_title(2);
5185 }
5186 else
5187 {
5188 if (!p_title)
5189 mch_restore_title(1);
5190 }
5191 }
5192}
5193#endif
5194
5195/*
5196 * set_options_bin - called when 'bin' changes value.
5197 */
5198 void
5199set_options_bin(oldval, newval, opt_flags)
5200 int oldval;
5201 int newval;
5202 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5203{
5204 /*
5205 * The option values that are changed when 'bin' changes are
5206 * copied when 'bin is set and restored when 'bin' is reset.
5207 */
5208 if (newval)
5209 {
5210 if (!oldval) /* switched on */
5211 {
5212 if (!(opt_flags & OPT_GLOBAL))
5213 {
5214 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5215 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5216 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5217 curbuf->b_p_et_nobin = curbuf->b_p_et;
5218 }
5219 if (!(opt_flags & OPT_LOCAL))
5220 {
5221 p_tw_nobin = p_tw;
5222 p_wm_nobin = p_wm;
5223 p_ml_nobin = p_ml;
5224 p_et_nobin = p_et;
5225 }
5226 }
5227
5228 if (!(opt_flags & OPT_GLOBAL))
5229 {
5230 curbuf->b_p_tw = 0; /* no automatic line wrap */
5231 curbuf->b_p_wm = 0; /* no automatic line wrap */
5232 curbuf->b_p_ml = 0; /* no modelines */
5233 curbuf->b_p_et = 0; /* no expandtab */
5234 }
5235 if (!(opt_flags & OPT_LOCAL))
5236 {
5237 p_tw = 0;
5238 p_wm = 0;
5239 p_ml = FALSE;
5240 p_et = FALSE;
5241 p_bin = TRUE; /* needed when called for the "-b" argument */
5242 }
5243 }
5244 else if (oldval) /* switched off */
5245 {
5246 if (!(opt_flags & OPT_GLOBAL))
5247 {
5248 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5249 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5250 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5251 curbuf->b_p_et = curbuf->b_p_et_nobin;
5252 }
5253 if (!(opt_flags & OPT_LOCAL))
5254 {
5255 p_tw = p_tw_nobin;
5256 p_wm = p_wm_nobin;
5257 p_ml = p_ml_nobin;
5258 p_et = p_et_nobin;
5259 }
5260 }
5261}
5262
5263#ifdef FEAT_VIMINFO
5264/*
5265 * Find the parameter represented by the given character (eg ', :, ", or /),
5266 * and return its associated value in the 'viminfo' string.
5267 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005268 * If the parameter is not specified in the string or there is no following
5269 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005270 */
5271 int
5272get_viminfo_parameter(type)
5273 int type;
5274{
5275 char_u *p;
5276
5277 p = find_viminfo_parameter(type);
5278 if (p != NULL && VIM_ISDIGIT(*p))
5279 return atoi((char *)p);
5280 return -1;
5281}
5282
5283/*
5284 * Find the parameter represented by the given character (eg ''', ':', '"', or
5285 * '/') in the 'viminfo' option and return a pointer to the string after it.
5286 * Return NULL if the parameter is not specified in the string.
5287 */
5288 char_u *
5289find_viminfo_parameter(type)
5290 int type;
5291{
5292 char_u *p;
5293
5294 for (p = p_viminfo; *p; ++p)
5295 {
5296 if (*p == type)
5297 return p + 1;
5298 if (*p == 'n') /* 'n' is always the last one */
5299 break;
5300 p = vim_strchr(p, ','); /* skip until next ',' */
5301 if (p == NULL) /* hit the end without finding parameter */
5302 break;
5303 }
5304 return NULL;
5305}
5306#endif
5307
5308/*
5309 * Expand environment variables for some string options.
5310 * These string options cannot be indirect!
5311 * If "val" is NULL expand the current value of the option.
5312 * Return pointer to NameBuff, or NULL when not expanded.
5313 */
5314 static char_u *
5315option_expand(opt_idx, val)
5316 int opt_idx;
5317 char_u *val;
5318{
5319 /* if option doesn't need expansion nothing to do */
5320 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5321 return NULL;
5322
5323 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5324 * expand_env() would truncate the string. */
5325 if (val != NULL && STRLEN(val) > MAXPATHL)
5326 return NULL;
5327
5328 if (val == NULL)
5329 val = *(char_u **)options[opt_idx].var;
5330
5331 /*
5332 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5333 * Escape spaces when expanding 'tags', they are used to separate file
5334 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005335 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005336 */
5337 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005338 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005339#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005340 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5341#endif
5342 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5344 return NULL;
5345
5346 return NameBuff;
5347}
5348
5349/*
5350 * After setting various option values: recompute variables that depend on
5351 * option values.
5352 */
5353 static void
5354didset_options()
5355{
5356 /* initialize the table for 'iskeyword' et.al. */
5357 (void)init_chartab();
5358
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005359#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005360 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005361#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005363 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005364#ifdef FEAT_SESSION
5365 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5366 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5367#endif
5368#ifdef FEAT_FOLDING
5369 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5370#endif
5371 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005372 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005373#ifdef FEAT_VIRTUALEDIT
5374 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5375#endif
5376#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5377 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5378#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005379#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005380 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005381 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005382 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005383 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005384#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5386 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5387#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005388#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005389 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5390#endif
5391#ifdef FEAT_CMDWIN
5392 /* set cedit_key */
5393 (void)check_cedit();
5394#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005395#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005396 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005397#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005398#ifdef FEAT_LINEBREAK
5399 /* initialize the table for 'breakat'. */
5400 fill_breakat_flags();
5401#endif
5402
5403}
5404
5405/*
5406 * More side effects of setting options.
5407 */
5408 static void
5409didset_options2()
5410{
5411 /* Initialize the highlight_attr[] table. */
5412 (void)highlight_changed();
5413
5414 /* Parse default for 'wildmode' */
5415 check_opt_wim();
5416
5417 (void)set_chars_option(&p_lcs);
5418#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5419 /* Parse default for 'fillchars'. */
5420 (void)set_chars_option(&p_fcs);
5421#endif
5422
5423#ifdef FEAT_CLIPBOARD
5424 /* Parse default for 'clipboard' */
5425 (void)check_clipboard_option();
5426#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005427}
5428
5429/*
5430 * Check for string options that are NULL (normally only termcap options).
5431 */
5432 void
5433check_options()
5434{
5435 int opt_idx;
5436
5437 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5438 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5439 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5440}
5441
5442/*
5443 * Check string options in a buffer for NULL value.
5444 */
5445 void
5446check_buf_options(buf)
5447 buf_T *buf;
5448{
5449#if defined(FEAT_QUICKFIX)
5450 check_string_option(&buf->b_p_bh);
5451 check_string_option(&buf->b_p_bt);
5452#endif
5453#ifdef FEAT_MBYTE
5454 check_string_option(&buf->b_p_fenc);
5455#endif
5456 check_string_option(&buf->b_p_ff);
5457#ifdef FEAT_FIND_ID
5458 check_string_option(&buf->b_p_def);
5459 check_string_option(&buf->b_p_inc);
5460# ifdef FEAT_EVAL
5461 check_string_option(&buf->b_p_inex);
5462# endif
5463#endif
5464#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5465 check_string_option(&buf->b_p_inde);
5466 check_string_option(&buf->b_p_indk);
5467#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005468#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5469 check_string_option(&buf->b_p_bexpr);
5470#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005471#if defined(FEAT_CRYPT)
5472 check_string_option(&buf->b_p_cm);
5473#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005474#if defined(FEAT_EVAL)
5475 check_string_option(&buf->b_p_fex);
5476#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005477#ifdef FEAT_CRYPT
5478 check_string_option(&buf->b_p_key);
5479#endif
5480 check_string_option(&buf->b_p_kp);
5481 check_string_option(&buf->b_p_mps);
5482 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005483 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005484 check_string_option(&buf->b_p_isk);
5485#ifdef FEAT_COMMENTS
5486 check_string_option(&buf->b_p_com);
5487#endif
5488#ifdef FEAT_FOLDING
5489 check_string_option(&buf->b_p_cms);
5490#endif
5491 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005492#ifdef FEAT_TEXTOBJ
5493 check_string_option(&buf->b_p_qe);
5494#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495#ifdef FEAT_SYN_HL
5496 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005497#endif
5498#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005499 check_string_option(&buf->b_s.b_p_spc);
5500 check_string_option(&buf->b_s.b_p_spf);
5501 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005502#endif
5503#ifdef FEAT_SEARCHPATH
5504 check_string_option(&buf->b_p_sua);
5505#endif
5506#ifdef FEAT_CINDENT
5507 check_string_option(&buf->b_p_cink);
5508 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005509 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005510#endif
5511#ifdef FEAT_AUTOCMD
5512 check_string_option(&buf->b_p_ft);
5513#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5515 check_string_option(&buf->b_p_cinw);
5516#endif
5517#ifdef FEAT_INS_EXPAND
5518 check_string_option(&buf->b_p_cpt);
5519#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005520#ifdef FEAT_COMPL_FUNC
5521 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005522 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005524#ifdef FEAT_KEYMAP
5525 check_string_option(&buf->b_p_keymap);
5526#endif
5527#ifdef FEAT_QUICKFIX
5528 check_string_option(&buf->b_p_gp);
5529 check_string_option(&buf->b_p_mp);
5530 check_string_option(&buf->b_p_efm);
5531#endif
5532 check_string_option(&buf->b_p_ep);
5533 check_string_option(&buf->b_p_path);
5534 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005535 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536#ifdef FEAT_INS_EXPAND
5537 check_string_option(&buf->b_p_dict);
5538 check_string_option(&buf->b_p_tsr);
5539#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005540#ifdef FEAT_LISP
5541 check_string_option(&buf->b_p_lw);
5542#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005543 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005544}
5545
5546/*
5547 * Free the string allocated for an option.
5548 * Checks for the string being empty_option. This may happen if we're out of
5549 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5550 * check_options().
5551 * Does NOT check for P_ALLOCED flag!
5552 */
5553 void
5554free_string_option(p)
5555 char_u *p;
5556{
5557 if (p != empty_option)
5558 vim_free(p);
5559}
5560
5561 void
5562clear_string_option(pp)
5563 char_u **pp;
5564{
5565 if (*pp != empty_option)
5566 vim_free(*pp);
5567 *pp = empty_option;
5568}
5569
5570 static void
5571check_string_option(pp)
5572 char_u **pp;
5573{
5574 if (*pp == NULL)
5575 *pp = empty_option;
5576}
5577
5578/*
5579 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5580 */
5581 void
5582set_term_option_alloced(p)
5583 char_u **p;
5584{
5585 int opt_idx;
5586
5587 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5588 if (options[opt_idx].var == (char_u *)p)
5589 {
5590 options[opt_idx].flags |= P_ALLOCED;
5591 return;
5592 }
5593 return; /* cannot happen: didn't find it! */
5594}
5595
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005596#if defined(FEAT_EVAL) || defined(PROTO)
5597/*
5598 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5599 * Return FALSE when it wasn't.
5600 * Return -1 for an unknown option.
5601 */
5602 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005603was_set_insecurely(opt, opt_flags)
5604 char_u *opt;
5605 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005606{
5607 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005608 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005609
5610 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005611 {
5612 flagp = insecure_flag(idx, opt_flags);
5613 return (*flagp & P_INSECURE) != 0;
5614 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005615 EMSG2(_(e_intern2), "was_set_insecurely()");
5616 return -1;
5617}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005618
5619/*
5620 * Get a pointer to the flags used for the P_INSECURE flag of option
5621 * "opt_idx". For some local options a local flags field is used.
5622 */
5623 static long_u *
5624insecure_flag(opt_idx, opt_flags)
5625 int opt_idx;
5626 int opt_flags;
5627{
5628 if (opt_flags & OPT_LOCAL)
5629 switch ((int)options[opt_idx].indir)
5630 {
5631#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005632 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005633#endif
5634#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005635# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005636 case PV_FDE: return &curwin->w_p_fde_flags;
5637 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005638# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005639# ifdef FEAT_BEVAL
5640 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5641# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005642# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005643 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005644# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005645 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005646# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005647 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005648# endif
5649#endif
5650 }
5651
5652 /* Nothing special, return global flags field. */
5653 return &options[opt_idx].flags;
5654}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005655#endif
5656
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005657#ifdef FEAT_TITLE
5658static void redraw_titles __ARGS((void));
5659
5660/*
5661 * Redraw the window title and/or tab page text later.
5662 */
5663static void redraw_titles()
5664{
5665 need_maketitle = TRUE;
5666# ifdef FEAT_WINDOWS
5667 redraw_tabline = TRUE;
5668# endif
5669}
5670#endif
5671
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672/*
5673 * Set a string option to a new value (without checking the effect).
5674 * The string is copied into allocated memory.
5675 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005676 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005677 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005678 */
5679 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005680set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681 char_u *name;
5682 int opt_idx;
5683 char_u *val;
5684 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005685 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005686{
5687 char_u *s;
5688 char_u **varp;
5689 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005690 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691
Bram Moolenaar89d40322006-08-29 15:30:07 +00005692 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005694 idx = findoption(name);
5695 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005696 {
5697 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005698 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005700 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701 }
5702
Bram Moolenaar89d40322006-08-29 15:30:07 +00005703 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704 return;
5705
5706 s = vim_strsave(val);
5707 if (s != NULL)
5708 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005709 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005711 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712 free_string_option(*varp);
5713 *varp = s;
5714
5715 /* For buffer/window local option may also set the global value. */
5716 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005717 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005718
Bram Moolenaar89d40322006-08-29 15:30:07 +00005719 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005720
5721 /* When setting both values of a global option with a local value,
5722 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005723 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005724 {
5725 free_string_option(*varp);
5726 *varp = empty_option;
5727 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005728# ifdef FEAT_EVAL
5729 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005730 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005731 set_sid == 0 ? current_SID : set_sid);
5732# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005733 }
5734}
5735
5736/*
5737 * Set global value for string option when it's a local option.
5738 */
5739 static void
5740set_string_option_global(opt_idx, varp)
5741 int opt_idx; /* option index */
5742 char_u **varp; /* pointer to option variable */
5743{
5744 char_u **p, *s;
5745
5746 /* the global value is always allocated */
5747 if (options[opt_idx].var == VAR_WIN)
5748 p = (char_u **)GLOBAL_WO(varp);
5749 else
5750 p = (char_u **)options[opt_idx].var;
5751 if (options[opt_idx].indir != PV_NONE
5752 && p != varp
5753 && (s = vim_strsave(*varp)) != NULL)
5754 {
5755 free_string_option(*p);
5756 *p = s;
5757 }
5758}
5759
5760/*
5761 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005762 *
5763 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005765 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005766set_string_option(opt_idx, value, opt_flags)
5767 int opt_idx;
5768 char_u *value;
5769 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5770{
5771 char_u *s;
5772 char_u **varp;
5773 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005774#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5775 char_u *saved_oldval = NULL;
5776#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005777 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005778
5779 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005780 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005781
5782 s = vim_strsave(value);
5783 if (s != NULL)
5784 {
5785 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5786 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005787 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005788 ? OPT_GLOBAL : OPT_LOCAL)
5789 : opt_flags);
5790 oldval = *varp;
5791 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005792
5793#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005794 if (!starting
5795# ifdef FEAT_CRYPT
5796 && options[opt_idx].indir != PV_KEY
5797# endif
5798 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005799 saved_oldval = vim_strsave(oldval);
5800#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005801 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5802 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005803 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005804
5805 /* call autocomamnd after handling side effects */
5806#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5807 if (saved_oldval != NULL)
5808 {
5809 char_u buf_type[7];
5810 sprintf((char *)buf_type, "%s",
5811 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005812 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5813 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005814 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5815 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5816 reset_v_option_vars();
5817 vim_free(saved_oldval);
5818 }
5819#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005820 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005821 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005822}
5823
5824/*
5825 * Handle string options that need some action to perform when changed.
5826 * Returns NULL for success, or an error message for an error.
5827 */
5828 static char_u *
5829did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5830 opt_flags)
5831 int opt_idx; /* index in options[] table */
5832 char_u **varp; /* pointer to the option variable */
5833 int new_value_alloced; /* new value was allocated */
5834 char_u *oldval; /* previous value of the option */
5835 char_u *errbuf; /* buffer for errors, or NULL */
5836 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5837{
5838 char_u *errmsg = NULL;
5839 char_u *s, *p;
5840 int did_chartab = FALSE;
5841 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005842 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005843#ifdef FEAT_GUI
5844 /* set when changing an option that only requires a redraw in the GUI */
5845 int redraw_gui_only = FALSE;
5846#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847
5848 /* Get the global option to compare with, otherwise we would have to check
5849 * two values for all local options. */
5850 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5851
5852 /* Disallow changing some options from secure mode */
5853 if ((secure
5854#ifdef HAVE_SANDBOX
5855 || sandbox != 0
5856#endif
5857 ) && (options[opt_idx].flags & P_SECURE))
5858 {
5859 errmsg = e_secure;
5860 }
5861
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005862 /* Check for a "normal" file name in some options. Disallow a path
5863 * separator (slash and/or backslash), wildcards and characters that are
5864 * often illegal in a file name. */
5865 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005866 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005867 {
5868 errmsg = e_invarg;
5869 }
5870
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871 /* 'term' */
5872 else if (varp == &T_NAME)
5873 {
5874 if (T_NAME[0] == NUL)
5875 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5876#ifdef FEAT_GUI
5877 if (gui.in_use)
5878 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5879 else if (term_is_gui(T_NAME))
5880 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5881#endif
5882 else if (set_termname(T_NAME) == FAIL)
5883 errmsg = (char_u *)N_("E522: Not found in termcap");
5884 else
5885 /* Screen colors may have changed. */
5886 redraw_later_clear();
5887 }
5888
5889 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005890 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005892 char_u *bkc = p_bkc;
5893 unsigned int *flags = &bkc_flags;
5894
5895 if (opt_flags & OPT_LOCAL)
5896 {
5897 bkc = curbuf->b_p_bkc;
5898 flags = &curbuf->b_bkc_flags;
5899 }
5900
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005901 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5902 /* make the local value empty: use the global value */
5903 *flags = 0;
5904 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005906 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5907 errmsg = e_invarg;
5908 if ((((int)*flags & BKC_AUTO) != 0)
5909 + (((int)*flags & BKC_YES) != 0)
5910 + (((int)*flags & BKC_NO) != 0) != 1)
5911 {
5912 /* Must have exactly one of "auto", "yes" and "no". */
5913 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5914 errmsg = e_invarg;
5915 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916 }
5917 }
5918
5919 /* 'backupext' and 'patchmode' */
5920 else if (varp == &p_bex || varp == &p_pm)
5921 {
5922 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5923 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5924 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5925 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005926#ifdef FEAT_LINEBREAK
5927 /* 'breakindentopt' */
5928 else if (varp == &curwin->w_p_briopt)
5929 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005930 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005931 errmsg = e_invarg;
5932 }
5933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005934
5935 /*
5936 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5937 * If the new option is invalid, use old value. 'lisp' option: refill
5938 * chartab[] for '-' char
5939 */
5940 else if ( varp == &p_isi
5941 || varp == &(curbuf->b_p_isk)
5942 || varp == &p_isp
5943 || varp == &p_isf)
5944 {
5945 if (init_chartab() == FAIL)
5946 {
5947 did_chartab = TRUE; /* need to restore it below */
5948 errmsg = e_invarg; /* error in value */
5949 }
5950 }
5951
5952 /* 'helpfile' */
5953 else if (varp == &p_hf)
5954 {
5955 /* May compute new values for $VIM and $VIMRUNTIME */
5956 if (didset_vim)
5957 {
5958 vim_setenv((char_u *)"VIM", (char_u *)"");
5959 didset_vim = FALSE;
5960 }
5961 if (didset_vimruntime)
5962 {
5963 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5964 didset_vimruntime = FALSE;
5965 }
5966 }
5967
Bram Moolenaar1a384422010-07-14 19:53:30 +02005968#ifdef FEAT_SYN_HL
5969 /* 'colorcolumn' */
5970 else if (varp == &curwin->w_p_cc)
5971 errmsg = check_colorcolumn(curwin);
5972#endif
5973
Bram Moolenaar071d4272004-06-13 20:20:40 +00005974#ifdef FEAT_MULTI_LANG
5975 /* 'helplang' */
5976 else if (varp == &p_hlg)
5977 {
5978 /* Check for "", "ab", "ab,cd", etc. */
5979 for (s = p_hlg; *s != NUL; s += 3)
5980 {
5981 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5982 {
5983 errmsg = e_invarg;
5984 break;
5985 }
5986 if (s[2] == NUL)
5987 break;
5988 }
5989 }
5990#endif
5991
5992 /* 'highlight' */
5993 else if (varp == &p_hl)
5994 {
5995 if (highlight_changed() == FAIL)
5996 errmsg = e_invarg; /* invalid flags */
5997 }
5998
5999 /* 'nrformats' */
6000 else if (gvarp == &p_nf)
6001 {
6002 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6003 errmsg = e_invarg;
6004 }
6005
6006#ifdef FEAT_SESSION
6007 /* 'sessionoptions' */
6008 else if (varp == &p_ssop)
6009 {
6010 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6011 errmsg = e_invarg;
6012 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6013 {
6014 /* Don't allow both "sesdir" and "curdir". */
6015 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6016 errmsg = e_invarg;
6017 }
6018 }
6019 /* 'viewoptions' */
6020 else if (varp == &p_vop)
6021 {
6022 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6023 errmsg = e_invarg;
6024 }
6025#endif
6026
6027 /* 'scrollopt' */
6028#ifdef FEAT_SCROLLBIND
6029 else if (varp == &p_sbo)
6030 {
6031 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6032 errmsg = e_invarg;
6033 }
6034#endif
6035
6036 /* 'ambiwidth' */
6037#ifdef FEAT_MBYTE
6038 else if (varp == &p_ambw)
6039 {
6040 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6041 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006042 else if (set_chars_option(&p_lcs) != NULL)
6043 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6044# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6045 else if (set_chars_option(&p_fcs) != NULL)
6046 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6047# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006048 }
6049#endif
6050
6051 /* 'background' */
6052 else if (varp == &p_bg)
6053 {
6054 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6055 {
6056#ifdef FEAT_EVAL
6057 int dark = (*p_bg == 'd');
6058#endif
6059
6060 init_highlight(FALSE, FALSE);
6061
6062#ifdef FEAT_EVAL
6063 if (dark != (*p_bg == 'd')
6064 && get_var_value((char_u *)"g:colors_name") != NULL)
6065 {
6066 /* The color scheme must have set 'background' back to another
6067 * value, that's not what we want here. Disable the color
6068 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006069 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006070 free_string_option(p_bg);
6071 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6072 check_string_option(&p_bg);
6073 init_highlight(FALSE, FALSE);
6074 }
6075#endif
6076 }
6077 else
6078 errmsg = e_invarg;
6079 }
6080
6081 /* 'wildmode' */
6082 else if (varp == &p_wim)
6083 {
6084 if (check_opt_wim() == FAIL)
6085 errmsg = e_invarg;
6086 }
6087
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006088#ifdef FEAT_CMDL_COMPL
6089 /* 'wildoptions' */
6090 else if (varp == &p_wop)
6091 {
6092 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6093 errmsg = e_invarg;
6094 }
6095#endif
6096
Bram Moolenaar071d4272004-06-13 20:20:40 +00006097#ifdef FEAT_WAK
6098 /* 'winaltkeys' */
6099 else if (varp == &p_wak)
6100 {
6101 if (*p_wak == NUL
6102 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6103 errmsg = e_invarg;
6104# ifdef FEAT_MENU
6105# ifdef FEAT_GUI_MOTIF
6106 else if (gui.in_use)
6107 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6108# else
6109# ifdef FEAT_GUI_GTK
6110 else if (gui.in_use)
6111 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6112# endif
6113# endif
6114# endif
6115 }
6116#endif
6117
6118#ifdef FEAT_AUTOCMD
6119 /* 'eventignore' */
6120 else if (varp == &p_ei)
6121 {
6122 if (check_ei() == FAIL)
6123 errmsg = e_invarg;
6124 }
6125#endif
6126
6127#ifdef FEAT_MBYTE
6128 /* 'encoding' and 'fileencoding' */
6129 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6130 {
6131 if (gvarp == &p_fenc)
6132 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006133 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134 errmsg = e_modifiable;
6135 else if (vim_strchr(*varp, ',') != NULL)
6136 /* No comma allowed in 'fileencoding'; catches confusing it
6137 * with 'fileencodings'. */
6138 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006140 {
6141# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006142 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006143 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006145 /* Add 'fileencoding' to the swap file. */
6146 ml_setflags(curbuf);
6147 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006148 }
6149 if (errmsg == NULL)
6150 {
6151 /* canonize the value, so that STRCMP() can be used on it */
6152 p = enc_canonize(*varp);
6153 if (p != NULL)
6154 {
6155 vim_free(*varp);
6156 *varp = p;
6157 }
6158 if (varp == &p_enc)
6159 {
6160 errmsg = mb_init();
6161# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006162 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006163# endif
6164 }
6165 }
6166
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006167# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006168 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6169 {
6170 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6171 if (STRCMP(p_tenc, "utf-8") != 0)
6172 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6173 }
6174# endif
6175
6176 if (errmsg == NULL)
6177 {
6178# ifdef FEAT_KEYMAP
6179 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6180 * (with another encoding). */
6181 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6182 (void)keymap_init();
6183# endif
6184
6185 /* When 'termencoding' is not empty and 'encoding' changes or when
6186 * 'termencoding' changes, need to setup for keyboard input and
6187 * display output conversion. */
6188 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6189 {
6190 convert_setup(&input_conv, p_tenc, p_enc);
6191 convert_setup(&output_conv, p_enc, p_tenc);
6192 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006193
6194# if defined(WIN3264) && defined(FEAT_MBYTE)
6195 /* $HOME may have characters in active code page. */
6196 if (varp == &p_enc)
6197 init_homedir();
6198# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006199 }
6200 }
6201#endif
6202
6203#if defined(FEAT_POSTSCRIPT)
6204 else if (varp == &p_penc)
6205 {
6206 /* Canonize printencoding if VIM standard one */
6207 p = enc_canonize(p_penc);
6208 if (p != NULL)
6209 {
6210 vim_free(p_penc);
6211 p_penc = p;
6212 }
6213 else
6214 {
6215 /* Ensure lower case and '-' for '_' */
6216 for (s = p_penc; *s != NUL; s++)
6217 {
6218 if (*s == '_')
6219 *s = '-';
6220 else
6221 *s = TOLOWER_ASC(*s);
6222 }
6223 }
6224 }
6225#endif
6226
Bram Moolenaar9372a112005-12-06 19:59:18 +00006227#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006228 else if (varp == &p_imak)
6229 {
6230 if (gui.in_use && !im_xim_isvalid_imactivate())
6231 errmsg = e_invarg;
6232 }
6233#endif
6234
6235#ifdef FEAT_KEYMAP
6236 else if (varp == &curbuf->b_p_keymap)
6237 {
6238 /* load or unload key mapping tables */
6239 errmsg = keymap_init();
6240
Bram Moolenaarfab06232009-03-04 03:13:35 +00006241 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006242 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006243 if (*curbuf->b_p_keymap != NUL)
6244 {
6245 /* Installed a new keymap, switch on using it. */
6246 curbuf->b_p_iminsert = B_IMODE_LMAP;
6247 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6248 curbuf->b_p_imsearch = B_IMODE_LMAP;
6249 }
6250 else
6251 {
6252 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6253 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6254 curbuf->b_p_iminsert = B_IMODE_NONE;
6255 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6256 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6257 }
6258 if ((opt_flags & OPT_LOCAL) == 0)
6259 {
6260 set_iminsert_global();
6261 set_imsearch_global();
6262 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006263# ifdef FEAT_WINDOWS
6264 status_redraw_curbuf();
6265# endif
6266 }
6267 }
6268#endif
6269
6270 /* 'fileformat' */
6271 else if (gvarp == &p_ff)
6272 {
6273 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6274 errmsg = e_modifiable;
6275 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6276 errmsg = e_invarg;
6277 else
6278 {
6279 /* may also change 'textmode' */
6280 if (get_fileformat(curbuf) == EOL_DOS)
6281 curbuf->b_p_tx = TRUE;
6282 else
6283 curbuf->b_p_tx = FALSE;
6284#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006285 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006286#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006287 /* update flag in swap file */
6288 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006289 /* Redraw needed when switching to/from "mac": a CR in the text
6290 * will be displayed differently. */
6291 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6292 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293 }
6294 }
6295
6296 /* 'fileformats' */
6297 else if (varp == &p_ffs)
6298 {
6299 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6300 errmsg = e_invarg;
6301 else
6302 {
6303 /* also change 'textauto' */
6304 if (*p_ffs == NUL)
6305 p_ta = FALSE;
6306 else
6307 p_ta = TRUE;
6308 }
6309 }
6310
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006311#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006312 /* 'cryptkey' */
6313 else if (gvarp == &p_key)
6314 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006315# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316 /* Make sure the ":set" command doesn't show the new value in the
6317 * history. */
6318 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006319# endif
6320 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6321 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006322 ml_set_crypt_key(curbuf, oldval,
6323 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006324 }
6325
6326 else if (gvarp == &p_cm)
6327 {
6328 if (opt_flags & OPT_LOCAL)
6329 p = curbuf->b_p_cm;
6330 else
6331 p = p_cm;
6332 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6333 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006334 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006335 errmsg = e_invarg;
6336 else
6337 {
6338 /* When setting the global value to empty, make it "zip". */
6339 if (*p_cm == NUL)
6340 {
6341 if (new_value_alloced)
6342 free_string_option(p_cm);
6343 p_cm = vim_strsave((char_u *)"zip");
6344 new_value_alloced = TRUE;
6345 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006346 /* When using ":set cm=name" the local value is going to be empty.
6347 * Do that here, otherwise the crypt functions will still use the
6348 * local value. */
6349 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6350 {
6351 free_string_option(curbuf->b_p_cm);
6352 curbuf->b_p_cm = empty_option;
6353 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006354
6355 /* Need to update the swapfile when the effective method changed.
6356 * Set "s" to the effective old value, "p" to the effective new
6357 * method and compare. */
6358 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6359 s = p_cm; /* was previously using the global value */
6360 else
6361 s = oldval;
6362 if (*curbuf->b_p_cm == NUL)
6363 p = p_cm; /* is now using the global value */
6364 else
6365 p = curbuf->b_p_cm;
6366 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006367 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006368
6369 /* If the global value changes need to update the swapfile for all
6370 * buffers using that value. */
6371 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6372 {
6373 buf_T *buf;
6374
6375 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6376 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006377 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006378 }
6379 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 }
6381#endif
6382
6383 /* 'matchpairs' */
6384 else if (gvarp == &p_mps)
6385 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006386#ifdef FEAT_MBYTE
6387 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006389 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006390 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006391 int x2 = -1;
6392 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006393
6394 if (*p != NUL)
6395 p += mb_ptr2len(p);
6396 if (*p != NUL)
6397 x2 = *p++;
6398 if (*p != NUL)
6399 {
6400 x3 = mb_ptr2char(p);
6401 p += mb_ptr2len(p);
6402 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006403 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006404 {
6405 errmsg = e_invarg;
6406 break;
6407 }
6408 if (*p == NUL)
6409 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006410 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006411 }
6412 else
6413#endif
6414 {
6415 /* Check for "x:y,x:y" */
6416 for (p = *varp; *p != NUL; p += 4)
6417 {
6418 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6419 {
6420 errmsg = e_invarg;
6421 break;
6422 }
6423 if (p[3] == NUL)
6424 break;
6425 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006426 }
6427 }
6428
6429#ifdef FEAT_COMMENTS
6430 /* 'comments' */
6431 else if (gvarp == &p_com)
6432 {
6433 for (s = *varp; *s; )
6434 {
6435 while (*s && *s != ':')
6436 {
6437 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6438 && !VIM_ISDIGIT(*s) && *s != '-')
6439 {
6440 errmsg = illegal_char(errbuf, *s);
6441 break;
6442 }
6443 ++s;
6444 }
6445 if (*s++ == NUL)
6446 errmsg = (char_u *)N_("E524: Missing colon");
6447 else if (*s == ',' || *s == NUL)
6448 errmsg = (char_u *)N_("E525: Zero length string");
6449 if (errmsg != NULL)
6450 break;
6451 while (*s && *s != ',')
6452 {
6453 if (*s == '\\' && s[1] != NUL)
6454 ++s;
6455 ++s;
6456 }
6457 s = skip_to_option_part(s);
6458 }
6459 }
6460#endif
6461
6462 /* 'listchars' */
6463 else if (varp == &p_lcs)
6464 {
6465 errmsg = set_chars_option(varp);
6466 }
6467
6468#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6469 /* 'fillchars' */
6470 else if (varp == &p_fcs)
6471 {
6472 errmsg = set_chars_option(varp);
6473 }
6474#endif
6475
6476#ifdef FEAT_CMDWIN
6477 /* 'cedit' */
6478 else if (varp == &p_cedit)
6479 {
6480 errmsg = check_cedit();
6481 }
6482#endif
6483
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006484 /* 'verbosefile' */
6485 else if (varp == &p_vfile)
6486 {
6487 verbose_stop();
6488 if (*p_vfile != NUL && verbose_open() == FAIL)
6489 errmsg = e_invarg;
6490 }
6491
Bram Moolenaar071d4272004-06-13 20:20:40 +00006492#ifdef FEAT_VIMINFO
6493 /* 'viminfo' */
6494 else if (varp == &p_viminfo)
6495 {
6496 for (s = p_viminfo; *s;)
6497 {
6498 /* Check it's a valid character */
6499 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6500 {
6501 errmsg = illegal_char(errbuf, *s);
6502 break;
6503 }
6504 if (*s == 'n') /* name is always last one */
6505 {
6506 break;
6507 }
6508 else if (*s == 'r') /* skip until next ',' */
6509 {
6510 while (*++s && *s != ',')
6511 ;
6512 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006513 else if (*s == '%')
6514 {
6515 /* optional number */
6516 while (vim_isdigit(*++s))
6517 ;
6518 }
6519 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006520 ++s; /* no extra chars */
6521 else /* must have a number */
6522 {
6523 while (vim_isdigit(*++s))
6524 ;
6525
6526 if (!VIM_ISDIGIT(*(s - 1)))
6527 {
6528 if (errbuf != NULL)
6529 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006530 sprintf((char *)errbuf,
6531 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006532 transchar_byte(*(s - 1)));
6533 errmsg = errbuf;
6534 }
6535 else
6536 errmsg = (char_u *)"";
6537 break;
6538 }
6539 }
6540 if (*s == ',')
6541 ++s;
6542 else if (*s)
6543 {
6544 if (errbuf != NULL)
6545 errmsg = (char_u *)N_("E527: Missing comma");
6546 else
6547 errmsg = (char_u *)"";
6548 break;
6549 }
6550 }
6551 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6552 errmsg = (char_u *)N_("E528: Must specify a ' value");
6553 }
6554#endif /* FEAT_VIMINFO */
6555
6556 /* terminal options */
6557 else if (istermoption(&options[opt_idx]) && full_screen)
6558 {
6559 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6560 if (varp == &T_CCO)
6561 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006562 int colors = atoi((char *)T_CCO);
6563
6564 /* Only reinitialize colors if t_Co value has really changed to
6565 * avoid expensive reload of colorscheme if t_Co is set to the
6566 * same value multiple times. */
6567 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006569 t_colors = colors;
6570 if (t_colors <= 1)
6571 {
6572 if (new_value_alloced)
6573 vim_free(T_CCO);
6574 T_CCO = empty_option;
6575 }
6576 /* We now have a different color setup, initialize it again. */
6577 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006579 }
6580 ttest(FALSE);
6581 if (varp == &T_ME)
6582 {
6583 out_str(T_ME);
6584 redraw_later(CLEAR);
6585#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6586 /* Since t_me has been set, this probably means that the user
6587 * wants to use this as default colors. Need to reset default
6588 * background/foreground colors. */
6589 mch_set_normal_colors();
6590#endif
6591 }
6592 }
6593
6594#ifdef FEAT_LINEBREAK
6595 /* 'showbreak' */
6596 else if (varp == &p_sbr)
6597 {
6598 for (s = p_sbr; *s; )
6599 {
6600 if (ptr2cells(s) != 1)
6601 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006602 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006603 }
6604 }
6605#endif
6606
6607#ifdef FEAT_GUI
6608 /* 'guifont' */
6609 else if (varp == &p_guifont)
6610 {
6611 if (gui.in_use)
6612 {
6613 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006614# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006615 /*
6616 * Put up a font dialog and let the user select a new value.
6617 * If this is cancelled go back to the old value but don't
6618 * give an error message.
6619 */
6620 if (STRCMP(p, "*") == 0)
6621 {
6622 p = gui_mch_font_dialog(oldval);
6623
6624 if (new_value_alloced)
6625 free_string_option(p_guifont);
6626
6627 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6628 new_value_alloced = TRUE;
6629 }
6630# endif
6631 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6632 {
6633# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6634 if (STRCMP(p_guifont, "*") == 0)
6635 {
6636 /* Dialog was cancelled: Keep the old value without giving
6637 * an error message. */
6638 if (new_value_alloced)
6639 free_string_option(p_guifont);
6640 p_guifont = vim_strsave(oldval);
6641 new_value_alloced = TRUE;
6642 }
6643 else
6644# endif
6645 errmsg = (char_u *)N_("E596: Invalid font(s)");
6646 }
6647 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006648 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006649 }
6650# ifdef FEAT_XFONTSET
6651 else if (varp == &p_guifontset)
6652 {
6653 if (STRCMP(p_guifontset, "*") == 0)
6654 errmsg = (char_u *)N_("E597: can't select fontset");
6655 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6656 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006657 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006658 }
6659# endif
6660# ifdef FEAT_MBYTE
6661 else if (varp == &p_guifontwide)
6662 {
6663 if (STRCMP(p_guifontwide, "*") == 0)
6664 errmsg = (char_u *)N_("E533: can't select wide font");
6665 else if (gui_get_wide_font() == FAIL)
6666 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006667 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006668 }
6669# endif
6670#endif
6671
6672#ifdef CURSOR_SHAPE
6673 /* 'guicursor' */
6674 else if (varp == &p_guicursor)
6675 errmsg = parse_shape_opt(SHAPE_CURSOR);
6676#endif
6677
6678#ifdef FEAT_MOUSESHAPE
6679 /* 'mouseshape' */
6680 else if (varp == &p_mouseshape)
6681 {
6682 errmsg = parse_shape_opt(SHAPE_MOUSE);
6683 update_mouseshape(-1);
6684 }
6685#endif
6686
6687#ifdef FEAT_PRINTER
6688 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006689 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006690# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006691 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006692 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006693# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006694#endif
6695
6696#ifdef FEAT_LANGMAP
6697 /* 'langmap' */
6698 else if (varp == &p_langmap)
6699 langmap_set();
6700#endif
6701
6702#ifdef FEAT_LINEBREAK
6703 /* 'breakat' */
6704 else if (varp == &p_breakat)
6705 fill_breakat_flags();
6706#endif
6707
6708#ifdef FEAT_TITLE
6709 /* 'titlestring' and 'iconstring' */
6710 else if (varp == &p_titlestring || varp == &p_iconstring)
6711 {
6712# ifdef FEAT_STL_OPT
6713 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6714
6715 /* NULL => statusline syntax */
6716 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6717 stl_syntax |= flagval;
6718 else
6719 stl_syntax &= ~flagval;
6720# endif
6721 did_set_title(varp == &p_iconstring);
6722
6723 }
6724#endif
6725
6726#ifdef FEAT_GUI
6727 /* 'guioptions' */
6728 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006729 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006730 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006731 redraw_gui_only = TRUE;
6732 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006733#endif
6734
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006735#if defined(FEAT_GUI_TABLINE)
6736 /* 'guitablabel' */
6737 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006738 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006739 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006740 redraw_gui_only = TRUE;
6741 }
6742 /* 'guitabtooltip' */
6743 else if (varp == &p_gtt)
6744 {
6745 redraw_gui_only = TRUE;
6746 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006747#endif
6748
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6750 /* 'ttymouse' */
6751 else if (varp == &p_ttym)
6752 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006753 /* Switch the mouse off before changing the escape sequences used for
6754 * that. */
6755 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6757 errmsg = e_invarg;
6758 else
6759 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006760 if (termcap_active)
6761 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006762 }
6763#endif
6764
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765 /* 'selection' */
6766 else if (varp == &p_sel)
6767 {
6768 if (*p_sel == NUL
6769 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6770 errmsg = e_invarg;
6771 }
6772
6773 /* 'selectmode' */
6774 else if (varp == &p_slm)
6775 {
6776 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6777 errmsg = e_invarg;
6778 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006779
6780#ifdef FEAT_BROWSE
6781 /* 'browsedir' */
6782 else if (varp == &p_bsdir)
6783 {
6784 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6785 && !mch_isdir(p_bsdir))
6786 errmsg = e_invarg;
6787 }
6788#endif
6789
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 /* 'keymodel' */
6791 else if (varp == &p_km)
6792 {
6793 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6794 errmsg = e_invarg;
6795 else
6796 {
6797 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6798 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6799 }
6800 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006801
6802 /* 'mousemodel' */
6803 else if (varp == &p_mousem)
6804 {
6805 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6806 errmsg = e_invarg;
6807#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6808 else if (*p_mousem != *oldval)
6809 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6810 * to create or delete the popup menus. */
6811 gui_motif_update_mousemodel(root_menu);
6812#endif
6813 }
6814
6815 /* 'switchbuf' */
6816 else if (varp == &p_swb)
6817 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006818 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006819 errmsg = e_invarg;
6820 }
6821
6822 /* 'debug' */
6823 else if (varp == &p_debug)
6824 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006825 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006826 errmsg = e_invarg;
6827 }
6828
6829 /* 'display' */
6830 else if (varp == &p_dy)
6831 {
6832 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6833 errmsg = e_invarg;
6834 else
6835 (void)init_chartab();
6836
6837 }
6838
6839#ifdef FEAT_VERTSPLIT
6840 /* 'eadirection' */
6841 else if (varp == &p_ead)
6842 {
6843 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6844 errmsg = e_invarg;
6845 }
6846#endif
6847
6848#ifdef FEAT_CLIPBOARD
6849 /* 'clipboard' */
6850 else if (varp == &p_cb)
6851 errmsg = check_clipboard_option();
6852#endif
6853
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006854#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006855 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6856 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006857 else if (varp == &(curwin->w_s->b_p_spl)
6858 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006859 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006860 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006861 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006862 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006863 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006864 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006865 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006866 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006867 /* 'spellsuggest' */
6868 else if (varp == &p_sps)
6869 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006870 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006871 errmsg = e_invarg;
6872 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006873 /* 'mkspellmem' */
6874 else if (varp == &p_msm)
6875 {
6876 if (spell_check_msm() != OK)
6877 errmsg = e_invarg;
6878 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006879#endif
6880
Bram Moolenaar071d4272004-06-13 20:20:40 +00006881#ifdef FEAT_QUICKFIX
6882 /* When 'bufhidden' is set, check for valid value. */
6883 else if (gvarp == &p_bh)
6884 {
6885 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6886 errmsg = e_invarg;
6887 }
6888
6889 /* When 'buftype' is set, check for valid value. */
6890 else if (gvarp == &p_bt)
6891 {
6892 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6893 errmsg = e_invarg;
6894 else
6895 {
6896# ifdef FEAT_WINDOWS
6897 if (curwin->w_status_height)
6898 {
6899 curwin->w_redr_status = TRUE;
6900 redraw_later(VALID);
6901 }
6902# endif
6903 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006904# ifdef FEAT_TITLE
6905 redraw_titles();
6906# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006907 }
6908 }
6909#endif
6910
6911#ifdef FEAT_STL_OPT
6912 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006913 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006914 {
6915 int wid;
6916
6917 if (varp == &p_ruf) /* reset ru_wid first */
6918 ru_wid = 0;
6919 s = *varp;
6920 if (varp == &p_ruf && *s == '%')
6921 {
6922 /* set ru_wid if 'ruf' starts with "%99(" */
6923 if (*++s == '-') /* ignore a '-' */
6924 s++;
6925 wid = getdigits(&s);
6926 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6927 ru_wid = wid;
6928 else
6929 errmsg = check_stl_option(p_ruf);
6930 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006931 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006932 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006933 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006934 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006935 comp_col();
6936 }
6937#endif
6938
6939#ifdef FEAT_INS_EXPAND
6940 /* check if it is a valid value for 'complete' -- Acevedo */
6941 else if (gvarp == &p_cpt)
6942 {
6943 for (s = *varp; *s;)
6944 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006945 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 s++;
6947 if (!*s)
6948 break;
6949 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6950 {
6951 errmsg = illegal_char(errbuf, *s);
6952 break;
6953 }
6954 if (*++s != NUL && *s != ',' && *s != ' ')
6955 {
6956 if (s[-1] == 'k' || s[-1] == 's')
6957 {
6958 /* skip optional filename after 'k' and 's' */
6959 while (*s && *s != ',' && *s != ' ')
6960 {
6961 if (*s == '\\')
6962 ++s;
6963 ++s;
6964 }
6965 }
6966 else
6967 {
6968 if (errbuf != NULL)
6969 {
6970 sprintf((char *)errbuf,
6971 _("E535: Illegal character after <%c>"),
6972 *--s);
6973 errmsg = errbuf;
6974 }
6975 else
6976 errmsg = (char_u *)"";
6977 break;
6978 }
6979 }
6980 }
6981 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006982
6983 /* 'completeopt' */
6984 else if (varp == &p_cot)
6985 {
6986 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6987 errmsg = e_invarg;
6988 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006989#endif /* FEAT_INS_EXPAND */
6990
6991
6992#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6993 else if (varp == &p_toolbar)
6994 {
6995 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6996 &toolbar_flags, TRUE) != OK)
6997 errmsg = e_invarg;
6998 else
6999 {
7000 out_flush();
7001 gui_mch_show_toolbar((toolbar_flags &
7002 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7003 }
7004 }
7005#endif
7006
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007007#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007008 /* 'toolbariconsize': GTK+ 2 only */
7009 else if (varp == &p_tbis)
7010 {
7011 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7012 errmsg = e_invarg;
7013 else
7014 {
7015 out_flush();
7016 gui_mch_show_toolbar((toolbar_flags &
7017 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7018 }
7019 }
7020#endif
7021
7022 /* 'pastetoggle': translate key codes like in a mapping */
7023 else if (varp == &p_pt)
7024 {
7025 if (*p_pt)
7026 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007027 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007028 if (p != NULL)
7029 {
7030 if (new_value_alloced)
7031 free_string_option(p_pt);
7032 p_pt = p;
7033 new_value_alloced = TRUE;
7034 }
7035 }
7036 }
7037
7038 /* 'backspace' */
7039 else if (varp == &p_bs)
7040 {
7041 if (VIM_ISDIGIT(*p_bs))
7042 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007043 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044 errmsg = e_invarg;
7045 }
7046 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7047 errmsg = e_invarg;
7048 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007049 else if (varp == &p_bo)
7050 {
7051 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7052 errmsg = e_invarg;
7053 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007054
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007055 /* 'tagcase' */
7056 else if (gvarp == &p_tc)
7057 {
7058 unsigned int *flags;
7059
7060 if (opt_flags & OPT_LOCAL)
7061 {
7062 p = curbuf->b_p_tc;
7063 flags = &curbuf->b_tc_flags;
7064 }
7065 else
7066 {
7067 p = p_tc;
7068 flags = &tc_flags;
7069 }
7070
7071 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7072 /* make the local value empty: use the global value */
7073 *flags = 0;
7074 else if (*p == NUL
7075 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7076 errmsg = e_invarg;
7077 }
7078
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007079#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007080 /* 'casemap' */
7081 else if (varp == &p_cmp)
7082 {
7083 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7084 errmsg = e_invarg;
7085 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007086#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007087
7088#ifdef FEAT_DIFF
7089 /* 'diffopt' */
7090 else if (varp == &p_dip)
7091 {
7092 if (diffopt_changed() == FAIL)
7093 errmsg = e_invarg;
7094 }
7095#endif
7096
7097#ifdef FEAT_FOLDING
7098 /* 'foldmethod' */
7099 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7100 {
7101 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7102 || *curwin->w_p_fdm == NUL)
7103 errmsg = e_invarg;
7104 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007105 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007107 if (foldmethodIsDiff(curwin))
7108 newFoldLevel();
7109 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007110 }
7111# ifdef FEAT_EVAL
7112 /* 'foldexpr' */
7113 else if (varp == &curwin->w_p_fde)
7114 {
7115 if (foldmethodIsExpr(curwin))
7116 foldUpdateAll(curwin);
7117 }
7118# endif
7119 /* 'foldmarker' */
7120 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7121 {
7122 p = vim_strchr(*varp, ',');
7123 if (p == NULL)
7124 errmsg = (char_u *)N_("E536: comma required");
7125 else if (p == *varp || p[1] == NUL)
7126 errmsg = e_invarg;
7127 else if (foldmethodIsMarker(curwin))
7128 foldUpdateAll(curwin);
7129 }
7130 /* 'commentstring' */
7131 else if (gvarp == &p_cms)
7132 {
7133 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7134 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7135 }
7136 /* 'foldopen' */
7137 else if (varp == &p_fdo)
7138 {
7139 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7140 errmsg = e_invarg;
7141 }
7142 /* 'foldclose' */
7143 else if (varp == &p_fcl)
7144 {
7145 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7146 errmsg = e_invarg;
7147 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007148 /* 'foldignore' */
7149 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7150 {
7151 if (foldmethodIsIndent(curwin))
7152 foldUpdateAll(curwin);
7153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154#endif
7155
7156#ifdef FEAT_VIRTUALEDIT
7157 /* 'virtualedit' */
7158 else if (varp == &p_ve)
7159 {
7160 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7161 errmsg = e_invarg;
7162 else if (STRCMP(p_ve, oldval) != 0)
7163 {
7164 /* Recompute cursor position in case the new 've' setting
7165 * changes something. */
7166 validate_virtcol();
7167 coladvance(curwin->w_virtcol);
7168 }
7169 }
7170#endif
7171
7172#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7173 else if (varp == &p_csqf)
7174 {
7175 if (p_csqf != NULL)
7176 {
7177 p = p_csqf;
7178 while (*p != NUL)
7179 {
7180 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7181 || p[1] == NUL
7182 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7183 || (p[2] != NUL && p[2] != ','))
7184 {
7185 errmsg = e_invarg;
7186 break;
7187 }
7188 else if (p[2] == NUL)
7189 break;
7190 else
7191 p += 3;
7192 }
7193 }
7194 }
7195#endif
7196
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007197#ifdef FEAT_CINDENT
7198 /* 'cinoptions' */
7199 else if (gvarp == &p_cino)
7200 {
7201 /* TODO: recognize errors */
7202 parse_cino(curbuf);
7203 }
7204#endif
7205
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007206#if defined(FEAT_RENDER_OPTIONS)
7207 else if (varp == &p_rop && gui.in_use)
7208 {
7209 if (!gui_mch_set_rendering_options(p_rop))
7210 errmsg = e_invarg;
7211 }
7212#endif
7213
Bram Moolenaar071d4272004-06-13 20:20:40 +00007214 /* Options that are a list of flags. */
7215 else
7216 {
7217 p = NULL;
7218 if (varp == &p_ww)
7219 p = (char_u *)WW_ALL;
7220 if (varp == &p_shm)
7221 p = (char_u *)SHM_ALL;
7222 else if (varp == &(p_cpo))
7223 p = (char_u *)CPO_ALL;
7224 else if (varp == &(curbuf->b_p_fo))
7225 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007226#ifdef FEAT_CONCEAL
7227 else if (varp == &curwin->w_p_cocu)
7228 p = (char_u *)COCU_ALL;
7229#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007230 else if (varp == &p_mouse)
7231 {
7232#ifdef FEAT_MOUSE
7233 p = (char_u *)MOUSE_ALL;
7234#else
7235 if (*p_mouse != NUL)
7236 errmsg = (char_u *)N_("E538: No mouse support");
7237#endif
7238 }
7239#if defined(FEAT_GUI)
7240 else if (varp == &p_go)
7241 p = (char_u *)GO_ALL;
7242#endif
7243 if (p != NULL)
7244 {
7245 for (s = *varp; *s; ++s)
7246 if (vim_strchr(p, *s) == NULL)
7247 {
7248 errmsg = illegal_char(errbuf, *s);
7249 break;
7250 }
7251 }
7252 }
7253
7254 /*
7255 * If error detected, restore the previous value.
7256 */
7257 if (errmsg != NULL)
7258 {
7259 if (new_value_alloced)
7260 free_string_option(*varp);
7261 *varp = oldval;
7262 /*
7263 * When resetting some values, need to act on it.
7264 */
7265 if (did_chartab)
7266 (void)init_chartab();
7267 if (varp == &p_hl)
7268 (void)highlight_changed();
7269 }
7270 else
7271 {
7272#ifdef FEAT_EVAL
7273 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007274 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275#endif
7276 /*
7277 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007278 * Use "free_oldval", because recursiveness may change the flags under
7279 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007280 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007281 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282 free_string_option(oldval);
7283 if (new_value_alloced)
7284 options[opt_idx].flags |= P_ALLOCED;
7285 else
7286 options[opt_idx].flags &= ~P_ALLOCED;
7287
7288 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007289 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007290 {
7291 /* global option with local value set to use global value; free
7292 * the local value and make it empty */
7293 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7294 free_string_option(*(char_u **)p);
7295 *(char_u **)p = empty_option;
7296 }
7297
7298 /* May set global value for local option. */
7299 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7300 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007301
7302#ifdef FEAT_AUTOCMD
7303 /*
7304 * Trigger the autocommand only after setting the flags.
7305 */
7306# ifdef FEAT_SYN_HL
7307 /* When 'syntax' is set, load the syntax of that name */
7308 if (varp == &(curbuf->b_p_syn))
7309 {
7310 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7311 curbuf->b_fname, TRUE, curbuf);
7312 }
7313# endif
7314 else if (varp == &(curbuf->b_p_ft))
7315 {
7316 /* 'filetype' is set, trigger the FileType autocommand */
7317 did_filetype = TRUE;
7318 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7319 curbuf->b_fname, TRUE, curbuf);
7320 }
7321#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007322#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007323 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007324 {
7325 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007326 char_u *q = curwin->w_s->b_p_spl;
7327
7328 /* Skip the first name if it is "cjk". */
7329 if (STRNCMP(q, "cjk,", 4) == 0)
7330 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007331
7332 /*
7333 * Source the spell/LANG.vim in 'runtimepath'.
7334 * They could set 'spellcapcheck' depending on the language.
7335 * Use the first name in 'spelllang' up to '_region' or
7336 * '.encoding'.
7337 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007338 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007339 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7340 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007341 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007342 source_runtime(fname, TRUE);
7343 }
7344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007345 }
7346
7347#ifdef FEAT_MOUSE
7348 if (varp == &p_mouse)
7349 {
7350# ifdef FEAT_MOUSE_TTY
7351 if (*p_mouse == NUL)
7352 mch_setmouse(FALSE); /* switch mouse off */
7353 else
7354# endif
7355 setmouse(); /* in case 'mouse' changed */
7356 }
7357#endif
7358
Bram Moolenaar913077c2012-03-28 19:59:04 +02007359 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007360 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007361 curwin->w_set_curswant = TRUE;
7362
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007363#ifdef FEAT_GUI
7364 /* check redraw when it's not a GUI option or the GUI is active. */
7365 if (!redraw_gui_only || gui.in_use)
7366#endif
7367 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007368
7369 return errmsg;
7370}
7371
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007372#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007373/*
7374 * Simple int comparison function for use with qsort()
7375 */
7376 static int
7377int_cmp(a, b)
7378 const void *a;
7379 const void *b;
7380{
7381 return *(const int *)a - *(const int *)b;
7382}
7383
7384/*
7385 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7386 * Returns error message, NULL if it's OK.
7387 */
7388 char_u *
7389check_colorcolumn(wp)
7390 win_T *wp;
7391{
7392 char_u *s;
7393 int col;
7394 int count = 0;
7395 int color_cols[256];
7396 int i;
7397 int j = 0;
7398
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007399 if (wp->w_buffer == NULL)
7400 return NULL; /* buffer was closed */
7401
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007402 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007403 {
7404 if (*s == '-' || *s == '+')
7405 {
7406 /* -N and +N: add to 'textwidth' */
7407 col = (*s == '-') ? -1 : 1;
7408 ++s;
7409 if (!VIM_ISDIGIT(*s))
7410 return e_invarg;
7411 col = col * getdigits(&s);
7412 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007413 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007414 col += wp->w_buffer->b_p_tw;
7415 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007416 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007417 }
7418 else if (VIM_ISDIGIT(*s))
7419 col = getdigits(&s);
7420 else
7421 return e_invarg;
7422 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007423skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007424 if (*s == NUL)
7425 break;
7426 if (*s != ',')
7427 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007428 if (*++s == NUL)
7429 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007430 }
7431
7432 vim_free(wp->w_p_cc_cols);
7433 if (count == 0)
7434 wp->w_p_cc_cols = NULL;
7435 else
7436 {
7437 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7438 if (wp->w_p_cc_cols != NULL)
7439 {
7440 /* sort the columns for faster usage on screen redraw inside
7441 * win_line() */
7442 qsort(color_cols, count, sizeof(int), int_cmp);
7443
7444 for (i = 0; i < count; ++i)
7445 /* skip duplicates */
7446 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7447 wp->w_p_cc_cols[j++] = color_cols[i];
7448 wp->w_p_cc_cols[j] = -1; /* end marker */
7449 }
7450 }
7451
7452 return NULL; /* no error */
7453}
7454#endif
7455
Bram Moolenaar071d4272004-06-13 20:20:40 +00007456/*
7457 * Handle setting 'listchars' or 'fillchars'.
7458 * Returns error message, NULL if it's OK.
7459 */
7460 static char_u *
7461set_chars_option(varp)
7462 char_u **varp;
7463{
7464 int round, i, len, entries;
7465 char_u *p, *s;
7466 int c1, c2 = 0;
7467 struct charstab
7468 {
7469 int *cp;
7470 char *name;
7471 };
7472#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7473 static struct charstab filltab[] =
7474 {
7475 {&fill_stl, "stl"},
7476 {&fill_stlnc, "stlnc"},
7477 {&fill_vert, "vert"},
7478 {&fill_fold, "fold"},
7479 {&fill_diff, "diff"},
7480 };
7481#endif
7482 static struct charstab lcstab[] =
7483 {
7484 {&lcs_eol, "eol"},
7485 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007486 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007487 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007488 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489 {&lcs_tab2, "tab"},
7490 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007491#ifdef FEAT_CONCEAL
7492 {&lcs_conceal, "conceal"},
7493#else
7494 {NULL, "conceal"},
7495#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 };
7497 struct charstab *tab;
7498
7499#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7500 if (varp == &p_lcs)
7501#endif
7502 {
7503 tab = lcstab;
7504 entries = sizeof(lcstab) / sizeof(struct charstab);
7505 }
7506#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7507 else
7508 {
7509 tab = filltab;
7510 entries = sizeof(filltab) / sizeof(struct charstab);
7511 }
7512#endif
7513
7514 /* first round: check for valid value, second round: assign values */
7515 for (round = 0; round <= 1; ++round)
7516 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007517 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518 {
7519 /* After checking that the value is valid: set defaults: space for
7520 * 'fillchars', NUL for 'listchars' */
7521 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007522 if (tab[i].cp != NULL)
7523 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007524 if (varp == &p_lcs)
7525 lcs_tab1 = NUL;
7526#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7527 else
7528 fill_diff = '-';
7529#endif
7530 }
7531 p = *varp;
7532 while (*p)
7533 {
7534 for (i = 0; i < entries; ++i)
7535 {
7536 len = (int)STRLEN(tab[i].name);
7537 if (STRNCMP(p, tab[i].name, len) == 0
7538 && p[len] == ':'
7539 && p[len + 1] != NUL)
7540 {
7541 s = p + len + 1;
7542#ifdef FEAT_MBYTE
7543 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007544 if (mb_char2cells(c1) > 1)
7545 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546#else
7547 c1 = *s++;
7548#endif
7549 if (tab[i].cp == &lcs_tab2)
7550 {
7551 if (*s == NUL)
7552 continue;
7553#ifdef FEAT_MBYTE
7554 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007555 if (mb_char2cells(c2) > 1)
7556 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007557#else
7558 c2 = *s++;
7559#endif
7560 }
7561 if (*s == ',' || *s == NUL)
7562 {
7563 if (round)
7564 {
7565 if (tab[i].cp == &lcs_tab2)
7566 {
7567 lcs_tab1 = c1;
7568 lcs_tab2 = c2;
7569 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007570 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007571 *(tab[i].cp) = c1;
7572
7573 }
7574 p = s;
7575 break;
7576 }
7577 }
7578 }
7579
7580 if (i == entries)
7581 return e_invarg;
7582 if (*p == ',')
7583 ++p;
7584 }
7585 }
7586
7587 return NULL; /* no error */
7588}
7589
7590#ifdef FEAT_STL_OPT
7591/*
7592 * Check validity of options with the 'statusline' format.
7593 * Return error message or NULL.
7594 */
7595 char_u *
7596check_stl_option(s)
7597 char_u *s;
7598{
7599 int itemcnt = 0;
7600 int groupdepth = 0;
7601 static char_u errbuf[80];
7602
7603 while (*s && itemcnt < STL_MAX_ITEM)
7604 {
7605 /* Check for valid keys after % sequences */
7606 while (*s && *s != '%')
7607 s++;
7608 if (!*s)
7609 break;
7610 s++;
7611 if (*s != '%' && *s != ')')
7612 ++itemcnt;
7613 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7614 {
7615 s++;
7616 continue;
7617 }
7618 if (*s == ')')
7619 {
7620 s++;
7621 if (--groupdepth < 0)
7622 break;
7623 continue;
7624 }
7625 if (*s == '-')
7626 s++;
7627 while (VIM_ISDIGIT(*s))
7628 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007629 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007630 continue;
7631 if (*s == '.')
7632 {
7633 s++;
7634 while (*s && VIM_ISDIGIT(*s))
7635 s++;
7636 }
7637 if (*s == '(')
7638 {
7639 groupdepth++;
7640 continue;
7641 }
7642 if (vim_strchr(STL_ALL, *s) == NULL)
7643 {
7644 return illegal_char(errbuf, *s);
7645 }
7646 if (*s == '{')
7647 {
7648 s++;
7649 while (*s != '}' && *s)
7650 s++;
7651 if (*s != '}')
7652 return (char_u *)N_("E540: Unclosed expression sequence");
7653 }
7654 }
7655 if (itemcnt >= STL_MAX_ITEM)
7656 return (char_u *)N_("E541: too many items");
7657 if (groupdepth != 0)
7658 return (char_u *)N_("E542: unbalanced groups");
7659 return NULL;
7660}
7661#endif
7662
7663#ifdef FEAT_CLIPBOARD
7664/*
7665 * Extract the items in the 'clipboard' option and set global values.
7666 */
7667 static char_u *
7668check_clipboard_option()
7669{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007670 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007671 int new_autoselect_star = FALSE;
7672 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007673 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007674 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007675 regprog_T *new_exclude_prog = NULL;
7676 char_u *errmsg = NULL;
7677 char_u *p;
7678
7679 for (p = p_cb; *p != NUL; )
7680 {
7681 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7682 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007683 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007684 p += 7;
7685 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007686 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007687 && (p[11] == ',' || p[11] == NUL))
7688 {
7689 new_unnamed |= CLIP_UNNAMED_PLUS;
7690 p += 11;
7691 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007692 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007693 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007694 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007695 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007696 p += 10;
7697 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007698 else if (STRNCMP(p, "autoselectplus", 14) == 0
7699 && (p[14] == ',' || p[14] == NUL))
7700 {
7701 new_autoselect_plus = TRUE;
7702 p += 14;
7703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007705 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007706 {
7707 new_autoselectml = TRUE;
7708 p += 12;
7709 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007710 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7711 {
7712 new_html = TRUE;
7713 p += 4;
7714 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7716 {
7717 p += 8;
7718 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7719 if (new_exclude_prog == NULL)
7720 errmsg = e_invarg;
7721 break;
7722 }
7723 else
7724 {
7725 errmsg = e_invarg;
7726 break;
7727 }
7728 if (*p == ',')
7729 ++p;
7730 }
7731 if (errmsg == NULL)
7732 {
7733 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007734 clip_autoselect_star = new_autoselect_star;
7735 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007737 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007738 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007740#ifdef FEAT_GUI_GTK
7741 if (gui.in_use)
7742 {
7743 gui_gtk_set_selection_targets();
7744 gui_gtk_set_dnd_targets();
7745 }
7746#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007747 }
7748 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007749 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750
7751 return errmsg;
7752}
7753#endif
7754
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007755#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007756 static char_u *
7757did_set_spell_option(is_spellfile)
7758 int is_spellfile;
7759{
7760 char_u *errmsg = NULL;
7761 win_T *wp;
7762 int l;
7763
7764 if (is_spellfile)
7765 {
7766 l = (int)STRLEN(curwin->w_s->b_p_spf);
7767 if (l > 0 && (l < 4
7768 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7769 errmsg = e_invarg;
7770 }
7771
7772 if (errmsg == NULL)
7773 {
7774 FOR_ALL_WINDOWS(wp)
7775 if (wp->w_buffer == curbuf && wp->w_p_spell)
7776 {
7777 errmsg = did_set_spelllang(wp);
7778# ifdef FEAT_WINDOWS
7779 break;
7780# endif
7781 }
7782 }
7783 return errmsg;
7784}
7785
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007786/*
7787 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7788 * Return error message when failed, NULL when OK.
7789 */
7790 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007791compile_cap_prog(synblock)
7792 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007793{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007794 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007795 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007796
Bram Moolenaar860cae12010-06-05 23:22:07 +02007797 if (*synblock->b_p_spc == NUL)
7798 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007799 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007800 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007801 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007802 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007803 if (re != NULL)
7804 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007805 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007806 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007807 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007808 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007809 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007810 return e_invarg;
7811 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007812 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007813 }
7814
Bram Moolenaar473de612013-06-08 18:19:48 +02007815 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007816 return NULL;
7817}
7818#endif
7819
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007820#if defined(FEAT_EVAL) || defined(PROTO)
7821/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007822 * Set the scriptID for an option, taking care of setting the buffer- or
7823 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007824 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007825 static void
7826set_option_scriptID_idx(opt_idx, opt_flags, id)
7827 int opt_idx;
7828 int opt_flags;
7829 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007830{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007831 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7832 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007833
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007834 /* Remember where the option was set. For local options need to do that
7835 * in the buffer or window structure. */
7836 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007837 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007838 if (both || (opt_flags & OPT_LOCAL))
7839 {
7840 if (indir & PV_BUF)
7841 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7842 else if (indir & PV_WIN)
7843 curwin->w_p_scriptID[indir & PV_MASK] = id;
7844 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007845}
7846#endif
7847
Bram Moolenaar071d4272004-06-13 20:20:40 +00007848/*
7849 * Set the value of a boolean option, and take care of side effects.
7850 * Returns NULL for success, or an error message for an error.
7851 */
7852 static char_u *
7853set_bool_option(opt_idx, varp, value, opt_flags)
7854 int opt_idx; /* index in options[] table */
7855 char_u *varp; /* pointer to the option variable */
7856 int value; /* new value */
7857 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7858{
7859 int old_value = *(int *)varp;
7860
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861 /* Disallow changing some options from secure mode */
7862 if ((secure
7863#ifdef HAVE_SANDBOX
7864 || sandbox != 0
7865#endif
7866 ) && (options[opt_idx].flags & P_SECURE))
7867 return e_secure;
7868
7869 *(int *)varp = value; /* set the new value */
7870#ifdef FEAT_EVAL
7871 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007872 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873#endif
7874
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007875#ifdef FEAT_GUI
7876 need_mouse_correct = TRUE;
7877#endif
7878
Bram Moolenaar071d4272004-06-13 20:20:40 +00007879 /* May set global value for local option. */
7880 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7881 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7882
7883 /*
7884 * Handle side effects of changing a bool option.
7885 */
7886
7887 /* 'compatible' */
7888 if ((int *)varp == &p_cp)
7889 {
7890 compatible_set();
7891 }
7892
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007893#ifdef FEAT_PERSISTENT_UNDO
7894 /* 'undofile' */
7895 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7896 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007897 /* Only take action when the option was set. When reset we do not
7898 * delete the undo file, the option may be set again without making
7899 * any changes in between. */
7900 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007901 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007902 char_u hash[UNDO_HASH_SIZE];
7903 buf_T *save_curbuf = curbuf;
7904
7905 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007906 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007907 /* When 'undofile' is set globally: for every buffer, otherwise
7908 * only for the current buffer: Try to read in the undofile,
7909 * if one exists, the buffer wasn't changed and the buffer was
7910 * loaded */
7911 if ((curbuf == save_curbuf
7912 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7913 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7914 {
7915 u_compute_hash(hash);
7916 u_read_undo(NULL, hash, curbuf->b_fname);
7917 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007918 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007919 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007920 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007921 }
7922#endif
7923
Bram Moolenaar071d4272004-06-13 20:20:40 +00007924 else if ((int *)varp == &curbuf->b_p_ro)
7925 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007926 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7928 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007929
7930 /* when 'readonly' is set may give W10 again */
7931 if (curbuf->b_p_ro)
7932 curbuf->b_did_warn = FALSE;
7933
Bram Moolenaar071d4272004-06-13 20:20:40 +00007934#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007935 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936#endif
7937 }
7938
Bram Moolenaar9c449722010-07-20 18:44:27 +02007939#ifdef FEAT_GUI
7940 else if ((int *)varp == &p_mh)
7941 {
7942 if (!p_mh)
7943 gui_mch_mousehide(FALSE);
7944 }
7945#endif
7946
Bram Moolenaara539df02010-08-01 14:35:05 +02007947#ifdef FEAT_TITLE
7948 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007950 {
7951 redraw_titles();
7952 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953 /* when 'endofline' is changed, redraw the window title */
7954 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007955 {
7956 redraw_titles();
7957 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007958 /* when 'fixeol' is changed, redraw the window title */
7959 else if ((int *)varp == &curbuf->b_p_fixeol)
7960 {
7961 redraw_titles();
7962 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007963# ifdef FEAT_MBYTE
7964 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007965 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007966 {
7967 redraw_titles();
7968 }
7969# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970#endif
7971
7972 /* when 'bin' is set also set some other options */
7973 else if ((int *)varp == &curbuf->b_p_bin)
7974 {
7975 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7976#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007977 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978#endif
7979 }
7980
7981#ifdef FEAT_AUTOCMD
7982 /* when 'buflisted' changes, trigger autocommands */
7983 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7984 {
7985 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7986 NULL, NULL, TRUE, curbuf);
7987 }
7988#endif
7989
7990 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7991 else if ((int *)varp == &curbuf->b_p_swf)
7992 {
7993 if (curbuf->b_p_swf && p_uc)
7994 ml_open_file(curbuf); /* create the swap file */
7995 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007996 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7997 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007998 mf_close_file(curbuf, TRUE); /* remove the swap file */
7999 }
8000
8001 /* when 'terse' is set change 'shortmess' */
8002 else if ((int *)varp == &p_terse)
8003 {
8004 char_u *p;
8005
8006 p = vim_strchr(p_shm, SHM_SEARCH);
8007
8008 /* insert 's' in p_shm */
8009 if (p_terse && p == NULL)
8010 {
8011 STRCPY(IObuff, p_shm);
8012 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008013 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014 }
8015 /* remove 's' from p_shm */
8016 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008017 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018 }
8019
8020 /* when 'paste' is set or reset also change other options */
8021 else if ((int *)varp == &p_paste)
8022 {
8023 paste_option_changed();
8024 }
8025
8026 /* when 'insertmode' is set from an autocommand need to do work here */
8027 else if ((int *)varp == &p_im)
8028 {
8029 if (p_im)
8030 {
8031 if ((State & INSERT) == 0)
8032 need_start_insertmode = TRUE;
8033 stop_insert_mode = FALSE;
8034 }
8035 else
8036 {
8037 need_start_insertmode = FALSE;
8038 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008039 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008040 clear_cmdline = TRUE; /* remove "(insert)" */
8041 restart_edit = 0;
8042 }
8043 }
8044
8045 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8046 else if ((int *)varp == &p_ic && p_hls)
8047 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008048 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008049 }
8050
8051#ifdef FEAT_SEARCH_EXTRA
8052 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8053 else if ((int *)varp == &p_hls)
8054 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008055 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 }
8057#endif
8058
8059#ifdef FEAT_SCROLLBIND
8060 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8061 * at the end of normal_cmd() */
8062 else if ((int *)varp == &curwin->w_p_scb)
8063 {
8064 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008065 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008067 curwin->w_scbind_pos = curwin->w_topline;
8068 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069 }
8070#endif
8071
8072#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8073 /* There can be only one window with 'previewwindow' set. */
8074 else if ((int *)varp == &curwin->w_p_pvw)
8075 {
8076 if (curwin->w_p_pvw)
8077 {
8078 win_T *win;
8079
8080 for (win = firstwin; win != NULL; win = win->w_next)
8081 if (win->w_p_pvw && win != curwin)
8082 {
8083 curwin->w_p_pvw = FALSE;
8084 return (char_u *)N_("E590: A preview window already exists");
8085 }
8086 }
8087 }
8088#endif
8089
8090 /* when 'textmode' is set or reset also change 'fileformat' */
8091 else if ((int *)varp == &curbuf->b_p_tx)
8092 {
8093 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8094 }
8095
8096 /* when 'textauto' is set or reset also change 'fileformats' */
8097 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008098 set_string_option_direct((char_u *)"ffs", -1,
8099 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008100 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008101
8102 /*
8103 * When 'lisp' option changes include/exclude '-' in
8104 * keyword characters.
8105 */
8106#ifdef FEAT_LISP
8107 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8108 {
8109 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8110 }
8111#endif
8112
8113#ifdef FEAT_TITLE
8114 /* when 'title' changed, may need to change the title; same for 'icon' */
8115 else if ((int *)varp == &p_title)
8116 {
8117 did_set_title(FALSE);
8118 }
8119
8120 else if ((int *)varp == &p_icon)
8121 {
8122 did_set_title(TRUE);
8123 }
8124#endif
8125
8126 else if ((int *)varp == &curbuf->b_changed)
8127 {
8128 if (!value)
8129 save_file_ff(curbuf); /* Buffer is unchanged */
8130#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008131 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132#endif
8133#ifdef FEAT_AUTOCMD
8134 modified_was_set = value;
8135#endif
8136 }
8137
8138#ifdef BACKSLASH_IN_FILENAME
8139 else if ((int *)varp == &p_ssl)
8140 {
8141 if (p_ssl)
8142 {
8143 psepc = '/';
8144 psepcN = '\\';
8145 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146 }
8147 else
8148 {
8149 psepc = '\\';
8150 psepcN = '/';
8151 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008152 }
8153
8154 /* need to adjust the file name arguments and buffer names. */
8155 buflist_slash_adjust();
8156 alist_slash_adjust();
8157# ifdef FEAT_EVAL
8158 scriptnames_slash_adjust();
8159# endif
8160 }
8161#endif
8162
8163 /* If 'wrap' is set, set w_leftcol to zero. */
8164 else if ((int *)varp == &curwin->w_p_wrap)
8165 {
8166 if (curwin->w_p_wrap)
8167 curwin->w_leftcol = 0;
8168 }
8169
8170#ifdef FEAT_WINDOWS
8171 else if ((int *)varp == &p_ea)
8172 {
8173 if (p_ea && !old_value)
8174 win_equal(curwin, FALSE, 0);
8175 }
8176#endif
8177
8178 else if ((int *)varp == &p_wiv)
8179 {
8180 /*
8181 * When 'weirdinvert' changed, set/reset 't_xs'.
8182 * Then set 'weirdinvert' according to value of 't_xs'.
8183 */
8184 if (p_wiv && !old_value)
8185 T_XS = (char_u *)"y";
8186 else if (!p_wiv && old_value)
8187 T_XS = empty_option;
8188 p_wiv = (*T_XS != NUL);
8189 }
8190
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008191#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192 else if ((int *)varp == &p_beval)
8193 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008194 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008196 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197 gui_mch_disable_beval_area(balloonEval);
8198 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008199#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008201#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 else if ((int *)varp == &p_acd)
8203 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008204 /* Change directories when the 'acd' option is set now. */
8205 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206 }
8207#endif
8208
8209#ifdef FEAT_DIFF
8210 /* 'diff' */
8211 else if ((int *)varp == &curwin->w_p_diff)
8212 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008213 /* May add or remove the buffer from the list of diff buffers. */
8214 diff_buf_adjust(curwin);
8215# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008216 if (foldmethodIsDiff(curwin))
8217 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008218# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008219 }
8220#endif
8221
8222#ifdef USE_IM_CONTROL
8223 /* 'imdisable' */
8224 else if ((int *)varp == &p_imdisable)
8225 {
8226 /* Only de-activate it here, it will be enabled when changing mode. */
8227 if (p_imdisable)
8228 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008229 else if (State & INSERT)
8230 /* When the option is set from an autocommand, it may need to take
8231 * effect right away. */
8232 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008233 }
8234#endif
8235
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008236#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008237 /* 'spell' */
8238 else if ((int *)varp == &curwin->w_p_spell)
8239 {
8240 if (curwin->w_p_spell)
8241 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008242 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008243 if (errmsg != NULL)
8244 EMSG(_(errmsg));
8245 }
8246 }
8247#endif
8248
Bram Moolenaar071d4272004-06-13 20:20:40 +00008249#ifdef FEAT_FKMAP
8250 else if ((int *)varp == &p_altkeymap)
8251 {
8252 if (old_value != p_altkeymap)
8253 {
8254 if (!p_altkeymap)
8255 {
8256 p_hkmap = p_fkmap;
8257 p_fkmap = 0;
8258 }
8259 else
8260 {
8261 p_fkmap = p_hkmap;
8262 p_hkmap = 0;
8263 }
8264 (void)init_chartab();
8265 }
8266 }
8267
8268 /*
8269 * In case some second language keymapping options have changed, check
8270 * and correct the setting in a consistent way.
8271 */
8272
8273 /*
8274 * If hkmap or fkmap are set, reset Arabic keymapping.
8275 */
8276 if ((p_hkmap || p_fkmap) && p_altkeymap)
8277 {
8278 p_altkeymap = p_fkmap;
8279# ifdef FEAT_ARABIC
8280 curwin->w_p_arab = FALSE;
8281# endif
8282 (void)init_chartab();
8283 }
8284
8285 /*
8286 * If hkmap set, reset Farsi keymapping.
8287 */
8288 if (p_hkmap && p_altkeymap)
8289 {
8290 p_altkeymap = 0;
8291 p_fkmap = 0;
8292# ifdef FEAT_ARABIC
8293 curwin->w_p_arab = FALSE;
8294# endif
8295 (void)init_chartab();
8296 }
8297
8298 /*
8299 * If fkmap set, reset Hebrew keymapping.
8300 */
8301 if (p_fkmap && !p_altkeymap)
8302 {
8303 p_altkeymap = 1;
8304 p_hkmap = 0;
8305# ifdef FEAT_ARABIC
8306 curwin->w_p_arab = FALSE;
8307# endif
8308 (void)init_chartab();
8309 }
8310#endif
8311
8312#ifdef FEAT_ARABIC
8313 if ((int *)varp == &curwin->w_p_arab)
8314 {
8315 if (curwin->w_p_arab)
8316 {
8317 /*
8318 * 'arabic' is set, handle various sub-settings.
8319 */
8320 if (!p_tbidi)
8321 {
8322 /* set rightleft mode */
8323 if (!curwin->w_p_rl)
8324 {
8325 curwin->w_p_rl = TRUE;
8326 changed_window_setting();
8327 }
8328
8329 /* Enable Arabic shaping (major part of what Arabic requires) */
8330 if (!p_arshape)
8331 {
8332 p_arshape = TRUE;
8333 redraw_later_clear();
8334 }
8335 }
8336
8337 /* Arabic requires a utf-8 encoding, inform the user if its not
8338 * set. */
8339 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008340 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008341 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8342
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008343 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008344 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8345#ifdef FEAT_EVAL
8346 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8347#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008348 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008349
8350# ifdef FEAT_MBYTE
8351 /* set 'delcombine' */
8352 p_deco = TRUE;
8353# endif
8354
8355# ifdef FEAT_KEYMAP
8356 /* Force-set the necessary keymap for arabic */
8357 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8358 OPT_LOCAL);
8359# endif
8360# ifdef FEAT_FKMAP
8361 p_altkeymap = 0;
8362 p_hkmap = 0;
8363 p_fkmap = 0;
8364 (void)init_chartab();
8365# endif
8366 }
8367 else
8368 {
8369 /*
8370 * 'arabic' is reset, handle various sub-settings.
8371 */
8372 if (!p_tbidi)
8373 {
8374 /* reset rightleft mode */
8375 if (curwin->w_p_rl)
8376 {
8377 curwin->w_p_rl = FALSE;
8378 changed_window_setting();
8379 }
8380
8381 /* 'arabicshape' isn't reset, it is a global option and
8382 * another window may still need it "on". */
8383 }
8384
8385 /* 'delcombine' isn't reset, it is a global option and another
8386 * window may still want it "on". */
8387
8388# ifdef FEAT_KEYMAP
8389 /* Revert to the default keymap */
8390 curbuf->b_p_iminsert = B_IMODE_NONE;
8391 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8392# endif
8393 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008394 }
8395
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008396#endif
8397
Bram Moolenaar071d4272004-06-13 20:20:40 +00008398 /*
8399 * End of handling side effects for bool options.
8400 */
8401
Bram Moolenaar53744302015-07-17 17:38:22 +02008402 /* after handling side effects, call autocommand */
8403
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404 options[opt_idx].flags |= P_WAS_SET;
8405
Bram Moolenaar53744302015-07-17 17:38:22 +02008406#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8407 if (!starting)
8408 {
8409 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008410 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8411 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8412 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008413 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8414 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8415 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8416 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8417 reset_v_option_vars();
8418 }
8419#endif
8420
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008422 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008423 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008424 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008425 check_redraw(options[opt_idx].flags);
8426
8427 return NULL;
8428}
8429
8430/*
8431 * Set the value of a number option, and take care of side effects.
8432 * Returns NULL for success, or an error message for an error.
8433 */
8434 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008435set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436 int opt_idx; /* index in options[] table */
8437 char_u *varp; /* pointer to the option variable */
8438 long value; /* new value */
8439 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008440 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8442 OPT_MODELINE */
8443{
8444 char_u *errmsg = NULL;
8445 long old_value = *(long *)varp;
8446 long old_Rows = Rows; /* remember old Rows */
8447 long old_Columns = Columns; /* remember old Columns */
8448 long *pp = (long *)varp;
8449
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008450 /* Disallow changing some options from secure mode. */
8451 if ((secure
8452#ifdef HAVE_SANDBOX
8453 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008454#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008455 ) && (options[opt_idx].flags & P_SECURE))
8456 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457
8458 *pp = value;
8459#ifdef FEAT_EVAL
8460 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008461 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008462#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008463#ifdef FEAT_GUI
8464 need_mouse_correct = TRUE;
8465#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466
Bram Moolenaar14f24742012-08-08 18:01:05 +02008467 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008468 {
8469 errmsg = e_positive;
8470 curbuf->b_p_sw = curbuf->b_p_ts;
8471 }
8472
8473 /*
8474 * Number options that need some action when changed
8475 */
8476#ifdef FEAT_WINDOWS
8477 if (pp == &p_wh || pp == &p_hh)
8478 {
8479 if (p_wh < 1)
8480 {
8481 errmsg = e_positive;
8482 p_wh = 1;
8483 }
8484 if (p_wmh > p_wh)
8485 {
8486 errmsg = e_winheight;
8487 p_wh = p_wmh;
8488 }
8489 if (p_hh < 0)
8490 {
8491 errmsg = e_positive;
8492 p_hh = 0;
8493 }
8494
8495 /* Change window height NOW */
8496 if (lastwin != firstwin)
8497 {
8498 if (pp == &p_wh && curwin->w_height < p_wh)
8499 win_setheight((int)p_wh);
8500 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8501 win_setheight((int)p_hh);
8502 }
8503 }
8504
8505 /* 'winminheight' */
8506 else if (pp == &p_wmh)
8507 {
8508 if (p_wmh < 0)
8509 {
8510 errmsg = e_positive;
8511 p_wmh = 0;
8512 }
8513 if (p_wmh > p_wh)
8514 {
8515 errmsg = e_winheight;
8516 p_wmh = p_wh;
8517 }
8518 win_setminheight();
8519 }
8520
8521# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008522 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008523 {
8524 if (p_wiw < 1)
8525 {
8526 errmsg = e_positive;
8527 p_wiw = 1;
8528 }
8529 if (p_wmw > p_wiw)
8530 {
8531 errmsg = e_winwidth;
8532 p_wiw = p_wmw;
8533 }
8534
8535 /* Change window width NOW */
8536 if (lastwin != firstwin && curwin->w_width < p_wiw)
8537 win_setwidth((int)p_wiw);
8538 }
8539
8540 /* 'winminwidth' */
8541 else if (pp == &p_wmw)
8542 {
8543 if (p_wmw < 0)
8544 {
8545 errmsg = e_positive;
8546 p_wmw = 0;
8547 }
8548 if (p_wmw > p_wiw)
8549 {
8550 errmsg = e_winwidth;
8551 p_wmw = p_wiw;
8552 }
8553 win_setminheight();
8554 }
8555# endif
8556
8557#endif
8558
8559#ifdef FEAT_WINDOWS
8560 /* (re)set last window status line */
8561 else if (pp == &p_ls)
8562 {
8563 last_status(FALSE);
8564 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008565
8566 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008567 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008568 {
8569 shell_new_rows(); /* recompute window positions and heights */
8570 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008571#endif
8572
8573#ifdef FEAT_GUI
8574 else if (pp == &p_linespace)
8575 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008576 /* Recompute gui.char_height and resize the Vim window to keep the
8577 * same number of lines. */
8578 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008579 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008580 }
8581#endif
8582
8583#ifdef FEAT_FOLDING
8584 /* 'foldlevel' */
8585 else if (pp == &curwin->w_p_fdl)
8586 {
8587 if (curwin->w_p_fdl < 0)
8588 curwin->w_p_fdl = 0;
8589 newFoldLevel();
8590 }
8591
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008592 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008593 else if (pp == &curwin->w_p_fml)
8594 {
8595 foldUpdateAll(curwin);
8596 }
8597
8598 /* 'foldnestmax' */
8599 else if (pp == &curwin->w_p_fdn)
8600 {
8601 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8602 foldUpdateAll(curwin);
8603 }
8604
8605 /* 'foldcolumn' */
8606 else if (pp == &curwin->w_p_fdc)
8607 {
8608 if (curwin->w_p_fdc < 0)
8609 {
8610 errmsg = e_positive;
8611 curwin->w_p_fdc = 0;
8612 }
8613 else if (curwin->w_p_fdc > 12)
8614 {
8615 errmsg = e_invarg;
8616 curwin->w_p_fdc = 12;
8617 }
8618 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008619#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008620
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008621#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622 /* 'shiftwidth' or 'tabstop' */
8623 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8624 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008625# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008626 if (foldmethodIsIndent(curwin))
8627 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008628# endif
8629# ifdef FEAT_CINDENT
8630 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8631 * parse 'cinoptions'. */
8632 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8633 parse_cino(curbuf);
8634# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008636#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008637
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008638#ifdef FEAT_MBYTE
8639 /* 'maxcombine' */
8640 else if (pp == &p_mco)
8641 {
8642 if (p_mco > MAX_MCO)
8643 p_mco = MAX_MCO;
8644 else if (p_mco < 0)
8645 p_mco = 0;
8646 screenclear(); /* will re-allocate the screen */
8647 }
8648#endif
8649
Bram Moolenaar071d4272004-06-13 20:20:40 +00008650 else if (pp == &curbuf->b_p_iminsert)
8651 {
8652 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8653 {
8654 errmsg = e_invarg;
8655 curbuf->b_p_iminsert = B_IMODE_NONE;
8656 }
8657 p_iminsert = curbuf->b_p_iminsert;
8658 if (termcap_active) /* don't do this in the alternate screen */
8659 showmode();
8660#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8661 /* Show/unshow value of 'keymap' in status lines. */
8662 status_redraw_curbuf();
8663#endif
8664 }
8665
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008666 else if (pp == &p_window)
8667 {
8668 if (p_window < 1)
8669 p_window = 1;
8670 else if (p_window >= Rows)
8671 p_window = Rows - 1;
8672 }
8673
Bram Moolenaar071d4272004-06-13 20:20:40 +00008674 else if (pp == &curbuf->b_p_imsearch)
8675 {
8676 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8677 {
8678 errmsg = e_invarg;
8679 curbuf->b_p_imsearch = B_IMODE_NONE;
8680 }
8681 p_imsearch = curbuf->b_p_imsearch;
8682 }
8683
8684#ifdef FEAT_TITLE
8685 /* if 'titlelen' has changed, redraw the title */
8686 else if (pp == &p_titlelen)
8687 {
8688 if (p_titlelen < 0)
8689 {
8690 errmsg = e_positive;
8691 p_titlelen = 85;
8692 }
8693 if (starting != NO_SCREEN && old_value != p_titlelen)
8694 need_maketitle = TRUE;
8695 }
8696#endif
8697
8698 /* if p_ch changed value, change the command line height */
8699 else if (pp == &p_ch)
8700 {
8701 if (p_ch < 1)
8702 {
8703 errmsg = e_positive;
8704 p_ch = 1;
8705 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008706 if (p_ch > Rows - min_rows() + 1)
8707 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008708
8709 /* Only compute the new window layout when startup has been
8710 * completed. Otherwise the frame sizes may be wrong. */
8711 if (p_ch != old_value && full_screen
8712#ifdef FEAT_GUI
8713 && !gui.starting
8714#endif
8715 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008716 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008717 }
8718
8719 /* when 'updatecount' changes from zero to non-zero, open swap files */
8720 else if (pp == &p_uc)
8721 {
8722 if (p_uc < 0)
8723 {
8724 errmsg = e_positive;
8725 p_uc = 100;
8726 }
8727 if (p_uc && !old_value)
8728 ml_open_files();
8729 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008730#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008731 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008732 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008733 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008734 {
8735 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008736 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008737 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008738 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008739 {
8740 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008741 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008742 }
8743 }
8744#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008745#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008746 else if (pp == &p_mzq)
8747 mzvim_reset_timer();
8748#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008749
8750 /* sync undo before 'undolevels' changes */
8751 else if (pp == &p_ul)
8752 {
8753 /* use the old value, otherwise u_sync() may not work properly */
8754 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008755 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008756 p_ul = value;
8757 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008758 else if (pp == &curbuf->b_p_ul)
8759 {
8760 /* use the old value, otherwise u_sync() may not work properly */
8761 curbuf->b_p_ul = old_value;
8762 u_sync(TRUE);
8763 curbuf->b_p_ul = value;
8764 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008766#ifdef FEAT_LINEBREAK
8767 /* 'numberwidth' must be positive */
8768 else if (pp == &curwin->w_p_nuw)
8769 {
8770 if (curwin->w_p_nuw < 1)
8771 {
8772 errmsg = e_positive;
8773 curwin->w_p_nuw = 1;
8774 }
8775 if (curwin->w_p_nuw > 10)
8776 {
8777 errmsg = e_invarg;
8778 curwin->w_p_nuw = 10;
8779 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008780 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008781 }
8782#endif
8783
Bram Moolenaar1a384422010-07-14 19:53:30 +02008784 else if (pp == &curbuf->b_p_tw)
8785 {
8786 if (curbuf->b_p_tw < 0)
8787 {
8788 errmsg = e_positive;
8789 curbuf->b_p_tw = 0;
8790 }
8791#ifdef FEAT_SYN_HL
8792# ifdef FEAT_WINDOWS
8793 {
8794 win_T *wp;
8795 tabpage_T *tp;
8796
8797 FOR_ALL_TAB_WINDOWS(tp, wp)
8798 check_colorcolumn(wp);
8799 }
8800# else
8801 check_colorcolumn(curwin);
8802# endif
8803#endif
8804 }
8805
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806 /*
8807 * Check the bounds for numeric options here
8808 */
8809 if (Rows < min_rows() && full_screen)
8810 {
8811 if (errbuf != NULL)
8812 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008813 vim_snprintf((char *)errbuf, errbuflen,
8814 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008815 errmsg = errbuf;
8816 }
8817 Rows = min_rows();
8818 }
8819 if (Columns < MIN_COLUMNS && full_screen)
8820 {
8821 if (errbuf != NULL)
8822 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008823 vim_snprintf((char *)errbuf, errbuflen,
8824 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008825 errmsg = errbuf;
8826 }
8827 Columns = MIN_COLUMNS;
8828 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008829 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008830
8831#ifdef DJGPP
8832 /* avoid a crash by checking for a too large value of 'columns' */
8833 if (old_Columns != Columns && full_screen && term_console)
8834 mch_check_columns();
8835#endif
8836
8837 /*
8838 * If the screen (shell) height has been changed, assume it is the
8839 * physical screenheight.
8840 */
8841 if (old_Rows != Rows || old_Columns != Columns)
8842 {
8843 /* Changing the screen size is not allowed while updating the screen. */
8844 if (updating_screen)
8845 *pp = old_value;
8846 else if (full_screen
8847#ifdef FEAT_GUI
8848 && !gui.starting
8849#endif
8850 )
8851 set_shellsize((int)Columns, (int)Rows, TRUE);
8852 else
8853 {
8854 /* Postpone the resizing; check the size and cmdline position for
8855 * messages. */
8856 check_shellsize();
8857 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8858 cmdline_row = Rows - p_ch;
8859 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008860 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008861 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862 }
8863
Bram Moolenaar071d4272004-06-13 20:20:40 +00008864 if (curbuf->b_p_ts <= 0)
8865 {
8866 errmsg = e_positive;
8867 curbuf->b_p_ts = 8;
8868 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869 if (p_tm < 0)
8870 {
8871 errmsg = e_positive;
8872 p_tm = 0;
8873 }
8874 if ((curwin->w_p_scr <= 0
8875 || (curwin->w_p_scr > curwin->w_height
8876 && curwin->w_height > 0))
8877 && full_screen)
8878 {
8879 if (pp == &(curwin->w_p_scr))
8880 {
8881 if (curwin->w_p_scr != 0)
8882 errmsg = e_scroll;
8883 win_comp_scroll(curwin);
8884 }
8885 /* If 'scroll' became invalid because of a side effect silently adjust
8886 * it. */
8887 else if (curwin->w_p_scr <= 0)
8888 curwin->w_p_scr = 1;
8889 else /* curwin->w_p_scr > curwin->w_height */
8890 curwin->w_p_scr = curwin->w_height;
8891 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008892 if (p_hi < 0)
8893 {
8894 errmsg = e_positive;
8895 p_hi = 0;
8896 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008897 else if (p_hi > 10000)
8898 {
8899 errmsg = e_invarg;
8900 p_hi = 10000;
8901 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008902 if (p_re < 0 || p_re > 2)
8903 {
8904 errmsg = e_invarg;
8905 p_re = 0;
8906 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907 if (p_report < 0)
8908 {
8909 errmsg = e_positive;
8910 p_report = 1;
8911 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008912 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913 {
8914 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8915 p_sj = Rows / 2;
8916 else
8917 {
8918 errmsg = e_scroll;
8919 p_sj = 1;
8920 }
8921 }
8922 if (p_so < 0 && full_screen)
8923 {
8924 errmsg = e_scroll;
8925 p_so = 0;
8926 }
8927 if (p_siso < 0 && full_screen)
8928 {
8929 errmsg = e_positive;
8930 p_siso = 0;
8931 }
8932#ifdef FEAT_CMDWIN
8933 if (p_cwh < 1)
8934 {
8935 errmsg = e_positive;
8936 p_cwh = 1;
8937 }
8938#endif
8939 if (p_ut < 0)
8940 {
8941 errmsg = e_positive;
8942 p_ut = 2000;
8943 }
8944 if (p_ss < 0)
8945 {
8946 errmsg = e_positive;
8947 p_ss = 0;
8948 }
8949
8950 /* May set global value for local option. */
8951 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8952 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8953
8954 options[opt_idx].flags |= P_WAS_SET;
8955
Bram Moolenaar53744302015-07-17 17:38:22 +02008956#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8957 if (!starting && errmsg == NULL)
8958 {
8959 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008960 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8961 vim_snprintf((char *)buf_new, 10, "%ld", value);
8962 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008963 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8964 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8965 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8966 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8967 reset_v_option_vars();
8968 }
8969#endif
8970
Bram Moolenaar071d4272004-06-13 20:20:40 +00008971 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008972 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008973 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008974 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008975 check_redraw(options[opt_idx].flags);
8976
8977 return errmsg;
8978}
8979
8980/*
8981 * Called after an option changed: check if something needs to be redrawn.
8982 */
8983 static void
8984check_redraw(flags)
8985 long_u flags;
8986{
8987 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008988 int doclear = (flags & P_RCLR) == P_RCLR;
8989 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008990
8991#ifdef FEAT_WINDOWS
8992 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8993 status_redraw_all();
8994#endif
8995
8996 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8997 changed_window_setting();
8998 if (flags & P_RBUF)
8999 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009000 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009001 redraw_all_later(CLEAR);
9002 else if (all)
9003 redraw_all_later(NOT_VALID);
9004}
9005
9006/*
9007 * Find index for option 'arg'.
9008 * Return -1 if not found.
9009 */
9010 static int
9011findoption(arg)
9012 char_u *arg;
9013{
9014 int opt_idx;
9015 char *s, *p;
9016 static short quick_tab[27] = {0, 0}; /* quick access table */
9017 int is_term_opt;
9018
9019 /*
9020 * For first call: Initialize the quick-access table.
9021 * It contains the index for the first option that starts with a certain
9022 * letter. There are 26 letters, plus the first "t_" option.
9023 */
9024 if (quick_tab[1] == 0)
9025 {
9026 p = options[0].fullname;
9027 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9028 {
9029 if (s[0] != p[0])
9030 {
9031 if (s[0] == 't' && s[1] == '_')
9032 quick_tab[26] = opt_idx;
9033 else
9034 quick_tab[CharOrdLow(s[0])] = opt_idx;
9035 }
9036 p = s;
9037 }
9038 }
9039
9040 /*
9041 * Check for name starting with an illegal character.
9042 */
9043#ifdef EBCDIC
9044 if (!islower(arg[0]))
9045#else
9046 if (arg[0] < 'a' || arg[0] > 'z')
9047#endif
9048 return -1;
9049
9050 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9051 if (is_term_opt)
9052 opt_idx = quick_tab[26];
9053 else
9054 opt_idx = quick_tab[CharOrdLow(arg[0])];
9055 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9056 {
9057 if (STRCMP(arg, s) == 0) /* match full name */
9058 break;
9059 }
9060 if (s == NULL && !is_term_opt)
9061 {
9062 opt_idx = quick_tab[CharOrdLow(arg[0])];
9063 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9064 {
9065 s = options[opt_idx].shortname;
9066 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9067 break;
9068 s = NULL;
9069 }
9070 }
9071 if (s == NULL)
9072 opt_idx = -1;
9073 return opt_idx;
9074}
9075
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009076#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009077/*
9078 * Get the value for an option.
9079 *
9080 * Returns:
9081 * Number or Toggle option: 1, *numval gets value.
9082 * String option: 0, *stringval gets allocated string.
9083 * Hidden Number or Toggle option: -1.
9084 * hidden String option: -2.
9085 * unknown option: -3.
9086 */
9087 int
9088get_option_value(name, numval, stringval, opt_flags)
9089 char_u *name;
9090 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02009091 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092 int opt_flags;
9093{
9094 int opt_idx;
9095 char_u *varp;
9096
9097 opt_idx = findoption(name);
9098 if (opt_idx < 0) /* unknown option */
9099 return -3;
9100
9101 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9102
9103 if (options[opt_idx].flags & P_STRING)
9104 {
9105 if (varp == NULL) /* hidden option */
9106 return -2;
9107 if (stringval != NULL)
9108 {
9109#ifdef FEAT_CRYPT
9110 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009111 if ((char_u **)varp == &curbuf->b_p_key
9112 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009113 *stringval = vim_strsave((char_u *)"*****");
9114 else
9115#endif
9116 *stringval = vim_strsave(*(char_u **)(varp));
9117 }
9118 return 0;
9119 }
9120
9121 if (varp == NULL) /* hidden option */
9122 return -1;
9123 if (options[opt_idx].flags & P_NUM)
9124 *numval = *(long *)varp;
9125 else
9126 {
9127 /* Special case: 'modified' is b_changed, but we also want to consider
9128 * it set when 'ff' or 'fenc' changed. */
9129 if ((int *)varp == &curbuf->b_changed)
9130 *numval = curbufIsChanged();
9131 else
9132 *numval = *(int *)varp;
9133 }
9134 return 1;
9135}
9136#endif
9137
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009138#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009139/*
9140 * Returns the option attributes and its value. Unlike the above function it
9141 * will return either global value or local value of the option depending on
9142 * what was requested, but it will never return global value if it was
9143 * requested to return local one and vice versa. Neither it will return
9144 * buffer-local value if it was requested to return window-local one.
9145 *
9146 * Pretends that option is absent if it is not present in the requested scope
9147 * (i.e. has no global, window-local or buffer-local value depending on
9148 * opt_type). Uses
9149 *
9150 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009151 * 0 hidden or unknown option, also option that does not have requested
9152 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009153 * see SOPT_* in vim.h for other flags
9154 *
9155 * Possible opt_type values: see SREQ_* in vim.h
9156 */
9157 int
9158get_option_value_strict(name, numval, stringval, opt_type, from)
9159 char_u *name;
9160 long *numval;
9161 char_u **stringval; /* NULL when only obtaining attributes */
9162 int opt_type;
9163 void *from;
9164{
9165 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009166 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009167 struct vimoption *p;
9168 int r = 0;
9169
9170 opt_idx = findoption(name);
9171 if (opt_idx < 0)
9172 return 0;
9173
9174 p = &(options[opt_idx]);
9175
9176 /* Hidden option */
9177 if (p->var == NULL)
9178 return 0;
9179
9180 if (p->flags & P_BOOL)
9181 r |= SOPT_BOOL;
9182 else if (p->flags & P_NUM)
9183 r |= SOPT_NUM;
9184 else if (p->flags & P_STRING)
9185 r |= SOPT_STRING;
9186
9187 if (p->indir == PV_NONE)
9188 {
9189 if (opt_type == SREQ_GLOBAL)
9190 r |= SOPT_GLOBAL;
9191 else
9192 return 0; /* Did not request global-only option */
9193 }
9194 else
9195 {
9196 if (p->indir & PV_BOTH)
9197 r |= SOPT_GLOBAL;
9198 else if (opt_type == SREQ_GLOBAL)
9199 return 0; /* Requested global option */
9200
9201 if (p->indir & PV_WIN)
9202 {
9203 if (opt_type == SREQ_BUF)
9204 return 0; /* Did not request window-local option */
9205 else
9206 r |= SOPT_WIN;
9207 }
9208 else if (p->indir & PV_BUF)
9209 {
9210 if (opt_type == SREQ_WIN)
9211 return 0; /* Did not request buffer-local option */
9212 else
9213 r |= SOPT_BUF;
9214 }
9215 }
9216
9217 if (stringval == NULL)
9218 return r;
9219
9220 if (opt_type == SREQ_GLOBAL)
9221 varp = p->var;
9222 else
9223 {
9224 if (opt_type == SREQ_BUF)
9225 {
9226 /* Special case: 'modified' is b_changed, but we also want to
9227 * consider it set when 'ff' or 'fenc' changed. */
9228 if (p->indir == PV_MOD)
9229 {
9230 *numval = bufIsChanged((buf_T *) from);
9231 varp = NULL;
9232 }
9233#ifdef FEAT_CRYPT
9234 else if (p->indir == PV_KEY)
9235 {
9236 /* never return the value of the crypt key */
9237 *stringval = NULL;
9238 varp = NULL;
9239 }
9240#endif
9241 else
9242 {
9243 aco_save_T aco;
9244 aucmd_prepbuf(&aco, (buf_T *) from);
9245 varp = get_varp(p);
9246 aucmd_restbuf(&aco);
9247 }
9248 }
9249 else if (opt_type == SREQ_WIN)
9250 {
9251 win_T *save_curwin;
9252 save_curwin = curwin;
9253 curwin = (win_T *) from;
9254 curbuf = curwin->w_buffer;
9255 varp = get_varp(p);
9256 curwin = save_curwin;
9257 curbuf = curwin->w_buffer;
9258 }
9259 if (varp == p->var)
9260 return (r | SOPT_UNSET);
9261 }
9262
9263 if (varp != NULL)
9264 {
9265 if (p->flags & P_STRING)
9266 *stringval = vim_strsave(*(char_u **)(varp));
9267 else if (p->flags & P_NUM)
9268 *numval = *(long *) varp;
9269 else
9270 *numval = *(int *)varp;
9271 }
9272
9273 return r;
9274}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009275
9276/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009277 * Iterate over options. First argument is a pointer to a pointer to a
9278 * structure inside options[] array, second is option type like in the above
9279 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009280 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009281 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009282 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009283 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009284 * first argument to NULL.
9285 *
9286 * Returns full option name for current option on each call.
9287 */
9288 char_u *
9289option_iter_next(option, opt_type)
9290 void **option;
9291 int opt_type;
9292{
9293 struct vimoption *ret = NULL;
9294 do
9295 {
9296 if (*option == NULL)
9297 *option = (void *) options;
9298 else if (((struct vimoption *) (*option))->fullname == NULL)
9299 {
9300 *option = NULL;
9301 return NULL;
9302 }
9303 else
9304 *option = (void *) (((struct vimoption *) (*option)) + 1);
9305
9306 ret = ((struct vimoption *) (*option));
9307
9308 /* Hidden option */
9309 if (ret->var == NULL)
9310 {
9311 ret = NULL;
9312 continue;
9313 }
9314
9315 switch (opt_type)
9316 {
9317 case SREQ_GLOBAL:
9318 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9319 ret = NULL;
9320 break;
9321 case SREQ_BUF:
9322 if (!(ret->indir & PV_BUF))
9323 ret = NULL;
9324 break;
9325 case SREQ_WIN:
9326 if (!(ret->indir & PV_WIN))
9327 ret = NULL;
9328 break;
9329 default:
9330 EMSG2(_(e_intern2), "option_iter_next()");
9331 return NULL;
9332 }
9333 }
9334 while (ret == NULL);
9335
9336 return (char_u *)ret->fullname;
9337}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009338#endif
9339
Bram Moolenaar071d4272004-06-13 20:20:40 +00009340/*
9341 * Set the value of option "name".
9342 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009343 *
9344 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009346 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009347set_option_value(name, number, string, opt_flags)
9348 char_u *name;
9349 long number;
9350 char_u *string;
9351 int opt_flags; /* OPT_LOCAL or 0 (both) */
9352{
9353 int opt_idx;
9354 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009355 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009356
9357 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009358 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009359 EMSG2(_("E355: Unknown option: %s"), name);
9360 else
9361 {
9362 flags = options[opt_idx].flags;
9363#ifdef HAVE_SANDBOX
9364 /* Disallow changing some options in the sandbox */
9365 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009366 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009367 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009368 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009369 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009371 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009372 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009373 else
9374 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009375 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009376 if (varp != NULL) /* hidden option is not changed */
9377 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009378 if (number == 0 && string != NULL)
9379 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009380 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009381
9382 /* Either we are given a string or we are setting option
9383 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009384 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009385 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009386 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009387 {
9388 /* There's another character after zeros or the string
9389 * is empty. In both cases, we are trying to set a
9390 * num option using a string. */
9391 EMSG3(_("E521: Number required: &%s = '%s'"),
9392 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009393 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009394
9395 }
9396 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009397 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009398 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009399 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009400 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009401 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009402 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009403 }
9404 }
9405 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009406 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009407}
9408
9409/*
9410 * Get the terminal code for a terminal option.
9411 * Returns NULL when not found.
9412 */
9413 char_u *
9414get_term_code(tname)
9415 char_u *tname;
9416{
9417 int opt_idx;
9418 char_u *varp;
9419
9420 if (tname[0] != 't' || tname[1] != '_' ||
9421 tname[2] == NUL || tname[3] == NUL)
9422 return NULL;
9423 if ((opt_idx = findoption(tname)) >= 0)
9424 {
9425 varp = get_varp(&(options[opt_idx]));
9426 if (varp != NULL)
9427 varp = *(char_u **)(varp);
9428 return varp;
9429 }
9430 return find_termcode(tname + 2);
9431}
9432
9433 char_u *
9434get_highlight_default()
9435{
9436 int i;
9437
9438 i = findoption((char_u *)"hl");
9439 if (i >= 0)
9440 return options[i].def_val[VI_DEFAULT];
9441 return (char_u *)NULL;
9442}
9443
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009444#if defined(FEAT_MBYTE) || defined(PROTO)
9445 char_u *
9446get_encoding_default()
9447{
9448 int i;
9449
9450 i = findoption((char_u *)"enc");
9451 if (i >= 0)
9452 return options[i].def_val[VI_DEFAULT];
9453 return (char_u *)NULL;
9454}
9455#endif
9456
Bram Moolenaar071d4272004-06-13 20:20:40 +00009457/*
9458 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9459 */
9460 static int
9461find_key_option(arg)
9462 char_u *arg;
9463{
9464 int key;
9465 int modifiers;
9466
9467 /*
9468 * Don't use get_special_key_code() for t_xx, we don't want it to call
9469 * add_termcap_entry().
9470 */
9471 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9472 key = TERMCAP2KEY(arg[2], arg[3]);
9473 else
9474 {
9475 --arg; /* put arg at the '<' */
9476 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009477 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009478 if (modifiers) /* can't handle modifiers here */
9479 key = 0;
9480 }
9481 return key;
9482}
9483
9484/*
9485 * if 'all' == 0: show changed options
9486 * if 'all' == 1: show all normal options
9487 * if 'all' == 2: show all terminal options
9488 */
9489 static void
9490showoptions(all, opt_flags)
9491 int all;
9492 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9493{
9494 struct vimoption *p;
9495 int col;
9496 int isterm;
9497 char_u *varp;
9498 struct vimoption **items;
9499 int item_count;
9500 int run;
9501 int row, rows;
9502 int cols;
9503 int i;
9504 int len;
9505
9506#define INC 20
9507#define GAP 3
9508
9509 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9510 PARAM_COUNT));
9511 if (items == NULL)
9512 return;
9513
9514 /* Highlight title */
9515 if (all == 2)
9516 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9517 else if (opt_flags & OPT_GLOBAL)
9518 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9519 else if (opt_flags & OPT_LOCAL)
9520 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9521 else
9522 MSG_PUTS_TITLE(_("\n--- Options ---"));
9523
9524 /*
9525 * do the loop two times:
9526 * 1. display the short items
9527 * 2. display the long items (only strings and numbers)
9528 */
9529 for (run = 1; run <= 2 && !got_int; ++run)
9530 {
9531 /*
9532 * collect the items in items[]
9533 */
9534 item_count = 0;
9535 for (p = &options[0]; p->fullname != NULL; p++)
9536 {
9537 varp = NULL;
9538 isterm = istermoption(p);
9539 if (opt_flags != 0)
9540 {
9541 if (p->indir != PV_NONE && !isterm)
9542 varp = get_varp_scope(p, opt_flags);
9543 }
9544 else
9545 varp = get_varp(p);
9546 if (varp != NULL
9547 && ((all == 2 && isterm)
9548 || (all == 1 && !isterm)
9549 || (all == 0 && !optval_default(p, varp))))
9550 {
9551 if (p->flags & P_BOOL)
9552 len = 1; /* a toggle option fits always */
9553 else
9554 {
9555 option_value2string(p, opt_flags);
9556 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9557 }
9558 if ((len <= INC - GAP && run == 1) ||
9559 (len > INC - GAP && run == 2))
9560 items[item_count++] = p;
9561 }
9562 }
9563
9564 /*
9565 * display the items
9566 */
9567 if (run == 1)
9568 {
9569 cols = (Columns + GAP - 3) / INC;
9570 if (cols == 0)
9571 cols = 1;
9572 rows = (item_count + cols - 1) / cols;
9573 }
9574 else /* run == 2 */
9575 rows = item_count;
9576 for (row = 0; row < rows && !got_int; ++row)
9577 {
9578 msg_putchar('\n'); /* go to next line */
9579 if (got_int) /* 'q' typed in more */
9580 break;
9581 col = 0;
9582 for (i = row; i < item_count; i += rows)
9583 {
9584 msg_col = col; /* make columns */
9585 showoneopt(items[i], opt_flags);
9586 col += INC;
9587 }
9588 out_flush();
9589 ui_breakcheck();
9590 }
9591 }
9592 vim_free(items);
9593}
9594
9595/*
9596 * Return TRUE if option "p" has its default value.
9597 */
9598 static int
9599optval_default(p, varp)
9600 struct vimoption *p;
9601 char_u *varp;
9602{
9603 int dvi;
9604
9605 if (varp == NULL)
9606 return TRUE; /* hidden option is always at default */
9607 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9608 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009609 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009610 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009611 /* the cast to long is required for Manx C, long_i is
9612 * needed for MSVC */
9613 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009614 /* P_STRING */
9615 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9616}
9617
9618/*
9619 * showoneopt: show the value of one option
9620 * must not be called with a hidden option!
9621 */
9622 static void
9623showoneopt(p, opt_flags)
9624 struct vimoption *p;
9625 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9626{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009627 char_u *varp;
9628 int save_silent = silent_mode;
9629
9630 silent_mode = FALSE;
9631 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009632
9633 varp = get_varp_scope(p, opt_flags);
9634
9635 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9636 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9637 ? !curbufIsChanged() : !*(int *)varp))
9638 MSG_PUTS("no");
9639 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9640 MSG_PUTS("--");
9641 else
9642 MSG_PUTS(" ");
9643 MSG_PUTS(p->fullname);
9644 if (!(p->flags & P_BOOL))
9645 {
9646 msg_putchar('=');
9647 /* put value string in NameBuff */
9648 option_value2string(p, opt_flags);
9649 msg_outtrans(NameBuff);
9650 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009651
9652 silent_mode = save_silent;
9653 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654}
9655
9656/*
9657 * Write modified options as ":set" commands to a file.
9658 *
9659 * There are three values for "opt_flags":
9660 * OPT_GLOBAL: Write global option values and fresh values of
9661 * buffer-local options (used for start of a session
9662 * file).
9663 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9664 * curwin (used for a vimrc file).
9665 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9666 * and local values for window-local options of
9667 * curwin. Local values are also written when at the
9668 * default value, because a modeline or autocommand
9669 * may have set them when doing ":edit file" and the
9670 * user has set them back at the default or fresh
9671 * value.
9672 * When "local_only" is TRUE, don't write fresh
9673 * values, only local values (for ":mkview").
9674 * (fresh value = value used for a new buffer or window for a local option).
9675 *
9676 * Return FAIL on error, OK otherwise.
9677 */
9678 int
9679makeset(fd, opt_flags, local_only)
9680 FILE *fd;
9681 int opt_flags;
9682 int local_only;
9683{
9684 struct vimoption *p;
9685 char_u *varp; /* currently used value */
9686 char_u *varp_fresh; /* local value */
9687 char_u *varp_local = NULL; /* fresh value */
9688 char *cmd;
9689 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009690 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009691
9692 /*
9693 * The options that don't have a default (terminal name, columns, lines)
9694 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009695 * Do the loop over "options[]" twice: once for options with the
9696 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009697 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009698 for (pri = 1; pri >= 0; --pri)
9699 {
9700 for (p = &options[0]; !istermoption(p); p++)
9701 if (!(p->flags & P_NO_MKRC)
9702 && !istermoption(p)
9703 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009704 {
9705 /* skip global option when only doing locals */
9706 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9707 continue;
9708
9709 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9710 * file, they are always buffer-specific. */
9711 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9712 continue;
9713
9714 /* Global values are only written when not at the default value. */
9715 varp = get_varp_scope(p, opt_flags);
9716 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9717 continue;
9718
9719 round = 2;
9720 if (p->indir != PV_NONE)
9721 {
9722 if (p->var == VAR_WIN)
9723 {
9724 /* skip window-local option when only doing globals */
9725 if (!(opt_flags & OPT_LOCAL))
9726 continue;
9727 /* When fresh value of window-local option is not at the
9728 * default, need to write it too. */
9729 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9730 {
9731 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9732 if (!optval_default(p, varp_fresh))
9733 {
9734 round = 1;
9735 varp_local = varp;
9736 varp = varp_fresh;
9737 }
9738 }
9739 }
9740 }
9741
9742 /* Round 1: fresh value for window-local options.
9743 * Round 2: other values */
9744 for ( ; round <= 2; varp = varp_local, ++round)
9745 {
9746 if (round == 1 || (opt_flags & OPT_GLOBAL))
9747 cmd = "set";
9748 else
9749 cmd = "setlocal";
9750
9751 if (p->flags & P_BOOL)
9752 {
9753 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9754 return FAIL;
9755 }
9756 else if (p->flags & P_NUM)
9757 {
9758 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9759 return FAIL;
9760 }
9761 else /* P_STRING */
9762 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009763#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9764 int do_endif = FALSE;
9765
Bram Moolenaar071d4272004-06-13 20:20:40 +00009766 /* Don't set 'syntax' and 'filetype' again if the value is
9767 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009768 if (
9769# if defined(FEAT_SYN_HL)
9770 p->indir == PV_SYN
9771# if defined(FEAT_AUTOCMD)
9772 ||
9773# endif
9774# endif
9775# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009776 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009777# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009778 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009779 {
9780 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9781 *(char_u **)(varp)) < 0
9782 || put_eol(fd) < 0)
9783 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009784 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009785 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009787 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9788 (p->flags & P_EXPAND) != 0) == FAIL)
9789 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009790#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9791 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009792 {
9793 if (put_line(fd, "endif") == FAIL)
9794 return FAIL;
9795 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009797 }
9798 }
9799 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009800 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009801 return OK;
9802}
9803
9804#if defined(FEAT_FOLDING) || defined(PROTO)
9805/*
9806 * Generate set commands for the local fold options only. Used when
9807 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9808 */
9809 int
9810makefoldset(fd)
9811 FILE *fd;
9812{
9813 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9814# ifdef FEAT_EVAL
9815 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9816 == FAIL
9817# endif
9818 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9819 == FAIL
9820 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9821 == FAIL
9822 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9823 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9824 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9825 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9826 )
9827 return FAIL;
9828
9829 return OK;
9830}
9831#endif
9832
9833 static int
9834put_setstring(fd, cmd, name, valuep, expand)
9835 FILE *fd;
9836 char *cmd;
9837 char *name;
9838 char_u **valuep;
9839 int expand;
9840{
9841 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009842 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009843
9844 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9845 return FAIL;
9846 if (*valuep != NULL)
9847 {
9848 /* Output 'pastetoggle' as key names. For other
9849 * options some characters have to be escaped with
9850 * CTRL-V or backslash */
9851 if (valuep == &p_pt)
9852 {
9853 s = *valuep;
9854 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009855 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009856 return FAIL;
9857 }
9858 else if (expand)
9859 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009860 buf = alloc(MAXPATHL);
9861 if (buf == NULL)
9862 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009863 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9864 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009865 {
9866 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009867 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009868 }
9869 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009870 }
9871 else if (put_escstr(fd, *valuep, 2) == FAIL)
9872 return FAIL;
9873 }
9874 if (put_eol(fd) < 0)
9875 return FAIL;
9876 return OK;
9877}
9878
9879 static int
9880put_setnum(fd, cmd, name, valuep)
9881 FILE *fd;
9882 char *cmd;
9883 char *name;
9884 long *valuep;
9885{
9886 long wc;
9887
9888 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9889 return FAIL;
9890 if (wc_use_keyname((char_u *)valuep, &wc))
9891 {
9892 /* print 'wildchar' and 'wildcharm' as a key name */
9893 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9894 return FAIL;
9895 }
9896 else if (fprintf(fd, "%ld", *valuep) < 0)
9897 return FAIL;
9898 if (put_eol(fd) < 0)
9899 return FAIL;
9900 return OK;
9901}
9902
9903 static int
9904put_setbool(fd, cmd, name, value)
9905 FILE *fd;
9906 char *cmd;
9907 char *name;
9908 int value;
9909{
Bram Moolenaar893de922007-10-02 18:40:57 +00009910 if (value < 0) /* global/local option using global value */
9911 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009912 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9913 || put_eol(fd) < 0)
9914 return FAIL;
9915 return OK;
9916}
9917
9918/*
9919 * Clear all the terminal options.
9920 * If the option has been allocated, free the memory.
9921 * Terminal options are never hidden or indirect.
9922 */
9923 void
9924clear_termoptions()
9925{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009926 /*
9927 * Reset a few things before clearing the old options. This may cause
9928 * outputting a few things that the terminal doesn't understand, but the
9929 * screen will be cleared later, so this is OK.
9930 */
9931#ifdef FEAT_MOUSE_TTY
9932 mch_setmouse(FALSE); /* switch mouse off */
9933#endif
9934#ifdef FEAT_TITLE
9935 mch_restore_title(3); /* restore window titles */
9936#endif
9937#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9938 /* When starting the GUI close the display opened for the clipboard.
9939 * After restoring the title, because that will need the display. */
9940 if (gui.starting)
9941 clear_xterm_clip();
9942#endif
9943#ifdef WIN3264
9944 /*
9945 * Check if this is allowed now.
9946 */
9947 if (can_end_termcap_mode(FALSE) == TRUE)
9948#endif
9949 stoptermcap(); /* stop termcap mode */
9950
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009951 free_termoptions();
9952}
9953
9954 void
9955free_termoptions()
9956{
9957 struct vimoption *p;
9958
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959 for (p = &options[0]; p->fullname != NULL; p++)
9960 if (istermoption(p))
9961 {
9962 if (p->flags & P_ALLOCED)
9963 free_string_option(*(char_u **)(p->var));
9964 if (p->flags & P_DEF_ALLOCED)
9965 free_string_option(p->def_val[VI_DEFAULT]);
9966 *(char_u **)(p->var) = empty_option;
9967 p->def_val[VI_DEFAULT] = empty_option;
9968 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9969 }
9970 clear_termcodes();
9971}
9972
9973/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009974 * Free the string for one term option, if it was allocated.
9975 * Set the string to empty_option and clear allocated flag.
9976 * "var" points to the option value.
9977 */
9978 void
9979free_one_termoption(var)
9980 char_u *var;
9981{
9982 struct vimoption *p;
9983
9984 for (p = &options[0]; p->fullname != NULL; p++)
9985 if (p->var == var)
9986 {
9987 if (p->flags & P_ALLOCED)
9988 free_string_option(*(char_u **)(p->var));
9989 *(char_u **)(p->var) = empty_option;
9990 p->flags &= ~P_ALLOCED;
9991 break;
9992 }
9993}
9994
9995/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009996 * Set the terminal option defaults to the current value.
9997 * Used after setting the terminal name.
9998 */
9999 void
10000set_term_defaults()
10001{
10002 struct vimoption *p;
10003
10004 for (p = &options[0]; p->fullname != NULL; p++)
10005 {
10006 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10007 {
10008 if (p->flags & P_DEF_ALLOCED)
10009 {
10010 free_string_option(p->def_val[VI_DEFAULT]);
10011 p->flags &= ~P_DEF_ALLOCED;
10012 }
10013 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10014 if (p->flags & P_ALLOCED)
10015 {
10016 p->flags |= P_DEF_ALLOCED;
10017 p->flags &= ~P_ALLOCED; /* don't free the value now */
10018 }
10019 }
10020 }
10021}
10022
10023/*
10024 * return TRUE if 'p' starts with 't_'
10025 */
10026 static int
10027istermoption(p)
10028 struct vimoption *p;
10029{
10030 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10031}
10032
10033/*
10034 * Compute columns for ruler and shown command. 'sc_col' is also used to
10035 * decide what the maximum length of a message on the status line can be.
10036 * If there is a status line for the last window, 'sc_col' is independent
10037 * of 'ru_col'.
10038 */
10039
10040#define COL_RULER 17 /* columns needed by standard ruler */
10041
10042 void
10043comp_col()
10044{
10045#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10046 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10047
10048 sc_col = 0;
10049 ru_col = 0;
10050 if (p_ru)
10051 {
10052#ifdef FEAT_STL_OPT
10053 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10054#else
10055 ru_col = COL_RULER + 1;
10056#endif
10057 /* no last status line, adjust sc_col */
10058 if (!last_has_status)
10059 sc_col = ru_col;
10060 }
10061 if (p_sc)
10062 {
10063 sc_col += SHOWCMD_COLS;
10064 if (!p_ru || last_has_status) /* no need for separating space */
10065 ++sc_col;
10066 }
10067 sc_col = Columns - sc_col;
10068 ru_col = Columns - ru_col;
10069 if (sc_col <= 0) /* screen too narrow, will become a mess */
10070 sc_col = 1;
10071 if (ru_col <= 0)
10072 ru_col = 1;
10073#else
10074 sc_col = Columns;
10075 ru_col = Columns;
10076#endif
10077}
10078
10079/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010080 * Unset local option value, similar to ":set opt<".
10081 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010082 void
10083unset_global_local_option(name, from)
10084 char_u *name;
10085 void *from;
10086{
10087 struct vimoption *p;
10088 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010089 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010090
10091 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010092 if (opt_idx < 0)
10093 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010094 p = &(options[opt_idx]);
10095
10096 switch ((int)p->indir)
10097 {
10098 /* global option with local value: use local value if it's been set */
10099 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010100 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010101 break;
10102 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010103 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010104 break;
10105 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010106 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010107 break;
10108 case PV_AR:
10109 buf->b_p_ar = -1;
10110 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010111 case PV_BKC:
10112 clear_string_option(&buf->b_p_bkc);
10113 buf->b_bkc_flags = 0;
10114 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010115 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010116 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010117 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010118 case PV_TC:
10119 clear_string_option(&buf->b_p_tc);
10120 buf->b_tc_flags = 0;
10121 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010122#ifdef FEAT_FIND_ID
10123 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010124 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010125 break;
10126 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010127 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010128 break;
10129#endif
10130#ifdef FEAT_INS_EXPAND
10131 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010132 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010133 break;
10134 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010135 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010136 break;
10137#endif
10138#ifdef FEAT_QUICKFIX
10139 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010140 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010141 break;
10142 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010143 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010144 break;
10145 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010146 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010147 break;
10148#endif
10149#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10150 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010151 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010152 break;
10153#endif
10154#if defined(FEAT_CRYPT)
10155 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010156 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010157 break;
10158#endif
10159#ifdef FEAT_STL_OPT
10160 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010161 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010162 break;
10163#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010164 case PV_UL:
10165 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10166 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010167#ifdef FEAT_LISP
10168 case PV_LW:
10169 clear_string_option(&buf->b_p_lw);
10170 break;
10171#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010172 }
10173}
10174
10175/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010176 * Get pointer to option variable, depending on local or global scope.
10177 */
10178 static char_u *
10179get_varp_scope(p, opt_flags)
10180 struct vimoption *p;
10181 int opt_flags;
10182{
10183 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10184 {
10185 if (p->var == VAR_WIN)
10186 return (char_u *)GLOBAL_WO(get_varp(p));
10187 return p->var;
10188 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010189 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 {
10191 switch ((int)p->indir)
10192 {
10193#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010194 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10195 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10196 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010198 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10199 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10200 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010201 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010202 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010203 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010205 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10206 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010207#endif
10208#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010209 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10210 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010212#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10213 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10214#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010215#if defined(FEAT_CRYPT)
10216 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10217#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010218#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010219 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010220#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010221 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010222#ifdef FEAT_LISP
10223 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10224#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010225 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010226 }
10227 return NULL; /* "cannot happen" */
10228 }
10229 return get_varp(p);
10230}
10231
10232/*
10233 * Get pointer to option variable.
10234 */
10235 static char_u *
10236get_varp(p)
10237 struct vimoption *p;
10238{
10239 /* hidden option, always return NULL */
10240 if (p->var == NULL)
10241 return NULL;
10242
10243 switch ((int)p->indir)
10244 {
10245 case PV_NONE: return p->var;
10246
10247 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010248 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010249 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010250 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010251 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010252 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010254 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010256 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010258 case PV_TC: return *curbuf->b_p_tc != NUL
10259 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010260 case PV_BKC: return *curbuf->b_p_bkc != NUL
10261 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010263 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010265 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10267#endif
10268#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010269 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010271 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10273#endif
10274#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010275 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010276 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010277 case PV_GP: return *curbuf->b_p_gp != NUL
10278 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10279 case PV_MP: return *curbuf->b_p_mp != NUL
10280 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010281#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010282#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10283 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10284 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10285#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010286#if defined(FEAT_CRYPT)
10287 case PV_CM: return *curbuf->b_p_cm != NUL
10288 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10289#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010290#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010291 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010292 ? (char_u *)&(curwin->w_p_stl) : p->var;
10293#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010294 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10295 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010296#ifdef FEAT_LISP
10297 case PV_LW: return *curbuf->b_p_lw != NUL
10298 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10299#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300
10301#ifdef FEAT_ARABIC
10302 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10303#endif
10304 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010305#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010306 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10307#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010308#ifdef FEAT_SYN_HL
10309 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10310 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010311 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010313#ifdef FEAT_DIFF
10314 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10315#endif
10316#ifdef FEAT_FOLDING
10317 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10318 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10319 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10320 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10321 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10322 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10323 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10324# ifdef FEAT_EVAL
10325 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10326 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10327# endif
10328 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10329#endif
10330 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010331 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010332#ifdef FEAT_LINEBREAK
10333 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10334#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010335#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010336 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10337#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010338#ifdef FEAT_VERTSPLIT
10339 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10342 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10343#endif
10344#ifdef FEAT_RIGHTLEFT
10345 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10346 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10347#endif
10348 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10349 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10350#ifdef FEAT_LINEBREAK
10351 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010352 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10353 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010354#endif
10355#ifdef FEAT_SCROLLBIND
10356 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10357#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010358#ifdef FEAT_CURSORBIND
10359 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10360#endif
10361#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010362 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10363 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010364#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365
10366 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10367 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10368#ifdef FEAT_MBYTE
10369 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10370#endif
10371#if defined(FEAT_QUICKFIX)
10372 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10373 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10374#endif
10375 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10376 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10377#ifdef FEAT_CINDENT
10378 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10379 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10380 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10381#endif
10382#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10383 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10384#endif
10385#ifdef FEAT_COMMENTS
10386 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10387#endif
10388#ifdef FEAT_FOLDING
10389 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10390#endif
10391#ifdef FEAT_INS_EXPAND
10392 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10393#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010394#ifdef FEAT_COMPL_FUNC
10395 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010396 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010397#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010399 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010400 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10401#ifdef FEAT_MBYTE
10402 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10403#endif
10404 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10405#ifdef FEAT_AUTOCMD
10406 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10407#endif
10408 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010409 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010410 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10411 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10412 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10413 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10414#ifdef FEAT_FIND_ID
10415# ifdef FEAT_EVAL
10416 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10417# endif
10418#endif
10419#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10420 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10421 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10422#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010423#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010424 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10425#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426#ifdef FEAT_CRYPT
10427 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10428#endif
10429#ifdef FEAT_LISP
10430 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10431#endif
10432 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10433 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10434 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10435 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10436 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010437 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010438#ifdef FEAT_TEXTOBJ
10439 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010441 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10442#ifdef FEAT_SMARTINDENT
10443 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10444#endif
10445#ifndef SHORT_FNAME
10446 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10447#endif
10448 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10449#ifdef FEAT_SEARCHPATH
10450 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10451#endif
10452 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10453#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010454 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010455 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10456#endif
10457#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010458 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10459 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10460 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010461#endif
10462 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10463 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10464 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10465 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010466#ifdef FEAT_PERSISTENT_UNDO
10467 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010469 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10470#ifdef FEAT_KEYMAP
10471 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10472#endif
10473 default: EMSG(_("E356: get_varp ERROR"));
10474 }
10475 /* always return a valid pointer to avoid a crash! */
10476 return (char_u *)&(curbuf->b_p_wm);
10477}
10478
10479/*
10480 * Get the value of 'equalprg', either the buffer-local one or the global one.
10481 */
10482 char_u *
10483get_equalprg()
10484{
10485 if (*curbuf->b_p_ep == NUL)
10486 return p_ep;
10487 return curbuf->b_p_ep;
10488}
10489
10490#if defined(FEAT_WINDOWS) || defined(PROTO)
10491/*
10492 * Copy options from one window to another.
10493 * Used when splitting a window.
10494 */
10495 void
10496win_copy_options(wp_from, wp_to)
10497 win_T *wp_from;
10498 win_T *wp_to;
10499{
10500 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10501 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10502# ifdef FEAT_RIGHTLEFT
10503# ifdef FEAT_FKMAP
10504 /* Is this right? */
10505 wp_to->w_farsi = wp_from->w_farsi;
10506# endif
10507# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010508#if defined(FEAT_LINEBREAK)
10509 briopt_check(wp_to);
10510#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511}
10512#endif
10513
10514/*
10515 * Copy the options from one winopt_T to another.
10516 * Doesn't free the old option values in "to", use clear_winopt() for that.
10517 * The 'scroll' option is not copied, because it depends on the window height.
10518 * The 'previewwindow' option is reset, there can be only one preview window.
10519 */
10520 void
10521copy_winopt(from, to)
10522 winopt_T *from;
10523 winopt_T *to;
10524{
10525#ifdef FEAT_ARABIC
10526 to->wo_arab = from->wo_arab;
10527#endif
10528 to->wo_list = from->wo_list;
10529 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010530 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010531#ifdef FEAT_LINEBREAK
10532 to->wo_nuw = from->wo_nuw;
10533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534#ifdef FEAT_RIGHTLEFT
10535 to->wo_rl = from->wo_rl;
10536 to->wo_rlc = vim_strsave(from->wo_rlc);
10537#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010538#ifdef FEAT_STL_OPT
10539 to->wo_stl = vim_strsave(from->wo_stl);
10540#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010542#ifdef FEAT_DIFF
10543 to->wo_wrap_save = from->wo_wrap_save;
10544#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545#ifdef FEAT_LINEBREAK
10546 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010547 to->wo_bri = from->wo_bri;
10548 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549#endif
10550#ifdef FEAT_SCROLLBIND
10551 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010552 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010554#ifdef FEAT_CURSORBIND
10555 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010556 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010557#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010558#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010559 to->wo_spell = from->wo_spell;
10560#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010561#ifdef FEAT_SYN_HL
10562 to->wo_cuc = from->wo_cuc;
10563 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010564 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010565#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566#ifdef FEAT_DIFF
10567 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010568 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010570#ifdef FEAT_CONCEAL
10571 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010572 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010573#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574#ifdef FEAT_FOLDING
10575 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010576 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010578 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579 to->wo_fdi = vim_strsave(from->wo_fdi);
10580 to->wo_fml = from->wo_fml;
10581 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010582 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010584 to->wo_fdm_save = from->wo_diff_saved
10585 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586 to->wo_fdn = from->wo_fdn;
10587# ifdef FEAT_EVAL
10588 to->wo_fde = vim_strsave(from->wo_fde);
10589 to->wo_fdt = vim_strsave(from->wo_fdt);
10590# endif
10591 to->wo_fmr = vim_strsave(from->wo_fmr);
10592#endif
10593 check_winopt(to); /* don't want NULL pointers */
10594}
10595
10596/*
10597 * Check string options in a window for a NULL value.
10598 */
10599 void
10600check_win_options(win)
10601 win_T *win;
10602{
10603 check_winopt(&win->w_onebuf_opt);
10604 check_winopt(&win->w_allbuf_opt);
10605}
10606
10607/*
10608 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10609 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010610 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010612 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010613{
10614#ifdef FEAT_FOLDING
10615 check_string_option(&wop->wo_fdi);
10616 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010617 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618# ifdef FEAT_EVAL
10619 check_string_option(&wop->wo_fde);
10620 check_string_option(&wop->wo_fdt);
10621# endif
10622 check_string_option(&wop->wo_fmr);
10623#endif
10624#ifdef FEAT_RIGHTLEFT
10625 check_string_option(&wop->wo_rlc);
10626#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010627#ifdef FEAT_STL_OPT
10628 check_string_option(&wop->wo_stl);
10629#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010630#ifdef FEAT_SYN_HL
10631 check_string_option(&wop->wo_cc);
10632#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010633#ifdef FEAT_CONCEAL
10634 check_string_option(&wop->wo_cocu);
10635#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010636#ifdef FEAT_LINEBREAK
10637 check_string_option(&wop->wo_briopt);
10638#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010639}
10640
10641/*
10642 * Free the allocated memory inside a winopt_T.
10643 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010644 void
10645clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010646 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647{
10648#ifdef FEAT_FOLDING
10649 clear_string_option(&wop->wo_fdi);
10650 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010651 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010652# ifdef FEAT_EVAL
10653 clear_string_option(&wop->wo_fde);
10654 clear_string_option(&wop->wo_fdt);
10655# endif
10656 clear_string_option(&wop->wo_fmr);
10657#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010658#ifdef FEAT_LINEBREAK
10659 clear_string_option(&wop->wo_briopt);
10660#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010661#ifdef FEAT_RIGHTLEFT
10662 clear_string_option(&wop->wo_rlc);
10663#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010664#ifdef FEAT_STL_OPT
10665 clear_string_option(&wop->wo_stl);
10666#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010667#ifdef FEAT_SYN_HL
10668 clear_string_option(&wop->wo_cc);
10669#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010670#ifdef FEAT_CONCEAL
10671 clear_string_option(&wop->wo_cocu);
10672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010673}
10674
10675/*
10676 * Copy global option values to local options for one buffer.
10677 * Used when creating a new buffer and sometimes when entering a buffer.
10678 * flags:
10679 * BCO_ENTER We will enter the buf buffer.
10680 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10681 * appropriate.
10682 * BCO_NOHELP Don't copy the values to a help buffer.
10683 */
10684 void
10685buf_copy_options(buf, flags)
10686 buf_T *buf;
10687 int flags;
10688{
10689 int should_copy = TRUE;
10690 char_u *save_p_isk = NULL; /* init for GCC */
10691 int dont_do_help;
10692 int did_isk = FALSE;
10693
10694 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010695 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010696 */
10697 if (buf == NULL || !buf_valid(buf))
10698 return;
10699
10700 /*
10701 * Skip this when the option defaults have not been set yet. Happens when
10702 * main() allocates the first buffer.
10703 */
10704 if (p_cpo != NULL)
10705 {
10706 /*
10707 * Always copy when entering and 'cpo' contains 'S'.
10708 * Don't copy when already initialized.
10709 * Don't copy when 'cpo' contains 's' and not entering.
10710 * 'S' BCO_ENTER initialized 's' should_copy
10711 * yes yes X X TRUE
10712 * yes no yes X FALSE
10713 * no X yes X FALSE
10714 * X no no yes FALSE
10715 * X no no no TRUE
10716 * no yes no X TRUE
10717 */
10718 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10719 && (buf->b_p_initialized
10720 || (!(flags & BCO_ENTER)
10721 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10722 should_copy = FALSE;
10723
10724 if (should_copy || (flags & BCO_ALWAYS))
10725 {
10726 /* Don't copy the options specific to a help buffer when
10727 * BCO_NOHELP is given or the options were initialized already
10728 * (jumping back to a help file with CTRL-T or CTRL-O) */
10729 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10730 || buf->b_p_initialized;
10731 if (dont_do_help) /* don't free b_p_isk */
10732 {
10733 save_p_isk = buf->b_p_isk;
10734 buf->b_p_isk = NULL;
10735 }
10736 /*
10737 * Always free the allocated strings.
10738 * If not already initialized, set 'readonly' and copy 'fileformat'.
10739 */
10740 if (!buf->b_p_initialized)
10741 {
10742 free_buf_options(buf, TRUE);
10743 buf->b_p_ro = FALSE; /* don't copy readonly */
10744 buf->b_p_tx = p_tx;
10745#ifdef FEAT_MBYTE
10746 buf->b_p_fenc = vim_strsave(p_fenc);
10747#endif
10748 buf->b_p_ff = vim_strsave(p_ff);
10749#if defined(FEAT_QUICKFIX)
10750 buf->b_p_bh = empty_option;
10751 buf->b_p_bt = empty_option;
10752#endif
10753 }
10754 else
10755 free_buf_options(buf, FALSE);
10756
10757 buf->b_p_ai = p_ai;
10758 buf->b_p_ai_nopaste = p_ai_nopaste;
10759 buf->b_p_sw = p_sw;
10760 buf->b_p_tw = p_tw;
10761 buf->b_p_tw_nopaste = p_tw_nopaste;
10762 buf->b_p_tw_nobin = p_tw_nobin;
10763 buf->b_p_wm = p_wm;
10764 buf->b_p_wm_nopaste = p_wm_nopaste;
10765 buf->b_p_wm_nobin = p_wm_nobin;
10766 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010767#ifdef FEAT_MBYTE
10768 buf->b_p_bomb = p_bomb;
10769#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010770 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771 buf->b_p_et = p_et;
10772 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010773 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 buf->b_p_ml = p_ml;
10775 buf->b_p_ml_nobin = p_ml_nobin;
10776 buf->b_p_inf = p_inf;
10777 buf->b_p_swf = p_swf;
10778#ifdef FEAT_INS_EXPAND
10779 buf->b_p_cpt = vim_strsave(p_cpt);
10780#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010781#ifdef FEAT_COMPL_FUNC
10782 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010783 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010785 buf->b_p_sts = p_sts;
10786 buf->b_p_sts_nopaste = p_sts_nopaste;
10787#ifndef SHORT_FNAME
10788 buf->b_p_sn = p_sn;
10789#endif
10790#ifdef FEAT_COMMENTS
10791 buf->b_p_com = vim_strsave(p_com);
10792#endif
10793#ifdef FEAT_FOLDING
10794 buf->b_p_cms = vim_strsave(p_cms);
10795#endif
10796 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010797 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798 buf->b_p_nf = vim_strsave(p_nf);
10799 buf->b_p_mps = vim_strsave(p_mps);
10800#ifdef FEAT_SMARTINDENT
10801 buf->b_p_si = p_si;
10802#endif
10803 buf->b_p_ci = p_ci;
10804#ifdef FEAT_CINDENT
10805 buf->b_p_cin = p_cin;
10806 buf->b_p_cink = vim_strsave(p_cink);
10807 buf->b_p_cino = vim_strsave(p_cino);
10808#endif
10809#ifdef FEAT_AUTOCMD
10810 /* Don't copy 'filetype', it must be detected */
10811 buf->b_p_ft = empty_option;
10812#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010813 buf->b_p_pi = p_pi;
10814#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10815 buf->b_p_cinw = vim_strsave(p_cinw);
10816#endif
10817#ifdef FEAT_LISP
10818 buf->b_p_lisp = p_lisp;
10819#endif
10820#ifdef FEAT_SYN_HL
10821 /* Don't copy 'syntax', it must be set */
10822 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010823 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010824#endif
10825#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010826 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010827 (void)compile_cap_prog(&buf->b_s);
10828 buf->b_s.b_p_spf = vim_strsave(p_spf);
10829 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010830#endif
10831#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10832 buf->b_p_inde = vim_strsave(p_inde);
10833 buf->b_p_indk = vim_strsave(p_indk);
10834#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010835#if defined(FEAT_EVAL)
10836 buf->b_p_fex = vim_strsave(p_fex);
10837#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010838#ifdef FEAT_CRYPT
10839 buf->b_p_key = vim_strsave(p_key);
10840#endif
10841#ifdef FEAT_SEARCHPATH
10842 buf->b_p_sua = vim_strsave(p_sua);
10843#endif
10844#ifdef FEAT_KEYMAP
10845 buf->b_p_keymap = vim_strsave(p_keymap);
10846 buf->b_kmap_state |= KEYMAP_INIT;
10847#endif
10848 /* This isn't really an option, but copying the langmap and IME
10849 * state from the current buffer is better than resetting it. */
10850 buf->b_p_iminsert = p_iminsert;
10851 buf->b_p_imsearch = p_imsearch;
10852
10853 /* options that are normally global but also have a local value
10854 * are not copied, start using the global value */
10855 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010856 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010857 buf->b_p_bkc = empty_option;
10858 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010859#ifdef FEAT_QUICKFIX
10860 buf->b_p_gp = empty_option;
10861 buf->b_p_mp = empty_option;
10862 buf->b_p_efm = empty_option;
10863#endif
10864 buf->b_p_ep = empty_option;
10865 buf->b_p_kp = empty_option;
10866 buf->b_p_path = empty_option;
10867 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010868 buf->b_p_tc = empty_option;
10869 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010870#ifdef FEAT_FIND_ID
10871 buf->b_p_def = empty_option;
10872 buf->b_p_inc = empty_option;
10873# ifdef FEAT_EVAL
10874 buf->b_p_inex = vim_strsave(p_inex);
10875# endif
10876#endif
10877#ifdef FEAT_INS_EXPAND
10878 buf->b_p_dict = empty_option;
10879 buf->b_p_tsr = empty_option;
10880#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010881#ifdef FEAT_TEXTOBJ
10882 buf->b_p_qe = vim_strsave(p_qe);
10883#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010884#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10885 buf->b_p_bexpr = empty_option;
10886#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010887#if defined(FEAT_CRYPT)
10888 buf->b_p_cm = empty_option;
10889#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010890#ifdef FEAT_PERSISTENT_UNDO
10891 buf->b_p_udf = p_udf;
10892#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010893#ifdef FEAT_LISP
10894 buf->b_p_lw = empty_option;
10895#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010896
10897 /*
10898 * Don't copy the options set by ex_help(), use the saved values,
10899 * when going from a help buffer to a non-help buffer.
10900 * Don't touch these at all when BCO_NOHELP is used and going from
10901 * or to a help buffer.
10902 */
10903 if (dont_do_help)
10904 buf->b_p_isk = save_p_isk;
10905 else
10906 {
10907 buf->b_p_isk = vim_strsave(p_isk);
10908 did_isk = TRUE;
10909 buf->b_p_ts = p_ts;
10910 buf->b_help = FALSE;
10911#ifdef FEAT_QUICKFIX
10912 if (buf->b_p_bt[0] == 'h')
10913 clear_string_option(&buf->b_p_bt);
10914#endif
10915 buf->b_p_ma = p_ma;
10916 }
10917 }
10918
10919 /*
10920 * When the options should be copied (ignoring BCO_ALWAYS), set the
10921 * flag that indicates that the options have been initialized.
10922 */
10923 if (should_copy)
10924 buf->b_p_initialized = TRUE;
10925 }
10926
10927 check_buf_options(buf); /* make sure we don't have NULLs */
10928 if (did_isk)
10929 (void)buf_init_chartab(buf, FALSE);
10930}
10931
10932/*
10933 * Reset the 'modifiable' option and its default value.
10934 */
10935 void
10936reset_modifiable()
10937{
10938 int opt_idx;
10939
10940 curbuf->b_p_ma = FALSE;
10941 p_ma = FALSE;
10942 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010943 if (opt_idx >= 0)
10944 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945}
10946
10947/*
10948 * Set the global value for 'iminsert' to the local value.
10949 */
10950 void
10951set_iminsert_global()
10952{
10953 p_iminsert = curbuf->b_p_iminsert;
10954}
10955
10956/*
10957 * Set the global value for 'imsearch' to the local value.
10958 */
10959 void
10960set_imsearch_global()
10961{
10962 p_imsearch = curbuf->b_p_imsearch;
10963}
10964
10965#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10966static int expand_option_idx = -1;
10967static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10968static int expand_option_flags = 0;
10969
10970 void
10971set_context_in_set_cmd(xp, arg, opt_flags)
10972 expand_T *xp;
10973 char_u *arg;
10974 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10975{
10976 int nextchar;
10977 long_u flags = 0; /* init for GCC */
10978 int opt_idx = 0; /* init for GCC */
10979 char_u *p;
10980 char_u *s;
10981 int is_term_option = FALSE;
10982 int key;
10983
10984 expand_option_flags = opt_flags;
10985
10986 xp->xp_context = EXPAND_SETTINGS;
10987 if (*arg == NUL)
10988 {
10989 xp->xp_pattern = arg;
10990 return;
10991 }
10992 p = arg + STRLEN(arg) - 1;
10993 if (*p == ' ' && *(p - 1) != '\\')
10994 {
10995 xp->xp_pattern = p + 1;
10996 return;
10997 }
10998 while (p > arg)
10999 {
11000 s = p;
11001 /* count number of backslashes before ' ' or ',' */
11002 if (*p == ' ' || *p == ',')
11003 {
11004 while (s > arg && *(s - 1) == '\\')
11005 --s;
11006 }
11007 /* break at a space with an even number of backslashes */
11008 if (*p == ' ' && ((p - s) & 1) == 0)
11009 {
11010 ++p;
11011 break;
11012 }
11013 --p;
11014 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011015 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011016 {
11017 xp->xp_context = EXPAND_BOOL_SETTINGS;
11018 p += 2;
11019 }
11020 if (STRNCMP(p, "inv", 3) == 0)
11021 {
11022 xp->xp_context = EXPAND_BOOL_SETTINGS;
11023 p += 3;
11024 }
11025 xp->xp_pattern = arg = p;
11026 if (*arg == '<')
11027 {
11028 while (*p != '>')
11029 if (*p++ == NUL) /* expand terminal option name */
11030 return;
11031 key = get_special_key_code(arg + 1);
11032 if (key == 0) /* unknown name */
11033 {
11034 xp->xp_context = EXPAND_NOTHING;
11035 return;
11036 }
11037 nextchar = *++p;
11038 is_term_option = TRUE;
11039 expand_option_name[2] = KEY2TERMCAP0(key);
11040 expand_option_name[3] = KEY2TERMCAP1(key);
11041 }
11042 else
11043 {
11044 if (p[0] == 't' && p[1] == '_')
11045 {
11046 p += 2;
11047 if (*p != NUL)
11048 ++p;
11049 if (*p == NUL)
11050 return; /* expand option name */
11051 nextchar = *++p;
11052 is_term_option = TRUE;
11053 expand_option_name[2] = p[-2];
11054 expand_option_name[3] = p[-1];
11055 }
11056 else
11057 {
11058 /* Allow * wildcard */
11059 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11060 p++;
11061 if (*p == NUL)
11062 return;
11063 nextchar = *p;
11064 *p = NUL;
11065 opt_idx = findoption(arg);
11066 *p = nextchar;
11067 if (opt_idx == -1 || options[opt_idx].var == NULL)
11068 {
11069 xp->xp_context = EXPAND_NOTHING;
11070 return;
11071 }
11072 flags = options[opt_idx].flags;
11073 if (flags & P_BOOL)
11074 {
11075 xp->xp_context = EXPAND_NOTHING;
11076 return;
11077 }
11078 }
11079 }
11080 /* handle "-=" and "+=" */
11081 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11082 {
11083 ++p;
11084 nextchar = '=';
11085 }
11086 if ((nextchar != '=' && nextchar != ':')
11087 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11088 {
11089 xp->xp_context = EXPAND_UNSUCCESSFUL;
11090 return;
11091 }
11092 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11093 {
11094 xp->xp_context = EXPAND_OLD_SETTING;
11095 if (is_term_option)
11096 expand_option_idx = -1;
11097 else
11098 expand_option_idx = opt_idx;
11099 xp->xp_pattern = p + 1;
11100 return;
11101 }
11102 xp->xp_context = EXPAND_NOTHING;
11103 if (is_term_option || (flags & P_NUM))
11104 return;
11105
11106 xp->xp_pattern = p + 1;
11107
11108 if (flags & P_EXPAND)
11109 {
11110 p = options[opt_idx].var;
11111 if (p == (char_u *)&p_bdir
11112 || p == (char_u *)&p_dir
11113 || p == (char_u *)&p_path
11114 || p == (char_u *)&p_rtp
11115#ifdef FEAT_SEARCHPATH
11116 || p == (char_u *)&p_cdpath
11117#endif
11118#ifdef FEAT_SESSION
11119 || p == (char_u *)&p_vdir
11120#endif
11121 )
11122 {
11123 xp->xp_context = EXPAND_DIRECTORIES;
11124 if (p == (char_u *)&p_path
11125#ifdef FEAT_SEARCHPATH
11126 || p == (char_u *)&p_cdpath
11127#endif
11128 )
11129 xp->xp_backslash = XP_BS_THREE;
11130 else
11131 xp->xp_backslash = XP_BS_ONE;
11132 }
11133 else
11134 {
11135 xp->xp_context = EXPAND_FILES;
11136 /* for 'tags' need three backslashes for a space */
11137 if (p == (char_u *)&p_tags)
11138 xp->xp_backslash = XP_BS_THREE;
11139 else
11140 xp->xp_backslash = XP_BS_ONE;
11141 }
11142 }
11143
11144 /* For an option that is a list of file names, find the start of the
11145 * last file name. */
11146 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11147 {
11148 /* count number of backslashes before ' ' or ',' */
11149 if (*p == ' ' || *p == ',')
11150 {
11151 s = p;
11152 while (s > xp->xp_pattern && *(s - 1) == '\\')
11153 --s;
11154 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11155 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11156 {
11157 xp->xp_pattern = p + 1;
11158 break;
11159 }
11160 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011161
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011162#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011163 /* for 'spellsuggest' start at "file:" */
11164 if (options[opt_idx].var == (char_u *)&p_sps
11165 && STRNCMP(p, "file:", 5) == 0)
11166 {
11167 xp->xp_pattern = p + 5;
11168 break;
11169 }
11170#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011171 }
11172
11173 return;
11174}
11175
11176 int
11177ExpandSettings(xp, regmatch, num_file, file)
11178 expand_T *xp;
11179 regmatch_T *regmatch;
11180 int *num_file;
11181 char_u ***file;
11182{
11183 int num_normal = 0; /* Nr of matching non-term-code settings */
11184 int num_term = 0; /* Nr of matching terminal code settings */
11185 int opt_idx;
11186 int match;
11187 int count = 0;
11188 char_u *str;
11189 int loop;
11190 int is_term_opt;
11191 char_u name_buf[MAX_KEY_NAME_LEN];
11192 static char *(names[]) = {"all", "termcap"};
11193 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11194
11195 /* do this loop twice:
11196 * loop == 0: count the number of matching options
11197 * loop == 1: copy the matching options into allocated memory
11198 */
11199 for (loop = 0; loop <= 1; ++loop)
11200 {
11201 regmatch->rm_ic = ic;
11202 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11203 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011204 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11205 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11207 {
11208 if (loop == 0)
11209 num_normal++;
11210 else
11211 (*file)[count++] = vim_strsave((char_u *)names[match]);
11212 }
11213 }
11214 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11215 opt_idx++)
11216 {
11217 if (options[opt_idx].var == NULL)
11218 continue;
11219 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11220 && !(options[opt_idx].flags & P_BOOL))
11221 continue;
11222 is_term_opt = istermoption(&options[opt_idx]);
11223 if (is_term_opt && num_normal > 0)
11224 continue;
11225 match = FALSE;
11226 if (vim_regexec(regmatch, str, (colnr_T)0)
11227 || (options[opt_idx].shortname != NULL
11228 && vim_regexec(regmatch,
11229 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11230 match = TRUE;
11231 else if (is_term_opt)
11232 {
11233 name_buf[0] = '<';
11234 name_buf[1] = 't';
11235 name_buf[2] = '_';
11236 name_buf[3] = str[2];
11237 name_buf[4] = str[3];
11238 name_buf[5] = '>';
11239 name_buf[6] = NUL;
11240 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11241 {
11242 match = TRUE;
11243 str = name_buf;
11244 }
11245 }
11246 if (match)
11247 {
11248 if (loop == 0)
11249 {
11250 if (is_term_opt)
11251 num_term++;
11252 else
11253 num_normal++;
11254 }
11255 else
11256 (*file)[count++] = vim_strsave(str);
11257 }
11258 }
11259 /*
11260 * Check terminal key codes, these are not in the option table
11261 */
11262 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11263 {
11264 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11265 {
11266 if (!isprint(str[0]) || !isprint(str[1]))
11267 continue;
11268
11269 name_buf[0] = 't';
11270 name_buf[1] = '_';
11271 name_buf[2] = str[0];
11272 name_buf[3] = str[1];
11273 name_buf[4] = NUL;
11274
11275 match = FALSE;
11276 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11277 match = TRUE;
11278 else
11279 {
11280 name_buf[0] = '<';
11281 name_buf[1] = 't';
11282 name_buf[2] = '_';
11283 name_buf[3] = str[0];
11284 name_buf[4] = str[1];
11285 name_buf[5] = '>';
11286 name_buf[6] = NUL;
11287
11288 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11289 match = TRUE;
11290 }
11291 if (match)
11292 {
11293 if (loop == 0)
11294 num_term++;
11295 else
11296 (*file)[count++] = vim_strsave(name_buf);
11297 }
11298 }
11299
11300 /*
11301 * Check special key names.
11302 */
11303 regmatch->rm_ic = TRUE; /* ignore case here */
11304 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11305 {
11306 name_buf[0] = '<';
11307 STRCPY(name_buf + 1, str);
11308 STRCAT(name_buf, ">");
11309
11310 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11311 {
11312 if (loop == 0)
11313 num_term++;
11314 else
11315 (*file)[count++] = vim_strsave(name_buf);
11316 }
11317 }
11318 }
11319 if (loop == 0)
11320 {
11321 if (num_normal > 0)
11322 *num_file = num_normal;
11323 else if (num_term > 0)
11324 *num_file = num_term;
11325 else
11326 return OK;
11327 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11328 if (*file == NULL)
11329 {
11330 *file = (char_u **)"";
11331 return FAIL;
11332 }
11333 }
11334 }
11335 return OK;
11336}
11337
11338 int
11339ExpandOldSetting(num_file, file)
11340 int *num_file;
11341 char_u ***file;
11342{
11343 char_u *var = NULL; /* init for GCC */
11344 char_u *buf;
11345
11346 *num_file = 0;
11347 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11348 if (*file == NULL)
11349 return FAIL;
11350
11351 /*
11352 * For a terminal key code expand_option_idx is < 0.
11353 */
11354 if (expand_option_idx < 0)
11355 {
11356 var = find_termcode(expand_option_name + 2);
11357 if (var == NULL)
11358 expand_option_idx = findoption(expand_option_name);
11359 }
11360
11361 if (expand_option_idx >= 0)
11362 {
11363 /* put string of option value in NameBuff */
11364 option_value2string(&options[expand_option_idx], expand_option_flags);
11365 var = NameBuff;
11366 }
11367 else if (var == NULL)
11368 var = (char_u *)"";
11369
11370 /* A backslash is required before some characters. This is the reverse of
11371 * what happens in do_set(). */
11372 buf = vim_strsave_escaped(var, escape_chars);
11373
11374 if (buf == NULL)
11375 {
11376 vim_free(*file);
11377 *file = NULL;
11378 return FAIL;
11379 }
11380
11381#ifdef BACKSLASH_IN_FILENAME
11382 /* For MS-Windows et al. we don't double backslashes at the start and
11383 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011384 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011385 if (var[0] == '\\' && var[1] == '\\'
11386 && expand_option_idx >= 0
11387 && (options[expand_option_idx].flags & P_EXPAND)
11388 && vim_isfilec(var[2])
11389 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011390 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011391#endif
11392
11393 *file[0] = buf;
11394 *num_file = 1;
11395 return OK;
11396}
11397#endif
11398
11399/*
11400 * Get the value for the numeric or string option *opp in a nice format into
11401 * NameBuff[]. Must not be called with a hidden option!
11402 */
11403 static void
11404option_value2string(opp, opt_flags)
11405 struct vimoption *opp;
11406 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11407{
11408 char_u *varp;
11409
11410 varp = get_varp_scope(opp, opt_flags);
11411
11412 if (opp->flags & P_NUM)
11413 {
11414 long wc = 0;
11415
11416 if (wc_use_keyname(varp, &wc))
11417 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11418 else if (wc != 0)
11419 STRCPY(NameBuff, transchar((int)wc));
11420 else
11421 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11422 }
11423 else /* P_STRING */
11424 {
11425 varp = *(char_u **)(varp);
11426 if (varp == NULL) /* just in case */
11427 NameBuff[0] = NUL;
11428#ifdef FEAT_CRYPT
11429 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011430 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431 STRCPY(NameBuff, "*****");
11432#endif
11433 else if (opp->flags & P_EXPAND)
11434 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11435 /* Translate 'pastetoggle' into special key names */
11436 else if ((char_u **)opp->var == &p_pt)
11437 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11438 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011439 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011440 }
11441}
11442
11443/*
11444 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11445 * printed as a keyname.
11446 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11447 */
11448 static int
11449wc_use_keyname(varp, wcp)
11450 char_u *varp;
11451 long *wcp;
11452{
11453 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11454 {
11455 *wcp = *(long *)varp;
11456 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11457 return TRUE;
11458 }
11459 return FALSE;
11460}
11461
Bram Moolenaar01615492015-02-03 13:00:38 +010011462#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011463/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011464 * Any character has an equivalent 'langmap' character. This is used for
11465 * keyboards that have a special language mode that sends characters above
11466 * 128 (although other characters can be translated too). The "to" field is a
11467 * Vim command character. This avoids having to switch the keyboard back to
11468 * ASCII mode when leaving Insert mode.
11469 *
11470 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11471 * commands.
11472 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11473 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11474 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011475 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011476# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011477/*
11478 * With multi-byte support use growarray for 'langmap' chars >= 256
11479 */
11480typedef struct
11481{
11482 int from;
11483 int to;
11484} langmap_entry_T;
11485
11486static garray_T langmap_mapga;
11487static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011488
11489/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011490 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11491 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011492 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011493 static void
11494langmap_set_entry(from, to)
11495 int from;
11496 int to;
11497{
11498 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011499 int a = 0;
11500 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011501
11502 /* Do a binary search for an existing entry. */
11503 while (a != b)
11504 {
11505 int i = (a + b) / 2;
11506 int d = entries[i].from - from;
11507
11508 if (d == 0)
11509 {
11510 entries[i].to = to;
11511 return;
11512 }
11513 if (d < 0)
11514 a = i + 1;
11515 else
11516 b = i;
11517 }
11518
11519 if (ga_grow(&langmap_mapga, 1) != OK)
11520 return; /* out of memory */
11521
11522 /* insert new entry at position "a" */
11523 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11524 mch_memmove(entries + 1, entries,
11525 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11526 ++langmap_mapga.ga_len;
11527 entries[0].from = from;
11528 entries[0].to = to;
11529}
11530
11531/*
11532 * Apply 'langmap' to multi-byte character "c" and return the result.
11533 */
11534 int
11535langmap_adjust_mb(c)
11536 int c;
11537{
11538 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11539 int a = 0;
11540 int b = langmap_mapga.ga_len;
11541
11542 while (a != b)
11543 {
11544 int i = (a + b) / 2;
11545 int d = entries[i].from - c;
11546
11547 if (d == 0)
11548 return entries[i].to; /* found matching entry */
11549 if (d < 0)
11550 a = i + 1;
11551 else
11552 b = i;
11553 }
11554 return c; /* no entry found, return "c" unmodified */
11555}
11556# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011557
11558 static void
11559langmap_init()
11560{
11561 int i;
11562
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011563 for (i = 0; i < 256; i++)
11564 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11565# ifdef FEAT_MBYTE
11566 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11567# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011568}
11569
11570/*
11571 * Called when langmap option is set; the language map can be
11572 * changed at any time!
11573 */
11574 static void
11575langmap_set()
11576{
11577 char_u *p;
11578 char_u *p2;
11579 int from, to;
11580
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011581#ifdef FEAT_MBYTE
11582 ga_clear(&langmap_mapga); /* clear the previous map first */
11583#endif
11584 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011585
11586 for (p = p_langmap; p[0] != NUL; )
11587 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011588 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11589 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011590 {
11591 if (p2[0] == '\\' && p2[1] != NUL)
11592 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011593 }
11594 if (p2[0] == ';')
11595 ++p2; /* abcd;ABCD form, p2 points to A */
11596 else
11597 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11598 while (p[0])
11599 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011600 if (p[0] == ',')
11601 {
11602 ++p;
11603 break;
11604 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011605 if (p[0] == '\\' && p[1] != NUL)
11606 ++p;
11607#ifdef FEAT_MBYTE
11608 from = (*mb_ptr2char)(p);
11609#else
11610 from = p[0];
11611#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011612 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011613 if (p2 == NULL)
11614 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011615 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011616 if (p[0] != ',')
11617 {
11618 if (p[0] == '\\')
11619 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011620#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011621 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011622#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011623 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011624#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011625 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011626 }
11627 else
11628 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011629 if (p2[0] != ',')
11630 {
11631 if (p2[0] == '\\')
11632 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011634 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011635#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011636 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011637#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011638 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011639 }
11640 if (to == NUL)
11641 {
11642 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11643 transchar(from));
11644 return;
11645 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011646
11647#ifdef FEAT_MBYTE
11648 if (from >= 256)
11649 langmap_set_entry(from, to);
11650 else
11651#endif
11652 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011653
11654 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011655 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011656 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011657 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011658 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011659 if (*p == ';')
11660 {
11661 p = p2;
11662 if (p[0] != NUL)
11663 {
11664 if (p[0] != ',')
11665 {
11666 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11667 return;
11668 }
11669 ++p;
11670 }
11671 break;
11672 }
11673 }
11674 }
11675 }
11676}
11677#endif
11678
11679/*
11680 * Return TRUE if format option 'x' is in effect.
11681 * Take care of no formatting when 'paste' is set.
11682 */
11683 int
11684has_format_option(x)
11685 int x;
11686{
11687 if (p_paste)
11688 return FALSE;
11689 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11690}
11691
11692/*
11693 * Return TRUE if "x" is present in 'shortmess' option, or
11694 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11695 */
11696 int
11697shortmess(x)
11698 int x;
11699{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011700 return p_shm != NULL &&
11701 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011702 || (vim_strchr(p_shm, 'a') != NULL
11703 && vim_strchr((char_u *)SHM_A, x) != NULL));
11704}
11705
11706/*
11707 * paste_option_changed() - Called after p_paste was set or reset.
11708 */
11709 static void
11710paste_option_changed()
11711{
11712 static int old_p_paste = FALSE;
11713 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011714 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011715#ifdef FEAT_CMDL_INFO
11716 static int save_ru = 0;
11717#endif
11718#ifdef FEAT_RIGHTLEFT
11719 static int save_ri = 0;
11720 static int save_hkmap = 0;
11721#endif
11722 buf_T *buf;
11723
11724 if (p_paste)
11725 {
11726 /*
11727 * Paste switched from off to on.
11728 * Save the current values, so they can be restored later.
11729 */
11730 if (!old_p_paste)
11731 {
11732 /* save options for each buffer */
11733 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11734 {
11735 buf->b_p_tw_nopaste = buf->b_p_tw;
11736 buf->b_p_wm_nopaste = buf->b_p_wm;
11737 buf->b_p_sts_nopaste = buf->b_p_sts;
11738 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011739 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011740 }
11741
11742 /* save global options */
11743 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011744 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011745#ifdef FEAT_CMDL_INFO
11746 save_ru = p_ru;
11747#endif
11748#ifdef FEAT_RIGHTLEFT
11749 save_ri = p_ri;
11750 save_hkmap = p_hkmap;
11751#endif
11752 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011753 p_ai_nopaste = p_ai;
11754 p_et_nopaste = p_et;
11755 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011756 p_tw_nopaste = p_tw;
11757 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011758 }
11759
11760 /*
11761 * Always set the option values, also when 'paste' is set when it is
11762 * already on.
11763 */
11764 /* set options for each buffer */
11765 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11766 {
11767 buf->b_p_tw = 0; /* textwidth is 0 */
11768 buf->b_p_wm = 0; /* wrapmargin is 0 */
11769 buf->b_p_sts = 0; /* softtabstop is 0 */
11770 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011771 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011772 }
11773
11774 /* set global options */
11775 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011776 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011777#ifdef FEAT_CMDL_INFO
11778# ifdef FEAT_WINDOWS
11779 if (p_ru)
11780 status_redraw_all(); /* redraw to remove the ruler */
11781# endif
11782 p_ru = 0; /* no ruler */
11783#endif
11784#ifdef FEAT_RIGHTLEFT
11785 p_ri = 0; /* no reverse insert */
11786 p_hkmap = 0; /* no Hebrew keyboard */
11787#endif
11788 /* set global values for local buffer options */
11789 p_tw = 0;
11790 p_wm = 0;
11791 p_sts = 0;
11792 p_ai = 0;
11793 }
11794
11795 /*
11796 * Paste switched from on to off: Restore saved values.
11797 */
11798 else if (old_p_paste)
11799 {
11800 /* restore options for each buffer */
11801 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11802 {
11803 buf->b_p_tw = buf->b_p_tw_nopaste;
11804 buf->b_p_wm = buf->b_p_wm_nopaste;
11805 buf->b_p_sts = buf->b_p_sts_nopaste;
11806 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011807 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011808 }
11809
11810 /* restore global options */
11811 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011812 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011813#ifdef FEAT_CMDL_INFO
11814# ifdef FEAT_WINDOWS
11815 if (p_ru != save_ru)
11816 status_redraw_all(); /* redraw to draw the ruler */
11817# endif
11818 p_ru = save_ru;
11819#endif
11820#ifdef FEAT_RIGHTLEFT
11821 p_ri = save_ri;
11822 p_hkmap = save_hkmap;
11823#endif
11824 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011825 p_ai = p_ai_nopaste;
11826 p_et = p_et_nopaste;
11827 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011828 p_tw = p_tw_nopaste;
11829 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011830 }
11831
11832 old_p_paste = p_paste;
11833}
11834
11835/*
11836 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11837 *
11838 * Reset 'compatible' and set the values for options that didn't get set yet
11839 * to the Vim defaults.
11840 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011841 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011842 */
11843 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011844vimrc_found(fname, envname)
11845 char_u *fname;
11846 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011847{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011848 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011849 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011850 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011851
11852 if (!option_was_set((char_u *)"cp"))
11853 {
11854 p_cp = FALSE;
11855 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11856 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11857 set_option_default(opt_idx, OPT_FREE, FALSE);
11858 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011859 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011860 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011861
11862 if (fname != NULL)
11863 {
11864 p = vim_getenv(envname, &dofree);
11865 if (p == NULL)
11866 {
11867 /* Set $MYVIMRC to the first vimrc file found. */
11868 p = FullName_save(fname, FALSE);
11869 if (p != NULL)
11870 {
11871 vim_setenv(envname, p);
11872 vim_free(p);
11873 }
11874 }
11875 else if (dofree)
11876 vim_free(p);
11877 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011878}
11879
11880/*
11881 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11882 */
11883 void
11884change_compatible(on)
11885 int on;
11886{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011887 int opt_idx;
11888
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889 if (p_cp != on)
11890 {
11891 p_cp = on;
11892 compatible_set();
11893 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011894 opt_idx = findoption((char_u *)"cp");
11895 if (opt_idx >= 0)
11896 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011897}
11898
11899/*
11900 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011901 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902 */
11903 int
11904option_was_set(name)
11905 char_u *name;
11906{
11907 int idx;
11908
11909 idx = findoption(name);
11910 if (idx < 0) /* unknown option */
11911 return FALSE;
11912 if (options[idx].flags & P_WAS_SET)
11913 return TRUE;
11914 return FALSE;
11915}
11916
11917/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011918 * Reset the flag indicating option "name" was set.
11919 */
11920 void
11921reset_option_was_set(name)
11922 char_u *name;
11923{
11924 int idx = findoption(name);
11925
11926 if (idx >= 0)
11927 options[idx].flags &= ~P_WAS_SET;
11928}
11929
11930/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011931 * compatible_set() - Called when 'compatible' has been set or unset.
11932 *
11933 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11934 * flag) to a Vi compatible value.
11935 * When 'compatible' is unset: Set all options that have a different default
11936 * for Vim (without the P_VI_DEF flag) to that default.
11937 */
11938 static void
11939compatible_set()
11940{
11941 int opt_idx;
11942
11943 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11944 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11945 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11946 set_option_default(opt_idx, OPT_FREE, p_cp);
11947 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011948 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011949}
11950
11951#ifdef FEAT_LINEBREAK
11952
11953# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11954 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011955 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011956# endif
11957
11958/*
11959 * fill_breakat_flags() -- called when 'breakat' changes value.
11960 */
11961 static void
11962fill_breakat_flags()
11963{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011964 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965 int i;
11966
11967 for (i = 0; i < 256; i++)
11968 breakat_flags[i] = FALSE;
11969
11970 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011971 for (p = p_breakat; *p; p++)
11972 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011973}
11974
11975# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011976 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977# endif
11978
11979#endif
11980
11981/*
11982 * Check an option that can be a range of string values.
11983 *
11984 * Return OK for correct value, FAIL otherwise.
11985 * Empty is always OK.
11986 */
11987 static int
11988check_opt_strings(val, values, list)
11989 char_u *val;
11990 char **values;
11991 int list; /* when TRUE: accept a list of values */
11992{
11993 return opt_strings_flags(val, values, NULL, list);
11994}
11995
11996/*
11997 * Handle an option that can be a range of string values.
11998 * Set a flag in "*flagp" for each string present.
11999 *
12000 * Return OK for correct value, FAIL otherwise.
12001 * Empty is always OK.
12002 */
12003 static int
12004opt_strings_flags(val, values, flagp, list)
12005 char_u *val; /* new value */
12006 char **values; /* array of valid string values */
12007 unsigned *flagp;
12008 int list; /* when TRUE: accept a list of values */
12009{
12010 int i;
12011 int len;
12012 unsigned new_flags = 0;
12013
12014 while (*val)
12015 {
12016 for (i = 0; ; ++i)
12017 {
12018 if (values[i] == NULL) /* val not found in values[] */
12019 return FAIL;
12020
12021 len = (int)STRLEN(values[i]);
12022 if (STRNCMP(values[i], val, len) == 0
12023 && ((list && val[len] == ',') || val[len] == NUL))
12024 {
12025 val += len + (val[len] == ',');
12026 new_flags |= (1 << i);
12027 break; /* check next item in val list */
12028 }
12029 }
12030 }
12031 if (flagp != NULL)
12032 *flagp = new_flags;
12033
12034 return OK;
12035}
12036
12037/*
12038 * Read the 'wildmode' option, fill wim_flags[].
12039 */
12040 static int
12041check_opt_wim()
12042{
12043 char_u new_wim_flags[4];
12044 char_u *p;
12045 int i;
12046 int idx = 0;
12047
12048 for (i = 0; i < 4; ++i)
12049 new_wim_flags[i] = 0;
12050
12051 for (p = p_wim; *p; ++p)
12052 {
12053 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12054 ;
12055 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12056 return FAIL;
12057 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12058 new_wim_flags[idx] |= WIM_LONGEST;
12059 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12060 new_wim_flags[idx] |= WIM_FULL;
12061 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12062 new_wim_flags[idx] |= WIM_LIST;
12063 else
12064 return FAIL;
12065 p += i;
12066 if (*p == NUL)
12067 break;
12068 if (*p == ',')
12069 {
12070 if (idx == 3)
12071 return FAIL;
12072 ++idx;
12073 }
12074 }
12075
12076 /* fill remaining entries with last flag */
12077 while (idx < 3)
12078 {
12079 new_wim_flags[idx + 1] = new_wim_flags[idx];
12080 ++idx;
12081 }
12082
12083 /* only when there are no errors, wim_flags[] is changed */
12084 for (i = 0; i < 4; ++i)
12085 wim_flags[i] = new_wim_flags[i];
12086 return OK;
12087}
12088
12089/*
12090 * Check if backspacing over something is allowed.
12091 */
12092 int
12093can_bs(what)
12094 int what; /* BS_INDENT, BS_EOL or BS_START */
12095{
12096 switch (*p_bs)
12097 {
12098 case '2': return TRUE;
12099 case '1': return (what != BS_START);
12100 case '0': return FALSE;
12101 }
12102 return vim_strchr(p_bs, what) != NULL;
12103}
12104
12105/*
12106 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12107 * the file must be considered changed when the value is different.
12108 */
12109 void
12110save_file_ff(buf)
12111 buf_T *buf;
12112{
12113 buf->b_start_ffc = *buf->b_p_ff;
12114 buf->b_start_eol = buf->b_p_eol;
12115#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012116 buf->b_start_bomb = buf->b_p_bomb;
12117
Bram Moolenaar071d4272004-06-13 20:20:40 +000012118 /* Only use free/alloc when necessary, they take time. */
12119 if (buf->b_start_fenc == NULL
12120 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12121 {
12122 vim_free(buf->b_start_fenc);
12123 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12124 }
12125#endif
12126}
12127
12128/*
12129 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12130 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012131 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12132 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012133 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012134 * When "ignore_empty" is true don't consider a new, empty buffer to be
12135 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136 */
12137 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012138file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012139 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012140 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012141{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012142 /* In a buffer that was never loaded the options are not valid. */
12143 if (buf->b_flags & BF_NEVERLOADED)
12144 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012145 if (ignore_empty
12146 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012147 && buf->b_ml.ml_line_count == 1
12148 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12149 return FALSE;
12150 if (buf->b_start_ffc != *buf->b_p_ff)
12151 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012152 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012153 return TRUE;
12154#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012155 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12156 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012157 if (buf->b_start_fenc == NULL)
12158 return (*buf->b_p_fenc != NUL);
12159 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12160#else
12161 return FALSE;
12162#endif
12163}
12164
12165/*
12166 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12167 */
12168 int
12169check_ff_value(p)
12170 char_u *p;
12171{
12172 return check_opt_strings(p, p_ff_values, FALSE);
12173}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012174
12175/*
12176 * Return the effective shiftwidth value for current buffer, using the
12177 * 'tabstop' value when 'shiftwidth' is zero.
12178 */
12179 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012180get_sw_value(buf)
12181 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012182{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012183 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012184}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012185
12186/*
12187 * Return the effective softtabstop value for the current buffer, using the
12188 * 'tabstop' value when 'softtabstop' is negative.
12189 */
12190 long
12191get_sts_value()
12192{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012193 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012194}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012195
12196/*
12197 * Check matchpairs option for "*initc".
12198 * If there is a match set "*initc" to the matching character and "*findc" to
12199 * the opposite character. Set "*backwards" to the direction.
12200 * When "switchit" is TRUE swap the direction.
12201 */
12202 void
12203find_mps_values(initc, findc, backwards, switchit)
12204 int *initc;
12205 int *findc;
12206 int *backwards;
12207 int switchit;
12208{
12209 char_u *ptr;
12210
12211 ptr = curbuf->b_p_mps;
12212 while (*ptr != NUL)
12213 {
12214#ifdef FEAT_MBYTE
12215 if (has_mbyte)
12216 {
12217 char_u *prev;
12218
12219 if (mb_ptr2char(ptr) == *initc)
12220 {
12221 if (switchit)
12222 {
12223 *findc = *initc;
12224 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12225 *backwards = TRUE;
12226 }
12227 else
12228 {
12229 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12230 *backwards = FALSE;
12231 }
12232 return;
12233 }
12234 prev = ptr;
12235 ptr += mb_ptr2len(ptr) + 1;
12236 if (mb_ptr2char(ptr) == *initc)
12237 {
12238 if (switchit)
12239 {
12240 *findc = *initc;
12241 *initc = mb_ptr2char(prev);
12242 *backwards = FALSE;
12243 }
12244 else
12245 {
12246 *findc = mb_ptr2char(prev);
12247 *backwards = TRUE;
12248 }
12249 return;
12250 }
12251 ptr += mb_ptr2len(ptr);
12252 }
12253 else
12254#endif
12255 {
12256 if (*ptr == *initc)
12257 {
12258 if (switchit)
12259 {
12260 *backwards = TRUE;
12261 *findc = *initc;
12262 *initc = ptr[2];
12263 }
12264 else
12265 {
12266 *backwards = FALSE;
12267 *findc = ptr[2];
12268 }
12269 return;
12270 }
12271 ptr += 2;
12272 if (*ptr == *initc)
12273 {
12274 if (switchit)
12275 {
12276 *backwards = FALSE;
12277 *findc = *initc;
12278 *initc = ptr[-2];
12279 }
12280 else
12281 {
12282 *backwards = TRUE;
12283 *findc = ptr[-2];
12284 }
12285 return;
12286 }
12287 ++ptr;
12288 }
12289 if (*ptr == ',')
12290 ++ptr;
12291 }
12292}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012293
12294#if defined(FEAT_LINEBREAK) || defined(PROTO)
12295/*
12296 * This is called when 'breakindentopt' is changed and when a window is
12297 * initialized.
12298 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012299 static int
12300briopt_check(wp)
12301 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012302{
12303 char_u *p;
12304 int bri_shift = 0;
12305 long bri_min = 20;
12306 int bri_sbr = FALSE;
12307
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012308 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012309 while (*p != NUL)
12310 {
12311 if (STRNCMP(p, "shift:", 6) == 0
12312 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12313 {
12314 p += 6;
12315 bri_shift = getdigits(&p);
12316 }
12317 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12318 {
12319 p += 4;
12320 bri_min = getdigits(&p);
12321 }
12322 else if (STRNCMP(p, "sbr", 3) == 0)
12323 {
12324 p += 3;
12325 bri_sbr = TRUE;
12326 }
12327 if (*p != ',' && *p != NUL)
12328 return FAIL;
12329 if (*p == ',')
12330 ++p;
12331 }
12332
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012333 wp->w_p_brishift = bri_shift;
12334 wp->w_p_brimin = bri_min;
12335 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012336
12337 return OK;
12338}
12339#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012340
12341/*
12342 * Get the local or global value of 'backupcopy'.
12343 */
12344 unsigned int
12345get_bkc_value(buf)
12346 buf_T *buf;
12347{
12348 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12349}