blob: 8e91fae74ae8d1719f0bfd8f8ed928a9bcafe75d [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
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.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * 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 Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
225#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#ifdef FEAT_WINDOWS
249# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000250# 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 Moolenaare4f25e42017-07-07 11:54:15 +0200260#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200261# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200262# define PV_TMS OPT_WIN(WV_TMS)
263#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200264#ifdef FEAT_SIGNS
265# define PV_SCL OPT_WIN(WV_SCL)
266#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000267
268/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269typedef enum
270{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000271 PV_NONE = 0,
272 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273} idopt_T;
274
275/*
276 * Options local to a window have a value local to a buffer and global to all
277 * buffers. Indicate this by setting "var" to VAR_WIN.
278 */
279#define VAR_WIN ((char_u *)-1)
280
281/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000282 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283 * Only to be used in option.c!
284 */
285static int p_ai;
286static int p_bin;
287#ifdef FEAT_MBYTE
288static int p_bomb;
289#endif
290#if defined(FEAT_QUICKFIX)
291static char_u *p_bh;
292static char_u *p_bt;
293#endif
294static int p_bl;
295static int p_ci;
296#ifdef FEAT_CINDENT
297static int p_cin;
298static char_u *p_cink;
299static char_u *p_cino;
300#endif
301#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
302static char_u *p_cinw;
303#endif
304#ifdef FEAT_COMMENTS
305static char_u *p_com;
306#endif
307#ifdef FEAT_FOLDING
308static char_u *p_cms;
309#endif
310#ifdef FEAT_INS_EXPAND
311static char_u *p_cpt;
312#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000313#ifdef FEAT_COMPL_FUNC
314static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000315static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000316#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200318static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319static int p_et;
320#ifdef FEAT_MBYTE
321static char_u *p_fenc;
322#endif
323static char_u *p_ff;
324static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000325static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326#ifdef FEAT_AUTOCMD
327static char_u *p_ft;
328#endif
329static long p_iminsert;
330static long p_imsearch;
331#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
332static char_u *p_inex;
333#endif
334#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
335static char_u *p_inde;
336static char_u *p_indk;
337#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000338#if defined(FEAT_EVAL)
339static char_u *p_fex;
340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000341static int p_inf;
342static char_u *p_isk;
343#ifdef FEAT_CRYPT
344static char_u *p_key;
345#endif
346#ifdef FEAT_LISP
347static int p_lisp;
348#endif
349static int p_ml;
350static int p_ma;
351static int p_mod;
352static char_u *p_mps;
353static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000355#ifdef FEAT_TEXTOBJ
356static char_u *p_qe;
357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static int p_ro;
359#ifdef FEAT_SMARTINDENT
360static int p_si;
361#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363static long p_sts;
364#if defined(FEAT_SEARCHPATH)
365static char_u *p_sua;
366#endif
367static long p_sw;
368static int p_swf;
369#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000370static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000371static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000372#endif
373#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000374static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000375static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000376static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377#endif
378static long p_ts;
379static long p_tw;
380static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200381#ifdef FEAT_PERSISTENT_UNDO
382static int p_udf;
383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000384static long p_wm;
385#ifdef FEAT_KEYMAP
386static char_u *p_keymap;
387#endif
388
389/* Saved values for when 'bin' is set. */
390static int p_et_nobin;
391static int p_ml_nobin;
392static long p_tw_nobin;
393static long p_wm_nobin;
394
395/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200396static int p_ai_nopaste;
397static int p_et_nopaste;
398static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399static long p_tw_nopaste;
400static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000401
402struct vimoption
403{
404 char *fullname; /* full option name */
405 char *shortname; /* permissible abbreviation */
406 long_u flags; /* see below */
407 char_u *var; /* global option: pointer to variable;
408 * window-local option: VAR_WIN;
409 * buffer-local option: global value */
410 idopt_T indir; /* global option: PV_NONE;
411 * local option: indirect option index */
412 char_u *def_val[2]; /* default values for variable (vi and vim) */
413#ifdef FEAT_EVAL
414 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000415# define SCRIPTID_INIT , 0
416#else
417# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000418#endif
419};
420
421#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
422#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
423
424/*
425 * Flags
426 */
427#define P_BOOL 0x01 /* the option is boolean */
428#define P_NUM 0x02 /* the option is numeric */
429#define P_STRING 0x04 /* the option is a string */
430#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000431 must use free_string_option() when
432 assigning new value. Not set if default is
433 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000434#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
435 never be used for local or hidden options! */
436#define P_NODEFAULT 0x40 /* don't set to default value */
437#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
438 use vim_free() when assigning new value */
439#define P_WAS_SET 0x100 /* option has been set/reset */
440#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
441#define P_VI_DEF 0x400 /* Use Vi default for Vim */
442#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
443
444 /* when option changed, what to display: */
445#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100446#define P_RWIN 0x2000 /* redraw current window and recompute text */
447#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000448#define P_RALL 0x6000 /* redraw all windows */
449#define P_RCLR 0x7000 /* clear and redraw all */
450
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200451#define P_COMMA 0x8000 /* comma separated list */
452#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
453 * commas */
454#define P_NODUP 0x20000L /* don't allow duplicate strings */
455#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200457#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
458#define P_GETTEXT 0x100000L /* expand default value with _() */
459#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
460#define P_NFNAME 0x400000L /* only normal file name chars allowed */
461#define P_INSECURE 0x800000L /* option was set from a modeline */
462#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200464#define P_NO_ML 0x2000000L /* not allowed in modeline */
465#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200466 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100467#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100468#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000469
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000470#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
471
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000472/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
473 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100474#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000475# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000476#else
477# define ISP_LATIN1 (char_u *)"@,161-255"
478#endif
479
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100480/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000481#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100482 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar21020352017-06-13 17:21:04 +0200483 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) \
484 || defined(FEAT_CONCEAL) || defined(FEAT_QUICKFIX)
485# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@: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,q:QuickFixLine"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000486#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100487# 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 +0000488#endif
489
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100490/* Default python version for pyx* commands */
491#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
492# define DEFAULT_PYTHON_VER 0
493#elif defined(FEAT_PYTHON3)
494# define DEFAULT_PYTHON_VER 3
495#elif defined(FEAT_PYTHON)
496# define DEFAULT_PYTHON_VER 2
497#else
498# define DEFAULT_PYTHON_VER 0
499#endif
500
Bram Moolenaar071d4272004-06-13 20:20:40 +0000501/*
502 * options[] is initialized here.
503 * The order of the options MUST be alphabetic for ":set all" and findoption().
504 * All option names MUST start with a lowercase letter (for findoption()).
505 * Exception: "t_" options are at the end.
506 * The options with a NULL variable are 'hidden': a set command for them is
507 * ignored and they are not printed.
508 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100509static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200511 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512#ifdef FEAT_RIGHTLEFT
513 (char_u *)&p_aleph, PV_NONE,
514#else
515 (char_u *)NULL, PV_NONE,
516#endif
517 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100518#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 (char_u *)128L,
520#else
521 (char_u *)224L,
522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000523 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
525#if defined(FEAT_GUI) && defined(MACOS_X)
526 (char_u *)&p_antialias, PV_NONE,
527 {(char_u *)FALSE, (char_u *)FALSE}
528#else
529 (char_u *)NULL, PV_NONE,
530 {(char_u *)FALSE, (char_u *)FALSE}
531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000532 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200533 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000534#ifdef FEAT_ARABIC
535 (char_u *)VAR_WIN, PV_ARAB,
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 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
541#ifdef FEAT_ARABIC
542 (char_u *)&p_arshape, PV_NONE,
543#else
544 (char_u *)NULL, PV_NONE,
545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000546 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
548#ifdef FEAT_RIGHTLEFT
549 (char_u *)&p_ari, PV_NONE,
550#else
551 (char_u *)NULL, PV_NONE,
552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
555#ifdef FEAT_FKMAP
556 (char_u *)&p_altkeymap, PV_NONE,
557#else
558 (char_u *)NULL, PV_NONE,
559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
562#if defined(FEAT_MBYTE)
563 (char_u *)&p_ambw, PV_NONE,
564 {(char_u *)"single", (char_u *)0L}
565#else
566 (char_u *)NULL, PV_NONE,
567 {(char_u *)0L, (char_u *)0L}
568#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100571#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100573 {(char_u *)FALSE, (char_u *)0L}
574#else
575 (char_u *)NULL, PV_NONE,
576 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100578 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"autoindent", "ai", P_BOOL|P_VI_DEF,
580 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"autoprint", "ap", P_BOOL|P_VI_DEF,
583 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000584 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000586 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000587 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 {"autowrite", "aw", P_BOOL|P_VI_DEF,
589 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591 {"autowriteall","awa", P_BOOL|P_VI_DEF,
592 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000593 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
595 (char_u *)&p_bg, PV_NONE,
596 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100597#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000598 (char_u *)"dark",
599#else
600 (char_u *)"light",
601#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000602 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200603 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000605 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
607 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200609 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200610 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611#ifdef UNIX
612 {(char_u *)"yes", (char_u *)"auto"}
613#else
614 {(char_u *)"auto", (char_u *)"auto"}
615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200617 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
618 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000621 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000622 (char_u *)&p_bex, PV_NONE,
623 {
624#ifdef VMS
625 (char_u *)"_",
626#else
627 (char_u *)"~",
628#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000629 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200630 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631#ifdef FEAT_WILDIGN
632 (char_u *)&p_bsk, PV_NONE,
633 {(char_u *)"", (char_u *)0L}
634#else
635 (char_u *)NULL, PV_NONE,
636 {(char_u *)0L, (char_u *)0L}
637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000638 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100640#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000641 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100642 {(char_u *)600L, (char_u *)0L}
643#else
644 (char_u *)NULL, PV_NONE,
645 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100647 SCRIPTID_INIT},
648 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
649#ifdef FEAT_BEVAL
650 (char_u *)&p_beval, PV_NONE,
651 {(char_u *)FALSE, (char_u *)0L}
652#else
653 (char_u *)NULL, PV_NONE,
654 {(char_u *)0L, (char_u *)0L}
655#endif
656 SCRIPTID_INIT},
657 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
658#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
659 (char_u *)&p_bexpr, PV_BEXPR,
660 {(char_u *)"", (char_u *)0L}
661#else
662 (char_u *)NULL, PV_NONE,
663 {(char_u *)0L, (char_u *)0L}
664#endif
665 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 {"beautify", "bf", P_BOOL|P_VI_DEF,
667 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000668 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200669 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
670 (char_u *)&p_bo, PV_NONE,
671 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
673 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000674 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000677 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
679#ifdef FEAT_MBYTE
680 (char_u *)&p_bomb, PV_BOMB,
681#else
682 (char_u *)NULL, PV_NONE,
683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000684 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000685 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
686#ifdef FEAT_LINEBREAK
687 (char_u *)&p_breakat, PV_NONE,
688 {(char_u *)" \t!@*-+;:,./?", (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 Moolenaar597a4222014-06-25 14:39:50 +0200694 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
695#ifdef FEAT_LINEBREAK
696 (char_u *)VAR_WIN, PV_BRI,
697 {(char_u *)FALSE, (char_u *)0L}
698#else
699 (char_u *)NULL, PV_NONE,
700 {(char_u *)0L, (char_u *)0L}
701#endif
702 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200703 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
704 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200705#ifdef FEAT_LINEBREAK
706 (char_u *)VAR_WIN, PV_BRIOPT,
707 {(char_u *)"", (char_u *)NULL}
708#else
709 (char_u *)NULL, PV_NONE,
710 {(char_u *)"", (char_u *)NULL}
711#endif
712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
714#ifdef FEAT_BROWSE
715 (char_u *)&p_bsdir, PV_NONE,
716 {(char_u *)"last", (char_u *)0L}
717#else
718 (char_u *)NULL, PV_NONE,
719 {(char_u *)0L, (char_u *)0L}
720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
723#if defined(FEAT_QUICKFIX)
724 (char_u *)&p_bh, PV_BH,
725 {(char_u *)"", (char_u *)0L}
726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
732 (char_u *)&p_bl, PV_BL,
733 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000734 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
736#if defined(FEAT_QUICKFIX)
737 (char_u *)&p_bt, PV_BT,
738 {(char_u *)"", (char_u *)0L}
739#else
740 (char_u *)NULL, PV_NONE,
741 {(char_u *)0L, (char_u *)0L}
742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000743 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200744 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000745#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000746 (char_u *)&p_cmp, PV_NONE,
747 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000748#else
749 (char_u *)NULL, PV_NONE,
750 {(char_u *)0L, (char_u *)0L}
751#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000752 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000753 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
754#ifdef FEAT_SEARCHPATH
755 (char_u *)&p_cdpath, PV_NONE,
756 {(char_u *)",,", (char_u *)0L}
757#else
758 (char_u *)NULL, PV_NONE,
759 {(char_u *)0L, (char_u *)0L}
760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000761 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762 {"cedit", NULL, P_STRING,
763#ifdef FEAT_CMDWIN
764 (char_u *)&p_cedit, PV_NONE,
765 {(char_u *)"", (char_u *)CTRL_F_STR}
766#else
767 (char_u *)NULL, PV_NONE,
768 {(char_u *)0L, (char_u *)0L}
769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000770 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
772#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
773 (char_u *)&p_ccv, PV_NONE,
774 {(char_u *)"", (char_u *)0L}
775#else
776 (char_u *)NULL, PV_NONE,
777 {(char_u *)0L, (char_u *)0L}
778#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000779 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
781#ifdef FEAT_CINDENT
782 (char_u *)&p_cin, PV_CIN,
783#else
784 (char_u *)NULL, PV_NONE,
785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200787 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000788#ifdef FEAT_CINDENT
789 (char_u *)&p_cink, PV_CINK,
790 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
791#else
792 (char_u *)NULL, PV_NONE,
793 {(char_u *)0L, (char_u *)0L}
794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000795 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200796 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000797#ifdef FEAT_CINDENT
798 (char_u *)&p_cino, PV_CINO,
799#else
800 (char_u *)NULL, PV_NONE,
801#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000802 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200803 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
805 (char_u *)&p_cinw, PV_CINW,
806 {(char_u *)"if,else,while,do,for,switch",
807 (char_u *)0L}
808#else
809 (char_u *)NULL, PV_NONE,
810 {(char_u *)0L, (char_u *)0L}
811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000812 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200813 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814#ifdef FEAT_CLIPBOARD
815 (char_u *)&p_cb, PV_NONE,
816# ifdef FEAT_XCLIPBOARD
817 {(char_u *)"autoselect,exclude:cons\\|linux",
818 (char_u *)0L}
819# else
820 {(char_u *)"", (char_u *)0L}
821# endif
822#else
823 (char_u *)NULL, PV_NONE,
824 {(char_u *)"", (char_u *)0L}
825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000826 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
828 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000829 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
831#ifdef FEAT_CMDWIN
832 (char_u *)&p_cwh, PV_NONE,
833#else
834 (char_u *)NULL, PV_NONE,
835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000836 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200837 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200838#ifdef FEAT_SYN_HL
839 (char_u *)VAR_WIN, PV_CC,
840#else
841 (char_u *)NULL, PV_NONE,
842#endif
843 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
845 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000846 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200847 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
848 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849#ifdef FEAT_COMMENTS
850 (char_u *)&p_com, PV_COM,
851 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
852 (char_u *)0L}
853#else
854 (char_u *)NULL, PV_NONE,
855 {(char_u *)0L, (char_u *)0L}
856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000857 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200858 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000859#ifdef FEAT_FOLDING
860 (char_u *)&p_cms, PV_CMS,
861 {(char_u *)"/*%s*/", (char_u *)0L}
862#else
863 (char_u *)NULL, PV_NONE,
864 {(char_u *)0L, (char_u *)0L}
865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000867 /* P_PRI_MKRC isn't needed here, optval_default()
868 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000869 {"compatible", "cp", P_BOOL|P_RALL,
870 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000871 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200872 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000873#ifdef FEAT_INS_EXPAND
874 (char_u *)&p_cpt, PV_CPT,
875 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
876#else
877 (char_u *)NULL, PV_NONE,
878 {(char_u *)0L, (char_u *)0L}
879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000880 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200881 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200882#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200883 (char_u *)VAR_WIN, PV_COCU,
884 {(char_u *)"", (char_u *)NULL}
885#else
886 (char_u *)NULL, PV_NONE,
887 {(char_u *)NULL, (char_u *)0L}
888#endif
889 SCRIPTID_INIT},
890 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
891#ifdef FEAT_CONCEAL
892 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200893#else
894 (char_u *)NULL, PV_NONE,
895#endif
896 {(char_u *)0L, (char_u *)0L}
897 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000898 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
899#ifdef FEAT_COMPL_FUNC
900 (char_u *)&p_cfu, PV_CFU,
901 {(char_u *)"", (char_u *)0L}
902#else
903 (char_u *)NULL, PV_NONE,
904 {(char_u *)0L, (char_u *)0L}
905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000906 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200907 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000908#ifdef FEAT_INS_EXPAND
909 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000910 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000911#else
912 (char_u *)NULL, PV_NONE,
913 {(char_u *)0L, (char_u *)0L}
914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000915 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 {"confirm", "cf", P_BOOL|P_VI_DEF,
917#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
918 (char_u *)&p_confirm, PV_NONE,
919#else
920 (char_u *)NULL, PV_NONE,
921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000922 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000923 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000925 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000926 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
927 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000928 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
930 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000931 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
932 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200933 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200934#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200935 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200936 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200937#else
938 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200939 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200940#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200941 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000942 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
943#ifdef FEAT_CSCOPE
944 (char_u *)&p_cspc, PV_NONE,
945#else
946 (char_u *)NULL, PV_NONE,
947#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000948 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
950#ifdef FEAT_CSCOPE
951 (char_u *)&p_csprg, PV_NONE,
952 {(char_u *)"cscope", (char_u *)0L}
953#else
954 (char_u *)NULL, PV_NONE,
955 {(char_u *)0L, (char_u *)0L}
956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000957 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200958 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
960 (char_u *)&p_csqf, PV_NONE,
961 {(char_u *)"", (char_u *)0L}
962#else
963 (char_u *)NULL, PV_NONE,
964 {(char_u *)0L, (char_u *)0L}
965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000966 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200967 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
968#ifdef FEAT_CSCOPE
969 (char_u *)&p_csre, PV_NONE,
970#else
971 (char_u *)NULL, PV_NONE,
972#endif
973 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000974 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
975#ifdef FEAT_CSCOPE
976 (char_u *)&p_cst, PV_NONE,
977#else
978 (char_u *)NULL, PV_NONE,
979#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000980 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000981 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
982#ifdef FEAT_CSCOPE
983 (char_u *)&p_csto, PV_NONE,
984#else
985 (char_u *)NULL, PV_NONE,
986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000987 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
989#ifdef FEAT_CSCOPE
990 (char_u *)&p_csverbose, PV_NONE,
991#else
992 (char_u *)NULL, PV_NONE,
993#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000994 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200995 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
996#ifdef FEAT_CURSORBIND
997 (char_u *)VAR_WIN, PV_CRBIND,
998#else
999 (char_u *)NULL, PV_NONE,
1000#endif
1001 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001002 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
1003#ifdef FEAT_SYN_HL
1004 (char_u *)VAR_WIN, PV_CUC,
1005#else
1006 (char_u *)NULL, PV_NONE,
1007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001008 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +01001009 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001010#ifdef FEAT_SYN_HL
1011 (char_u *)VAR_WIN, PV_CUL,
1012#else
1013 (char_u *)NULL, PV_NONE,
1014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001015 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016 {"debug", NULL, P_STRING|P_VI_DEF,
1017 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001018 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001019 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001021 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001022 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023#else
1024 (char_u *)NULL, PV_NONE,
1025 {(char_u *)NULL, (char_u *)0L}
1026#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001027 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1029#ifdef FEAT_MBYTE
1030 (char_u *)&p_deco, PV_NONE,
1031#else
1032 (char_u *)NULL, PV_NONE,
1033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001034 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001035 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001037 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038#else
1039 (char_u *)NULL, PV_NONE,
1040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1043#ifdef FEAT_DIFF
1044 (char_u *)VAR_WIN, PV_DIFF,
1045#else
1046 (char_u *)NULL, PV_NONE,
1047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001048 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001049 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1051 (char_u *)&p_dex, PV_NONE,
1052 {(char_u *)"", (char_u *)0L}
1053#else
1054 (char_u *)NULL, PV_NONE,
1055 {(char_u *)0L, (char_u *)0L}
1056#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001057 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001058 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1059 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060#ifdef FEAT_DIFF
1061 (char_u *)&p_dip, PV_NONE,
1062 {(char_u *)"filler", (char_u *)NULL}
1063#else
1064 (char_u *)NULL, PV_NONE,
1065 {(char_u *)"", (char_u *)NULL}
1066#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1069#ifdef FEAT_DIGRAPHS
1070 (char_u *)&p_dg, PV_NONE,
1071#else
1072 (char_u *)NULL, PV_NONE,
1073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001075 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1076 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001078 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001079 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001083#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 (char_u *)&p_ead, PV_NONE,
1085 {(char_u *)"both", (char_u *)0L}
1086#else
1087 (char_u *)NULL, PV_NONE,
1088 {(char_u *)NULL, (char_u *)0L}
1089#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1092 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001094 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1095#if defined(FEAT_MBYTE)
1096 (char_u *)&p_emoji, PV_NONE,
1097 {(char_u *)TRUE, (char_u *)0L}
1098#else
1099 (char_u *)NULL, PV_NONE,
1100 {(char_u *)0L, (char_u *)0L}
1101#endif
1102 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001103 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104#ifdef FEAT_MBYTE
1105 (char_u *)&p_enc, PV_NONE,
1106 {(char_u *)ENC_DFLT, (char_u *)0L}
1107#else
1108 (char_u *)NULL, PV_NONE,
1109 {(char_u *)0L, (char_u *)0L}
1110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1113 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1116 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001119 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001120 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1122 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001124 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1125#ifdef FEAT_QUICKFIX
1126 (char_u *)&p_ef, PV_NONE,
1127 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1128#else
1129 (char_u *)NULL, PV_NONE,
1130 {(char_u *)NULL, (char_u *)0L}
1131#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001132 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001133 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001135 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137#else
1138 (char_u *)NULL, PV_NONE,
1139 {(char_u *)NULL, (char_u *)0L}
1140#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001141 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142 {"esckeys", "ek", P_BOOL|P_VIM,
1143 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001144 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001145 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146#ifdef FEAT_AUTOCMD
1147 (char_u *)&p_ei, PV_NONE,
1148#else
1149 (char_u *)NULL, PV_NONE,
1150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001151 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1153 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001154 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1156 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001157 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001158 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1159 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160#ifdef FEAT_MBYTE
1161 (char_u *)&p_fenc, PV_FENC,
1162 {(char_u *)"", (char_u *)0L}
1163#else
1164 (char_u *)NULL, PV_NONE,
1165 {(char_u *)0L, (char_u *)0L}
1166#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001167 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001168 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169#ifdef FEAT_MBYTE
1170 (char_u *)&p_fencs, PV_NONE,
1171 {(char_u *)"ucs-bom", (char_u *)0L}
1172#else
1173 (char_u *)NULL, PV_NONE,
1174 {(char_u *)0L, (char_u *)0L}
1175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001176 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001177 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1178 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001180 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001181 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001183 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1184 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001185 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1186 (char_u *)&p_fic, PV_NONE,
1187 {
1188#ifdef CASE_INSENSITIVE_FILENAME
1189 (char_u *)TRUE,
1190#else
1191 (char_u *)FALSE,
1192#endif
1193 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001194 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195#ifdef FEAT_AUTOCMD
1196 (char_u *)&p_ft, PV_FT,
1197 {(char_u *)"", (char_u *)0L}
1198#else
1199 (char_u *)NULL, PV_NONE,
1200 {(char_u *)0L, (char_u *)0L}
1201#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001202 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001203 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1205 (char_u *)&p_fcs, PV_NONE,
1206 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1207#else
1208 (char_u *)NULL, PV_NONE,
1209 {(char_u *)"", (char_u *)0L}
1210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001211 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001212 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1213 (char_u *)&p_fixeol, PV_FIXEOL,
1214 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1216#ifdef FEAT_FKMAP
1217 (char_u *)&p_fkmap, PV_NONE,
1218#else
1219 (char_u *)NULL, PV_NONE,
1220#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001221 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 {"flash", "fl", P_BOOL|P_VI_DEF,
1223 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001224 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001225 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001226#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001228 {(char_u *)"", (char_u *)0L}
1229#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001230 (char_u *)NULL, PV_NONE,
1231 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001232#endif
1233 SCRIPTID_INIT},
1234 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1235#ifdef FEAT_FOLDING
1236 (char_u *)VAR_WIN, PV_FDC,
1237 {(char_u *)FALSE, (char_u *)0L}
1238#else
1239 (char_u *)NULL, PV_NONE,
1240 {(char_u *)NULL, (char_u *)0L}
1241#endif
1242 SCRIPTID_INIT},
1243 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1244#ifdef FEAT_FOLDING
1245 (char_u *)VAR_WIN, PV_FEN,
1246 {(char_u *)TRUE, (char_u *)0L}
1247#else
1248 (char_u *)NULL, PV_NONE,
1249 {(char_u *)NULL, (char_u *)0L}
1250#endif
1251 SCRIPTID_INIT},
1252 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1253#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1254 (char_u *)VAR_WIN, PV_FDE,
1255 {(char_u *)"0", (char_u *)NULL}
1256#else
1257 (char_u *)NULL, PV_NONE,
1258 {(char_u *)NULL, (char_u *)0L}
1259#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001262#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001263 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001264 {(char_u *)"#", (char_u *)NULL}
1265#else
1266 (char_u *)NULL, PV_NONE,
1267 {(char_u *)NULL, (char_u *)0L}
1268#endif
1269 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001271#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001272 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001273 {(char_u *)0L, (char_u *)0L}
1274#else
1275 (char_u *)NULL, PV_NONE,
1276 {(char_u *)NULL, (char_u *)0L}
1277#endif
1278 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001279 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001280#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001281 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001282 {(char_u *)-1L, (char_u *)0L}
1283#else
1284 (char_u *)NULL, PV_NONE,
1285 {(char_u *)NULL, (char_u *)0L}
1286#endif
1287 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001289 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001290#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001292 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001293#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294 (char_u *)NULL, PV_NONE,
1295 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001296#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001297 SCRIPTID_INIT},
1298 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1299#ifdef FEAT_FOLDING
1300 (char_u *)VAR_WIN, PV_FDM,
1301 {(char_u *)"manual", (char_u *)NULL}
1302#else
1303 (char_u *)NULL, PV_NONE,
1304 {(char_u *)NULL, (char_u *)0L}
1305#endif
1306 SCRIPTID_INIT},
1307 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1308#ifdef FEAT_FOLDING
1309 (char_u *)VAR_WIN, PV_FML,
1310 {(char_u *)1L, (char_u *)0L}
1311#else
1312 (char_u *)NULL, PV_NONE,
1313 {(char_u *)NULL, (char_u *)0L}
1314#endif
1315 SCRIPTID_INIT},
1316 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1317#ifdef FEAT_FOLDING
1318 (char_u *)VAR_WIN, PV_FDN,
1319 {(char_u *)20L, (char_u *)0L}
1320#else
1321 (char_u *)NULL, PV_NONE,
1322 {(char_u *)NULL, (char_u *)0L}
1323#endif
1324 SCRIPTID_INIT},
1325 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1326#ifdef FEAT_FOLDING
1327 (char_u *)&p_fdo, PV_NONE,
1328 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1329 (char_u *)0L}
1330#else
1331 (char_u *)NULL, PV_NONE,
1332 {(char_u *)NULL, (char_u *)0L}
1333#endif
1334 SCRIPTID_INIT},
1335 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1336#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1337 (char_u *)VAR_WIN, PV_FDT,
1338 {(char_u *)"foldtext()", (char_u *)NULL}
1339#else
1340 (char_u *)NULL, PV_NONE,
1341 {(char_u *)NULL, (char_u *)0L}
1342#endif
1343 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001344 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001345#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001346 (char_u *)&p_fex, PV_FEX,
1347 {(char_u *)"", (char_u *)0L}
1348#else
1349 (char_u *)NULL, PV_NONE,
1350 {(char_u *)0L, (char_u *)0L}
1351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1354 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1356 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001357 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1358 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1360 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001362 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001363 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001364 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1365#ifdef HAVE_FSYNC
1366 (char_u *)&p_fs, PV_NONE,
1367 {(char_u *)TRUE, (char_u *)0L}
1368#else
1369 (char_u *)NULL, PV_NONE,
1370 {(char_u *)FALSE, (char_u *)0L}
1371#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001372 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1374 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001375 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 {"graphic", "gr", P_BOOL|P_VI_DEF,
1377 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001379 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380#ifdef FEAT_QUICKFIX
1381 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383#else
1384 (char_u *)NULL, PV_NONE,
1385 {(char_u *)NULL, (char_u *)0L}
1386#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001387 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001388 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1389#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001390 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001391 {
1392# ifdef WIN3264
1393 /* may be changed to "grep -n" in os_win32.c */
1394 (char_u *)"findstr /n",
1395# else
1396# ifdef UNIX
1397 /* Add an extra file name so that grep will always
1398 * insert a file name in the match line. */
1399 (char_u *)"grep -n $* /dev/null",
1400# else
1401# ifdef VMS
1402 (char_u *)"SEARCH/NUMBERS ",
1403# else
1404 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405# endif
1406# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001409#else
1410 (char_u *)NULL, PV_NONE,
1411 {(char_u *)NULL, (char_u *)0L}
1412#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001413 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001414 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415#ifdef CURSOR_SHAPE
1416 (char_u *)&p_guicursor, PV_NONE,
1417 {
1418# ifdef FEAT_GUI
1419 (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",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001420# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001421 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1422# endif
1423 (char_u *)0L}
1424#else
1425 (char_u *)NULL, PV_NONE,
1426 {(char_u *)NULL, (char_u *)0L}
1427#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001428 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001429 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430#ifdef FEAT_GUI
1431 (char_u *)&p_guifont, PV_NONE,
1432 {(char_u *)"", (char_u *)0L}
1433#else
1434 (char_u *)NULL, PV_NONE,
1435 {(char_u *)NULL, (char_u *)0L}
1436#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001437 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001438 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001439#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1440 (char_u *)&p_guifontset, PV_NONE,
1441 {(char_u *)"", (char_u *)0L}
1442#else
1443 (char_u *)NULL, PV_NONE,
1444 {(char_u *)NULL, (char_u *)0L}
1445#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001446 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001447 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1449 (char_u *)&p_guifontwide, PV_NONE,
1450 {(char_u *)"", (char_u *)0L}
1451#else
1452 (char_u *)NULL, PV_NONE,
1453 {(char_u *)NULL, (char_u *)0L}
1454#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001455 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001457#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 (char_u *)&p_ghr, PV_NONE,
1459#else
1460 (char_u *)NULL, PV_NONE,
1461#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001462 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001464#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 (char_u *)&p_go, PV_NONE,
1466# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001467 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001469 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470# endif
1471#else
1472 (char_u *)NULL, PV_NONE,
1473 {(char_u *)NULL, (char_u *)0L}
1474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001475 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"guipty", NULL, P_BOOL|P_VI_DEF,
1477#if defined(FEAT_GUI)
1478 (char_u *)&p_guipty, PV_NONE,
1479#else
1480 (char_u *)NULL, PV_NONE,
1481#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001482 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001483 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001484#if defined(FEAT_GUI_TABLINE)
1485 (char_u *)&p_gtl, PV_NONE,
1486 {(char_u *)"", (char_u *)0L}
1487#else
1488 (char_u *)NULL, PV_NONE,
1489 {(char_u *)NULL, (char_u *)0L}
1490#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001491 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001492 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001493#if defined(FEAT_GUI_TABLINE)
1494 (char_u *)&p_gtt, PV_NONE,
1495 {(char_u *)"", (char_u *)0L}
1496#else
1497 (char_u *)NULL, PV_NONE,
1498 {(char_u *)NULL, (char_u *)0L}
1499#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001500 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1502 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001503 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1505 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001506 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1507 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"helpheight", "hh", P_NUM|P_VI_DEF,
1509#ifdef FEAT_WINDOWS
1510 (char_u *)&p_hh, PV_NONE,
1511#else
1512 (char_u *)NULL, PV_NONE,
1513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001514 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001515 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516#ifdef FEAT_MULTI_LANG
1517 (char_u *)&p_hlg, PV_NONE,
1518 {(char_u *)"", (char_u *)0L}
1519#else
1520 (char_u *)NULL, PV_NONE,
1521 {(char_u *)0L, (char_u *)0L}
1522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001523 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524 {"hidden", "hid", P_BOOL|P_VI_DEF,
1525 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001526 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001527 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001529 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1530 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"history", "hi", P_NUM|P_VIM,
1532 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001533 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001534 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1535#ifdef FEAT_RIGHTLEFT
1536 (char_u *)&p_hkmap, PV_NONE,
1537#else
1538 (char_u *)NULL, PV_NONE,
1539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1542#ifdef FEAT_RIGHTLEFT
1543 (char_u *)&p_hkmapp, PV_NONE,
1544#else
1545 (char_u *)NULL, PV_NONE,
1546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001547 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1549 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001550 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001551 {"icon", NULL, P_BOOL|P_VI_DEF,
1552#ifdef FEAT_TITLE
1553 (char_u *)&p_icon, PV_NONE,
1554#else
1555 (char_u *)NULL, PV_NONE,
1556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {"iconstring", NULL, P_STRING|P_VI_DEF,
1559#ifdef FEAT_TITLE
1560 (char_u *)&p_iconstring, PV_NONE,
1561#else
1562 (char_u *)NULL, PV_NONE,
1563#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001564 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001565 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1566 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001568 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1569# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1570 (char_u *)&p_imaf, PV_NONE,
1571 {(char_u *)"", (char_u *)NULL}
1572# else
1573 (char_u *)NULL, PV_NONE,
1574 {(char_u *)NULL, (char_u *)0L}
1575# endif
1576 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001578#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 (char_u *)&p_imak, PV_NONE,
1580#else
1581 (char_u *)NULL, PV_NONE,
1582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001583 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1585#ifdef USE_IM_CONTROL
1586 (char_u *)&p_imcmdline, PV_NONE,
1587#else
1588 (char_u *)NULL, PV_NONE,
1589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001590 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001591 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1592#ifdef USE_IM_CONTROL
1593 (char_u *)&p_imdisable, PV_NONE,
1594#else
1595 (char_u *)NULL, PV_NONE,
1596#endif
1597#ifdef __sgi
1598 {(char_u *)TRUE, (char_u *)0L}
1599#else
1600 {(char_u *)FALSE, (char_u *)0L}
1601#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001602 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001603 {"iminsert", "imi", P_NUM|P_VI_DEF,
1604 (char_u *)&p_iminsert, PV_IMI,
1605#ifdef B_IMODE_IM
1606 {(char_u *)B_IMODE_IM, (char_u *)0L}
1607#else
1608 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {"imsearch", "ims", P_NUM|P_VI_DEF,
1612 (char_u *)&p_imsearch, PV_IMS,
1613#ifdef B_IMODE_IM
1614 {(char_u *)B_IMODE_IM, (char_u *)0L}
1615#else
1616 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001618 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001619 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001620# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1621 (char_u *)&p_imsf, PV_NONE,
1622 {(char_u *)"", (char_u *)NULL}
1623# else
1624 (char_u *)NULL, PV_NONE,
1625 {(char_u *)NULL, (char_u *)0L}
1626# endif
1627 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001628 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1629#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001630 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1632#else
1633 (char_u *)NULL, PV_NONE,
1634 {(char_u *)0L, (char_u *)0L}
1635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001636 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001637 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1638#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1639 (char_u *)&p_inex, PV_INEX,
1640 {(char_u *)"", (char_u *)0L}
1641#else
1642 (char_u *)NULL, PV_NONE,
1643 {(char_u *)0L, (char_u *)0L}
1644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001645 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1647 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001648 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1650#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1651 (char_u *)&p_inde, PV_INDE,
1652 {(char_u *)"", (char_u *)0L}
1653#else
1654 (char_u *)NULL, PV_NONE,
1655 {(char_u *)0L, (char_u *)0L}
1656#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001657 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001658 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1660 (char_u *)&p_indk, PV_INDK,
1661 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1662#else
1663 (char_u *)NULL, PV_NONE,
1664 {(char_u *)0L, (char_u *)0L}
1665#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001666 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001667 {"infercase", "inf", P_BOOL|P_VI_DEF,
1668 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1671 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001672 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001673 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1674 (char_u *)&p_isf, PV_NONE,
1675 {
1676#ifdef BACKSLASH_IN_FILENAME
1677 /* Excluded are: & and ^ are special in cmd.exe
1678 * ( and ) are used in text separating fnames */
1679 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1680#else
1681# ifdef AMIGA
1682 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1683# else
1684# ifdef VMS
1685 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1686# else /* UNIX et al. */
1687# ifdef EBCDIC
1688 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1689# else
1690 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1691# endif
1692# endif
1693# endif
1694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001695 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001696 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1697 (char_u *)&p_isi, PV_NONE,
1698 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001699#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 (char_u *)"@,48-57,_,128-167,224-235",
1701#else
1702# ifdef EBCDIC
1703 /* TODO: EBCDIC Check this! @ == isalpha()*/
1704 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1705 "112-120,128,140-142,156,158,172,"
1706 "174,186,191,203-207,219-225,235-239,"
1707 "251-254",
1708# else
1709 (char_u *)"@,48-57,_,192-255",
1710# endif
1711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001712 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1714 (char_u *)&p_isk, PV_ISK,
1715 {
1716#ifdef EBCDIC
1717 (char_u *)"@,240-249,_",
1718 /* TODO: EBCDIC Check this! @ == isalpha()*/
1719 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1720 "112-120,128,140-142,156,158,172,"
1721 "174,186,191,203-207,219-225,235-239,"
1722 "251-254",
1723#else
1724 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001725# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 (char_u *)"@,48-57,_,128-167,224-235"
1727# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001728 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729# endif
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1733 (char_u *)&p_isp, PV_NONE,
1734 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001735#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 || defined(VMS)
1737 (char_u *)"@,~-255",
1738#else
1739# ifdef EBCDIC
1740 /* all chars above 63 are printable */
1741 (char_u *)"63-255",
1742# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001743 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744# endif
1745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001746 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1748 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1751#ifdef FEAT_CRYPT
1752 (char_u *)&p_key, PV_KEY,
1753 {(char_u *)"", (char_u *)0L}
1754#else
1755 (char_u *)NULL, PV_NONE,
1756 {(char_u *)0L, (char_u *)0L}
1757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001758 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001759 {"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 +00001760#ifdef FEAT_KEYMAP
1761 (char_u *)&p_keymap, PV_KMAP,
1762 {(char_u *)"", (char_u *)0L}
1763#else
1764 (char_u *)NULL, PV_NONE,
1765 {(char_u *)"", (char_u *)0L}
1766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001768 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001770 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001772 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001774#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775 (char_u *)":help",
1776#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001777# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001779# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001780# ifdef USEMAN_S
1781 (char_u *)"man -s",
1782# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001784# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785# endif
1786#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001787 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001788 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789#ifdef FEAT_LANGMAP
1790 (char_u *)&p_langmap, PV_NONE,
1791 {(char_u *)"", /* unmatched } */
1792#else
1793 (char_u *)NULL, PV_NONE,
1794 {(char_u *)NULL,
1795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001796 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001797 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001798#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1799 (char_u *)&p_lm, PV_NONE,
1800#else
1801 (char_u *)NULL, PV_NONE,
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001804 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1805#ifdef FEAT_LANGMAP
1806 (char_u *)&p_lnr, PV_NONE,
1807#else
1808 (char_u *)NULL, PV_NONE,
1809#endif
1810 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001811 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1812#ifdef FEAT_LANGMAP
1813 (char_u *)&p_lrm, PV_NONE,
1814#else
1815 (char_u *)NULL, PV_NONE,
1816#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001817 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1819#ifdef FEAT_WINDOWS
1820 (char_u *)&p_ls, PV_NONE,
1821#else
1822 (char_u *)NULL, PV_NONE,
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1826 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1829#ifdef FEAT_LINEBREAK
1830 (char_u *)VAR_WIN, PV_LBR,
1831#else
1832 (char_u *)NULL, PV_NONE,
1833#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1836 (char_u *)&Rows, PV_NONE,
1837 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001838#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 (char_u *)25L,
1840#else
1841 (char_u *)24L,
1842#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001844 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1845#ifdef FEAT_GUI
1846 (char_u *)&p_linespace, PV_NONE,
1847#else
1848 (char_u *)NULL, PV_NONE,
1849#endif
1850#ifdef FEAT_GUI_W32
1851 {(char_u *)1L, (char_u *)0L}
1852#else
1853 {(char_u *)0L, (char_u *)0L}
1854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856 {"lisp", NULL, P_BOOL|P_VI_DEF,
1857#ifdef FEAT_LISP
1858 (char_u *)&p_lisp, PV_LISP,
1859#else
1860 (char_u *)NULL, PV_NONE,
1861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001863 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001865 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1867#else
1868 (char_u *)NULL, PV_NONE,
1869 {(char_u *)"", (char_u *)0L}
1870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1873 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001874 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001875 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1879 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001881 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001882#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001883 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001884 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001885#else
1886 (char_u *)NULL, PV_NONE,
1887 {(char_u *)"", (char_u *)0L}
1888#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001889 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001890 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001891#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001892 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001893 {(char_u *)TRUE, (char_u *)0L}
1894#else
1895 (char_u *)NULL, PV_NONE,
1896 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001897#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001898 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"magic", NULL, P_BOOL|P_VI_DEF,
1900 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001902 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903#ifdef FEAT_QUICKFIX
1904 (char_u *)&p_mef, PV_NONE,
1905 {(char_u *)"", (char_u *)0L}
1906#else
1907 (char_u *)NULL, PV_NONE,
1908 {(char_u *)NULL, (char_u *)0L}
1909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001910 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001911 {"makeencoding","menc", P_STRING|P_VI_DEF,
1912#ifdef FEAT_MBYTE
1913 (char_u *)&p_menc, PV_MENC,
1914 {(char_u *)"", (char_u *)0L}
1915#else
1916 (char_u *)NULL, PV_NONE,
1917 {(char_u *)0L, (char_u *)0L}
1918#endif
1919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1921#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001922 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923# ifdef VMS
1924 {(char_u *)"MMS", (char_u *)0L}
1925# else
1926 {(char_u *)"make", (char_u *)0L}
1927# endif
1928#else
1929 (char_u *)NULL, PV_NONE,
1930 {(char_u *)NULL, (char_u *)0L}
1931#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001932 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001933 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1936 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 {"matchtime", "mat", P_NUM|P_VI_DEF,
1938 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001939 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001940 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001941#ifdef FEAT_MBYTE
1942 (char_u *)&p_mco, PV_NONE,
1943#else
1944 (char_u *)NULL, PV_NONE,
1945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1948#ifdef FEAT_EVAL
1949 (char_u *)&p_mfd, PV_NONE,
1950#else
1951 (char_u *)NULL, PV_NONE,
1952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1955 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001956 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957 {"maxmem", "mm", P_NUM|P_VI_DEF,
1958 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1960 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001961 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1962 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1965 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001966 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1967 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"menuitems", "mis", P_NUM|P_VI_DEF,
1969#ifdef FEAT_MENU
1970 (char_u *)&p_mis, PV_NONE,
1971#else
1972 (char_u *)NULL, PV_NONE,
1973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 {"mesg", NULL, P_BOOL|P_VI_DEF,
1976 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001978 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001979#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001980 (char_u *)&p_msm, PV_NONE,
1981 {(char_u *)"460000,2000,500", (char_u *)0L}
1982#else
1983 (char_u *)NULL, PV_NONE,
1984 {(char_u *)0L, (char_u *)0L}
1985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001986 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 {"modeline", "ml", P_BOOL|P_VIM,
1988 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001989 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001990 {"modelines", "mls", P_NUM|P_VI_DEF,
1991 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001992 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001993 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1994 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001995 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1997 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 {"more", NULL, P_BOOL|P_VIM,
2000 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002001 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
2003 (char_u *)&p_mouse, PV_NONE,
2004 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002005#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 (char_u *)"a",
2007#else
2008 (char_u *)"",
2009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002010 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002011 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
2012#ifdef FEAT_GUI
2013 (char_u *)&p_mousef, PV_NONE,
2014#else
2015 (char_u *)NULL, PV_NONE,
2016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002017 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2019#ifdef FEAT_GUI
2020 (char_u *)&p_mh, PV_NONE,
2021#else
2022 (char_u *)NULL, PV_NONE,
2023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002024 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2026 (char_u *)&p_mousem, PV_NONE,
2027 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002028#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029 (char_u *)"popup",
2030#else
2031# if defined(MACOS)
2032 (char_u *)"popup_setpos",
2033# else
2034 (char_u *)"extend",
2035# endif
2036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002037 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002038 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039#ifdef FEAT_MOUSESHAPE
2040 (char_u *)&p_mouseshape, PV_NONE,
2041 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2042#else
2043 (char_u *)NULL, PV_NONE,
2044 {(char_u *)NULL, (char_u *)0L}
2045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002046 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002047 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2048 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002049 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002050 {"mzquantum", "mzq", P_NUM,
2051#ifdef FEAT_MZSCHEME
2052 (char_u *)&p_mzq, PV_NONE,
2053#else
2054 (char_u *)NULL, PV_NONE,
2055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002057 {"novice", NULL, P_BOOL|P_VI_DEF,
2058 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002059 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002060 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002062 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2065 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002067 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2068#ifdef FEAT_LINEBREAK
2069 (char_u *)VAR_WIN, PV_NUW,
2070#else
2071 (char_u *)NULL, PV_NONE,
2072#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002073 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002074 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002075#ifdef FEAT_COMPL_FUNC
2076 (char_u *)&p_ofu, PV_OFU,
2077 {(char_u *)"", (char_u *)0L}
2078#else
2079 (char_u *)NULL, PV_NONE,
2080 {(char_u *)0L, (char_u *)0L}
2081#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002082 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 {"open", NULL, P_BOOL|P_VI_DEF,
2084 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002086 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002087#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002088 (char_u *)&p_odev, PV_NONE,
2089#else
2090 (char_u *)NULL, PV_NONE,
2091#endif
2092 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002094 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2095 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002097 {"optimize", "opt", P_BOOL|P_VI_DEF,
2098 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002099 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002101 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002102 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002103 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2104 |P_SECURE,
2105 (char_u *)&p_pp, PV_NONE,
2106 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2107 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"paragraphs", "para", P_STRING|P_VI_DEF,
2109 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002110 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002112 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2116 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2119#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2120 (char_u *)&p_pex, PV_NONE,
2121 {(char_u *)"", (char_u *)0L}
2122#else
2123 (char_u *)NULL, PV_NONE,
2124 {(char_u *)0L, (char_u *)0L}
2125#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002126 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002127 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002129 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002131 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002133#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 (char_u *)".,,",
2135#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002138 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002139 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002140#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002141 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002142 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002143#else
2144 (char_u *)NULL, PV_NONE,
2145 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002146#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002147 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2149 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002150 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002151 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2153 (char_u *)&p_pvh, PV_NONE,
2154#else
2155 (char_u *)NULL, PV_NONE,
2156#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2159#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2160 (char_u *)VAR_WIN, PV_PVW,
2161#else
2162 (char_u *)NULL, PV_NONE,
2163#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002164 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002165 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166#ifdef FEAT_PRINTER
2167 (char_u *)&p_pdev, PV_NONE,
2168 {(char_u *)"", (char_u *)0L}
2169#else
2170 (char_u *)NULL, PV_NONE,
2171 {(char_u *)NULL, (char_u *)0L}
2172#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002173 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174 {"printencoding", "penc", P_STRING|P_VI_DEF,
2175#ifdef FEAT_POSTSCRIPT
2176 (char_u *)&p_penc, 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
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002182 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002183 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002184#ifdef FEAT_POSTSCRIPT
2185 (char_u *)&p_pexpr, PV_NONE,
2186 {(char_u *)"", (char_u *)0L}
2187#else
2188 (char_u *)NULL, PV_NONE,
2189 {(char_u *)NULL, (char_u *)0L}
2190#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002191 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002192 {"printfont", "pfn", P_STRING|P_VI_DEF,
2193#ifdef FEAT_PRINTER
2194 (char_u *)&p_pfn, PV_NONE,
2195 {
2196# ifdef MSWIN
2197 (char_u *)"Courier_New:h10",
2198# else
2199 (char_u *)"courier",
2200# endif
2201 (char_u *)0L}
2202#else
2203 (char_u *)NULL, PV_NONE,
2204 {(char_u *)NULL, (char_u *)0L}
2205#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002206 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2208#ifdef FEAT_PRINTER
2209 (char_u *)&p_header, PV_NONE,
2210 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
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 Moolenaar8299df92004-07-10 09:47:34 +00002216 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2217#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2218 (char_u *)&p_pmcs, PV_NONE,
2219 {(char_u *)"", (char_u *)0L}
2220#else
2221 (char_u *)NULL, PV_NONE,
2222 {(char_u *)NULL, (char_u *)0L}
2223#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002224 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002225 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2226#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2227 (char_u *)&p_pmfn, PV_NONE,
2228 {(char_u *)"", (char_u *)0L}
2229#else
2230 (char_u *)NULL, PV_NONE,
2231 {(char_u *)NULL, (char_u *)0L}
2232#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002234 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002235#ifdef FEAT_PRINTER
2236 (char_u *)&p_popt, PV_NONE,
2237 {(char_u *)"", (char_u *)0L}
2238#else
2239 (char_u *)NULL, PV_NONE,
2240 {(char_u *)NULL, (char_u *)0L}
2241#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002242 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002244 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002245 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002246 {"pumheight", "ph", P_NUM|P_VI_DEF,
2247#ifdef FEAT_INS_EXPAND
2248 (char_u *)&p_ph, PV_NONE,
2249#else
2250 (char_u *)NULL, PV_NONE,
2251#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002252 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002253 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002254#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002255 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002256 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002257#else
2258 (char_u *)NULL, PV_NONE,
2259 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002260#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002261 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002262 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002263#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002264 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002265 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002266#else
2267 (char_u *)NULL, PV_NONE,
2268 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002269#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002270 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002271 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2272#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2273 (char_u *)&p_pyx, PV_NONE,
2274#else
2275 (char_u *)NULL, PV_NONE,
2276#endif
2277 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2278 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002279 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2280#ifdef FEAT_TEXTOBJ
2281 (char_u *)&p_qe, PV_QE,
2282 {(char_u *)"\\", (char_u *)0L}
2283#else
2284 (char_u *)NULL, PV_NONE,
2285 {(char_u *)NULL, (char_u *)0L}
2286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2289 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 {"redraw", NULL, P_BOOL|P_VI_DEF,
2292 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002293 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002294 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2295#ifdef FEAT_RELTIME
2296 (char_u *)&p_rdt, PV_NONE,
2297#else
2298 (char_u *)NULL, PV_NONE,
2299#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002300 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002301 {"regexpengine", "re", P_NUM|P_VI_DEF,
2302 (char_u *)&p_re, PV_NONE,
2303 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002304 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2305 (char_u *)VAR_WIN, PV_RNU,
2306 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 {"remap", NULL, P_BOOL|P_VI_DEF,
2308 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002310 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002311#ifdef FEAT_RENDER_OPTIONS
2312 (char_u *)&p_rop, PV_NONE,
2313 {(char_u *)"", (char_u *)0L}
2314#else
2315 (char_u *)NULL, PV_NONE,
2316 {(char_u *)NULL, (char_u *)0L}
2317#endif
2318 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 {"report", NULL, P_NUM|P_VI_DEF,
2320 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002321 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2323#ifdef WIN3264
2324 (char_u *)&p_rs, PV_NONE,
2325#else
2326 (char_u *)NULL, PV_NONE,
2327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2330#ifdef FEAT_RIGHTLEFT
2331 (char_u *)&p_ri, PV_NONE,
2332#else
2333 (char_u *)NULL, PV_NONE,
2334#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2337#ifdef FEAT_RIGHTLEFT
2338 (char_u *)VAR_WIN, PV_RL,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2344#ifdef FEAT_RIGHTLEFT
2345 (char_u *)VAR_WIN, PV_RLC,
2346 {(char_u *)"search", (char_u *)NULL}
2347#else
2348 (char_u *)NULL, PV_NONE,
2349 {(char_u *)NULL, (char_u *)0L}
2350#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002352 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002353#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002354 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002355 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002356#else
2357 (char_u *)NULL, PV_NONE,
2358 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002359#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002360 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2362#ifdef FEAT_CMDL_INFO
2363 (char_u *)&p_ru, PV_NONE,
2364#else
2365 (char_u *)NULL, PV_NONE,
2366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2369#ifdef FEAT_STL_OPT
2370 (char_u *)&p_ruf, PV_NONE,
2371#else
2372 (char_u *)NULL, PV_NONE,
2373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002375 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2376 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2379 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2381 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002382 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2384#ifdef FEAT_SCROLLBIND
2385 (char_u *)VAR_WIN, PV_SCBIND,
2386#else
2387 (char_u *)NULL, PV_NONE,
2388#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002389 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2391 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2394 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002396 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397#ifdef FEAT_SCROLLBIND
2398 (char_u *)&p_sbo, PV_NONE,
2399 {(char_u *)"ver,jump", (char_u *)0L}
2400#else
2401 (char_u *)NULL, PV_NONE,
2402 {(char_u *)0L, (char_u *)0L}
2403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"sections", "sect", P_STRING|P_VI_DEF,
2406 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2408 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2410 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002411 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002414 {(char_u *)"inclusive", (char_u *)0L}
2415 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002416 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002419 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420#ifdef FEAT_SESSION
2421 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002422 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 (char_u *)0L}
2424#else
2425 (char_u *)NULL, PV_NONE,
2426 {(char_u *)0L, (char_u *)0L}
2427#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2430 (char_u *)&p_sh, PV_NONE,
2431 {
2432#ifdef VMS
2433 (char_u *)"-",
2434#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002435# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002437# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439# endif
2440#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2443 (char_u *)&p_shcf, PV_NONE,
2444 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002445#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 (char_u *)"/c",
2447#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2452#ifdef FEAT_QUICKFIX
2453 (char_u *)&p_sp, PV_NONE,
2454 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002455#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457#else
2458 (char_u *)">",
2459#endif
2460 (char_u *)0L}
2461#else
2462 (char_u *)NULL, PV_NONE,
2463 {(char_u *)0L, (char_u *)0L}
2464#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002465 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002466 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2467 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2470 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002471 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002472 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2473#ifdef BACKSLASH_IN_FILENAME
2474 (char_u *)&p_ssl, PV_NONE,
2475#else
2476 (char_u *)NULL, PV_NONE,
2477#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002479 {"shelltemp", "stmp", P_BOOL,
2480 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002481 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 {"shelltype", "st", P_NUM|P_VI_DEF,
2483#ifdef AMIGA
2484 (char_u *)&p_st, PV_NONE,
2485#else
2486 (char_u *)NULL, PV_NONE,
2487#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002488 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2490 (char_u *)&p_sxq, PV_NONE,
2491 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002492#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 (char_u *)"\"",
2494#else
2495 (char_u *)"",
2496#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002498 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2499 (char_u *)&p_sxe, PV_NONE,
2500 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002501#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002502 (char_u *)"\"&|<>()@^",
2503#else
2504 (char_u *)"",
2505#endif
2506 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2508 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002509 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2511 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2514 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)"", (char_u *)"filnxtToO"}
2516 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002519 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2521#ifdef FEAT_LINEBREAK
2522 (char_u *)&p_sbr, PV_NONE,
2523#else
2524 (char_u *)NULL, PV_NONE,
2525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"showcmd", "sc", P_BOOL|P_VIM,
2528#ifdef FEAT_CMDL_INFO
2529 (char_u *)&p_sc, PV_NONE,
2530#else
2531 (char_u *)NULL, PV_NONE,
2532#endif
2533 {(char_u *)FALSE,
2534#ifdef UNIX
2535 (char_u *)FALSE
2536#else
2537 (char_u *)TRUE
2538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2541 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2544 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 {"showmode", "smd", P_BOOL|P_VIM,
2547 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002548 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002549 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2550#ifdef FEAT_WINDOWS
2551 (char_u *)&p_stal, PV_NONE,
2552#else
2553 (char_u *)NULL, PV_NONE,
2554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002555 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2557 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2560 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002562 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2563#ifdef FEAT_SIGNS
2564 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002565 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002566#else
2567 (char_u *)NULL, PV_NONE,
2568 {(char_u *)NULL, (char_u *)0L}
2569#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2572 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2575 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2578#ifdef FEAT_SMARTINDENT
2579 (char_u *)&p_si, PV_SI,
2580#else
2581 (char_u *)NULL, PV_NONE,
2582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2585 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2588 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002589 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2591 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002592 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002593 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002594#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002595 (char_u *)VAR_WIN, PV_SPELL,
2596#else
2597 (char_u *)NULL, PV_NONE,
2598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002599 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002600 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002601#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002602 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002603 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002604#else
2605 (char_u *)NULL, PV_NONE,
2606 {(char_u *)0L, (char_u *)0L}
2607#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002608 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002609 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2610 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002611#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002612 (char_u *)&p_spf, PV_SPF,
2613 {(char_u *)"", (char_u *)0L}
2614#else
2615 (char_u *)NULL, PV_NONE,
2616 {(char_u *)0L, (char_u *)0L}
2617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002619 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2620 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002621#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002622 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002623 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002624#else
2625 (char_u *)NULL, PV_NONE,
2626 {(char_u *)0L, (char_u *)0L}
2627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002629 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002630#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002631 (char_u *)&p_sps, PV_NONE,
2632 {(char_u *)"best", (char_u *)0L}
2633#else
2634 (char_u *)NULL, PV_NONE,
2635 {(char_u *)0L, (char_u *)0L}
2636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2639#ifdef FEAT_WINDOWS
2640 (char_u *)&p_sb, PV_NONE,
2641#else
2642 (char_u *)NULL, PV_NONE,
2643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002646#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 (char_u *)&p_spr, PV_NONE,
2648#else
2649 (char_u *)NULL, PV_NONE,
2650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2653 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2656#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002657 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658#else
2659 (char_u *)NULL, PV_NONE,
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002662 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 (char_u *)&p_su, PV_NONE,
2664 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002666 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002667#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 (char_u *)&p_sua, PV_SUA,
2669 {(char_u *)"", (char_u *)0L}
2670#else
2671 (char_u *)NULL, PV_NONE,
2672 {(char_u *)0L, (char_u *)0L}
2673#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002674 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2676 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"swapsync", "sws", P_STRING|P_VI_DEF,
2679 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002681 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002684 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2685#ifdef FEAT_SYN_HL
2686 (char_u *)&p_smc, PV_SMC,
2687 {(char_u *)3000L, (char_u *)0L}
2688#else
2689 (char_u *)NULL, PV_NONE,
2690 {(char_u *)0L, (char_u *)0L}
2691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002692 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002693 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694#ifdef FEAT_SYN_HL
2695 (char_u *)&p_syn, PV_SYN,
2696 {(char_u *)"", (char_u *)0L}
2697#else
2698 (char_u *)NULL, PV_NONE,
2699 {(char_u *)0L, (char_u *)0L}
2700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002702 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2703#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002704 (char_u *)&p_tal, PV_NONE,
2705#else
2706 (char_u *)NULL, PV_NONE,
2707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002709 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2710#ifdef FEAT_WINDOWS
2711 (char_u *)&p_tpm, PV_NONE,
2712#else
2713 (char_u *)NULL, PV_NONE,
2714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2717 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2720 (char_u *)&p_tbs, PV_NONE,
2721#ifdef VMS /* binary searching doesn't appear to work on VMS */
2722 {(char_u *)0L, (char_u *)0L}
2723#else
2724 {(char_u *)TRUE, (char_u *)0L}
2725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002727 {"tagcase", "tc", P_STRING|P_VIM,
2728 (char_u *)&p_tc, PV_TC,
2729 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"taglength", "tl", P_NUM|P_VI_DEF,
2731 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"tagrelative", "tr", P_BOOL|P_VIM,
2734 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002736 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002737 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {
2739#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2740 (char_u *)"./tags,./TAGS,tags,TAGS",
2741#else
2742 (char_u *)"./tags,tags",
2743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2746 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002748 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002749#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002750 (char_u *)&p_tcldll, PV_NONE,
2751 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002752#else
2753 (char_u *)NULL, PV_NONE,
2754 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002755#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002756 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2758 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002759 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2761#ifdef FEAT_ARABIC
2762 (char_u *)&p_tbidi, PV_NONE,
2763#else
2764 (char_u *)NULL, PV_NONE,
2765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2768#ifdef FEAT_MBYTE
2769 (char_u *)&p_tenc, PV_NONE,
2770 {(char_u *)"", (char_u *)0L}
2771#else
2772 (char_u *)NULL, PV_NONE,
2773 {(char_u *)0L, (char_u *)0L}
2774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002776 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2777#ifdef FEAT_TERMGUICOLORS
2778 (char_u *)&p_tgc, PV_NONE,
2779 {(char_u *)FALSE, (char_u *)FALSE}
2780#else
2781 (char_u*)NULL, PV_NONE,
2782 {(char_u *)FALSE, (char_u *)FALSE}
2783#endif
2784 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002785 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2786#ifdef FEAT_TERMINAL
2787 (char_u *)VAR_WIN, PV_TK,
2788 {(char_u *)"\x17", (char_u *)NULL}
2789#else
2790 (char_u *)NULL, PV_NONE,
2791 {(char_u *)NULL, (char_u *)0L}
2792#endif
2793 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002794 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2795#ifdef FEAT_TERMINAL
2796 (char_u *)VAR_WIN, PV_TMS,
2797 {(char_u *)"", (char_u *)NULL}
2798#else
2799 (char_u *)NULL, PV_NONE,
2800 {(char_u *)NULL, (char_u *)0L}
2801#endif
2802 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"terse", NULL, P_BOOL|P_VI_DEF,
2804 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"textauto", "ta", P_BOOL|P_VIM,
2807 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2809 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2811 (char_u *)&p_tx, PV_TX,
2812 {
2813#ifdef USE_CRNL
2814 (char_u *)TRUE,
2815#else
2816 (char_u *)FALSE,
2817#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002819 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002822 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002824 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825#else
2826 (char_u *)NULL, PV_NONE,
2827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2830 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"timeout", "to", P_BOOL|P_VI_DEF,
2833 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2836 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"title", NULL, P_BOOL|P_VI_DEF,
2839#ifdef FEAT_TITLE
2840 (char_u *)&p_title, PV_NONE,
2841#else
2842 (char_u *)NULL, PV_NONE,
2843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002844 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 {"titlelen", NULL, P_NUM|P_VI_DEF,
2846#ifdef FEAT_TITLE
2847 (char_u *)&p_titlelen, PV_NONE,
2848#else
2849 (char_u *)NULL, PV_NONE,
2850#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002851 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002852 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853#ifdef FEAT_TITLE
2854 (char_u *)&p_titleold, PV_NONE,
2855 {(char_u *)N_("Thanks for flying Vim"),
2856 (char_u *)0L}
2857#else
2858 (char_u *)NULL, PV_NONE,
2859 {(char_u *)0L, (char_u *)0L}
2860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002861 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862 {"titlestring", NULL, P_STRING|P_VI_DEF,
2863#ifdef FEAT_TITLE
2864 (char_u *)&p_titlestring, PV_NONE,
2865#else
2866 (char_u *)NULL, PV_NONE,
2867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002868 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002869 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002870#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002873#else
2874 (char_u *)NULL, PV_NONE,
2875 {(char_u *)0L, (char_u *)0L}
2876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002877 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002879#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002881 {(char_u *)"small", (char_u *)0L}
2882#else
2883 (char_u *)NULL, PV_NONE,
2884 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002886 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2888 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002889 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2891 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002892 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2894 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002895 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2897 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002898 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2900#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2901 (char_u *)&p_ttym, PV_NONE,
2902#else
2903 (char_u *)NULL, PV_NONE,
2904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2907 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002908 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2910 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002911 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002912 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2913 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002914#ifdef FEAT_PERSISTENT_UNDO
2915 (char_u *)&p_udir, PV_NONE,
2916 {(char_u *)".", (char_u *)0L}
2917#else
2918 (char_u *)NULL, PV_NONE,
2919 {(char_u *)0L, (char_u *)0L}
2920#endif
2921 SCRIPTID_INIT},
2922 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2923#ifdef FEAT_PERSISTENT_UNDO
2924 (char_u *)&p_udf, PV_UDF,
2925#else
2926 (char_u *)NULL, PV_NONE,
2927#endif
2928 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002930 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002932#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933 (char_u *)1000L,
2934#else
2935 (char_u *)100L,
2936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002937 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002938 {"undoreload", "ur", P_NUM|P_VI_DEF,
2939 (char_u *)&p_ur, PV_NONE,
2940 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 {"updatecount", "uc", P_NUM|P_VI_DEF,
2942 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002943 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 {"updatetime", "ut", P_NUM|P_VI_DEF,
2945 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002946 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 {"verbose", "vbs", P_NUM|P_VI_DEF,
2948 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002949 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002950 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2951 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002952 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2954#ifdef FEAT_SESSION
2955 (char_u *)&p_vdir, PV_NONE,
2956 {(char_u *)DFLT_VDIR, (char_u *)0L}
2957#else
2958 (char_u *)NULL, PV_NONE,
2959 {(char_u *)0L, (char_u *)0L}
2960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002961 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002962 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963#ifdef FEAT_SESSION
2964 (char_u *)&p_vop, PV_NONE,
2965 {(char_u *)"folds,options,cursor", (char_u *)0L}
2966#else
2967 (char_u *)NULL, PV_NONE,
2968 {(char_u *)0L, (char_u *)0L}
2969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002970 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002971 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972#ifdef FEAT_VIMINFO
2973 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002974#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002975 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976#else
2977# ifdef AMIGA
2978 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002979 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002981 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982# endif
2983#endif
2984#else
2985 (char_u *)NULL, PV_NONE,
2986 {(char_u *)0L, (char_u *)0L}
2987#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002988 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002989 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2990#ifdef FEAT_VIMINFO
2991 (char_u *)&p_viminfofile, PV_NONE,
2992 {(char_u *)"", (char_u *)0L}
2993#else
2994 (char_u *)NULL, PV_NONE,
2995 {(char_u *)0L, (char_u *)0L}
2996#endif
2997 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002998 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2999 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000#ifdef FEAT_VIRTUALEDIT
3001 (char_u *)&p_ve, PV_NONE,
3002 {(char_u *)"", (char_u *)""}
3003#else
3004 (char_u *)NULL, PV_NONE,
3005 {(char_u *)0L, (char_u *)0L}
3006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003007 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3009 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 {"w300", NULL, P_NUM|P_VI_DEF,
3012 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003013 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 {"w1200", NULL, P_NUM|P_VI_DEF,
3015 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003016 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 {"w9600", NULL, P_NUM|P_VI_DEF,
3018 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003019 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"warn", NULL, P_BOOL|P_VI_DEF,
3021 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003022 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3024 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003025 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003026 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003028 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"wildchar", "wc", P_NUM|P_VIM,
3030 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003031 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3032 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003033 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003035 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003036 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037#ifdef FEAT_WILDIGN
3038 (char_u *)&p_wig, PV_NONE,
3039#else
3040 (char_u *)NULL, PV_NONE,
3041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003042 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003043 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3044 (char_u *)&p_wic, PV_NONE,
3045 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3047#ifdef FEAT_WILDMENU
3048 (char_u *)&p_wmnu, PV_NONE,
3049#else
3050 (char_u *)NULL, PV_NONE,
3051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003052 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003053 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003055 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003056 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3057#ifdef FEAT_CMDL_COMPL
3058 (char_u *)&p_wop, PV_NONE,
3059 {(char_u *)"", (char_u *)0L}
3060#else
3061 (char_u *)NULL, PV_NONE,
3062 {(char_u *)NULL, (char_u *)0L}
3063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003064 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3066#ifdef FEAT_WAK
3067 (char_u *)&p_wak, PV_NONE,
3068 {(char_u *)"menu", (char_u *)0L}
3069#else
3070 (char_u *)NULL, PV_NONE,
3071 {(char_u *)NULL, (char_u *)0L}
3072#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003073 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003075 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003076 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 {"winheight", "wh", P_NUM|P_VI_DEF,
3078#ifdef FEAT_WINDOWS
3079 (char_u *)&p_wh, PV_NONE,
3080#else
3081 (char_u *)NULL, PV_NONE,
3082#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003083 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003085#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 (char_u *)VAR_WIN, PV_WFH,
3087#else
3088 (char_u *)NULL, PV_NONE,
3089#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003090 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003091 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003092#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003093 (char_u *)VAR_WIN, PV_WFW,
3094#else
3095 (char_u *)NULL, PV_NONE,
3096#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"winminheight", "wmh", P_NUM|P_VI_DEF,
3099#ifdef FEAT_WINDOWS
3100 (char_u *)&p_wmh, PV_NONE,
3101#else
3102 (char_u *)NULL, PV_NONE,
3103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003104 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003106#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 (char_u *)&p_wmw, PV_NONE,
3108#else
3109 (char_u *)NULL, PV_NONE,
3110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003111 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003113#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 (char_u *)&p_wiw, PV_NONE,
3115#else
3116 (char_u *)NULL, PV_NONE,
3117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003118 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3120 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003121 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3123 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003124 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3126 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003127 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 {"write", NULL, P_BOOL|P_VI_DEF,
3129 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003130 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 {"writeany", "wa", P_BOOL|P_VI_DEF,
3132 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003133 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3135 (char_u *)&p_wb, PV_NONE,
3136 {
3137#ifdef FEAT_WRITEBACKUP
3138 (char_u *)TRUE,
3139#else
3140 (char_u *)FALSE,
3141#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003142 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 {"writedelay", "wd", P_NUM|P_VI_DEF,
3144 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003145 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146
3147/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003148#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003150 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151
3152 p_term("t_AB", T_CAB)
3153 p_term("t_AF", T_CAF)
3154 p_term("t_AL", T_CAL)
3155 p_term("t_al", T_AL)
3156 p_term("t_bc", T_BC)
3157 p_term("t_cd", T_CD)
3158 p_term("t_ce", T_CE)
3159 p_term("t_cl", T_CL)
3160 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003161 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_Co", T_CCO)
3163 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003164 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003166#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 p_term("t_CV", T_CSV)
3168#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_da", T_DA)
3170 p_term("t_db", T_DB)
3171 p_term("t_DL", T_CDL)
3172 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003173 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174 p_term("t_fs", T_FS)
3175 p_term("t_IE", T_CIE)
3176 p_term("t_IS", T_CIS)
3177 p_term("t_ke", T_KE)
3178 p_term("t_ks", T_KS)
3179 p_term("t_le", T_LE)
3180 p_term("t_mb", T_MB)
3181 p_term("t_md", T_MD)
3182 p_term("t_me", T_ME)
3183 p_term("t_mr", T_MR)
3184 p_term("t_ms", T_MS)
3185 p_term("t_nd", T_ND)
3186 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003187 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188 p_term("t_RI", T_CRI)
3189 p_term("t_RV", T_CRV)
3190 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003192 p_term("t_Sf", T_CSF)
3193 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003195 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 p_term("t_te", T_TE)
3198 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003199 p_term("t_ts", T_TS)
3200 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201 p_term("t_ue", T_UE)
3202 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003203 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204 p_term("t_vb", T_VB)
3205 p_term("t_ve", T_VE)
3206 p_term("t_vi", T_VI)
3207 p_term("t_vs", T_VS)
3208 p_term("t_WP", T_CWP)
Bram Moolenaar9f928862017-04-11 22:44:05 +02003209 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003211 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 p_term("t_xs", T_XS)
3213 p_term("t_ZH", T_CZH)
3214 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003215 p_term("t_8f", T_8F)
3216 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003217 p_term("t_BE", T_BE)
3218 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219
3220/* terminal key codes are not in here */
3221
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003222 /* end marker */
3223 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224};
3225
3226#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3227
3228#ifdef FEAT_MBYTE
3229static char *(p_ambw_values[]) = {"single", "double", NULL};
3230#endif
3231static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003232static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003234#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003235static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003236#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003237#ifdef FEAT_CMDL_COMPL
3238static char *(p_wop_values[]) = {"tagfile", NULL};
3239#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240#ifdef FEAT_WAK
3241static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3242#endif
3243static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3245static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247#ifdef FEAT_BROWSE
3248static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3249#endif
3250#ifdef FEAT_SCROLLBIND
3251static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3252#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003253static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003254#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3256#endif
3257#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003258# ifdef FEAT_AUTOCMD
3259static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3260# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003262# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3264#endif
3265static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3266#ifdef FEAT_FOLDING
3267static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003268# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003270# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003271 NULL};
3272static char *(p_fcl_values[]) = {"all", NULL};
3273#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003274#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003275static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003276#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003277#ifdef FEAT_SIGNS
3278static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3279#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003281static void set_option_default(int, int opt_flags, int compatible);
3282static void set_options_default(int opt_flags);
3283static char_u *term_bg_default(void);
3284static void did_set_option(int opt_idx, int opt_flags, int new_value);
3285static char_u *illegal_char(char_u *, int);
3286static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003288static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289#endif
3290#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003291static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static char_u *option_expand(int opt_idx, char_u *val);
3294static void didset_options(void);
3295static void didset_options2(void);
3296static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003297#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003298static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003299#else
3300# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3301#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003302static void set_string_option_global(int opt_idx, char_u **varp);
3303static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3304static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3305static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003306#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003307static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003308#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003310static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003312#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003313static char_u *did_set_spell_option(int is_spellfile);
3314static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003315#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003316#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003317static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003318#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003319static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3320static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3321static void check_redraw(long_u flags);
3322static int findoption(char_u *);
3323static int find_key_option(char_u *);
3324static void showoptions(int all, int opt_flags);
3325static int optval_default(struct vimoption *, char_u *varp);
3326static void showoneopt(struct vimoption *, int opt_flags);
3327static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3328static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3329static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3330static int istermoption(struct vimoption *);
3331static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3332static char_u *get_varp(struct vimoption *);
3333static void option_value2string(struct vimoption *, int opt_flags);
3334static void check_winopt(winopt_T *wop);
3335static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003337static void langmap_init(void);
3338static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003340static void paste_option_changed(void);
3341static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003343static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003345static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3346static int check_opt_strings(char_u *val, char **values, int);
3347static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003348#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003349static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351
3352/*
3353 * Initialize the options, first part.
3354 *
3355 * Called only once from main(), just after creating the first buffer.
3356 */
3357 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003358set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359{
3360 char_u *p;
3361 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003362 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363
3364#ifdef FEAT_LANGMAP
3365 langmap_init();
3366#endif
3367
3368 /* Be Vi compatible by default */
3369 p_cp = TRUE;
3370
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003371 /* Use POSIX compatibility when $VIM_POSIX is set. */
3372 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003373 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003374 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003375 set_string_default("shm", (char_u *)"A");
3376 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003377
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 /*
3379 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003380 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003382 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003383#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003384 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003386 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387# endif
3388#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003389 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390 set_string_default("sh", p);
3391
3392#ifdef FEAT_WILDIGN
3393 /*
3394 * Set the default for 'backupskip' to include environment variables for
3395 * temp files.
3396 */
3397 {
3398# ifdef UNIX
3399 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3400# else
3401 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3402# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003403 int len;
3404 garray_T ga;
3405 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406
3407 ga_init2(&ga, 1, 100);
3408 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3409 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003410 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411# ifdef UNIX
3412 if (*names[n] == NUL)
3413 p = (char_u *)"/tmp";
3414 else
3415# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003416 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417 if (p != NULL && *p != NUL)
3418 {
3419 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003420 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421 if (ga_grow(&ga, len) == OK)
3422 {
3423 if (ga.ga_len > 0)
3424 STRCAT(ga.ga_data, ",");
3425 STRCAT(ga.ga_data, p);
3426 add_pathsep(ga.ga_data);
3427 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428 ga.ga_len += len;
3429 }
3430 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003431 if (mustfree)
3432 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 }
3434 if (ga.ga_data != NULL)
3435 {
3436 set_string_default("bsk", ga.ga_data);
3437 vim_free(ga.ga_data);
3438 }
3439 }
3440#endif
3441
3442 /*
3443 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3444 */
3445 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003446 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003448#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3449 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3450#endif
3451 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003453 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003454 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003455#else
3456# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003457 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003458 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003460 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461# endif
3462#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003464 opt_idx = findoption((char_u *)"maxmem");
3465 if (opt_idx >= 0)
3466 {
3467#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003468 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3469 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003470#endif
3471 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3472 }
3473 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003474 }
3475
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476#ifdef FEAT_SEARCHPATH
3477 {
3478 char_u *cdpath;
3479 char_u *buf;
3480 int i;
3481 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003482 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483
3484 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003485 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486 if (cdpath != NULL)
3487 {
3488 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3489 if (buf != NULL)
3490 {
3491 buf[0] = ','; /* start with ",", current dir first */
3492 j = 1;
3493 for (i = 0; cdpath[i] != NUL; ++i)
3494 {
3495 if (vim_ispathlistsep(cdpath[i]))
3496 buf[j++] = ',';
3497 else
3498 {
3499 if (cdpath[i] == ' ' || cdpath[i] == ',')
3500 buf[j++] = '\\';
3501 buf[j++] = cdpath[i];
3502 }
3503 }
3504 buf[j] = NUL;
3505 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003506 if (opt_idx >= 0)
3507 {
3508 options[opt_idx].def_val[VI_DEFAULT] = buf;
3509 options[opt_idx].flags |= P_DEF_ALLOCED;
3510 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003511 else
3512 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003513 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003514 if (mustfree)
3515 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003516 }
3517 }
3518#endif
3519
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003520#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003521 /* Set print encoding on platforms that don't default to latin1 */
3522 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003523# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524 (char_u *)"cp1252"
3525# else
3526# ifdef VMS
3527 (char_u *)"dec-mcs"
3528# else
3529# ifdef EBCDIC
3530 (char_u *)"ebcdic-uk"
3531# else
3532# ifdef MAC
3533 (char_u *)"mac-roman"
3534# else /* HPUX */
3535 (char_u *)"hp-roman8"
3536# endif
3537# endif
3538# endif
3539# endif
3540 );
3541#endif
3542
3543#ifdef FEAT_POSTSCRIPT
3544 /* 'printexpr' must be allocated to be able to evaluate it. */
3545 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003546# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003547 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003548# else
3549# ifdef VMS
3550 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3551
3552# else
3553 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3554# endif
3555# endif
3556 );
3557#endif
3558
3559 /*
3560 * Set all the options (except the terminal options) to their default
3561 * value. Also set the global value for local options.
3562 */
3563 set_options_default(0);
3564
3565#ifdef FEAT_GUI
3566 if (found_reverse_arg)
3567 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3568#endif
3569
3570 curbuf->b_p_initialized = TRUE;
3571 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003572 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 check_buf_options(curbuf);
3574 check_win_options(curwin);
3575 check_options();
3576
3577 /* Must be before option_expand(), because that one needs vim_isIDc() */
3578 didset_options();
3579
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003580#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003581 /* Use the current chartab for the generic chartab. This is not in
3582 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003583 init_spell_chartab();
3584#endif
3585
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586 /*
3587 * Expand environment variables and things like "~" for the defaults.
3588 * If option_expand() returns non-NULL the variable is expanded. This can
3589 * only happen for non-indirect options.
3590 * Also set the default to the expanded value, so ":set" does not list
3591 * them.
3592 * Don't set the P_ALLOCED flag, because we don't want to free the
3593 * default.
3594 */
3595 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3596 {
3597 if ((options[opt_idx].flags & P_GETTEXT)
3598 && options[opt_idx].var != NULL)
3599 p = (char_u *)_(*(char **)options[opt_idx].var);
3600 else
3601 p = option_expand(opt_idx, NULL);
3602 if (p != NULL && (p = vim_strsave(p)) != NULL)
3603 {
3604 *(char_u **)options[opt_idx].var = p;
3605 /* VIMEXP
3606 * Defaults for all expanded options are currently the same for Vi
3607 * and Vim. When this changes, add some code here! Also need to
3608 * split P_DEF_ALLOCED in two.
3609 */
3610 if (options[opt_idx].flags & P_DEF_ALLOCED)
3611 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3612 options[opt_idx].def_val[VI_DEFAULT] = p;
3613 options[opt_idx].flags |= P_DEF_ALLOCED;
3614 }
3615 }
3616
Bram Moolenaar071d4272004-06-13 20:20:40 +00003617 save_file_ff(curbuf); /* Buffer is unchanged */
3618
Bram Moolenaar071d4272004-06-13 20:20:40 +00003619#if defined(FEAT_ARABIC)
3620 /* Detect use of mlterm.
3621 * Mlterm is a terminal emulator akin to xterm that has some special
3622 * abilities (bidi namely).
3623 * NOTE: mlterm's author is being asked to 'set' a variable
3624 * instead of an environment variable due to inheritance.
3625 */
3626 if (mch_getenv((char_u *)"MLTERM") != NULL)
3627 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3628#endif
3629
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003630 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003631
3632#ifdef FEAT_MBYTE
3633# if defined(WIN3264) && defined(FEAT_GETTEXT)
3634 /*
3635 * If $LANG isn't set, try to get a good value for it. This makes the
3636 * right language be used automatically. Don't do this for English.
3637 */
3638 if (mch_getenv((char_u *)"LANG") == NULL)
3639 {
3640 char buf[20];
3641
3642 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3643 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3644 * only the first two. */
3645 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3646 (LPTSTR)buf, 20);
3647 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3648 {
3649 /* There are a few exceptions (probably more) */
3650 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3651 STRCPY(buf, "zh_TW");
3652 else if (STRNICMP(buf, "chs", 3) == 0
3653 || STRNICMP(buf, "zhc", 3) == 0)
3654 STRCPY(buf, "zh_CN");
3655 else if (STRNICMP(buf, "jp", 2) == 0)
3656 STRCPY(buf, "ja");
3657 else
3658 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003659 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003660 }
3661 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003662# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003663# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003664 /* Moved to os_mac_conv.c to avoid dependency problems. */
3665 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003666# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003667# endif
3668
3669 /* enc_locale() will try to find the encoding of the current locale. */
3670 p = enc_locale();
3671 if (p != NULL)
3672 {
3673 char_u *save_enc;
3674
3675 /* Try setting 'encoding' and check if the value is valid.
3676 * If not, go back to the default "latin1". */
3677 save_enc = p_enc;
3678 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003679 if (STRCMP(p_enc, "gb18030") == 0)
3680 {
3681 /* We don't support "gb18030", but "cp936" is a good substitute
3682 * for practical purposes, thus use that. It's not an alias to
3683 * still support conversion between gb18030 and utf-8. */
3684 p_enc = vim_strsave((char_u *)"cp936");
3685 vim_free(p);
3686 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687 if (mb_init() == NULL)
3688 {
3689 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003690 if (opt_idx >= 0)
3691 {
3692 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3693 options[opt_idx].flags |= P_DEF_ALLOCED;
3694 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003696#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003697 if (STRCMP(p_enc, "latin1") == 0
3698# ifdef FEAT_MBYTE
3699 || enc_utf8
3700# endif
3701 )
3702 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003703 /* Adjust the default for 'isprint' and 'iskeyword' to match
3704 * latin1. Also set the defaults for when 'nocompatible' is
3705 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003706 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003707 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003708 set_string_option_direct((char_u *)"isk", -1,
3709 ISK_LATIN1, OPT_FREE, SID_NONE);
3710 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003711 if (opt_idx >= 0)
3712 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003713 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003714 if (opt_idx >= 0)
3715 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003716 (void)init_chartab();
3717 }
3718#endif
3719
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720# if defined(WIN3264) && !defined(FEAT_GUI)
3721 /* Win32 console: When GetACP() returns a different value from
3722 * GetConsoleCP() set 'termencoding'. */
3723 if (GetACP() != GetConsoleCP())
3724 {
3725 char buf[50];
3726
3727 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3728 p_tenc = vim_strsave((char_u *)buf);
3729 if (p_tenc != NULL)
3730 {
3731 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003732 if (opt_idx >= 0)
3733 {
3734 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3735 options[opt_idx].flags |= P_DEF_ALLOCED;
3736 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737 convert_setup(&input_conv, p_tenc, p_enc);
3738 convert_setup(&output_conv, p_enc, p_tenc);
3739 }
3740 else
3741 p_tenc = empty_option;
3742 }
3743# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003744# if defined(WIN3264) && defined(FEAT_MBYTE)
3745 /* $HOME may have characters in active code page. */
3746 init_homedir();
3747# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 }
3749 else
3750 {
3751 vim_free(p_enc);
3752 p_enc = save_enc;
3753 }
3754 }
3755#endif
3756
3757#ifdef FEAT_MULTI_LANG
3758 /* Set the default for 'helplang'. */
3759 set_helplang_default(get_mess_lang());
3760#endif
3761}
3762
3763/*
3764 * Set an option to its default value.
3765 * This does not take care of side effects!
3766 */
3767 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003768set_option_default(
3769 int opt_idx,
3770 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3771 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772{
3773 char_u *varp; /* pointer to variable for current option */
3774 int dvi; /* index in def_val[] */
3775 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003776 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3778
3779 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3780 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003781 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003782 {
3783 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3784 if (flags & P_STRING)
3785 {
3786 /* Use set_string_option_direct() for local options to handle
3787 * freeing and allocating the value. */
3788 if (options[opt_idx].indir != PV_NONE)
3789 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003790 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791 else
3792 {
3793 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3794 free_string_option(*(char_u **)(varp));
3795 *(char_u **)varp = options[opt_idx].def_val[dvi];
3796 options[opt_idx].flags &= ~P_ALLOCED;
3797 }
3798 }
3799 else if (flags & P_NUM)
3800 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003801 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802 win_comp_scroll(curwin);
3803 else
3804 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003805 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806 /* May also set global value for local option. */
3807 if (both)
3808 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3809 *(long *)varp;
3810 }
3811 }
3812 else /* P_BOOL */
3813 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003814 /* the cast to long is required for Manx C, long_i is needed for
3815 * MSVC */
3816 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003817#ifdef UNIX
3818 /* 'modeline' defaults to off for root */
3819 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3820 *(int *)varp = FALSE;
3821#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822 /* May also set global value for local option. */
3823 if (both)
3824 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3825 *(int *)varp;
3826 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003827
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003828 /* The default value is not insecure. */
3829 flagsp = insecure_flag(opt_idx, opt_flags);
3830 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831 }
3832
3833#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003834 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835#endif
3836}
3837
3838/*
3839 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003840 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841 */
3842 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003843set_options_default(
3844 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003845{
3846 int i;
3847#ifdef FEAT_WINDOWS
3848 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003849 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850#endif
3851
3852 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003853 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003854#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003855 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003856 || (TRUE
3857# if defined(FEAT_MBYTE)
3858 && options[i].var != (char_u *)&p_enc
3859# endif
3860# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003861 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003862 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003863# endif
3864 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003865#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003866 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867 set_option_default(i, opt_flags, p_cp);
3868
3869#ifdef FEAT_WINDOWS
3870 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003871 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872 win_comp_scroll(wp);
3873#else
3874 win_comp_scroll(curwin);
3875#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003876#ifdef FEAT_CINDENT
3877 parse_cino(curbuf);
3878#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879}
3880
3881/*
3882 * Set the Vi-default value of a string option.
3883 * Used for 'sh', 'backupskip' and 'term'.
3884 */
3885 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003886set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887{
3888 char_u *p;
3889 int opt_idx;
3890
3891 p = vim_strsave(val);
3892 if (p != NULL) /* we don't want a NULL */
3893 {
3894 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003895 if (opt_idx >= 0)
3896 {
3897 if (options[opt_idx].flags & P_DEF_ALLOCED)
3898 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3899 options[opt_idx].def_val[VI_DEFAULT] = p;
3900 options[opt_idx].flags |= P_DEF_ALLOCED;
3901 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902 }
3903}
3904
3905/*
3906 * Set the Vi-default value of a number option.
3907 * Used for 'lines' and 'columns'.
3908 */
3909 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003910set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003912 int opt_idx;
3913
3914 opt_idx = findoption((char_u *)name);
3915 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003916 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917}
3918
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003919#if defined(EXITFREE) || defined(PROTO)
3920/*
3921 * Free all options.
3922 */
3923 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003924free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003925{
3926 int i;
3927
3928 for (i = 0; !istermoption(&options[i]); i++)
3929 {
3930 if (options[i].indir == PV_NONE)
3931 {
3932 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003933 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003934 free_string_option(*(char_u **)options[i].var);
3935 if (options[i].flags & P_DEF_ALLOCED)
3936 free_string_option(options[i].def_val[VI_DEFAULT]);
3937 }
3938 else if (options[i].var != VAR_WIN
3939 && (options[i].flags & P_STRING))
3940 /* buffer-local option: free global value */
3941 free_string_option(*(char_u **)options[i].var);
3942 }
3943}
3944#endif
3945
3946
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947/*
3948 * Initialize the options, part two: After getting Rows and Columns and
3949 * setting 'term'.
3950 */
3951 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003952set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003953{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003954 int idx;
3955
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 /*
3957 * 'scroll' defaults to half the window height. Note that this default is
3958 * wrong when the window height changes.
3959 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003960 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003961 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003962 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003963 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 comp_col();
3965
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003966 /*
3967 * 'window' is only for backwards compatibility with Vi.
3968 * Default is Rows - 1.
3969 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003970 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003971 p_window = Rows - 1;
3972 set_number_default("window", Rows - 1);
3973
Bram Moolenaarf740b292006-02-16 22:11:02 +00003974 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003975#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003976 /*
3977 * If 'background' wasn't set by the user, try guessing the value,
3978 * depending on the terminal name. Only need to check for terminals
3979 * with a dark background, that can handle color.
3980 */
3981 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003982 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3983 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003985 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003986 /* don't mark it as set, when starting the GUI it may be
3987 * changed again */
3988 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989 }
3990#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003991
3992#ifdef CURSOR_SHAPE
3993 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3994#endif
3995#ifdef FEAT_MOUSESHAPE
3996 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3997#endif
3998#ifdef FEAT_PRINTER
3999 (void)parse_printoptions(); /* parse 'printoptions' default value */
4000#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004001}
4002
4003/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004004 * Return "dark" or "light" depending on the kind of terminal.
4005 * This is just guessing! Recognized are:
4006 * "linux" Linux console
4007 * "screen.linux" Linux console with screen
4008 * "cygwin" Cygwin shell
4009 * "putty" Putty program
4010 * We also check the COLORFGBG environment variable, which is set by
4011 * rxvt and derivatives. This variable contains either two or three
4012 * values separated by semicolons; we want the last value in either
4013 * case. If this value is 0-6 or 8, our background is dark.
4014 */
4015 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004016term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004017{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004018#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004019 /* DOS console nearly always black */
4020 return (char_u *)"dark";
4021#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004022 char_u *p;
4023
Bram Moolenaarf740b292006-02-16 22:11:02 +00004024 if (STRCMP(T_NAME, "linux") == 0
4025 || STRCMP(T_NAME, "screen.linux") == 0
4026 || STRCMP(T_NAME, "cygwin") == 0
4027 || STRCMP(T_NAME, "putty") == 0
4028 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4029 && (p = vim_strrchr(p, ';')) != NULL
4030 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4031 && p[2] == NUL))
4032 return (char_u *)"dark";
4033 return (char_u *)"light";
4034#endif
4035}
4036
4037/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 * Initialize the options, part three: After reading the .vimrc
4039 */
4040 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004041set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004042{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004043#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044/*
4045 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4046 * This is done after other initializations, where 'shell' might have been
4047 * set, but only if they have not been set before.
4048 */
4049 char_u *p;
4050 int idx_srr;
4051 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004052# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 int idx_sp;
4054 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004055# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056
4057 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004058 if (idx_srr < 0)
4059 do_srr = FALSE;
4060 else
4061 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004062# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004064 if (idx_sp < 0)
4065 do_sp = FALSE;
4066 else
4067 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004068# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004069 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 if (p != NULL)
4071 {
4072 /*
4073 * Default for p_sp is "| tee", for p_srr is ">".
4074 * For known shells it is changed here to include stderr.
4075 */
4076 if ( fnamecmp(p, "csh") == 0
4077 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004078# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 || fnamecmp(p, "csh.exe") == 0
4080 || fnamecmp(p, "tcsh.exe") == 0
4081# endif
4082 )
4083 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004084# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 if (do_sp)
4086 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004087# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004091# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4093 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004094# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 if (do_srr)
4096 {
4097 p_srr = (char_u *)">&";
4098 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4099 }
4100 }
4101 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004102 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 if ( fnamecmp(p, "sh") == 0
4104 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004105 || fnamecmp(p, "mksh") == 0
4106 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004108 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004110 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004111# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 || fnamecmp(p, "cmd") == 0
4113 || fnamecmp(p, "sh.exe") == 0
4114 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004115 || fnamecmp(p, "mksh.exe") == 0
4116 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004118 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 || fnamecmp(p, "bash.exe") == 0
4120 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004122 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004124# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 if (do_sp)
4126 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004127# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004129# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004131# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4133 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004134# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 if (do_srr)
4136 {
4137 p_srr = (char_u *)">%s 2>&1";
4138 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4139 }
4140 }
4141 vim_free(p);
4142 }
4143#endif
4144
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004145#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004147 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4148 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 * This is done after other initializations, where 'shell' might have been
4150 * set, but only if they have not been set before. Default for p_shcf is
4151 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004152 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004154 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 {
4156 int idx3;
4157
4158 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004159 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 {
4161 p_shcf = (char_u *)"-c";
4162 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4163 }
4164
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165 /* Somehow Win32 requires the quotes around the redirection too */
4166 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004167 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004168 {
4169 p_sxq = (char_u *)"\"";
4170 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4171 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004173 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4174 {
4175 int idx3;
4176
4177 /*
4178 * cmd.exe on Windows will strip the first and last double quote given
4179 * on the command line, e.g. most of the time things like:
4180 * cmd /c "my path/to/echo" "my args to echo"
4181 * become:
4182 * my path/to/echo" "my args to echo
4183 * when executed.
4184 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004185 * To avoid this, set shellxquote to surround the command in
4186 * parenthesis. This appears to make most commands work, without
4187 * breaking commands that worked previously, such as
4188 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004189 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004190 idx3 = findoption((char_u *)"sxq");
4191 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4192 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004193 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004194 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4195 }
4196
Bram Moolenaara64ba222012-02-12 23:23:31 +01004197 idx3 = findoption((char_u *)"shcf");
4198 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4199 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004200 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004201 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4202 }
4203 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004204#endif
4205
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004206 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004207 {
4208 int idx_ffs = findoption((char_u *)"ffs");
4209
4210 /* Apply the first entry of 'fileformats' to the initial buffer. */
4211 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4212 set_fileformat(default_fileformat(), OPT_LOCAL);
4213 }
4214
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215#ifdef FEAT_TITLE
4216 set_title_defaults();
4217#endif
4218}
4219
4220#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4221/*
4222 * When 'helplang' is still at its default value, set it to "lang".
4223 * Only the first two characters of "lang" are used.
4224 */
4225 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004226set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227{
4228 int idx;
4229
4230 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4231 return;
4232 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004233 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234 {
4235 if (options[idx].flags & P_ALLOCED)
4236 free_string_option(p_hlg);
4237 p_hlg = vim_strsave(lang);
4238 if (p_hlg == NULL)
4239 p_hlg = empty_option;
4240 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004241 {
4242 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4243 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4244 {
4245 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4246 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4247 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004248 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004249 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004250 options[idx].flags |= P_ALLOCED;
4251 }
4252}
4253#endif
4254
4255#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004256static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004257
4258 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004259gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260{
4261 if (gui_get_lightness(gui.back_pixel) < 127)
4262 return (char_u *)"dark";
4263 return (char_u *)"light";
4264}
4265
4266/*
4267 * Option initializations that can only be done after opening the GUI window.
4268 */
4269 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004270init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004271{
4272 /* Set the 'background' option according to the lightness of the
4273 * background color, unless the user has set it already. */
4274 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4275 {
4276 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4277 highlight_changed();
4278 }
4279}
4280#endif
4281
4282#ifdef FEAT_TITLE
4283/*
4284 * 'title' and 'icon' only default to true if they have not been set or reset
4285 * in .vimrc and we can read the old value.
4286 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4287 * they can be reset. This reduces startup time when using X on a remote
4288 * machine.
4289 */
4290 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004291set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004292{
4293 int idx1;
4294 long val;
4295
4296 /*
4297 * If GUI is (going to be) used, we can always set the window title and
4298 * icon name. Saves a bit of time, because the X11 display server does
4299 * not need to be contacted.
4300 */
4301 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004302 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303 {
4304#ifdef FEAT_GUI
4305 if (gui.starting || gui.in_use)
4306 val = TRUE;
4307 else
4308#endif
4309 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004310 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311 p_title = val;
4312 }
4313 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004314 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004315 {
4316#ifdef FEAT_GUI
4317 if (gui.starting || gui.in_use)
4318 val = TRUE;
4319 else
4320#endif
4321 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004322 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004323 p_icon = val;
4324 }
4325}
4326#endif
4327
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004328#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4329 static void
4330trigger_optionsset_string(
4331 int opt_idx,
4332 int opt_flags,
4333 char_u *oldval,
4334 char_u *newval)
4335{
4336 if (oldval != NULL && newval != NULL)
4337 {
4338 char_u buf_type[7];
4339
4340 sprintf((char *)buf_type, "%s",
4341 (opt_flags & OPT_LOCAL) ? "local" : "global");
4342 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4343 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4344 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4345 apply_autocmds(EVENT_OPTIONSET,
4346 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4347 reset_v_option_vars();
4348 }
4349 vim_free(oldval);
4350 vim_free(newval);
4351}
4352#endif
4353
Bram Moolenaar071d4272004-06-13 20:20:40 +00004354/*
4355 * Parse 'arg' for option settings.
4356 *
4357 * 'arg' may be IObuff, but only when no errors can be present and option
4358 * does not need to be expanded with option_expand().
4359 * "opt_flags":
4360 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004361 * OPT_GLOBAL for ":setglobal"
4362 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004363 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004364 * OPT_WINONLY to only set window-local options
4365 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004366 *
4367 * returns FAIL if an error is detected, OK otherwise
4368 */
4369 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004370do_set(
4371 char_u *arg, /* option string (may be written to!) */
4372 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004373{
4374 int opt_idx;
4375 char_u *errmsg;
4376 char_u errbuf[80];
4377 char_u *startarg;
4378 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4379 int nextchar; /* next non-white char after option name */
4380 int afterchar; /* character just after option name */
4381 int len;
4382 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004383 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004384 int key;
4385 long_u flags; /* flags for current option */
4386 char_u *varp = NULL; /* pointer to variable for current option */
4387 int did_show = FALSE; /* already showed one value */
4388 int adding; /* "opt+=arg" */
4389 int prepending; /* "opt^=arg" */
4390 int removing; /* "opt-=arg" */
4391 int cp_val = 0;
4392 char_u key_name[2];
4393
4394 if (*arg == NUL)
4395 {
4396 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004397 did_show = TRUE;
4398 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399 }
4400
4401 while (*arg != NUL) /* loop to process all options */
4402 {
4403 errmsg = NULL;
4404 startarg = arg; /* remember for error message */
4405
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004406 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4407 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 {
4409 /*
4410 * ":set all" show all options.
4411 * ":set all&" set all options to their default value.
4412 */
4413 arg += 3;
4414 if (*arg == '&')
4415 {
4416 ++arg;
4417 /* Only for :set command set global value of local options. */
4418 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004419 didset_options();
4420 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004421 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004422 }
4423 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004424 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004426 did_show = TRUE;
4427 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004428 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004429 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004430 {
4431 showoptions(2, opt_flags);
4432 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004433 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004434 arg += 7;
4435 }
4436 else
4437 {
4438 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004439 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004440 {
4441 prefix = 0;
4442 arg += 2;
4443 }
4444 else if (STRNCMP(arg, "inv", 3) == 0)
4445 {
4446 prefix = 2;
4447 arg += 3;
4448 }
4449
4450 /* find end of name */
4451 key = 0;
4452 if (*arg == '<')
4453 {
4454 nextchar = 0;
4455 opt_idx = -1;
4456 /* look out for <t_>;> */
4457 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4458 len = 5;
4459 else
4460 {
4461 len = 1;
4462 while (arg[len] != NUL && arg[len] != '>')
4463 ++len;
4464 }
4465 if (arg[len] != '>')
4466 {
4467 errmsg = e_invarg;
4468 goto skip;
4469 }
4470 arg[len] = NUL; /* put NUL after name */
4471 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4472 opt_idx = findoption(arg + 1);
4473 arg[len++] = '>'; /* restore '>' */
4474 if (opt_idx == -1)
4475 key = find_key_option(arg + 1);
4476 }
4477 else
4478 {
4479 len = 0;
4480 /*
4481 * The two characters after "t_" may not be alphanumeric.
4482 */
4483 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4484 len = 4;
4485 else
4486 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4487 ++len;
4488 nextchar = arg[len];
4489 arg[len] = NUL; /* put NUL after name */
4490 opt_idx = findoption(arg);
4491 arg[len] = nextchar; /* restore nextchar */
4492 if (opt_idx == -1)
4493 key = find_key_option(arg);
4494 }
4495
4496 /* remember character after option name */
4497 afterchar = arg[len];
4498
4499 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004500 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004501 ++len;
4502
4503 adding = FALSE;
4504 prepending = FALSE;
4505 removing = FALSE;
4506 if (arg[len] != NUL && arg[len + 1] == '=')
4507 {
4508 if (arg[len] == '+')
4509 {
4510 adding = TRUE; /* "+=" */
4511 ++len;
4512 }
4513 else if (arg[len] == '^')
4514 {
4515 prepending = TRUE; /* "^=" */
4516 ++len;
4517 }
4518 else if (arg[len] == '-')
4519 {
4520 removing = TRUE; /* "-=" */
4521 ++len;
4522 }
4523 }
4524 nextchar = arg[len];
4525
4526 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4527 {
4528 errmsg = (char_u *)N_("E518: Unknown option");
4529 goto skip;
4530 }
4531
4532 if (opt_idx >= 0)
4533 {
4534 if (options[opt_idx].var == NULL) /* hidden option: skip */
4535 {
4536 /* Only give an error message when requesting the value of
4537 * a hidden option, ignore setting it. */
4538 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4539 && (!(options[opt_idx].flags & P_BOOL)
4540 || nextchar == '?'))
4541 errmsg = (char_u *)N_("E519: Option not supported");
4542 goto skip;
4543 }
4544
4545 flags = options[opt_idx].flags;
4546 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4547 }
4548 else
4549 {
4550 flags = P_STRING;
4551 if (key < 0)
4552 {
4553 key_name[0] = KEY2TERMCAP0(key);
4554 key_name[1] = KEY2TERMCAP1(key);
4555 }
4556 else
4557 {
4558 key_name[0] = KS_KEY;
4559 key_name[1] = (key & 0xff);
4560 }
4561 }
4562
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004563 /* Skip all options that are not window-local (used when showing
4564 * an already loaded buffer in a window). */
4565 if ((opt_flags & OPT_WINONLY)
4566 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4567 goto skip;
4568
Bram Moolenaara3227e22006-03-08 21:32:40 +00004569 /* Skip all options that are window-local (used for :vimgrep). */
4570 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4571 && options[opt_idx].var == VAR_WIN)
4572 goto skip;
4573
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004574 /* Disallow changing some options from modelines. */
4575 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004576 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004577 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004578 {
4579 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4580 goto skip;
4581 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004582#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004583 /* In diff mode some options are overruled. This avoids that
4584 * 'foldmethod' becomes "marker" instead of "diff" and that
4585 * "wrap" gets set. */
4586 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004587 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004588 && (
4589#ifdef FEAT_FOLDING
4590 options[opt_idx].indir == PV_FDM ||
4591#endif
4592 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004593 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004594#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004595 }
4596
4597#ifdef HAVE_SANDBOX
4598 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004599 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004600 {
4601 errmsg = (char_u *)_(e_sandbox);
4602 goto skip;
4603 }
4604#endif
4605
4606 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4607 {
4608 arg += len;
4609 cp_val = p_cp;
4610 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4611 {
4612 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4613 {
4614 cp_val = FALSE;
4615 arg += 3;
4616 }
4617 else /* "opt&vi": set to Vi default */
4618 {
4619 cp_val = TRUE;
4620 arg += 2;
4621 }
4622 }
4623 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004624 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004625 {
4626 errmsg = e_trailing;
4627 goto skip;
4628 }
4629 }
4630
4631 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004632 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4633 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004634 */
4635 if (nextchar == '?'
4636 || (prefix == 1
4637 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4638 && !(flags & P_BOOL)))
4639 {
4640 /*
4641 * print value
4642 */
4643 if (did_show)
4644 msg_putchar('\n'); /* cursor below last one */
4645 else
4646 {
4647 gotocmdline(TRUE); /* cursor at status line */
4648 did_show = TRUE; /* remember that we did a line */
4649 }
4650 if (opt_idx >= 0)
4651 {
4652 showoneopt(&options[opt_idx], opt_flags);
4653#ifdef FEAT_EVAL
4654 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004655 {
4656 /* Mention where the option was last set. */
4657 if (varp == options[opt_idx].var)
4658 last_set_msg(options[opt_idx].scriptID);
4659 else if ((int)options[opt_idx].indir & PV_WIN)
4660 last_set_msg(curwin->w_p_scriptID[
4661 (int)options[opt_idx].indir & PV_MASK]);
4662 else if ((int)options[opt_idx].indir & PV_BUF)
4663 last_set_msg(curbuf->b_p_scriptID[
4664 (int)options[opt_idx].indir & PV_MASK]);
4665 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004666#endif
4667 }
4668 else
4669 {
4670 char_u *p;
4671
4672 p = find_termcode(key_name);
4673 if (p == NULL)
4674 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004675 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004676 goto skip;
4677 }
4678 else
4679 (void)show_one_termcode(key_name, p, TRUE);
4680 }
4681 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004682 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004683 errmsg = e_trailing;
4684 }
4685 else
4686 {
4687 if (flags & P_BOOL) /* boolean */
4688 {
4689 if (nextchar == '=' || nextchar == ':')
4690 {
4691 errmsg = e_invarg;
4692 goto skip;
4693 }
4694
4695 /*
4696 * ":set opt!": invert
4697 * ":set opt&": reset to default value
4698 * ":set opt<": reset to global value
4699 */
4700 if (nextchar == '!')
4701 value = *(int *)(varp) ^ 1;
4702 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004703 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004704 ((flags & P_VI_DEF) || cp_val)
4705 ? VI_DEFAULT : VIM_DEFAULT];
4706 else if (nextchar == '<')
4707 {
4708 /* For 'autoread' -1 means to use global value. */
4709 if ((int *)varp == &curbuf->b_p_ar
4710 && opt_flags == OPT_LOCAL)
4711 value = -1;
4712 else
4713 value = *(int *)get_varp_scope(&(options[opt_idx]),
4714 OPT_GLOBAL);
4715 }
4716 else
4717 {
4718 /*
4719 * ":set invopt": invert
4720 * ":set opt" or ":set noopt": set or reset
4721 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004722 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004723 {
4724 errmsg = e_trailing;
4725 goto skip;
4726 }
4727 if (prefix == 2) /* inv */
4728 value = *(int *)(varp) ^ 1;
4729 else
4730 value = prefix;
4731 }
4732
4733 errmsg = set_bool_option(opt_idx, varp, (int)value,
4734 opt_flags);
4735 }
4736 else /* numeric or string */
4737 {
4738 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4739 || prefix != 1)
4740 {
4741 errmsg = e_invarg;
4742 goto skip;
4743 }
4744
4745 if (flags & P_NUM) /* numeric */
4746 {
4747 /*
4748 * Different ways to set a number option:
4749 * & set to default value
4750 * < set to global value
4751 * <xx> accept special key codes for 'wildchar'
4752 * c accept any non-digit for 'wildchar'
4753 * [-]0-9 set number
4754 * other error
4755 */
4756 ++arg;
4757 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004758 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 ((flags & P_VI_DEF) || cp_val)
4760 ? VI_DEFAULT : VIM_DEFAULT];
4761 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004762 {
4763 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4764 * use the global value. */
4765 if ((long *)varp == &curbuf->b_p_ul
4766 && opt_flags == OPT_LOCAL)
4767 value = NO_LOCAL_UNDOLEVEL;
4768 else
4769 value = *(long *)get_varp_scope(
4770 &(options[opt_idx]), OPT_GLOBAL);
4771 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004772 else if (((long *)varp == &p_wc
4773 || (long *)varp == &p_wcm)
4774 && (*arg == '<'
4775 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004776 || (*arg != NUL
4777 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004778 && !VIM_ISDIGIT(*arg))))
4779 {
4780 value = string_to_key(arg);
4781 if (value == 0 && (long *)varp != &p_wcm)
4782 {
4783 errmsg = e_invarg;
4784 goto skip;
4785 }
4786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004787 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4788 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004789 /* Allow negative (for 'undolevels'), octal and
4790 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004791 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4792 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004793 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004794 {
4795 errmsg = e_invarg;
4796 goto skip;
4797 }
4798 }
4799 else
4800 {
4801 errmsg = (char_u *)N_("E521: Number required after =");
4802 goto skip;
4803 }
4804
4805 if (adding)
4806 value = *(long *)varp + value;
4807 if (prepending)
4808 value = *(long *)varp * value;
4809 if (removing)
4810 value = *(long *)varp - value;
4811 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004812 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004813 }
4814 else if (opt_idx >= 0) /* string */
4815 {
4816 char_u *save_arg = NULL;
4817 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004818 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004819 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004820 char_u *origval = NULL;
4821#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4822 char_u *saved_origval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004823 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004825 unsigned newlen;
4826 int comma;
4827 int bs;
4828 int new_value_alloced; /* new string option
4829 was allocated */
4830
4831 /* When using ":set opt=val" for a global option
4832 * with a local value the local value will be
4833 * reset, use the global value here. */
4834 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004835 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004836 varp = options[opt_idx].var;
4837
4838 /* The old value is kept until we are sure that the
4839 * new value is valid. */
4840 oldval = *(char_u **)varp;
4841 if (nextchar == '&') /* set to default val */
4842 {
4843 newval = options[opt_idx].def_val[
4844 ((flags & P_VI_DEF) || cp_val)
4845 ? VI_DEFAULT : VIM_DEFAULT];
4846 if ((char_u **)varp == &p_bg)
4847 {
4848 /* guess the value of 'background' */
4849#ifdef FEAT_GUI
4850 if (gui.in_use)
4851 newval = gui_bg_default();
4852 else
4853#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004854 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004855 }
4856
4857 /* expand environment variables and ~ (since the
4858 * default value was already expanded, only
4859 * required when an environment variable was set
4860 * later */
4861 if (newval == NULL)
4862 newval = empty_option;
4863 else
4864 {
4865 s = option_expand(opt_idx, newval);
4866 if (s == NULL)
4867 s = newval;
4868 newval = vim_strsave(s);
4869 }
4870 new_value_alloced = TRUE;
4871 }
4872 else if (nextchar == '<') /* set to global val */
4873 {
4874 newval = vim_strsave(*(char_u **)get_varp_scope(
4875 &(options[opt_idx]), OPT_GLOBAL));
4876 new_value_alloced = TRUE;
4877 }
4878 else
4879 {
4880 ++arg; /* jump to after the '=' or ':' */
4881
4882 /*
4883 * Set 'keywordprg' to ":help" if an empty
4884 * value was passed to :set by the user.
4885 * Misuse errbuf[] for the resulting string.
4886 */
4887 if (varp == (char_u *)&p_kp
4888 && (*arg == NUL || *arg == ' '))
4889 {
4890 STRCPY(errbuf, ":help");
4891 save_arg = arg;
4892 arg = errbuf;
4893 }
4894 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004895 * Convert 'backspace' number to string, for
4896 * adding, prepending and removing string.
4897 */
4898 else if (varp == (char_u *)&p_bs
4899 && VIM_ISDIGIT(**(char_u **)varp))
4900 {
4901 i = getdigits((char_u **)varp);
4902 switch (i)
4903 {
4904 case 0:
4905 *(char_u **)varp = empty_option;
4906 break;
4907 case 1:
4908 *(char_u **)varp = vim_strsave(
4909 (char_u *)"indent,eol");
4910 break;
4911 case 2:
4912 *(char_u **)varp = vim_strsave(
4913 (char_u *)"indent,eol,start");
4914 break;
4915 }
4916 vim_free(oldval);
4917 oldval = *(char_u **)varp;
4918 }
4919 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004920 * Convert 'whichwrap' number to string, for
4921 * backwards compatibility with Vim 3.0.
4922 * Misuse errbuf[] for the resulting string.
4923 */
4924 else if (varp == (char_u *)&p_ww
4925 && VIM_ISDIGIT(*arg))
4926 {
4927 *errbuf = NUL;
4928 i = getdigits(&arg);
4929 if (i & 1)
4930 STRCAT(errbuf, "b,");
4931 if (i & 2)
4932 STRCAT(errbuf, "s,");
4933 if (i & 4)
4934 STRCAT(errbuf, "h,l,");
4935 if (i & 8)
4936 STRCAT(errbuf, "<,>,");
4937 if (i & 16)
4938 STRCAT(errbuf, "[,],");
4939 if (*errbuf != NUL) /* remove trailing , */
4940 errbuf[STRLEN(errbuf) - 1] = NUL;
4941 save_arg = arg;
4942 arg = errbuf;
4943 }
4944 /*
4945 * Remove '>' before 'dir' and 'bdir', for
4946 * backwards compatibility with version 3.0
4947 */
4948 else if ( *arg == '>'
4949 && (varp == (char_u *)&p_dir
4950 || varp == (char_u *)&p_bdir))
4951 {
4952 ++arg;
4953 }
4954
4955 /* When setting the local value of a global
4956 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004957 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004958 && (opt_flags & OPT_LOCAL))
4959 origval = *(char_u **)get_varp(
4960 &options[opt_idx]);
4961 else
4962 origval = oldval;
4963
4964 /*
4965 * Copy the new string into allocated memory.
4966 * Can't use set_string_option_direct(), because
4967 * we need to remove the backslashes.
4968 */
4969 /* get a bit too much */
4970 newlen = (unsigned)STRLEN(arg) + 1;
4971 if (adding || prepending || removing)
4972 newlen += (unsigned)STRLEN(origval) + 1;
4973 newval = alloc(newlen);
4974 if (newval == NULL) /* out of mem, don't change */
4975 break;
4976 s = newval;
4977
4978 /*
4979 * Copy the string, skip over escaped chars.
4980 * For MS-DOS and WIN32 backslashes before normal
4981 * file name characters are not removed, and keep
4982 * backslash at start, for "\\machine\path", but
4983 * do remove it for "\\\\machine\\path".
4984 * The reverse is found in ExpandOldSetting().
4985 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004986 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004987 {
4988 if (*arg == '\\' && arg[1] != NUL
4989#ifdef BACKSLASH_IN_FILENAME
4990 && !((flags & P_EXPAND)
4991 && vim_isfilec(arg[1])
4992 && (arg[1] != '\\'
4993 || (s == newval
4994 && arg[2] != '\\')))
4995#endif
4996 )
4997 ++arg; /* remove backslash */
4998#ifdef FEAT_MBYTE
4999 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005000 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005001 {
5002 /* copy multibyte char */
5003 mch_memmove(s, arg, (size_t)i);
5004 arg += i;
5005 s += i;
5006 }
5007 else
5008#endif
5009 *s++ = *arg++;
5010 }
5011 *s = NUL;
5012
5013 /*
5014 * Expand environment variables and ~.
5015 * Don't do it when adding without inserting a
5016 * comma.
5017 */
5018 if (!(adding || prepending || removing)
5019 || (flags & P_COMMA))
5020 {
5021 s = option_expand(opt_idx, newval);
5022 if (s != NULL)
5023 {
5024 vim_free(newval);
5025 newlen = (unsigned)STRLEN(s) + 1;
5026 if (adding || prepending || removing)
5027 newlen += (unsigned)STRLEN(origval) + 1;
5028 newval = alloc(newlen);
5029 if (newval == NULL)
5030 break;
5031 STRCPY(newval, s);
5032 }
5033 }
5034
5035 /* locate newval[] in origval[] when removing it
5036 * and when adding to avoid duplicates */
5037 i = 0; /* init for GCC */
5038 if (removing || (flags & P_NODUP))
5039 {
5040 i = (int)STRLEN(newval);
5041 bs = 0;
5042 for (s = origval; *s; ++s)
5043 {
5044 if ((!(flags & P_COMMA)
5045 || s == origval
5046 || (s[-1] == ',' && !(bs & 1)))
5047 && STRNCMP(s, newval, i) == 0
5048 && (!(flags & P_COMMA)
5049 || s[i] == ','
5050 || s[i] == NUL))
5051 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005052 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005053 * even number of backslashes or a single
5054 * backslash preceded by a comma before it
5055 * is recognized as a separator */
5056 if ((s > origval + 1
5057 && s[-1] == '\\'
5058 && s[-2] != ',')
5059 || (s == origval + 1
5060 && s[-1] == '\\'))
5061
Bram Moolenaar071d4272004-06-13 20:20:40 +00005062 ++bs;
5063 else
5064 bs = 0;
5065 }
5066
5067 /* do not add if already there */
5068 if ((adding || prepending) && *s)
5069 {
5070 prepending = FALSE;
5071 adding = FALSE;
5072 STRCPY(newval, origval);
5073 }
5074 }
5075
5076 /* concatenate the two strings; add a ',' if
5077 * needed */
5078 if (adding || prepending)
5079 {
5080 comma = ((flags & P_COMMA) && *origval != NUL
5081 && *newval != NUL);
5082 if (adding)
5083 {
5084 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005085 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005086 if (comma && i > 1
5087 && (flags & P_ONECOMMA) == P_ONECOMMA
5088 && origval[i - 1] == ','
5089 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005090 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005091 mch_memmove(newval + i + comma, newval,
5092 STRLEN(newval) + 1);
5093 mch_memmove(newval, origval, (size_t)i);
5094 }
5095 else
5096 {
5097 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005098 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005099 }
5100 if (comma)
5101 newval[i] = ',';
5102 }
5103
5104 /* Remove newval[] from origval[]. (Note: "i" has
5105 * been set above and is used here). */
5106 if (removing)
5107 {
5108 STRCPY(newval, origval);
5109 if (*s)
5110 {
5111 /* may need to remove a comma */
5112 if (flags & P_COMMA)
5113 {
5114 if (s == origval)
5115 {
5116 /* include comma after string */
5117 if (s[i] == ',')
5118 ++i;
5119 }
5120 else
5121 {
5122 /* include comma before string */
5123 --s;
5124 ++i;
5125 }
5126 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005127 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005128 }
5129 }
5130
5131 if (flags & P_FLAGLIST)
5132 {
5133 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005134 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005135 {
5136 /* if options have P_FLAGLIST and
5137 * P_ONECOMMA such as 'whichwrap' */
5138 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005139 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005140 if (*s != ',' && *(s + 1) == ','
5141 && vim_strchr(s + 2, *s) != NULL)
5142 {
5143 /* Remove the duplicated value and
5144 * the next comma. */
5145 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005146 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005147 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005148 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005149 else
5150 {
5151 if ((!(flags & P_COMMA) || *s != ',')
5152 && vim_strchr(s + 1, *s) != NULL)
5153 {
5154 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005155 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005156 }
5157 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005158 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005159 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005160 }
5161
5162 if (save_arg != NULL) /* number for 'whichwrap' */
5163 arg = save_arg;
5164 new_value_alloced = TRUE;
5165 }
5166
5167 /* Set the new value. */
5168 *(char_u **)(varp) = newval;
5169
Bram Moolenaar53744302015-07-17 17:38:22 +02005170#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005171 if (!starting
5172# ifdef FEAT_CRYPT
5173 && options[opt_idx].indir != PV_KEY
5174# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005175 && origval != NULL && newval != NULL)
5176 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005177 /* origval may be freed by
5178 * did_set_string_option(), make a copy. */
5179 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005180 /* newval (and varp) may become invalid if the
5181 * buffer is closed by autocommands. */
5182 saved_newval = vim_strsave(newval);
5183 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005184#endif
5185
Bram Moolenaar071d4272004-06-13 20:20:40 +00005186 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005187 * ":set" on local options. Note: when setting 'syntax'
5188 * or 'filetype' autocommands may be triggered that can
5189 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005190 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5191 new_value_alloced, oldval, errbuf, opt_flags);
5192
5193 /* If error detected, print the error message. */
5194 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005195 {
5196#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5197 vim_free(saved_origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005198 vim_free(saved_newval);
Bram Moolenaara9884962015-12-13 15:08:56 +01005199#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005200 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005201 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005202#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005203 trigger_optionsset_string(opt_idx, opt_flags,
5204 saved_origval, saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005206 }
5207 else /* key code option */
5208 {
5209 char_u *p;
5210
5211 if (nextchar == '&')
5212 {
5213 if (add_termcap_entry(key_name, TRUE) == FAIL)
5214 errmsg = (char_u *)N_("E522: Not found in termcap");
5215 }
5216 else
5217 {
5218 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005219 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005220 if (*p == '\\' && p[1] != NUL)
5221 ++p;
5222 nextchar = *p;
5223 *p = NUL;
5224 add_termcode(key_name, arg, FALSE);
5225 *p = nextchar;
5226 }
5227 if (full_screen)
5228 ttest(FALSE);
5229 redraw_all_later(CLEAR);
5230 }
5231 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005232
Bram Moolenaar071d4272004-06-13 20:20:40 +00005233 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005234 did_set_option(opt_idx, opt_flags,
5235 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005236 }
5237
5238skip:
5239 /*
5240 * Advance to next argument.
5241 * - skip until a blank found, taking care of backslashes
5242 * - skip blanks
5243 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5244 */
5245 for (i = 0; i < 2 ; ++i)
5246 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005247 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005248 if (*arg++ == '\\' && *arg != NUL)
5249 ++arg;
5250 arg = skipwhite(arg);
5251 if (*arg != '=')
5252 break;
5253 }
5254 }
5255
5256 if (errmsg != NULL)
5257 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005258 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005259 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005260 if (i + (arg - startarg) < IOSIZE)
5261 {
5262 /* append the argument with the error */
5263 STRCAT(IObuff, ": ");
5264 mch_memmove(IObuff + i, startarg, (arg - startarg));
5265 IObuff[i + (arg - startarg)] = NUL;
5266 }
5267 /* make sure all characters are printable */
5268 trans_characters(IObuff, IOSIZE);
5269
5270 ++no_wait_return; /* wait_return done later */
5271 emsg(IObuff); /* show error highlighted */
5272 --no_wait_return;
5273
5274 return FAIL;
5275 }
5276
5277 arg = skipwhite(arg);
5278 }
5279
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005280theend:
5281 if (silent_mode && did_show)
5282 {
5283 /* After displaying option values in silent mode. */
5284 silent_mode = FALSE;
5285 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5286 msg_putchar('\n');
5287 cursor_on(); /* msg_start() switches it off */
5288 out_flush();
5289 silent_mode = TRUE;
5290 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5291 }
5292
Bram Moolenaar071d4272004-06-13 20:20:40 +00005293 return OK;
5294}
5295
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005296/*
5297 * Call this when an option has been given a new value through a user command.
5298 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5299 */
5300 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005301did_set_option(
5302 int opt_idx,
5303 int opt_flags, /* possibly with OPT_MODELINE */
5304 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005305{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005306 long_u *p;
5307
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005308 options[opt_idx].flags |= P_WAS_SET;
5309
5310 /* When an option is set in the sandbox, from a modeline or in secure mode
5311 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005312 * flag. */
5313 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005314 if (secure
5315#ifdef HAVE_SANDBOX
5316 || sandbox != 0
5317#endif
5318 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005319 *p = *p | P_INSECURE;
5320 else if (new_value)
5321 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005322}
5323
Bram Moolenaar071d4272004-06-13 20:20:40 +00005324 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005325illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326{
5327 if (errbuf == NULL)
5328 return (char_u *)"";
5329 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005330 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005331 return errbuf;
5332}
5333
5334/*
5335 * Convert a key name or string into a key value.
5336 * Used for 'wildchar' and 'cedit' options.
5337 */
5338 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005339string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005340{
5341 if (*arg == '<')
5342 return find_key_option(arg + 1);
5343 if (*arg == '^')
5344 return Ctrl_chr(arg[1]);
5345 return *arg;
5346}
5347
5348#ifdef FEAT_CMDWIN
5349/*
5350 * Check value of 'cedit' and set cedit_key.
5351 * Returns NULL if value is OK, error message otherwise.
5352 */
5353 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005354check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355{
5356 int n;
5357
5358 if (*p_cedit == NUL)
5359 cedit_key = -1;
5360 else
5361 {
5362 n = string_to_key(p_cedit);
5363 if (vim_isprintc(n))
5364 return e_invarg;
5365 cedit_key = n;
5366 }
5367 return NULL;
5368}
5369#endif
5370
5371#ifdef FEAT_TITLE
5372/*
5373 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5374 * maketitle() to create and display it.
5375 * When switching the title or icon off, call mch_restore_title() to get
5376 * the old value back.
5377 */
5378 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005379did_set_title(
5380 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005381{
5382 if (starting != NO_SCREEN
5383#ifdef FEAT_GUI
5384 && !gui.starting
5385#endif
5386 )
5387 {
5388 maketitle();
5389 if (icon)
5390 {
5391 if (!p_icon)
5392 mch_restore_title(2);
5393 }
5394 else
5395 {
5396 if (!p_title)
5397 mch_restore_title(1);
5398 }
5399 }
5400}
5401#endif
5402
5403/*
5404 * set_options_bin - called when 'bin' changes value.
5405 */
5406 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005407set_options_bin(
5408 int oldval,
5409 int newval,
5410 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005411{
5412 /*
5413 * The option values that are changed when 'bin' changes are
5414 * copied when 'bin is set and restored when 'bin' is reset.
5415 */
5416 if (newval)
5417 {
5418 if (!oldval) /* switched on */
5419 {
5420 if (!(opt_flags & OPT_GLOBAL))
5421 {
5422 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5423 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5424 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5425 curbuf->b_p_et_nobin = curbuf->b_p_et;
5426 }
5427 if (!(opt_flags & OPT_LOCAL))
5428 {
5429 p_tw_nobin = p_tw;
5430 p_wm_nobin = p_wm;
5431 p_ml_nobin = p_ml;
5432 p_et_nobin = p_et;
5433 }
5434 }
5435
5436 if (!(opt_flags & OPT_GLOBAL))
5437 {
5438 curbuf->b_p_tw = 0; /* no automatic line wrap */
5439 curbuf->b_p_wm = 0; /* no automatic line wrap */
5440 curbuf->b_p_ml = 0; /* no modelines */
5441 curbuf->b_p_et = 0; /* no expandtab */
5442 }
5443 if (!(opt_flags & OPT_LOCAL))
5444 {
5445 p_tw = 0;
5446 p_wm = 0;
5447 p_ml = FALSE;
5448 p_et = FALSE;
5449 p_bin = TRUE; /* needed when called for the "-b" argument */
5450 }
5451 }
5452 else if (oldval) /* switched off */
5453 {
5454 if (!(opt_flags & OPT_GLOBAL))
5455 {
5456 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5457 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5458 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5459 curbuf->b_p_et = curbuf->b_p_et_nobin;
5460 }
5461 if (!(opt_flags & OPT_LOCAL))
5462 {
5463 p_tw = p_tw_nobin;
5464 p_wm = p_wm_nobin;
5465 p_ml = p_ml_nobin;
5466 p_et = p_et_nobin;
5467 }
5468 }
5469}
5470
5471#ifdef FEAT_VIMINFO
5472/*
5473 * Find the parameter represented by the given character (eg ', :, ", or /),
5474 * and return its associated value in the 'viminfo' string.
5475 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005476 * If the parameter is not specified in the string or there is no following
5477 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478 */
5479 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005480get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005481{
5482 char_u *p;
5483
5484 p = find_viminfo_parameter(type);
5485 if (p != NULL && VIM_ISDIGIT(*p))
5486 return atoi((char *)p);
5487 return -1;
5488}
5489
5490/*
5491 * Find the parameter represented by the given character (eg ''', ':', '"', or
5492 * '/') in the 'viminfo' option and return a pointer to the string after it.
5493 * Return NULL if the parameter is not specified in the string.
5494 */
5495 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005496find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005497{
5498 char_u *p;
5499
5500 for (p = p_viminfo; *p; ++p)
5501 {
5502 if (*p == type)
5503 return p + 1;
5504 if (*p == 'n') /* 'n' is always the last one */
5505 break;
5506 p = vim_strchr(p, ','); /* skip until next ',' */
5507 if (p == NULL) /* hit the end without finding parameter */
5508 break;
5509 }
5510 return NULL;
5511}
5512#endif
5513
5514/*
5515 * Expand environment variables for some string options.
5516 * These string options cannot be indirect!
5517 * If "val" is NULL expand the current value of the option.
5518 * Return pointer to NameBuff, or NULL when not expanded.
5519 */
5520 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005521option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522{
5523 /* if option doesn't need expansion nothing to do */
5524 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5525 return NULL;
5526
5527 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5528 * expand_env() would truncate the string. */
5529 if (val != NULL && STRLEN(val) > MAXPATHL)
5530 return NULL;
5531
5532 if (val == NULL)
5533 val = *(char_u **)options[opt_idx].var;
5534
5535 /*
5536 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5537 * Escape spaces when expanding 'tags', they are used to separate file
5538 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005539 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540 */
5541 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005542 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005543#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005544 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5545#endif
5546 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5548 return NULL;
5549
5550 return NameBuff;
5551}
5552
5553/*
5554 * After setting various option values: recompute variables that depend on
5555 * option values.
5556 */
5557 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005558didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559{
5560 /* initialize the table for 'iskeyword' et.al. */
5561 (void)init_chartab();
5562
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005563#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005565#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005567 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568#ifdef FEAT_SESSION
5569 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5570 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5571#endif
5572#ifdef FEAT_FOLDING
5573 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5574#endif
5575 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005576 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577#ifdef FEAT_VIRTUALEDIT
5578 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5579#endif
5580#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5581 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5582#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005583#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005584 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005585 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005586 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005587 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5590 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5591#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005592#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005593 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5594#endif
5595#ifdef FEAT_CMDWIN
5596 /* set cedit_key */
5597 (void)check_cedit();
5598#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005599#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005600 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005601#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005602#ifdef FEAT_LINEBREAK
5603 /* initialize the table for 'breakat'. */
5604 fill_breakat_flags();
5605#endif
5606
5607}
5608
5609/*
5610 * More side effects of setting options.
5611 */
5612 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005613didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005614{
5615 /* Initialize the highlight_attr[] table. */
5616 (void)highlight_changed();
5617
5618 /* Parse default for 'wildmode' */
5619 check_opt_wim();
5620
5621 (void)set_chars_option(&p_lcs);
5622#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5623 /* Parse default for 'fillchars'. */
5624 (void)set_chars_option(&p_fcs);
5625#endif
5626
5627#ifdef FEAT_CLIPBOARD
5628 /* Parse default for 'clipboard' */
5629 (void)check_clipboard_option();
5630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005631}
5632
5633/*
5634 * Check for string options that are NULL (normally only termcap options).
5635 */
5636 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005637check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638{
5639 int opt_idx;
5640
5641 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5642 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5643 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5644}
5645
5646/*
5647 * Check string options in a buffer for NULL value.
5648 */
5649 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005650check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005651{
5652#if defined(FEAT_QUICKFIX)
5653 check_string_option(&buf->b_p_bh);
5654 check_string_option(&buf->b_p_bt);
5655#endif
5656#ifdef FEAT_MBYTE
5657 check_string_option(&buf->b_p_fenc);
5658#endif
5659 check_string_option(&buf->b_p_ff);
5660#ifdef FEAT_FIND_ID
5661 check_string_option(&buf->b_p_def);
5662 check_string_option(&buf->b_p_inc);
5663# ifdef FEAT_EVAL
5664 check_string_option(&buf->b_p_inex);
5665# endif
5666#endif
5667#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5668 check_string_option(&buf->b_p_inde);
5669 check_string_option(&buf->b_p_indk);
5670#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005671#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5672 check_string_option(&buf->b_p_bexpr);
5673#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005674#if defined(FEAT_CRYPT)
5675 check_string_option(&buf->b_p_cm);
5676#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005677 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005678#if defined(FEAT_EVAL)
5679 check_string_option(&buf->b_p_fex);
5680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681#ifdef FEAT_CRYPT
5682 check_string_option(&buf->b_p_key);
5683#endif
5684 check_string_option(&buf->b_p_kp);
5685 check_string_option(&buf->b_p_mps);
5686 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005687 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005688 check_string_option(&buf->b_p_isk);
5689#ifdef FEAT_COMMENTS
5690 check_string_option(&buf->b_p_com);
5691#endif
5692#ifdef FEAT_FOLDING
5693 check_string_option(&buf->b_p_cms);
5694#endif
5695 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005696#ifdef FEAT_TEXTOBJ
5697 check_string_option(&buf->b_p_qe);
5698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699#ifdef FEAT_SYN_HL
5700 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005701 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005702#endif
5703#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005704 check_string_option(&buf->b_s.b_p_spc);
5705 check_string_option(&buf->b_s.b_p_spf);
5706 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707#endif
5708#ifdef FEAT_SEARCHPATH
5709 check_string_option(&buf->b_p_sua);
5710#endif
5711#ifdef FEAT_CINDENT
5712 check_string_option(&buf->b_p_cink);
5713 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005714 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715#endif
5716#ifdef FEAT_AUTOCMD
5717 check_string_option(&buf->b_p_ft);
5718#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5720 check_string_option(&buf->b_p_cinw);
5721#endif
5722#ifdef FEAT_INS_EXPAND
5723 check_string_option(&buf->b_p_cpt);
5724#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005725#ifdef FEAT_COMPL_FUNC
5726 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005727 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005729#ifdef FEAT_KEYMAP
5730 check_string_option(&buf->b_p_keymap);
5731#endif
5732#ifdef FEAT_QUICKFIX
5733 check_string_option(&buf->b_p_gp);
5734 check_string_option(&buf->b_p_mp);
5735 check_string_option(&buf->b_p_efm);
5736#endif
5737 check_string_option(&buf->b_p_ep);
5738 check_string_option(&buf->b_p_path);
5739 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005740 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005741#ifdef FEAT_INS_EXPAND
5742 check_string_option(&buf->b_p_dict);
5743 check_string_option(&buf->b_p_tsr);
5744#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005745#ifdef FEAT_LISP
5746 check_string_option(&buf->b_p_lw);
5747#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005748 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005749#ifdef FEAT_MBYTE
5750 check_string_option(&buf->b_p_menc);
5751#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005752}
5753
5754/*
5755 * Free the string allocated for an option.
5756 * Checks for the string being empty_option. This may happen if we're out of
5757 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5758 * check_options().
5759 * Does NOT check for P_ALLOCED flag!
5760 */
5761 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005762free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005763{
5764 if (p != empty_option)
5765 vim_free(p);
5766}
5767
5768 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005769clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005770{
5771 if (*pp != empty_option)
5772 vim_free(*pp);
5773 *pp = empty_option;
5774}
5775
5776 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005777check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005778{
5779 if (*pp == NULL)
5780 *pp = empty_option;
5781}
5782
5783/*
5784 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5785 */
5786 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005787set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005788{
5789 int opt_idx;
5790
5791 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5792 if (options[opt_idx].var == (char_u *)p)
5793 {
5794 options[opt_idx].flags |= P_ALLOCED;
5795 return;
5796 }
5797 return; /* cannot happen: didn't find it! */
5798}
5799
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005800#if defined(FEAT_EVAL) || defined(PROTO)
5801/*
5802 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5803 * Return FALSE when it wasn't.
5804 * Return -1 for an unknown option.
5805 */
5806 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005807was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005808{
5809 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005810 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005811
5812 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005813 {
5814 flagp = insecure_flag(idx, opt_flags);
5815 return (*flagp & P_INSECURE) != 0;
5816 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005817 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005818 return -1;
5819}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005820
5821/*
5822 * Get a pointer to the flags used for the P_INSECURE flag of option
5823 * "opt_idx". For some local options a local flags field is used.
5824 */
5825 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005826insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005827{
5828 if (opt_flags & OPT_LOCAL)
5829 switch ((int)options[opt_idx].indir)
5830 {
5831#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005832 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005833#endif
5834#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005835# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005836 case PV_FDE: return &curwin->w_p_fde_flags;
5837 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005838# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005839# ifdef FEAT_BEVAL
5840 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5841# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005842# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005843 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005844# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005845 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005846# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005847 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005848# endif
5849#endif
5850 }
5851
5852 /* Nothing special, return global flags field. */
5853 return &options[opt_idx].flags;
5854}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005855#endif
5856
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005857#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005858static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005859
5860/*
5861 * Redraw the window title and/or tab page text later.
5862 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005863static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005864{
5865 need_maketitle = TRUE;
5866# ifdef FEAT_WINDOWS
5867 redraw_tabline = TRUE;
5868# endif
5869}
5870#endif
5871
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872/*
5873 * Set a string option to a new value (without checking the effect).
5874 * The string is copied into allocated memory.
5875 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005876 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005877 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878 */
5879 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005880set_string_option_direct(
5881 char_u *name,
5882 int opt_idx,
5883 char_u *val,
5884 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5885 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886{
5887 char_u *s;
5888 char_u **varp;
5889 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005890 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891
Bram Moolenaar89d40322006-08-29 15:30:07 +00005892 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005894 idx = findoption(name);
5895 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005896 {
5897 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005898 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005899 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005900 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005901 }
5902
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 return;
5905
5906 s = vim_strsave(val);
5907 if (s != NULL)
5908 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005909 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005911 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 free_string_option(*varp);
5913 *varp = s;
5914
5915 /* For buffer/window local option may also set the global value. */
5916 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005917 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918
Bram Moolenaar89d40322006-08-29 15:30:07 +00005919 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005920
5921 /* When setting both values of a global option with a local value,
5922 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005923 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924 {
5925 free_string_option(*varp);
5926 *varp = empty_option;
5927 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005928# ifdef FEAT_EVAL
5929 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005930 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005931 set_sid == 0 ? current_SID : set_sid);
5932# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005933 }
5934}
5935
5936/*
5937 * Set global value for string option when it's a local option.
5938 */
5939 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005940set_string_option_global(
5941 int opt_idx, /* option index */
5942 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005943{
5944 char_u **p, *s;
5945
5946 /* the global value is always allocated */
5947 if (options[opt_idx].var == VAR_WIN)
5948 p = (char_u **)GLOBAL_WO(varp);
5949 else
5950 p = (char_u **)options[opt_idx].var;
5951 if (options[opt_idx].indir != PV_NONE
5952 && p != varp
5953 && (s = vim_strsave(*varp)) != NULL)
5954 {
5955 free_string_option(*p);
5956 *p = s;
5957 }
5958}
5959
5960/*
5961 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005962 *
5963 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005964 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005965 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005966set_string_option(
5967 int opt_idx,
5968 char_u *value,
5969 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005970{
5971 char_u *s;
5972 char_u **varp;
5973 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005974#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5975 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005976 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005977#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005978 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005979
5980 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005981 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005982
5983 s = vim_strsave(value);
5984 if (s != NULL)
5985 {
5986 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5987 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005988 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005989 ? OPT_GLOBAL : OPT_LOCAL)
5990 : opt_flags);
5991 oldval = *varp;
5992 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005993
5994#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005995 if (!starting
5996# ifdef FEAT_CRYPT
5997 && options[opt_idx].indir != PV_KEY
5998# endif
5999 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006000 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006001 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006002 saved_newval = vim_strsave(s);
6003 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006004#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006005 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6006 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006007 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006008
Bram Moolenaar53744302015-07-17 17:38:22 +02006009#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006010 /* call autocommand after handling side effects */
6011 trigger_optionsset_string(opt_idx, opt_flags,
6012 saved_oldval, saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006013#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006014 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006015 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006016}
6017
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006018#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006019/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006020 * Return TRUE if "val" is a valid 'filetype' name.
6021 * Also used for 'syntax' and 'keymap'.
6022 */
6023 static int
6024valid_filetype(char_u *val)
6025{
6026 char_u *s;
6027
6028 for (s = val; *s != NUL; ++s)
6029 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6030 return FALSE;
6031 return TRUE;
6032}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006033#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006034
6035/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006036 * Handle string options that need some action to perform when changed.
6037 * Returns NULL for success, or an error message for an error.
6038 */
6039 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006040did_set_string_option(
6041 int opt_idx, /* index in options[] table */
6042 char_u **varp, /* pointer to the option variable */
6043 int new_value_alloced, /* new value was allocated */
6044 char_u *oldval, /* previous value of the option */
6045 char_u *errbuf, /* buffer for errors, or NULL */
6046 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006047{
6048 char_u *errmsg = NULL;
6049 char_u *s, *p;
6050 int did_chartab = FALSE;
6051 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006052 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006053#ifdef FEAT_GUI
6054 /* set when changing an option that only requires a redraw in the GUI */
6055 int redraw_gui_only = FALSE;
6056#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006057#ifdef FEAT_AUTOCMD
6058 int ft_changed = FALSE;
6059#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006060
6061 /* Get the global option to compare with, otherwise we would have to check
6062 * two values for all local options. */
6063 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6064
6065 /* Disallow changing some options from secure mode */
6066 if ((secure
6067#ifdef HAVE_SANDBOX
6068 || sandbox != 0
6069#endif
6070 ) && (options[opt_idx].flags & P_SECURE))
6071 {
6072 errmsg = e_secure;
6073 }
6074
Bram Moolenaar7554da42016-11-25 22:04:13 +01006075 /* Check for a "normal" directory or file name in some options. Disallow a
6076 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006077 * are often illegal in a file name. Be more permissive if "secure" is off.
6078 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006079 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006080 && vim_strpbrk(*varp, (char_u *)(secure
6081 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006082 || ((options[opt_idx].flags & P_NDNAME)
6083 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006084 {
6085 errmsg = e_invarg;
6086 }
6087
Bram Moolenaar071d4272004-06-13 20:20:40 +00006088 /* 'term' */
6089 else if (varp == &T_NAME)
6090 {
6091 if (T_NAME[0] == NUL)
6092 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6093#ifdef FEAT_GUI
6094 if (gui.in_use)
6095 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6096 else if (term_is_gui(T_NAME))
6097 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6098#endif
6099 else if (set_termname(T_NAME) == FAIL)
6100 errmsg = (char_u *)N_("E522: Not found in termcap");
6101 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006102 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006103 /* Screen colors may have changed. */
6104 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006105
6106 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6107 * P_ALLOCED flag on 'term'. */
6108 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006109 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 }
6112
6113 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006114 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006115 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006116 char_u *bkc = p_bkc;
6117 unsigned int *flags = &bkc_flags;
6118
6119 if (opt_flags & OPT_LOCAL)
6120 {
6121 bkc = curbuf->b_p_bkc;
6122 flags = &curbuf->b_bkc_flags;
6123 }
6124
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006125 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6126 /* make the local value empty: use the global value */
6127 *flags = 0;
6128 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006129 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006130 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6131 errmsg = e_invarg;
6132 if ((((int)*flags & BKC_AUTO) != 0)
6133 + (((int)*flags & BKC_YES) != 0)
6134 + (((int)*flags & BKC_NO) != 0) != 1)
6135 {
6136 /* Must have exactly one of "auto", "yes" and "no". */
6137 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6138 errmsg = e_invarg;
6139 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006140 }
6141 }
6142
6143 /* 'backupext' and 'patchmode' */
6144 else if (varp == &p_bex || varp == &p_pm)
6145 {
6146 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6147 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6148 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6149 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006150#ifdef FEAT_LINEBREAK
6151 /* 'breakindentopt' */
6152 else if (varp == &curwin->w_p_briopt)
6153 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006154 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006155 errmsg = e_invarg;
6156 }
6157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006158
6159 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006160 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006161 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006162 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006163 */
6164 else if ( varp == &p_isi
6165 || varp == &(curbuf->b_p_isk)
6166 || varp == &p_isp
6167 || varp == &p_isf)
6168 {
6169 if (init_chartab() == FAIL)
6170 {
6171 did_chartab = TRUE; /* need to restore it below */
6172 errmsg = e_invarg; /* error in value */
6173 }
6174 }
6175
6176 /* 'helpfile' */
6177 else if (varp == &p_hf)
6178 {
6179 /* May compute new values for $VIM and $VIMRUNTIME */
6180 if (didset_vim)
6181 {
6182 vim_setenv((char_u *)"VIM", (char_u *)"");
6183 didset_vim = FALSE;
6184 }
6185 if (didset_vimruntime)
6186 {
6187 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6188 didset_vimruntime = FALSE;
6189 }
6190 }
6191
Bram Moolenaar1a384422010-07-14 19:53:30 +02006192#ifdef FEAT_SYN_HL
6193 /* 'colorcolumn' */
6194 else if (varp == &curwin->w_p_cc)
6195 errmsg = check_colorcolumn(curwin);
6196#endif
6197
Bram Moolenaar071d4272004-06-13 20:20:40 +00006198#ifdef FEAT_MULTI_LANG
6199 /* 'helplang' */
6200 else if (varp == &p_hlg)
6201 {
6202 /* Check for "", "ab", "ab,cd", etc. */
6203 for (s = p_hlg; *s != NUL; s += 3)
6204 {
6205 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6206 {
6207 errmsg = e_invarg;
6208 break;
6209 }
6210 if (s[2] == NUL)
6211 break;
6212 }
6213 }
6214#endif
6215
6216 /* 'highlight' */
6217 else if (varp == &p_hl)
6218 {
6219 if (highlight_changed() == FAIL)
6220 errmsg = e_invarg; /* invalid flags */
6221 }
6222
6223 /* 'nrformats' */
6224 else if (gvarp == &p_nf)
6225 {
6226 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6227 errmsg = e_invarg;
6228 }
6229
6230#ifdef FEAT_SESSION
6231 /* 'sessionoptions' */
6232 else if (varp == &p_ssop)
6233 {
6234 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6235 errmsg = e_invarg;
6236 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6237 {
6238 /* Don't allow both "sesdir" and "curdir". */
6239 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6240 errmsg = e_invarg;
6241 }
6242 }
6243 /* 'viewoptions' */
6244 else if (varp == &p_vop)
6245 {
6246 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6247 errmsg = e_invarg;
6248 }
6249#endif
6250
6251 /* 'scrollopt' */
6252#ifdef FEAT_SCROLLBIND
6253 else if (varp == &p_sbo)
6254 {
6255 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6256 errmsg = e_invarg;
6257 }
6258#endif
6259
6260 /* 'ambiwidth' */
6261#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006262 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006263 {
6264 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6265 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006266 else if (set_chars_option(&p_lcs) != NULL)
6267 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6268# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6269 else if (set_chars_option(&p_fcs) != NULL)
6270 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6271# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006272 }
6273#endif
6274
6275 /* 'background' */
6276 else if (varp == &p_bg)
6277 {
6278 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6279 {
6280#ifdef FEAT_EVAL
6281 int dark = (*p_bg == 'd');
6282#endif
6283
6284 init_highlight(FALSE, FALSE);
6285
6286#ifdef FEAT_EVAL
6287 if (dark != (*p_bg == 'd')
6288 && get_var_value((char_u *)"g:colors_name") != NULL)
6289 {
6290 /* The color scheme must have set 'background' back to another
6291 * value, that's not what we want here. Disable the color
6292 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006293 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006294 free_string_option(p_bg);
6295 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6296 check_string_option(&p_bg);
6297 init_highlight(FALSE, FALSE);
6298 }
6299#endif
6300 }
6301 else
6302 errmsg = e_invarg;
6303 }
6304
6305 /* 'wildmode' */
6306 else if (varp == &p_wim)
6307 {
6308 if (check_opt_wim() == FAIL)
6309 errmsg = e_invarg;
6310 }
6311
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006312#ifdef FEAT_CMDL_COMPL
6313 /* 'wildoptions' */
6314 else if (varp == &p_wop)
6315 {
6316 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6317 errmsg = e_invarg;
6318 }
6319#endif
6320
Bram Moolenaar071d4272004-06-13 20:20:40 +00006321#ifdef FEAT_WAK
6322 /* 'winaltkeys' */
6323 else if (varp == &p_wak)
6324 {
6325 if (*p_wak == NUL
6326 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6327 errmsg = e_invarg;
6328# ifdef FEAT_MENU
6329# ifdef FEAT_GUI_MOTIF
6330 else if (gui.in_use)
6331 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6332# else
6333# ifdef FEAT_GUI_GTK
6334 else if (gui.in_use)
6335 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6336# endif
6337# endif
6338# endif
6339 }
6340#endif
6341
6342#ifdef FEAT_AUTOCMD
6343 /* 'eventignore' */
6344 else if (varp == &p_ei)
6345 {
6346 if (check_ei() == FAIL)
6347 errmsg = e_invarg;
6348 }
6349#endif
6350
6351#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006352 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6353 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6354 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006355 {
6356 if (gvarp == &p_fenc)
6357 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006358 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006359 errmsg = e_modifiable;
6360 else if (vim_strchr(*varp, ',') != NULL)
6361 /* No comma allowed in 'fileencoding'; catches confusing it
6362 * with 'fileencodings'. */
6363 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006364 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006365 {
6366# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006367 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006368 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006369# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006370 /* Add 'fileencoding' to the swap file. */
6371 ml_setflags(curbuf);
6372 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006373 }
6374 if (errmsg == NULL)
6375 {
6376 /* canonize the value, so that STRCMP() can be used on it */
6377 p = enc_canonize(*varp);
6378 if (p != NULL)
6379 {
6380 vim_free(*varp);
6381 *varp = p;
6382 }
6383 if (varp == &p_enc)
6384 {
6385 errmsg = mb_init();
6386# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006387 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388# endif
6389 }
6390 }
6391
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006392# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006393 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6394 {
6395 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6396 if (STRCMP(p_tenc, "utf-8") != 0)
6397 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6398 }
6399# endif
6400
6401 if (errmsg == NULL)
6402 {
6403# ifdef FEAT_KEYMAP
6404 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6405 * (with another encoding). */
6406 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6407 (void)keymap_init();
6408# endif
6409
6410 /* When 'termencoding' is not empty and 'encoding' changes or when
6411 * 'termencoding' changes, need to setup for keyboard input and
6412 * display output conversion. */
6413 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6414 {
6415 convert_setup(&input_conv, p_tenc, p_enc);
6416 convert_setup(&output_conv, p_enc, p_tenc);
6417 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006418
6419# if defined(WIN3264) && defined(FEAT_MBYTE)
6420 /* $HOME may have characters in active code page. */
6421 if (varp == &p_enc)
6422 init_homedir();
6423# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006424 }
6425 }
6426#endif
6427
6428#if defined(FEAT_POSTSCRIPT)
6429 else if (varp == &p_penc)
6430 {
6431 /* Canonize printencoding if VIM standard one */
6432 p = enc_canonize(p_penc);
6433 if (p != NULL)
6434 {
6435 vim_free(p_penc);
6436 p_penc = p;
6437 }
6438 else
6439 {
6440 /* Ensure lower case and '-' for '_' */
6441 for (s = p_penc; *s != NUL; s++)
6442 {
6443 if (*s == '_')
6444 *s = '-';
6445 else
6446 *s = TOLOWER_ASC(*s);
6447 }
6448 }
6449 }
6450#endif
6451
Bram Moolenaar9372a112005-12-06 19:59:18 +00006452#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006453 else if (varp == &p_imak)
6454 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006455 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006456 errmsg = e_invarg;
6457 }
6458#endif
6459
6460#ifdef FEAT_KEYMAP
6461 else if (varp == &curbuf->b_p_keymap)
6462 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006463 if (!valid_filetype(*varp))
6464 errmsg = e_invarg;
6465 else
6466 /* load or unload key mapping tables */
6467 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468
Bram Moolenaarfab06232009-03-04 03:13:35 +00006469 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006470 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006471 if (*curbuf->b_p_keymap != NUL)
6472 {
6473 /* Installed a new keymap, switch on using it. */
6474 curbuf->b_p_iminsert = B_IMODE_LMAP;
6475 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6476 curbuf->b_p_imsearch = B_IMODE_LMAP;
6477 }
6478 else
6479 {
6480 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6481 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6482 curbuf->b_p_iminsert = B_IMODE_NONE;
6483 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6484 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6485 }
6486 if ((opt_flags & OPT_LOCAL) == 0)
6487 {
6488 set_iminsert_global();
6489 set_imsearch_global();
6490 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006491# ifdef FEAT_WINDOWS
6492 status_redraw_curbuf();
6493# endif
6494 }
6495 }
6496#endif
6497
6498 /* 'fileformat' */
6499 else if (gvarp == &p_ff)
6500 {
6501 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6502 errmsg = e_modifiable;
6503 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6504 errmsg = e_invarg;
6505 else
6506 {
6507 /* may also change 'textmode' */
6508 if (get_fileformat(curbuf) == EOL_DOS)
6509 curbuf->b_p_tx = TRUE;
6510 else
6511 curbuf->b_p_tx = FALSE;
6512#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006513 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006514#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006515 /* update flag in swap file */
6516 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006517 /* Redraw needed when switching to/from "mac": a CR in the text
6518 * will be displayed differently. */
6519 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6520 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006521 }
6522 }
6523
6524 /* 'fileformats' */
6525 else if (varp == &p_ffs)
6526 {
6527 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6528 errmsg = e_invarg;
6529 else
6530 {
6531 /* also change 'textauto' */
6532 if (*p_ffs == NUL)
6533 p_ta = FALSE;
6534 else
6535 p_ta = TRUE;
6536 }
6537 }
6538
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006539#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006540 /* 'cryptkey' */
6541 else if (gvarp == &p_key)
6542 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006543# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006544 /* Make sure the ":set" command doesn't show the new value in the
6545 * history. */
6546 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006547# endif
6548 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6549 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006550 ml_set_crypt_key(curbuf, oldval,
6551 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006552 }
6553
6554 else if (gvarp == &p_cm)
6555 {
6556 if (opt_flags & OPT_LOCAL)
6557 p = curbuf->b_p_cm;
6558 else
6559 p = p_cm;
6560 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6561 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006562 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006563 errmsg = e_invarg;
6564 else
6565 {
6566 /* When setting the global value to empty, make it "zip". */
6567 if (*p_cm == NUL)
6568 {
6569 if (new_value_alloced)
6570 free_string_option(p_cm);
6571 p_cm = vim_strsave((char_u *)"zip");
6572 new_value_alloced = TRUE;
6573 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006574 /* When using ":set cm=name" the local value is going to be empty.
6575 * Do that here, otherwise the crypt functions will still use the
6576 * local value. */
6577 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6578 {
6579 free_string_option(curbuf->b_p_cm);
6580 curbuf->b_p_cm = empty_option;
6581 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006582
6583 /* Need to update the swapfile when the effective method changed.
6584 * Set "s" to the effective old value, "p" to the effective new
6585 * method and compare. */
6586 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6587 s = p_cm; /* was previously using the global value */
6588 else
6589 s = oldval;
6590 if (*curbuf->b_p_cm == NUL)
6591 p = p_cm; /* is now using the global value */
6592 else
6593 p = curbuf->b_p_cm;
6594 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006595 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006596
6597 /* If the global value changes need to update the swapfile for all
6598 * buffers using that value. */
6599 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6600 {
6601 buf_T *buf;
6602
Bram Moolenaar29323592016-07-24 22:04:11 +02006603 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006604 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006605 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006606 }
6607 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006608 }
6609#endif
6610
6611 /* 'matchpairs' */
6612 else if (gvarp == &p_mps)
6613 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006614#ifdef FEAT_MBYTE
6615 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006616 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006617 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006619 int x2 = -1;
6620 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006621
6622 if (*p != NUL)
6623 p += mb_ptr2len(p);
6624 if (*p != NUL)
6625 x2 = *p++;
6626 if (*p != NUL)
6627 {
6628 x3 = mb_ptr2char(p);
6629 p += mb_ptr2len(p);
6630 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006631 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006632 {
6633 errmsg = e_invarg;
6634 break;
6635 }
6636 if (*p == NUL)
6637 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006638 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006639 }
6640 else
6641#endif
6642 {
6643 /* Check for "x:y,x:y" */
6644 for (p = *varp; *p != NUL; p += 4)
6645 {
6646 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6647 {
6648 errmsg = e_invarg;
6649 break;
6650 }
6651 if (p[3] == NUL)
6652 break;
6653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 }
6655 }
6656
6657#ifdef FEAT_COMMENTS
6658 /* 'comments' */
6659 else if (gvarp == &p_com)
6660 {
6661 for (s = *varp; *s; )
6662 {
6663 while (*s && *s != ':')
6664 {
6665 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6666 && !VIM_ISDIGIT(*s) && *s != '-')
6667 {
6668 errmsg = illegal_char(errbuf, *s);
6669 break;
6670 }
6671 ++s;
6672 }
6673 if (*s++ == NUL)
6674 errmsg = (char_u *)N_("E524: Missing colon");
6675 else if (*s == ',' || *s == NUL)
6676 errmsg = (char_u *)N_("E525: Zero length string");
6677 if (errmsg != NULL)
6678 break;
6679 while (*s && *s != ',')
6680 {
6681 if (*s == '\\' && s[1] != NUL)
6682 ++s;
6683 ++s;
6684 }
6685 s = skip_to_option_part(s);
6686 }
6687 }
6688#endif
6689
6690 /* 'listchars' */
6691 else if (varp == &p_lcs)
6692 {
6693 errmsg = set_chars_option(varp);
6694 }
6695
6696#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6697 /* 'fillchars' */
6698 else if (varp == &p_fcs)
6699 {
6700 errmsg = set_chars_option(varp);
6701 }
6702#endif
6703
6704#ifdef FEAT_CMDWIN
6705 /* 'cedit' */
6706 else if (varp == &p_cedit)
6707 {
6708 errmsg = check_cedit();
6709 }
6710#endif
6711
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006712 /* 'verbosefile' */
6713 else if (varp == &p_vfile)
6714 {
6715 verbose_stop();
6716 if (*p_vfile != NUL && verbose_open() == FAIL)
6717 errmsg = e_invarg;
6718 }
6719
Bram Moolenaar071d4272004-06-13 20:20:40 +00006720#ifdef FEAT_VIMINFO
6721 /* 'viminfo' */
6722 else if (varp == &p_viminfo)
6723 {
6724 for (s = p_viminfo; *s;)
6725 {
6726 /* Check it's a valid character */
6727 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6728 {
6729 errmsg = illegal_char(errbuf, *s);
6730 break;
6731 }
6732 if (*s == 'n') /* name is always last one */
6733 {
6734 break;
6735 }
6736 else if (*s == 'r') /* skip until next ',' */
6737 {
6738 while (*++s && *s != ',')
6739 ;
6740 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006741 else if (*s == '%')
6742 {
6743 /* optional number */
6744 while (vim_isdigit(*++s))
6745 ;
6746 }
6747 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006748 ++s; /* no extra chars */
6749 else /* must have a number */
6750 {
6751 while (vim_isdigit(*++s))
6752 ;
6753
6754 if (!VIM_ISDIGIT(*(s - 1)))
6755 {
6756 if (errbuf != NULL)
6757 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006758 sprintf((char *)errbuf,
6759 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006760 transchar_byte(*(s - 1)));
6761 errmsg = errbuf;
6762 }
6763 else
6764 errmsg = (char_u *)"";
6765 break;
6766 }
6767 }
6768 if (*s == ',')
6769 ++s;
6770 else if (*s)
6771 {
6772 if (errbuf != NULL)
6773 errmsg = (char_u *)N_("E527: Missing comma");
6774 else
6775 errmsg = (char_u *)"";
6776 break;
6777 }
6778 }
6779 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6780 errmsg = (char_u *)N_("E528: Must specify a ' value");
6781 }
6782#endif /* FEAT_VIMINFO */
6783
6784 /* terminal options */
6785 else if (istermoption(&options[opt_idx]) && full_screen)
6786 {
6787 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6788 if (varp == &T_CCO)
6789 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006790 int colors = atoi((char *)T_CCO);
6791
6792 /* Only reinitialize colors if t_Co value has really changed to
6793 * avoid expensive reload of colorscheme if t_Co is set to the
6794 * same value multiple times. */
6795 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006796 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006797 t_colors = colors;
6798 if (t_colors <= 1)
6799 {
6800 if (new_value_alloced)
6801 vim_free(T_CCO);
6802 T_CCO = empty_option;
6803 }
6804 /* We now have a different color setup, initialize it again. */
6805 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006806 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006807 }
6808 ttest(FALSE);
6809 if (varp == &T_ME)
6810 {
6811 out_str(T_ME);
6812 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006813#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006814 /* Since t_me has been set, this probably means that the user
6815 * wants to use this as default colors. Need to reset default
6816 * background/foreground colors. */
6817 mch_set_normal_colors();
6818#endif
6819 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006820 if (varp == &T_BE && termcap_active)
6821 {
6822 if (*T_BE == NUL)
6823 /* When clearing t_BE we assume the user no longer wants
6824 * bracketed paste, thus disable it by writing t_BD. */
6825 out_str(T_BD);
6826 else
6827 out_str(T_BE);
6828 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829 }
6830
6831#ifdef FEAT_LINEBREAK
6832 /* 'showbreak' */
6833 else if (varp == &p_sbr)
6834 {
6835 for (s = p_sbr; *s; )
6836 {
6837 if (ptr2cells(s) != 1)
6838 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006839 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006840 }
6841 }
6842#endif
6843
6844#ifdef FEAT_GUI
6845 /* 'guifont' */
6846 else if (varp == &p_guifont)
6847 {
6848 if (gui.in_use)
6849 {
6850 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006851# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006852 /*
6853 * Put up a font dialog and let the user select a new value.
6854 * If this is cancelled go back to the old value but don't
6855 * give an error message.
6856 */
6857 if (STRCMP(p, "*") == 0)
6858 {
6859 p = gui_mch_font_dialog(oldval);
6860
6861 if (new_value_alloced)
6862 free_string_option(p_guifont);
6863
6864 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6865 new_value_alloced = TRUE;
6866 }
6867# endif
6868 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6869 {
6870# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6871 if (STRCMP(p_guifont, "*") == 0)
6872 {
6873 /* Dialog was cancelled: Keep the old value without giving
6874 * an error message. */
6875 if (new_value_alloced)
6876 free_string_option(p_guifont);
6877 p_guifont = vim_strsave(oldval);
6878 new_value_alloced = TRUE;
6879 }
6880 else
6881# endif
6882 errmsg = (char_u *)N_("E596: Invalid font(s)");
6883 }
6884 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006885 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006886 }
6887# ifdef FEAT_XFONTSET
6888 else if (varp == &p_guifontset)
6889 {
6890 if (STRCMP(p_guifontset, "*") == 0)
6891 errmsg = (char_u *)N_("E597: can't select fontset");
6892 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6893 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006894 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006895 }
6896# endif
6897# ifdef FEAT_MBYTE
6898 else if (varp == &p_guifontwide)
6899 {
6900 if (STRCMP(p_guifontwide, "*") == 0)
6901 errmsg = (char_u *)N_("E533: can't select wide font");
6902 else if (gui_get_wide_font() == FAIL)
6903 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006904 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006905 }
6906# endif
6907#endif
6908
6909#ifdef CURSOR_SHAPE
6910 /* 'guicursor' */
6911 else if (varp == &p_guicursor)
6912 errmsg = parse_shape_opt(SHAPE_CURSOR);
6913#endif
6914
6915#ifdef FEAT_MOUSESHAPE
6916 /* 'mouseshape' */
6917 else if (varp == &p_mouseshape)
6918 {
6919 errmsg = parse_shape_opt(SHAPE_MOUSE);
6920 update_mouseshape(-1);
6921 }
6922#endif
6923
6924#ifdef FEAT_PRINTER
6925 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006926 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006927# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006928 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006929 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006930# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006931#endif
6932
6933#ifdef FEAT_LANGMAP
6934 /* 'langmap' */
6935 else if (varp == &p_langmap)
6936 langmap_set();
6937#endif
6938
6939#ifdef FEAT_LINEBREAK
6940 /* 'breakat' */
6941 else if (varp == &p_breakat)
6942 fill_breakat_flags();
6943#endif
6944
6945#ifdef FEAT_TITLE
6946 /* 'titlestring' and 'iconstring' */
6947 else if (varp == &p_titlestring || varp == &p_iconstring)
6948 {
6949# ifdef FEAT_STL_OPT
6950 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6951
6952 /* NULL => statusline syntax */
6953 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6954 stl_syntax |= flagval;
6955 else
6956 stl_syntax &= ~flagval;
6957# endif
6958 did_set_title(varp == &p_iconstring);
6959
6960 }
6961#endif
6962
6963#ifdef FEAT_GUI
6964 /* 'guioptions' */
6965 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006966 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006967 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006968 redraw_gui_only = TRUE;
6969 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006970#endif
6971
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006972#if defined(FEAT_GUI_TABLINE)
6973 /* 'guitablabel' */
6974 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006975 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006976 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006977 redraw_gui_only = TRUE;
6978 }
6979 /* 'guitabtooltip' */
6980 else if (varp == &p_gtt)
6981 {
6982 redraw_gui_only = TRUE;
6983 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006984#endif
6985
Bram Moolenaar071d4272004-06-13 20:20:40 +00006986#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6987 /* 'ttymouse' */
6988 else if (varp == &p_ttym)
6989 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006990 /* Switch the mouse off before changing the escape sequences used for
6991 * that. */
6992 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6994 errmsg = e_invarg;
6995 else
6996 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006997 if (termcap_active)
6998 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006999 }
7000#endif
7001
Bram Moolenaar071d4272004-06-13 20:20:40 +00007002 /* 'selection' */
7003 else if (varp == &p_sel)
7004 {
7005 if (*p_sel == NUL
7006 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7007 errmsg = e_invarg;
7008 }
7009
7010 /* 'selectmode' */
7011 else if (varp == &p_slm)
7012 {
7013 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7014 errmsg = e_invarg;
7015 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007016
7017#ifdef FEAT_BROWSE
7018 /* 'browsedir' */
7019 else if (varp == &p_bsdir)
7020 {
7021 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7022 && !mch_isdir(p_bsdir))
7023 errmsg = e_invarg;
7024 }
7025#endif
7026
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027 /* 'keymodel' */
7028 else if (varp == &p_km)
7029 {
7030 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7031 errmsg = e_invarg;
7032 else
7033 {
7034 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7035 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7036 }
7037 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007038
7039 /* 'mousemodel' */
7040 else if (varp == &p_mousem)
7041 {
7042 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7043 errmsg = e_invarg;
7044#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7045 else if (*p_mousem != *oldval)
7046 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7047 * to create or delete the popup menus. */
7048 gui_motif_update_mousemodel(root_menu);
7049#endif
7050 }
7051
7052 /* 'switchbuf' */
7053 else if (varp == &p_swb)
7054 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007055 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007056 errmsg = e_invarg;
7057 }
7058
7059 /* 'debug' */
7060 else if (varp == &p_debug)
7061 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007062 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063 errmsg = e_invarg;
7064 }
7065
7066 /* 'display' */
7067 else if (varp == &p_dy)
7068 {
7069 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7070 errmsg = e_invarg;
7071 else
7072 (void)init_chartab();
7073
7074 }
7075
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007076#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077 /* 'eadirection' */
7078 else if (varp == &p_ead)
7079 {
7080 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7081 errmsg = e_invarg;
7082 }
7083#endif
7084
7085#ifdef FEAT_CLIPBOARD
7086 /* 'clipboard' */
7087 else if (varp == &p_cb)
7088 errmsg = check_clipboard_option();
7089#endif
7090
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007091#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007092 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7093 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007094 else if (varp == &(curwin->w_s->b_p_spl)
7095 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007096 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007097 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007098 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007099 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007100 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007101 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007102 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007103 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007104 /* 'spellsuggest' */
7105 else if (varp == &p_sps)
7106 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007107 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007108 errmsg = e_invarg;
7109 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007110 /* 'mkspellmem' */
7111 else if (varp == &p_msm)
7112 {
7113 if (spell_check_msm() != OK)
7114 errmsg = e_invarg;
7115 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007116#endif
7117
Bram Moolenaar071d4272004-06-13 20:20:40 +00007118#ifdef FEAT_QUICKFIX
7119 /* When 'bufhidden' is set, check for valid value. */
7120 else if (gvarp == &p_bh)
7121 {
7122 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7123 errmsg = e_invarg;
7124 }
7125
7126 /* When 'buftype' is set, check for valid value. */
7127 else if (gvarp == &p_bt)
7128 {
7129 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7130 errmsg = e_invarg;
7131 else
7132 {
7133# ifdef FEAT_WINDOWS
7134 if (curwin->w_status_height)
7135 {
7136 curwin->w_redr_status = TRUE;
7137 redraw_later(VALID);
7138 }
7139# endif
7140 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007141# ifdef FEAT_TITLE
7142 redraw_titles();
7143# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144 }
7145 }
7146#endif
7147
7148#ifdef FEAT_STL_OPT
7149 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007150 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007151 {
7152 int wid;
7153
7154 if (varp == &p_ruf) /* reset ru_wid first */
7155 ru_wid = 0;
7156 s = *varp;
7157 if (varp == &p_ruf && *s == '%')
7158 {
7159 /* set ru_wid if 'ruf' starts with "%99(" */
7160 if (*++s == '-') /* ignore a '-' */
7161 s++;
7162 wid = getdigits(&s);
7163 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7164 ru_wid = wid;
7165 else
7166 errmsg = check_stl_option(p_ruf);
7167 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007168 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007169 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007170 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007171 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007172 comp_col();
7173 }
7174#endif
7175
7176#ifdef FEAT_INS_EXPAND
7177 /* check if it is a valid value for 'complete' -- Acevedo */
7178 else if (gvarp == &p_cpt)
7179 {
7180 for (s = *varp; *s;)
7181 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007182 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007183 s++;
7184 if (!*s)
7185 break;
7186 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7187 {
7188 errmsg = illegal_char(errbuf, *s);
7189 break;
7190 }
7191 if (*++s != NUL && *s != ',' && *s != ' ')
7192 {
7193 if (s[-1] == 'k' || s[-1] == 's')
7194 {
7195 /* skip optional filename after 'k' and 's' */
7196 while (*s && *s != ',' && *s != ' ')
7197 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007198 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007199 ++s;
7200 ++s;
7201 }
7202 }
7203 else
7204 {
7205 if (errbuf != NULL)
7206 {
7207 sprintf((char *)errbuf,
7208 _("E535: Illegal character after <%c>"),
7209 *--s);
7210 errmsg = errbuf;
7211 }
7212 else
7213 errmsg = (char_u *)"";
7214 break;
7215 }
7216 }
7217 }
7218 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007219
7220 /* 'completeopt' */
7221 else if (varp == &p_cot)
7222 {
7223 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7224 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007225 else
7226 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007227 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007228#endif /* FEAT_INS_EXPAND */
7229
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007230#ifdef FEAT_SIGNS
7231 /* 'signcolumn' */
7232 else if (varp == &curwin->w_p_scl)
7233 {
7234 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7235 errmsg = e_invarg;
7236 }
7237#endif
7238
Bram Moolenaar071d4272004-06-13 20:20:40 +00007239
7240#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007241 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242 else if (varp == &p_toolbar)
7243 {
7244 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7245 &toolbar_flags, TRUE) != OK)
7246 errmsg = e_invarg;
7247 else
7248 {
7249 out_flush();
7250 gui_mch_show_toolbar((toolbar_flags &
7251 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7252 }
7253 }
7254#endif
7255
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007256#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007257 /* 'toolbariconsize': GTK+ 2 only */
7258 else if (varp == &p_tbis)
7259 {
7260 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7261 errmsg = e_invarg;
7262 else
7263 {
7264 out_flush();
7265 gui_mch_show_toolbar((toolbar_flags &
7266 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7267 }
7268 }
7269#endif
7270
7271 /* 'pastetoggle': translate key codes like in a mapping */
7272 else if (varp == &p_pt)
7273 {
7274 if (*p_pt)
7275 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007276 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007277 if (p != NULL)
7278 {
7279 if (new_value_alloced)
7280 free_string_option(p_pt);
7281 p_pt = p;
7282 new_value_alloced = TRUE;
7283 }
7284 }
7285 }
7286
7287 /* 'backspace' */
7288 else if (varp == &p_bs)
7289 {
7290 if (VIM_ISDIGIT(*p_bs))
7291 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007292 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007293 errmsg = e_invarg;
7294 }
7295 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7296 errmsg = e_invarg;
7297 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007298 else if (varp == &p_bo)
7299 {
7300 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7301 errmsg = e_invarg;
7302 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007303
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007304 /* 'tagcase' */
7305 else if (gvarp == &p_tc)
7306 {
7307 unsigned int *flags;
7308
7309 if (opt_flags & OPT_LOCAL)
7310 {
7311 p = curbuf->b_p_tc;
7312 flags = &curbuf->b_tc_flags;
7313 }
7314 else
7315 {
7316 p = p_tc;
7317 flags = &tc_flags;
7318 }
7319
7320 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7321 /* make the local value empty: use the global value */
7322 *flags = 0;
7323 else if (*p == NUL
7324 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7325 errmsg = e_invarg;
7326 }
7327
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007328#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007329 /* 'casemap' */
7330 else if (varp == &p_cmp)
7331 {
7332 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7333 errmsg = e_invarg;
7334 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007335#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336
7337#ifdef FEAT_DIFF
7338 /* 'diffopt' */
7339 else if (varp == &p_dip)
7340 {
7341 if (diffopt_changed() == FAIL)
7342 errmsg = e_invarg;
7343 }
7344#endif
7345
7346#ifdef FEAT_FOLDING
7347 /* 'foldmethod' */
7348 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7349 {
7350 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7351 || *curwin->w_p_fdm == NUL)
7352 errmsg = e_invarg;
7353 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007354 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007355 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007356 if (foldmethodIsDiff(curwin))
7357 newFoldLevel();
7358 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007359 }
7360# ifdef FEAT_EVAL
7361 /* 'foldexpr' */
7362 else if (varp == &curwin->w_p_fde)
7363 {
7364 if (foldmethodIsExpr(curwin))
7365 foldUpdateAll(curwin);
7366 }
7367# endif
7368 /* 'foldmarker' */
7369 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7370 {
7371 p = vim_strchr(*varp, ',');
7372 if (p == NULL)
7373 errmsg = (char_u *)N_("E536: comma required");
7374 else if (p == *varp || p[1] == NUL)
7375 errmsg = e_invarg;
7376 else if (foldmethodIsMarker(curwin))
7377 foldUpdateAll(curwin);
7378 }
7379 /* 'commentstring' */
7380 else if (gvarp == &p_cms)
7381 {
7382 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7383 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7384 }
7385 /* 'foldopen' */
7386 else if (varp == &p_fdo)
7387 {
7388 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7389 errmsg = e_invarg;
7390 }
7391 /* 'foldclose' */
7392 else if (varp == &p_fcl)
7393 {
7394 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7395 errmsg = e_invarg;
7396 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007397 /* 'foldignore' */
7398 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7399 {
7400 if (foldmethodIsIndent(curwin))
7401 foldUpdateAll(curwin);
7402 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007403#endif
7404
7405#ifdef FEAT_VIRTUALEDIT
7406 /* 'virtualedit' */
7407 else if (varp == &p_ve)
7408 {
7409 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7410 errmsg = e_invarg;
7411 else if (STRCMP(p_ve, oldval) != 0)
7412 {
7413 /* Recompute cursor position in case the new 've' setting
7414 * changes something. */
7415 validate_virtcol();
7416 coladvance(curwin->w_virtcol);
7417 }
7418 }
7419#endif
7420
7421#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7422 else if (varp == &p_csqf)
7423 {
7424 if (p_csqf != NULL)
7425 {
7426 p = p_csqf;
7427 while (*p != NUL)
7428 {
7429 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7430 || p[1] == NUL
7431 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7432 || (p[2] != NUL && p[2] != ','))
7433 {
7434 errmsg = e_invarg;
7435 break;
7436 }
7437 else if (p[2] == NUL)
7438 break;
7439 else
7440 p += 3;
7441 }
7442 }
7443 }
7444#endif
7445
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007446#ifdef FEAT_CINDENT
7447 /* 'cinoptions' */
7448 else if (gvarp == &p_cino)
7449 {
7450 /* TODO: recognize errors */
7451 parse_cino(curbuf);
7452 }
7453#endif
7454
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007455#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007456 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007457 else if (varp == &p_rop && gui.in_use)
7458 {
7459 if (!gui_mch_set_rendering_options(p_rop))
7460 errmsg = e_invarg;
7461 }
7462#endif
7463
Bram Moolenaard0b51382016-11-04 15:23:45 +01007464#ifdef FEAT_AUTOCMD
7465 else if (gvarp == &p_ft)
7466 {
7467 if (!valid_filetype(*varp))
7468 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007469 else
7470 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007471 }
7472#endif
7473
7474#ifdef FEAT_SYN_HL
7475 else if (gvarp == &p_syn)
7476 {
7477 if (!valid_filetype(*varp))
7478 errmsg = e_invarg;
7479 }
7480#endif
7481
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 /* Options that are a list of flags. */
7483 else
7484 {
7485 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007486 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007487 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007488 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007490 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007492 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007493 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007494#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007495 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007496 p = (char_u *)COCU_ALL;
7497#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007498 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499 {
7500#ifdef FEAT_MOUSE
7501 p = (char_u *)MOUSE_ALL;
7502#else
7503 if (*p_mouse != NUL)
7504 errmsg = (char_u *)N_("E538: No mouse support");
7505#endif
7506 }
7507#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007508 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007509 p = (char_u *)GO_ALL;
7510#endif
7511 if (p != NULL)
7512 {
7513 for (s = *varp; *s; ++s)
7514 if (vim_strchr(p, *s) == NULL)
7515 {
7516 errmsg = illegal_char(errbuf, *s);
7517 break;
7518 }
7519 }
7520 }
7521
7522 /*
7523 * If error detected, restore the previous value.
7524 */
7525 if (errmsg != NULL)
7526 {
7527 if (new_value_alloced)
7528 free_string_option(*varp);
7529 *varp = oldval;
7530 /*
7531 * When resetting some values, need to act on it.
7532 */
7533 if (did_chartab)
7534 (void)init_chartab();
7535 if (varp == &p_hl)
7536 (void)highlight_changed();
7537 }
7538 else
7539 {
7540#ifdef FEAT_EVAL
7541 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007542 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543#endif
7544 /*
7545 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007546 * Use "free_oldval", because recursiveness may change the flags under
7547 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007549 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007550 free_string_option(oldval);
7551 if (new_value_alloced)
7552 options[opt_idx].flags |= P_ALLOCED;
7553 else
7554 options[opt_idx].flags &= ~P_ALLOCED;
7555
7556 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007557 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007558 {
7559 /* global option with local value set to use global value; free
7560 * the local value and make it empty */
7561 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7562 free_string_option(*(char_u **)p);
7563 *(char_u **)p = empty_option;
7564 }
7565
7566 /* May set global value for local option. */
7567 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7568 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007569
7570#ifdef FEAT_AUTOCMD
7571 /*
7572 * Trigger the autocommand only after setting the flags.
7573 */
7574# ifdef FEAT_SYN_HL
7575 /* When 'syntax' is set, load the syntax of that name */
7576 if (varp == &(curbuf->b_p_syn))
7577 {
7578 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7579 curbuf->b_fname, TRUE, curbuf);
7580 }
7581# endif
7582 else if (varp == &(curbuf->b_p_ft))
7583 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007584 /* 'filetype' is set, trigger the FileType autocommand.
7585 * Skip this when called from a modeline and the filetype was
7586 * already set to this value. */
7587 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7588 {
7589 did_filetype = TRUE;
7590 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007591 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007592 /* Just in case the old "curbuf" is now invalid. */
7593 if (varp != &(curbuf->b_p_ft))
7594 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007595 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007596 }
7597#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007598#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007599 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007600 {
7601 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007602 char_u *q = curwin->w_s->b_p_spl;
7603
7604 /* Skip the first name if it is "cjk". */
7605 if (STRNCMP(q, "cjk,", 4) == 0)
7606 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007607
7608 /*
7609 * Source the spell/LANG.vim in 'runtimepath'.
7610 * They could set 'spellcapcheck' depending on the language.
7611 * Use the first name in 'spelllang' up to '_region' or
7612 * '.encoding'.
7613 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007614 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007615 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7616 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007617 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007618 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007619 }
7620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621 }
7622
7623#ifdef FEAT_MOUSE
7624 if (varp == &p_mouse)
7625 {
7626# ifdef FEAT_MOUSE_TTY
7627 if (*p_mouse == NUL)
7628 mch_setmouse(FALSE); /* switch mouse off */
7629 else
7630# endif
7631 setmouse(); /* in case 'mouse' changed */
7632 }
7633#endif
7634
Bram Moolenaar913077c2012-03-28 19:59:04 +02007635 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007636 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007637 curwin->w_set_curswant = TRUE;
7638
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007639#ifdef FEAT_GUI
7640 /* check redraw when it's not a GUI option or the GUI is active. */
7641 if (!redraw_gui_only || gui.in_use)
7642#endif
7643 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007644
7645 return errmsg;
7646}
7647
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007648#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007649/*
7650 * Simple int comparison function for use with qsort()
7651 */
7652 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007653int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007654{
7655 return *(const int *)a - *(const int *)b;
7656}
7657
7658/*
7659 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7660 * Returns error message, NULL if it's OK.
7661 */
7662 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007663check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007664{
7665 char_u *s;
7666 int col;
7667 int count = 0;
7668 int color_cols[256];
7669 int i;
7670 int j = 0;
7671
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007672 if (wp->w_buffer == NULL)
7673 return NULL; /* buffer was closed */
7674
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007675 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007676 {
7677 if (*s == '-' || *s == '+')
7678 {
7679 /* -N and +N: add to 'textwidth' */
7680 col = (*s == '-') ? -1 : 1;
7681 ++s;
7682 if (!VIM_ISDIGIT(*s))
7683 return e_invarg;
7684 col = col * getdigits(&s);
7685 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007686 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007687 col += wp->w_buffer->b_p_tw;
7688 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007689 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007690 }
7691 else if (VIM_ISDIGIT(*s))
7692 col = getdigits(&s);
7693 else
7694 return e_invarg;
7695 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007696skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007697 if (*s == NUL)
7698 break;
7699 if (*s != ',')
7700 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007701 if (*++s == NUL)
7702 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007703 }
7704
7705 vim_free(wp->w_p_cc_cols);
7706 if (count == 0)
7707 wp->w_p_cc_cols = NULL;
7708 else
7709 {
7710 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7711 if (wp->w_p_cc_cols != NULL)
7712 {
7713 /* sort the columns for faster usage on screen redraw inside
7714 * win_line() */
7715 qsort(color_cols, count, sizeof(int), int_cmp);
7716
7717 for (i = 0; i < count; ++i)
7718 /* skip duplicates */
7719 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7720 wp->w_p_cc_cols[j++] = color_cols[i];
7721 wp->w_p_cc_cols[j] = -1; /* end marker */
7722 }
7723 }
7724
7725 return NULL; /* no error */
7726}
7727#endif
7728
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729/*
7730 * Handle setting 'listchars' or 'fillchars'.
7731 * Returns error message, NULL if it's OK.
7732 */
7733 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007734set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735{
7736 int round, i, len, entries;
7737 char_u *p, *s;
7738 int c1, c2 = 0;
7739 struct charstab
7740 {
7741 int *cp;
7742 char *name;
7743 };
7744#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7745 static struct charstab filltab[] =
7746 {
7747 {&fill_stl, "stl"},
7748 {&fill_stlnc, "stlnc"},
7749 {&fill_vert, "vert"},
7750 {&fill_fold, "fold"},
7751 {&fill_diff, "diff"},
7752 };
7753#endif
7754 static struct charstab lcstab[] =
7755 {
7756 {&lcs_eol, "eol"},
7757 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007758 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007760 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761 {&lcs_tab2, "tab"},
7762 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007763#ifdef FEAT_CONCEAL
7764 {&lcs_conceal, "conceal"},
7765#else
7766 {NULL, "conceal"},
7767#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007768 };
7769 struct charstab *tab;
7770
7771#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7772 if (varp == &p_lcs)
7773#endif
7774 {
7775 tab = lcstab;
7776 entries = sizeof(lcstab) / sizeof(struct charstab);
7777 }
7778#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7779 else
7780 {
7781 tab = filltab;
7782 entries = sizeof(filltab) / sizeof(struct charstab);
7783 }
7784#endif
7785
7786 /* first round: check for valid value, second round: assign values */
7787 for (round = 0; round <= 1; ++round)
7788 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007789 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007790 {
7791 /* After checking that the value is valid: set defaults: space for
7792 * 'fillchars', NUL for 'listchars' */
7793 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007794 if (tab[i].cp != NULL)
7795 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007796 if (varp == &p_lcs)
7797 lcs_tab1 = NUL;
7798#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7799 else
7800 fill_diff = '-';
7801#endif
7802 }
7803 p = *varp;
7804 while (*p)
7805 {
7806 for (i = 0; i < entries; ++i)
7807 {
7808 len = (int)STRLEN(tab[i].name);
7809 if (STRNCMP(p, tab[i].name, len) == 0
7810 && p[len] == ':'
7811 && p[len + 1] != NUL)
7812 {
7813 s = p + len + 1;
7814#ifdef FEAT_MBYTE
7815 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007816 if (mb_char2cells(c1) > 1)
7817 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818#else
7819 c1 = *s++;
7820#endif
7821 if (tab[i].cp == &lcs_tab2)
7822 {
7823 if (*s == NUL)
7824 continue;
7825#ifdef FEAT_MBYTE
7826 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007827 if (mb_char2cells(c2) > 1)
7828 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007829#else
7830 c2 = *s++;
7831#endif
7832 }
7833 if (*s == ',' || *s == NUL)
7834 {
7835 if (round)
7836 {
7837 if (tab[i].cp == &lcs_tab2)
7838 {
7839 lcs_tab1 = c1;
7840 lcs_tab2 = c2;
7841 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007842 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007843 *(tab[i].cp) = c1;
7844
7845 }
7846 p = s;
7847 break;
7848 }
7849 }
7850 }
7851
7852 if (i == entries)
7853 return e_invarg;
7854 if (*p == ',')
7855 ++p;
7856 }
7857 }
7858
7859 return NULL; /* no error */
7860}
7861
7862#ifdef FEAT_STL_OPT
7863/*
7864 * Check validity of options with the 'statusline' format.
7865 * Return error message or NULL.
7866 */
7867 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007868check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869{
7870 int itemcnt = 0;
7871 int groupdepth = 0;
7872 static char_u errbuf[80];
7873
7874 while (*s && itemcnt < STL_MAX_ITEM)
7875 {
7876 /* Check for valid keys after % sequences */
7877 while (*s && *s != '%')
7878 s++;
7879 if (!*s)
7880 break;
7881 s++;
7882 if (*s != '%' && *s != ')')
7883 ++itemcnt;
7884 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7885 {
7886 s++;
7887 continue;
7888 }
7889 if (*s == ')')
7890 {
7891 s++;
7892 if (--groupdepth < 0)
7893 break;
7894 continue;
7895 }
7896 if (*s == '-')
7897 s++;
7898 while (VIM_ISDIGIT(*s))
7899 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007900 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901 continue;
7902 if (*s == '.')
7903 {
7904 s++;
7905 while (*s && VIM_ISDIGIT(*s))
7906 s++;
7907 }
7908 if (*s == '(')
7909 {
7910 groupdepth++;
7911 continue;
7912 }
7913 if (vim_strchr(STL_ALL, *s) == NULL)
7914 {
7915 return illegal_char(errbuf, *s);
7916 }
7917 if (*s == '{')
7918 {
7919 s++;
7920 while (*s != '}' && *s)
7921 s++;
7922 if (*s != '}')
7923 return (char_u *)N_("E540: Unclosed expression sequence");
7924 }
7925 }
7926 if (itemcnt >= STL_MAX_ITEM)
7927 return (char_u *)N_("E541: too many items");
7928 if (groupdepth != 0)
7929 return (char_u *)N_("E542: unbalanced groups");
7930 return NULL;
7931}
7932#endif
7933
7934#ifdef FEAT_CLIPBOARD
7935/*
7936 * Extract the items in the 'clipboard' option and set global values.
7937 */
7938 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007939check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007940{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007941 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007942 int new_autoselect_star = FALSE;
7943 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007945 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946 regprog_T *new_exclude_prog = NULL;
7947 char_u *errmsg = NULL;
7948 char_u *p;
7949
7950 for (p = p_cb; *p != NUL; )
7951 {
7952 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7953 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007954 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007955 p += 7;
7956 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007957 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007958 && (p[11] == ',' || p[11] == NUL))
7959 {
7960 new_unnamed |= CLIP_UNNAMED_PLUS;
7961 p += 11;
7962 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007964 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007965 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007966 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 p += 10;
7968 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007969 else if (STRNCMP(p, "autoselectplus", 14) == 0
7970 && (p[14] == ',' || p[14] == NUL))
7971 {
7972 new_autoselect_plus = TRUE;
7973 p += 14;
7974 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007975 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007976 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007977 {
7978 new_autoselectml = TRUE;
7979 p += 12;
7980 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007981 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7982 {
7983 new_html = TRUE;
7984 p += 4;
7985 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007986 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7987 {
7988 p += 8;
7989 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7990 if (new_exclude_prog == NULL)
7991 errmsg = e_invarg;
7992 break;
7993 }
7994 else
7995 {
7996 errmsg = e_invarg;
7997 break;
7998 }
7999 if (*p == ',')
8000 ++p;
8001 }
8002 if (errmsg == NULL)
8003 {
8004 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008005 clip_autoselect_star = new_autoselect_star;
8006 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008008 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008009 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008011#ifdef FEAT_GUI_GTK
8012 if (gui.in_use)
8013 {
8014 gui_gtk_set_selection_targets();
8015 gui_gtk_set_dnd_targets();
8016 }
8017#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018 }
8019 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008020 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021
8022 return errmsg;
8023}
8024#endif
8025
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008026#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008027 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008028did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008029{
8030 char_u *errmsg = NULL;
8031 win_T *wp;
8032 int l;
8033
8034 if (is_spellfile)
8035 {
8036 l = (int)STRLEN(curwin->w_s->b_p_spf);
8037 if (l > 0 && (l < 4
8038 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8039 errmsg = e_invarg;
8040 }
8041
8042 if (errmsg == NULL)
8043 {
8044 FOR_ALL_WINDOWS(wp)
8045 if (wp->w_buffer == curbuf && wp->w_p_spell)
8046 {
8047 errmsg = did_set_spelllang(wp);
8048# ifdef FEAT_WINDOWS
8049 break;
8050# endif
8051 }
8052 }
8053 return errmsg;
8054}
8055
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008056/*
8057 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8058 * Return error message when failed, NULL when OK.
8059 */
8060 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008061compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008062{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008063 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008064 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008065
Bram Moolenaar860cae12010-06-05 23:22:07 +02008066 if (*synblock->b_p_spc == NUL)
8067 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008068 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008069 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008070 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008071 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008072 if (re != NULL)
8073 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008074 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008075 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008076 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008077 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008078 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008079 return e_invarg;
8080 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008081 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008082 }
8083
Bram Moolenaar473de612013-06-08 18:19:48 +02008084 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008085 return NULL;
8086}
8087#endif
8088
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008089#if defined(FEAT_EVAL) || defined(PROTO)
8090/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008091 * Set the scriptID for an option, taking care of setting the buffer- or
8092 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008093 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008094 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008095set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008096{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008097 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8098 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008099
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008100 /* Remember where the option was set. For local options need to do that
8101 * in the buffer or window structure. */
8102 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008103 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008104 if (both || (opt_flags & OPT_LOCAL))
8105 {
8106 if (indir & PV_BUF)
8107 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8108 else if (indir & PV_WIN)
8109 curwin->w_p_scriptID[indir & PV_MASK] = id;
8110 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008111}
8112#endif
8113
Bram Moolenaar071d4272004-06-13 20:20:40 +00008114/*
8115 * Set the value of a boolean option, and take care of side effects.
8116 * Returns NULL for success, or an error message for an error.
8117 */
8118 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008119set_bool_option(
8120 int opt_idx, /* index in options[] table */
8121 char_u *varp, /* pointer to the option variable */
8122 int value, /* new value */
8123 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124{
8125 int old_value = *(int *)varp;
8126
Bram Moolenaar071d4272004-06-13 20:20:40 +00008127 /* Disallow changing some options from secure mode */
8128 if ((secure
8129#ifdef HAVE_SANDBOX
8130 || sandbox != 0
8131#endif
8132 ) && (options[opt_idx].flags & P_SECURE))
8133 return e_secure;
8134
8135 *(int *)varp = value; /* set the new value */
8136#ifdef FEAT_EVAL
8137 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008138 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008139#endif
8140
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008141#ifdef FEAT_GUI
8142 need_mouse_correct = TRUE;
8143#endif
8144
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145 /* May set global value for local option. */
8146 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8147 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8148
8149 /*
8150 * Handle side effects of changing a bool option.
8151 */
8152
8153 /* 'compatible' */
8154 if ((int *)varp == &p_cp)
8155 {
8156 compatible_set();
8157 }
8158
Bram Moolenaar920694c2016-08-21 17:45:02 +02008159#ifdef FEAT_LANGMAP
8160 if ((int *)varp == &p_lrm)
8161 /* 'langremap' -> !'langnoremap' */
8162 p_lnr = !p_lrm;
8163 else if ((int *)varp == &p_lnr)
8164 /* 'langnoremap' -> !'langremap' */
8165 p_lrm = !p_lnr;
8166#endif
8167
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008168#ifdef FEAT_PERSISTENT_UNDO
8169 /* 'undofile' */
8170 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8171 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008172 /* Only take action when the option was set. When reset we do not
8173 * delete the undo file, the option may be set again without making
8174 * any changes in between. */
8175 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008176 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008177 char_u hash[UNDO_HASH_SIZE];
8178 buf_T *save_curbuf = curbuf;
8179
Bram Moolenaar29323592016-07-24 22:04:11 +02008180 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008181 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008182 /* When 'undofile' is set globally: for every buffer, otherwise
8183 * only for the current buffer: Try to read in the undofile,
8184 * if one exists, the buffer wasn't changed and the buffer was
8185 * loaded */
8186 if ((curbuf == save_curbuf
8187 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8188 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8189 {
8190 u_compute_hash(hash);
8191 u_read_undo(NULL, hash, curbuf->b_fname);
8192 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008193 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008194 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008195 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008196 }
8197#endif
8198
Bram Moolenaar071d4272004-06-13 20:20:40 +00008199 else if ((int *)varp == &curbuf->b_p_ro)
8200 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008201 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8203 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008204
8205 /* when 'readonly' is set may give W10 again */
8206 if (curbuf->b_p_ro)
8207 curbuf->b_did_warn = FALSE;
8208
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008210 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008211#endif
8212 }
8213
Bram Moolenaar9c449722010-07-20 18:44:27 +02008214#ifdef FEAT_GUI
8215 else if ((int *)varp == &p_mh)
8216 {
8217 if (!p_mh)
8218 gui_mch_mousehide(FALSE);
8219 }
8220#endif
8221
Bram Moolenaara539df02010-08-01 14:35:05 +02008222#ifdef FEAT_TITLE
8223 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008224 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008225 {
8226 redraw_titles();
8227 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008228 /* when 'endofline' is changed, redraw the window title */
8229 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008230 {
8231 redraw_titles();
8232 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008233 /* when 'fixeol' is changed, redraw the window title */
8234 else if ((int *)varp == &curbuf->b_p_fixeol)
8235 {
8236 redraw_titles();
8237 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008238# ifdef FEAT_MBYTE
8239 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008240 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008241 {
8242 redraw_titles();
8243 }
8244# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245#endif
8246
8247 /* when 'bin' is set also set some other options */
8248 else if ((int *)varp == &curbuf->b_p_bin)
8249 {
8250 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8251#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008252 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008253#endif
8254 }
8255
8256#ifdef FEAT_AUTOCMD
8257 /* when 'buflisted' changes, trigger autocommands */
8258 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8259 {
8260 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8261 NULL, NULL, TRUE, curbuf);
8262 }
8263#endif
8264
8265 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8266 else if ((int *)varp == &curbuf->b_p_swf)
8267 {
8268 if (curbuf->b_p_swf && p_uc)
8269 ml_open_file(curbuf); /* create the swap file */
8270 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008271 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8272 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008273 mf_close_file(curbuf, TRUE); /* remove the swap file */
8274 }
8275
8276 /* when 'terse' is set change 'shortmess' */
8277 else if ((int *)varp == &p_terse)
8278 {
8279 char_u *p;
8280
8281 p = vim_strchr(p_shm, SHM_SEARCH);
8282
8283 /* insert 's' in p_shm */
8284 if (p_terse && p == NULL)
8285 {
8286 STRCPY(IObuff, p_shm);
8287 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008288 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289 }
8290 /* remove 's' from p_shm */
8291 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008292 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008293 }
8294
8295 /* when 'paste' is set or reset also change other options */
8296 else if ((int *)varp == &p_paste)
8297 {
8298 paste_option_changed();
8299 }
8300
8301 /* when 'insertmode' is set from an autocommand need to do work here */
8302 else if ((int *)varp == &p_im)
8303 {
8304 if (p_im)
8305 {
8306 if ((State & INSERT) == 0)
8307 need_start_insertmode = TRUE;
8308 stop_insert_mode = FALSE;
8309 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008310 /* only reset if it was set previously */
8311 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008312 {
8313 need_start_insertmode = FALSE;
8314 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008315 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 clear_cmdline = TRUE; /* remove "(insert)" */
8317 restart_edit = 0;
8318 }
8319 }
8320
8321 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8322 else if ((int *)varp == &p_ic && p_hls)
8323 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008324 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008325 }
8326
8327#ifdef FEAT_SEARCH_EXTRA
8328 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8329 else if ((int *)varp == &p_hls)
8330 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008331 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008332 }
8333#endif
8334
8335#ifdef FEAT_SCROLLBIND
8336 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8337 * at the end of normal_cmd() */
8338 else if ((int *)varp == &curwin->w_p_scb)
8339 {
8340 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008341 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008342 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008343 curwin->w_scbind_pos = curwin->w_topline;
8344 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 }
8346#endif
8347
8348#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8349 /* There can be only one window with 'previewwindow' set. */
8350 else if ((int *)varp == &curwin->w_p_pvw)
8351 {
8352 if (curwin->w_p_pvw)
8353 {
8354 win_T *win;
8355
Bram Moolenaar29323592016-07-24 22:04:11 +02008356 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008357 if (win->w_p_pvw && win != curwin)
8358 {
8359 curwin->w_p_pvw = FALSE;
8360 return (char_u *)N_("E590: A preview window already exists");
8361 }
8362 }
8363 }
8364#endif
8365
8366 /* when 'textmode' is set or reset also change 'fileformat' */
8367 else if ((int *)varp == &curbuf->b_p_tx)
8368 {
8369 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8370 }
8371
8372 /* when 'textauto' is set or reset also change 'fileformats' */
8373 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008374 set_string_option_direct((char_u *)"ffs", -1,
8375 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008376 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008377
8378 /*
8379 * When 'lisp' option changes include/exclude '-' in
8380 * keyword characters.
8381 */
8382#ifdef FEAT_LISP
8383 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8384 {
8385 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8386 }
8387#endif
8388
8389#ifdef FEAT_TITLE
8390 /* when 'title' changed, may need to change the title; same for 'icon' */
8391 else if ((int *)varp == &p_title)
8392 {
8393 did_set_title(FALSE);
8394 }
8395
8396 else if ((int *)varp == &p_icon)
8397 {
8398 did_set_title(TRUE);
8399 }
8400#endif
8401
8402 else if ((int *)varp == &curbuf->b_changed)
8403 {
8404 if (!value)
8405 save_file_ff(curbuf); /* Buffer is unchanged */
8406#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008407 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408#endif
8409#ifdef FEAT_AUTOCMD
8410 modified_was_set = value;
8411#endif
8412 }
8413
8414#ifdef BACKSLASH_IN_FILENAME
8415 else if ((int *)varp == &p_ssl)
8416 {
8417 if (p_ssl)
8418 {
8419 psepc = '/';
8420 psepcN = '\\';
8421 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008422 }
8423 else
8424 {
8425 psepc = '\\';
8426 psepcN = '/';
8427 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428 }
8429
8430 /* need to adjust the file name arguments and buffer names. */
8431 buflist_slash_adjust();
8432 alist_slash_adjust();
8433# ifdef FEAT_EVAL
8434 scriptnames_slash_adjust();
8435# endif
8436 }
8437#endif
8438
8439 /* If 'wrap' is set, set w_leftcol to zero. */
8440 else if ((int *)varp == &curwin->w_p_wrap)
8441 {
8442 if (curwin->w_p_wrap)
8443 curwin->w_leftcol = 0;
8444 }
8445
8446#ifdef FEAT_WINDOWS
8447 else if ((int *)varp == &p_ea)
8448 {
8449 if (p_ea && !old_value)
8450 win_equal(curwin, FALSE, 0);
8451 }
8452#endif
8453
8454 else if ((int *)varp == &p_wiv)
8455 {
8456 /*
8457 * When 'weirdinvert' changed, set/reset 't_xs'.
8458 * Then set 'weirdinvert' according to value of 't_xs'.
8459 */
8460 if (p_wiv && !old_value)
8461 T_XS = (char_u *)"y";
8462 else if (!p_wiv && old_value)
8463 T_XS = empty_option;
8464 p_wiv = (*T_XS != NUL);
8465 }
8466
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008467#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008468 else if ((int *)varp == &p_beval)
8469 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008470 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008472 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 gui_mch_disable_beval_area(balloonEval);
8474 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008475#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008476
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008477#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008478 else if ((int *)varp == &p_acd)
8479 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008480 /* Change directories when the 'acd' option is set now. */
8481 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008482 }
8483#endif
8484
8485#ifdef FEAT_DIFF
8486 /* 'diff' */
8487 else if ((int *)varp == &curwin->w_p_diff)
8488 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008489 /* May add or remove the buffer from the list of diff buffers. */
8490 diff_buf_adjust(curwin);
8491# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492 if (foldmethodIsDiff(curwin))
8493 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008494# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495 }
8496#endif
8497
8498#ifdef USE_IM_CONTROL
8499 /* 'imdisable' */
8500 else if ((int *)varp == &p_imdisable)
8501 {
8502 /* Only de-activate it here, it will be enabled when changing mode. */
8503 if (p_imdisable)
8504 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008505 else if (State & INSERT)
8506 /* When the option is set from an autocommand, it may need to take
8507 * effect right away. */
8508 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008509 }
8510#endif
8511
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008512#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008513 /* 'spell' */
8514 else if ((int *)varp == &curwin->w_p_spell)
8515 {
8516 if (curwin->w_p_spell)
8517 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008518 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008519 if (errmsg != NULL)
8520 EMSG(_(errmsg));
8521 }
8522 }
8523#endif
8524
Bram Moolenaar071d4272004-06-13 20:20:40 +00008525#ifdef FEAT_FKMAP
8526 else if ((int *)varp == &p_altkeymap)
8527 {
8528 if (old_value != p_altkeymap)
8529 {
8530 if (!p_altkeymap)
8531 {
8532 p_hkmap = p_fkmap;
8533 p_fkmap = 0;
8534 }
8535 else
8536 {
8537 p_fkmap = p_hkmap;
8538 p_hkmap = 0;
8539 }
8540 (void)init_chartab();
8541 }
8542 }
8543
8544 /*
8545 * In case some second language keymapping options have changed, check
8546 * and correct the setting in a consistent way.
8547 */
8548
8549 /*
8550 * If hkmap or fkmap are set, reset Arabic keymapping.
8551 */
8552 if ((p_hkmap || p_fkmap) && p_altkeymap)
8553 {
8554 p_altkeymap = p_fkmap;
8555# ifdef FEAT_ARABIC
8556 curwin->w_p_arab = FALSE;
8557# endif
8558 (void)init_chartab();
8559 }
8560
8561 /*
8562 * If hkmap set, reset Farsi keymapping.
8563 */
8564 if (p_hkmap && p_altkeymap)
8565 {
8566 p_altkeymap = 0;
8567 p_fkmap = 0;
8568# ifdef FEAT_ARABIC
8569 curwin->w_p_arab = FALSE;
8570# endif
8571 (void)init_chartab();
8572 }
8573
8574 /*
8575 * If fkmap set, reset Hebrew keymapping.
8576 */
8577 if (p_fkmap && !p_altkeymap)
8578 {
8579 p_altkeymap = 1;
8580 p_hkmap = 0;
8581# ifdef FEAT_ARABIC
8582 curwin->w_p_arab = FALSE;
8583# endif
8584 (void)init_chartab();
8585 }
8586#endif
8587
8588#ifdef FEAT_ARABIC
8589 if ((int *)varp == &curwin->w_p_arab)
8590 {
8591 if (curwin->w_p_arab)
8592 {
8593 /*
8594 * 'arabic' is set, handle various sub-settings.
8595 */
8596 if (!p_tbidi)
8597 {
8598 /* set rightleft mode */
8599 if (!curwin->w_p_rl)
8600 {
8601 curwin->w_p_rl = TRUE;
8602 changed_window_setting();
8603 }
8604
8605 /* Enable Arabic shaping (major part of what Arabic requires) */
8606 if (!p_arshape)
8607 {
8608 p_arshape = TRUE;
8609 redraw_later_clear();
8610 }
8611 }
8612
8613 /* Arabic requires a utf-8 encoding, inform the user if its not
8614 * set. */
8615 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008616 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008617 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8618
Bram Moolenaar8820b482017-03-16 17:23:31 +01008619 msg_source(HL_ATTR(HLF_W));
8620 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008621#ifdef FEAT_EVAL
8622 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8623#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008624 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625
8626# ifdef FEAT_MBYTE
8627 /* set 'delcombine' */
8628 p_deco = TRUE;
8629# endif
8630
8631# ifdef FEAT_KEYMAP
8632 /* Force-set the necessary keymap for arabic */
8633 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8634 OPT_LOCAL);
8635# endif
8636# ifdef FEAT_FKMAP
8637 p_altkeymap = 0;
8638 p_hkmap = 0;
8639 p_fkmap = 0;
8640 (void)init_chartab();
8641# endif
8642 }
8643 else
8644 {
8645 /*
8646 * 'arabic' is reset, handle various sub-settings.
8647 */
8648 if (!p_tbidi)
8649 {
8650 /* reset rightleft mode */
8651 if (curwin->w_p_rl)
8652 {
8653 curwin->w_p_rl = FALSE;
8654 changed_window_setting();
8655 }
8656
8657 /* 'arabicshape' isn't reset, it is a global option and
8658 * another window may still need it "on". */
8659 }
8660
8661 /* 'delcombine' isn't reset, it is a global option and another
8662 * window may still want it "on". */
8663
8664# ifdef FEAT_KEYMAP
8665 /* Revert to the default keymap */
8666 curbuf->b_p_iminsert = B_IMODE_NONE;
8667 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8668# endif
8669 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008670 }
8671
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008672#endif
8673
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008674#ifdef FEAT_TERMGUICOLORS
8675 /* 'termguicolors' */
8676 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008677 {
8678# ifdef FEAT_GUI
8679 if (!gui.in_use && !gui.starting)
8680# endif
8681 highlight_gui_started();
8682 }
8683#endif
8684
Bram Moolenaar071d4272004-06-13 20:20:40 +00008685 /*
8686 * End of handling side effects for bool options.
8687 */
8688
Bram Moolenaar53744302015-07-17 17:38:22 +02008689 /* after handling side effects, call autocommand */
8690
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691 options[opt_idx].flags |= P_WAS_SET;
8692
Bram Moolenaar53744302015-07-17 17:38:22 +02008693#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8694 if (!starting)
8695 {
8696 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008697 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8698 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8699 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008700 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8701 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8702 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8703 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8704 reset_v_option_vars();
8705 }
8706#endif
8707
Bram Moolenaar071d4272004-06-13 20:20:40 +00008708 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008709 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008710 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008711 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008712 check_redraw(options[opt_idx].flags);
8713
8714 return NULL;
8715}
8716
8717/*
8718 * Set the value of a number option, and take care of side effects.
8719 * Returns NULL for success, or an error message for an error.
8720 */
8721 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008722set_num_option(
8723 int opt_idx, /* index in options[] table */
8724 char_u *varp, /* pointer to the option variable */
8725 long value, /* new value */
8726 char_u *errbuf, /* buffer for error messages */
8727 size_t errbuflen, /* length of "errbuf" */
8728 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729 OPT_MODELINE */
8730{
8731 char_u *errmsg = NULL;
8732 long old_value = *(long *)varp;
8733 long old_Rows = Rows; /* remember old Rows */
8734 long old_Columns = Columns; /* remember old Columns */
8735 long *pp = (long *)varp;
8736
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008737 /* Disallow changing some options from secure mode. */
8738 if ((secure
8739#ifdef HAVE_SANDBOX
8740 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008741#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008742 ) && (options[opt_idx].flags & P_SECURE))
8743 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008744
8745 *pp = value;
8746#ifdef FEAT_EVAL
8747 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008748 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008749#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008750#ifdef FEAT_GUI
8751 need_mouse_correct = TRUE;
8752#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008753
Bram Moolenaar14f24742012-08-08 18:01:05 +02008754 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755 {
8756 errmsg = e_positive;
8757 curbuf->b_p_sw = curbuf->b_p_ts;
8758 }
8759
8760 /*
8761 * Number options that need some action when changed
8762 */
8763#ifdef FEAT_WINDOWS
8764 if (pp == &p_wh || pp == &p_hh)
8765 {
8766 if (p_wh < 1)
8767 {
8768 errmsg = e_positive;
8769 p_wh = 1;
8770 }
8771 if (p_wmh > p_wh)
8772 {
8773 errmsg = e_winheight;
8774 p_wh = p_wmh;
8775 }
8776 if (p_hh < 0)
8777 {
8778 errmsg = e_positive;
8779 p_hh = 0;
8780 }
8781
8782 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008783 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008784 {
8785 if (pp == &p_wh && curwin->w_height < p_wh)
8786 win_setheight((int)p_wh);
8787 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8788 win_setheight((int)p_hh);
8789 }
8790 }
8791
8792 /* 'winminheight' */
8793 else if (pp == &p_wmh)
8794 {
8795 if (p_wmh < 0)
8796 {
8797 errmsg = e_positive;
8798 p_wmh = 0;
8799 }
8800 if (p_wmh > p_wh)
8801 {
8802 errmsg = e_winheight;
8803 p_wmh = p_wh;
8804 }
8805 win_setminheight();
8806 }
8807
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008808# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008809 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008810 {
8811 if (p_wiw < 1)
8812 {
8813 errmsg = e_positive;
8814 p_wiw = 1;
8815 }
8816 if (p_wmw > p_wiw)
8817 {
8818 errmsg = e_winwidth;
8819 p_wiw = p_wmw;
8820 }
8821
8822 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008823 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008824 win_setwidth((int)p_wiw);
8825 }
8826
8827 /* 'winminwidth' */
8828 else if (pp == &p_wmw)
8829 {
8830 if (p_wmw < 0)
8831 {
8832 errmsg = e_positive;
8833 p_wmw = 0;
8834 }
8835 if (p_wmw > p_wiw)
8836 {
8837 errmsg = e_winwidth;
8838 p_wmw = p_wiw;
8839 }
8840 win_setminheight();
8841 }
8842# endif
8843
8844#endif
8845
8846#ifdef FEAT_WINDOWS
8847 /* (re)set last window status line */
8848 else if (pp == &p_ls)
8849 {
8850 last_status(FALSE);
8851 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008852
8853 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008854 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008855 {
8856 shell_new_rows(); /* recompute window positions and heights */
8857 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858#endif
8859
8860#ifdef FEAT_GUI
8861 else if (pp == &p_linespace)
8862 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008863 /* Recompute gui.char_height and resize the Vim window to keep the
8864 * same number of lines. */
8865 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008866 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008867 }
8868#endif
8869
8870#ifdef FEAT_FOLDING
8871 /* 'foldlevel' */
8872 else if (pp == &curwin->w_p_fdl)
8873 {
8874 if (curwin->w_p_fdl < 0)
8875 curwin->w_p_fdl = 0;
8876 newFoldLevel();
8877 }
8878
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008879 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880 else if (pp == &curwin->w_p_fml)
8881 {
8882 foldUpdateAll(curwin);
8883 }
8884
8885 /* 'foldnestmax' */
8886 else if (pp == &curwin->w_p_fdn)
8887 {
8888 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8889 foldUpdateAll(curwin);
8890 }
8891
8892 /* 'foldcolumn' */
8893 else if (pp == &curwin->w_p_fdc)
8894 {
8895 if (curwin->w_p_fdc < 0)
8896 {
8897 errmsg = e_positive;
8898 curwin->w_p_fdc = 0;
8899 }
8900 else if (curwin->w_p_fdc > 12)
8901 {
8902 errmsg = e_invarg;
8903 curwin->w_p_fdc = 12;
8904 }
8905 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008906#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008908#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008909 /* 'shiftwidth' or 'tabstop' */
8910 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8911 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008912# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913 if (foldmethodIsIndent(curwin))
8914 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008915# endif
8916# ifdef FEAT_CINDENT
8917 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8918 * parse 'cinoptions'. */
8919 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8920 parse_cino(curbuf);
8921# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008923#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008925#ifdef FEAT_MBYTE
8926 /* 'maxcombine' */
8927 else if (pp == &p_mco)
8928 {
8929 if (p_mco > MAX_MCO)
8930 p_mco = MAX_MCO;
8931 else if (p_mco < 0)
8932 p_mco = 0;
8933 screenclear(); /* will re-allocate the screen */
8934 }
8935#endif
8936
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937 else if (pp == &curbuf->b_p_iminsert)
8938 {
8939 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8940 {
8941 errmsg = e_invarg;
8942 curbuf->b_p_iminsert = B_IMODE_NONE;
8943 }
8944 p_iminsert = curbuf->b_p_iminsert;
8945 if (termcap_active) /* don't do this in the alternate screen */
8946 showmode();
8947#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8948 /* Show/unshow value of 'keymap' in status lines. */
8949 status_redraw_curbuf();
8950#endif
8951 }
8952
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008953 else if (pp == &p_window)
8954 {
8955 if (p_window < 1)
8956 p_window = 1;
8957 else if (p_window >= Rows)
8958 p_window = Rows - 1;
8959 }
8960
Bram Moolenaar071d4272004-06-13 20:20:40 +00008961 else if (pp == &curbuf->b_p_imsearch)
8962 {
8963 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8964 {
8965 errmsg = e_invarg;
8966 curbuf->b_p_imsearch = B_IMODE_NONE;
8967 }
8968 p_imsearch = curbuf->b_p_imsearch;
8969 }
8970
8971#ifdef FEAT_TITLE
8972 /* if 'titlelen' has changed, redraw the title */
8973 else if (pp == &p_titlelen)
8974 {
8975 if (p_titlelen < 0)
8976 {
8977 errmsg = e_positive;
8978 p_titlelen = 85;
8979 }
8980 if (starting != NO_SCREEN && old_value != p_titlelen)
8981 need_maketitle = TRUE;
8982 }
8983#endif
8984
8985 /* if p_ch changed value, change the command line height */
8986 else if (pp == &p_ch)
8987 {
8988 if (p_ch < 1)
8989 {
8990 errmsg = e_positive;
8991 p_ch = 1;
8992 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008993 if (p_ch > Rows - min_rows() + 1)
8994 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995
8996 /* Only compute the new window layout when startup has been
8997 * completed. Otherwise the frame sizes may be wrong. */
8998 if (p_ch != old_value && full_screen
8999#ifdef FEAT_GUI
9000 && !gui.starting
9001#endif
9002 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009003 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009004 }
9005
9006 /* when 'updatecount' changes from zero to non-zero, open swap files */
9007 else if (pp == &p_uc)
9008 {
9009 if (p_uc < 0)
9010 {
9011 errmsg = e_positive;
9012 p_uc = 100;
9013 }
9014 if (p_uc && !old_value)
9015 ml_open_files();
9016 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009017#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009018 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009019 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009020 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009021 {
9022 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009023 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009024 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009025 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009026 {
9027 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009028 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009029 }
9030 }
9031#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009032#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009033 else if (pp == &p_mzq)
9034 mzvim_reset_timer();
9035#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009036
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009037#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9038 /* 'pyxversion' */
9039 else if (pp == &p_pyx)
9040 {
9041 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9042 errmsg = e_invarg;
9043 }
9044#endif
9045
Bram Moolenaar071d4272004-06-13 20:20:40 +00009046 /* sync undo before 'undolevels' changes */
9047 else if (pp == &p_ul)
9048 {
9049 /* use the old value, otherwise u_sync() may not work properly */
9050 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009051 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009052 p_ul = value;
9053 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009054 else if (pp == &curbuf->b_p_ul)
9055 {
9056 /* use the old value, otherwise u_sync() may not work properly */
9057 curbuf->b_p_ul = old_value;
9058 u_sync(TRUE);
9059 curbuf->b_p_ul = value;
9060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009061
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009062#ifdef FEAT_LINEBREAK
9063 /* 'numberwidth' must be positive */
9064 else if (pp == &curwin->w_p_nuw)
9065 {
9066 if (curwin->w_p_nuw < 1)
9067 {
9068 errmsg = e_positive;
9069 curwin->w_p_nuw = 1;
9070 }
9071 if (curwin->w_p_nuw > 10)
9072 {
9073 errmsg = e_invarg;
9074 curwin->w_p_nuw = 10;
9075 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009076 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009077 }
9078#endif
9079
Bram Moolenaar1a384422010-07-14 19:53:30 +02009080 else if (pp == &curbuf->b_p_tw)
9081 {
9082 if (curbuf->b_p_tw < 0)
9083 {
9084 errmsg = e_positive;
9085 curbuf->b_p_tw = 0;
9086 }
9087#ifdef FEAT_SYN_HL
9088# ifdef FEAT_WINDOWS
9089 {
9090 win_T *wp;
9091 tabpage_T *tp;
9092
9093 FOR_ALL_TAB_WINDOWS(tp, wp)
9094 check_colorcolumn(wp);
9095 }
9096# else
9097 check_colorcolumn(curwin);
9098# endif
9099#endif
9100 }
9101
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102 /*
9103 * Check the bounds for numeric options here
9104 */
9105 if (Rows < min_rows() && full_screen)
9106 {
9107 if (errbuf != NULL)
9108 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009109 vim_snprintf((char *)errbuf, errbuflen,
9110 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 errmsg = errbuf;
9112 }
9113 Rows = min_rows();
9114 }
9115 if (Columns < MIN_COLUMNS && full_screen)
9116 {
9117 if (errbuf != NULL)
9118 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009119 vim_snprintf((char *)errbuf, errbuflen,
9120 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121 errmsg = errbuf;
9122 }
9123 Columns = MIN_COLUMNS;
9124 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009125 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009126
Bram Moolenaar071d4272004-06-13 20:20:40 +00009127 /*
9128 * If the screen (shell) height has been changed, assume it is the
9129 * physical screenheight.
9130 */
9131 if (old_Rows != Rows || old_Columns != Columns)
9132 {
9133 /* Changing the screen size is not allowed while updating the screen. */
9134 if (updating_screen)
9135 *pp = old_value;
9136 else if (full_screen
9137#ifdef FEAT_GUI
9138 && !gui.starting
9139#endif
9140 )
9141 set_shellsize((int)Columns, (int)Rows, TRUE);
9142 else
9143 {
9144 /* Postpone the resizing; check the size and cmdline position for
9145 * messages. */
9146 check_shellsize();
9147 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9148 cmdline_row = Rows - p_ch;
9149 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009150 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009151 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009152 }
9153
Bram Moolenaar071d4272004-06-13 20:20:40 +00009154 if (curbuf->b_p_ts <= 0)
9155 {
9156 errmsg = e_positive;
9157 curbuf->b_p_ts = 8;
9158 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009159 if (p_tm < 0)
9160 {
9161 errmsg = e_positive;
9162 p_tm = 0;
9163 }
9164 if ((curwin->w_p_scr <= 0
9165 || (curwin->w_p_scr > curwin->w_height
9166 && curwin->w_height > 0))
9167 && full_screen)
9168 {
9169 if (pp == &(curwin->w_p_scr))
9170 {
9171 if (curwin->w_p_scr != 0)
9172 errmsg = e_scroll;
9173 win_comp_scroll(curwin);
9174 }
9175 /* If 'scroll' became invalid because of a side effect silently adjust
9176 * it. */
9177 else if (curwin->w_p_scr <= 0)
9178 curwin->w_p_scr = 1;
9179 else /* curwin->w_p_scr > curwin->w_height */
9180 curwin->w_p_scr = curwin->w_height;
9181 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009182 if (p_hi < 0)
9183 {
9184 errmsg = e_positive;
9185 p_hi = 0;
9186 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009187 else if (p_hi > 10000)
9188 {
9189 errmsg = e_invarg;
9190 p_hi = 10000;
9191 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009192 if (p_re < 0 || p_re > 2)
9193 {
9194 errmsg = e_invarg;
9195 p_re = 0;
9196 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009197 if (p_report < 0)
9198 {
9199 errmsg = e_positive;
9200 p_report = 1;
9201 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009202 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009203 {
9204 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9205 p_sj = Rows / 2;
9206 else
9207 {
9208 errmsg = e_scroll;
9209 p_sj = 1;
9210 }
9211 }
9212 if (p_so < 0 && full_screen)
9213 {
9214 errmsg = e_scroll;
9215 p_so = 0;
9216 }
9217 if (p_siso < 0 && full_screen)
9218 {
9219 errmsg = e_positive;
9220 p_siso = 0;
9221 }
9222#ifdef FEAT_CMDWIN
9223 if (p_cwh < 1)
9224 {
9225 errmsg = e_positive;
9226 p_cwh = 1;
9227 }
9228#endif
9229 if (p_ut < 0)
9230 {
9231 errmsg = e_positive;
9232 p_ut = 2000;
9233 }
9234 if (p_ss < 0)
9235 {
9236 errmsg = e_positive;
9237 p_ss = 0;
9238 }
9239
9240 /* May set global value for local option. */
9241 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9242 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9243
9244 options[opt_idx].flags |= P_WAS_SET;
9245
Bram Moolenaar53744302015-07-17 17:38:22 +02009246#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9247 if (!starting && errmsg == NULL)
9248 {
9249 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009250 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9251 vim_snprintf((char *)buf_new, 10, "%ld", value);
9252 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009253 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9254 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9255 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9256 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9257 reset_v_option_vars();
9258 }
9259#endif
9260
Bram Moolenaar071d4272004-06-13 20:20:40 +00009261 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009262 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009263 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009264 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009265 check_redraw(options[opt_idx].flags);
9266
9267 return errmsg;
9268}
9269
9270/*
9271 * Called after an option changed: check if something needs to be redrawn.
9272 */
9273 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009274check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009275{
9276 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009277 int doclear = (flags & P_RCLR) == P_RCLR;
9278 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009279
9280#ifdef FEAT_WINDOWS
9281 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9282 status_redraw_all();
9283#endif
9284
9285 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9286 changed_window_setting();
9287 if (flags & P_RBUF)
9288 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009289 if (flags & P_RWINONLY)
9290 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009291 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009292 redraw_all_later(CLEAR);
9293 else if (all)
9294 redraw_all_later(NOT_VALID);
9295}
9296
9297/*
9298 * Find index for option 'arg'.
9299 * Return -1 if not found.
9300 */
9301 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009302findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009303{
9304 int opt_idx;
9305 char *s, *p;
9306 static short quick_tab[27] = {0, 0}; /* quick access table */
9307 int is_term_opt;
9308
9309 /*
9310 * For first call: Initialize the quick-access table.
9311 * It contains the index for the first option that starts with a certain
9312 * letter. There are 26 letters, plus the first "t_" option.
9313 */
9314 if (quick_tab[1] == 0)
9315 {
9316 p = options[0].fullname;
9317 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9318 {
9319 if (s[0] != p[0])
9320 {
9321 if (s[0] == 't' && s[1] == '_')
9322 quick_tab[26] = opt_idx;
9323 else
9324 quick_tab[CharOrdLow(s[0])] = opt_idx;
9325 }
9326 p = s;
9327 }
9328 }
9329
9330 /*
9331 * Check for name starting with an illegal character.
9332 */
9333#ifdef EBCDIC
9334 if (!islower(arg[0]))
9335#else
9336 if (arg[0] < 'a' || arg[0] > 'z')
9337#endif
9338 return -1;
9339
9340 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9341 if (is_term_opt)
9342 opt_idx = quick_tab[26];
9343 else
9344 opt_idx = quick_tab[CharOrdLow(arg[0])];
9345 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9346 {
9347 if (STRCMP(arg, s) == 0) /* match full name */
9348 break;
9349 }
9350 if (s == NULL && !is_term_opt)
9351 {
9352 opt_idx = quick_tab[CharOrdLow(arg[0])];
9353 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9354 {
9355 s = options[opt_idx].shortname;
9356 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9357 break;
9358 s = NULL;
9359 }
9360 }
9361 if (s == NULL)
9362 opt_idx = -1;
9363 return opt_idx;
9364}
9365
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009366#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009367/*
9368 * Get the value for an option.
9369 *
9370 * Returns:
9371 * Number or Toggle option: 1, *numval gets value.
9372 * String option: 0, *stringval gets allocated string.
9373 * Hidden Number or Toggle option: -1.
9374 * hidden String option: -2.
9375 * unknown option: -3.
9376 */
9377 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009378get_option_value(
9379 char_u *name,
9380 long *numval,
9381 char_u **stringval, /* NULL when only checking existence */
9382 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009383{
9384 int opt_idx;
9385 char_u *varp;
9386
9387 opt_idx = findoption(name);
9388 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009389 {
9390 int key;
9391
9392 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9393 && (key = find_key_option(name)) != 0)
9394 {
9395 char_u key_name[2];
9396 char_u *p;
9397
9398 if (key < 0)
9399 {
9400 key_name[0] = KEY2TERMCAP0(key);
9401 key_name[1] = KEY2TERMCAP1(key);
9402 }
9403 else
9404 {
9405 key_name[0] = KS_KEY;
9406 key_name[1] = (key & 0xff);
9407 }
9408 p = find_termcode(key_name);
9409 if (p != NULL)
9410 {
9411 if (stringval != NULL)
9412 *stringval = vim_strsave(p);
9413 return 0;
9414 }
9415 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009417 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418
9419 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9420
9421 if (options[opt_idx].flags & P_STRING)
9422 {
9423 if (varp == NULL) /* hidden option */
9424 return -2;
9425 if (stringval != NULL)
9426 {
9427#ifdef FEAT_CRYPT
9428 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009429 if ((char_u **)varp == &curbuf->b_p_key
9430 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009431 *stringval = vim_strsave((char_u *)"*****");
9432 else
9433#endif
9434 *stringval = vim_strsave(*(char_u **)(varp));
9435 }
9436 return 0;
9437 }
9438
9439 if (varp == NULL) /* hidden option */
9440 return -1;
9441 if (options[opt_idx].flags & P_NUM)
9442 *numval = *(long *)varp;
9443 else
9444 {
9445 /* Special case: 'modified' is b_changed, but we also want to consider
9446 * it set when 'ff' or 'fenc' changed. */
9447 if ((int *)varp == &curbuf->b_changed)
9448 *numval = curbufIsChanged();
9449 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009450 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009451 }
9452 return 1;
9453}
9454#endif
9455
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009456#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009457/*
9458 * Returns the option attributes and its value. Unlike the above function it
9459 * will return either global value or local value of the option depending on
9460 * what was requested, but it will never return global value if it was
9461 * requested to return local one and vice versa. Neither it will return
9462 * buffer-local value if it was requested to return window-local one.
9463 *
9464 * Pretends that option is absent if it is not present in the requested scope
9465 * (i.e. has no global, window-local or buffer-local value depending on
9466 * opt_type). Uses
9467 *
9468 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009469 * 0 hidden or unknown option, also option that does not have requested
9470 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009471 * see SOPT_* in vim.h for other flags
9472 *
9473 * Possible opt_type values: see SREQ_* in vim.h
9474 */
9475 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009476get_option_value_strict(
9477 char_u *name,
9478 long *numval,
9479 char_u **stringval, /* NULL when only obtaining attributes */
9480 int opt_type,
9481 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009482{
9483 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009484 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009485 struct vimoption *p;
9486 int r = 0;
9487
9488 opt_idx = findoption(name);
9489 if (opt_idx < 0)
9490 return 0;
9491
9492 p = &(options[opt_idx]);
9493
9494 /* Hidden option */
9495 if (p->var == NULL)
9496 return 0;
9497
9498 if (p->flags & P_BOOL)
9499 r |= SOPT_BOOL;
9500 else if (p->flags & P_NUM)
9501 r |= SOPT_NUM;
9502 else if (p->flags & P_STRING)
9503 r |= SOPT_STRING;
9504
9505 if (p->indir == PV_NONE)
9506 {
9507 if (opt_type == SREQ_GLOBAL)
9508 r |= SOPT_GLOBAL;
9509 else
9510 return 0; /* Did not request global-only option */
9511 }
9512 else
9513 {
9514 if (p->indir & PV_BOTH)
9515 r |= SOPT_GLOBAL;
9516 else if (opt_type == SREQ_GLOBAL)
9517 return 0; /* Requested global option */
9518
9519 if (p->indir & PV_WIN)
9520 {
9521 if (opt_type == SREQ_BUF)
9522 return 0; /* Did not request window-local option */
9523 else
9524 r |= SOPT_WIN;
9525 }
9526 else if (p->indir & PV_BUF)
9527 {
9528 if (opt_type == SREQ_WIN)
9529 return 0; /* Did not request buffer-local option */
9530 else
9531 r |= SOPT_BUF;
9532 }
9533 }
9534
9535 if (stringval == NULL)
9536 return r;
9537
9538 if (opt_type == SREQ_GLOBAL)
9539 varp = p->var;
9540 else
9541 {
9542 if (opt_type == SREQ_BUF)
9543 {
9544 /* Special case: 'modified' is b_changed, but we also want to
9545 * consider it set when 'ff' or 'fenc' changed. */
9546 if (p->indir == PV_MOD)
9547 {
9548 *numval = bufIsChanged((buf_T *) from);
9549 varp = NULL;
9550 }
9551#ifdef FEAT_CRYPT
9552 else if (p->indir == PV_KEY)
9553 {
9554 /* never return the value of the crypt key */
9555 *stringval = NULL;
9556 varp = NULL;
9557 }
9558#endif
9559 else
9560 {
9561 aco_save_T aco;
9562 aucmd_prepbuf(&aco, (buf_T *) from);
9563 varp = get_varp(p);
9564 aucmd_restbuf(&aco);
9565 }
9566 }
9567 else if (opt_type == SREQ_WIN)
9568 {
9569 win_T *save_curwin;
9570 save_curwin = curwin;
9571 curwin = (win_T *) from;
9572 curbuf = curwin->w_buffer;
9573 varp = get_varp(p);
9574 curwin = save_curwin;
9575 curbuf = curwin->w_buffer;
9576 }
9577 if (varp == p->var)
9578 return (r | SOPT_UNSET);
9579 }
9580
9581 if (varp != NULL)
9582 {
9583 if (p->flags & P_STRING)
9584 *stringval = vim_strsave(*(char_u **)(varp));
9585 else if (p->flags & P_NUM)
9586 *numval = *(long *) varp;
9587 else
9588 *numval = *(int *)varp;
9589 }
9590
9591 return r;
9592}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009593
9594/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009595 * Iterate over options. First argument is a pointer to a pointer to a
9596 * structure inside options[] array, second is option type like in the above
9597 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009598 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009599 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009600 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009601 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009602 * first argument to NULL.
9603 *
9604 * Returns full option name for current option on each call.
9605 */
9606 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009607option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009608{
9609 struct vimoption *ret = NULL;
9610 do
9611 {
9612 if (*option == NULL)
9613 *option = (void *) options;
9614 else if (((struct vimoption *) (*option))->fullname == NULL)
9615 {
9616 *option = NULL;
9617 return NULL;
9618 }
9619 else
9620 *option = (void *) (((struct vimoption *) (*option)) + 1);
9621
9622 ret = ((struct vimoption *) (*option));
9623
9624 /* Hidden option */
9625 if (ret->var == NULL)
9626 {
9627 ret = NULL;
9628 continue;
9629 }
9630
9631 switch (opt_type)
9632 {
9633 case SREQ_GLOBAL:
9634 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9635 ret = NULL;
9636 break;
9637 case SREQ_BUF:
9638 if (!(ret->indir & PV_BUF))
9639 ret = NULL;
9640 break;
9641 case SREQ_WIN:
9642 if (!(ret->indir & PV_WIN))
9643 ret = NULL;
9644 break;
9645 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009646 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009647 return NULL;
9648 }
9649 }
9650 while (ret == NULL);
9651
9652 return (char_u *)ret->fullname;
9653}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009654#endif
9655
Bram Moolenaar071d4272004-06-13 20:20:40 +00009656/*
9657 * Set the value of option "name".
9658 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009659 *
9660 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009661 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009662 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009663set_option_value(
9664 char_u *name,
9665 long number,
9666 char_u *string,
9667 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009668{
9669 int opt_idx;
9670 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009671 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009672
9673 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009674 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009675 {
9676 int key;
9677
9678 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9679 && (key = find_key_option(name)) != 0)
9680 {
9681 char_u key_name[2];
9682
9683 if (key < 0)
9684 {
9685 key_name[0] = KEY2TERMCAP0(key);
9686 key_name[1] = KEY2TERMCAP1(key);
9687 }
9688 else
9689 {
9690 key_name[0] = KS_KEY;
9691 key_name[1] = (key & 0xff);
9692 }
9693 add_termcode(key_name, string, FALSE);
9694 if (full_screen)
9695 ttest(FALSE);
9696 redraw_all_later(CLEAR);
9697 return NULL;
9698 }
9699
Bram Moolenaar071d4272004-06-13 20:20:40 +00009700 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009701 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009702 else
9703 {
9704 flags = options[opt_idx].flags;
9705#ifdef HAVE_SANDBOX
9706 /* Disallow changing some options in the sandbox */
9707 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009708 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009709 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009710 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009711 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009712#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009713 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009714 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715 else
9716 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009717 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009718 if (varp != NULL) /* hidden option is not changed */
9719 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009720 if (number == 0 && string != NULL)
9721 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009722 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009723
9724 /* Either we are given a string or we are setting option
9725 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009726 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009727 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009728 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009729 {
9730 /* There's another character after zeros or the string
9731 * is empty. In both cases, we are trying to set a
9732 * num option using a string. */
9733 EMSG3(_("E521: Number required: &%s = '%s'"),
9734 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009735 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009736
9737 }
9738 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009739 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009740 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009741 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009743 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009744 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009745 }
9746 }
9747 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009748 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009749}
9750
9751/*
9752 * Get the terminal code for a terminal option.
9753 * Returns NULL when not found.
9754 */
9755 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009756get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009757{
9758 int opt_idx;
9759 char_u *varp;
9760
9761 if (tname[0] != 't' || tname[1] != '_' ||
9762 tname[2] == NUL || tname[3] == NUL)
9763 return NULL;
9764 if ((opt_idx = findoption(tname)) >= 0)
9765 {
9766 varp = get_varp(&(options[opt_idx]));
9767 if (varp != NULL)
9768 varp = *(char_u **)(varp);
9769 return varp;
9770 }
9771 return find_termcode(tname + 2);
9772}
9773
9774 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009775get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009776{
9777 int i;
9778
9779 i = findoption((char_u *)"hl");
9780 if (i >= 0)
9781 return options[i].def_val[VI_DEFAULT];
9782 return (char_u *)NULL;
9783}
9784
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009785#if defined(FEAT_MBYTE) || defined(PROTO)
9786 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009787get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009788{
9789 int i;
9790
9791 i = findoption((char_u *)"enc");
9792 if (i >= 0)
9793 return options[i].def_val[VI_DEFAULT];
9794 return (char_u *)NULL;
9795}
9796#endif
9797
Bram Moolenaar071d4272004-06-13 20:20:40 +00009798/*
9799 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9800 */
9801 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009802find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009803{
9804 int key;
9805 int modifiers;
9806
9807 /*
9808 * Don't use get_special_key_code() for t_xx, we don't want it to call
9809 * add_termcap_entry().
9810 */
9811 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9812 key = TERMCAP2KEY(arg[2], arg[3]);
9813 else
9814 {
9815 --arg; /* put arg at the '<' */
9816 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009817 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009818 if (modifiers) /* can't handle modifiers here */
9819 key = 0;
9820 }
9821 return key;
9822}
9823
9824/*
9825 * if 'all' == 0: show changed options
9826 * if 'all' == 1: show all normal options
9827 * if 'all' == 2: show all terminal options
9828 */
9829 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009830showoptions(
9831 int all,
9832 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009833{
9834 struct vimoption *p;
9835 int col;
9836 int isterm;
9837 char_u *varp;
9838 struct vimoption **items;
9839 int item_count;
9840 int run;
9841 int row, rows;
9842 int cols;
9843 int i;
9844 int len;
9845
9846#define INC 20
9847#define GAP 3
9848
9849 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9850 PARAM_COUNT));
9851 if (items == NULL)
9852 return;
9853
9854 /* Highlight title */
9855 if (all == 2)
9856 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9857 else if (opt_flags & OPT_GLOBAL)
9858 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9859 else if (opt_flags & OPT_LOCAL)
9860 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9861 else
9862 MSG_PUTS_TITLE(_("\n--- Options ---"));
9863
9864 /*
9865 * do the loop two times:
9866 * 1. display the short items
9867 * 2. display the long items (only strings and numbers)
9868 */
9869 for (run = 1; run <= 2 && !got_int; ++run)
9870 {
9871 /*
9872 * collect the items in items[]
9873 */
9874 item_count = 0;
9875 for (p = &options[0]; p->fullname != NULL; p++)
9876 {
9877 varp = NULL;
9878 isterm = istermoption(p);
9879 if (opt_flags != 0)
9880 {
9881 if (p->indir != PV_NONE && !isterm)
9882 varp = get_varp_scope(p, opt_flags);
9883 }
9884 else
9885 varp = get_varp(p);
9886 if (varp != NULL
9887 && ((all == 2 && isterm)
9888 || (all == 1 && !isterm)
9889 || (all == 0 && !optval_default(p, varp))))
9890 {
9891 if (p->flags & P_BOOL)
9892 len = 1; /* a toggle option fits always */
9893 else
9894 {
9895 option_value2string(p, opt_flags);
9896 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9897 }
9898 if ((len <= INC - GAP && run == 1) ||
9899 (len > INC - GAP && run == 2))
9900 items[item_count++] = p;
9901 }
9902 }
9903
9904 /*
9905 * display the items
9906 */
9907 if (run == 1)
9908 {
9909 cols = (Columns + GAP - 3) / INC;
9910 if (cols == 0)
9911 cols = 1;
9912 rows = (item_count + cols - 1) / cols;
9913 }
9914 else /* run == 2 */
9915 rows = item_count;
9916 for (row = 0; row < rows && !got_int; ++row)
9917 {
9918 msg_putchar('\n'); /* go to next line */
9919 if (got_int) /* 'q' typed in more */
9920 break;
9921 col = 0;
9922 for (i = row; i < item_count; i += rows)
9923 {
9924 msg_col = col; /* make columns */
9925 showoneopt(items[i], opt_flags);
9926 col += INC;
9927 }
9928 out_flush();
9929 ui_breakcheck();
9930 }
9931 }
9932 vim_free(items);
9933}
9934
9935/*
9936 * Return TRUE if option "p" has its default value.
9937 */
9938 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009939optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940{
9941 int dvi;
9942
9943 if (varp == NULL)
9944 return TRUE; /* hidden option is always at default */
9945 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9946 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009947 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009948 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009949 /* the cast to long is required for Manx C, long_i is
9950 * needed for MSVC */
9951 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009952 /* P_STRING */
9953 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9954}
9955
9956/*
9957 * showoneopt: show the value of one option
9958 * must not be called with a hidden option!
9959 */
9960 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009961showoneopt(
9962 struct vimoption *p,
9963 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009964{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009965 char_u *varp;
9966 int save_silent = silent_mode;
9967
9968 silent_mode = FALSE;
9969 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009970
9971 varp = get_varp_scope(p, opt_flags);
9972
9973 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9974 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9975 ? !curbufIsChanged() : !*(int *)varp))
9976 MSG_PUTS("no");
9977 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9978 MSG_PUTS("--");
9979 else
9980 MSG_PUTS(" ");
9981 MSG_PUTS(p->fullname);
9982 if (!(p->flags & P_BOOL))
9983 {
9984 msg_putchar('=');
9985 /* put value string in NameBuff */
9986 option_value2string(p, opt_flags);
9987 msg_outtrans(NameBuff);
9988 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009989
9990 silent_mode = save_silent;
9991 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992}
9993
9994/*
9995 * Write modified options as ":set" commands to a file.
9996 *
9997 * There are three values for "opt_flags":
9998 * OPT_GLOBAL: Write global option values and fresh values of
9999 * buffer-local options (used for start of a session
10000 * file).
10001 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10002 * curwin (used for a vimrc file).
10003 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10004 * and local values for window-local options of
10005 * curwin. Local values are also written when at the
10006 * default value, because a modeline or autocommand
10007 * may have set them when doing ":edit file" and the
10008 * user has set them back at the default or fresh
10009 * value.
10010 * When "local_only" is TRUE, don't write fresh
10011 * values, only local values (for ":mkview").
10012 * (fresh value = value used for a new buffer or window for a local option).
10013 *
10014 * Return FAIL on error, OK otherwise.
10015 */
10016 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010017makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010018{
10019 struct vimoption *p;
10020 char_u *varp; /* currently used value */
10021 char_u *varp_fresh; /* local value */
10022 char_u *varp_local = NULL; /* fresh value */
10023 char *cmd;
10024 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010025 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010026
10027 /*
10028 * The options that don't have a default (terminal name, columns, lines)
10029 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010030 * Do the loop over "options[]" twice: once for options with the
10031 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010032 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010033 for (pri = 1; pri >= 0; --pri)
10034 {
10035 for (p = &options[0]; !istermoption(p); p++)
10036 if (!(p->flags & P_NO_MKRC)
10037 && !istermoption(p)
10038 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010039 {
10040 /* skip global option when only doing locals */
10041 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10042 continue;
10043
10044 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10045 * file, they are always buffer-specific. */
10046 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10047 continue;
10048
10049 /* Global values are only written when not at the default value. */
10050 varp = get_varp_scope(p, opt_flags);
10051 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10052 continue;
10053
10054 round = 2;
10055 if (p->indir != PV_NONE)
10056 {
10057 if (p->var == VAR_WIN)
10058 {
10059 /* skip window-local option when only doing globals */
10060 if (!(opt_flags & OPT_LOCAL))
10061 continue;
10062 /* When fresh value of window-local option is not at the
10063 * default, need to write it too. */
10064 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10065 {
10066 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10067 if (!optval_default(p, varp_fresh))
10068 {
10069 round = 1;
10070 varp_local = varp;
10071 varp = varp_fresh;
10072 }
10073 }
10074 }
10075 }
10076
10077 /* Round 1: fresh value for window-local options.
10078 * Round 2: other values */
10079 for ( ; round <= 2; varp = varp_local, ++round)
10080 {
10081 if (round == 1 || (opt_flags & OPT_GLOBAL))
10082 cmd = "set";
10083 else
10084 cmd = "setlocal";
10085
10086 if (p->flags & P_BOOL)
10087 {
10088 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10089 return FAIL;
10090 }
10091 else if (p->flags & P_NUM)
10092 {
10093 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10094 return FAIL;
10095 }
10096 else /* P_STRING */
10097 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010098#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10099 int do_endif = FALSE;
10100
Bram Moolenaar071d4272004-06-13 20:20:40 +000010101 /* Don't set 'syntax' and 'filetype' again if the value is
10102 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010103 if (
10104# if defined(FEAT_SYN_HL)
10105 p->indir == PV_SYN
10106# if defined(FEAT_AUTOCMD)
10107 ||
10108# endif
10109# endif
10110# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010111 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010112# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010113 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010114 {
10115 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10116 *(char_u **)(varp)) < 0
10117 || put_eol(fd) < 0)
10118 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010119 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010121#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010122 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10123 (p->flags & P_EXPAND) != 0) == FAIL)
10124 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010125#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10126 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127 {
10128 if (put_line(fd, "endif") == FAIL)
10129 return FAIL;
10130 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010132 }
10133 }
10134 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010135 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010136 return OK;
10137}
10138
10139#if defined(FEAT_FOLDING) || defined(PROTO)
10140/*
10141 * Generate set commands for the local fold options only. Used when
10142 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10143 */
10144 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010145makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146{
10147 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10148# ifdef FEAT_EVAL
10149 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10150 == FAIL
10151# endif
10152 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10153 == FAIL
10154 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10155 == FAIL
10156 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10157 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10158 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10159 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10160 )
10161 return FAIL;
10162
10163 return OK;
10164}
10165#endif
10166
10167 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010168put_setstring(
10169 FILE *fd,
10170 char *cmd,
10171 char *name,
10172 char_u **valuep,
10173 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174{
10175 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010176 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010177
10178 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10179 return FAIL;
10180 if (*valuep != NULL)
10181 {
10182 /* Output 'pastetoggle' as key names. For other
10183 * options some characters have to be escaped with
10184 * CTRL-V or backslash */
10185 if (valuep == &p_pt)
10186 {
10187 s = *valuep;
10188 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010189 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 return FAIL;
10191 }
10192 else if (expand)
10193 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010194 buf = alloc(MAXPATHL);
10195 if (buf == NULL)
10196 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10198 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010199 {
10200 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010201 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010202 }
10203 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204 }
10205 else if (put_escstr(fd, *valuep, 2) == FAIL)
10206 return FAIL;
10207 }
10208 if (put_eol(fd) < 0)
10209 return FAIL;
10210 return OK;
10211}
10212
10213 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010214put_setnum(
10215 FILE *fd,
10216 char *cmd,
10217 char *name,
10218 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010219{
10220 long wc;
10221
10222 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10223 return FAIL;
10224 if (wc_use_keyname((char_u *)valuep, &wc))
10225 {
10226 /* print 'wildchar' and 'wildcharm' as a key name */
10227 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10228 return FAIL;
10229 }
10230 else if (fprintf(fd, "%ld", *valuep) < 0)
10231 return FAIL;
10232 if (put_eol(fd) < 0)
10233 return FAIL;
10234 return OK;
10235}
10236
10237 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010238put_setbool(
10239 FILE *fd,
10240 char *cmd,
10241 char *name,
10242 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010243{
Bram Moolenaar893de922007-10-02 18:40:57 +000010244 if (value < 0) /* global/local option using global value */
10245 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10247 || put_eol(fd) < 0)
10248 return FAIL;
10249 return OK;
10250}
10251
10252/*
10253 * Clear all the terminal options.
10254 * If the option has been allocated, free the memory.
10255 * Terminal options are never hidden or indirect.
10256 */
10257 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010258clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260 /*
10261 * Reset a few things before clearing the old options. This may cause
10262 * outputting a few things that the terminal doesn't understand, but the
10263 * screen will be cleared later, so this is OK.
10264 */
10265#ifdef FEAT_MOUSE_TTY
10266 mch_setmouse(FALSE); /* switch mouse off */
10267#endif
10268#ifdef FEAT_TITLE
10269 mch_restore_title(3); /* restore window titles */
10270#endif
10271#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10272 /* When starting the GUI close the display opened for the clipboard.
10273 * After restoring the title, because that will need the display. */
10274 if (gui.starting)
10275 clear_xterm_clip();
10276#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010277 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010278
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010279 free_termoptions();
10280}
10281
10282 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010283free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010284{
10285 struct vimoption *p;
10286
Bram Moolenaar071d4272004-06-13 20:20:40 +000010287 for (p = &options[0]; p->fullname != NULL; p++)
10288 if (istermoption(p))
10289 {
10290 if (p->flags & P_ALLOCED)
10291 free_string_option(*(char_u **)(p->var));
10292 if (p->flags & P_DEF_ALLOCED)
10293 free_string_option(p->def_val[VI_DEFAULT]);
10294 *(char_u **)(p->var) = empty_option;
10295 p->def_val[VI_DEFAULT] = empty_option;
10296 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10297 }
10298 clear_termcodes();
10299}
10300
10301/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010302 * Free the string for one term option, if it was allocated.
10303 * Set the string to empty_option and clear allocated flag.
10304 * "var" points to the option value.
10305 */
10306 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010307free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010308{
10309 struct vimoption *p;
10310
10311 for (p = &options[0]; p->fullname != NULL; p++)
10312 if (p->var == var)
10313 {
10314 if (p->flags & P_ALLOCED)
10315 free_string_option(*(char_u **)(p->var));
10316 *(char_u **)(p->var) = empty_option;
10317 p->flags &= ~P_ALLOCED;
10318 break;
10319 }
10320}
10321
10322/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323 * Set the terminal option defaults to the current value.
10324 * Used after setting the terminal name.
10325 */
10326 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010327set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010328{
10329 struct vimoption *p;
10330
10331 for (p = &options[0]; p->fullname != NULL; p++)
10332 {
10333 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10334 {
10335 if (p->flags & P_DEF_ALLOCED)
10336 {
10337 free_string_option(p->def_val[VI_DEFAULT]);
10338 p->flags &= ~P_DEF_ALLOCED;
10339 }
10340 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10341 if (p->flags & P_ALLOCED)
10342 {
10343 p->flags |= P_DEF_ALLOCED;
10344 p->flags &= ~P_ALLOCED; /* don't free the value now */
10345 }
10346 }
10347 }
10348}
10349
10350/*
10351 * return TRUE if 'p' starts with 't_'
10352 */
10353 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010354istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010355{
10356 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10357}
10358
10359/*
10360 * Compute columns for ruler and shown command. 'sc_col' is also used to
10361 * decide what the maximum length of a message on the status line can be.
10362 * If there is a status line for the last window, 'sc_col' is independent
10363 * of 'ru_col'.
10364 */
10365
10366#define COL_RULER 17 /* columns needed by standard ruler */
10367
10368 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010369comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370{
10371#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010372 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010373
10374 sc_col = 0;
10375 ru_col = 0;
10376 if (p_ru)
10377 {
10378#ifdef FEAT_STL_OPT
10379 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10380#else
10381 ru_col = COL_RULER + 1;
10382#endif
10383 /* no last status line, adjust sc_col */
10384 if (!last_has_status)
10385 sc_col = ru_col;
10386 }
10387 if (p_sc)
10388 {
10389 sc_col += SHOWCMD_COLS;
10390 if (!p_ru || last_has_status) /* no need for separating space */
10391 ++sc_col;
10392 }
10393 sc_col = Columns - sc_col;
10394 ru_col = Columns - ru_col;
10395 if (sc_col <= 0) /* screen too narrow, will become a mess */
10396 sc_col = 1;
10397 if (ru_col <= 0)
10398 ru_col = 1;
10399#else
10400 sc_col = Columns;
10401 ru_col = Columns;
10402#endif
10403}
10404
10405/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010406 * Unset local option value, similar to ":set opt<".
10407 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010408 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010409unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010410{
10411 struct vimoption *p;
10412 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010413 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010414
10415 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010416 if (opt_idx < 0)
10417 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010418 p = &(options[opt_idx]);
10419
10420 switch ((int)p->indir)
10421 {
10422 /* global option with local value: use local value if it's been set */
10423 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010424 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010425 break;
10426 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010427 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010428 break;
10429 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010430 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010431 break;
10432 case PV_AR:
10433 buf->b_p_ar = -1;
10434 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010435 case PV_BKC:
10436 clear_string_option(&buf->b_p_bkc);
10437 buf->b_bkc_flags = 0;
10438 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010439 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010440 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010441 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010442 case PV_TC:
10443 clear_string_option(&buf->b_p_tc);
10444 buf->b_tc_flags = 0;
10445 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010446#ifdef FEAT_FIND_ID
10447 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010448 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010449 break;
10450 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010451 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010452 break;
10453#endif
10454#ifdef FEAT_INS_EXPAND
10455 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010456 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010457 break;
10458 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010459 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010460 break;
10461#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010462 case PV_FP:
10463 clear_string_option(&buf->b_p_fp);
10464 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010465#ifdef FEAT_QUICKFIX
10466 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010467 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010468 break;
10469 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010470 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010471 break;
10472 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010473 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010474 break;
10475#endif
10476#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10477 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010478 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010479 break;
10480#endif
10481#if defined(FEAT_CRYPT)
10482 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010483 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010484 break;
10485#endif
10486#ifdef FEAT_STL_OPT
10487 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010488 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010489 break;
10490#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010491 case PV_UL:
10492 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10493 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010494#ifdef FEAT_LISP
10495 case PV_LW:
10496 clear_string_option(&buf->b_p_lw);
10497 break;
10498#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010499#ifdef FEAT_MBYTE
10500 case PV_MENC:
10501 clear_string_option(&buf->b_p_menc);
10502 break;
10503#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010504 }
10505}
10506
10507/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010508 * Get pointer to option variable, depending on local or global scope.
10509 */
10510 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010511get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512{
10513 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10514 {
10515 if (p->var == VAR_WIN)
10516 return (char_u *)GLOBAL_WO(get_varp(p));
10517 return p->var;
10518 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010519 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520 {
10521 switch ((int)p->indir)
10522 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010523 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010525 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10526 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10527 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010529 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10530 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10531 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010532 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010533 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010534 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010536 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10537 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538#endif
10539#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010540 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10541 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010543#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10544 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10545#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010546#if defined(FEAT_CRYPT)
10547 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10548#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010549#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010550 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010551#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010552 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010553#ifdef FEAT_LISP
10554 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10555#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010556 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010557#ifdef FEAT_MBYTE
10558 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560 }
10561 return NULL; /* "cannot happen" */
10562 }
10563 return get_varp(p);
10564}
10565
10566/*
10567 * Get pointer to option variable.
10568 */
10569 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010570get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571{
10572 /* hidden option, always return NULL */
10573 if (p->var == NULL)
10574 return NULL;
10575
10576 switch ((int)p->indir)
10577 {
10578 case PV_NONE: return p->var;
10579
10580 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010581 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010583 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010585 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010587 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010589 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010591 case PV_TC: return *curbuf->b_p_tc != NUL
10592 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010593 case PV_BKC: return *curbuf->b_p_bkc != NUL
10594 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010596 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010597 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010598 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10600#endif
10601#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010602 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010604 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10606#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010607 case PV_FP: return *curbuf->b_p_fp != NUL
10608 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010609#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010610 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010612 case PV_GP: return *curbuf->b_p_gp != NUL
10613 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10614 case PV_MP: return *curbuf->b_p_mp != NUL
10615 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010617#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10618 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10619 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10620#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010621#if defined(FEAT_CRYPT)
10622 case PV_CM: return *curbuf->b_p_cm != NUL
10623 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10624#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010625#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010626 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010627 ? (char_u *)&(curwin->w_p_stl) : p->var;
10628#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010629 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10630 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010631#ifdef FEAT_LISP
10632 case PV_LW: return *curbuf->b_p_lw != NUL
10633 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10634#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010635#ifdef FEAT_MBYTE
10636 case PV_MENC: return *curbuf->b_p_menc != NUL
10637 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10638#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010639
10640#ifdef FEAT_ARABIC
10641 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10642#endif
10643 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010644#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010645 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10646#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010647#ifdef FEAT_SYN_HL
10648 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10649 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010650 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010651#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010652#ifdef FEAT_DIFF
10653 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10654#endif
10655#ifdef FEAT_FOLDING
10656 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10657 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10658 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10659 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10660 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10661 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10662 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10663# ifdef FEAT_EVAL
10664 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10665 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10666# endif
10667 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10668#endif
10669 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010670 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010671#ifdef FEAT_LINEBREAK
10672 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10673#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010674#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010675 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010676 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010678#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10679 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10680#endif
10681#ifdef FEAT_RIGHTLEFT
10682 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10683 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10684#endif
10685 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10686 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10687#ifdef FEAT_LINEBREAK
10688 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010689 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10690 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691#endif
10692#ifdef FEAT_SCROLLBIND
10693 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10694#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010695#ifdef FEAT_CURSORBIND
10696 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10697#endif
10698#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010699 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10700 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10701#endif
10702#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010703 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010704 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010705#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010706
10707 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10708 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10709#ifdef FEAT_MBYTE
10710 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10711#endif
10712#if defined(FEAT_QUICKFIX)
10713 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10714 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10715#endif
10716 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10717 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10718#ifdef FEAT_CINDENT
10719 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10720 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10721 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10722#endif
10723#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10724 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10725#endif
10726#ifdef FEAT_COMMENTS
10727 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10728#endif
10729#ifdef FEAT_FOLDING
10730 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10731#endif
10732#ifdef FEAT_INS_EXPAND
10733 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10734#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010735#ifdef FEAT_COMPL_FUNC
10736 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010737 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010740 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10742#ifdef FEAT_MBYTE
10743 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10744#endif
10745 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10746#ifdef FEAT_AUTOCMD
10747 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10748#endif
10749 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010750 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10752 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10753 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10754 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10755#ifdef FEAT_FIND_ID
10756# ifdef FEAT_EVAL
10757 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10758# endif
10759#endif
10760#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10761 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10762 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10763#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010764#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010765 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10766#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767#ifdef FEAT_CRYPT
10768 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10769#endif
10770#ifdef FEAT_LISP
10771 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10772#endif
10773 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10774 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10775 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10776 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10777 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010779#ifdef FEAT_TEXTOBJ
10780 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10781#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010782 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10783#ifdef FEAT_SMARTINDENT
10784 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10785#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010787 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10788#ifdef FEAT_SEARCHPATH
10789 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10790#endif
10791 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10792#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010793 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010794 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10795#endif
10796#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010797 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10798 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10799 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010800#endif
10801 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10802 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10803 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10804 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010805#ifdef FEAT_PERSISTENT_UNDO
10806 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10807#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010808 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10809#ifdef FEAT_KEYMAP
10810 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10811#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010812#ifdef FEAT_SIGNS
10813 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10814#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010815 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010816 }
10817 /* always return a valid pointer to avoid a crash! */
10818 return (char_u *)&(curbuf->b_p_wm);
10819}
10820
10821/*
10822 * Get the value of 'equalprg', either the buffer-local one or the global one.
10823 */
10824 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010825get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010826{
10827 if (*curbuf->b_p_ep == NUL)
10828 return p_ep;
10829 return curbuf->b_p_ep;
10830}
10831
10832#if defined(FEAT_WINDOWS) || defined(PROTO)
10833/*
10834 * Copy options from one window to another.
10835 * Used when splitting a window.
10836 */
10837 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010838win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010839{
10840 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10841 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10842# ifdef FEAT_RIGHTLEFT
10843# ifdef FEAT_FKMAP
10844 /* Is this right? */
10845 wp_to->w_farsi = wp_from->w_farsi;
10846# endif
10847# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010848#if defined(FEAT_LINEBREAK)
10849 briopt_check(wp_to);
10850#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851}
10852#endif
10853
10854/*
10855 * Copy the options from one winopt_T to another.
10856 * Doesn't free the old option values in "to", use clear_winopt() for that.
10857 * The 'scroll' option is not copied, because it depends on the window height.
10858 * The 'previewwindow' option is reset, there can be only one preview window.
10859 */
10860 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010861copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862{
10863#ifdef FEAT_ARABIC
10864 to->wo_arab = from->wo_arab;
10865#endif
10866 to->wo_list = from->wo_list;
10867 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010868 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010869#ifdef FEAT_LINEBREAK
10870 to->wo_nuw = from->wo_nuw;
10871#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872#ifdef FEAT_RIGHTLEFT
10873 to->wo_rl = from->wo_rl;
10874 to->wo_rlc = vim_strsave(from->wo_rlc);
10875#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010876#ifdef FEAT_STL_OPT
10877 to->wo_stl = vim_strsave(from->wo_stl);
10878#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010880#ifdef FEAT_DIFF
10881 to->wo_wrap_save = from->wo_wrap_save;
10882#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883#ifdef FEAT_LINEBREAK
10884 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010885 to->wo_bri = from->wo_bri;
10886 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887#endif
10888#ifdef FEAT_SCROLLBIND
10889 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010890 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010891#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010892#ifdef FEAT_CURSORBIND
10893 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010894 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010895#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010896#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010897 to->wo_spell = from->wo_spell;
10898#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010899#ifdef FEAT_SYN_HL
10900 to->wo_cuc = from->wo_cuc;
10901 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010902 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010903#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010904#ifdef FEAT_DIFF
10905 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010906 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010908#ifdef FEAT_CONCEAL
10909 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010910 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010911#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010912#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010913 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010914 to->wo_tms = vim_strsave(from->wo_tms);
10915#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916#ifdef FEAT_FOLDING
10917 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010918 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010919 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010920 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921 to->wo_fdi = vim_strsave(from->wo_fdi);
10922 to->wo_fml = from->wo_fml;
10923 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010924 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010925 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010926 to->wo_fdm_save = from->wo_diff_saved
10927 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010928 to->wo_fdn = from->wo_fdn;
10929# ifdef FEAT_EVAL
10930 to->wo_fde = vim_strsave(from->wo_fde);
10931 to->wo_fdt = vim_strsave(from->wo_fdt);
10932# endif
10933 to->wo_fmr = vim_strsave(from->wo_fmr);
10934#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010935#ifdef FEAT_SIGNS
10936 to->wo_scl = vim_strsave(from->wo_scl);
10937#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938 check_winopt(to); /* don't want NULL pointers */
10939}
10940
10941/*
10942 * Check string options in a window for a NULL value.
10943 */
10944 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010945check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010946{
10947 check_winopt(&win->w_onebuf_opt);
10948 check_winopt(&win->w_allbuf_opt);
10949}
10950
10951/*
10952 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10953 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010954 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010955check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010956{
10957#ifdef FEAT_FOLDING
10958 check_string_option(&wop->wo_fdi);
10959 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010960 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010961# ifdef FEAT_EVAL
10962 check_string_option(&wop->wo_fde);
10963 check_string_option(&wop->wo_fdt);
10964# endif
10965 check_string_option(&wop->wo_fmr);
10966#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010967#ifdef FEAT_SIGNS
10968 check_string_option(&wop->wo_scl);
10969#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010970#ifdef FEAT_RIGHTLEFT
10971 check_string_option(&wop->wo_rlc);
10972#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010973#ifdef FEAT_STL_OPT
10974 check_string_option(&wop->wo_stl);
10975#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010976#ifdef FEAT_SYN_HL
10977 check_string_option(&wop->wo_cc);
10978#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010979#ifdef FEAT_CONCEAL
10980 check_string_option(&wop->wo_cocu);
10981#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010982#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010983 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010984 check_string_option(&wop->wo_tms);
10985#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010986#ifdef FEAT_LINEBREAK
10987 check_string_option(&wop->wo_briopt);
10988#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989}
10990
10991/*
10992 * Free the allocated memory inside a winopt_T.
10993 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010995clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010996{
10997#ifdef FEAT_FOLDING
10998 clear_string_option(&wop->wo_fdi);
10999 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011000 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011001# ifdef FEAT_EVAL
11002 clear_string_option(&wop->wo_fde);
11003 clear_string_option(&wop->wo_fdt);
11004# endif
11005 clear_string_option(&wop->wo_fmr);
11006#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011007#ifdef FEAT_SIGNS
11008 clear_string_option(&wop->wo_scl);
11009#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011010#ifdef FEAT_LINEBREAK
11011 clear_string_option(&wop->wo_briopt);
11012#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013#ifdef FEAT_RIGHTLEFT
11014 clear_string_option(&wop->wo_rlc);
11015#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011016#ifdef FEAT_STL_OPT
11017 clear_string_option(&wop->wo_stl);
11018#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011019#ifdef FEAT_SYN_HL
11020 clear_string_option(&wop->wo_cc);
11021#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011022#ifdef FEAT_CONCEAL
11023 clear_string_option(&wop->wo_cocu);
11024#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011025#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011026 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011027 clear_string_option(&wop->wo_tms);
11028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011029}
11030
11031/*
11032 * Copy global option values to local options for one buffer.
11033 * Used when creating a new buffer and sometimes when entering a buffer.
11034 * flags:
11035 * BCO_ENTER We will enter the buf buffer.
11036 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11037 * appropriate.
11038 * BCO_NOHELP Don't copy the values to a help buffer.
11039 */
11040 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011041buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011042{
11043 int should_copy = TRUE;
11044 char_u *save_p_isk = NULL; /* init for GCC */
11045 int dont_do_help;
11046 int did_isk = FALSE;
11047
11048 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011049 * Skip this when the option defaults have not been set yet. Happens when
11050 * main() allocates the first buffer.
11051 */
11052 if (p_cpo != NULL)
11053 {
11054 /*
11055 * Always copy when entering and 'cpo' contains 'S'.
11056 * Don't copy when already initialized.
11057 * Don't copy when 'cpo' contains 's' and not entering.
11058 * 'S' BCO_ENTER initialized 's' should_copy
11059 * yes yes X X TRUE
11060 * yes no yes X FALSE
11061 * no X yes X FALSE
11062 * X no no yes FALSE
11063 * X no no no TRUE
11064 * no yes no X TRUE
11065 */
11066 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11067 && (buf->b_p_initialized
11068 || (!(flags & BCO_ENTER)
11069 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11070 should_copy = FALSE;
11071
11072 if (should_copy || (flags & BCO_ALWAYS))
11073 {
11074 /* Don't copy the options specific to a help buffer when
11075 * BCO_NOHELP is given or the options were initialized already
11076 * (jumping back to a help file with CTRL-T or CTRL-O) */
11077 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11078 || buf->b_p_initialized;
11079 if (dont_do_help) /* don't free b_p_isk */
11080 {
11081 save_p_isk = buf->b_p_isk;
11082 buf->b_p_isk = NULL;
11083 }
11084 /*
11085 * Always free the allocated strings.
11086 * If not already initialized, set 'readonly' and copy 'fileformat'.
11087 */
11088 if (!buf->b_p_initialized)
11089 {
11090 free_buf_options(buf, TRUE);
11091 buf->b_p_ro = FALSE; /* don't copy readonly */
11092 buf->b_p_tx = p_tx;
11093#ifdef FEAT_MBYTE
11094 buf->b_p_fenc = vim_strsave(p_fenc);
11095#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011096 switch (*p_ffs)
11097 {
11098 case 'm':
11099 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11100 case 'd':
11101 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11102 case 'u':
11103 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11104 default:
11105 buf->b_p_ff = vim_strsave(p_ff);
11106 }
11107 if (buf->b_p_ff != NULL)
11108 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109#if defined(FEAT_QUICKFIX)
11110 buf->b_p_bh = empty_option;
11111 buf->b_p_bt = empty_option;
11112#endif
11113 }
11114 else
11115 free_buf_options(buf, FALSE);
11116
11117 buf->b_p_ai = p_ai;
11118 buf->b_p_ai_nopaste = p_ai_nopaste;
11119 buf->b_p_sw = p_sw;
11120 buf->b_p_tw = p_tw;
11121 buf->b_p_tw_nopaste = p_tw_nopaste;
11122 buf->b_p_tw_nobin = p_tw_nobin;
11123 buf->b_p_wm = p_wm;
11124 buf->b_p_wm_nopaste = p_wm_nopaste;
11125 buf->b_p_wm_nobin = p_wm_nobin;
11126 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011127#ifdef FEAT_MBYTE
11128 buf->b_p_bomb = p_bomb;
11129#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011130 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011131 buf->b_p_et = p_et;
11132 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011133 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011134 buf->b_p_ml = p_ml;
11135 buf->b_p_ml_nobin = p_ml_nobin;
11136 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011137 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011138#ifdef FEAT_INS_EXPAND
11139 buf->b_p_cpt = vim_strsave(p_cpt);
11140#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011141#ifdef FEAT_COMPL_FUNC
11142 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011143 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145 buf->b_p_sts = p_sts;
11146 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011148#ifdef FEAT_COMMENTS
11149 buf->b_p_com = vim_strsave(p_com);
11150#endif
11151#ifdef FEAT_FOLDING
11152 buf->b_p_cms = vim_strsave(p_cms);
11153#endif
11154 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011155 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156 buf->b_p_nf = vim_strsave(p_nf);
11157 buf->b_p_mps = vim_strsave(p_mps);
11158#ifdef FEAT_SMARTINDENT
11159 buf->b_p_si = p_si;
11160#endif
11161 buf->b_p_ci = p_ci;
11162#ifdef FEAT_CINDENT
11163 buf->b_p_cin = p_cin;
11164 buf->b_p_cink = vim_strsave(p_cink);
11165 buf->b_p_cino = vim_strsave(p_cino);
11166#endif
11167#ifdef FEAT_AUTOCMD
11168 /* Don't copy 'filetype', it must be detected */
11169 buf->b_p_ft = empty_option;
11170#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011171 buf->b_p_pi = p_pi;
11172#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11173 buf->b_p_cinw = vim_strsave(p_cinw);
11174#endif
11175#ifdef FEAT_LISP
11176 buf->b_p_lisp = p_lisp;
11177#endif
11178#ifdef FEAT_SYN_HL
11179 /* Don't copy 'syntax', it must be set */
11180 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011181 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011182 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011183#endif
11184#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011185 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011186 (void)compile_cap_prog(&buf->b_s);
11187 buf->b_s.b_p_spf = vim_strsave(p_spf);
11188 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011189#endif
11190#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11191 buf->b_p_inde = vim_strsave(p_inde);
11192 buf->b_p_indk = vim_strsave(p_indk);
11193#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011194 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011195#if defined(FEAT_EVAL)
11196 buf->b_p_fex = vim_strsave(p_fex);
11197#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011198#ifdef FEAT_CRYPT
11199 buf->b_p_key = vim_strsave(p_key);
11200#endif
11201#ifdef FEAT_SEARCHPATH
11202 buf->b_p_sua = vim_strsave(p_sua);
11203#endif
11204#ifdef FEAT_KEYMAP
11205 buf->b_p_keymap = vim_strsave(p_keymap);
11206 buf->b_kmap_state |= KEYMAP_INIT;
11207#endif
11208 /* This isn't really an option, but copying the langmap and IME
11209 * state from the current buffer is better than resetting it. */
11210 buf->b_p_iminsert = p_iminsert;
11211 buf->b_p_imsearch = p_imsearch;
11212
11213 /* options that are normally global but also have a local value
11214 * are not copied, start using the global value */
11215 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011216 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011217 buf->b_p_bkc = empty_option;
11218 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011219#ifdef FEAT_QUICKFIX
11220 buf->b_p_gp = empty_option;
11221 buf->b_p_mp = empty_option;
11222 buf->b_p_efm = empty_option;
11223#endif
11224 buf->b_p_ep = empty_option;
11225 buf->b_p_kp = empty_option;
11226 buf->b_p_path = empty_option;
11227 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011228 buf->b_p_tc = empty_option;
11229 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011230#ifdef FEAT_FIND_ID
11231 buf->b_p_def = empty_option;
11232 buf->b_p_inc = empty_option;
11233# ifdef FEAT_EVAL
11234 buf->b_p_inex = vim_strsave(p_inex);
11235# endif
11236#endif
11237#ifdef FEAT_INS_EXPAND
11238 buf->b_p_dict = empty_option;
11239 buf->b_p_tsr = empty_option;
11240#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011241#ifdef FEAT_TEXTOBJ
11242 buf->b_p_qe = vim_strsave(p_qe);
11243#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011244#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11245 buf->b_p_bexpr = empty_option;
11246#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011247#if defined(FEAT_CRYPT)
11248 buf->b_p_cm = empty_option;
11249#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011250#ifdef FEAT_PERSISTENT_UNDO
11251 buf->b_p_udf = p_udf;
11252#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011253#ifdef FEAT_LISP
11254 buf->b_p_lw = empty_option;
11255#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011256#ifdef FEAT_MBYTE
11257 buf->b_p_menc = empty_option;
11258#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011259
11260 /*
11261 * Don't copy the options set by ex_help(), use the saved values,
11262 * when going from a help buffer to a non-help buffer.
11263 * Don't touch these at all when BCO_NOHELP is used and going from
11264 * or to a help buffer.
11265 */
11266 if (dont_do_help)
11267 buf->b_p_isk = save_p_isk;
11268 else
11269 {
11270 buf->b_p_isk = vim_strsave(p_isk);
11271 did_isk = TRUE;
11272 buf->b_p_ts = p_ts;
11273 buf->b_help = FALSE;
11274#ifdef FEAT_QUICKFIX
11275 if (buf->b_p_bt[0] == 'h')
11276 clear_string_option(&buf->b_p_bt);
11277#endif
11278 buf->b_p_ma = p_ma;
11279 }
11280 }
11281
11282 /*
11283 * When the options should be copied (ignoring BCO_ALWAYS), set the
11284 * flag that indicates that the options have been initialized.
11285 */
11286 if (should_copy)
11287 buf->b_p_initialized = TRUE;
11288 }
11289
11290 check_buf_options(buf); /* make sure we don't have NULLs */
11291 if (did_isk)
11292 (void)buf_init_chartab(buf, FALSE);
11293}
11294
11295/*
11296 * Reset the 'modifiable' option and its default value.
11297 */
11298 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011299reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011300{
11301 int opt_idx;
11302
11303 curbuf->b_p_ma = FALSE;
11304 p_ma = FALSE;
11305 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011306 if (opt_idx >= 0)
11307 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011308}
11309
11310/*
11311 * Set the global value for 'iminsert' to the local value.
11312 */
11313 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011314set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315{
11316 p_iminsert = curbuf->b_p_iminsert;
11317}
11318
11319/*
11320 * Set the global value for 'imsearch' to the local value.
11321 */
11322 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011323set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011324{
11325 p_imsearch = curbuf->b_p_imsearch;
11326}
11327
11328#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11329static int expand_option_idx = -1;
11330static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11331static int expand_option_flags = 0;
11332
11333 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011334set_context_in_set_cmd(
11335 expand_T *xp,
11336 char_u *arg,
11337 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011338{
11339 int nextchar;
11340 long_u flags = 0; /* init for GCC */
11341 int opt_idx = 0; /* init for GCC */
11342 char_u *p;
11343 char_u *s;
11344 int is_term_option = FALSE;
11345 int key;
11346
11347 expand_option_flags = opt_flags;
11348
11349 xp->xp_context = EXPAND_SETTINGS;
11350 if (*arg == NUL)
11351 {
11352 xp->xp_pattern = arg;
11353 return;
11354 }
11355 p = arg + STRLEN(arg) - 1;
11356 if (*p == ' ' && *(p - 1) != '\\')
11357 {
11358 xp->xp_pattern = p + 1;
11359 return;
11360 }
11361 while (p > arg)
11362 {
11363 s = p;
11364 /* count number of backslashes before ' ' or ',' */
11365 if (*p == ' ' || *p == ',')
11366 {
11367 while (s > arg && *(s - 1) == '\\')
11368 --s;
11369 }
11370 /* break at a space with an even number of backslashes */
11371 if (*p == ' ' && ((p - s) & 1) == 0)
11372 {
11373 ++p;
11374 break;
11375 }
11376 --p;
11377 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011378 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011379 {
11380 xp->xp_context = EXPAND_BOOL_SETTINGS;
11381 p += 2;
11382 }
11383 if (STRNCMP(p, "inv", 3) == 0)
11384 {
11385 xp->xp_context = EXPAND_BOOL_SETTINGS;
11386 p += 3;
11387 }
11388 xp->xp_pattern = arg = p;
11389 if (*arg == '<')
11390 {
11391 while (*p != '>')
11392 if (*p++ == NUL) /* expand terminal option name */
11393 return;
11394 key = get_special_key_code(arg + 1);
11395 if (key == 0) /* unknown name */
11396 {
11397 xp->xp_context = EXPAND_NOTHING;
11398 return;
11399 }
11400 nextchar = *++p;
11401 is_term_option = TRUE;
11402 expand_option_name[2] = KEY2TERMCAP0(key);
11403 expand_option_name[3] = KEY2TERMCAP1(key);
11404 }
11405 else
11406 {
11407 if (p[0] == 't' && p[1] == '_')
11408 {
11409 p += 2;
11410 if (*p != NUL)
11411 ++p;
11412 if (*p == NUL)
11413 return; /* expand option name */
11414 nextchar = *++p;
11415 is_term_option = TRUE;
11416 expand_option_name[2] = p[-2];
11417 expand_option_name[3] = p[-1];
11418 }
11419 else
11420 {
11421 /* Allow * wildcard */
11422 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11423 p++;
11424 if (*p == NUL)
11425 return;
11426 nextchar = *p;
11427 *p = NUL;
11428 opt_idx = findoption(arg);
11429 *p = nextchar;
11430 if (opt_idx == -1 || options[opt_idx].var == NULL)
11431 {
11432 xp->xp_context = EXPAND_NOTHING;
11433 return;
11434 }
11435 flags = options[opt_idx].flags;
11436 if (flags & P_BOOL)
11437 {
11438 xp->xp_context = EXPAND_NOTHING;
11439 return;
11440 }
11441 }
11442 }
11443 /* handle "-=" and "+=" */
11444 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11445 {
11446 ++p;
11447 nextchar = '=';
11448 }
11449 if ((nextchar != '=' && nextchar != ':')
11450 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11451 {
11452 xp->xp_context = EXPAND_UNSUCCESSFUL;
11453 return;
11454 }
11455 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11456 {
11457 xp->xp_context = EXPAND_OLD_SETTING;
11458 if (is_term_option)
11459 expand_option_idx = -1;
11460 else
11461 expand_option_idx = opt_idx;
11462 xp->xp_pattern = p + 1;
11463 return;
11464 }
11465 xp->xp_context = EXPAND_NOTHING;
11466 if (is_term_option || (flags & P_NUM))
11467 return;
11468
11469 xp->xp_pattern = p + 1;
11470
11471 if (flags & P_EXPAND)
11472 {
11473 p = options[opt_idx].var;
11474 if (p == (char_u *)&p_bdir
11475 || p == (char_u *)&p_dir
11476 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011477 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011478 || p == (char_u *)&p_rtp
11479#ifdef FEAT_SEARCHPATH
11480 || p == (char_u *)&p_cdpath
11481#endif
11482#ifdef FEAT_SESSION
11483 || p == (char_u *)&p_vdir
11484#endif
11485 )
11486 {
11487 xp->xp_context = EXPAND_DIRECTORIES;
11488 if (p == (char_u *)&p_path
11489#ifdef FEAT_SEARCHPATH
11490 || p == (char_u *)&p_cdpath
11491#endif
11492 )
11493 xp->xp_backslash = XP_BS_THREE;
11494 else
11495 xp->xp_backslash = XP_BS_ONE;
11496 }
11497 else
11498 {
11499 xp->xp_context = EXPAND_FILES;
11500 /* for 'tags' need three backslashes for a space */
11501 if (p == (char_u *)&p_tags)
11502 xp->xp_backslash = XP_BS_THREE;
11503 else
11504 xp->xp_backslash = XP_BS_ONE;
11505 }
11506 }
11507
11508 /* For an option that is a list of file names, find the start of the
11509 * last file name. */
11510 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11511 {
11512 /* count number of backslashes before ' ' or ',' */
11513 if (*p == ' ' || *p == ',')
11514 {
11515 s = p;
11516 while (s > xp->xp_pattern && *(s - 1) == '\\')
11517 --s;
11518 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11519 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11520 {
11521 xp->xp_pattern = p + 1;
11522 break;
11523 }
11524 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011525
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011526#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011527 /* for 'spellsuggest' start at "file:" */
11528 if (options[opt_idx].var == (char_u *)&p_sps
11529 && STRNCMP(p, "file:", 5) == 0)
11530 {
11531 xp->xp_pattern = p + 5;
11532 break;
11533 }
11534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535 }
11536
11537 return;
11538}
11539
11540 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011541ExpandSettings(
11542 expand_T *xp,
11543 regmatch_T *regmatch,
11544 int *num_file,
11545 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546{
11547 int num_normal = 0; /* Nr of matching non-term-code settings */
11548 int num_term = 0; /* Nr of matching terminal code settings */
11549 int opt_idx;
11550 int match;
11551 int count = 0;
11552 char_u *str;
11553 int loop;
11554 int is_term_opt;
11555 char_u name_buf[MAX_KEY_NAME_LEN];
11556 static char *(names[]) = {"all", "termcap"};
11557 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11558
11559 /* do this loop twice:
11560 * loop == 0: count the number of matching options
11561 * loop == 1: copy the matching options into allocated memory
11562 */
11563 for (loop = 0; loop <= 1; ++loop)
11564 {
11565 regmatch->rm_ic = ic;
11566 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11567 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011568 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11569 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011570 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11571 {
11572 if (loop == 0)
11573 num_normal++;
11574 else
11575 (*file)[count++] = vim_strsave((char_u *)names[match]);
11576 }
11577 }
11578 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11579 opt_idx++)
11580 {
11581 if (options[opt_idx].var == NULL)
11582 continue;
11583 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11584 && !(options[opt_idx].flags & P_BOOL))
11585 continue;
11586 is_term_opt = istermoption(&options[opt_idx]);
11587 if (is_term_opt && num_normal > 0)
11588 continue;
11589 match = FALSE;
11590 if (vim_regexec(regmatch, str, (colnr_T)0)
11591 || (options[opt_idx].shortname != NULL
11592 && vim_regexec(regmatch,
11593 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11594 match = TRUE;
11595 else if (is_term_opt)
11596 {
11597 name_buf[0] = '<';
11598 name_buf[1] = 't';
11599 name_buf[2] = '_';
11600 name_buf[3] = str[2];
11601 name_buf[4] = str[3];
11602 name_buf[5] = '>';
11603 name_buf[6] = NUL;
11604 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11605 {
11606 match = TRUE;
11607 str = name_buf;
11608 }
11609 }
11610 if (match)
11611 {
11612 if (loop == 0)
11613 {
11614 if (is_term_opt)
11615 num_term++;
11616 else
11617 num_normal++;
11618 }
11619 else
11620 (*file)[count++] = vim_strsave(str);
11621 }
11622 }
11623 /*
11624 * Check terminal key codes, these are not in the option table
11625 */
11626 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11627 {
11628 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11629 {
11630 if (!isprint(str[0]) || !isprint(str[1]))
11631 continue;
11632
11633 name_buf[0] = 't';
11634 name_buf[1] = '_';
11635 name_buf[2] = str[0];
11636 name_buf[3] = str[1];
11637 name_buf[4] = NUL;
11638
11639 match = FALSE;
11640 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11641 match = TRUE;
11642 else
11643 {
11644 name_buf[0] = '<';
11645 name_buf[1] = 't';
11646 name_buf[2] = '_';
11647 name_buf[3] = str[0];
11648 name_buf[4] = str[1];
11649 name_buf[5] = '>';
11650 name_buf[6] = NUL;
11651
11652 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11653 match = TRUE;
11654 }
11655 if (match)
11656 {
11657 if (loop == 0)
11658 num_term++;
11659 else
11660 (*file)[count++] = vim_strsave(name_buf);
11661 }
11662 }
11663
11664 /*
11665 * Check special key names.
11666 */
11667 regmatch->rm_ic = TRUE; /* ignore case here */
11668 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11669 {
11670 name_buf[0] = '<';
11671 STRCPY(name_buf + 1, str);
11672 STRCAT(name_buf, ">");
11673
11674 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11675 {
11676 if (loop == 0)
11677 num_term++;
11678 else
11679 (*file)[count++] = vim_strsave(name_buf);
11680 }
11681 }
11682 }
11683 if (loop == 0)
11684 {
11685 if (num_normal > 0)
11686 *num_file = num_normal;
11687 else if (num_term > 0)
11688 *num_file = num_term;
11689 else
11690 return OK;
11691 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11692 if (*file == NULL)
11693 {
11694 *file = (char_u **)"";
11695 return FAIL;
11696 }
11697 }
11698 }
11699 return OK;
11700}
11701
11702 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011703ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011704{
11705 char_u *var = NULL; /* init for GCC */
11706 char_u *buf;
11707
11708 *num_file = 0;
11709 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11710 if (*file == NULL)
11711 return FAIL;
11712
11713 /*
11714 * For a terminal key code expand_option_idx is < 0.
11715 */
11716 if (expand_option_idx < 0)
11717 {
11718 var = find_termcode(expand_option_name + 2);
11719 if (var == NULL)
11720 expand_option_idx = findoption(expand_option_name);
11721 }
11722
11723 if (expand_option_idx >= 0)
11724 {
11725 /* put string of option value in NameBuff */
11726 option_value2string(&options[expand_option_idx], expand_option_flags);
11727 var = NameBuff;
11728 }
11729 else if (var == NULL)
11730 var = (char_u *)"";
11731
11732 /* A backslash is required before some characters. This is the reverse of
11733 * what happens in do_set(). */
11734 buf = vim_strsave_escaped(var, escape_chars);
11735
11736 if (buf == NULL)
11737 {
11738 vim_free(*file);
11739 *file = NULL;
11740 return FAIL;
11741 }
11742
11743#ifdef BACKSLASH_IN_FILENAME
11744 /* For MS-Windows et al. we don't double backslashes at the start and
11745 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011746 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011747 if (var[0] == '\\' && var[1] == '\\'
11748 && expand_option_idx >= 0
11749 && (options[expand_option_idx].flags & P_EXPAND)
11750 && vim_isfilec(var[2])
11751 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011752 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011753#endif
11754
11755 *file[0] = buf;
11756 *num_file = 1;
11757 return OK;
11758}
11759#endif
11760
11761/*
11762 * Get the value for the numeric or string option *opp in a nice format into
11763 * NameBuff[]. Must not be called with a hidden option!
11764 */
11765 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011766option_value2string(
11767 struct vimoption *opp,
11768 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011769{
11770 char_u *varp;
11771
11772 varp = get_varp_scope(opp, opt_flags);
11773
11774 if (opp->flags & P_NUM)
11775 {
11776 long wc = 0;
11777
11778 if (wc_use_keyname(varp, &wc))
11779 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11780 else if (wc != 0)
11781 STRCPY(NameBuff, transchar((int)wc));
11782 else
11783 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11784 }
11785 else /* P_STRING */
11786 {
11787 varp = *(char_u **)(varp);
11788 if (varp == NULL) /* just in case */
11789 NameBuff[0] = NUL;
11790#ifdef FEAT_CRYPT
11791 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011792 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011793 STRCPY(NameBuff, "*****");
11794#endif
11795 else if (opp->flags & P_EXPAND)
11796 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11797 /* Translate 'pastetoggle' into special key names */
11798 else if ((char_u **)opp->var == &p_pt)
11799 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11800 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011801 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011802 }
11803}
11804
11805/*
11806 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11807 * printed as a keyname.
11808 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11809 */
11810 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011811wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011812{
11813 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11814 {
11815 *wcp = *(long *)varp;
11816 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11817 return TRUE;
11818 }
11819 return FALSE;
11820}
11821
Bram Moolenaar01615492015-02-03 13:00:38 +010011822#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011823/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011824 * Any character has an equivalent 'langmap' character. This is used for
11825 * keyboards that have a special language mode that sends characters above
11826 * 128 (although other characters can be translated too). The "to" field is a
11827 * Vim command character. This avoids having to switch the keyboard back to
11828 * ASCII mode when leaving Insert mode.
11829 *
11830 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11831 * commands.
11832 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11833 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11834 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011835 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011836# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011837/*
11838 * With multi-byte support use growarray for 'langmap' chars >= 256
11839 */
11840typedef struct
11841{
11842 int from;
11843 int to;
11844} langmap_entry_T;
11845
11846static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011847static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011848
11849/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011850 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11851 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011852 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011853 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011854langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011855{
11856 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011857 int a = 0;
11858 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011859
11860 /* Do a binary search for an existing entry. */
11861 while (a != b)
11862 {
11863 int i = (a + b) / 2;
11864 int d = entries[i].from - from;
11865
11866 if (d == 0)
11867 {
11868 entries[i].to = to;
11869 return;
11870 }
11871 if (d < 0)
11872 a = i + 1;
11873 else
11874 b = i;
11875 }
11876
11877 if (ga_grow(&langmap_mapga, 1) != OK)
11878 return; /* out of memory */
11879
11880 /* insert new entry at position "a" */
11881 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11882 mch_memmove(entries + 1, entries,
11883 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11884 ++langmap_mapga.ga_len;
11885 entries[0].from = from;
11886 entries[0].to = to;
11887}
11888
11889/*
11890 * Apply 'langmap' to multi-byte character "c" and return the result.
11891 */
11892 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011893langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011894{
11895 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11896 int a = 0;
11897 int b = langmap_mapga.ga_len;
11898
11899 while (a != b)
11900 {
11901 int i = (a + b) / 2;
11902 int d = entries[i].from - c;
11903
11904 if (d == 0)
11905 return entries[i].to; /* found matching entry */
11906 if (d < 0)
11907 a = i + 1;
11908 else
11909 b = i;
11910 }
11911 return c; /* no entry found, return "c" unmodified */
11912}
11913# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011914
11915 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011916langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011917{
11918 int i;
11919
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011920 for (i = 0; i < 256; i++)
11921 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11922# ifdef FEAT_MBYTE
11923 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11924# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011925}
11926
11927/*
11928 * Called when langmap option is set; the language map can be
11929 * changed at any time!
11930 */
11931 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011932langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011933{
11934 char_u *p;
11935 char_u *p2;
11936 int from, to;
11937
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011938#ifdef FEAT_MBYTE
11939 ga_clear(&langmap_mapga); /* clear the previous map first */
11940#endif
11941 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011942
11943 for (p = p_langmap; p[0] != NUL; )
11944 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011945 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011946 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947 {
11948 if (p2[0] == '\\' && p2[1] != NUL)
11949 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011950 }
11951 if (p2[0] == ';')
11952 ++p2; /* abcd;ABCD form, p2 points to A */
11953 else
11954 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11955 while (p[0])
11956 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011957 if (p[0] == ',')
11958 {
11959 ++p;
11960 break;
11961 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011962 if (p[0] == '\\' && p[1] != NUL)
11963 ++p;
11964#ifdef FEAT_MBYTE
11965 from = (*mb_ptr2char)(p);
11966#else
11967 from = p[0];
11968#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011969 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011970 if (p2 == NULL)
11971 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011972 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011973 if (p[0] != ',')
11974 {
11975 if (p[0] == '\\')
11976 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011978 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011979#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011980 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011981#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011982 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011983 }
11984 else
11985 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011986 if (p2[0] != ',')
11987 {
11988 if (p2[0] == '\\')
11989 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011990#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011991 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011992#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011993 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011994#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011995 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011996 }
11997 if (to == NUL)
11998 {
11999 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12000 transchar(from));
12001 return;
12002 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012003
12004#ifdef FEAT_MBYTE
12005 if (from >= 256)
12006 langmap_set_entry(from, to);
12007 else
12008#endif
12009 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012010
12011 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012012 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012013 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012014 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012015 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012016 if (*p == ';')
12017 {
12018 p = p2;
12019 if (p[0] != NUL)
12020 {
12021 if (p[0] != ',')
12022 {
12023 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12024 return;
12025 }
12026 ++p;
12027 }
12028 break;
12029 }
12030 }
12031 }
12032 }
12033}
12034#endif
12035
12036/*
12037 * Return TRUE if format option 'x' is in effect.
12038 * Take care of no formatting when 'paste' is set.
12039 */
12040 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012041has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012042{
12043 if (p_paste)
12044 return FALSE;
12045 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12046}
12047
12048/*
12049 * Return TRUE if "x" is present in 'shortmess' option, or
12050 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12051 */
12052 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012053shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012054{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012055 return p_shm != NULL &&
12056 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012057 || (vim_strchr(p_shm, 'a') != NULL
12058 && vim_strchr((char_u *)SHM_A, x) != NULL));
12059}
12060
12061/*
12062 * paste_option_changed() - Called after p_paste was set or reset.
12063 */
12064 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012065paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012066{
12067 static int old_p_paste = FALSE;
12068 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012069 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070#ifdef FEAT_CMDL_INFO
12071 static int save_ru = 0;
12072#endif
12073#ifdef FEAT_RIGHTLEFT
12074 static int save_ri = 0;
12075 static int save_hkmap = 0;
12076#endif
12077 buf_T *buf;
12078
12079 if (p_paste)
12080 {
12081 /*
12082 * Paste switched from off to on.
12083 * Save the current values, so they can be restored later.
12084 */
12085 if (!old_p_paste)
12086 {
12087 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012088 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012089 {
12090 buf->b_p_tw_nopaste = buf->b_p_tw;
12091 buf->b_p_wm_nopaste = buf->b_p_wm;
12092 buf->b_p_sts_nopaste = buf->b_p_sts;
12093 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012094 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095 }
12096
12097 /* save global options */
12098 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012099 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012100#ifdef FEAT_CMDL_INFO
12101 save_ru = p_ru;
12102#endif
12103#ifdef FEAT_RIGHTLEFT
12104 save_ri = p_ri;
12105 save_hkmap = p_hkmap;
12106#endif
12107 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012108 p_ai_nopaste = p_ai;
12109 p_et_nopaste = p_et;
12110 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012111 p_tw_nopaste = p_tw;
12112 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012113 }
12114
12115 /*
12116 * Always set the option values, also when 'paste' is set when it is
12117 * already on.
12118 */
12119 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012120 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121 {
12122 buf->b_p_tw = 0; /* textwidth is 0 */
12123 buf->b_p_wm = 0; /* wrapmargin is 0 */
12124 buf->b_p_sts = 0; /* softtabstop is 0 */
12125 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012126 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012127 }
12128
12129 /* set global options */
12130 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012131 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012132#ifdef FEAT_CMDL_INFO
12133# ifdef FEAT_WINDOWS
12134 if (p_ru)
12135 status_redraw_all(); /* redraw to remove the ruler */
12136# endif
12137 p_ru = 0; /* no ruler */
12138#endif
12139#ifdef FEAT_RIGHTLEFT
12140 p_ri = 0; /* no reverse insert */
12141 p_hkmap = 0; /* no Hebrew keyboard */
12142#endif
12143 /* set global values for local buffer options */
12144 p_tw = 0;
12145 p_wm = 0;
12146 p_sts = 0;
12147 p_ai = 0;
12148 }
12149
12150 /*
12151 * Paste switched from on to off: Restore saved values.
12152 */
12153 else if (old_p_paste)
12154 {
12155 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012156 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012157 {
12158 buf->b_p_tw = buf->b_p_tw_nopaste;
12159 buf->b_p_wm = buf->b_p_wm_nopaste;
12160 buf->b_p_sts = buf->b_p_sts_nopaste;
12161 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012162 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012163 }
12164
12165 /* restore global options */
12166 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012167 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012168#ifdef FEAT_CMDL_INFO
12169# ifdef FEAT_WINDOWS
12170 if (p_ru != save_ru)
12171 status_redraw_all(); /* redraw to draw the ruler */
12172# endif
12173 p_ru = save_ru;
12174#endif
12175#ifdef FEAT_RIGHTLEFT
12176 p_ri = save_ri;
12177 p_hkmap = save_hkmap;
12178#endif
12179 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012180 p_ai = p_ai_nopaste;
12181 p_et = p_et_nopaste;
12182 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012183 p_tw = p_tw_nopaste;
12184 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012185 }
12186
12187 old_p_paste = p_paste;
12188}
12189
12190/*
12191 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12192 *
12193 * Reset 'compatible' and set the values for options that didn't get set yet
12194 * to the Vim defaults.
12195 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012196 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012197 */
12198 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012199vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012200{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012201 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012202 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012203 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012204
12205 if (!option_was_set((char_u *)"cp"))
12206 {
12207 p_cp = FALSE;
12208 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12209 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12210 set_option_default(opt_idx, OPT_FREE, FALSE);
12211 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012212 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012213 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012214
12215 if (fname != NULL)
12216 {
12217 p = vim_getenv(envname, &dofree);
12218 if (p == NULL)
12219 {
12220 /* Set $MYVIMRC to the first vimrc file found. */
12221 p = FullName_save(fname, FALSE);
12222 if (p != NULL)
12223 {
12224 vim_setenv(envname, p);
12225 vim_free(p);
12226 }
12227 }
12228 else if (dofree)
12229 vim_free(p);
12230 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012231}
12232
12233/*
12234 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12235 */
12236 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012237change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012238{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012239 int opt_idx;
12240
Bram Moolenaar071d4272004-06-13 20:20:40 +000012241 if (p_cp != on)
12242 {
12243 p_cp = on;
12244 compatible_set();
12245 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012246 opt_idx = findoption((char_u *)"cp");
12247 if (opt_idx >= 0)
12248 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249}
12250
12251/*
12252 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012253 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012254 */
12255 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012256option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012257{
12258 int idx;
12259
12260 idx = findoption(name);
12261 if (idx < 0) /* unknown option */
12262 return FALSE;
12263 if (options[idx].flags & P_WAS_SET)
12264 return TRUE;
12265 return FALSE;
12266}
12267
12268/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012269 * Reset the flag indicating option "name" was set.
12270 */
12271 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012272reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012273{
12274 int idx = findoption(name);
12275
12276 if (idx >= 0)
12277 options[idx].flags &= ~P_WAS_SET;
12278}
12279
12280/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012281 * compatible_set() - Called when 'compatible' has been set or unset.
12282 *
12283 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12284 * flag) to a Vi compatible value.
12285 * When 'compatible' is unset: Set all options that have a different default
12286 * for Vim (without the P_VI_DEF flag) to that default.
12287 */
12288 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012289compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012290{
12291 int opt_idx;
12292
12293 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12294 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12295 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12296 set_option_default(opt_idx, OPT_FREE, p_cp);
12297 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012298 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012299}
12300
12301#ifdef FEAT_LINEBREAK
12302
12303# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12304 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012305 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306# endif
12307
12308/*
12309 * fill_breakat_flags() -- called when 'breakat' changes value.
12310 */
12311 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012312fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012313{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012314 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012315 int i;
12316
12317 for (i = 0; i < 256; i++)
12318 breakat_flags[i] = FALSE;
12319
12320 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012321 for (p = p_breakat; *p; p++)
12322 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012323}
12324
12325# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012326 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012327# endif
12328
12329#endif
12330
12331/*
12332 * Check an option that can be a range of string values.
12333 *
12334 * Return OK for correct value, FAIL otherwise.
12335 * Empty is always OK.
12336 */
12337 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012338check_opt_strings(
12339 char_u *val,
12340 char **values,
12341 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012342{
12343 return opt_strings_flags(val, values, NULL, list);
12344}
12345
12346/*
12347 * Handle an option that can be a range of string values.
12348 * Set a flag in "*flagp" for each string present.
12349 *
12350 * Return OK for correct value, FAIL otherwise.
12351 * Empty is always OK.
12352 */
12353 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012354opt_strings_flags(
12355 char_u *val, /* new value */
12356 char **values, /* array of valid string values */
12357 unsigned *flagp,
12358 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012359{
12360 int i;
12361 int len;
12362 unsigned new_flags = 0;
12363
12364 while (*val)
12365 {
12366 for (i = 0; ; ++i)
12367 {
12368 if (values[i] == NULL) /* val not found in values[] */
12369 return FAIL;
12370
12371 len = (int)STRLEN(values[i]);
12372 if (STRNCMP(values[i], val, len) == 0
12373 && ((list && val[len] == ',') || val[len] == NUL))
12374 {
12375 val += len + (val[len] == ',');
12376 new_flags |= (1 << i);
12377 break; /* check next item in val list */
12378 }
12379 }
12380 }
12381 if (flagp != NULL)
12382 *flagp = new_flags;
12383
12384 return OK;
12385}
12386
12387/*
12388 * Read the 'wildmode' option, fill wim_flags[].
12389 */
12390 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012391check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012392{
12393 char_u new_wim_flags[4];
12394 char_u *p;
12395 int i;
12396 int idx = 0;
12397
12398 for (i = 0; i < 4; ++i)
12399 new_wim_flags[i] = 0;
12400
12401 for (p = p_wim; *p; ++p)
12402 {
12403 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12404 ;
12405 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12406 return FAIL;
12407 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12408 new_wim_flags[idx] |= WIM_LONGEST;
12409 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12410 new_wim_flags[idx] |= WIM_FULL;
12411 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12412 new_wim_flags[idx] |= WIM_LIST;
12413 else
12414 return FAIL;
12415 p += i;
12416 if (*p == NUL)
12417 break;
12418 if (*p == ',')
12419 {
12420 if (idx == 3)
12421 return FAIL;
12422 ++idx;
12423 }
12424 }
12425
12426 /* fill remaining entries with last flag */
12427 while (idx < 3)
12428 {
12429 new_wim_flags[idx + 1] = new_wim_flags[idx];
12430 ++idx;
12431 }
12432
12433 /* only when there are no errors, wim_flags[] is changed */
12434 for (i = 0; i < 4; ++i)
12435 wim_flags[i] = new_wim_flags[i];
12436 return OK;
12437}
12438
12439/*
12440 * Check if backspacing over something is allowed.
12441 */
12442 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012443can_bs(
12444 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012445{
12446 switch (*p_bs)
12447 {
12448 case '2': return TRUE;
12449 case '1': return (what != BS_START);
12450 case '0': return FALSE;
12451 }
12452 return vim_strchr(p_bs, what) != NULL;
12453}
12454
12455/*
12456 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12457 * the file must be considered changed when the value is different.
12458 */
12459 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012460save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012461{
12462 buf->b_start_ffc = *buf->b_p_ff;
12463 buf->b_start_eol = buf->b_p_eol;
12464#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012465 buf->b_start_bomb = buf->b_p_bomb;
12466
Bram Moolenaar071d4272004-06-13 20:20:40 +000012467 /* Only use free/alloc when necessary, they take time. */
12468 if (buf->b_start_fenc == NULL
12469 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12470 {
12471 vim_free(buf->b_start_fenc);
12472 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12473 }
12474#endif
12475}
12476
12477/*
12478 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12479 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012480 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12481 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012482 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012483 * When "ignore_empty" is true don't consider a new, empty buffer to be
12484 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012485 */
12486 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012487file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012488{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012489 /* In a buffer that was never loaded the options are not valid. */
12490 if (buf->b_flags & BF_NEVERLOADED)
12491 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012492 if (ignore_empty
12493 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012494 && buf->b_ml.ml_line_count == 1
12495 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12496 return FALSE;
12497 if (buf->b_start_ffc != *buf->b_p_ff)
12498 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012499 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012500 return TRUE;
12501#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012502 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12503 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012504 if (buf->b_start_fenc == NULL)
12505 return (*buf->b_p_fenc != NUL);
12506 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12507#else
12508 return FALSE;
12509#endif
12510}
12511
12512/*
12513 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12514 */
12515 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012516check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012517{
12518 return check_opt_strings(p, p_ff_values, FALSE);
12519}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012520
12521/*
12522 * Return the effective shiftwidth value for current buffer, using the
12523 * 'tabstop' value when 'shiftwidth' is zero.
12524 */
12525 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012526get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012527{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012528 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012529}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012530
12531/*
12532 * Return the effective softtabstop value for the current buffer, using the
12533 * 'tabstop' value when 'softtabstop' is negative.
12534 */
12535 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012536get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012537{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012538 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012539}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012540
12541/*
12542 * Check matchpairs option for "*initc".
12543 * If there is a match set "*initc" to the matching character and "*findc" to
12544 * the opposite character. Set "*backwards" to the direction.
12545 * When "switchit" is TRUE swap the direction.
12546 */
12547 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012548find_mps_values(
12549 int *initc,
12550 int *findc,
12551 int *backwards,
12552 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012553{
12554 char_u *ptr;
12555
12556 ptr = curbuf->b_p_mps;
12557 while (*ptr != NUL)
12558 {
12559#ifdef FEAT_MBYTE
12560 if (has_mbyte)
12561 {
12562 char_u *prev;
12563
12564 if (mb_ptr2char(ptr) == *initc)
12565 {
12566 if (switchit)
12567 {
12568 *findc = *initc;
12569 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12570 *backwards = TRUE;
12571 }
12572 else
12573 {
12574 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12575 *backwards = FALSE;
12576 }
12577 return;
12578 }
12579 prev = ptr;
12580 ptr += mb_ptr2len(ptr) + 1;
12581 if (mb_ptr2char(ptr) == *initc)
12582 {
12583 if (switchit)
12584 {
12585 *findc = *initc;
12586 *initc = mb_ptr2char(prev);
12587 *backwards = FALSE;
12588 }
12589 else
12590 {
12591 *findc = mb_ptr2char(prev);
12592 *backwards = TRUE;
12593 }
12594 return;
12595 }
12596 ptr += mb_ptr2len(ptr);
12597 }
12598 else
12599#endif
12600 {
12601 if (*ptr == *initc)
12602 {
12603 if (switchit)
12604 {
12605 *backwards = TRUE;
12606 *findc = *initc;
12607 *initc = ptr[2];
12608 }
12609 else
12610 {
12611 *backwards = FALSE;
12612 *findc = ptr[2];
12613 }
12614 return;
12615 }
12616 ptr += 2;
12617 if (*ptr == *initc)
12618 {
12619 if (switchit)
12620 {
12621 *backwards = FALSE;
12622 *findc = *initc;
12623 *initc = ptr[-2];
12624 }
12625 else
12626 {
12627 *backwards = TRUE;
12628 *findc = ptr[-2];
12629 }
12630 return;
12631 }
12632 ++ptr;
12633 }
12634 if (*ptr == ',')
12635 ++ptr;
12636 }
12637}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012638
12639#if defined(FEAT_LINEBREAK) || defined(PROTO)
12640/*
12641 * This is called when 'breakindentopt' is changed and when a window is
12642 * initialized.
12643 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012644 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012645briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012646{
12647 char_u *p;
12648 int bri_shift = 0;
12649 long bri_min = 20;
12650 int bri_sbr = FALSE;
12651
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012652 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012653 while (*p != NUL)
12654 {
12655 if (STRNCMP(p, "shift:", 6) == 0
12656 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12657 {
12658 p += 6;
12659 bri_shift = getdigits(&p);
12660 }
12661 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12662 {
12663 p += 4;
12664 bri_min = getdigits(&p);
12665 }
12666 else if (STRNCMP(p, "sbr", 3) == 0)
12667 {
12668 p += 3;
12669 bri_sbr = TRUE;
12670 }
12671 if (*p != ',' && *p != NUL)
12672 return FAIL;
12673 if (*p == ',')
12674 ++p;
12675 }
12676
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012677 wp->w_p_brishift = bri_shift;
12678 wp->w_p_brimin = bri_min;
12679 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012680
12681 return OK;
12682}
12683#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012684
12685/*
12686 * Get the local or global value of 'backupcopy'.
12687 */
12688 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012689get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012690{
12691 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12692}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012693
12694#if defined(FEAT_SIGNS) || defined(PROTO)
12695/*
12696 * Return TRUE when window "wp" has a column to draw signs in.
12697 */
12698 int
12699signcolumn_on(win_T *wp)
12700{
12701 if (*wp->w_p_scl == 'n')
12702 return FALSE;
12703 if (*wp->w_p_scl == 'y')
12704 return TRUE;
12705 return (wp->w_buffer->b_signlist != NULL
12706# ifdef FEAT_NETBEANS_INTG
12707 || wp->w_buffer->b_has_sign_column
12708# endif
12709 );
12710}
12711#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012712
12713#if defined(FEAT_EVAL) || defined(PROTO)
12714/*
12715 * Get window or buffer local options.
12716 */
12717 dict_T *
12718get_winbuf_options(int bufopt)
12719{
12720 dict_T *d;
12721 int opt_idx;
12722
12723 d = dict_alloc();
12724 if (d == NULL)
12725 return NULL;
12726
12727 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12728 {
12729 struct vimoption *opt = &options[opt_idx];
12730
12731 if ((bufopt && (opt->indir & PV_BUF))
12732 || (!bufopt && (opt->indir & PV_WIN)))
12733 {
12734 char_u *varp = get_varp(opt);
12735
12736 if (varp != NULL)
12737 {
12738 if (opt->flags & P_STRING)
12739 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012740 else if (opt->flags & P_NUM)
12741 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012742 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012743 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012744 }
12745 }
12746 }
12747
12748 return d;
12749}
12750#endif