blob: 5f8489fdd46684ec19c2cc31fe5887aadcdd8129 [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 Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290static char_u *p_bh;
291static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000292static int p_bl;
293static int p_ci;
294#ifdef FEAT_CINDENT
295static int p_cin;
296static char_u *p_cink;
297static char_u *p_cino;
298#endif
299#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
300static char_u *p_cinw;
301#endif
302#ifdef FEAT_COMMENTS
303static char_u *p_com;
304#endif
305#ifdef FEAT_FOLDING
306static char_u *p_cms;
307#endif
308#ifdef FEAT_INS_EXPAND
309static char_u *p_cpt;
310#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000311#ifdef FEAT_COMPL_FUNC
312static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000313static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000314#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200316static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static int p_et;
318#ifdef FEAT_MBYTE
319static char_u *p_fenc;
320#endif
321static char_u *p_ff;
322static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000323static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324#ifdef FEAT_AUTOCMD
325static char_u *p_ft;
326#endif
327static long p_iminsert;
328static long p_imsearch;
329#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
330static char_u *p_inex;
331#endif
332#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
333static char_u *p_inde;
334static char_u *p_indk;
335#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000336#if defined(FEAT_EVAL)
337static char_u *p_fex;
338#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339static int p_inf;
340static char_u *p_isk;
341#ifdef FEAT_CRYPT
342static char_u *p_key;
343#endif
344#ifdef FEAT_LISP
345static int p_lisp;
346#endif
347static int p_ml;
348static int p_ma;
349static int p_mod;
350static char_u *p_mps;
351static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000353#ifdef FEAT_TEXTOBJ
354static char_u *p_qe;
355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static int p_ro;
357#ifdef FEAT_SMARTINDENT
358static int p_si;
359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361static long p_sts;
362#if defined(FEAT_SEARCHPATH)
363static char_u *p_sua;
364#endif
365static long p_sw;
366static int p_swf;
367#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000368static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000370#endif
371#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000372static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000373static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000374static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375#endif
376static long p_ts;
377static long p_tw;
378static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200379#ifdef FEAT_PERSISTENT_UNDO
380static int p_udf;
381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382static long p_wm;
383#ifdef FEAT_KEYMAP
384static char_u *p_keymap;
385#endif
386
387/* Saved values for when 'bin' is set. */
388static int p_et_nobin;
389static int p_ml_nobin;
390static long p_tw_nobin;
391static long p_wm_nobin;
392
393/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200394static int p_ai_nopaste;
395static int p_et_nopaste;
396static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397static long p_tw_nopaste;
398static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399
400struct vimoption
401{
402 char *fullname; /* full option name */
403 char *shortname; /* permissible abbreviation */
404 long_u flags; /* see below */
405 char_u *var; /* global option: pointer to variable;
406 * window-local option: VAR_WIN;
407 * buffer-local option: global value */
408 idopt_T indir; /* global option: PV_NONE;
409 * local option: indirect option index */
410 char_u *def_val[2]; /* default values for variable (vi and vim) */
411#ifdef FEAT_EVAL
412 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000413# define SCRIPTID_INIT , 0
414#else
415# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416#endif
417};
418
419#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
420#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
421
422/*
423 * Flags
424 */
425#define P_BOOL 0x01 /* the option is boolean */
426#define P_NUM 0x02 /* the option is numeric */
427#define P_STRING 0x04 /* the option is a string */
428#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000429 must use free_string_option() when
430 assigning new value. Not set if default is
431 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000432#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
433 never be used for local or hidden options! */
434#define P_NODEFAULT 0x40 /* don't set to default value */
435#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
436 use vim_free() when assigning new value */
437#define P_WAS_SET 0x100 /* option has been set/reset */
438#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
439#define P_VI_DEF 0x400 /* Use Vi default for Vim */
440#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
441
442 /* when option changed, what to display: */
443#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100444#define P_RWIN 0x2000 /* redraw current window and recompute text */
445#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000446#define P_RALL 0x6000 /* redraw all windows */
447#define P_RCLR 0x7000 /* clear and redraw all */
448
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200449#define P_COMMA 0x8000 /* comma separated list */
450#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
451 * commas */
452#define P_NODUP 0x20000L /* don't allow duplicate strings */
453#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000454
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200455#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
456#define P_GETTEXT 0x100000L /* expand default value with _() */
457#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
458#define P_NFNAME 0x400000L /* only normal file name chars allowed */
459#define P_INSECURE 0x800000L /* option was set from a modeline */
460#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100461 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200462#define P_NO_ML 0x2000000L /* not allowed in modeline */
463#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200464 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100465#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100466#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000467
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000468#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
469
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000470/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
471 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100472#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000473# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000474#else
475# define ISP_LATIN1 (char_u *)"@,161-255"
476#endif
477
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100478/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000479#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100480 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar21020352017-06-13 17:21:04 +0200481 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) \
Bram Moolenaar3633cf52017-07-31 22:29:35 +0200482 || defined(FEAT_CONCEAL) || defined(FEAT_QUICKFIX) \
483 || defined(FEAT_TERMINAL)
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200484# 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,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000485#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100486# 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 +0000487#endif
488
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100489/* Default python version for pyx* commands */
490#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
491# define DEFAULT_PYTHON_VER 0
492#elif defined(FEAT_PYTHON3)
493# define DEFAULT_PYTHON_VER 3
494#elif defined(FEAT_PYTHON)
495# define DEFAULT_PYTHON_VER 2
496#else
497# define DEFAULT_PYTHON_VER 0
498#endif
499
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500/*
501 * options[] is initialized here.
502 * The order of the options MUST be alphabetic for ":set all" and findoption().
503 * All option names MUST start with a lowercase letter (for findoption()).
504 * Exception: "t_" options are at the end.
505 * The options with a NULL variable are 'hidden': a set command for them is
506 * ignored and they are not printed.
507 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100508static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200510 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511#ifdef FEAT_RIGHTLEFT
512 (char_u *)&p_aleph, PV_NONE,
513#else
514 (char_u *)NULL, PV_NONE,
515#endif
516 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100517#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 (char_u *)128L,
519#else
520 (char_u *)224L,
521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000522 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000523 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
524#if defined(FEAT_GUI) && defined(MACOS_X)
525 (char_u *)&p_antialias, PV_NONE,
526 {(char_u *)FALSE, (char_u *)FALSE}
527#else
528 (char_u *)NULL, PV_NONE,
529 {(char_u *)FALSE, (char_u *)FALSE}
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200532 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533#ifdef FEAT_ARABIC
534 (char_u *)VAR_WIN, PV_ARAB,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000538 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
540#ifdef FEAT_ARABIC
541 (char_u *)&p_arshape, PV_NONE,
542#else
543 (char_u *)NULL, PV_NONE,
544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000545 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
547#ifdef FEAT_RIGHTLEFT
548 (char_u *)&p_ari, PV_NONE,
549#else
550 (char_u *)NULL, PV_NONE,
551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
554#ifdef FEAT_FKMAP
555 (char_u *)&p_altkeymap, PV_NONE,
556#else
557 (char_u *)NULL, PV_NONE,
558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
561#if defined(FEAT_MBYTE)
562 (char_u *)&p_ambw, PV_NONE,
563 {(char_u *)"single", (char_u *)0L}
564#else
565 (char_u *)NULL, PV_NONE,
566 {(char_u *)0L, (char_u *)0L}
567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100570#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100572 {(char_u *)FALSE, (char_u *)0L}
573#else
574 (char_u *)NULL, PV_NONE,
575 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100577 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"autoindent", "ai", P_BOOL|P_VI_DEF,
579 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"autoprint", "ap", P_BOOL|P_VI_DEF,
582 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000585 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 {"autowrite", "aw", P_BOOL|P_VI_DEF,
588 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000589 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 {"autowriteall","awa", P_BOOL|P_VI_DEF,
591 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000592 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
594 (char_u *)&p_bg, PV_NONE,
595 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100596#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 (char_u *)"dark",
598#else
599 (char_u *)"light",
600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000601 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200602 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
606 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000607 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200608 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200609 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610#ifdef UNIX
611 {(char_u *)"yes", (char_u *)"auto"}
612#else
613 {(char_u *)"auto", (char_u *)"auto"}
614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200616 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
617 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000620 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 (char_u *)&p_bex, PV_NONE,
622 {
623#ifdef VMS
624 (char_u *)"_",
625#else
626 (char_u *)"~",
627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200629 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630#ifdef FEAT_WILDIGN
631 (char_u *)&p_bsk, PV_NONE,
632 {(char_u *)"", (char_u *)0L}
633#else
634 (char_u *)NULL, PV_NONE,
635 {(char_u *)0L, (char_u *)0L}
636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100639#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100641 {(char_u *)600L, (char_u *)0L}
642#else
643 (char_u *)NULL, PV_NONE,
644 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100646 SCRIPTID_INIT},
647 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
648#ifdef FEAT_BEVAL
649 (char_u *)&p_beval, PV_NONE,
650 {(char_u *)FALSE, (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
655 SCRIPTID_INIT},
656 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
657#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
658 (char_u *)&p_bexpr, PV_BEXPR,
659 {(char_u *)"", (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
664 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"beautify", "bf", P_BOOL|P_VI_DEF,
666 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200668 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
669 (char_u *)&p_bo, PV_NONE,
670 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
672 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000673 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000676 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
678#ifdef FEAT_MBYTE
679 (char_u *)&p_bomb, PV_BOMB,
680#else
681 (char_u *)NULL, PV_NONE,
682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000683 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
685#ifdef FEAT_LINEBREAK
686 (char_u *)&p_breakat, PV_NONE,
687 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
688#else
689 (char_u *)NULL, PV_NONE,
690 {(char_u *)0L, (char_u *)0L}
691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000692 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200693 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
694#ifdef FEAT_LINEBREAK
695 (char_u *)VAR_WIN, PV_BRI,
696 {(char_u *)FALSE, (char_u *)0L}
697#else
698 (char_u *)NULL, PV_NONE,
699 {(char_u *)0L, (char_u *)0L}
700#endif
701 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200702 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
703 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200704#ifdef FEAT_LINEBREAK
705 (char_u *)VAR_WIN, PV_BRIOPT,
706 {(char_u *)"", (char_u *)NULL}
707#else
708 (char_u *)NULL, PV_NONE,
709 {(char_u *)"", (char_u *)NULL}
710#endif
711 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
713#ifdef FEAT_BROWSE
714 (char_u *)&p_bsdir, PV_NONE,
715 {(char_u *)"last", (char_u *)0L}
716#else
717 (char_u *)NULL, PV_NONE,
718 {(char_u *)0L, (char_u *)0L}
719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000720 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 (char_u *)&p_bh, PV_BH,
723 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
726 (char_u *)&p_bl, PV_BL,
727 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000728 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 (char_u *)&p_bt, PV_BT,
731 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000732 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200733 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000734#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735 (char_u *)&p_cmp, PV_NONE,
736 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000737#else
738 (char_u *)NULL, PV_NONE,
739 {(char_u *)0L, (char_u *)0L}
740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000741 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
743#ifdef FEAT_SEARCHPATH
744 (char_u *)&p_cdpath, PV_NONE,
745 {(char_u *)",,", (char_u *)0L}
746#else
747 (char_u *)NULL, PV_NONE,
748 {(char_u *)0L, (char_u *)0L}
749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000750 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 {"cedit", NULL, P_STRING,
752#ifdef FEAT_CMDWIN
753 (char_u *)&p_cedit, PV_NONE,
754 {(char_u *)"", (char_u *)CTRL_F_STR}
755#else
756 (char_u *)NULL, PV_NONE,
757 {(char_u *)0L, (char_u *)0L}
758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000759 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
761#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
762 (char_u *)&p_ccv, PV_NONE,
763 {(char_u *)"", (char_u *)0L}
764#else
765 (char_u *)NULL, PV_NONE,
766 {(char_u *)0L, (char_u *)0L}
767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000768 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
770#ifdef FEAT_CINDENT
771 (char_u *)&p_cin, PV_CIN,
772#else
773 (char_u *)NULL, PV_NONE,
774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000775 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200776 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777#ifdef FEAT_CINDENT
778 (char_u *)&p_cink, PV_CINK,
779 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
780#else
781 (char_u *)NULL, PV_NONE,
782 {(char_u *)0L, (char_u *)0L}
783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000784 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200785 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786#ifdef FEAT_CINDENT
787 (char_u *)&p_cino, PV_CINO,
788#else
789 (char_u *)NULL, PV_NONE,
790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000791 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200792 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
794 (char_u *)&p_cinw, PV_CINW,
795 {(char_u *)"if,else,while,do,for,switch",
796 (char_u *)0L}
797#else
798 (char_u *)NULL, PV_NONE,
799 {(char_u *)0L, (char_u *)0L}
800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000801 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200802 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000803#ifdef FEAT_CLIPBOARD
804 (char_u *)&p_cb, PV_NONE,
805# ifdef FEAT_XCLIPBOARD
806 {(char_u *)"autoselect,exclude:cons\\|linux",
807 (char_u *)0L}
808# else
809 {(char_u *)"", (char_u *)0L}
810# endif
811#else
812 (char_u *)NULL, PV_NONE,
813 {(char_u *)"", (char_u *)0L}
814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000815 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
817 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000818 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
820#ifdef FEAT_CMDWIN
821 (char_u *)&p_cwh, PV_NONE,
822#else
823 (char_u *)NULL, PV_NONE,
824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200826 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200827#ifdef FEAT_SYN_HL
828 (char_u *)VAR_WIN, PV_CC,
829#else
830 (char_u *)NULL, PV_NONE,
831#endif
832 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
834 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000835 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200836 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
837 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838#ifdef FEAT_COMMENTS
839 (char_u *)&p_com, PV_COM,
840 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
841 (char_u *)0L}
842#else
843 (char_u *)NULL, PV_NONE,
844 {(char_u *)0L, (char_u *)0L}
845#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000846 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200847 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848#ifdef FEAT_FOLDING
849 (char_u *)&p_cms, PV_CMS,
850 {(char_u *)"/*%s*/", (char_u *)0L}
851#else
852 (char_u *)NULL, PV_NONE,
853 {(char_u *)0L, (char_u *)0L}
854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000855 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000856 /* P_PRI_MKRC isn't needed here, optval_default()
857 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000858 {"compatible", "cp", P_BOOL|P_RALL,
859 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000860 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200861 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862#ifdef FEAT_INS_EXPAND
863 (char_u *)&p_cpt, PV_CPT,
864 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
865#else
866 (char_u *)NULL, PV_NONE,
867 {(char_u *)0L, (char_u *)0L}
868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000869 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200870 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200871#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200872 (char_u *)VAR_WIN, PV_COCU,
873 {(char_u *)"", (char_u *)NULL}
874#else
875 (char_u *)NULL, PV_NONE,
876 {(char_u *)NULL, (char_u *)0L}
877#endif
878 SCRIPTID_INIT},
879 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
880#ifdef FEAT_CONCEAL
881 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200882#else
883 (char_u *)NULL, PV_NONE,
884#endif
885 {(char_u *)0L, (char_u *)0L}
886 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000887 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
888#ifdef FEAT_COMPL_FUNC
889 (char_u *)&p_cfu, PV_CFU,
890 {(char_u *)"", (char_u *)0L}
891#else
892 (char_u *)NULL, PV_NONE,
893 {(char_u *)0L, (char_u *)0L}
894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000895 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200896 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000897#ifdef FEAT_INS_EXPAND
898 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000899 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000900#else
901 (char_u *)NULL, PV_NONE,
902 {(char_u *)0L, (char_u *)0L}
903#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"confirm", "cf", P_BOOL|P_VI_DEF,
906#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
907 (char_u *)&p_confirm, PV_NONE,
908#else
909 (char_u *)NULL, PV_NONE,
910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
916 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
919 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
921 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200922 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200923#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200924 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200925 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200926#else
927 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200929#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200930 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
932#ifdef FEAT_CSCOPE
933 (char_u *)&p_cspc, PV_NONE,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_csprg, PV_NONE,
941 {(char_u *)"cscope", (char_u *)0L}
942#else
943 (char_u *)NULL, PV_NONE,
944 {(char_u *)0L, (char_u *)0L}
945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000946 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200947 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
949 (char_u *)&p_csqf, PV_NONE,
950 {(char_u *)"", (char_u *)0L}
951#else
952 (char_u *)NULL, PV_NONE,
953 {(char_u *)0L, (char_u *)0L}
954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000955 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200956 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
957#ifdef FEAT_CSCOPE
958 (char_u *)&p_csre, PV_NONE,
959#else
960 (char_u *)NULL, PV_NONE,
961#endif
962 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
964#ifdef FEAT_CSCOPE
965 (char_u *)&p_cst, PV_NONE,
966#else
967 (char_u *)NULL, PV_NONE,
968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000969 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000970 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
971#ifdef FEAT_CSCOPE
972 (char_u *)&p_csto, PV_NONE,
973#else
974 (char_u *)NULL, PV_NONE,
975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000976 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
978#ifdef FEAT_CSCOPE
979 (char_u *)&p_csverbose, PV_NONE,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200984 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
985#ifdef FEAT_CURSORBIND
986 (char_u *)VAR_WIN, PV_CRBIND,
987#else
988 (char_u *)NULL, PV_NONE,
989#endif
990 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000991 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
992#ifdef FEAT_SYN_HL
993 (char_u *)VAR_WIN, PV_CUC,
994#else
995 (char_u *)NULL, PV_NONE,
996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100998 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000999#ifdef FEAT_SYN_HL
1000 (char_u *)VAR_WIN, PV_CUL,
1001#else
1002 (char_u *)NULL, PV_NONE,
1003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"debug", NULL, P_STRING|P_VI_DEF,
1006 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001007 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001008 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001010 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001011 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#else
1013 (char_u *)NULL, PV_NONE,
1014 {(char_u *)NULL, (char_u *)0L}
1015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1018#ifdef FEAT_MBYTE
1019 (char_u *)&p_deco, PV_NONE,
1020#else
1021 (char_u *)NULL, PV_NONE,
1022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001023 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001024 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001026 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001027#else
1028 (char_u *)NULL, PV_NONE,
1029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1032#ifdef FEAT_DIFF
1033 (char_u *)VAR_WIN, PV_DIFF,
1034#else
1035 (char_u *)NULL, PV_NONE,
1036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001038 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1040 (char_u *)&p_dex, PV_NONE,
1041 {(char_u *)"", (char_u *)0L}
1042#else
1043 (char_u *)NULL, PV_NONE,
1044 {(char_u *)0L, (char_u *)0L}
1045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001046 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001047 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1048 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049#ifdef FEAT_DIFF
1050 (char_u *)&p_dip, PV_NONE,
1051 {(char_u *)"filler", (char_u *)NULL}
1052#else
1053 (char_u *)NULL, PV_NONE,
1054 {(char_u *)"", (char_u *)NULL}
1055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1058#ifdef FEAT_DIGRAPHS
1059 (char_u *)&p_dg, PV_NONE,
1060#else
1061 (char_u *)NULL, PV_NONE,
1062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001064 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1065 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001068 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001072#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 (char_u *)&p_ead, PV_NONE,
1074 {(char_u *)"both", (char_u *)0L}
1075#else
1076 (char_u *)NULL, PV_NONE,
1077 {(char_u *)NULL, (char_u *)0L}
1078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001079 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1081 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001083 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1084#if defined(FEAT_MBYTE)
1085 (char_u *)&p_emoji, PV_NONE,
1086 {(char_u *)TRUE, (char_u *)0L}
1087#else
1088 (char_u *)NULL, PV_NONE,
1089 {(char_u *)0L, (char_u *)0L}
1090#endif
1091 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001092 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093#ifdef FEAT_MBYTE
1094 (char_u *)&p_enc, PV_NONE,
1095 {(char_u *)ENC_DFLT, (char_u *)0L}
1096#else
1097 (char_u *)NULL, PV_NONE,
1098 {(char_u *)0L, (char_u *)0L}
1099#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001100 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1102 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1105 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001108 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1111 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001112 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1114#ifdef FEAT_QUICKFIX
1115 (char_u *)&p_ef, PV_NONE,
1116 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1117#else
1118 (char_u *)NULL, PV_NONE,
1119 {(char_u *)NULL, (char_u *)0L}
1120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001122 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001124 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#else
1127 (char_u *)NULL, PV_NONE,
1128 {(char_u *)NULL, (char_u *)0L}
1129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"esckeys", "ek", P_BOOL|P_VIM,
1132 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135#ifdef FEAT_AUTOCMD
1136 (char_u *)&p_ei, PV_NONE,
1137#else
1138 (char_u *)NULL, PV_NONE,
1139#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1142 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1145 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001147 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1148 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149#ifdef FEAT_MBYTE
1150 (char_u *)&p_fenc, PV_FENC,
1151 {(char_u *)"", (char_u *)0L}
1152#else
1153 (char_u *)NULL, PV_NONE,
1154 {(char_u *)0L, (char_u *)0L}
1155#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001157 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158#ifdef FEAT_MBYTE
1159 (char_u *)&p_fencs, PV_NONE,
1160 {(char_u *)"ucs-bom", (char_u *)0L}
1161#else
1162 (char_u *)NULL, PV_NONE,
1163 {(char_u *)0L, (char_u *)0L}
1164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001166 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1167 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001170 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1173 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001174 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1175 (char_u *)&p_fic, PV_NONE,
1176 {
1177#ifdef CASE_INSENSITIVE_FILENAME
1178 (char_u *)TRUE,
1179#else
1180 (char_u *)FALSE,
1181#endif
1182 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001183 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184#ifdef FEAT_AUTOCMD
1185 (char_u *)&p_ft, PV_FT,
1186 {(char_u *)"", (char_u *)0L}
1187#else
1188 (char_u *)NULL, PV_NONE,
1189 {(char_u *)0L, (char_u *)0L}
1190#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001192 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1194 (char_u *)&p_fcs, PV_NONE,
1195 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1196#else
1197 (char_u *)NULL, PV_NONE,
1198 {(char_u *)"", (char_u *)0L}
1199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001201 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1202 (char_u *)&p_fixeol, PV_FIXEOL,
1203 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1205#ifdef FEAT_FKMAP
1206 (char_u *)&p_fkmap, PV_NONE,
1207#else
1208 (char_u *)NULL, PV_NONE,
1209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"flash", "fl", P_BOOL|P_VI_DEF,
1212 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001214 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001215#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001217 {(char_u *)"", (char_u *)0L}
1218#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)NULL, PV_NONE,
1220 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221#endif
1222 SCRIPTID_INIT},
1223 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1224#ifdef FEAT_FOLDING
1225 (char_u *)VAR_WIN, PV_FDC,
1226 {(char_u *)FALSE, (char_u *)0L}
1227#else
1228 (char_u *)NULL, PV_NONE,
1229 {(char_u *)NULL, (char_u *)0L}
1230#endif
1231 SCRIPTID_INIT},
1232 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1233#ifdef FEAT_FOLDING
1234 (char_u *)VAR_WIN, PV_FEN,
1235 {(char_u *)TRUE, (char_u *)0L}
1236#else
1237 (char_u *)NULL, PV_NONE,
1238 {(char_u *)NULL, (char_u *)0L}
1239#endif
1240 SCRIPTID_INIT},
1241 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1242#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1243 (char_u *)VAR_WIN, PV_FDE,
1244 {(char_u *)"0", (char_u *)NULL}
1245#else
1246 (char_u *)NULL, PV_NONE,
1247 {(char_u *)NULL, (char_u *)0L}
1248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001251#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253 {(char_u *)"#", (char_u *)NULL}
1254#else
1255 (char_u *)NULL, PV_NONE,
1256 {(char_u *)NULL, (char_u *)0L}
1257#endif
1258 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001260#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001262 {(char_u *)0L, (char_u *)0L}
1263#else
1264 (char_u *)NULL, PV_NONE,
1265 {(char_u *)NULL, (char_u *)0L}
1266#endif
1267 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001268 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001269#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001271 {(char_u *)-1L, (char_u *)0L}
1272#else
1273 (char_u *)NULL, PV_NONE,
1274 {(char_u *)NULL, (char_u *)0L}
1275#endif
1276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001278 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001279#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001282#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283 (char_u *)NULL, PV_NONE,
1284 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001286 SCRIPTID_INIT},
1287 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1288#ifdef FEAT_FOLDING
1289 (char_u *)VAR_WIN, PV_FDM,
1290 {(char_u *)"manual", (char_u *)NULL}
1291#else
1292 (char_u *)NULL, PV_NONE,
1293 {(char_u *)NULL, (char_u *)0L}
1294#endif
1295 SCRIPTID_INIT},
1296 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1297#ifdef FEAT_FOLDING
1298 (char_u *)VAR_WIN, PV_FML,
1299 {(char_u *)1L, (char_u *)0L}
1300#else
1301 (char_u *)NULL, PV_NONE,
1302 {(char_u *)NULL, (char_u *)0L}
1303#endif
1304 SCRIPTID_INIT},
1305 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1306#ifdef FEAT_FOLDING
1307 (char_u *)VAR_WIN, PV_FDN,
1308 {(char_u *)20L, (char_u *)0L}
1309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
1313 SCRIPTID_INIT},
1314 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1315#ifdef FEAT_FOLDING
1316 (char_u *)&p_fdo, PV_NONE,
1317 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1318 (char_u *)0L}
1319#else
1320 (char_u *)NULL, PV_NONE,
1321 {(char_u *)NULL, (char_u *)0L}
1322#endif
1323 SCRIPTID_INIT},
1324 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1325#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1326 (char_u *)VAR_WIN, PV_FDT,
1327 {(char_u *)"foldtext()", (char_u *)NULL}
1328#else
1329 (char_u *)NULL, PV_NONE,
1330 {(char_u *)NULL, (char_u *)0L}
1331#endif
1332 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001333 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001334#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001335 (char_u *)&p_fex, PV_FEX,
1336 {(char_u *)"", (char_u *)0L}
1337#else
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)0L, (char_u *)0L}
1340#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001341 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1343 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1345 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001346 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1347 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1349 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001351 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001353 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1354#ifdef HAVE_FSYNC
1355 (char_u *)&p_fs, PV_NONE,
1356 {(char_u *)TRUE, (char_u *)0L}
1357#else
1358 (char_u *)NULL, PV_NONE,
1359 {(char_u *)FALSE, (char_u *)0L}
1360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001361 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1363 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"graphic", "gr", P_BOOL|P_VI_DEF,
1366 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001368 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369#ifdef FEAT_QUICKFIX
1370 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372#else
1373 (char_u *)NULL, PV_NONE,
1374 {(char_u *)NULL, (char_u *)0L}
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1378#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001379 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {
1381# ifdef WIN3264
1382 /* may be changed to "grep -n" in os_win32.c */
1383 (char_u *)"findstr /n",
1384# else
1385# ifdef UNIX
1386 /* Add an extra file name so that grep will always
1387 * insert a file name in the match line. */
1388 (char_u *)"grep -n $* /dev/null",
1389# else
1390# ifdef VMS
1391 (char_u *)"SEARCH/NUMBERS ",
1392# else
1393 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394# endif
1395# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001403 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404#ifdef CURSOR_SHAPE
1405 (char_u *)&p_guicursor, PV_NONE,
1406 {
1407# ifdef FEAT_GUI
1408 (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 +01001409# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1411# endif
1412 (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)NULL, (char_u *)0L}
1416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001418 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419#ifdef FEAT_GUI
1420 (char_u *)&p_guifont, PV_NONE,
1421 {(char_u *)"", (char_u *)0L}
1422#else
1423 (char_u *)NULL, PV_NONE,
1424 {(char_u *)NULL, (char_u *)0L}
1425#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001427 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1429 (char_u *)&p_guifontset, PV_NONE,
1430 {(char_u *)"", (char_u *)0L}
1431#else
1432 (char_u *)NULL, PV_NONE,
1433 {(char_u *)NULL, (char_u *)0L}
1434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001436 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1438 (char_u *)&p_guifontwide, PV_NONE,
1439 {(char_u *)"", (char_u *)0L}
1440#else
1441 (char_u *)NULL, PV_NONE,
1442 {(char_u *)NULL, (char_u *)0L}
1443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001446#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 (char_u *)&p_ghr, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001453#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454 (char_u *)&p_go, PV_NONE,
1455# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001456 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001458 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459# endif
1460#else
1461 (char_u *)NULL, PV_NONE,
1462 {(char_u *)NULL, (char_u *)0L}
1463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"guipty", NULL, P_BOOL|P_VI_DEF,
1466#if defined(FEAT_GUI)
1467 (char_u *)&p_guipty, PV_NONE,
1468#else
1469 (char_u *)NULL, PV_NONE,
1470#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001472 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001473#if defined(FEAT_GUI_TABLINE)
1474 (char_u *)&p_gtl, PV_NONE,
1475 {(char_u *)"", (char_u *)0L}
1476#else
1477 (char_u *)NULL, PV_NONE,
1478 {(char_u *)NULL, (char_u *)0L}
1479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001481 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001482#if defined(FEAT_GUI_TABLINE)
1483 (char_u *)&p_gtt, PV_NONE,
1484 {(char_u *)"", (char_u *)0L}
1485#else
1486 (char_u *)NULL, PV_NONE,
1487 {(char_u *)NULL, (char_u *)0L}
1488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001489 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1491 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1494 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001495 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"helpheight", "hh", P_NUM|P_VI_DEF,
1498#ifdef FEAT_WINDOWS
1499 (char_u *)&p_hh, PV_NONE,
1500#else
1501 (char_u *)NULL, PV_NONE,
1502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001503 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001504 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505#ifdef FEAT_MULTI_LANG
1506 (char_u *)&p_hlg, PV_NONE,
1507 {(char_u *)"", (char_u *)0L}
1508#else
1509 (char_u *)NULL, PV_NONE,
1510 {(char_u *)0L, (char_u *)0L}
1511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001512 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 {"hidden", "hid", P_BOOL|P_VI_DEF,
1514 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001516 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1519 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"history", "hi", P_NUM|P_VIM,
1521 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001522 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1524#ifdef FEAT_RIGHTLEFT
1525 (char_u *)&p_hkmap, PV_NONE,
1526#else
1527 (char_u *)NULL, PV_NONE,
1528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001529 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1531#ifdef FEAT_RIGHTLEFT
1532 (char_u *)&p_hkmapp, PV_NONE,
1533#else
1534 (char_u *)NULL, PV_NONE,
1535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1538 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"icon", NULL, P_BOOL|P_VI_DEF,
1541#ifdef FEAT_TITLE
1542 (char_u *)&p_icon, PV_NONE,
1543#else
1544 (char_u *)NULL, PV_NONE,
1545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 {"iconstring", NULL, P_STRING|P_VI_DEF,
1548#ifdef FEAT_TITLE
1549 (char_u *)&p_iconstring, PV_NONE,
1550#else
1551 (char_u *)NULL, PV_NONE,
1552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001553 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1555 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001557 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1558# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1559 (char_u *)&p_imaf, PV_NONE,
1560 {(char_u *)"", (char_u *)NULL}
1561# else
1562 (char_u *)NULL, PV_NONE,
1563 {(char_u *)NULL, (char_u *)0L}
1564# endif
1565 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001567#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568 (char_u *)&p_imak, PV_NONE,
1569#else
1570 (char_u *)NULL, PV_NONE,
1571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001572 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001573 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1574#ifdef USE_IM_CONTROL
1575 (char_u *)&p_imcmdline, PV_NONE,
1576#else
1577 (char_u *)NULL, PV_NONE,
1578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1581#ifdef USE_IM_CONTROL
1582 (char_u *)&p_imdisable, PV_NONE,
1583#else
1584 (char_u *)NULL, PV_NONE,
1585#endif
1586#ifdef __sgi
1587 {(char_u *)TRUE, (char_u *)0L}
1588#else
1589 {(char_u *)FALSE, (char_u *)0L}
1590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001592 {"iminsert", "imi", P_NUM|P_VI_DEF,
1593 (char_u *)&p_iminsert, PV_IMI,
1594#ifdef B_IMODE_IM
1595 {(char_u *)B_IMODE_IM, (char_u *)0L}
1596#else
1597 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001599 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 {"imsearch", "ims", P_NUM|P_VI_DEF,
1601 (char_u *)&p_imsearch, PV_IMS,
1602#ifdef B_IMODE_IM
1603 {(char_u *)B_IMODE_IM, (char_u *)0L}
1604#else
1605 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001607 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001608 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001609#if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001610 (char_u *)&p_imsf, PV_NONE,
1611 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001612#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001613 (char_u *)NULL, PV_NONE,
1614 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001615#endif
1616 SCRIPTID_INIT},
1617 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1618#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1619 (char_u *)&p_imst, PV_NONE,
1620 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1621#else
1622 (char_u *)NULL, PV_NONE,
1623 {(char_u *)0L, (char_u *)0L}
1624#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001625 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1627#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001628 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1630#else
1631 (char_u *)NULL, PV_NONE,
1632 {(char_u *)0L, (char_u *)0L}
1633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1636#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1637 (char_u *)&p_inex, PV_INEX,
1638 {(char_u *)"", (char_u *)0L}
1639#else
1640 (char_u *)NULL, PV_NONE,
1641 {(char_u *)0L, (char_u *)0L}
1642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1645 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1648#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1649 (char_u *)&p_inde, PV_INDE,
1650 {(char_u *)"", (char_u *)0L}
1651#else
1652 (char_u *)NULL, PV_NONE,
1653 {(char_u *)0L, (char_u *)0L}
1654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001656 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1658 (char_u *)&p_indk, PV_INDK,
1659 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1660#else
1661 (char_u *)NULL, PV_NONE,
1662 {(char_u *)0L, (char_u *)0L}
1663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"infercase", "inf", P_BOOL|P_VI_DEF,
1666 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1669 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001670 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1672 (char_u *)&p_isf, PV_NONE,
1673 {
1674#ifdef BACKSLASH_IN_FILENAME
1675 /* Excluded are: & and ^ are special in cmd.exe
1676 * ( and ) are used in text separating fnames */
1677 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1678#else
1679# ifdef AMIGA
1680 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1681# else
1682# ifdef VMS
1683 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1684# else /* UNIX et al. */
1685# ifdef EBCDIC
1686 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1687# else
1688 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1689# endif
1690# endif
1691# endif
1692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001693 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1695 (char_u *)&p_isi, PV_NONE,
1696 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001697#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698 (char_u *)"@,48-57,_,128-167,224-235",
1699#else
1700# ifdef EBCDIC
1701 /* TODO: EBCDIC Check this! @ == isalpha()*/
1702 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1703 "112-120,128,140-142,156,158,172,"
1704 "174,186,191,203-207,219-225,235-239,"
1705 "251-254",
1706# else
1707 (char_u *)"@,48-57,_,192-255",
1708# endif
1709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1712 (char_u *)&p_isk, PV_ISK,
1713 {
1714#ifdef EBCDIC
1715 (char_u *)"@,240-249,_",
1716 /* TODO: EBCDIC Check this! @ == isalpha()*/
1717 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1718 "112-120,128,140-142,156,158,172,"
1719 "174,186,191,203-207,219-225,235-239,"
1720 "251-254",
1721#else
1722 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001723# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724 (char_u *)"@,48-57,_,128-167,224-235"
1725# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001726 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727# endif
1728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001729 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1731 (char_u *)&p_isp, PV_NONE,
1732 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001733#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 || defined(VMS)
1735 (char_u *)"@,~-255",
1736#else
1737# ifdef EBCDIC
1738 /* all chars above 63 are printable */
1739 (char_u *)"63-255",
1740# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001741 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742# endif
1743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001744 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1746 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001747 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1749#ifdef FEAT_CRYPT
1750 (char_u *)&p_key, PV_KEY,
1751 {(char_u *)"", (char_u *)0L}
1752#else
1753 (char_u *)NULL, PV_NONE,
1754 {(char_u *)0L, (char_u *)0L}
1755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001757 {"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 +00001758#ifdef FEAT_KEYMAP
1759 (char_u *)&p_keymap, PV_KMAP,
1760 {(char_u *)"", (char_u *)0L}
1761#else
1762 (char_u *)NULL, PV_NONE,
1763 {(char_u *)"", (char_u *)0L}
1764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001765 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001766 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001770 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001772#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 (char_u *)":help",
1774#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001775# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001777# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001778# ifdef USEMAN_S
1779 (char_u *)"man -s",
1780# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001782# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783# endif
1784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001786 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787#ifdef FEAT_LANGMAP
1788 (char_u *)&p_langmap, PV_NONE,
1789 {(char_u *)"", /* unmatched } */
1790#else
1791 (char_u *)NULL, PV_NONE,
1792 {(char_u *)NULL,
1793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001795 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1797 (char_u *)&p_lm, PV_NONE,
1798#else
1799 (char_u *)NULL, PV_NONE,
1800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001801 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001802 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1803#ifdef FEAT_LANGMAP
1804 (char_u *)&p_lnr, PV_NONE,
1805#else
1806 (char_u *)NULL, PV_NONE,
1807#endif
1808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001809 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1810#ifdef FEAT_LANGMAP
1811 (char_u *)&p_lrm, PV_NONE,
1812#else
1813 (char_u *)NULL, PV_NONE,
1814#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001815 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1817#ifdef FEAT_WINDOWS
1818 (char_u *)&p_ls, PV_NONE,
1819#else
1820 (char_u *)NULL, PV_NONE,
1821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1824 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1827#ifdef FEAT_LINEBREAK
1828 (char_u *)VAR_WIN, PV_LBR,
1829#else
1830 (char_u *)NULL, PV_NONE,
1831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1834 (char_u *)&Rows, PV_NONE,
1835 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001836#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001837 (char_u *)25L,
1838#else
1839 (char_u *)24L,
1840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1843#ifdef FEAT_GUI
1844 (char_u *)&p_linespace, PV_NONE,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
1848#ifdef FEAT_GUI_W32
1849 {(char_u *)1L, (char_u *)0L}
1850#else
1851 {(char_u *)0L, (char_u *)0L}
1852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001853 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001854 {"lisp", NULL, P_BOOL|P_VI_DEF,
1855#ifdef FEAT_LISP
1856 (char_u *)&p_lisp, PV_LISP,
1857#else
1858 (char_u *)NULL, PV_NONE,
1859#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001861 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001863 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1865#else
1866 (char_u *)NULL, PV_NONE,
1867 {(char_u *)"", (char_u *)0L}
1868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1871 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001873 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1877 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001878 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001879 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001880#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001881 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001882 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001883#else
1884 (char_u *)NULL, PV_NONE,
1885 {(char_u *)"", (char_u *)0L}
1886#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001887 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001888 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001889#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001890 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001891 {(char_u *)TRUE, (char_u *)0L}
1892#else
1893 (char_u *)NULL, PV_NONE,
1894 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001895#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001896 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"magic", NULL, P_BOOL|P_VI_DEF,
1898 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001900 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901#ifdef FEAT_QUICKFIX
1902 (char_u *)&p_mef, PV_NONE,
1903 {(char_u *)"", (char_u *)0L}
1904#else
1905 (char_u *)NULL, PV_NONE,
1906 {(char_u *)NULL, (char_u *)0L}
1907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001909 {"makeencoding","menc", P_STRING|P_VI_DEF,
1910#ifdef FEAT_MBYTE
1911 (char_u *)&p_menc, PV_MENC,
1912 {(char_u *)"", (char_u *)0L}
1913#else
1914 (char_u *)NULL, PV_NONE,
1915 {(char_u *)0L, (char_u *)0L}
1916#endif
1917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1919#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001920 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921# ifdef VMS
1922 {(char_u *)"MMS", (char_u *)0L}
1923# else
1924 {(char_u *)"make", (char_u *)0L}
1925# endif
1926#else
1927 (char_u *)NULL, PV_NONE,
1928 {(char_u *)NULL, (char_u *)0L}
1929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001931 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001933 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1934 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"matchtime", "mat", P_NUM|P_VI_DEF,
1936 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001938 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001939#ifdef FEAT_MBYTE
1940 (char_u *)&p_mco, PV_NONE,
1941#else
1942 (char_u *)NULL, PV_NONE,
1943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1946#ifdef FEAT_EVAL
1947 (char_u *)&p_mfd, PV_NONE,
1948#else
1949 (char_u *)NULL, PV_NONE,
1950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1953 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955 {"maxmem", "mm", P_NUM|P_VI_DEF,
1956 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001957 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1958 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001959 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1960 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1963 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1965 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 {"menuitems", "mis", P_NUM|P_VI_DEF,
1967#ifdef FEAT_MENU
1968 (char_u *)&p_mis, PV_NONE,
1969#else
1970 (char_u *)NULL, PV_NONE,
1971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"mesg", NULL, P_BOOL|P_VI_DEF,
1974 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001976 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001977#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001978 (char_u *)&p_msm, PV_NONE,
1979 {(char_u *)"460000,2000,500", (char_u *)0L}
1980#else
1981 (char_u *)NULL, PV_NONE,
1982 {(char_u *)0L, (char_u *)0L}
1983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"modeline", "ml", P_BOOL|P_VIM,
1986 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"modelines", "mls", P_NUM|P_VI_DEF,
1989 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1992 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1995 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {"more", NULL, P_BOOL|P_VIM,
1998 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001999 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002000 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
2001 (char_u *)&p_mouse, PV_NONE,
2002 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002003#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 (char_u *)"a",
2005#else
2006 (char_u *)"",
2007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002008 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
2010#ifdef FEAT_GUI
2011 (char_u *)&p_mousef, PV_NONE,
2012#else
2013 (char_u *)NULL, PV_NONE,
2014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2017#ifdef FEAT_GUI
2018 (char_u *)&p_mh, PV_NONE,
2019#else
2020 (char_u *)NULL, PV_NONE,
2021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2024 (char_u *)&p_mousem, PV_NONE,
2025 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002026#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 (char_u *)"popup",
2028#else
2029# if defined(MACOS)
2030 (char_u *)"popup_setpos",
2031# else
2032 (char_u *)"extend",
2033# endif
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002036 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037#ifdef FEAT_MOUSESHAPE
2038 (char_u *)&p_mouseshape, PV_NONE,
2039 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2040#else
2041 (char_u *)NULL, PV_NONE,
2042 {(char_u *)NULL, (char_u *)0L}
2043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2046 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002047 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002048 {"mzquantum", "mzq", P_NUM,
2049#ifdef FEAT_MZSCHEME
2050 (char_u *)&p_mzq, PV_NONE,
2051#else
2052 (char_u *)NULL, PV_NONE,
2053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 {"novice", NULL, P_BOOL|P_VI_DEF,
2056 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002057 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002058 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002060 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2063 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002065 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2066#ifdef FEAT_LINEBREAK
2067 (char_u *)VAR_WIN, PV_NUW,
2068#else
2069 (char_u *)NULL, PV_NONE,
2070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002071 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002072 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002073#ifdef FEAT_COMPL_FUNC
2074 (char_u *)&p_ofu, PV_OFU,
2075 {(char_u *)"", (char_u *)0L}
2076#else
2077 (char_u *)NULL, PV_NONE,
2078 {(char_u *)0L, (char_u *)0L}
2079#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 {"open", NULL, P_BOOL|P_VI_DEF,
2082 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002084 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002085#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002086 (char_u *)&p_odev, PV_NONE,
2087#else
2088 (char_u *)NULL, PV_NONE,
2089#endif
2090 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002092 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2093 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002094 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"optimize", "opt", P_BOOL|P_VI_DEF,
2096 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002100 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002101 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2102 |P_SECURE,
2103 (char_u *)&p_pp, PV_NONE,
2104 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2105 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 {"paragraphs", "para", P_STRING|P_VI_DEF,
2107 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002108 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002109 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002110 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2114 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002115 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2117#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2118 (char_u *)&p_pex, PV_NONE,
2119 {(char_u *)"", (char_u *)0L}
2120#else
2121 (char_u *)NULL, PV_NONE,
2122 {(char_u *)0L, (char_u *)0L}
2123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002125 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002127 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002129 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002131#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 (char_u *)".,,",
2133#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002136 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002137 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002138#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002139 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002140 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002141#else
2142 (char_u *)NULL, PV_NONE,
2143 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002144#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002145 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2147 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002149 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2151 (char_u *)&p_pvh, PV_NONE,
2152#else
2153 (char_u *)NULL, PV_NONE,
2154#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002155 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2157#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2158 (char_u *)VAR_WIN, PV_PVW,
2159#else
2160 (char_u *)NULL, PV_NONE,
2161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002162 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002163 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002164#ifdef FEAT_PRINTER
2165 (char_u *)&p_pdev, PV_NONE,
2166 {(char_u *)"", (char_u *)0L}
2167#else
2168 (char_u *)NULL, PV_NONE,
2169 {(char_u *)NULL, (char_u *)0L}
2170#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002171 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 {"printencoding", "penc", P_STRING|P_VI_DEF,
2173#ifdef FEAT_POSTSCRIPT
2174 (char_u *)&p_penc, PV_NONE,
2175 {(char_u *)"", (char_u *)0L}
2176#else
2177 (char_u *)NULL, PV_NONE,
2178 {(char_u *)NULL, (char_u *)0L}
2179#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002180 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002181 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182#ifdef FEAT_POSTSCRIPT
2183 (char_u *)&p_pexpr, PV_NONE,
2184 {(char_u *)"", (char_u *)0L}
2185#else
2186 (char_u *)NULL, PV_NONE,
2187 {(char_u *)NULL, (char_u *)0L}
2188#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002189 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 {"printfont", "pfn", P_STRING|P_VI_DEF,
2191#ifdef FEAT_PRINTER
2192 (char_u *)&p_pfn, PV_NONE,
2193 {
2194# ifdef MSWIN
2195 (char_u *)"Courier_New:h10",
2196# else
2197 (char_u *)"courier",
2198# endif
2199 (char_u *)0L}
2200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2206#ifdef FEAT_PRINTER
2207 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002208 /* untranslated to avoid problems when 'encoding'
2209 * is changed */
2210 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211#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,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002788 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002789#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 Moolenaar9e13aa72017-08-16 23:14:08 +02003112 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003113#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003114 (char_u *)&p_winptydll, PV_NONE, {
3115# ifdef _WIN64
3116 (char_u *)"winpty64.dll",
3117# else
3118 (char_u *)"winpty32.dll",
3119# endif
3120 (char_u *)0L}
3121#else
3122 (char_u *)NULL, PV_NONE,
3123 {(char_u *)0L, (char_u *)0L}
3124#endif
3125 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003127#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 (char_u *)&p_wiw, PV_NONE,
3129#else
3130 (char_u *)NULL, PV_NONE,
3131#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003132 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3134 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003135 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3137 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003138 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3140 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003141 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 {"write", NULL, P_BOOL|P_VI_DEF,
3143 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003144 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 {"writeany", "wa", P_BOOL|P_VI_DEF,
3146 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003147 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3149 (char_u *)&p_wb, PV_NONE,
3150 {
3151#ifdef FEAT_WRITEBACKUP
3152 (char_u *)TRUE,
3153#else
3154 (char_u *)FALSE,
3155#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003156 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 {"writedelay", "wd", P_NUM|P_VI_DEF,
3158 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003159 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160
3161/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003162#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003164 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165
3166 p_term("t_AB", T_CAB)
3167 p_term("t_AF", T_CAF)
3168 p_term("t_AL", T_CAL)
3169 p_term("t_al", T_AL)
3170 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003171 p_term("t_BE", T_BE)
3172 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 p_term("t_cd", T_CD)
3174 p_term("t_ce", T_CE)
3175 p_term("t_cl", T_CL)
3176 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003177 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178 p_term("t_Co", T_CCO)
3179 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003180 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003182#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 p_term("t_CV", T_CSV)
3184#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_da", T_DA)
3186 p_term("t_db", T_DB)
3187 p_term("t_DL", T_CDL)
3188 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003189 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003190 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003192 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 p_term("t_IE", T_CIE)
3194 p_term("t_IS", T_CIS)
3195 p_term("t_ke", T_KE)
3196 p_term("t_ks", T_KS)
3197 p_term("t_le", T_LE)
3198 p_term("t_mb", T_MB)
3199 p_term("t_md", T_MD)
3200 p_term("t_me", T_ME)
3201 p_term("t_mr", T_MR)
3202 p_term("t_ms", T_MS)
3203 p_term("t_nd", T_ND)
3204 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003205 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003206 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003208 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209 p_term("t_RV", T_CRV)
3210 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003211 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003213 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003214 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003215 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003217 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 p_term("t_te", T_TE)
3220 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003221 p_term("t_ts", T_TS)
3222 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 p_term("t_ue", T_UE)
3224 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003225 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 p_term("t_vb", T_VB)
3227 p_term("t_ve", T_VE)
3228 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003229 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230 p_term("t_vs", T_VS)
3231 p_term("t_WP", T_CWP)
3232 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003233 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234 p_term("t_xs", T_XS)
3235 p_term("t_ZH", T_CZH)
3236 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003237 p_term("t_8f", T_8F)
3238 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239
3240/* terminal key codes are not in here */
3241
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003242 /* end marker */
3243 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244};
3245
3246#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3247
3248#ifdef FEAT_MBYTE
3249static char *(p_ambw_values[]) = {"single", "double", NULL};
3250#endif
3251static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003252static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003254#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003255static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003256#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003257#ifdef FEAT_CMDL_COMPL
3258static char *(p_wop_values[]) = {"tagfile", NULL};
3259#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260#ifdef FEAT_WAK
3261static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3262#endif
3263static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3265static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267#ifdef FEAT_BROWSE
3268static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3269#endif
3270#ifdef FEAT_SCROLLBIND
3271static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3272#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003273static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003274#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3276#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003277#ifdef FEAT_AUTOCMD
3278static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3279#else
3280static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003282static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3284#ifdef FEAT_FOLDING
3285static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003286# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003288# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289 NULL};
3290static char *(p_fcl_values[]) = {"all", NULL};
3291#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003292#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003293static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003294#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003295#ifdef FEAT_SIGNS
3296static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3297#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static void set_option_default(int, int opt_flags, int compatible);
3300static void set_options_default(int opt_flags);
3301static char_u *term_bg_default(void);
3302static void did_set_option(int opt_idx, int opt_flags, int new_value);
3303static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003304#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306#endif
3307#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003308static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003310static char_u *option_expand(int opt_idx, char_u *val);
3311static void didset_options(void);
3312static void didset_options2(void);
3313static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003314#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003315static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003316#else
3317# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3318#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003319static void set_string_option_global(int opt_idx, char_u **varp);
3320static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3321static 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);
3322static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003323#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003324static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003327static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003329#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003330static char_u *did_set_spell_option(int is_spellfile);
3331static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003332#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003333#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003334static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003335#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003336static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3337static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3338static void check_redraw(long_u flags);
3339static int findoption(char_u *);
3340static int find_key_option(char_u *);
3341static void showoptions(int all, int opt_flags);
3342static int optval_default(struct vimoption *, char_u *varp);
3343static void showoneopt(struct vimoption *, int opt_flags);
3344static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3345static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3346static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3347static int istermoption(struct vimoption *);
3348static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3349static char_u *get_varp(struct vimoption *);
3350static void option_value2string(struct vimoption *, int opt_flags);
3351static void check_winopt(winopt_T *wop);
3352static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003354static void langmap_init(void);
3355static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003356#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003357static void paste_option_changed(void);
3358static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003360static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003362static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3363static int check_opt_strings(char_u *val, char **values, int);
3364static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003365#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003366static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003367#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368
3369/*
3370 * Initialize the options, first part.
3371 *
3372 * Called only once from main(), just after creating the first buffer.
3373 */
3374 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003375set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376{
3377 char_u *p;
3378 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003379 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380
3381#ifdef FEAT_LANGMAP
3382 langmap_init();
3383#endif
3384
3385 /* Be Vi compatible by default */
3386 p_cp = TRUE;
3387
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003388 /* Use POSIX compatibility when $VIM_POSIX is set. */
3389 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003390 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003391 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003392 set_string_default("shm", (char_u *)"A");
3393 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003394
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 /*
3396 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003397 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003399 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003400#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003401 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003403 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404# endif
3405#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003406 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407 set_string_default("sh", p);
3408
3409#ifdef FEAT_WILDIGN
3410 /*
3411 * Set the default for 'backupskip' to include environment variables for
3412 * temp files.
3413 */
3414 {
3415# ifdef UNIX
3416 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3417# else
3418 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3419# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003420 int len;
3421 garray_T ga;
3422 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003423
3424 ga_init2(&ga, 1, 100);
3425 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3426 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003427 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428# ifdef UNIX
3429 if (*names[n] == NUL)
3430 p = (char_u *)"/tmp";
3431 else
3432# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003433 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434 if (p != NULL && *p != NUL)
3435 {
3436 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003437 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438 if (ga_grow(&ga, len) == OK)
3439 {
3440 if (ga.ga_len > 0)
3441 STRCAT(ga.ga_data, ",");
3442 STRCAT(ga.ga_data, p);
3443 add_pathsep(ga.ga_data);
3444 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445 ga.ga_len += len;
3446 }
3447 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003448 if (mustfree)
3449 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450 }
3451 if (ga.ga_data != NULL)
3452 {
3453 set_string_default("bsk", ga.ga_data);
3454 vim_free(ga.ga_data);
3455 }
3456 }
3457#endif
3458
3459 /*
3460 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3461 */
3462 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003463 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003465#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3466 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3467#endif
3468 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003470 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003471 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472#else
3473# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003474 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003475 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003477 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478# endif
3479#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003481 opt_idx = findoption((char_u *)"maxmem");
3482 if (opt_idx >= 0)
3483 {
3484#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003485 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3486 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003487#endif
3488 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3489 }
3490 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 }
3492
Bram Moolenaar071d4272004-06-13 20:20:40 +00003493#ifdef FEAT_SEARCHPATH
3494 {
3495 char_u *cdpath;
3496 char_u *buf;
3497 int i;
3498 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003499 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003500
3501 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003502 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003503 if (cdpath != NULL)
3504 {
3505 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3506 if (buf != NULL)
3507 {
3508 buf[0] = ','; /* start with ",", current dir first */
3509 j = 1;
3510 for (i = 0; cdpath[i] != NUL; ++i)
3511 {
3512 if (vim_ispathlistsep(cdpath[i]))
3513 buf[j++] = ',';
3514 else
3515 {
3516 if (cdpath[i] == ' ' || cdpath[i] == ',')
3517 buf[j++] = '\\';
3518 buf[j++] = cdpath[i];
3519 }
3520 }
3521 buf[j] = NUL;
3522 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003523 if (opt_idx >= 0)
3524 {
3525 options[opt_idx].def_val[VI_DEFAULT] = buf;
3526 options[opt_idx].flags |= P_DEF_ALLOCED;
3527 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003528 else
3529 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003530 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003531 if (mustfree)
3532 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533 }
3534 }
3535#endif
3536
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003537#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003538 /* Set print encoding on platforms that don't default to latin1 */
3539 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003540# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003541 (char_u *)"cp1252"
3542# else
3543# ifdef VMS
3544 (char_u *)"dec-mcs"
3545# else
3546# ifdef EBCDIC
3547 (char_u *)"ebcdic-uk"
3548# else
3549# ifdef MAC
3550 (char_u *)"mac-roman"
3551# else /* HPUX */
3552 (char_u *)"hp-roman8"
3553# endif
3554# endif
3555# endif
3556# endif
3557 );
3558#endif
3559
3560#ifdef FEAT_POSTSCRIPT
3561 /* 'printexpr' must be allocated to be able to evaluate it. */
3562 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003563# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003564 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565# else
3566# ifdef VMS
3567 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3568
3569# else
3570 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3571# endif
3572# endif
3573 );
3574#endif
3575
3576 /*
3577 * Set all the options (except the terminal options) to their default
3578 * value. Also set the global value for local options.
3579 */
3580 set_options_default(0);
3581
3582#ifdef FEAT_GUI
3583 if (found_reverse_arg)
3584 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3585#endif
3586
3587 curbuf->b_p_initialized = TRUE;
3588 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003589 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003590 check_buf_options(curbuf);
3591 check_win_options(curwin);
3592 check_options();
3593
3594 /* Must be before option_expand(), because that one needs vim_isIDc() */
3595 didset_options();
3596
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003597#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003598 /* Use the current chartab for the generic chartab. This is not in
3599 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003600 init_spell_chartab();
3601#endif
3602
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603 /*
3604 * Expand environment variables and things like "~" for the defaults.
3605 * If option_expand() returns non-NULL the variable is expanded. This can
3606 * only happen for non-indirect options.
3607 * Also set the default to the expanded value, so ":set" does not list
3608 * them.
3609 * Don't set the P_ALLOCED flag, because we don't want to free the
3610 * default.
3611 */
3612 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3613 {
3614 if ((options[opt_idx].flags & P_GETTEXT)
3615 && options[opt_idx].var != NULL)
3616 p = (char_u *)_(*(char **)options[opt_idx].var);
3617 else
3618 p = option_expand(opt_idx, NULL);
3619 if (p != NULL && (p = vim_strsave(p)) != NULL)
3620 {
3621 *(char_u **)options[opt_idx].var = p;
3622 /* VIMEXP
3623 * Defaults for all expanded options are currently the same for Vi
3624 * and Vim. When this changes, add some code here! Also need to
3625 * split P_DEF_ALLOCED in two.
3626 */
3627 if (options[opt_idx].flags & P_DEF_ALLOCED)
3628 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3629 options[opt_idx].def_val[VI_DEFAULT] = p;
3630 options[opt_idx].flags |= P_DEF_ALLOCED;
3631 }
3632 }
3633
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634 save_file_ff(curbuf); /* Buffer is unchanged */
3635
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636#if defined(FEAT_ARABIC)
3637 /* Detect use of mlterm.
3638 * Mlterm is a terminal emulator akin to xterm that has some special
3639 * abilities (bidi namely).
3640 * NOTE: mlterm's author is being asked to 'set' a variable
3641 * instead of an environment variable due to inheritance.
3642 */
3643 if (mch_getenv((char_u *)"MLTERM") != NULL)
3644 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3645#endif
3646
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003647 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003648
3649#ifdef FEAT_MBYTE
3650# if defined(WIN3264) && defined(FEAT_GETTEXT)
3651 /*
3652 * If $LANG isn't set, try to get a good value for it. This makes the
3653 * right language be used automatically. Don't do this for English.
3654 */
3655 if (mch_getenv((char_u *)"LANG") == NULL)
3656 {
3657 char buf[20];
3658
3659 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3660 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3661 * only the first two. */
3662 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3663 (LPTSTR)buf, 20);
3664 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3665 {
3666 /* There are a few exceptions (probably more) */
3667 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3668 STRCPY(buf, "zh_TW");
3669 else if (STRNICMP(buf, "chs", 3) == 0
3670 || STRNICMP(buf, "zhc", 3) == 0)
3671 STRCPY(buf, "zh_CN");
3672 else if (STRNICMP(buf, "jp", 2) == 0)
3673 STRCPY(buf, "ja");
3674 else
3675 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003676 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677 }
3678 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003679# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003680# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003681 /* Moved to os_mac_conv.c to avoid dependency problems. */
3682 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003683# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003684# endif
3685
3686 /* enc_locale() will try to find the encoding of the current locale. */
3687 p = enc_locale();
3688 if (p != NULL)
3689 {
3690 char_u *save_enc;
3691
3692 /* Try setting 'encoding' and check if the value is valid.
3693 * If not, go back to the default "latin1". */
3694 save_enc = p_enc;
3695 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003696 if (STRCMP(p_enc, "gb18030") == 0)
3697 {
3698 /* We don't support "gb18030", but "cp936" is a good substitute
3699 * for practical purposes, thus use that. It's not an alias to
3700 * still support conversion between gb18030 and utf-8. */
3701 p_enc = vim_strsave((char_u *)"cp936");
3702 vim_free(p);
3703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003704 if (mb_init() == NULL)
3705 {
3706 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003707 if (opt_idx >= 0)
3708 {
3709 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3710 options[opt_idx].flags |= P_DEF_ALLOCED;
3711 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003712
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003713#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003714 if (STRCMP(p_enc, "latin1") == 0
3715# ifdef FEAT_MBYTE
3716 || enc_utf8
3717# endif
3718 )
3719 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003720 /* Adjust the default for 'isprint' and 'iskeyword' to match
3721 * latin1. Also set the defaults for when 'nocompatible' is
3722 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003723 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003724 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003725 set_string_option_direct((char_u *)"isk", -1,
3726 ISK_LATIN1, OPT_FREE, SID_NONE);
3727 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003728 if (opt_idx >= 0)
3729 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003730 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003731 if (opt_idx >= 0)
3732 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003733 (void)init_chartab();
3734 }
3735#endif
3736
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737# if defined(WIN3264) && !defined(FEAT_GUI)
3738 /* Win32 console: When GetACP() returns a different value from
3739 * GetConsoleCP() set 'termencoding'. */
3740 if (GetACP() != GetConsoleCP())
3741 {
3742 char buf[50];
3743
3744 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3745 p_tenc = vim_strsave((char_u *)buf);
3746 if (p_tenc != NULL)
3747 {
3748 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003749 if (opt_idx >= 0)
3750 {
3751 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3752 options[opt_idx].flags |= P_DEF_ALLOCED;
3753 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003754 convert_setup(&input_conv, p_tenc, p_enc);
3755 convert_setup(&output_conv, p_enc, p_tenc);
3756 }
3757 else
3758 p_tenc = empty_option;
3759 }
3760# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003761# if defined(WIN3264) && defined(FEAT_MBYTE)
3762 /* $HOME may have characters in active code page. */
3763 init_homedir();
3764# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003765 }
3766 else
3767 {
3768 vim_free(p_enc);
3769 p_enc = save_enc;
3770 }
3771 }
3772#endif
3773
3774#ifdef FEAT_MULTI_LANG
3775 /* Set the default for 'helplang'. */
3776 set_helplang_default(get_mess_lang());
3777#endif
3778}
3779
3780/*
3781 * Set an option to its default value.
3782 * This does not take care of side effects!
3783 */
3784 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003785set_option_default(
3786 int opt_idx,
3787 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3788 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789{
3790 char_u *varp; /* pointer to variable for current option */
3791 int dvi; /* index in def_val[] */
3792 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003793 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3795
3796 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3797 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003798 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799 {
3800 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3801 if (flags & P_STRING)
3802 {
3803 /* Use set_string_option_direct() for local options to handle
3804 * freeing and allocating the value. */
3805 if (options[opt_idx].indir != PV_NONE)
3806 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003807 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 else
3809 {
3810 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3811 free_string_option(*(char_u **)(varp));
3812 *(char_u **)varp = options[opt_idx].def_val[dvi];
3813 options[opt_idx].flags &= ~P_ALLOCED;
3814 }
3815 }
3816 else if (flags & P_NUM)
3817 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003818 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003819 win_comp_scroll(curwin);
3820 else
3821 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003822 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823 /* May also set global value for local option. */
3824 if (both)
3825 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3826 *(long *)varp;
3827 }
3828 }
3829 else /* P_BOOL */
3830 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003831 /* the cast to long is required for Manx C, long_i is needed for
3832 * MSVC */
3833 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003834#ifdef UNIX
3835 /* 'modeline' defaults to off for root */
3836 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3837 *(int *)varp = FALSE;
3838#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839 /* May also set global value for local option. */
3840 if (both)
3841 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3842 *(int *)varp;
3843 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003844
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003845 /* The default value is not insecure. */
3846 flagsp = insecure_flag(opt_idx, opt_flags);
3847 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 }
3849
3850#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003851 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852#endif
3853}
3854
3855/*
3856 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003857 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 */
3859 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003860set_options_default(
3861 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862{
3863 int i;
3864#ifdef FEAT_WINDOWS
3865 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003866 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867#endif
3868
3869 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003870 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003871#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003872 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003873 || (TRUE
3874# if defined(FEAT_MBYTE)
3875 && options[i].var != (char_u *)&p_enc
3876# endif
3877# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003878 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003879 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003880# endif
3881 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003882#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003883 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 set_option_default(i, opt_flags, p_cp);
3885
3886#ifdef FEAT_WINDOWS
3887 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003888 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889 win_comp_scroll(wp);
3890#else
3891 win_comp_scroll(curwin);
3892#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003893#ifdef FEAT_CINDENT
3894 parse_cino(curbuf);
3895#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896}
3897
3898/*
3899 * Set the Vi-default value of a string option.
3900 * Used for 'sh', 'backupskip' and 'term'.
3901 */
3902 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003903set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904{
3905 char_u *p;
3906 int opt_idx;
3907
3908 p = vim_strsave(val);
3909 if (p != NULL) /* we don't want a NULL */
3910 {
3911 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003912 if (opt_idx >= 0)
3913 {
3914 if (options[opt_idx].flags & P_DEF_ALLOCED)
3915 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3916 options[opt_idx].def_val[VI_DEFAULT] = p;
3917 options[opt_idx].flags |= P_DEF_ALLOCED;
3918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 }
3920}
3921
3922/*
3923 * Set the Vi-default value of a number option.
3924 * Used for 'lines' and 'columns'.
3925 */
3926 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003927set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003929 int opt_idx;
3930
3931 opt_idx = findoption((char_u *)name);
3932 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003933 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934}
3935
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003936#if defined(EXITFREE) || defined(PROTO)
3937/*
3938 * Free all options.
3939 */
3940 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003941free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003942{
3943 int i;
3944
3945 for (i = 0; !istermoption(&options[i]); i++)
3946 {
3947 if (options[i].indir == PV_NONE)
3948 {
3949 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003950 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003951 free_string_option(*(char_u **)options[i].var);
3952 if (options[i].flags & P_DEF_ALLOCED)
3953 free_string_option(options[i].def_val[VI_DEFAULT]);
3954 }
3955 else if (options[i].var != VAR_WIN
3956 && (options[i].flags & P_STRING))
3957 /* buffer-local option: free global value */
3958 free_string_option(*(char_u **)options[i].var);
3959 }
3960}
3961#endif
3962
3963
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964/*
3965 * Initialize the options, part two: After getting Rows and Columns and
3966 * setting 'term'.
3967 */
3968 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003969set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003971 int idx;
3972
Bram Moolenaar071d4272004-06-13 20:20:40 +00003973 /*
3974 * 'scroll' defaults to half the window height. Note that this default is
3975 * wrong when the window height changes.
3976 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003977 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003978 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003979 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003980 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 comp_col();
3982
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003983 /*
3984 * 'window' is only for backwards compatibility with Vi.
3985 * Default is Rows - 1.
3986 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003987 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003988 p_window = Rows - 1;
3989 set_number_default("window", Rows - 1);
3990
Bram Moolenaarf740b292006-02-16 22:11:02 +00003991 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003992#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003993 /*
3994 * If 'background' wasn't set by the user, try guessing the value,
3995 * depending on the terminal name. Only need to check for terminals
3996 * with a dark background, that can handle color.
3997 */
3998 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003999 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
4000 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00004001 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004002 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004003 /* don't mark it as set, when starting the GUI it may be
4004 * changed again */
4005 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004006 }
4007#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004008
4009#ifdef CURSOR_SHAPE
4010 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4011#endif
4012#ifdef FEAT_MOUSESHAPE
4013 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4014#endif
4015#ifdef FEAT_PRINTER
4016 (void)parse_printoptions(); /* parse 'printoptions' default value */
4017#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018}
4019
4020/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004021 * Return "dark" or "light" depending on the kind of terminal.
4022 * This is just guessing! Recognized are:
4023 * "linux" Linux console
4024 * "screen.linux" Linux console with screen
4025 * "cygwin" Cygwin shell
4026 * "putty" Putty program
4027 * We also check the COLORFGBG environment variable, which is set by
4028 * rxvt and derivatives. This variable contains either two or three
4029 * values separated by semicolons; we want the last value in either
4030 * case. If this value is 0-6 or 8, our background is dark.
4031 */
4032 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004033term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004034{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004035#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004036 /* DOS console nearly always black */
4037 return (char_u *)"dark";
4038#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004039 char_u *p;
4040
Bram Moolenaarf740b292006-02-16 22:11:02 +00004041 if (STRCMP(T_NAME, "linux") == 0
4042 || STRCMP(T_NAME, "screen.linux") == 0
4043 || STRCMP(T_NAME, "cygwin") == 0
4044 || STRCMP(T_NAME, "putty") == 0
4045 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4046 && (p = vim_strrchr(p, ';')) != NULL
4047 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4048 && p[2] == NUL))
4049 return (char_u *)"dark";
4050 return (char_u *)"light";
4051#endif
4052}
4053
4054/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 * Initialize the options, part three: After reading the .vimrc
4056 */
4057 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004058set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004060#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061/*
4062 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4063 * This is done after other initializations, where 'shell' might have been
4064 * set, but only if they have not been set before.
4065 */
4066 char_u *p;
4067 int idx_srr;
4068 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 int idx_sp;
4071 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004072# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073
4074 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004075 if (idx_srr < 0)
4076 do_srr = FALSE;
4077 else
4078 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004081 if (idx_sp < 0)
4082 do_sp = FALSE;
4083 else
4084 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004085# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004086 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 if (p != NULL)
4088 {
4089 /*
4090 * Default for p_sp is "| tee", for p_srr is ">".
4091 * For known shells it is changed here to include stderr.
4092 */
4093 if ( fnamecmp(p, "csh") == 0
4094 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004095# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 || fnamecmp(p, "csh.exe") == 0
4097 || fnamecmp(p, "tcsh.exe") == 0
4098# endif
4099 )
4100 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004101# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 if (do_sp)
4103 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004104# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004106# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004108# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4110 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004111# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 if (do_srr)
4113 {
4114 p_srr = (char_u *)">&";
4115 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4116 }
4117 }
4118 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004119 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 if ( fnamecmp(p, "sh") == 0
4121 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004122 || fnamecmp(p, "mksh") == 0
4123 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004125 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004127 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004128# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 || fnamecmp(p, "cmd") == 0
4130 || fnamecmp(p, "sh.exe") == 0
4131 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004132 || fnamecmp(p, "mksh.exe") == 0
4133 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004135 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 || fnamecmp(p, "bash.exe") == 0
4137 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004139 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004141# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 if (do_sp)
4143 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004144# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004146# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004148# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4150 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004151# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004152 if (do_srr)
4153 {
4154 p_srr = (char_u *)">%s 2>&1";
4155 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4156 }
4157 }
4158 vim_free(p);
4159 }
4160#endif
4161
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004162#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004164 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4165 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166 * This is done after other initializations, where 'shell' might have been
4167 * set, but only if they have not been set before. Default for p_shcf is
4168 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004169 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004170 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004171 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 {
4173 int idx3;
4174
4175 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004176 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 {
4178 p_shcf = (char_u *)"-c";
4179 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4180 }
4181
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182 /* Somehow Win32 requires the quotes around the redirection too */
4183 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004184 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004185 {
4186 p_sxq = (char_u *)"\"";
4187 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4188 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004189 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004190 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4191 {
4192 int idx3;
4193
4194 /*
4195 * cmd.exe on Windows will strip the first and last double quote given
4196 * on the command line, e.g. most of the time things like:
4197 * cmd /c "my path/to/echo" "my args to echo"
4198 * become:
4199 * my path/to/echo" "my args to echo
4200 * when executed.
4201 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004202 * To avoid this, set shellxquote to surround the command in
4203 * parenthesis. This appears to make most commands work, without
4204 * breaking commands that worked previously, such as
4205 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004206 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004207 idx3 = findoption((char_u *)"sxq");
4208 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4209 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004210 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004211 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4212 }
4213
Bram Moolenaara64ba222012-02-12 23:23:31 +01004214 idx3 = findoption((char_u *)"shcf");
4215 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4216 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004217 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004218 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4219 }
4220 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221#endif
4222
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004223 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004224 {
4225 int idx_ffs = findoption((char_u *)"ffs");
4226
4227 /* Apply the first entry of 'fileformats' to the initial buffer. */
4228 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4229 set_fileformat(default_fileformat(), OPT_LOCAL);
4230 }
4231
Bram Moolenaar071d4272004-06-13 20:20:40 +00004232#ifdef FEAT_TITLE
4233 set_title_defaults();
4234#endif
4235}
4236
4237#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4238/*
4239 * When 'helplang' is still at its default value, set it to "lang".
4240 * Only the first two characters of "lang" are used.
4241 */
4242 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004243set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004244{
4245 int idx;
4246
4247 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4248 return;
4249 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004250 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004251 {
4252 if (options[idx].flags & P_ALLOCED)
4253 free_string_option(p_hlg);
4254 p_hlg = vim_strsave(lang);
4255 if (p_hlg == NULL)
4256 p_hlg = empty_option;
4257 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004258 {
4259 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4260 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4261 {
4262 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4263 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4264 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004265 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004266 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004267 options[idx].flags |= P_ALLOCED;
4268 }
4269}
4270#endif
4271
4272#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004273static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004274
4275 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004276gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004277{
4278 if (gui_get_lightness(gui.back_pixel) < 127)
4279 return (char_u *)"dark";
4280 return (char_u *)"light";
4281}
4282
4283/*
4284 * Option initializations that can only be done after opening the GUI window.
4285 */
4286 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004287init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004288{
4289 /* Set the 'background' option according to the lightness of the
4290 * background color, unless the user has set it already. */
4291 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4292 {
4293 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4294 highlight_changed();
4295 }
4296}
4297#endif
4298
4299#ifdef FEAT_TITLE
4300/*
4301 * 'title' and 'icon' only default to true if they have not been set or reset
4302 * in .vimrc and we can read the old value.
4303 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4304 * they can be reset. This reduces startup time when using X on a remote
4305 * machine.
4306 */
4307 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004308set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004309{
4310 int idx1;
4311 long val;
4312
4313 /*
4314 * If GUI is (going to be) used, we can always set the window title and
4315 * icon name. Saves a bit of time, because the X11 display server does
4316 * not need to be contacted.
4317 */
4318 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004319 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004320 {
4321#ifdef FEAT_GUI
4322 if (gui.starting || gui.in_use)
4323 val = TRUE;
4324 else
4325#endif
4326 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004327 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004328 p_title = val;
4329 }
4330 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004331 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004332 {
4333#ifdef FEAT_GUI
4334 if (gui.starting || gui.in_use)
4335 val = TRUE;
4336 else
4337#endif
4338 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004339 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004340 p_icon = val;
4341 }
4342}
4343#endif
4344
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004345#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4346 static void
4347trigger_optionsset_string(
4348 int opt_idx,
4349 int opt_flags,
4350 char_u *oldval,
4351 char_u *newval)
4352{
4353 if (oldval != NULL && newval != NULL)
4354 {
4355 char_u buf_type[7];
4356
4357 sprintf((char *)buf_type, "%s",
4358 (opt_flags & OPT_LOCAL) ? "local" : "global");
4359 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4360 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4361 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4362 apply_autocmds(EVENT_OPTIONSET,
4363 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4364 reset_v_option_vars();
4365 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004366}
4367#endif
4368
Bram Moolenaar071d4272004-06-13 20:20:40 +00004369/*
4370 * Parse 'arg' for option settings.
4371 *
4372 * 'arg' may be IObuff, but only when no errors can be present and option
4373 * does not need to be expanded with option_expand().
4374 * "opt_flags":
4375 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004376 * OPT_GLOBAL for ":setglobal"
4377 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004378 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004379 * OPT_WINONLY to only set window-local options
4380 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004381 *
4382 * returns FAIL if an error is detected, OK otherwise
4383 */
4384 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004385do_set(
4386 char_u *arg, /* option string (may be written to!) */
4387 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004388{
4389 int opt_idx;
4390 char_u *errmsg;
4391 char_u errbuf[80];
4392 char_u *startarg;
4393 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4394 int nextchar; /* next non-white char after option name */
4395 int afterchar; /* character just after option name */
4396 int len;
4397 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004398 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399 int key;
4400 long_u flags; /* flags for current option */
4401 char_u *varp = NULL; /* pointer to variable for current option */
4402 int did_show = FALSE; /* already showed one value */
4403 int adding; /* "opt+=arg" */
4404 int prepending; /* "opt^=arg" */
4405 int removing; /* "opt-=arg" */
4406 int cp_val = 0;
4407 char_u key_name[2];
4408
4409 if (*arg == NUL)
4410 {
4411 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004412 did_show = TRUE;
4413 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004414 }
4415
4416 while (*arg != NUL) /* loop to process all options */
4417 {
4418 errmsg = NULL;
4419 startarg = arg; /* remember for error message */
4420
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004421 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4422 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004423 {
4424 /*
4425 * ":set all" show all options.
4426 * ":set all&" set all options to their default value.
4427 */
4428 arg += 3;
4429 if (*arg == '&')
4430 {
4431 ++arg;
4432 /* Only for :set command set global value of local options. */
4433 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004434 didset_options();
4435 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004436 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004437 }
4438 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004439 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004440 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004441 did_show = TRUE;
4442 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004443 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004444 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004445 {
4446 showoptions(2, opt_flags);
4447 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004448 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004449 arg += 7;
4450 }
4451 else
4452 {
4453 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004454 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004455 {
4456 prefix = 0;
4457 arg += 2;
4458 }
4459 else if (STRNCMP(arg, "inv", 3) == 0)
4460 {
4461 prefix = 2;
4462 arg += 3;
4463 }
4464
4465 /* find end of name */
4466 key = 0;
4467 if (*arg == '<')
4468 {
4469 nextchar = 0;
4470 opt_idx = -1;
4471 /* look out for <t_>;> */
4472 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4473 len = 5;
4474 else
4475 {
4476 len = 1;
4477 while (arg[len] != NUL && arg[len] != '>')
4478 ++len;
4479 }
4480 if (arg[len] != '>')
4481 {
4482 errmsg = e_invarg;
4483 goto skip;
4484 }
4485 arg[len] = NUL; /* put NUL after name */
4486 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4487 opt_idx = findoption(arg + 1);
4488 arg[len++] = '>'; /* restore '>' */
4489 if (opt_idx == -1)
4490 key = find_key_option(arg + 1);
4491 }
4492 else
4493 {
4494 len = 0;
4495 /*
4496 * The two characters after "t_" may not be alphanumeric.
4497 */
4498 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4499 len = 4;
4500 else
4501 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4502 ++len;
4503 nextchar = arg[len];
4504 arg[len] = NUL; /* put NUL after name */
4505 opt_idx = findoption(arg);
4506 arg[len] = nextchar; /* restore nextchar */
4507 if (opt_idx == -1)
4508 key = find_key_option(arg);
4509 }
4510
4511 /* remember character after option name */
4512 afterchar = arg[len];
4513
4514 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004515 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004516 ++len;
4517
4518 adding = FALSE;
4519 prepending = FALSE;
4520 removing = FALSE;
4521 if (arg[len] != NUL && arg[len + 1] == '=')
4522 {
4523 if (arg[len] == '+')
4524 {
4525 adding = TRUE; /* "+=" */
4526 ++len;
4527 }
4528 else if (arg[len] == '^')
4529 {
4530 prepending = TRUE; /* "^=" */
4531 ++len;
4532 }
4533 else if (arg[len] == '-')
4534 {
4535 removing = TRUE; /* "-=" */
4536 ++len;
4537 }
4538 }
4539 nextchar = arg[len];
4540
4541 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4542 {
4543 errmsg = (char_u *)N_("E518: Unknown option");
4544 goto skip;
4545 }
4546
4547 if (opt_idx >= 0)
4548 {
4549 if (options[opt_idx].var == NULL) /* hidden option: skip */
4550 {
4551 /* Only give an error message when requesting the value of
4552 * a hidden option, ignore setting it. */
4553 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4554 && (!(options[opt_idx].flags & P_BOOL)
4555 || nextchar == '?'))
4556 errmsg = (char_u *)N_("E519: Option not supported");
4557 goto skip;
4558 }
4559
4560 flags = options[opt_idx].flags;
4561 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4562 }
4563 else
4564 {
4565 flags = P_STRING;
4566 if (key < 0)
4567 {
4568 key_name[0] = KEY2TERMCAP0(key);
4569 key_name[1] = KEY2TERMCAP1(key);
4570 }
4571 else
4572 {
4573 key_name[0] = KS_KEY;
4574 key_name[1] = (key & 0xff);
4575 }
4576 }
4577
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004578 /* Skip all options that are not window-local (used when showing
4579 * an already loaded buffer in a window). */
4580 if ((opt_flags & OPT_WINONLY)
4581 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4582 goto skip;
4583
Bram Moolenaara3227e22006-03-08 21:32:40 +00004584 /* Skip all options that are window-local (used for :vimgrep). */
4585 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4586 && options[opt_idx].var == VAR_WIN)
4587 goto skip;
4588
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004589 /* Disallow changing some options from modelines. */
4590 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004591 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004592 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004593 {
4594 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4595 goto skip;
4596 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004597#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004598 /* In diff mode some options are overruled. This avoids that
4599 * 'foldmethod' becomes "marker" instead of "diff" and that
4600 * "wrap" gets set. */
4601 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004602 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004603 && (
4604#ifdef FEAT_FOLDING
4605 options[opt_idx].indir == PV_FDM ||
4606#endif
4607 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004608 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004609#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004610 }
4611
4612#ifdef HAVE_SANDBOX
4613 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004614 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615 {
4616 errmsg = (char_u *)_(e_sandbox);
4617 goto skip;
4618 }
4619#endif
4620
4621 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4622 {
4623 arg += len;
4624 cp_val = p_cp;
4625 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4626 {
4627 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4628 {
4629 cp_val = FALSE;
4630 arg += 3;
4631 }
4632 else /* "opt&vi": set to Vi default */
4633 {
4634 cp_val = TRUE;
4635 arg += 2;
4636 }
4637 }
4638 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004639 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004640 {
4641 errmsg = e_trailing;
4642 goto skip;
4643 }
4644 }
4645
4646 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004647 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4648 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004649 */
4650 if (nextchar == '?'
4651 || (prefix == 1
4652 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4653 && !(flags & P_BOOL)))
4654 {
4655 /*
4656 * print value
4657 */
4658 if (did_show)
4659 msg_putchar('\n'); /* cursor below last one */
4660 else
4661 {
4662 gotocmdline(TRUE); /* cursor at status line */
4663 did_show = TRUE; /* remember that we did a line */
4664 }
4665 if (opt_idx >= 0)
4666 {
4667 showoneopt(&options[opt_idx], opt_flags);
4668#ifdef FEAT_EVAL
4669 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004670 {
4671 /* Mention where the option was last set. */
4672 if (varp == options[opt_idx].var)
4673 last_set_msg(options[opt_idx].scriptID);
4674 else if ((int)options[opt_idx].indir & PV_WIN)
4675 last_set_msg(curwin->w_p_scriptID[
4676 (int)options[opt_idx].indir & PV_MASK]);
4677 else if ((int)options[opt_idx].indir & PV_BUF)
4678 last_set_msg(curbuf->b_p_scriptID[
4679 (int)options[opt_idx].indir & PV_MASK]);
4680 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004681#endif
4682 }
4683 else
4684 {
4685 char_u *p;
4686
4687 p = find_termcode(key_name);
4688 if (p == NULL)
4689 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004690 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004691 goto skip;
4692 }
4693 else
4694 (void)show_one_termcode(key_name, p, TRUE);
4695 }
4696 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004697 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004698 errmsg = e_trailing;
4699 }
4700 else
4701 {
4702 if (flags & P_BOOL) /* boolean */
4703 {
4704 if (nextchar == '=' || nextchar == ':')
4705 {
4706 errmsg = e_invarg;
4707 goto skip;
4708 }
4709
4710 /*
4711 * ":set opt!": invert
4712 * ":set opt&": reset to default value
4713 * ":set opt<": reset to global value
4714 */
4715 if (nextchar == '!')
4716 value = *(int *)(varp) ^ 1;
4717 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004718 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004719 ((flags & P_VI_DEF) || cp_val)
4720 ? VI_DEFAULT : VIM_DEFAULT];
4721 else if (nextchar == '<')
4722 {
4723 /* For 'autoread' -1 means to use global value. */
4724 if ((int *)varp == &curbuf->b_p_ar
4725 && opt_flags == OPT_LOCAL)
4726 value = -1;
4727 else
4728 value = *(int *)get_varp_scope(&(options[opt_idx]),
4729 OPT_GLOBAL);
4730 }
4731 else
4732 {
4733 /*
4734 * ":set invopt": invert
4735 * ":set opt" or ":set noopt": set or reset
4736 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004737 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004738 {
4739 errmsg = e_trailing;
4740 goto skip;
4741 }
4742 if (prefix == 2) /* inv */
4743 value = *(int *)(varp) ^ 1;
4744 else
4745 value = prefix;
4746 }
4747
4748 errmsg = set_bool_option(opt_idx, varp, (int)value,
4749 opt_flags);
4750 }
4751 else /* numeric or string */
4752 {
4753 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4754 || prefix != 1)
4755 {
4756 errmsg = e_invarg;
4757 goto skip;
4758 }
4759
4760 if (flags & P_NUM) /* numeric */
4761 {
4762 /*
4763 * Different ways to set a number option:
4764 * & set to default value
4765 * < set to global value
4766 * <xx> accept special key codes for 'wildchar'
4767 * c accept any non-digit for 'wildchar'
4768 * [-]0-9 set number
4769 * other error
4770 */
4771 ++arg;
4772 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004773 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004774 ((flags & P_VI_DEF) || cp_val)
4775 ? VI_DEFAULT : VIM_DEFAULT];
4776 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004777 {
4778 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4779 * use the global value. */
4780 if ((long *)varp == &curbuf->b_p_ul
4781 && opt_flags == OPT_LOCAL)
4782 value = NO_LOCAL_UNDOLEVEL;
4783 else
4784 value = *(long *)get_varp_scope(
4785 &(options[opt_idx]), OPT_GLOBAL);
4786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004787 else if (((long *)varp == &p_wc
4788 || (long *)varp == &p_wcm)
4789 && (*arg == '<'
4790 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004791 || (*arg != NUL
4792 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004793 && !VIM_ISDIGIT(*arg))))
4794 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004795 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004796 if (value == 0 && (long *)varp != &p_wcm)
4797 {
4798 errmsg = e_invarg;
4799 goto skip;
4800 }
4801 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004802 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4803 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004804 /* Allow negative (for 'undolevels'), octal and
4805 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004806 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4807 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004808 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004809 {
4810 errmsg = e_invarg;
4811 goto skip;
4812 }
4813 }
4814 else
4815 {
4816 errmsg = (char_u *)N_("E521: Number required after =");
4817 goto skip;
4818 }
4819
4820 if (adding)
4821 value = *(long *)varp + value;
4822 if (prepending)
4823 value = *(long *)varp * value;
4824 if (removing)
4825 value = *(long *)varp - value;
4826 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004827 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004828 }
4829 else if (opt_idx >= 0) /* string */
4830 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004831 char_u *save_arg = NULL;
4832 char_u *s = NULL;
4833 char_u *oldval = NULL; /* previous value if *varp */
4834 char_u *newval;
4835 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004836#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004837 char_u *saved_origval = NULL;
4838 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004839#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004840 unsigned newlen;
4841 int comma;
4842 int bs;
4843 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004844 was allocated */
4845
4846 /* When using ":set opt=val" for a global option
4847 * with a local value the local value will be
4848 * reset, use the global value here. */
4849 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004850 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004851 varp = options[opt_idx].var;
4852
4853 /* The old value is kept until we are sure that the
4854 * new value is valid. */
4855 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004856
4857 /* When setting the local value of a global
4858 * option, the old value may be the global value. */
4859 if (((int)options[opt_idx].indir & PV_BOTH)
4860 && (opt_flags & OPT_LOCAL))
4861 origval = *(char_u **)get_varp(
4862 &options[opt_idx]);
4863 else
4864 origval = oldval;
4865
Bram Moolenaar071d4272004-06-13 20:20:40 +00004866 if (nextchar == '&') /* set to default val */
4867 {
4868 newval = options[opt_idx].def_val[
4869 ((flags & P_VI_DEF) || cp_val)
4870 ? VI_DEFAULT : VIM_DEFAULT];
4871 if ((char_u **)varp == &p_bg)
4872 {
4873 /* guess the value of 'background' */
4874#ifdef FEAT_GUI
4875 if (gui.in_use)
4876 newval = gui_bg_default();
4877 else
4878#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004879 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004880 }
4881
4882 /* expand environment variables and ~ (since the
4883 * default value was already expanded, only
4884 * required when an environment variable was set
4885 * later */
4886 if (newval == NULL)
4887 newval = empty_option;
4888 else
4889 {
4890 s = option_expand(opt_idx, newval);
4891 if (s == NULL)
4892 s = newval;
4893 newval = vim_strsave(s);
4894 }
4895 new_value_alloced = TRUE;
4896 }
4897 else if (nextchar == '<') /* set to global val */
4898 {
4899 newval = vim_strsave(*(char_u **)get_varp_scope(
4900 &(options[opt_idx]), OPT_GLOBAL));
4901 new_value_alloced = TRUE;
4902 }
4903 else
4904 {
4905 ++arg; /* jump to after the '=' or ':' */
4906
4907 /*
4908 * Set 'keywordprg' to ":help" if an empty
4909 * value was passed to :set by the user.
4910 * Misuse errbuf[] for the resulting string.
4911 */
4912 if (varp == (char_u *)&p_kp
4913 && (*arg == NUL || *arg == ' '))
4914 {
4915 STRCPY(errbuf, ":help");
4916 save_arg = arg;
4917 arg = errbuf;
4918 }
4919 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004920 * Convert 'backspace' number to string, for
4921 * adding, prepending and removing string.
4922 */
4923 else if (varp == (char_u *)&p_bs
4924 && VIM_ISDIGIT(**(char_u **)varp))
4925 {
4926 i = getdigits((char_u **)varp);
4927 switch (i)
4928 {
4929 case 0:
4930 *(char_u **)varp = empty_option;
4931 break;
4932 case 1:
4933 *(char_u **)varp = vim_strsave(
4934 (char_u *)"indent,eol");
4935 break;
4936 case 2:
4937 *(char_u **)varp = vim_strsave(
4938 (char_u *)"indent,eol,start");
4939 break;
4940 }
4941 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004942 if (origval == oldval)
4943 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004944 oldval = *(char_u **)varp;
4945 }
4946 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004947 * Convert 'whichwrap' number to string, for
4948 * backwards compatibility with Vim 3.0.
4949 * Misuse errbuf[] for the resulting string.
4950 */
4951 else if (varp == (char_u *)&p_ww
4952 && VIM_ISDIGIT(*arg))
4953 {
4954 *errbuf = NUL;
4955 i = getdigits(&arg);
4956 if (i & 1)
4957 STRCAT(errbuf, "b,");
4958 if (i & 2)
4959 STRCAT(errbuf, "s,");
4960 if (i & 4)
4961 STRCAT(errbuf, "h,l,");
4962 if (i & 8)
4963 STRCAT(errbuf, "<,>,");
4964 if (i & 16)
4965 STRCAT(errbuf, "[,],");
4966 if (*errbuf != NUL) /* remove trailing , */
4967 errbuf[STRLEN(errbuf) - 1] = NUL;
4968 save_arg = arg;
4969 arg = errbuf;
4970 }
4971 /*
4972 * Remove '>' before 'dir' and 'bdir', for
4973 * backwards compatibility with version 3.0
4974 */
4975 else if ( *arg == '>'
4976 && (varp == (char_u *)&p_dir
4977 || varp == (char_u *)&p_bdir))
4978 {
4979 ++arg;
4980 }
4981
Bram Moolenaar071d4272004-06-13 20:20:40 +00004982 /*
4983 * Copy the new string into allocated memory.
4984 * Can't use set_string_option_direct(), because
4985 * we need to remove the backslashes.
4986 */
4987 /* get a bit too much */
4988 newlen = (unsigned)STRLEN(arg) + 1;
4989 if (adding || prepending || removing)
4990 newlen += (unsigned)STRLEN(origval) + 1;
4991 newval = alloc(newlen);
4992 if (newval == NULL) /* out of mem, don't change */
4993 break;
4994 s = newval;
4995
4996 /*
4997 * Copy the string, skip over escaped chars.
4998 * For MS-DOS and WIN32 backslashes before normal
4999 * file name characters are not removed, and keep
5000 * backslash at start, for "\\machine\path", but
5001 * do remove it for "\\\\machine\\path".
5002 * The reverse is found in ExpandOldSetting().
5003 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005004 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005005 {
5006 if (*arg == '\\' && arg[1] != NUL
5007#ifdef BACKSLASH_IN_FILENAME
5008 && !((flags & P_EXPAND)
5009 && vim_isfilec(arg[1])
5010 && (arg[1] != '\\'
5011 || (s == newval
5012 && arg[2] != '\\')))
5013#endif
5014 )
5015 ++arg; /* remove backslash */
5016#ifdef FEAT_MBYTE
5017 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005018 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005019 {
5020 /* copy multibyte char */
5021 mch_memmove(s, arg, (size_t)i);
5022 arg += i;
5023 s += i;
5024 }
5025 else
5026#endif
5027 *s++ = *arg++;
5028 }
5029 *s = NUL;
5030
5031 /*
5032 * Expand environment variables and ~.
5033 * Don't do it when adding without inserting a
5034 * comma.
5035 */
5036 if (!(adding || prepending || removing)
5037 || (flags & P_COMMA))
5038 {
5039 s = option_expand(opt_idx, newval);
5040 if (s != NULL)
5041 {
5042 vim_free(newval);
5043 newlen = (unsigned)STRLEN(s) + 1;
5044 if (adding || prepending || removing)
5045 newlen += (unsigned)STRLEN(origval) + 1;
5046 newval = alloc(newlen);
5047 if (newval == NULL)
5048 break;
5049 STRCPY(newval, s);
5050 }
5051 }
5052
5053 /* locate newval[] in origval[] when removing it
5054 * and when adding to avoid duplicates */
5055 i = 0; /* init for GCC */
5056 if (removing || (flags & P_NODUP))
5057 {
5058 i = (int)STRLEN(newval);
5059 bs = 0;
5060 for (s = origval; *s; ++s)
5061 {
5062 if ((!(flags & P_COMMA)
5063 || s == origval
5064 || (s[-1] == ',' && !(bs & 1)))
5065 && STRNCMP(s, newval, i) == 0
5066 && (!(flags & P_COMMA)
5067 || s[i] == ','
5068 || s[i] == NUL))
5069 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005070 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005071 * even number of backslashes or a single
5072 * backslash preceded by a comma before it
5073 * is recognized as a separator */
5074 if ((s > origval + 1
5075 && s[-1] == '\\'
5076 && s[-2] != ',')
5077 || (s == origval + 1
5078 && s[-1] == '\\'))
5079
Bram Moolenaar071d4272004-06-13 20:20:40 +00005080 ++bs;
5081 else
5082 bs = 0;
5083 }
5084
5085 /* do not add if already there */
5086 if ((adding || prepending) && *s)
5087 {
5088 prepending = FALSE;
5089 adding = FALSE;
5090 STRCPY(newval, origval);
5091 }
5092 }
5093
5094 /* concatenate the two strings; add a ',' if
5095 * needed */
5096 if (adding || prepending)
5097 {
5098 comma = ((flags & P_COMMA) && *origval != NUL
5099 && *newval != NUL);
5100 if (adding)
5101 {
5102 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005103 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005104 if (comma && i > 1
5105 && (flags & P_ONECOMMA) == P_ONECOMMA
5106 && origval[i - 1] == ','
5107 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005108 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005109 mch_memmove(newval + i + comma, newval,
5110 STRLEN(newval) + 1);
5111 mch_memmove(newval, origval, (size_t)i);
5112 }
5113 else
5114 {
5115 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005116 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005117 }
5118 if (comma)
5119 newval[i] = ',';
5120 }
5121
5122 /* Remove newval[] from origval[]. (Note: "i" has
5123 * been set above and is used here). */
5124 if (removing)
5125 {
5126 STRCPY(newval, origval);
5127 if (*s)
5128 {
5129 /* may need to remove a comma */
5130 if (flags & P_COMMA)
5131 {
5132 if (s == origval)
5133 {
5134 /* include comma after string */
5135 if (s[i] == ',')
5136 ++i;
5137 }
5138 else
5139 {
5140 /* include comma before string */
5141 --s;
5142 ++i;
5143 }
5144 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005145 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005146 }
5147 }
5148
5149 if (flags & P_FLAGLIST)
5150 {
5151 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005152 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005153 {
5154 /* if options have P_FLAGLIST and
5155 * P_ONECOMMA such as 'whichwrap' */
5156 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005157 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005158 if (*s != ',' && *(s + 1) == ','
5159 && vim_strchr(s + 2, *s) != NULL)
5160 {
5161 /* Remove the duplicated value and
5162 * the next comma. */
5163 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005164 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005165 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005166 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005167 else
5168 {
5169 if ((!(flags & P_COMMA) || *s != ',')
5170 && vim_strchr(s + 1, *s) != NULL)
5171 {
5172 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005173 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005174 }
5175 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005176 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005177 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005178 }
5179
5180 if (save_arg != NULL) /* number for 'whichwrap' */
5181 arg = save_arg;
5182 new_value_alloced = TRUE;
5183 }
5184
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005185 /*
5186 * Set the new value.
5187 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005188 *(char_u **)(varp) = newval;
5189
Bram Moolenaar53744302015-07-17 17:38:22 +02005190#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005191 if (!starting
5192# ifdef FEAT_CRYPT
5193 && options[opt_idx].indir != PV_KEY
5194# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005195 && origval != NULL && newval != NULL)
5196 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005197 /* origval may be freed by
5198 * did_set_string_option(), make a copy. */
5199 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005200 /* newval (and varp) may become invalid if the
5201 * buffer is closed by autocommands. */
5202 saved_newval = vim_strsave(newval);
5203 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005204#endif
5205
Bram Moolenaar071d4272004-06-13 20:20:40 +00005206 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005207 * ":set" on local options. Note: when setting 'syntax'
5208 * or 'filetype' autocommands may be triggered that can
5209 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005210 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5211 new_value_alloced, oldval, errbuf, opt_flags);
5212
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005213#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5214 if (errmsg == NULL)
5215 trigger_optionsset_string(opt_idx, opt_flags,
5216 saved_origval, saved_newval);
5217 vim_free(saved_origval);
5218 vim_free(saved_newval);
5219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005220 /* If error detected, print the error message. */
5221 if (errmsg != NULL)
5222 goto skip;
5223 }
5224 else /* key code option */
5225 {
5226 char_u *p;
5227
5228 if (nextchar == '&')
5229 {
5230 if (add_termcap_entry(key_name, TRUE) == FAIL)
5231 errmsg = (char_u *)N_("E522: Not found in termcap");
5232 }
5233 else
5234 {
5235 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005236 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005237 if (*p == '\\' && p[1] != NUL)
5238 ++p;
5239 nextchar = *p;
5240 *p = NUL;
5241 add_termcode(key_name, arg, FALSE);
5242 *p = nextchar;
5243 }
5244 if (full_screen)
5245 ttest(FALSE);
5246 redraw_all_later(CLEAR);
5247 }
5248 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005249
Bram Moolenaar071d4272004-06-13 20:20:40 +00005250 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005251 did_set_option(opt_idx, opt_flags,
5252 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005253 }
5254
5255skip:
5256 /*
5257 * Advance to next argument.
5258 * - skip until a blank found, taking care of backslashes
5259 * - skip blanks
5260 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5261 */
5262 for (i = 0; i < 2 ; ++i)
5263 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005264 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005265 if (*arg++ == '\\' && *arg != NUL)
5266 ++arg;
5267 arg = skipwhite(arg);
5268 if (*arg != '=')
5269 break;
5270 }
5271 }
5272
5273 if (errmsg != NULL)
5274 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005275 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005276 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005277 if (i + (arg - startarg) < IOSIZE)
5278 {
5279 /* append the argument with the error */
5280 STRCAT(IObuff, ": ");
5281 mch_memmove(IObuff + i, startarg, (arg - startarg));
5282 IObuff[i + (arg - startarg)] = NUL;
5283 }
5284 /* make sure all characters are printable */
5285 trans_characters(IObuff, IOSIZE);
5286
5287 ++no_wait_return; /* wait_return done later */
5288 emsg(IObuff); /* show error highlighted */
5289 --no_wait_return;
5290
5291 return FAIL;
5292 }
5293
5294 arg = skipwhite(arg);
5295 }
5296
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005297theend:
5298 if (silent_mode && did_show)
5299 {
5300 /* After displaying option values in silent mode. */
5301 silent_mode = FALSE;
5302 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5303 msg_putchar('\n');
5304 cursor_on(); /* msg_start() switches it off */
5305 out_flush();
5306 silent_mode = TRUE;
5307 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5308 }
5309
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310 return OK;
5311}
5312
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005313/*
5314 * Call this when an option has been given a new value through a user command.
5315 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5316 */
5317 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005318did_set_option(
5319 int opt_idx,
5320 int opt_flags, /* possibly with OPT_MODELINE */
5321 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005322{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005323 long_u *p;
5324
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005325 options[opt_idx].flags |= P_WAS_SET;
5326
5327 /* When an option is set in the sandbox, from a modeline or in secure mode
5328 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005329 * flag. */
5330 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005331 if (secure
5332#ifdef HAVE_SANDBOX
5333 || sandbox != 0
5334#endif
5335 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005336 *p = *p | P_INSECURE;
5337 else if (new_value)
5338 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005339}
5340
Bram Moolenaar071d4272004-06-13 20:20:40 +00005341 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005342illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343{
5344 if (errbuf == NULL)
5345 return (char_u *)"";
5346 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005347 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 return errbuf;
5349}
5350
5351/*
5352 * Convert a key name or string into a key value.
5353 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005354 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005356 int
5357string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005358{
5359 if (*arg == '<')
5360 return find_key_option(arg + 1);
5361 if (*arg == '^')
5362 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005363 if (multi_byte)
5364 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005365 return *arg;
5366}
5367
5368#ifdef FEAT_CMDWIN
5369/*
5370 * Check value of 'cedit' and set cedit_key.
5371 * Returns NULL if value is OK, error message otherwise.
5372 */
5373 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005374check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375{
5376 int n;
5377
5378 if (*p_cedit == NUL)
5379 cedit_key = -1;
5380 else
5381 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005382 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005383 if (vim_isprintc(n))
5384 return e_invarg;
5385 cedit_key = n;
5386 }
5387 return NULL;
5388}
5389#endif
5390
5391#ifdef FEAT_TITLE
5392/*
5393 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5394 * maketitle() to create and display it.
5395 * When switching the title or icon off, call mch_restore_title() to get
5396 * the old value back.
5397 */
5398 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005399did_set_title(
5400 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005401{
5402 if (starting != NO_SCREEN
5403#ifdef FEAT_GUI
5404 && !gui.starting
5405#endif
5406 )
5407 {
5408 maketitle();
5409 if (icon)
5410 {
5411 if (!p_icon)
5412 mch_restore_title(2);
5413 }
5414 else
5415 {
5416 if (!p_title)
5417 mch_restore_title(1);
5418 }
5419 }
5420}
5421#endif
5422
5423/*
5424 * set_options_bin - called when 'bin' changes value.
5425 */
5426 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005427set_options_bin(
5428 int oldval,
5429 int newval,
5430 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005431{
5432 /*
5433 * The option values that are changed when 'bin' changes are
5434 * copied when 'bin is set and restored when 'bin' is reset.
5435 */
5436 if (newval)
5437 {
5438 if (!oldval) /* switched on */
5439 {
5440 if (!(opt_flags & OPT_GLOBAL))
5441 {
5442 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5443 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5444 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5445 curbuf->b_p_et_nobin = curbuf->b_p_et;
5446 }
5447 if (!(opt_flags & OPT_LOCAL))
5448 {
5449 p_tw_nobin = p_tw;
5450 p_wm_nobin = p_wm;
5451 p_ml_nobin = p_ml;
5452 p_et_nobin = p_et;
5453 }
5454 }
5455
5456 if (!(opt_flags & OPT_GLOBAL))
5457 {
5458 curbuf->b_p_tw = 0; /* no automatic line wrap */
5459 curbuf->b_p_wm = 0; /* no automatic line wrap */
5460 curbuf->b_p_ml = 0; /* no modelines */
5461 curbuf->b_p_et = 0; /* no expandtab */
5462 }
5463 if (!(opt_flags & OPT_LOCAL))
5464 {
5465 p_tw = 0;
5466 p_wm = 0;
5467 p_ml = FALSE;
5468 p_et = FALSE;
5469 p_bin = TRUE; /* needed when called for the "-b" argument */
5470 }
5471 }
5472 else if (oldval) /* switched off */
5473 {
5474 if (!(opt_flags & OPT_GLOBAL))
5475 {
5476 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5477 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5478 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5479 curbuf->b_p_et = curbuf->b_p_et_nobin;
5480 }
5481 if (!(opt_flags & OPT_LOCAL))
5482 {
5483 p_tw = p_tw_nobin;
5484 p_wm = p_wm_nobin;
5485 p_ml = p_ml_nobin;
5486 p_et = p_et_nobin;
5487 }
5488 }
5489}
5490
5491#ifdef FEAT_VIMINFO
5492/*
5493 * Find the parameter represented by the given character (eg ', :, ", or /),
5494 * and return its associated value in the 'viminfo' string.
5495 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005496 * If the parameter is not specified in the string or there is no following
5497 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005498 */
5499 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005500get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005501{
5502 char_u *p;
5503
5504 p = find_viminfo_parameter(type);
5505 if (p != NULL && VIM_ISDIGIT(*p))
5506 return atoi((char *)p);
5507 return -1;
5508}
5509
5510/*
5511 * Find the parameter represented by the given character (eg ''', ':', '"', or
5512 * '/') in the 'viminfo' option and return a pointer to the string after it.
5513 * Return NULL if the parameter is not specified in the string.
5514 */
5515 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005516find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517{
5518 char_u *p;
5519
5520 for (p = p_viminfo; *p; ++p)
5521 {
5522 if (*p == type)
5523 return p + 1;
5524 if (*p == 'n') /* 'n' is always the last one */
5525 break;
5526 p = vim_strchr(p, ','); /* skip until next ',' */
5527 if (p == NULL) /* hit the end without finding parameter */
5528 break;
5529 }
5530 return NULL;
5531}
5532#endif
5533
5534/*
5535 * Expand environment variables for some string options.
5536 * These string options cannot be indirect!
5537 * If "val" is NULL expand the current value of the option.
5538 * Return pointer to NameBuff, or NULL when not expanded.
5539 */
5540 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005541option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005542{
5543 /* if option doesn't need expansion nothing to do */
5544 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5545 return NULL;
5546
5547 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5548 * expand_env() would truncate the string. */
5549 if (val != NULL && STRLEN(val) > MAXPATHL)
5550 return NULL;
5551
5552 if (val == NULL)
5553 val = *(char_u **)options[opt_idx].var;
5554
5555 /*
5556 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5557 * Escape spaces when expanding 'tags', they are used to separate file
5558 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005559 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005560 */
5561 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005562 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005563#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005564 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5565#endif
5566 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005567 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5568 return NULL;
5569
5570 return NameBuff;
5571}
5572
5573/*
5574 * After setting various option values: recompute variables that depend on
5575 * option values.
5576 */
5577 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005578didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005579{
5580 /* initialize the table for 'iskeyword' et.al. */
5581 (void)init_chartab();
5582
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005583#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005585#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005586 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005587 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588#ifdef FEAT_SESSION
5589 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5590 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5591#endif
5592#ifdef FEAT_FOLDING
5593 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5594#endif
5595 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005596 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005597#ifdef FEAT_VIRTUALEDIT
5598 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5599#endif
5600#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5601 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5602#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005603#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005604 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005605 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005606 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005607 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005608#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005609#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5610 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5611#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005612#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005613 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5614#endif
5615#ifdef FEAT_CMDWIN
5616 /* set cedit_key */
5617 (void)check_cedit();
5618#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005619#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005620 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005621#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005622#ifdef FEAT_LINEBREAK
5623 /* initialize the table for 'breakat'. */
5624 fill_breakat_flags();
5625#endif
5626
5627}
5628
5629/*
5630 * More side effects of setting options.
5631 */
5632 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005633didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005634{
5635 /* Initialize the highlight_attr[] table. */
5636 (void)highlight_changed();
5637
5638 /* Parse default for 'wildmode' */
5639 check_opt_wim();
5640
5641 (void)set_chars_option(&p_lcs);
5642#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5643 /* Parse default for 'fillchars'. */
5644 (void)set_chars_option(&p_fcs);
5645#endif
5646
5647#ifdef FEAT_CLIPBOARD
5648 /* Parse default for 'clipboard' */
5649 (void)check_clipboard_option();
5650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005651}
5652
5653/*
5654 * Check for string options that are NULL (normally only termcap options).
5655 */
5656 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005657check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005658{
5659 int opt_idx;
5660
5661 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5662 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5663 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5664}
5665
5666/*
5667 * Check string options in a buffer for NULL value.
5668 */
5669 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005670check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672 check_string_option(&buf->b_p_bh);
5673 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005674#ifdef FEAT_MBYTE
5675 check_string_option(&buf->b_p_fenc);
5676#endif
5677 check_string_option(&buf->b_p_ff);
5678#ifdef FEAT_FIND_ID
5679 check_string_option(&buf->b_p_def);
5680 check_string_option(&buf->b_p_inc);
5681# ifdef FEAT_EVAL
5682 check_string_option(&buf->b_p_inex);
5683# endif
5684#endif
5685#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5686 check_string_option(&buf->b_p_inde);
5687 check_string_option(&buf->b_p_indk);
5688#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005689#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5690 check_string_option(&buf->b_p_bexpr);
5691#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005692#if defined(FEAT_CRYPT)
5693 check_string_option(&buf->b_p_cm);
5694#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005695 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005696#if defined(FEAT_EVAL)
5697 check_string_option(&buf->b_p_fex);
5698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699#ifdef FEAT_CRYPT
5700 check_string_option(&buf->b_p_key);
5701#endif
5702 check_string_option(&buf->b_p_kp);
5703 check_string_option(&buf->b_p_mps);
5704 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005705 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706 check_string_option(&buf->b_p_isk);
5707#ifdef FEAT_COMMENTS
5708 check_string_option(&buf->b_p_com);
5709#endif
5710#ifdef FEAT_FOLDING
5711 check_string_option(&buf->b_p_cms);
5712#endif
5713 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005714#ifdef FEAT_TEXTOBJ
5715 check_string_option(&buf->b_p_qe);
5716#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717#ifdef FEAT_SYN_HL
5718 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005719 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005720#endif
5721#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005722 check_string_option(&buf->b_s.b_p_spc);
5723 check_string_option(&buf->b_s.b_p_spf);
5724 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725#endif
5726#ifdef FEAT_SEARCHPATH
5727 check_string_option(&buf->b_p_sua);
5728#endif
5729#ifdef FEAT_CINDENT
5730 check_string_option(&buf->b_p_cink);
5731 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005732 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005733#endif
5734#ifdef FEAT_AUTOCMD
5735 check_string_option(&buf->b_p_ft);
5736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5738 check_string_option(&buf->b_p_cinw);
5739#endif
5740#ifdef FEAT_INS_EXPAND
5741 check_string_option(&buf->b_p_cpt);
5742#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005743#ifdef FEAT_COMPL_FUNC
5744 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005745 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005746#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005747#ifdef FEAT_KEYMAP
5748 check_string_option(&buf->b_p_keymap);
5749#endif
5750#ifdef FEAT_QUICKFIX
5751 check_string_option(&buf->b_p_gp);
5752 check_string_option(&buf->b_p_mp);
5753 check_string_option(&buf->b_p_efm);
5754#endif
5755 check_string_option(&buf->b_p_ep);
5756 check_string_option(&buf->b_p_path);
5757 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005758 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005759#ifdef FEAT_INS_EXPAND
5760 check_string_option(&buf->b_p_dict);
5761 check_string_option(&buf->b_p_tsr);
5762#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005763#ifdef FEAT_LISP
5764 check_string_option(&buf->b_p_lw);
5765#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005766 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005767#ifdef FEAT_MBYTE
5768 check_string_option(&buf->b_p_menc);
5769#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005770}
5771
5772/*
5773 * Free the string allocated for an option.
5774 * Checks for the string being empty_option. This may happen if we're out of
5775 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5776 * check_options().
5777 * Does NOT check for P_ALLOCED flag!
5778 */
5779 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005780free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005781{
5782 if (p != empty_option)
5783 vim_free(p);
5784}
5785
5786 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005787clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005788{
5789 if (*pp != empty_option)
5790 vim_free(*pp);
5791 *pp = empty_option;
5792}
5793
5794 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005795check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005796{
5797 if (*pp == NULL)
5798 *pp = empty_option;
5799}
5800
5801/*
5802 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5803 */
5804 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005805set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005806{
5807 int opt_idx;
5808
5809 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5810 if (options[opt_idx].var == (char_u *)p)
5811 {
5812 options[opt_idx].flags |= P_ALLOCED;
5813 return;
5814 }
5815 return; /* cannot happen: didn't find it! */
5816}
5817
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005818#if defined(FEAT_EVAL) || defined(PROTO)
5819/*
5820 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5821 * Return FALSE when it wasn't.
5822 * Return -1 for an unknown option.
5823 */
5824 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005825was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005826{
5827 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005828 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005829
5830 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005831 {
5832 flagp = insecure_flag(idx, opt_flags);
5833 return (*flagp & P_INSECURE) != 0;
5834 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005835 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005836 return -1;
5837}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005838
5839/*
5840 * Get a pointer to the flags used for the P_INSECURE flag of option
5841 * "opt_idx". For some local options a local flags field is used.
5842 */
5843 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005844insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005845{
5846 if (opt_flags & OPT_LOCAL)
5847 switch ((int)options[opt_idx].indir)
5848 {
5849#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005850 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005851#endif
5852#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005853# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005854 case PV_FDE: return &curwin->w_p_fde_flags;
5855 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005856# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005857# ifdef FEAT_BEVAL
5858 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5859# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005860# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005861 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005862# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005863 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005864# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005865 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005866# endif
5867#endif
5868 }
5869
5870 /* Nothing special, return global flags field. */
5871 return &options[opt_idx].flags;
5872}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005873#endif
5874
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005875#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005876static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005877
5878/*
5879 * Redraw the window title and/or tab page text later.
5880 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005881static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005882{
5883 need_maketitle = TRUE;
5884# ifdef FEAT_WINDOWS
5885 redraw_tabline = TRUE;
5886# endif
5887}
5888#endif
5889
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890/*
5891 * Set a string option to a new value (without checking the effect).
5892 * The string is copied into allocated memory.
5893 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005894 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005895 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 */
5897 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005898set_string_option_direct(
5899 char_u *name,
5900 int opt_idx,
5901 char_u *val,
5902 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5903 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904{
5905 char_u *s;
5906 char_u **varp;
5907 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005908 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005909
Bram Moolenaar89d40322006-08-29 15:30:07 +00005910 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005912 idx = findoption(name);
5913 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005914 {
5915 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005916 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 }
5920
Bram Moolenaar89d40322006-08-29 15:30:07 +00005921 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005922 return;
5923
5924 s = vim_strsave(val);
5925 if (s != NULL)
5926 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005927 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005928 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005929 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930 free_string_option(*varp);
5931 *varp = s;
5932
5933 /* For buffer/window local option may also set the global value. */
5934 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005935 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005936
Bram Moolenaar89d40322006-08-29 15:30:07 +00005937 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938
5939 /* When setting both values of a global option with a local value,
5940 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005941 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005942 {
5943 free_string_option(*varp);
5944 *varp = empty_option;
5945 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005946# ifdef FEAT_EVAL
5947 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005948 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005949 set_sid == 0 ? current_SID : set_sid);
5950# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005951 }
5952}
5953
5954/*
5955 * Set global value for string option when it's a local option.
5956 */
5957 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005958set_string_option_global(
5959 int opt_idx, /* option index */
5960 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005961{
5962 char_u **p, *s;
5963
5964 /* the global value is always allocated */
5965 if (options[opt_idx].var == VAR_WIN)
5966 p = (char_u **)GLOBAL_WO(varp);
5967 else
5968 p = (char_u **)options[opt_idx].var;
5969 if (options[opt_idx].indir != PV_NONE
5970 && p != varp
5971 && (s = vim_strsave(*varp)) != NULL)
5972 {
5973 free_string_option(*p);
5974 *p = s;
5975 }
5976}
5977
5978/*
5979 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005980 *
5981 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005982 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005983 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005984set_string_option(
5985 int opt_idx,
5986 char_u *value,
5987 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005988{
5989 char_u *s;
5990 char_u **varp;
5991 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005992#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5993 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005994 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005995#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005996 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005997
5998 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005999 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006000
6001 s = vim_strsave(value);
6002 if (s != NULL)
6003 {
6004 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6005 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006006 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006007 ? OPT_GLOBAL : OPT_LOCAL)
6008 : opt_flags);
6009 oldval = *varp;
6010 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006011
6012#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006013 if (!starting
6014# ifdef FEAT_CRYPT
6015 && options[opt_idx].indir != PV_KEY
6016# endif
6017 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006018 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006019 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006020 saved_newval = vim_strsave(s);
6021 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006022#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006023 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6024 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006025 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006026
Bram Moolenaar53744302015-07-17 17:38:22 +02006027#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006028 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006029 if (r == NULL)
6030 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006031 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006032 vim_free(saved_oldval);
6033 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006034#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006035 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006036 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037}
6038
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006039#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006040/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006041 * Return TRUE if "val" is a valid 'filetype' name.
6042 * Also used for 'syntax' and 'keymap'.
6043 */
6044 static int
6045valid_filetype(char_u *val)
6046{
6047 char_u *s;
6048
6049 for (s = val; *s != NUL; ++s)
6050 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6051 return FALSE;
6052 return TRUE;
6053}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006054#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006055
6056/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006057 * Handle string options that need some action to perform when changed.
6058 * Returns NULL for success, or an error message for an error.
6059 */
6060 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006061did_set_string_option(
6062 int opt_idx, /* index in options[] table */
6063 char_u **varp, /* pointer to the option variable */
6064 int new_value_alloced, /* new value was allocated */
6065 char_u *oldval, /* previous value of the option */
6066 char_u *errbuf, /* buffer for errors, or NULL */
6067 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006068{
6069 char_u *errmsg = NULL;
6070 char_u *s, *p;
6071 int did_chartab = FALSE;
6072 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006073 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006074#ifdef FEAT_GUI
6075 /* set when changing an option that only requires a redraw in the GUI */
6076 int redraw_gui_only = FALSE;
6077#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006078#ifdef FEAT_AUTOCMD
6079 int ft_changed = FALSE;
6080#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006081
6082 /* Get the global option to compare with, otherwise we would have to check
6083 * two values for all local options. */
6084 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6085
6086 /* Disallow changing some options from secure mode */
6087 if ((secure
6088#ifdef HAVE_SANDBOX
6089 || sandbox != 0
6090#endif
6091 ) && (options[opt_idx].flags & P_SECURE))
6092 {
6093 errmsg = e_secure;
6094 }
6095
Bram Moolenaar7554da42016-11-25 22:04:13 +01006096 /* Check for a "normal" directory or file name in some options. Disallow a
6097 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006098 * are often illegal in a file name. Be more permissive if "secure" is off.
6099 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006100 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006101 && vim_strpbrk(*varp, (char_u *)(secure
6102 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006103 || ((options[opt_idx].flags & P_NDNAME)
6104 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006105 {
6106 errmsg = e_invarg;
6107 }
6108
Bram Moolenaar071d4272004-06-13 20:20:40 +00006109 /* 'term' */
6110 else if (varp == &T_NAME)
6111 {
6112 if (T_NAME[0] == NUL)
6113 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6114#ifdef FEAT_GUI
6115 if (gui.in_use)
6116 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6117 else if (term_is_gui(T_NAME))
6118 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6119#endif
6120 else if (set_termname(T_NAME) == FAIL)
6121 errmsg = (char_u *)N_("E522: Not found in termcap");
6122 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006123 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 /* Screen colors may have changed. */
6125 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006126
6127 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6128 * P_ALLOCED flag on 'term'. */
6129 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006130 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006132 }
6133
6134 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006135 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006137 char_u *bkc = p_bkc;
6138 unsigned int *flags = &bkc_flags;
6139
6140 if (opt_flags & OPT_LOCAL)
6141 {
6142 bkc = curbuf->b_p_bkc;
6143 flags = &curbuf->b_bkc_flags;
6144 }
6145
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006146 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6147 /* make the local value empty: use the global value */
6148 *flags = 0;
6149 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006151 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6152 errmsg = e_invarg;
6153 if ((((int)*flags & BKC_AUTO) != 0)
6154 + (((int)*flags & BKC_YES) != 0)
6155 + (((int)*flags & BKC_NO) != 0) != 1)
6156 {
6157 /* Must have exactly one of "auto", "yes" and "no". */
6158 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6159 errmsg = e_invarg;
6160 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006161 }
6162 }
6163
6164 /* 'backupext' and 'patchmode' */
6165 else if (varp == &p_bex || varp == &p_pm)
6166 {
6167 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6168 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6169 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6170 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006171#ifdef FEAT_LINEBREAK
6172 /* 'breakindentopt' */
6173 else if (varp == &curwin->w_p_briopt)
6174 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006175 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006176 errmsg = e_invarg;
6177 }
6178#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006179
6180 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006181 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006182 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006183 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006184 */
6185 else if ( varp == &p_isi
6186 || varp == &(curbuf->b_p_isk)
6187 || varp == &p_isp
6188 || varp == &p_isf)
6189 {
6190 if (init_chartab() == FAIL)
6191 {
6192 did_chartab = TRUE; /* need to restore it below */
6193 errmsg = e_invarg; /* error in value */
6194 }
6195 }
6196
6197 /* 'helpfile' */
6198 else if (varp == &p_hf)
6199 {
6200 /* May compute new values for $VIM and $VIMRUNTIME */
6201 if (didset_vim)
6202 {
6203 vim_setenv((char_u *)"VIM", (char_u *)"");
6204 didset_vim = FALSE;
6205 }
6206 if (didset_vimruntime)
6207 {
6208 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6209 didset_vimruntime = FALSE;
6210 }
6211 }
6212
Bram Moolenaar1a384422010-07-14 19:53:30 +02006213#ifdef FEAT_SYN_HL
6214 /* 'colorcolumn' */
6215 else if (varp == &curwin->w_p_cc)
6216 errmsg = check_colorcolumn(curwin);
6217#endif
6218
Bram Moolenaar071d4272004-06-13 20:20:40 +00006219#ifdef FEAT_MULTI_LANG
6220 /* 'helplang' */
6221 else if (varp == &p_hlg)
6222 {
6223 /* Check for "", "ab", "ab,cd", etc. */
6224 for (s = p_hlg; *s != NUL; s += 3)
6225 {
6226 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6227 {
6228 errmsg = e_invarg;
6229 break;
6230 }
6231 if (s[2] == NUL)
6232 break;
6233 }
6234 }
6235#endif
6236
6237 /* 'highlight' */
6238 else if (varp == &p_hl)
6239 {
6240 if (highlight_changed() == FAIL)
6241 errmsg = e_invarg; /* invalid flags */
6242 }
6243
6244 /* 'nrformats' */
6245 else if (gvarp == &p_nf)
6246 {
6247 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6248 errmsg = e_invarg;
6249 }
6250
6251#ifdef FEAT_SESSION
6252 /* 'sessionoptions' */
6253 else if (varp == &p_ssop)
6254 {
6255 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6256 errmsg = e_invarg;
6257 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6258 {
6259 /* Don't allow both "sesdir" and "curdir". */
6260 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6261 errmsg = e_invarg;
6262 }
6263 }
6264 /* 'viewoptions' */
6265 else if (varp == &p_vop)
6266 {
6267 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6268 errmsg = e_invarg;
6269 }
6270#endif
6271
6272 /* 'scrollopt' */
6273#ifdef FEAT_SCROLLBIND
6274 else if (varp == &p_sbo)
6275 {
6276 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6277 errmsg = e_invarg;
6278 }
6279#endif
6280
6281 /* 'ambiwidth' */
6282#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006283 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006284 {
6285 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6286 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006287 else if (set_chars_option(&p_lcs) != NULL)
6288 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6289# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6290 else if (set_chars_option(&p_fcs) != NULL)
6291 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6292# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293 }
6294#endif
6295
6296 /* 'background' */
6297 else if (varp == &p_bg)
6298 {
6299 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6300 {
6301#ifdef FEAT_EVAL
6302 int dark = (*p_bg == 'd');
6303#endif
6304
6305 init_highlight(FALSE, FALSE);
6306
6307#ifdef FEAT_EVAL
6308 if (dark != (*p_bg == 'd')
6309 && get_var_value((char_u *)"g:colors_name") != NULL)
6310 {
6311 /* The color scheme must have set 'background' back to another
6312 * value, that's not what we want here. Disable the color
6313 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006314 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315 free_string_option(p_bg);
6316 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6317 check_string_option(&p_bg);
6318 init_highlight(FALSE, FALSE);
6319 }
6320#endif
6321 }
6322 else
6323 errmsg = e_invarg;
6324 }
6325
6326 /* 'wildmode' */
6327 else if (varp == &p_wim)
6328 {
6329 if (check_opt_wim() == FAIL)
6330 errmsg = e_invarg;
6331 }
6332
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006333#ifdef FEAT_CMDL_COMPL
6334 /* 'wildoptions' */
6335 else if (varp == &p_wop)
6336 {
6337 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6338 errmsg = e_invarg;
6339 }
6340#endif
6341
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342#ifdef FEAT_WAK
6343 /* 'winaltkeys' */
6344 else if (varp == &p_wak)
6345 {
6346 if (*p_wak == NUL
6347 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6348 errmsg = e_invarg;
6349# ifdef FEAT_MENU
6350# ifdef FEAT_GUI_MOTIF
6351 else if (gui.in_use)
6352 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6353# else
6354# ifdef FEAT_GUI_GTK
6355 else if (gui.in_use)
6356 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6357# endif
6358# endif
6359# endif
6360 }
6361#endif
6362
6363#ifdef FEAT_AUTOCMD
6364 /* 'eventignore' */
6365 else if (varp == &p_ei)
6366 {
6367 if (check_ei() == FAIL)
6368 errmsg = e_invarg;
6369 }
6370#endif
6371
6372#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006373 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6374 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6375 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006376 {
6377 if (gvarp == &p_fenc)
6378 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006379 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 errmsg = e_modifiable;
6381 else if (vim_strchr(*varp, ',') != NULL)
6382 /* No comma allowed in 'fileencoding'; catches confusing it
6383 * with 'fileencodings'. */
6384 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006385 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006386 {
6387# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006389 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006390# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006391 /* Add 'fileencoding' to the swap file. */
6392 ml_setflags(curbuf);
6393 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006394 }
6395 if (errmsg == NULL)
6396 {
6397 /* canonize the value, so that STRCMP() can be used on it */
6398 p = enc_canonize(*varp);
6399 if (p != NULL)
6400 {
6401 vim_free(*varp);
6402 *varp = p;
6403 }
6404 if (varp == &p_enc)
6405 {
6406 errmsg = mb_init();
6407# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006408 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006409# endif
6410 }
6411 }
6412
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006413# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006414 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6415 {
6416 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6417 if (STRCMP(p_tenc, "utf-8") != 0)
6418 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6419 }
6420# endif
6421
6422 if (errmsg == NULL)
6423 {
6424# ifdef FEAT_KEYMAP
6425 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6426 * (with another encoding). */
6427 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6428 (void)keymap_init();
6429# endif
6430
6431 /* When 'termencoding' is not empty and 'encoding' changes or when
6432 * 'termencoding' changes, need to setup for keyboard input and
6433 * display output conversion. */
6434 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6435 {
6436 convert_setup(&input_conv, p_tenc, p_enc);
6437 convert_setup(&output_conv, p_enc, p_tenc);
6438 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006439
6440# if defined(WIN3264) && defined(FEAT_MBYTE)
6441 /* $HOME may have characters in active code page. */
6442 if (varp == &p_enc)
6443 init_homedir();
6444# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006445 }
6446 }
6447#endif
6448
6449#if defined(FEAT_POSTSCRIPT)
6450 else if (varp == &p_penc)
6451 {
6452 /* Canonize printencoding if VIM standard one */
6453 p = enc_canonize(p_penc);
6454 if (p != NULL)
6455 {
6456 vim_free(p_penc);
6457 p_penc = p;
6458 }
6459 else
6460 {
6461 /* Ensure lower case and '-' for '_' */
6462 for (s = p_penc; *s != NUL; s++)
6463 {
6464 if (*s == '_')
6465 *s = '-';
6466 else
6467 *s = TOLOWER_ASC(*s);
6468 }
6469 }
6470 }
6471#endif
6472
Bram Moolenaar9372a112005-12-06 19:59:18 +00006473#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006474 else if (varp == &p_imak)
6475 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006476 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006477 errmsg = e_invarg;
6478 }
6479#endif
6480
6481#ifdef FEAT_KEYMAP
6482 else if (varp == &curbuf->b_p_keymap)
6483 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006484 if (!valid_filetype(*varp))
6485 errmsg = e_invarg;
6486 else
6487 /* load or unload key mapping tables */
6488 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006489
Bram Moolenaarfab06232009-03-04 03:13:35 +00006490 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006491 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006492 if (*curbuf->b_p_keymap != NUL)
6493 {
6494 /* Installed a new keymap, switch on using it. */
6495 curbuf->b_p_iminsert = B_IMODE_LMAP;
6496 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6497 curbuf->b_p_imsearch = B_IMODE_LMAP;
6498 }
6499 else
6500 {
6501 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6502 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6503 curbuf->b_p_iminsert = B_IMODE_NONE;
6504 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6505 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6506 }
6507 if ((opt_flags & OPT_LOCAL) == 0)
6508 {
6509 set_iminsert_global();
6510 set_imsearch_global();
6511 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006512# ifdef FEAT_WINDOWS
6513 status_redraw_curbuf();
6514# endif
6515 }
6516 }
6517#endif
6518
6519 /* 'fileformat' */
6520 else if (gvarp == &p_ff)
6521 {
6522 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6523 errmsg = e_modifiable;
6524 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6525 errmsg = e_invarg;
6526 else
6527 {
6528 /* may also change 'textmode' */
6529 if (get_fileformat(curbuf) == EOL_DOS)
6530 curbuf->b_p_tx = TRUE;
6531 else
6532 curbuf->b_p_tx = FALSE;
6533#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006534 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006535#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006536 /* update flag in swap file */
6537 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006538 /* Redraw needed when switching to/from "mac": a CR in the text
6539 * will be displayed differently. */
6540 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6541 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006542 }
6543 }
6544
6545 /* 'fileformats' */
6546 else if (varp == &p_ffs)
6547 {
6548 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6549 errmsg = e_invarg;
6550 else
6551 {
6552 /* also change 'textauto' */
6553 if (*p_ffs == NUL)
6554 p_ta = FALSE;
6555 else
6556 p_ta = TRUE;
6557 }
6558 }
6559
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006560#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006561 /* 'cryptkey' */
6562 else if (gvarp == &p_key)
6563 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006564# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006565 /* Make sure the ":set" command doesn't show the new value in the
6566 * history. */
6567 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006568# endif
6569 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6570 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006571 ml_set_crypt_key(curbuf, oldval,
6572 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006573 }
6574
6575 else if (gvarp == &p_cm)
6576 {
6577 if (opt_flags & OPT_LOCAL)
6578 p = curbuf->b_p_cm;
6579 else
6580 p = p_cm;
6581 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6582 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006583 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006584 errmsg = e_invarg;
6585 else
6586 {
6587 /* When setting the global value to empty, make it "zip". */
6588 if (*p_cm == NUL)
6589 {
6590 if (new_value_alloced)
6591 free_string_option(p_cm);
6592 p_cm = vim_strsave((char_u *)"zip");
6593 new_value_alloced = TRUE;
6594 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006595 /* When using ":set cm=name" the local value is going to be empty.
6596 * Do that here, otherwise the crypt functions will still use the
6597 * local value. */
6598 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6599 {
6600 free_string_option(curbuf->b_p_cm);
6601 curbuf->b_p_cm = empty_option;
6602 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006603
6604 /* Need to update the swapfile when the effective method changed.
6605 * Set "s" to the effective old value, "p" to the effective new
6606 * method and compare. */
6607 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6608 s = p_cm; /* was previously using the global value */
6609 else
6610 s = oldval;
6611 if (*curbuf->b_p_cm == NUL)
6612 p = p_cm; /* is now using the global value */
6613 else
6614 p = curbuf->b_p_cm;
6615 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006616 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006617
6618 /* If the global value changes need to update the swapfile for all
6619 * buffers using that value. */
6620 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6621 {
6622 buf_T *buf;
6623
Bram Moolenaar29323592016-07-24 22:04:11 +02006624 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006625 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006626 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006627 }
6628 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006629 }
6630#endif
6631
6632 /* 'matchpairs' */
6633 else if (gvarp == &p_mps)
6634 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006635#ifdef FEAT_MBYTE
6636 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006637 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006638 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006639 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006640 int x2 = -1;
6641 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006642
6643 if (*p != NUL)
6644 p += mb_ptr2len(p);
6645 if (*p != NUL)
6646 x2 = *p++;
6647 if (*p != NUL)
6648 {
6649 x3 = mb_ptr2char(p);
6650 p += mb_ptr2len(p);
6651 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006652 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006653 {
6654 errmsg = e_invarg;
6655 break;
6656 }
6657 if (*p == NUL)
6658 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006659 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006660 }
6661 else
6662#endif
6663 {
6664 /* Check for "x:y,x:y" */
6665 for (p = *varp; *p != NUL; p += 4)
6666 {
6667 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6668 {
6669 errmsg = e_invarg;
6670 break;
6671 }
6672 if (p[3] == NUL)
6673 break;
6674 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006675 }
6676 }
6677
6678#ifdef FEAT_COMMENTS
6679 /* 'comments' */
6680 else if (gvarp == &p_com)
6681 {
6682 for (s = *varp; *s; )
6683 {
6684 while (*s && *s != ':')
6685 {
6686 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6687 && !VIM_ISDIGIT(*s) && *s != '-')
6688 {
6689 errmsg = illegal_char(errbuf, *s);
6690 break;
6691 }
6692 ++s;
6693 }
6694 if (*s++ == NUL)
6695 errmsg = (char_u *)N_("E524: Missing colon");
6696 else if (*s == ',' || *s == NUL)
6697 errmsg = (char_u *)N_("E525: Zero length string");
6698 if (errmsg != NULL)
6699 break;
6700 while (*s && *s != ',')
6701 {
6702 if (*s == '\\' && s[1] != NUL)
6703 ++s;
6704 ++s;
6705 }
6706 s = skip_to_option_part(s);
6707 }
6708 }
6709#endif
6710
6711 /* 'listchars' */
6712 else if (varp == &p_lcs)
6713 {
6714 errmsg = set_chars_option(varp);
6715 }
6716
6717#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6718 /* 'fillchars' */
6719 else if (varp == &p_fcs)
6720 {
6721 errmsg = set_chars_option(varp);
6722 }
6723#endif
6724
6725#ifdef FEAT_CMDWIN
6726 /* 'cedit' */
6727 else if (varp == &p_cedit)
6728 {
6729 errmsg = check_cedit();
6730 }
6731#endif
6732
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006733 /* 'verbosefile' */
6734 else if (varp == &p_vfile)
6735 {
6736 verbose_stop();
6737 if (*p_vfile != NUL && verbose_open() == FAIL)
6738 errmsg = e_invarg;
6739 }
6740
Bram Moolenaar071d4272004-06-13 20:20:40 +00006741#ifdef FEAT_VIMINFO
6742 /* 'viminfo' */
6743 else if (varp == &p_viminfo)
6744 {
6745 for (s = p_viminfo; *s;)
6746 {
6747 /* Check it's a valid character */
6748 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6749 {
6750 errmsg = illegal_char(errbuf, *s);
6751 break;
6752 }
6753 if (*s == 'n') /* name is always last one */
6754 {
6755 break;
6756 }
6757 else if (*s == 'r') /* skip until next ',' */
6758 {
6759 while (*++s && *s != ',')
6760 ;
6761 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006762 else if (*s == '%')
6763 {
6764 /* optional number */
6765 while (vim_isdigit(*++s))
6766 ;
6767 }
6768 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006769 ++s; /* no extra chars */
6770 else /* must have a number */
6771 {
6772 while (vim_isdigit(*++s))
6773 ;
6774
6775 if (!VIM_ISDIGIT(*(s - 1)))
6776 {
6777 if (errbuf != NULL)
6778 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006779 sprintf((char *)errbuf,
6780 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006781 transchar_byte(*(s - 1)));
6782 errmsg = errbuf;
6783 }
6784 else
6785 errmsg = (char_u *)"";
6786 break;
6787 }
6788 }
6789 if (*s == ',')
6790 ++s;
6791 else if (*s)
6792 {
6793 if (errbuf != NULL)
6794 errmsg = (char_u *)N_("E527: Missing comma");
6795 else
6796 errmsg = (char_u *)"";
6797 break;
6798 }
6799 }
6800 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6801 errmsg = (char_u *)N_("E528: Must specify a ' value");
6802 }
6803#endif /* FEAT_VIMINFO */
6804
6805 /* terminal options */
6806 else if (istermoption(&options[opt_idx]) && full_screen)
6807 {
6808 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6809 if (varp == &T_CCO)
6810 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006811 int colors = atoi((char *)T_CCO);
6812
6813 /* Only reinitialize colors if t_Co value has really changed to
6814 * avoid expensive reload of colorscheme if t_Co is set to the
6815 * same value multiple times. */
6816 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006817 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006818 t_colors = colors;
6819 if (t_colors <= 1)
6820 {
6821 if (new_value_alloced)
6822 vim_free(T_CCO);
6823 T_CCO = empty_option;
6824 }
6825 /* We now have a different color setup, initialize it again. */
6826 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006827 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006828 }
6829 ttest(FALSE);
6830 if (varp == &T_ME)
6831 {
6832 out_str(T_ME);
6833 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006834#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 /* Since t_me has been set, this probably means that the user
6836 * wants to use this as default colors. Need to reset default
6837 * background/foreground colors. */
6838 mch_set_normal_colors();
6839#endif
6840 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006841 if (varp == &T_BE && termcap_active)
6842 {
6843 if (*T_BE == NUL)
6844 /* When clearing t_BE we assume the user no longer wants
6845 * bracketed paste, thus disable it by writing t_BD. */
6846 out_str(T_BD);
6847 else
6848 out_str(T_BE);
6849 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006850 }
6851
6852#ifdef FEAT_LINEBREAK
6853 /* 'showbreak' */
6854 else if (varp == &p_sbr)
6855 {
6856 for (s = p_sbr; *s; )
6857 {
6858 if (ptr2cells(s) != 1)
6859 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006860 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006861 }
6862 }
6863#endif
6864
6865#ifdef FEAT_GUI
6866 /* 'guifont' */
6867 else if (varp == &p_guifont)
6868 {
6869 if (gui.in_use)
6870 {
6871 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006872# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873 /*
6874 * Put up a font dialog and let the user select a new value.
6875 * If this is cancelled go back to the old value but don't
6876 * give an error message.
6877 */
6878 if (STRCMP(p, "*") == 0)
6879 {
6880 p = gui_mch_font_dialog(oldval);
6881
6882 if (new_value_alloced)
6883 free_string_option(p_guifont);
6884
6885 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6886 new_value_alloced = TRUE;
6887 }
6888# endif
6889 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6890 {
6891# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6892 if (STRCMP(p_guifont, "*") == 0)
6893 {
6894 /* Dialog was cancelled: Keep the old value without giving
6895 * an error message. */
6896 if (new_value_alloced)
6897 free_string_option(p_guifont);
6898 p_guifont = vim_strsave(oldval);
6899 new_value_alloced = TRUE;
6900 }
6901 else
6902# endif
6903 errmsg = (char_u *)N_("E596: Invalid font(s)");
6904 }
6905 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006906 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006907 }
6908# ifdef FEAT_XFONTSET
6909 else if (varp == &p_guifontset)
6910 {
6911 if (STRCMP(p_guifontset, "*") == 0)
6912 errmsg = (char_u *)N_("E597: can't select fontset");
6913 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6914 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006915 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006916 }
6917# endif
6918# ifdef FEAT_MBYTE
6919 else if (varp == &p_guifontwide)
6920 {
6921 if (STRCMP(p_guifontwide, "*") == 0)
6922 errmsg = (char_u *)N_("E533: can't select wide font");
6923 else if (gui_get_wide_font() == FAIL)
6924 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006925 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006926 }
6927# endif
6928#endif
6929
6930#ifdef CURSOR_SHAPE
6931 /* 'guicursor' */
6932 else if (varp == &p_guicursor)
6933 errmsg = parse_shape_opt(SHAPE_CURSOR);
6934#endif
6935
6936#ifdef FEAT_MOUSESHAPE
6937 /* 'mouseshape' */
6938 else if (varp == &p_mouseshape)
6939 {
6940 errmsg = parse_shape_opt(SHAPE_MOUSE);
6941 update_mouseshape(-1);
6942 }
6943#endif
6944
6945#ifdef FEAT_PRINTER
6946 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006947 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006948# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006949 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006950 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006951# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006952#endif
6953
6954#ifdef FEAT_LANGMAP
6955 /* 'langmap' */
6956 else if (varp == &p_langmap)
6957 langmap_set();
6958#endif
6959
6960#ifdef FEAT_LINEBREAK
6961 /* 'breakat' */
6962 else if (varp == &p_breakat)
6963 fill_breakat_flags();
6964#endif
6965
6966#ifdef FEAT_TITLE
6967 /* 'titlestring' and 'iconstring' */
6968 else if (varp == &p_titlestring || varp == &p_iconstring)
6969 {
6970# ifdef FEAT_STL_OPT
6971 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6972
6973 /* NULL => statusline syntax */
6974 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6975 stl_syntax |= flagval;
6976 else
6977 stl_syntax &= ~flagval;
6978# endif
6979 did_set_title(varp == &p_iconstring);
6980
6981 }
6982#endif
6983
6984#ifdef FEAT_GUI
6985 /* 'guioptions' */
6986 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006987 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006988 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006989 redraw_gui_only = TRUE;
6990 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006991#endif
6992
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006993#if defined(FEAT_GUI_TABLINE)
6994 /* 'guitablabel' */
6995 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006996 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006997 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006998 redraw_gui_only = TRUE;
6999 }
7000 /* 'guitabtooltip' */
7001 else if (varp == &p_gtt)
7002 {
7003 redraw_gui_only = TRUE;
7004 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007005#endif
7006
Bram Moolenaar071d4272004-06-13 20:20:40 +00007007#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7008 /* 'ttymouse' */
7009 else if (varp == &p_ttym)
7010 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007011 /* Switch the mouse off before changing the escape sequences used for
7012 * that. */
7013 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007014 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7015 errmsg = e_invarg;
7016 else
7017 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007018 if (termcap_active)
7019 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007020 }
7021#endif
7022
Bram Moolenaar071d4272004-06-13 20:20:40 +00007023 /* 'selection' */
7024 else if (varp == &p_sel)
7025 {
7026 if (*p_sel == NUL
7027 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7028 errmsg = e_invarg;
7029 }
7030
7031 /* 'selectmode' */
7032 else if (varp == &p_slm)
7033 {
7034 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7035 errmsg = e_invarg;
7036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007037
7038#ifdef FEAT_BROWSE
7039 /* 'browsedir' */
7040 else if (varp == &p_bsdir)
7041 {
7042 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7043 && !mch_isdir(p_bsdir))
7044 errmsg = e_invarg;
7045 }
7046#endif
7047
Bram Moolenaar071d4272004-06-13 20:20:40 +00007048 /* 'keymodel' */
7049 else if (varp == &p_km)
7050 {
7051 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7052 errmsg = e_invarg;
7053 else
7054 {
7055 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7056 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7057 }
7058 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059
7060 /* 'mousemodel' */
7061 else if (varp == &p_mousem)
7062 {
7063 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7064 errmsg = e_invarg;
7065#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7066 else if (*p_mousem != *oldval)
7067 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7068 * to create or delete the popup menus. */
7069 gui_motif_update_mousemodel(root_menu);
7070#endif
7071 }
7072
7073 /* 'switchbuf' */
7074 else if (varp == &p_swb)
7075 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007076 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077 errmsg = e_invarg;
7078 }
7079
7080 /* 'debug' */
7081 else if (varp == &p_debug)
7082 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007083 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007084 errmsg = e_invarg;
7085 }
7086
7087 /* 'display' */
7088 else if (varp == &p_dy)
7089 {
7090 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7091 errmsg = e_invarg;
7092 else
7093 (void)init_chartab();
7094
7095 }
7096
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007097#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007098 /* 'eadirection' */
7099 else if (varp == &p_ead)
7100 {
7101 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7102 errmsg = e_invarg;
7103 }
7104#endif
7105
7106#ifdef FEAT_CLIPBOARD
7107 /* 'clipboard' */
7108 else if (varp == &p_cb)
7109 errmsg = check_clipboard_option();
7110#endif
7111
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007112#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007113 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7114 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007115 else if (varp == &(curwin->w_s->b_p_spl)
7116 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007117 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007118 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007119 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007120 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007121 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007122 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007123 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007124 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007125 /* 'spellsuggest' */
7126 else if (varp == &p_sps)
7127 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007128 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007129 errmsg = e_invarg;
7130 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007131 /* 'mkspellmem' */
7132 else if (varp == &p_msm)
7133 {
7134 if (spell_check_msm() != OK)
7135 errmsg = e_invarg;
7136 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007137#endif
7138
Bram Moolenaar071d4272004-06-13 20:20:40 +00007139 /* When 'bufhidden' is set, check for valid value. */
7140 else if (gvarp == &p_bh)
7141 {
7142 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7143 errmsg = e_invarg;
7144 }
7145
7146 /* When 'buftype' is set, check for valid value. */
7147 else if (gvarp == &p_bt)
7148 {
7149 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7150 errmsg = e_invarg;
7151 else
7152 {
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007153#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154 if (curwin->w_status_height)
7155 {
7156 curwin->w_redr_status = TRUE;
7157 redraw_later(VALID);
7158 }
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007159#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007160 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007161#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007162 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007164 }
7165 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007166
7167#ifdef FEAT_STL_OPT
7168 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007169 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007170 {
7171 int wid;
7172
7173 if (varp == &p_ruf) /* reset ru_wid first */
7174 ru_wid = 0;
7175 s = *varp;
7176 if (varp == &p_ruf && *s == '%')
7177 {
7178 /* set ru_wid if 'ruf' starts with "%99(" */
7179 if (*++s == '-') /* ignore a '-' */
7180 s++;
7181 wid = getdigits(&s);
7182 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7183 ru_wid = wid;
7184 else
7185 errmsg = check_stl_option(p_ruf);
7186 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007187 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007188 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007189 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007190 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007191 comp_col();
7192 }
7193#endif
7194
7195#ifdef FEAT_INS_EXPAND
7196 /* check if it is a valid value for 'complete' -- Acevedo */
7197 else if (gvarp == &p_cpt)
7198 {
7199 for (s = *varp; *s;)
7200 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007201 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007202 s++;
7203 if (!*s)
7204 break;
7205 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7206 {
7207 errmsg = illegal_char(errbuf, *s);
7208 break;
7209 }
7210 if (*++s != NUL && *s != ',' && *s != ' ')
7211 {
7212 if (s[-1] == 'k' || s[-1] == 's')
7213 {
7214 /* skip optional filename after 'k' and 's' */
7215 while (*s && *s != ',' && *s != ' ')
7216 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007217 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007218 ++s;
7219 ++s;
7220 }
7221 }
7222 else
7223 {
7224 if (errbuf != NULL)
7225 {
7226 sprintf((char *)errbuf,
7227 _("E535: Illegal character after <%c>"),
7228 *--s);
7229 errmsg = errbuf;
7230 }
7231 else
7232 errmsg = (char_u *)"";
7233 break;
7234 }
7235 }
7236 }
7237 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007238
7239 /* 'completeopt' */
7240 else if (varp == &p_cot)
7241 {
7242 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7243 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007244 else
7245 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007246 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007247#endif /* FEAT_INS_EXPAND */
7248
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007249#ifdef FEAT_SIGNS
7250 /* 'signcolumn' */
7251 else if (varp == &curwin->w_p_scl)
7252 {
7253 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7254 errmsg = e_invarg;
7255 }
7256#endif
7257
Bram Moolenaar071d4272004-06-13 20:20:40 +00007258
7259#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007260 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007261 else if (varp == &p_toolbar)
7262 {
7263 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7264 &toolbar_flags, TRUE) != OK)
7265 errmsg = e_invarg;
7266 else
7267 {
7268 out_flush();
7269 gui_mch_show_toolbar((toolbar_flags &
7270 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7271 }
7272 }
7273#endif
7274
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007275#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007276 /* 'toolbariconsize': GTK+ 2 only */
7277 else if (varp == &p_tbis)
7278 {
7279 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7280 errmsg = e_invarg;
7281 else
7282 {
7283 out_flush();
7284 gui_mch_show_toolbar((toolbar_flags &
7285 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7286 }
7287 }
7288#endif
7289
7290 /* 'pastetoggle': translate key codes like in a mapping */
7291 else if (varp == &p_pt)
7292 {
7293 if (*p_pt)
7294 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007295 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007296 if (p != NULL)
7297 {
7298 if (new_value_alloced)
7299 free_string_option(p_pt);
7300 p_pt = p;
7301 new_value_alloced = TRUE;
7302 }
7303 }
7304 }
7305
7306 /* 'backspace' */
7307 else if (varp == &p_bs)
7308 {
7309 if (VIM_ISDIGIT(*p_bs))
7310 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007311 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007312 errmsg = e_invarg;
7313 }
7314 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7315 errmsg = e_invarg;
7316 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007317 else if (varp == &p_bo)
7318 {
7319 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7320 errmsg = e_invarg;
7321 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007322
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007323 /* 'tagcase' */
7324 else if (gvarp == &p_tc)
7325 {
7326 unsigned int *flags;
7327
7328 if (opt_flags & OPT_LOCAL)
7329 {
7330 p = curbuf->b_p_tc;
7331 flags = &curbuf->b_tc_flags;
7332 }
7333 else
7334 {
7335 p = p_tc;
7336 flags = &tc_flags;
7337 }
7338
7339 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7340 /* make the local value empty: use the global value */
7341 *flags = 0;
7342 else if (*p == NUL
7343 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7344 errmsg = e_invarg;
7345 }
7346
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007347#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007348 /* 'casemap' */
7349 else if (varp == &p_cmp)
7350 {
7351 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7352 errmsg = e_invarg;
7353 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007355
7356#ifdef FEAT_DIFF
7357 /* 'diffopt' */
7358 else if (varp == &p_dip)
7359 {
7360 if (diffopt_changed() == FAIL)
7361 errmsg = e_invarg;
7362 }
7363#endif
7364
7365#ifdef FEAT_FOLDING
7366 /* 'foldmethod' */
7367 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7368 {
7369 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7370 || *curwin->w_p_fdm == NUL)
7371 errmsg = e_invarg;
7372 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007373 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007374 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007375 if (foldmethodIsDiff(curwin))
7376 newFoldLevel();
7377 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007378 }
7379# ifdef FEAT_EVAL
7380 /* 'foldexpr' */
7381 else if (varp == &curwin->w_p_fde)
7382 {
7383 if (foldmethodIsExpr(curwin))
7384 foldUpdateAll(curwin);
7385 }
7386# endif
7387 /* 'foldmarker' */
7388 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7389 {
7390 p = vim_strchr(*varp, ',');
7391 if (p == NULL)
7392 errmsg = (char_u *)N_("E536: comma required");
7393 else if (p == *varp || p[1] == NUL)
7394 errmsg = e_invarg;
7395 else if (foldmethodIsMarker(curwin))
7396 foldUpdateAll(curwin);
7397 }
7398 /* 'commentstring' */
7399 else if (gvarp == &p_cms)
7400 {
7401 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7402 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7403 }
7404 /* 'foldopen' */
7405 else if (varp == &p_fdo)
7406 {
7407 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7408 errmsg = e_invarg;
7409 }
7410 /* 'foldclose' */
7411 else if (varp == &p_fcl)
7412 {
7413 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7414 errmsg = e_invarg;
7415 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007416 /* 'foldignore' */
7417 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7418 {
7419 if (foldmethodIsIndent(curwin))
7420 foldUpdateAll(curwin);
7421 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007422#endif
7423
7424#ifdef FEAT_VIRTUALEDIT
7425 /* 'virtualedit' */
7426 else if (varp == &p_ve)
7427 {
7428 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7429 errmsg = e_invarg;
7430 else if (STRCMP(p_ve, oldval) != 0)
7431 {
7432 /* Recompute cursor position in case the new 've' setting
7433 * changes something. */
7434 validate_virtcol();
7435 coladvance(curwin->w_virtcol);
7436 }
7437 }
7438#endif
7439
7440#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7441 else if (varp == &p_csqf)
7442 {
7443 if (p_csqf != NULL)
7444 {
7445 p = p_csqf;
7446 while (*p != NUL)
7447 {
7448 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7449 || p[1] == NUL
7450 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7451 || (p[2] != NUL && p[2] != ','))
7452 {
7453 errmsg = e_invarg;
7454 break;
7455 }
7456 else if (p[2] == NUL)
7457 break;
7458 else
7459 p += 3;
7460 }
7461 }
7462 }
7463#endif
7464
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007465#ifdef FEAT_CINDENT
7466 /* 'cinoptions' */
7467 else if (gvarp == &p_cino)
7468 {
7469 /* TODO: recognize errors */
7470 parse_cino(curbuf);
7471 }
7472#endif
7473
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007474#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007475 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007476 else if (varp == &p_rop && gui.in_use)
7477 {
7478 if (!gui_mch_set_rendering_options(p_rop))
7479 errmsg = e_invarg;
7480 }
7481#endif
7482
Bram Moolenaard0b51382016-11-04 15:23:45 +01007483#ifdef FEAT_AUTOCMD
7484 else if (gvarp == &p_ft)
7485 {
7486 if (!valid_filetype(*varp))
7487 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007488 else
7489 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007490 }
7491#endif
7492
7493#ifdef FEAT_SYN_HL
7494 else if (gvarp == &p_syn)
7495 {
7496 if (!valid_filetype(*varp))
7497 errmsg = e_invarg;
7498 }
7499#endif
7500
Bram Moolenaar825680f2017-07-22 17:04:02 +02007501#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007502 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007503 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007504 {
7505 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7506 errmsg = e_invarg;
7507 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007508 /* 'termsize' */
7509 else if (varp == &curwin->w_p_tms)
7510 {
7511 if (*curwin->w_p_tms != NUL)
7512 {
7513 p = skipdigits(curwin->w_p_tms);
7514 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7515 errmsg = e_invarg;
7516 }
7517 }
7518#endif
7519
Bram Moolenaar071d4272004-06-13 20:20:40 +00007520 /* Options that are a list of flags. */
7521 else
7522 {
7523 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007524 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007526 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007528 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007529 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007530 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007531 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007532#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007533 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007534 p = (char_u *)COCU_ALL;
7535#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007536 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007537 {
7538#ifdef FEAT_MOUSE
7539 p = (char_u *)MOUSE_ALL;
7540#else
7541 if (*p_mouse != NUL)
7542 errmsg = (char_u *)N_("E538: No mouse support");
7543#endif
7544 }
7545#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007546 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007547 p = (char_u *)GO_ALL;
7548#endif
7549 if (p != NULL)
7550 {
7551 for (s = *varp; *s; ++s)
7552 if (vim_strchr(p, *s) == NULL)
7553 {
7554 errmsg = illegal_char(errbuf, *s);
7555 break;
7556 }
7557 }
7558 }
7559
7560 /*
7561 * If error detected, restore the previous value.
7562 */
7563 if (errmsg != NULL)
7564 {
7565 if (new_value_alloced)
7566 free_string_option(*varp);
7567 *varp = oldval;
7568 /*
7569 * When resetting some values, need to act on it.
7570 */
7571 if (did_chartab)
7572 (void)init_chartab();
7573 if (varp == &p_hl)
7574 (void)highlight_changed();
7575 }
7576 else
7577 {
7578#ifdef FEAT_EVAL
7579 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007580 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007581#endif
7582 /*
7583 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007584 * Use "free_oldval", because recursiveness may change the flags under
7585 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007586 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007587 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007588 free_string_option(oldval);
7589 if (new_value_alloced)
7590 options[opt_idx].flags |= P_ALLOCED;
7591 else
7592 options[opt_idx].flags &= ~P_ALLOCED;
7593
7594 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007595 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007596 {
7597 /* global option with local value set to use global value; free
7598 * the local value and make it empty */
7599 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7600 free_string_option(*(char_u **)p);
7601 *(char_u **)p = empty_option;
7602 }
7603
7604 /* May set global value for local option. */
7605 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7606 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007607
7608#ifdef FEAT_AUTOCMD
7609 /*
7610 * Trigger the autocommand only after setting the flags.
7611 */
7612# ifdef FEAT_SYN_HL
7613 /* When 'syntax' is set, load the syntax of that name */
7614 if (varp == &(curbuf->b_p_syn))
7615 {
7616 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7617 curbuf->b_fname, TRUE, curbuf);
7618 }
7619# endif
7620 else if (varp == &(curbuf->b_p_ft))
7621 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007622 /* 'filetype' is set, trigger the FileType autocommand.
7623 * Skip this when called from a modeline and the filetype was
7624 * already set to this value. */
7625 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7626 {
7627 did_filetype = TRUE;
7628 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007629 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007630 /* Just in case the old "curbuf" is now invalid. */
7631 if (varp != &(curbuf->b_p_ft))
7632 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007633 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007634 }
7635#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007636#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007637 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007638 {
7639 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007640 char_u *q = curwin->w_s->b_p_spl;
7641
7642 /* Skip the first name if it is "cjk". */
7643 if (STRNCMP(q, "cjk,", 4) == 0)
7644 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007645
7646 /*
7647 * Source the spell/LANG.vim in 'runtimepath'.
7648 * They could set 'spellcapcheck' depending on the language.
7649 * Use the first name in 'spelllang' up to '_region' or
7650 * '.encoding'.
7651 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007652 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007653 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7654 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007655 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007656 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007657 }
7658#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 }
7660
7661#ifdef FEAT_MOUSE
7662 if (varp == &p_mouse)
7663 {
7664# ifdef FEAT_MOUSE_TTY
7665 if (*p_mouse == NUL)
7666 mch_setmouse(FALSE); /* switch mouse off */
7667 else
7668# endif
7669 setmouse(); /* in case 'mouse' changed */
7670 }
7671#endif
7672
Bram Moolenaar913077c2012-03-28 19:59:04 +02007673 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007674 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007675 curwin->w_set_curswant = TRUE;
7676
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007677#ifdef FEAT_GUI
7678 /* check redraw when it's not a GUI option or the GUI is active. */
7679 if (!redraw_gui_only || gui.in_use)
7680#endif
7681 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007682
7683 return errmsg;
7684}
7685
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007686#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007687/*
7688 * Simple int comparison function for use with qsort()
7689 */
7690 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007691int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007692{
7693 return *(const int *)a - *(const int *)b;
7694}
7695
7696/*
7697 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7698 * Returns error message, NULL if it's OK.
7699 */
7700 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007701check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007702{
7703 char_u *s;
7704 int col;
7705 int count = 0;
7706 int color_cols[256];
7707 int i;
7708 int j = 0;
7709
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007710 if (wp->w_buffer == NULL)
7711 return NULL; /* buffer was closed */
7712
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007713 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007714 {
7715 if (*s == '-' || *s == '+')
7716 {
7717 /* -N and +N: add to 'textwidth' */
7718 col = (*s == '-') ? -1 : 1;
7719 ++s;
7720 if (!VIM_ISDIGIT(*s))
7721 return e_invarg;
7722 col = col * getdigits(&s);
7723 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007724 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007725 col += wp->w_buffer->b_p_tw;
7726 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007727 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007728 }
7729 else if (VIM_ISDIGIT(*s))
7730 col = getdigits(&s);
7731 else
7732 return e_invarg;
7733 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007734skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007735 if (*s == NUL)
7736 break;
7737 if (*s != ',')
7738 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007739 if (*++s == NUL)
7740 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007741 }
7742
7743 vim_free(wp->w_p_cc_cols);
7744 if (count == 0)
7745 wp->w_p_cc_cols = NULL;
7746 else
7747 {
7748 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7749 if (wp->w_p_cc_cols != NULL)
7750 {
7751 /* sort the columns for faster usage on screen redraw inside
7752 * win_line() */
7753 qsort(color_cols, count, sizeof(int), int_cmp);
7754
7755 for (i = 0; i < count; ++i)
7756 /* skip duplicates */
7757 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7758 wp->w_p_cc_cols[j++] = color_cols[i];
7759 wp->w_p_cc_cols[j] = -1; /* end marker */
7760 }
7761 }
7762
7763 return NULL; /* no error */
7764}
7765#endif
7766
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767/*
7768 * Handle setting 'listchars' or 'fillchars'.
7769 * Returns error message, NULL if it's OK.
7770 */
7771 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007772set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007773{
7774 int round, i, len, entries;
7775 char_u *p, *s;
7776 int c1, c2 = 0;
7777 struct charstab
7778 {
7779 int *cp;
7780 char *name;
7781 };
7782#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7783 static struct charstab filltab[] =
7784 {
7785 {&fill_stl, "stl"},
7786 {&fill_stlnc, "stlnc"},
7787 {&fill_vert, "vert"},
7788 {&fill_fold, "fold"},
7789 {&fill_diff, "diff"},
7790 };
7791#endif
7792 static struct charstab lcstab[] =
7793 {
7794 {&lcs_eol, "eol"},
7795 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007796 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007797 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007798 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799 {&lcs_tab2, "tab"},
7800 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007801#ifdef FEAT_CONCEAL
7802 {&lcs_conceal, "conceal"},
7803#else
7804 {NULL, "conceal"},
7805#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007806 };
7807 struct charstab *tab;
7808
7809#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7810 if (varp == &p_lcs)
7811#endif
7812 {
7813 tab = lcstab;
7814 entries = sizeof(lcstab) / sizeof(struct charstab);
7815 }
7816#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7817 else
7818 {
7819 tab = filltab;
7820 entries = sizeof(filltab) / sizeof(struct charstab);
7821 }
7822#endif
7823
7824 /* first round: check for valid value, second round: assign values */
7825 for (round = 0; round <= 1; ++round)
7826 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007827 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007828 {
7829 /* After checking that the value is valid: set defaults: space for
7830 * 'fillchars', NUL for 'listchars' */
7831 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007832 if (tab[i].cp != NULL)
7833 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007834 if (varp == &p_lcs)
7835 lcs_tab1 = NUL;
7836#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7837 else
7838 fill_diff = '-';
7839#endif
7840 }
7841 p = *varp;
7842 while (*p)
7843 {
7844 for (i = 0; i < entries; ++i)
7845 {
7846 len = (int)STRLEN(tab[i].name);
7847 if (STRNCMP(p, tab[i].name, len) == 0
7848 && p[len] == ':'
7849 && p[len + 1] != NUL)
7850 {
7851 s = p + len + 1;
7852#ifdef FEAT_MBYTE
7853 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007854 if (mb_char2cells(c1) > 1)
7855 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007856#else
7857 c1 = *s++;
7858#endif
7859 if (tab[i].cp == &lcs_tab2)
7860 {
7861 if (*s == NUL)
7862 continue;
7863#ifdef FEAT_MBYTE
7864 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007865 if (mb_char2cells(c2) > 1)
7866 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007867#else
7868 c2 = *s++;
7869#endif
7870 }
7871 if (*s == ',' || *s == NUL)
7872 {
7873 if (round)
7874 {
7875 if (tab[i].cp == &lcs_tab2)
7876 {
7877 lcs_tab1 = c1;
7878 lcs_tab2 = c2;
7879 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007880 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007881 *(tab[i].cp) = c1;
7882
7883 }
7884 p = s;
7885 break;
7886 }
7887 }
7888 }
7889
7890 if (i == entries)
7891 return e_invarg;
7892 if (*p == ',')
7893 ++p;
7894 }
7895 }
7896
7897 return NULL; /* no error */
7898}
7899
7900#ifdef FEAT_STL_OPT
7901/*
7902 * Check validity of options with the 'statusline' format.
7903 * Return error message or NULL.
7904 */
7905 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007906check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907{
7908 int itemcnt = 0;
7909 int groupdepth = 0;
7910 static char_u errbuf[80];
7911
7912 while (*s && itemcnt < STL_MAX_ITEM)
7913 {
7914 /* Check for valid keys after % sequences */
7915 while (*s && *s != '%')
7916 s++;
7917 if (!*s)
7918 break;
7919 s++;
7920 if (*s != '%' && *s != ')')
7921 ++itemcnt;
7922 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7923 {
7924 s++;
7925 continue;
7926 }
7927 if (*s == ')')
7928 {
7929 s++;
7930 if (--groupdepth < 0)
7931 break;
7932 continue;
7933 }
7934 if (*s == '-')
7935 s++;
7936 while (VIM_ISDIGIT(*s))
7937 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007938 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939 continue;
7940 if (*s == '.')
7941 {
7942 s++;
7943 while (*s && VIM_ISDIGIT(*s))
7944 s++;
7945 }
7946 if (*s == '(')
7947 {
7948 groupdepth++;
7949 continue;
7950 }
7951 if (vim_strchr(STL_ALL, *s) == NULL)
7952 {
7953 return illegal_char(errbuf, *s);
7954 }
7955 if (*s == '{')
7956 {
7957 s++;
7958 while (*s != '}' && *s)
7959 s++;
7960 if (*s != '}')
7961 return (char_u *)N_("E540: Unclosed expression sequence");
7962 }
7963 }
7964 if (itemcnt >= STL_MAX_ITEM)
7965 return (char_u *)N_("E541: too many items");
7966 if (groupdepth != 0)
7967 return (char_u *)N_("E542: unbalanced groups");
7968 return NULL;
7969}
7970#endif
7971
7972#ifdef FEAT_CLIPBOARD
7973/*
7974 * Extract the items in the 'clipboard' option and set global values.
7975 */
7976 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007977check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007979 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007980 int new_autoselect_star = FALSE;
7981 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007982 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007983 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007984 regprog_T *new_exclude_prog = NULL;
7985 char_u *errmsg = NULL;
7986 char_u *p;
7987
7988 for (p = p_cb; *p != NUL; )
7989 {
7990 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7991 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007992 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007993 p += 7;
7994 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007995 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007996 && (p[11] == ',' || p[11] == NUL))
7997 {
7998 new_unnamed |= CLIP_UNNAMED_PLUS;
7999 p += 11;
8000 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008002 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008004 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008005 p += 10;
8006 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008007 else if (STRNCMP(p, "autoselectplus", 14) == 0
8008 && (p[14] == ',' || p[14] == NUL))
8009 {
8010 new_autoselect_plus = TRUE;
8011 p += 14;
8012 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008014 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008015 {
8016 new_autoselectml = TRUE;
8017 p += 12;
8018 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008019 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8020 {
8021 new_html = TRUE;
8022 p += 4;
8023 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008024 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8025 {
8026 p += 8;
8027 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8028 if (new_exclude_prog == NULL)
8029 errmsg = e_invarg;
8030 break;
8031 }
8032 else
8033 {
8034 errmsg = e_invarg;
8035 break;
8036 }
8037 if (*p == ',')
8038 ++p;
8039 }
8040 if (errmsg == NULL)
8041 {
8042 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008043 clip_autoselect_star = new_autoselect_star;
8044 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008046 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008047 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008048 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008049#ifdef FEAT_GUI_GTK
8050 if (gui.in_use)
8051 {
8052 gui_gtk_set_selection_targets();
8053 gui_gtk_set_dnd_targets();
8054 }
8055#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 }
8057 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008058 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008059
8060 return errmsg;
8061}
8062#endif
8063
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008064#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008065 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008066did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008067{
8068 char_u *errmsg = NULL;
8069 win_T *wp;
8070 int l;
8071
8072 if (is_spellfile)
8073 {
8074 l = (int)STRLEN(curwin->w_s->b_p_spf);
8075 if (l > 0 && (l < 4
8076 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8077 errmsg = e_invarg;
8078 }
8079
8080 if (errmsg == NULL)
8081 {
8082 FOR_ALL_WINDOWS(wp)
8083 if (wp->w_buffer == curbuf && wp->w_p_spell)
8084 {
8085 errmsg = did_set_spelllang(wp);
8086# ifdef FEAT_WINDOWS
8087 break;
8088# endif
8089 }
8090 }
8091 return errmsg;
8092}
8093
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008094/*
8095 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8096 * Return error message when failed, NULL when OK.
8097 */
8098 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008099compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008100{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008101 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008102 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008103
Bram Moolenaar860cae12010-06-05 23:22:07 +02008104 if (*synblock->b_p_spc == NUL)
8105 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008106 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008107 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008108 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008109 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008110 if (re != NULL)
8111 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008112 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008113 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008114 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008115 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008116 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008117 return e_invarg;
8118 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008119 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008120 }
8121
Bram Moolenaar473de612013-06-08 18:19:48 +02008122 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008123 return NULL;
8124}
8125#endif
8126
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008127#if defined(FEAT_EVAL) || defined(PROTO)
8128/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008129 * Set the scriptID for an option, taking care of setting the buffer- or
8130 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008131 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008132 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008133set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008134{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008135 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8136 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008137
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008138 /* Remember where the option was set. For local options need to do that
8139 * in the buffer or window structure. */
8140 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008141 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008142 if (both || (opt_flags & OPT_LOCAL))
8143 {
8144 if (indir & PV_BUF)
8145 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8146 else if (indir & PV_WIN)
8147 curwin->w_p_scriptID[indir & PV_MASK] = id;
8148 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008149}
8150#endif
8151
Bram Moolenaar071d4272004-06-13 20:20:40 +00008152/*
8153 * Set the value of a boolean option, and take care of side effects.
8154 * Returns NULL for success, or an error message for an error.
8155 */
8156 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008157set_bool_option(
8158 int opt_idx, /* index in options[] table */
8159 char_u *varp, /* pointer to the option variable */
8160 int value, /* new value */
8161 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008162{
8163 int old_value = *(int *)varp;
8164
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 /* Disallow changing some options from secure mode */
8166 if ((secure
8167#ifdef HAVE_SANDBOX
8168 || sandbox != 0
8169#endif
8170 ) && (options[opt_idx].flags & P_SECURE))
8171 return e_secure;
8172
8173 *(int *)varp = value; /* set the new value */
8174#ifdef FEAT_EVAL
8175 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008176 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008177#endif
8178
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008179#ifdef FEAT_GUI
8180 need_mouse_correct = TRUE;
8181#endif
8182
Bram Moolenaar071d4272004-06-13 20:20:40 +00008183 /* May set global value for local option. */
8184 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8185 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8186
8187 /*
8188 * Handle side effects of changing a bool option.
8189 */
8190
8191 /* 'compatible' */
8192 if ((int *)varp == &p_cp)
8193 {
8194 compatible_set();
8195 }
8196
Bram Moolenaar920694c2016-08-21 17:45:02 +02008197#ifdef FEAT_LANGMAP
8198 if ((int *)varp == &p_lrm)
8199 /* 'langremap' -> !'langnoremap' */
8200 p_lnr = !p_lrm;
8201 else if ((int *)varp == &p_lnr)
8202 /* 'langnoremap' -> !'langremap' */
8203 p_lrm = !p_lnr;
8204#endif
8205
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008206#ifdef FEAT_PERSISTENT_UNDO
8207 /* 'undofile' */
8208 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8209 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008210 /* Only take action when the option was set. When reset we do not
8211 * delete the undo file, the option may be set again without making
8212 * any changes in between. */
8213 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008214 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008215 char_u hash[UNDO_HASH_SIZE];
8216 buf_T *save_curbuf = curbuf;
8217
Bram Moolenaar29323592016-07-24 22:04:11 +02008218 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008219 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008220 /* When 'undofile' is set globally: for every buffer, otherwise
8221 * only for the current buffer: Try to read in the undofile,
8222 * if one exists, the buffer wasn't changed and the buffer was
8223 * loaded */
8224 if ((curbuf == save_curbuf
8225 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8226 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8227 {
8228 u_compute_hash(hash);
8229 u_read_undo(NULL, hash, curbuf->b_fname);
8230 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008231 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008232 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008233 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008234 }
8235#endif
8236
Bram Moolenaar071d4272004-06-13 20:20:40 +00008237 else if ((int *)varp == &curbuf->b_p_ro)
8238 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008239 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008240 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8241 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008242
8243 /* when 'readonly' is set may give W10 again */
8244 if (curbuf->b_p_ro)
8245 curbuf->b_did_warn = FALSE;
8246
Bram Moolenaar071d4272004-06-13 20:20:40 +00008247#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008248 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008249#endif
8250 }
8251
Bram Moolenaar9c449722010-07-20 18:44:27 +02008252#ifdef FEAT_GUI
8253 else if ((int *)varp == &p_mh)
8254 {
8255 if (!p_mh)
8256 gui_mch_mousehide(FALSE);
8257 }
8258#endif
8259
Bram Moolenaara539df02010-08-01 14:35:05 +02008260 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008262 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008263# ifdef FEAT_TERMINAL
8264 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008265 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008266 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008267 {
8268 curbuf->b_p_ma = FALSE;
8269 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8270 }
8271# endif
8272# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008273 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008274# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008275 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008276#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008277 /* when 'endofline' is changed, redraw the window title */
8278 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008279 {
8280 redraw_titles();
8281 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008282 /* when 'fixeol' is changed, redraw the window title */
8283 else if ((int *)varp == &curbuf->b_p_fixeol)
8284 {
8285 redraw_titles();
8286 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008287# ifdef FEAT_MBYTE
8288 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008289 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008290 {
8291 redraw_titles();
8292 }
8293# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008294#endif
8295
8296 /* when 'bin' is set also set some other options */
8297 else if ((int *)varp == &curbuf->b_p_bin)
8298 {
8299 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8300#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008301 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008302#endif
8303 }
8304
8305#ifdef FEAT_AUTOCMD
8306 /* when 'buflisted' changes, trigger autocommands */
8307 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8308 {
8309 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8310 NULL, NULL, TRUE, curbuf);
8311 }
8312#endif
8313
8314 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8315 else if ((int *)varp == &curbuf->b_p_swf)
8316 {
8317 if (curbuf->b_p_swf && p_uc)
8318 ml_open_file(curbuf); /* create the swap file */
8319 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008320 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8321 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008322 mf_close_file(curbuf, TRUE); /* remove the swap file */
8323 }
8324
8325 /* when 'terse' is set change 'shortmess' */
8326 else if ((int *)varp == &p_terse)
8327 {
8328 char_u *p;
8329
8330 p = vim_strchr(p_shm, SHM_SEARCH);
8331
8332 /* insert 's' in p_shm */
8333 if (p_terse && p == NULL)
8334 {
8335 STRCPY(IObuff, p_shm);
8336 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008337 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008338 }
8339 /* remove 's' from p_shm */
8340 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008341 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008342 }
8343
8344 /* when 'paste' is set or reset also change other options */
8345 else if ((int *)varp == &p_paste)
8346 {
8347 paste_option_changed();
8348 }
8349
8350 /* when 'insertmode' is set from an autocommand need to do work here */
8351 else if ((int *)varp == &p_im)
8352 {
8353 if (p_im)
8354 {
8355 if ((State & INSERT) == 0)
8356 need_start_insertmode = TRUE;
8357 stop_insert_mode = FALSE;
8358 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008359 /* only reset if it was set previously */
8360 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008361 {
8362 need_start_insertmode = FALSE;
8363 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008364 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008365 clear_cmdline = TRUE; /* remove "(insert)" */
8366 restart_edit = 0;
8367 }
8368 }
8369
8370 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8371 else if ((int *)varp == &p_ic && p_hls)
8372 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008373 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008374 }
8375
8376#ifdef FEAT_SEARCH_EXTRA
8377 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8378 else if ((int *)varp == &p_hls)
8379 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008380 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008381 }
8382#endif
8383
8384#ifdef FEAT_SCROLLBIND
8385 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8386 * at the end of normal_cmd() */
8387 else if ((int *)varp == &curwin->w_p_scb)
8388 {
8389 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008390 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008391 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008392 curwin->w_scbind_pos = curwin->w_topline;
8393 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008394 }
8395#endif
8396
8397#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8398 /* There can be only one window with 'previewwindow' set. */
8399 else if ((int *)varp == &curwin->w_p_pvw)
8400 {
8401 if (curwin->w_p_pvw)
8402 {
8403 win_T *win;
8404
Bram Moolenaar29323592016-07-24 22:04:11 +02008405 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406 if (win->w_p_pvw && win != curwin)
8407 {
8408 curwin->w_p_pvw = FALSE;
8409 return (char_u *)N_("E590: A preview window already exists");
8410 }
8411 }
8412 }
8413#endif
8414
8415 /* when 'textmode' is set or reset also change 'fileformat' */
8416 else if ((int *)varp == &curbuf->b_p_tx)
8417 {
8418 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8419 }
8420
8421 /* when 'textauto' is set or reset also change 'fileformats' */
8422 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423 set_string_option_direct((char_u *)"ffs", -1,
8424 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008425 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008426
8427 /*
8428 * When 'lisp' option changes include/exclude '-' in
8429 * keyword characters.
8430 */
8431#ifdef FEAT_LISP
8432 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8433 {
8434 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8435 }
8436#endif
8437
8438#ifdef FEAT_TITLE
8439 /* when 'title' changed, may need to change the title; same for 'icon' */
8440 else if ((int *)varp == &p_title)
8441 {
8442 did_set_title(FALSE);
8443 }
8444
8445 else if ((int *)varp == &p_icon)
8446 {
8447 did_set_title(TRUE);
8448 }
8449#endif
8450
8451 else if ((int *)varp == &curbuf->b_changed)
8452 {
8453 if (!value)
8454 save_file_ff(curbuf); /* Buffer is unchanged */
8455#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008456 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457#endif
8458#ifdef FEAT_AUTOCMD
8459 modified_was_set = value;
8460#endif
8461 }
8462
8463#ifdef BACKSLASH_IN_FILENAME
8464 else if ((int *)varp == &p_ssl)
8465 {
8466 if (p_ssl)
8467 {
8468 psepc = '/';
8469 psepcN = '\\';
8470 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471 }
8472 else
8473 {
8474 psepc = '\\';
8475 psepcN = '/';
8476 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477 }
8478
8479 /* need to adjust the file name arguments and buffer names. */
8480 buflist_slash_adjust();
8481 alist_slash_adjust();
8482# ifdef FEAT_EVAL
8483 scriptnames_slash_adjust();
8484# endif
8485 }
8486#endif
8487
8488 /* If 'wrap' is set, set w_leftcol to zero. */
8489 else if ((int *)varp == &curwin->w_p_wrap)
8490 {
8491 if (curwin->w_p_wrap)
8492 curwin->w_leftcol = 0;
8493 }
8494
8495#ifdef FEAT_WINDOWS
8496 else if ((int *)varp == &p_ea)
8497 {
8498 if (p_ea && !old_value)
8499 win_equal(curwin, FALSE, 0);
8500 }
8501#endif
8502
8503 else if ((int *)varp == &p_wiv)
8504 {
8505 /*
8506 * When 'weirdinvert' changed, set/reset 't_xs'.
8507 * Then set 'weirdinvert' according to value of 't_xs'.
8508 */
8509 if (p_wiv && !old_value)
8510 T_XS = (char_u *)"y";
8511 else if (!p_wiv && old_value)
8512 T_XS = empty_option;
8513 p_wiv = (*T_XS != NUL);
8514 }
8515
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008516#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008517 else if ((int *)varp == &p_beval)
8518 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008519 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008521 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008522 gui_mch_disable_beval_area(balloonEval);
8523 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008524#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008525
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008526#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008527 else if ((int *)varp == &p_acd)
8528 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008529 /* Change directories when the 'acd' option is set now. */
8530 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008531 }
8532#endif
8533
8534#ifdef FEAT_DIFF
8535 /* 'diff' */
8536 else if ((int *)varp == &curwin->w_p_diff)
8537 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008538 /* May add or remove the buffer from the list of diff buffers. */
8539 diff_buf_adjust(curwin);
8540# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008541 if (foldmethodIsDiff(curwin))
8542 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008543# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008544 }
8545#endif
8546
8547#ifdef USE_IM_CONTROL
8548 /* 'imdisable' */
8549 else if ((int *)varp == &p_imdisable)
8550 {
8551 /* Only de-activate it here, it will be enabled when changing mode. */
8552 if (p_imdisable)
8553 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008554 else if (State & INSERT)
8555 /* When the option is set from an autocommand, it may need to take
8556 * effect right away. */
8557 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008558 }
8559#endif
8560
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008561#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008562 /* 'spell' */
8563 else if ((int *)varp == &curwin->w_p_spell)
8564 {
8565 if (curwin->w_p_spell)
8566 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008567 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008568 if (errmsg != NULL)
8569 EMSG(_(errmsg));
8570 }
8571 }
8572#endif
8573
Bram Moolenaar071d4272004-06-13 20:20:40 +00008574#ifdef FEAT_FKMAP
8575 else if ((int *)varp == &p_altkeymap)
8576 {
8577 if (old_value != p_altkeymap)
8578 {
8579 if (!p_altkeymap)
8580 {
8581 p_hkmap = p_fkmap;
8582 p_fkmap = 0;
8583 }
8584 else
8585 {
8586 p_fkmap = p_hkmap;
8587 p_hkmap = 0;
8588 }
8589 (void)init_chartab();
8590 }
8591 }
8592
8593 /*
8594 * In case some second language keymapping options have changed, check
8595 * and correct the setting in a consistent way.
8596 */
8597
8598 /*
8599 * If hkmap or fkmap are set, reset Arabic keymapping.
8600 */
8601 if ((p_hkmap || p_fkmap) && p_altkeymap)
8602 {
8603 p_altkeymap = p_fkmap;
8604# ifdef FEAT_ARABIC
8605 curwin->w_p_arab = FALSE;
8606# endif
8607 (void)init_chartab();
8608 }
8609
8610 /*
8611 * If hkmap set, reset Farsi keymapping.
8612 */
8613 if (p_hkmap && p_altkeymap)
8614 {
8615 p_altkeymap = 0;
8616 p_fkmap = 0;
8617# ifdef FEAT_ARABIC
8618 curwin->w_p_arab = FALSE;
8619# endif
8620 (void)init_chartab();
8621 }
8622
8623 /*
8624 * If fkmap set, reset Hebrew keymapping.
8625 */
8626 if (p_fkmap && !p_altkeymap)
8627 {
8628 p_altkeymap = 1;
8629 p_hkmap = 0;
8630# ifdef FEAT_ARABIC
8631 curwin->w_p_arab = FALSE;
8632# endif
8633 (void)init_chartab();
8634 }
8635#endif
8636
8637#ifdef FEAT_ARABIC
8638 if ((int *)varp == &curwin->w_p_arab)
8639 {
8640 if (curwin->w_p_arab)
8641 {
8642 /*
8643 * 'arabic' is set, handle various sub-settings.
8644 */
8645 if (!p_tbidi)
8646 {
8647 /* set rightleft mode */
8648 if (!curwin->w_p_rl)
8649 {
8650 curwin->w_p_rl = TRUE;
8651 changed_window_setting();
8652 }
8653
8654 /* Enable Arabic shaping (major part of what Arabic requires) */
8655 if (!p_arshape)
8656 {
8657 p_arshape = TRUE;
8658 redraw_later_clear();
8659 }
8660 }
8661
8662 /* Arabic requires a utf-8 encoding, inform the user if its not
8663 * set. */
8664 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008665 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008666 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8667
Bram Moolenaar8820b482017-03-16 17:23:31 +01008668 msg_source(HL_ATTR(HLF_W));
8669 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008670#ifdef FEAT_EVAL
8671 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8672#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008674
8675# ifdef FEAT_MBYTE
8676 /* set 'delcombine' */
8677 p_deco = TRUE;
8678# endif
8679
8680# ifdef FEAT_KEYMAP
8681 /* Force-set the necessary keymap for arabic */
8682 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8683 OPT_LOCAL);
8684# endif
8685# ifdef FEAT_FKMAP
8686 p_altkeymap = 0;
8687 p_hkmap = 0;
8688 p_fkmap = 0;
8689 (void)init_chartab();
8690# endif
8691 }
8692 else
8693 {
8694 /*
8695 * 'arabic' is reset, handle various sub-settings.
8696 */
8697 if (!p_tbidi)
8698 {
8699 /* reset rightleft mode */
8700 if (curwin->w_p_rl)
8701 {
8702 curwin->w_p_rl = FALSE;
8703 changed_window_setting();
8704 }
8705
8706 /* 'arabicshape' isn't reset, it is a global option and
8707 * another window may still need it "on". */
8708 }
8709
8710 /* 'delcombine' isn't reset, it is a global option and another
8711 * window may still want it "on". */
8712
8713# ifdef FEAT_KEYMAP
8714 /* Revert to the default keymap */
8715 curbuf->b_p_iminsert = B_IMODE_NONE;
8716 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8717# endif
8718 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008719 }
8720
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008721#endif
8722
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008723#ifdef FEAT_TERMGUICOLORS
8724 /* 'termguicolors' */
8725 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008726 {
8727# ifdef FEAT_GUI
8728 if (!gui.in_use && !gui.starting)
8729# endif
8730 highlight_gui_started();
8731 }
8732#endif
8733
Bram Moolenaar071d4272004-06-13 20:20:40 +00008734 /*
8735 * End of handling side effects for bool options.
8736 */
8737
Bram Moolenaar53744302015-07-17 17:38:22 +02008738 /* after handling side effects, call autocommand */
8739
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740 options[opt_idx].flags |= P_WAS_SET;
8741
Bram Moolenaar53744302015-07-17 17:38:22 +02008742#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8743 if (!starting)
8744 {
8745 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008746 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8747 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8748 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008749 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8750 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8751 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8752 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8753 reset_v_option_vars();
8754 }
8755#endif
8756
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008758 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008759 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008760 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008761 check_redraw(options[opt_idx].flags);
8762
8763 return NULL;
8764}
8765
8766/*
8767 * Set the value of a number option, and take care of side effects.
8768 * Returns NULL for success, or an error message for an error.
8769 */
8770 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008771set_num_option(
8772 int opt_idx, /* index in options[] table */
8773 char_u *varp, /* pointer to the option variable */
8774 long value, /* new value */
8775 char_u *errbuf, /* buffer for error messages */
8776 size_t errbuflen, /* length of "errbuf" */
8777 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778 OPT_MODELINE */
8779{
8780 char_u *errmsg = NULL;
8781 long old_value = *(long *)varp;
8782 long old_Rows = Rows; /* remember old Rows */
8783 long old_Columns = Columns; /* remember old Columns */
8784 long *pp = (long *)varp;
8785
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008786 /* Disallow changing some options from secure mode. */
8787 if ((secure
8788#ifdef HAVE_SANDBOX
8789 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008790#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008791 ) && (options[opt_idx].flags & P_SECURE))
8792 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008793
8794 *pp = value;
8795#ifdef FEAT_EVAL
8796 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008797 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008799#ifdef FEAT_GUI
8800 need_mouse_correct = TRUE;
8801#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802
Bram Moolenaar14f24742012-08-08 18:01:05 +02008803 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 {
8805 errmsg = e_positive;
8806 curbuf->b_p_sw = curbuf->b_p_ts;
8807 }
8808
8809 /*
8810 * Number options that need some action when changed
8811 */
8812#ifdef FEAT_WINDOWS
8813 if (pp == &p_wh || pp == &p_hh)
8814 {
8815 if (p_wh < 1)
8816 {
8817 errmsg = e_positive;
8818 p_wh = 1;
8819 }
8820 if (p_wmh > p_wh)
8821 {
8822 errmsg = e_winheight;
8823 p_wh = p_wmh;
8824 }
8825 if (p_hh < 0)
8826 {
8827 errmsg = e_positive;
8828 p_hh = 0;
8829 }
8830
8831 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008832 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833 {
8834 if (pp == &p_wh && curwin->w_height < p_wh)
8835 win_setheight((int)p_wh);
8836 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8837 win_setheight((int)p_hh);
8838 }
8839 }
8840
8841 /* 'winminheight' */
8842 else if (pp == &p_wmh)
8843 {
8844 if (p_wmh < 0)
8845 {
8846 errmsg = e_positive;
8847 p_wmh = 0;
8848 }
8849 if (p_wmh > p_wh)
8850 {
8851 errmsg = e_winheight;
8852 p_wmh = p_wh;
8853 }
8854 win_setminheight();
8855 }
8856
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008857# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008858 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008859 {
8860 if (p_wiw < 1)
8861 {
8862 errmsg = e_positive;
8863 p_wiw = 1;
8864 }
8865 if (p_wmw > p_wiw)
8866 {
8867 errmsg = e_winwidth;
8868 p_wiw = p_wmw;
8869 }
8870
8871 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008872 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008873 win_setwidth((int)p_wiw);
8874 }
8875
8876 /* 'winminwidth' */
8877 else if (pp == &p_wmw)
8878 {
8879 if (p_wmw < 0)
8880 {
8881 errmsg = e_positive;
8882 p_wmw = 0;
8883 }
8884 if (p_wmw > p_wiw)
8885 {
8886 errmsg = e_winwidth;
8887 p_wmw = p_wiw;
8888 }
8889 win_setminheight();
8890 }
8891# endif
8892
8893#endif
8894
8895#ifdef FEAT_WINDOWS
8896 /* (re)set last window status line */
8897 else if (pp == &p_ls)
8898 {
8899 last_status(FALSE);
8900 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008901
8902 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008903 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008904 {
8905 shell_new_rows(); /* recompute window positions and heights */
8906 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907#endif
8908
8909#ifdef FEAT_GUI
8910 else if (pp == &p_linespace)
8911 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008912 /* Recompute gui.char_height and resize the Vim window to keep the
8913 * same number of lines. */
8914 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008915 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008916 }
8917#endif
8918
8919#ifdef FEAT_FOLDING
8920 /* 'foldlevel' */
8921 else if (pp == &curwin->w_p_fdl)
8922 {
8923 if (curwin->w_p_fdl < 0)
8924 curwin->w_p_fdl = 0;
8925 newFoldLevel();
8926 }
8927
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008928 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929 else if (pp == &curwin->w_p_fml)
8930 {
8931 foldUpdateAll(curwin);
8932 }
8933
8934 /* 'foldnestmax' */
8935 else if (pp == &curwin->w_p_fdn)
8936 {
8937 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8938 foldUpdateAll(curwin);
8939 }
8940
8941 /* 'foldcolumn' */
8942 else if (pp == &curwin->w_p_fdc)
8943 {
8944 if (curwin->w_p_fdc < 0)
8945 {
8946 errmsg = e_positive;
8947 curwin->w_p_fdc = 0;
8948 }
8949 else if (curwin->w_p_fdc > 12)
8950 {
8951 errmsg = e_invarg;
8952 curwin->w_p_fdc = 12;
8953 }
8954 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008955#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008957#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008958 /* 'shiftwidth' or 'tabstop' */
8959 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8960 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008961# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008962 if (foldmethodIsIndent(curwin))
8963 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008964# endif
8965# ifdef FEAT_CINDENT
8966 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8967 * parse 'cinoptions'. */
8968 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8969 parse_cino(curbuf);
8970# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008971 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008972#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008974#ifdef FEAT_MBYTE
8975 /* 'maxcombine' */
8976 else if (pp == &p_mco)
8977 {
8978 if (p_mco > MAX_MCO)
8979 p_mco = MAX_MCO;
8980 else if (p_mco < 0)
8981 p_mco = 0;
8982 screenclear(); /* will re-allocate the screen */
8983 }
8984#endif
8985
Bram Moolenaar071d4272004-06-13 20:20:40 +00008986 else if (pp == &curbuf->b_p_iminsert)
8987 {
8988 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8989 {
8990 errmsg = e_invarg;
8991 curbuf->b_p_iminsert = B_IMODE_NONE;
8992 }
8993 p_iminsert = curbuf->b_p_iminsert;
8994 if (termcap_active) /* don't do this in the alternate screen */
8995 showmode();
8996#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8997 /* Show/unshow value of 'keymap' in status lines. */
8998 status_redraw_curbuf();
8999#endif
9000 }
9001
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009002#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9003 /* 'imstyle' */
9004 else if (pp == &p_imst)
9005 {
9006 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9007 errmsg = e_invarg;
9008 }
9009#endif
9010
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009011 else if (pp == &p_window)
9012 {
9013 if (p_window < 1)
9014 p_window = 1;
9015 else if (p_window >= Rows)
9016 p_window = Rows - 1;
9017 }
9018
Bram Moolenaar071d4272004-06-13 20:20:40 +00009019 else if (pp == &curbuf->b_p_imsearch)
9020 {
9021 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9022 {
9023 errmsg = e_invarg;
9024 curbuf->b_p_imsearch = B_IMODE_NONE;
9025 }
9026 p_imsearch = curbuf->b_p_imsearch;
9027 }
9028
9029#ifdef FEAT_TITLE
9030 /* if 'titlelen' has changed, redraw the title */
9031 else if (pp == &p_titlelen)
9032 {
9033 if (p_titlelen < 0)
9034 {
9035 errmsg = e_positive;
9036 p_titlelen = 85;
9037 }
9038 if (starting != NO_SCREEN && old_value != p_titlelen)
9039 need_maketitle = TRUE;
9040 }
9041#endif
9042
9043 /* if p_ch changed value, change the command line height */
9044 else if (pp == &p_ch)
9045 {
9046 if (p_ch < 1)
9047 {
9048 errmsg = e_positive;
9049 p_ch = 1;
9050 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009051 if (p_ch > Rows - min_rows() + 1)
9052 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009053
9054 /* Only compute the new window layout when startup has been
9055 * completed. Otherwise the frame sizes may be wrong. */
9056 if (p_ch != old_value && full_screen
9057#ifdef FEAT_GUI
9058 && !gui.starting
9059#endif
9060 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009061 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009062 }
9063
9064 /* when 'updatecount' changes from zero to non-zero, open swap files */
9065 else if (pp == &p_uc)
9066 {
9067 if (p_uc < 0)
9068 {
9069 errmsg = e_positive;
9070 p_uc = 100;
9071 }
9072 if (p_uc && !old_value)
9073 ml_open_files();
9074 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009075#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009076 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009077 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009078 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009079 {
9080 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009081 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009082 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009083 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009084 {
9085 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009086 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009087 }
9088 }
9089#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009090#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009091 else if (pp == &p_mzq)
9092 mzvim_reset_timer();
9093#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009095#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9096 /* 'pyxversion' */
9097 else if (pp == &p_pyx)
9098 {
9099 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9100 errmsg = e_invarg;
9101 }
9102#endif
9103
Bram Moolenaar071d4272004-06-13 20:20:40 +00009104 /* sync undo before 'undolevels' changes */
9105 else if (pp == &p_ul)
9106 {
9107 /* use the old value, otherwise u_sync() may not work properly */
9108 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009109 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009110 p_ul = value;
9111 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009112 else if (pp == &curbuf->b_p_ul)
9113 {
9114 /* use the old value, otherwise u_sync() may not work properly */
9115 curbuf->b_p_ul = old_value;
9116 u_sync(TRUE);
9117 curbuf->b_p_ul = value;
9118 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009119
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009120#ifdef FEAT_LINEBREAK
9121 /* 'numberwidth' must be positive */
9122 else if (pp == &curwin->w_p_nuw)
9123 {
9124 if (curwin->w_p_nuw < 1)
9125 {
9126 errmsg = e_positive;
9127 curwin->w_p_nuw = 1;
9128 }
9129 if (curwin->w_p_nuw > 10)
9130 {
9131 errmsg = e_invarg;
9132 curwin->w_p_nuw = 10;
9133 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009134 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009135 }
9136#endif
9137
Bram Moolenaar1a384422010-07-14 19:53:30 +02009138 else if (pp == &curbuf->b_p_tw)
9139 {
9140 if (curbuf->b_p_tw < 0)
9141 {
9142 errmsg = e_positive;
9143 curbuf->b_p_tw = 0;
9144 }
9145#ifdef FEAT_SYN_HL
9146# ifdef FEAT_WINDOWS
9147 {
9148 win_T *wp;
9149 tabpage_T *tp;
9150
9151 FOR_ALL_TAB_WINDOWS(tp, wp)
9152 check_colorcolumn(wp);
9153 }
9154# else
9155 check_colorcolumn(curwin);
9156# endif
9157#endif
9158 }
9159
Bram Moolenaar071d4272004-06-13 20:20:40 +00009160 /*
9161 * Check the bounds for numeric options here
9162 */
9163 if (Rows < min_rows() && full_screen)
9164 {
9165 if (errbuf != NULL)
9166 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009167 vim_snprintf((char *)errbuf, errbuflen,
9168 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009169 errmsg = errbuf;
9170 }
9171 Rows = min_rows();
9172 }
9173 if (Columns < MIN_COLUMNS && full_screen)
9174 {
9175 if (errbuf != NULL)
9176 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009177 vim_snprintf((char *)errbuf, errbuflen,
9178 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009179 errmsg = errbuf;
9180 }
9181 Columns = MIN_COLUMNS;
9182 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009183 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009184
Bram Moolenaar071d4272004-06-13 20:20:40 +00009185 /*
9186 * If the screen (shell) height has been changed, assume it is the
9187 * physical screenheight.
9188 */
9189 if (old_Rows != Rows || old_Columns != Columns)
9190 {
9191 /* Changing the screen size is not allowed while updating the screen. */
9192 if (updating_screen)
9193 *pp = old_value;
9194 else if (full_screen
9195#ifdef FEAT_GUI
9196 && !gui.starting
9197#endif
9198 )
9199 set_shellsize((int)Columns, (int)Rows, TRUE);
9200 else
9201 {
9202 /* Postpone the resizing; check the size and cmdline position for
9203 * messages. */
9204 check_shellsize();
9205 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9206 cmdline_row = Rows - p_ch;
9207 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009208 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009209 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009210 }
9211
Bram Moolenaar071d4272004-06-13 20:20:40 +00009212 if (curbuf->b_p_ts <= 0)
9213 {
9214 errmsg = e_positive;
9215 curbuf->b_p_ts = 8;
9216 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009217 if (p_tm < 0)
9218 {
9219 errmsg = e_positive;
9220 p_tm = 0;
9221 }
9222 if ((curwin->w_p_scr <= 0
9223 || (curwin->w_p_scr > curwin->w_height
9224 && curwin->w_height > 0))
9225 && full_screen)
9226 {
9227 if (pp == &(curwin->w_p_scr))
9228 {
9229 if (curwin->w_p_scr != 0)
9230 errmsg = e_scroll;
9231 win_comp_scroll(curwin);
9232 }
9233 /* If 'scroll' became invalid because of a side effect silently adjust
9234 * it. */
9235 else if (curwin->w_p_scr <= 0)
9236 curwin->w_p_scr = 1;
9237 else /* curwin->w_p_scr > curwin->w_height */
9238 curwin->w_p_scr = curwin->w_height;
9239 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009240 if (p_hi < 0)
9241 {
9242 errmsg = e_positive;
9243 p_hi = 0;
9244 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009245 else if (p_hi > 10000)
9246 {
9247 errmsg = e_invarg;
9248 p_hi = 10000;
9249 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009250 if (p_re < 0 || p_re > 2)
9251 {
9252 errmsg = e_invarg;
9253 p_re = 0;
9254 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255 if (p_report < 0)
9256 {
9257 errmsg = e_positive;
9258 p_report = 1;
9259 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009260 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009261 {
9262 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9263 p_sj = Rows / 2;
9264 else
9265 {
9266 errmsg = e_scroll;
9267 p_sj = 1;
9268 }
9269 }
9270 if (p_so < 0 && full_screen)
9271 {
9272 errmsg = e_scroll;
9273 p_so = 0;
9274 }
9275 if (p_siso < 0 && full_screen)
9276 {
9277 errmsg = e_positive;
9278 p_siso = 0;
9279 }
9280#ifdef FEAT_CMDWIN
9281 if (p_cwh < 1)
9282 {
9283 errmsg = e_positive;
9284 p_cwh = 1;
9285 }
9286#endif
9287 if (p_ut < 0)
9288 {
9289 errmsg = e_positive;
9290 p_ut = 2000;
9291 }
9292 if (p_ss < 0)
9293 {
9294 errmsg = e_positive;
9295 p_ss = 0;
9296 }
9297
9298 /* May set global value for local option. */
9299 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9300 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9301
9302 options[opt_idx].flags |= P_WAS_SET;
9303
Bram Moolenaar53744302015-07-17 17:38:22 +02009304#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9305 if (!starting && errmsg == NULL)
9306 {
9307 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009308 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9309 vim_snprintf((char *)buf_new, 10, "%ld", value);
9310 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009311 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9312 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9313 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9314 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9315 reset_v_option_vars();
9316 }
9317#endif
9318
Bram Moolenaar071d4272004-06-13 20:20:40 +00009319 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009320 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009321 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009322 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009323 check_redraw(options[opt_idx].flags);
9324
9325 return errmsg;
9326}
9327
9328/*
9329 * Called after an option changed: check if something needs to be redrawn.
9330 */
9331 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009332check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009333{
9334 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009335 int doclear = (flags & P_RCLR) == P_RCLR;
9336 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337
9338#ifdef FEAT_WINDOWS
9339 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9340 status_redraw_all();
9341#endif
9342
9343 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9344 changed_window_setting();
9345 if (flags & P_RBUF)
9346 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009347 if (flags & P_RWINONLY)
9348 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009349 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009350 redraw_all_later(CLEAR);
9351 else if (all)
9352 redraw_all_later(NOT_VALID);
9353}
9354
9355/*
9356 * Find index for option 'arg'.
9357 * Return -1 if not found.
9358 */
9359 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009360findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361{
9362 int opt_idx;
9363 char *s, *p;
9364 static short quick_tab[27] = {0, 0}; /* quick access table */
9365 int is_term_opt;
9366
9367 /*
9368 * For first call: Initialize the quick-access table.
9369 * It contains the index for the first option that starts with a certain
9370 * letter. There are 26 letters, plus the first "t_" option.
9371 */
9372 if (quick_tab[1] == 0)
9373 {
9374 p = options[0].fullname;
9375 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9376 {
9377 if (s[0] != p[0])
9378 {
9379 if (s[0] == 't' && s[1] == '_')
9380 quick_tab[26] = opt_idx;
9381 else
9382 quick_tab[CharOrdLow(s[0])] = opt_idx;
9383 }
9384 p = s;
9385 }
9386 }
9387
9388 /*
9389 * Check for name starting with an illegal character.
9390 */
9391#ifdef EBCDIC
9392 if (!islower(arg[0]))
9393#else
9394 if (arg[0] < 'a' || arg[0] > 'z')
9395#endif
9396 return -1;
9397
9398 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9399 if (is_term_opt)
9400 opt_idx = quick_tab[26];
9401 else
9402 opt_idx = quick_tab[CharOrdLow(arg[0])];
9403 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9404 {
9405 if (STRCMP(arg, s) == 0) /* match full name */
9406 break;
9407 }
9408 if (s == NULL && !is_term_opt)
9409 {
9410 opt_idx = quick_tab[CharOrdLow(arg[0])];
9411 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9412 {
9413 s = options[opt_idx].shortname;
9414 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9415 break;
9416 s = NULL;
9417 }
9418 }
9419 if (s == NULL)
9420 opt_idx = -1;
9421 return opt_idx;
9422}
9423
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009424#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425/*
9426 * Get the value for an option.
9427 *
9428 * Returns:
9429 * Number or Toggle option: 1, *numval gets value.
9430 * String option: 0, *stringval gets allocated string.
9431 * Hidden Number or Toggle option: -1.
9432 * hidden String option: -2.
9433 * unknown option: -3.
9434 */
9435 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009436get_option_value(
9437 char_u *name,
9438 long *numval,
9439 char_u **stringval, /* NULL when only checking existence */
9440 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009441{
9442 int opt_idx;
9443 char_u *varp;
9444
9445 opt_idx = findoption(name);
9446 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009447 {
9448 int key;
9449
9450 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9451 && (key = find_key_option(name)) != 0)
9452 {
9453 char_u key_name[2];
9454 char_u *p;
9455
9456 if (key < 0)
9457 {
9458 key_name[0] = KEY2TERMCAP0(key);
9459 key_name[1] = KEY2TERMCAP1(key);
9460 }
9461 else
9462 {
9463 key_name[0] = KS_KEY;
9464 key_name[1] = (key & 0xff);
9465 }
9466 p = find_termcode(key_name);
9467 if (p != NULL)
9468 {
9469 if (stringval != NULL)
9470 *stringval = vim_strsave(p);
9471 return 0;
9472 }
9473 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009474 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009475 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009476
9477 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9478
9479 if (options[opt_idx].flags & P_STRING)
9480 {
9481 if (varp == NULL) /* hidden option */
9482 return -2;
9483 if (stringval != NULL)
9484 {
9485#ifdef FEAT_CRYPT
9486 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009487 if ((char_u **)varp == &curbuf->b_p_key
9488 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009489 *stringval = vim_strsave((char_u *)"*****");
9490 else
9491#endif
9492 *stringval = vim_strsave(*(char_u **)(varp));
9493 }
9494 return 0;
9495 }
9496
9497 if (varp == NULL) /* hidden option */
9498 return -1;
9499 if (options[opt_idx].flags & P_NUM)
9500 *numval = *(long *)varp;
9501 else
9502 {
9503 /* Special case: 'modified' is b_changed, but we also want to consider
9504 * it set when 'ff' or 'fenc' changed. */
9505 if ((int *)varp == &curbuf->b_changed)
9506 *numval = curbufIsChanged();
9507 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009508 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009509 }
9510 return 1;
9511}
9512#endif
9513
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009514#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009515/*
9516 * Returns the option attributes and its value. Unlike the above function it
9517 * will return either global value or local value of the option depending on
9518 * what was requested, but it will never return global value if it was
9519 * requested to return local one and vice versa. Neither it will return
9520 * buffer-local value if it was requested to return window-local one.
9521 *
9522 * Pretends that option is absent if it is not present in the requested scope
9523 * (i.e. has no global, window-local or buffer-local value depending on
9524 * opt_type). Uses
9525 *
9526 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009527 * 0 hidden or unknown option, also option that does not have requested
9528 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009529 * see SOPT_* in vim.h for other flags
9530 *
9531 * Possible opt_type values: see SREQ_* in vim.h
9532 */
9533 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009534get_option_value_strict(
9535 char_u *name,
9536 long *numval,
9537 char_u **stringval, /* NULL when only obtaining attributes */
9538 int opt_type,
9539 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009540{
9541 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009542 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009543 struct vimoption *p;
9544 int r = 0;
9545
9546 opt_idx = findoption(name);
9547 if (opt_idx < 0)
9548 return 0;
9549
9550 p = &(options[opt_idx]);
9551
9552 /* Hidden option */
9553 if (p->var == NULL)
9554 return 0;
9555
9556 if (p->flags & P_BOOL)
9557 r |= SOPT_BOOL;
9558 else if (p->flags & P_NUM)
9559 r |= SOPT_NUM;
9560 else if (p->flags & P_STRING)
9561 r |= SOPT_STRING;
9562
9563 if (p->indir == PV_NONE)
9564 {
9565 if (opt_type == SREQ_GLOBAL)
9566 r |= SOPT_GLOBAL;
9567 else
9568 return 0; /* Did not request global-only option */
9569 }
9570 else
9571 {
9572 if (p->indir & PV_BOTH)
9573 r |= SOPT_GLOBAL;
9574 else if (opt_type == SREQ_GLOBAL)
9575 return 0; /* Requested global option */
9576
9577 if (p->indir & PV_WIN)
9578 {
9579 if (opt_type == SREQ_BUF)
9580 return 0; /* Did not request window-local option */
9581 else
9582 r |= SOPT_WIN;
9583 }
9584 else if (p->indir & PV_BUF)
9585 {
9586 if (opt_type == SREQ_WIN)
9587 return 0; /* Did not request buffer-local option */
9588 else
9589 r |= SOPT_BUF;
9590 }
9591 }
9592
9593 if (stringval == NULL)
9594 return r;
9595
9596 if (opt_type == SREQ_GLOBAL)
9597 varp = p->var;
9598 else
9599 {
9600 if (opt_type == SREQ_BUF)
9601 {
9602 /* Special case: 'modified' is b_changed, but we also want to
9603 * consider it set when 'ff' or 'fenc' changed. */
9604 if (p->indir == PV_MOD)
9605 {
9606 *numval = bufIsChanged((buf_T *) from);
9607 varp = NULL;
9608 }
9609#ifdef FEAT_CRYPT
9610 else if (p->indir == PV_KEY)
9611 {
9612 /* never return the value of the crypt key */
9613 *stringval = NULL;
9614 varp = NULL;
9615 }
9616#endif
9617 else
9618 {
9619 aco_save_T aco;
9620 aucmd_prepbuf(&aco, (buf_T *) from);
9621 varp = get_varp(p);
9622 aucmd_restbuf(&aco);
9623 }
9624 }
9625 else if (opt_type == SREQ_WIN)
9626 {
9627 win_T *save_curwin;
9628 save_curwin = curwin;
9629 curwin = (win_T *) from;
9630 curbuf = curwin->w_buffer;
9631 varp = get_varp(p);
9632 curwin = save_curwin;
9633 curbuf = curwin->w_buffer;
9634 }
9635 if (varp == p->var)
9636 return (r | SOPT_UNSET);
9637 }
9638
9639 if (varp != NULL)
9640 {
9641 if (p->flags & P_STRING)
9642 *stringval = vim_strsave(*(char_u **)(varp));
9643 else if (p->flags & P_NUM)
9644 *numval = *(long *) varp;
9645 else
9646 *numval = *(int *)varp;
9647 }
9648
9649 return r;
9650}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009651
9652/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009653 * Iterate over options. First argument is a pointer to a pointer to a
9654 * structure inside options[] array, second is option type like in the above
9655 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009656 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009657 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009658 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009659 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009660 * first argument to NULL.
9661 *
9662 * Returns full option name for current option on each call.
9663 */
9664 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009665option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009666{
9667 struct vimoption *ret = NULL;
9668 do
9669 {
9670 if (*option == NULL)
9671 *option = (void *) options;
9672 else if (((struct vimoption *) (*option))->fullname == NULL)
9673 {
9674 *option = NULL;
9675 return NULL;
9676 }
9677 else
9678 *option = (void *) (((struct vimoption *) (*option)) + 1);
9679
9680 ret = ((struct vimoption *) (*option));
9681
9682 /* Hidden option */
9683 if (ret->var == NULL)
9684 {
9685 ret = NULL;
9686 continue;
9687 }
9688
9689 switch (opt_type)
9690 {
9691 case SREQ_GLOBAL:
9692 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9693 ret = NULL;
9694 break;
9695 case SREQ_BUF:
9696 if (!(ret->indir & PV_BUF))
9697 ret = NULL;
9698 break;
9699 case SREQ_WIN:
9700 if (!(ret->indir & PV_WIN))
9701 ret = NULL;
9702 break;
9703 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009704 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009705 return NULL;
9706 }
9707 }
9708 while (ret == NULL);
9709
9710 return (char_u *)ret->fullname;
9711}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009712#endif
9713
Bram Moolenaar071d4272004-06-13 20:20:40 +00009714/*
9715 * Set the value of option "name".
9716 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009717 *
9718 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009719 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009720 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009721set_option_value(
9722 char_u *name,
9723 long number,
9724 char_u *string,
9725 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009726{
9727 int opt_idx;
9728 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009729 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009730
9731 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009732 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009733 {
9734 int key;
9735
9736 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9737 && (key = find_key_option(name)) != 0)
9738 {
9739 char_u key_name[2];
9740
9741 if (key < 0)
9742 {
9743 key_name[0] = KEY2TERMCAP0(key);
9744 key_name[1] = KEY2TERMCAP1(key);
9745 }
9746 else
9747 {
9748 key_name[0] = KS_KEY;
9749 key_name[1] = (key & 0xff);
9750 }
9751 add_termcode(key_name, string, FALSE);
9752 if (full_screen)
9753 ttest(FALSE);
9754 redraw_all_later(CLEAR);
9755 return NULL;
9756 }
9757
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009759 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760 else
9761 {
9762 flags = options[opt_idx].flags;
9763#ifdef HAVE_SANDBOX
9764 /* Disallow changing some options in the sandbox */
9765 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009766 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009767 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009768 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009769 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009770#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009771 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009772 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009773 else
9774 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009775 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009776 if (varp != NULL) /* hidden option is not changed */
9777 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009778 if (number == 0 && string != NULL)
9779 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009780 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009781
9782 /* Either we are given a string or we are setting option
9783 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009784 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009785 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009786 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009787 {
9788 /* There's another character after zeros or the string
9789 * is empty. In both cases, we are trying to set a
9790 * num option using a string. */
9791 EMSG3(_("E521: Number required: &%s = '%s'"),
9792 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009793 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009794
9795 }
9796 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009797 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009798 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009799 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009800 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009801 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009802 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009803 }
9804 }
9805 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009806 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009807}
9808
9809/*
9810 * Get the terminal code for a terminal option.
9811 * Returns NULL when not found.
9812 */
9813 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009814get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009815{
9816 int opt_idx;
9817 char_u *varp;
9818
9819 if (tname[0] != 't' || tname[1] != '_' ||
9820 tname[2] == NUL || tname[3] == NUL)
9821 return NULL;
9822 if ((opt_idx = findoption(tname)) >= 0)
9823 {
9824 varp = get_varp(&(options[opt_idx]));
9825 if (varp != NULL)
9826 varp = *(char_u **)(varp);
9827 return varp;
9828 }
9829 return find_termcode(tname + 2);
9830}
9831
9832 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009833get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009834{
9835 int i;
9836
9837 i = findoption((char_u *)"hl");
9838 if (i >= 0)
9839 return options[i].def_val[VI_DEFAULT];
9840 return (char_u *)NULL;
9841}
9842
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009843#if defined(FEAT_MBYTE) || defined(PROTO)
9844 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009845get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009846{
9847 int i;
9848
9849 i = findoption((char_u *)"enc");
9850 if (i >= 0)
9851 return options[i].def_val[VI_DEFAULT];
9852 return (char_u *)NULL;
9853}
9854#endif
9855
Bram Moolenaar071d4272004-06-13 20:20:40 +00009856/*
9857 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9858 */
9859 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009860find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009861{
9862 int key;
9863 int modifiers;
9864
9865 /*
9866 * Don't use get_special_key_code() for t_xx, we don't want it to call
9867 * add_termcap_entry().
9868 */
9869 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9870 key = TERMCAP2KEY(arg[2], arg[3]);
9871 else
9872 {
9873 --arg; /* put arg at the '<' */
9874 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009875 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009876 if (modifiers) /* can't handle modifiers here */
9877 key = 0;
9878 }
9879 return key;
9880}
9881
9882/*
9883 * if 'all' == 0: show changed options
9884 * if 'all' == 1: show all normal options
9885 * if 'all' == 2: show all terminal options
9886 */
9887 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009888showoptions(
9889 int all,
9890 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009891{
9892 struct vimoption *p;
9893 int col;
9894 int isterm;
9895 char_u *varp;
9896 struct vimoption **items;
9897 int item_count;
9898 int run;
9899 int row, rows;
9900 int cols;
9901 int i;
9902 int len;
9903
9904#define INC 20
9905#define GAP 3
9906
9907 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9908 PARAM_COUNT));
9909 if (items == NULL)
9910 return;
9911
9912 /* Highlight title */
9913 if (all == 2)
9914 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9915 else if (opt_flags & OPT_GLOBAL)
9916 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9917 else if (opt_flags & OPT_LOCAL)
9918 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9919 else
9920 MSG_PUTS_TITLE(_("\n--- Options ---"));
9921
9922 /*
9923 * do the loop two times:
9924 * 1. display the short items
9925 * 2. display the long items (only strings and numbers)
9926 */
9927 for (run = 1; run <= 2 && !got_int; ++run)
9928 {
9929 /*
9930 * collect the items in items[]
9931 */
9932 item_count = 0;
9933 for (p = &options[0]; p->fullname != NULL; p++)
9934 {
9935 varp = NULL;
9936 isterm = istermoption(p);
9937 if (opt_flags != 0)
9938 {
9939 if (p->indir != PV_NONE && !isterm)
9940 varp = get_varp_scope(p, opt_flags);
9941 }
9942 else
9943 varp = get_varp(p);
9944 if (varp != NULL
9945 && ((all == 2 && isterm)
9946 || (all == 1 && !isterm)
9947 || (all == 0 && !optval_default(p, varp))))
9948 {
9949 if (p->flags & P_BOOL)
9950 len = 1; /* a toggle option fits always */
9951 else
9952 {
9953 option_value2string(p, opt_flags);
9954 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9955 }
9956 if ((len <= INC - GAP && run == 1) ||
9957 (len > INC - GAP && run == 2))
9958 items[item_count++] = p;
9959 }
9960 }
9961
9962 /*
9963 * display the items
9964 */
9965 if (run == 1)
9966 {
9967 cols = (Columns + GAP - 3) / INC;
9968 if (cols == 0)
9969 cols = 1;
9970 rows = (item_count + cols - 1) / cols;
9971 }
9972 else /* run == 2 */
9973 rows = item_count;
9974 for (row = 0; row < rows && !got_int; ++row)
9975 {
9976 msg_putchar('\n'); /* go to next line */
9977 if (got_int) /* 'q' typed in more */
9978 break;
9979 col = 0;
9980 for (i = row; i < item_count; i += rows)
9981 {
9982 msg_col = col; /* make columns */
9983 showoneopt(items[i], opt_flags);
9984 col += INC;
9985 }
9986 out_flush();
9987 ui_breakcheck();
9988 }
9989 }
9990 vim_free(items);
9991}
9992
9993/*
9994 * Return TRUE if option "p" has its default value.
9995 */
9996 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009997optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009998{
9999 int dvi;
10000
10001 if (varp == NULL)
10002 return TRUE; /* hidden option is always at default */
10003 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10004 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010005 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010007 /* the cast to long is required for Manx C, long_i is
10008 * needed for MSVC */
10009 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010010 /* P_STRING */
10011 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10012}
10013
10014/*
10015 * showoneopt: show the value of one option
10016 * must not be called with a hidden option!
10017 */
10018 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010019showoneopt(
10020 struct vimoption *p,
10021 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010022{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010023 char_u *varp;
10024 int save_silent = silent_mode;
10025
10026 silent_mode = FALSE;
10027 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010028
10029 varp = get_varp_scope(p, opt_flags);
10030
10031 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10032 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10033 ? !curbufIsChanged() : !*(int *)varp))
10034 MSG_PUTS("no");
10035 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10036 MSG_PUTS("--");
10037 else
10038 MSG_PUTS(" ");
10039 MSG_PUTS(p->fullname);
10040 if (!(p->flags & P_BOOL))
10041 {
10042 msg_putchar('=');
10043 /* put value string in NameBuff */
10044 option_value2string(p, opt_flags);
10045 msg_outtrans(NameBuff);
10046 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010047
10048 silent_mode = save_silent;
10049 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010050}
10051
10052/*
10053 * Write modified options as ":set" commands to a file.
10054 *
10055 * There are three values for "opt_flags":
10056 * OPT_GLOBAL: Write global option values and fresh values of
10057 * buffer-local options (used for start of a session
10058 * file).
10059 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10060 * curwin (used for a vimrc file).
10061 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10062 * and local values for window-local options of
10063 * curwin. Local values are also written when at the
10064 * default value, because a modeline or autocommand
10065 * may have set them when doing ":edit file" and the
10066 * user has set them back at the default or fresh
10067 * value.
10068 * When "local_only" is TRUE, don't write fresh
10069 * values, only local values (for ":mkview").
10070 * (fresh value = value used for a new buffer or window for a local option).
10071 *
10072 * Return FAIL on error, OK otherwise.
10073 */
10074 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010075makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010076{
10077 struct vimoption *p;
10078 char_u *varp; /* currently used value */
10079 char_u *varp_fresh; /* local value */
10080 char_u *varp_local = NULL; /* fresh value */
10081 char *cmd;
10082 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010083 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010084
10085 /*
10086 * The options that don't have a default (terminal name, columns, lines)
10087 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010088 * Do the loop over "options[]" twice: once for options with the
10089 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010090 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010091 for (pri = 1; pri >= 0; --pri)
10092 {
10093 for (p = &options[0]; !istermoption(p); p++)
10094 if (!(p->flags & P_NO_MKRC)
10095 && !istermoption(p)
10096 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010097 {
10098 /* skip global option when only doing locals */
10099 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10100 continue;
10101
10102 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10103 * file, they are always buffer-specific. */
10104 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10105 continue;
10106
10107 /* Global values are only written when not at the default value. */
10108 varp = get_varp_scope(p, opt_flags);
10109 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10110 continue;
10111
10112 round = 2;
10113 if (p->indir != PV_NONE)
10114 {
10115 if (p->var == VAR_WIN)
10116 {
10117 /* skip window-local option when only doing globals */
10118 if (!(opt_flags & OPT_LOCAL))
10119 continue;
10120 /* When fresh value of window-local option is not at the
10121 * default, need to write it too. */
10122 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10123 {
10124 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10125 if (!optval_default(p, varp_fresh))
10126 {
10127 round = 1;
10128 varp_local = varp;
10129 varp = varp_fresh;
10130 }
10131 }
10132 }
10133 }
10134
10135 /* Round 1: fresh value for window-local options.
10136 * Round 2: other values */
10137 for ( ; round <= 2; varp = varp_local, ++round)
10138 {
10139 if (round == 1 || (opt_flags & OPT_GLOBAL))
10140 cmd = "set";
10141 else
10142 cmd = "setlocal";
10143
10144 if (p->flags & P_BOOL)
10145 {
10146 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10147 return FAIL;
10148 }
10149 else if (p->flags & P_NUM)
10150 {
10151 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10152 return FAIL;
10153 }
10154 else /* P_STRING */
10155 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010156#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10157 int do_endif = FALSE;
10158
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159 /* Don't set 'syntax' and 'filetype' again if the value is
10160 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010161 if (
10162# if defined(FEAT_SYN_HL)
10163 p->indir == PV_SYN
10164# if defined(FEAT_AUTOCMD)
10165 ||
10166# endif
10167# endif
10168# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010169 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010170# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010171 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172 {
10173 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10174 *(char_u **)(varp)) < 0
10175 || put_eol(fd) < 0)
10176 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010177 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010179#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10181 (p->flags & P_EXPAND) != 0) == FAIL)
10182 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010183#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10184 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185 {
10186 if (put_line(fd, "endif") == FAIL)
10187 return FAIL;
10188 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010189#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 }
10191 }
10192 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010193 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194 return OK;
10195}
10196
10197#if defined(FEAT_FOLDING) || defined(PROTO)
10198/*
10199 * Generate set commands for the local fold options only. Used when
10200 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10201 */
10202 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010203makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204{
10205 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10206# ifdef FEAT_EVAL
10207 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10208 == FAIL
10209# endif
10210 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10211 == FAIL
10212 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10213 == FAIL
10214 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10215 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10216 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10217 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10218 )
10219 return FAIL;
10220
10221 return OK;
10222}
10223#endif
10224
10225 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010226put_setstring(
10227 FILE *fd,
10228 char *cmd,
10229 char *name,
10230 char_u **valuep,
10231 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232{
10233 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010234 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010235
10236 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10237 return FAIL;
10238 if (*valuep != NULL)
10239 {
10240 /* Output 'pastetoggle' as key names. For other
10241 * options some characters have to be escaped with
10242 * CTRL-V or backslash */
10243 if (valuep == &p_pt)
10244 {
10245 s = *valuep;
10246 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010247 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248 return FAIL;
10249 }
10250 else if (expand)
10251 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010252 buf = alloc(MAXPATHL);
10253 if (buf == NULL)
10254 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10256 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010257 {
10258 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010260 }
10261 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262 }
10263 else if (put_escstr(fd, *valuep, 2) == FAIL)
10264 return FAIL;
10265 }
10266 if (put_eol(fd) < 0)
10267 return FAIL;
10268 return OK;
10269}
10270
10271 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010272put_setnum(
10273 FILE *fd,
10274 char *cmd,
10275 char *name,
10276 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010277{
10278 long wc;
10279
10280 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10281 return FAIL;
10282 if (wc_use_keyname((char_u *)valuep, &wc))
10283 {
10284 /* print 'wildchar' and 'wildcharm' as a key name */
10285 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10286 return FAIL;
10287 }
10288 else if (fprintf(fd, "%ld", *valuep) < 0)
10289 return FAIL;
10290 if (put_eol(fd) < 0)
10291 return FAIL;
10292 return OK;
10293}
10294
10295 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010296put_setbool(
10297 FILE *fd,
10298 char *cmd,
10299 char *name,
10300 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301{
Bram Moolenaar893de922007-10-02 18:40:57 +000010302 if (value < 0) /* global/local option using global value */
10303 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010304 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10305 || put_eol(fd) < 0)
10306 return FAIL;
10307 return OK;
10308}
10309
10310/*
10311 * Clear all the terminal options.
10312 * If the option has been allocated, free the memory.
10313 * Terminal options are never hidden or indirect.
10314 */
10315 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010316clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010317{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318 /*
10319 * Reset a few things before clearing the old options. This may cause
10320 * outputting a few things that the terminal doesn't understand, but the
10321 * screen will be cleared later, so this is OK.
10322 */
10323#ifdef FEAT_MOUSE_TTY
10324 mch_setmouse(FALSE); /* switch mouse off */
10325#endif
10326#ifdef FEAT_TITLE
10327 mch_restore_title(3); /* restore window titles */
10328#endif
10329#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10330 /* When starting the GUI close the display opened for the clipboard.
10331 * After restoring the title, because that will need the display. */
10332 if (gui.starting)
10333 clear_xterm_clip();
10334#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010335 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010336
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010337 free_termoptions();
10338}
10339
10340 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010341free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010342{
10343 struct vimoption *p;
10344
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345 for (p = &options[0]; p->fullname != NULL; p++)
10346 if (istermoption(p))
10347 {
10348 if (p->flags & P_ALLOCED)
10349 free_string_option(*(char_u **)(p->var));
10350 if (p->flags & P_DEF_ALLOCED)
10351 free_string_option(p->def_val[VI_DEFAULT]);
10352 *(char_u **)(p->var) = empty_option;
10353 p->def_val[VI_DEFAULT] = empty_option;
10354 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10355 }
10356 clear_termcodes();
10357}
10358
10359/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010360 * Free the string for one term option, if it was allocated.
10361 * Set the string to empty_option and clear allocated flag.
10362 * "var" points to the option value.
10363 */
10364 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010365free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010366{
10367 struct vimoption *p;
10368
10369 for (p = &options[0]; p->fullname != NULL; p++)
10370 if (p->var == var)
10371 {
10372 if (p->flags & P_ALLOCED)
10373 free_string_option(*(char_u **)(p->var));
10374 *(char_u **)(p->var) = empty_option;
10375 p->flags &= ~P_ALLOCED;
10376 break;
10377 }
10378}
10379
10380/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010381 * Set the terminal option defaults to the current value.
10382 * Used after setting the terminal name.
10383 */
10384 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010385set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010386{
10387 struct vimoption *p;
10388
10389 for (p = &options[0]; p->fullname != NULL; p++)
10390 {
10391 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10392 {
10393 if (p->flags & P_DEF_ALLOCED)
10394 {
10395 free_string_option(p->def_val[VI_DEFAULT]);
10396 p->flags &= ~P_DEF_ALLOCED;
10397 }
10398 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10399 if (p->flags & P_ALLOCED)
10400 {
10401 p->flags |= P_DEF_ALLOCED;
10402 p->flags &= ~P_ALLOCED; /* don't free the value now */
10403 }
10404 }
10405 }
10406}
10407
10408/*
10409 * return TRUE if 'p' starts with 't_'
10410 */
10411 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010412istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413{
10414 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10415}
10416
10417/*
10418 * Compute columns for ruler and shown command. 'sc_col' is also used to
10419 * decide what the maximum length of a message on the status line can be.
10420 * If there is a status line for the last window, 'sc_col' is independent
10421 * of 'ru_col'.
10422 */
10423
10424#define COL_RULER 17 /* columns needed by standard ruler */
10425
10426 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010427comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010428{
10429#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010430 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431
10432 sc_col = 0;
10433 ru_col = 0;
10434 if (p_ru)
10435 {
10436#ifdef FEAT_STL_OPT
10437 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10438#else
10439 ru_col = COL_RULER + 1;
10440#endif
10441 /* no last status line, adjust sc_col */
10442 if (!last_has_status)
10443 sc_col = ru_col;
10444 }
10445 if (p_sc)
10446 {
10447 sc_col += SHOWCMD_COLS;
10448 if (!p_ru || last_has_status) /* no need for separating space */
10449 ++sc_col;
10450 }
10451 sc_col = Columns - sc_col;
10452 ru_col = Columns - ru_col;
10453 if (sc_col <= 0) /* screen too narrow, will become a mess */
10454 sc_col = 1;
10455 if (ru_col <= 0)
10456 ru_col = 1;
10457#else
10458 sc_col = Columns;
10459 ru_col = Columns;
10460#endif
10461}
10462
10463/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010464 * Unset local option value, similar to ":set opt<".
10465 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010466 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010467unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010468{
10469 struct vimoption *p;
10470 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010471 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010472
10473 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010474 if (opt_idx < 0)
10475 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010476 p = &(options[opt_idx]);
10477
10478 switch ((int)p->indir)
10479 {
10480 /* global option with local value: use local value if it's been set */
10481 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010482 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010483 break;
10484 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010485 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010486 break;
10487 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010488 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010489 break;
10490 case PV_AR:
10491 buf->b_p_ar = -1;
10492 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010493 case PV_BKC:
10494 clear_string_option(&buf->b_p_bkc);
10495 buf->b_bkc_flags = 0;
10496 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010497 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010498 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010499 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010500 case PV_TC:
10501 clear_string_option(&buf->b_p_tc);
10502 buf->b_tc_flags = 0;
10503 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010504#ifdef FEAT_FIND_ID
10505 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010506 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010507 break;
10508 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010509 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010510 break;
10511#endif
10512#ifdef FEAT_INS_EXPAND
10513 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010514 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010515 break;
10516 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010517 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010518 break;
10519#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010520 case PV_FP:
10521 clear_string_option(&buf->b_p_fp);
10522 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010523#ifdef FEAT_QUICKFIX
10524 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010525 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010526 break;
10527 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010528 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010529 break;
10530 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010531 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010532 break;
10533#endif
10534#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10535 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010536 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010537 break;
10538#endif
10539#if defined(FEAT_CRYPT)
10540 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010541 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010542 break;
10543#endif
10544#ifdef FEAT_STL_OPT
10545 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010546 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010547 break;
10548#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010549 case PV_UL:
10550 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10551 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010552#ifdef FEAT_LISP
10553 case PV_LW:
10554 clear_string_option(&buf->b_p_lw);
10555 break;
10556#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010557#ifdef FEAT_MBYTE
10558 case PV_MENC:
10559 clear_string_option(&buf->b_p_menc);
10560 break;
10561#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010562 }
10563}
10564
10565/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566 * Get pointer to option variable, depending on local or global scope.
10567 */
10568 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010569get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010570{
10571 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10572 {
10573 if (p->var == VAR_WIN)
10574 return (char_u *)GLOBAL_WO(get_varp(p));
10575 return p->var;
10576 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010577 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010578 {
10579 switch ((int)p->indir)
10580 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010581 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010583 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10584 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10585 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010587 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10588 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10589 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010590 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010591 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010592 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010594 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10595 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596#endif
10597#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010598 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10599 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010601#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10602 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10603#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010604#if defined(FEAT_CRYPT)
10605 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10606#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010607#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010608 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010609#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010610 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010611#ifdef FEAT_LISP
10612 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10613#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010614 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010615#ifdef FEAT_MBYTE
10616 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618 }
10619 return NULL; /* "cannot happen" */
10620 }
10621 return get_varp(p);
10622}
10623
10624/*
10625 * Get pointer to option variable.
10626 */
10627 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010628get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629{
10630 /* hidden option, always return NULL */
10631 if (p->var == NULL)
10632 return NULL;
10633
10634 switch ((int)p->indir)
10635 {
10636 case PV_NONE: return p->var;
10637
10638 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010639 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010640 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010641 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010643 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010644 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010645 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010646 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010647 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010648 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010649 case PV_TC: return *curbuf->b_p_tc != NUL
10650 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010651 case PV_BKC: return *curbuf->b_p_bkc != NUL
10652 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010653#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010654 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010656 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10658#endif
10659#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010660 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010661 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010662 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010663 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10664#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010665 case PV_FP: return *curbuf->b_p_fp != NUL
10666 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010667#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010668 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010669 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010670 case PV_GP: return *curbuf->b_p_gp != NUL
10671 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10672 case PV_MP: return *curbuf->b_p_mp != NUL
10673 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010674#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010675#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10676 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10677 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10678#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010679#if defined(FEAT_CRYPT)
10680 case PV_CM: return *curbuf->b_p_cm != NUL
10681 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10682#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010683#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010684 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010685 ? (char_u *)&(curwin->w_p_stl) : p->var;
10686#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010687 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10688 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010689#ifdef FEAT_LISP
10690 case PV_LW: return *curbuf->b_p_lw != NUL
10691 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10692#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010693#ifdef FEAT_MBYTE
10694 case PV_MENC: return *curbuf->b_p_menc != NUL
10695 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10696#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010697
10698#ifdef FEAT_ARABIC
10699 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10700#endif
10701 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010702#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010703 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10704#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010705#ifdef FEAT_SYN_HL
10706 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10707 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010708 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010710#ifdef FEAT_DIFF
10711 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10712#endif
10713#ifdef FEAT_FOLDING
10714 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10715 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10716 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10717 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10718 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10719 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10720 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10721# ifdef FEAT_EVAL
10722 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10723 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10724# endif
10725 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10726#endif
10727 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010728 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010729#ifdef FEAT_LINEBREAK
10730 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10731#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010732#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010733 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010734 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10735#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010736#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10737 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10738#endif
10739#ifdef FEAT_RIGHTLEFT
10740 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10741 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10742#endif
10743 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10744 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10745#ifdef FEAT_LINEBREAK
10746 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010747 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10748 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010749#endif
10750#ifdef FEAT_SCROLLBIND
10751 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10752#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010753#ifdef FEAT_CURSORBIND
10754 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10755#endif
10756#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010757 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10758 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10759#endif
10760#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010761 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010762 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010763#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764
10765 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10766 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10767#ifdef FEAT_MBYTE
10768 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10769#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10771 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10773 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10774#ifdef FEAT_CINDENT
10775 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10776 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10777 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10778#endif
10779#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10780 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10781#endif
10782#ifdef FEAT_COMMENTS
10783 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10784#endif
10785#ifdef FEAT_FOLDING
10786 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10787#endif
10788#ifdef FEAT_INS_EXPAND
10789 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10790#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010791#ifdef FEAT_COMPL_FUNC
10792 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010793 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010794#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010795 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010796 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10798#ifdef FEAT_MBYTE
10799 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10800#endif
10801 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10802#ifdef FEAT_AUTOCMD
10803 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10804#endif
10805 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010806 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010807 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10808 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10809 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10810 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10811#ifdef FEAT_FIND_ID
10812# ifdef FEAT_EVAL
10813 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10814# endif
10815#endif
10816#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10817 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10818 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10819#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010820#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010821 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10822#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010823#ifdef FEAT_CRYPT
10824 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10825#endif
10826#ifdef FEAT_LISP
10827 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10828#endif
10829 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10830 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10831 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10832 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10833 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010834 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010835#ifdef FEAT_TEXTOBJ
10836 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10837#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010838 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10839#ifdef FEAT_SMARTINDENT
10840 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10841#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010842 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010843 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10844#ifdef FEAT_SEARCHPATH
10845 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10846#endif
10847 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10848#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010849 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010850 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10851#endif
10852#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010853 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10854 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10855 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856#endif
10857 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10858 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10859 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10860 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010861#ifdef FEAT_PERSISTENT_UNDO
10862 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10863#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10865#ifdef FEAT_KEYMAP
10866 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10867#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010868#ifdef FEAT_SIGNS
10869 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10870#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010871 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872 }
10873 /* always return a valid pointer to avoid a crash! */
10874 return (char_u *)&(curbuf->b_p_wm);
10875}
10876
10877/*
10878 * Get the value of 'equalprg', either the buffer-local one or the global one.
10879 */
10880 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010881get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010882{
10883 if (*curbuf->b_p_ep == NUL)
10884 return p_ep;
10885 return curbuf->b_p_ep;
10886}
10887
10888#if defined(FEAT_WINDOWS) || defined(PROTO)
10889/*
10890 * Copy options from one window to another.
10891 * Used when splitting a window.
10892 */
10893 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010894win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895{
10896 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10897 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10898# ifdef FEAT_RIGHTLEFT
10899# ifdef FEAT_FKMAP
10900 /* Is this right? */
10901 wp_to->w_farsi = wp_from->w_farsi;
10902# endif
10903# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010904#if defined(FEAT_LINEBREAK)
10905 briopt_check(wp_to);
10906#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907}
10908#endif
10909
10910/*
10911 * Copy the options from one winopt_T to another.
10912 * Doesn't free the old option values in "to", use clear_winopt() for that.
10913 * The 'scroll' option is not copied, because it depends on the window height.
10914 * The 'previewwindow' option is reset, there can be only one preview window.
10915 */
10916 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010917copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918{
10919#ifdef FEAT_ARABIC
10920 to->wo_arab = from->wo_arab;
10921#endif
10922 to->wo_list = from->wo_list;
10923 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010924 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010925#ifdef FEAT_LINEBREAK
10926 to->wo_nuw = from->wo_nuw;
10927#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010928#ifdef FEAT_RIGHTLEFT
10929 to->wo_rl = from->wo_rl;
10930 to->wo_rlc = vim_strsave(from->wo_rlc);
10931#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010932#ifdef FEAT_STL_OPT
10933 to->wo_stl = vim_strsave(from->wo_stl);
10934#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010936#ifdef FEAT_DIFF
10937 to->wo_wrap_save = from->wo_wrap_save;
10938#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939#ifdef FEAT_LINEBREAK
10940 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010941 to->wo_bri = from->wo_bri;
10942 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943#endif
10944#ifdef FEAT_SCROLLBIND
10945 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010946 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010948#ifdef FEAT_CURSORBIND
10949 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010950 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010951#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010952#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010953 to->wo_spell = from->wo_spell;
10954#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010955#ifdef FEAT_SYN_HL
10956 to->wo_cuc = from->wo_cuc;
10957 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010958 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010959#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010960#ifdef FEAT_DIFF
10961 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010962 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010964#ifdef FEAT_CONCEAL
10965 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010966 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010967#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010968#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010969 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010970 to->wo_tms = vim_strsave(from->wo_tms);
10971#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010972#ifdef FEAT_FOLDING
10973 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010974 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010976 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010977 to->wo_fdi = vim_strsave(from->wo_fdi);
10978 to->wo_fml = from->wo_fml;
10979 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010980 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010981 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010982 to->wo_fdm_save = from->wo_diff_saved
10983 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010984 to->wo_fdn = from->wo_fdn;
10985# ifdef FEAT_EVAL
10986 to->wo_fde = vim_strsave(from->wo_fde);
10987 to->wo_fdt = vim_strsave(from->wo_fdt);
10988# endif
10989 to->wo_fmr = vim_strsave(from->wo_fmr);
10990#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010991#ifdef FEAT_SIGNS
10992 to->wo_scl = vim_strsave(from->wo_scl);
10993#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994 check_winopt(to); /* don't want NULL pointers */
10995}
10996
10997/*
10998 * Check string options in a window for a NULL value.
10999 */
11000 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011001check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011002{
11003 check_winopt(&win->w_onebuf_opt);
11004 check_winopt(&win->w_allbuf_opt);
11005}
11006
11007/*
11008 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11009 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011010 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011011check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011012{
11013#ifdef FEAT_FOLDING
11014 check_string_option(&wop->wo_fdi);
11015 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011016 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011017# ifdef FEAT_EVAL
11018 check_string_option(&wop->wo_fde);
11019 check_string_option(&wop->wo_fdt);
11020# endif
11021 check_string_option(&wop->wo_fmr);
11022#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011023#ifdef FEAT_SIGNS
11024 check_string_option(&wop->wo_scl);
11025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011026#ifdef FEAT_RIGHTLEFT
11027 check_string_option(&wop->wo_rlc);
11028#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011029#ifdef FEAT_STL_OPT
11030 check_string_option(&wop->wo_stl);
11031#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011032#ifdef FEAT_SYN_HL
11033 check_string_option(&wop->wo_cc);
11034#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011035#ifdef FEAT_CONCEAL
11036 check_string_option(&wop->wo_cocu);
11037#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011038#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011039 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011040 check_string_option(&wop->wo_tms);
11041#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011042#ifdef FEAT_LINEBREAK
11043 check_string_option(&wop->wo_briopt);
11044#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011045}
11046
11047/*
11048 * Free the allocated memory inside a winopt_T.
11049 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011050 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011051clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011052{
11053#ifdef FEAT_FOLDING
11054 clear_string_option(&wop->wo_fdi);
11055 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011056 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011057# ifdef FEAT_EVAL
11058 clear_string_option(&wop->wo_fde);
11059 clear_string_option(&wop->wo_fdt);
11060# endif
11061 clear_string_option(&wop->wo_fmr);
11062#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011063#ifdef FEAT_SIGNS
11064 clear_string_option(&wop->wo_scl);
11065#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011066#ifdef FEAT_LINEBREAK
11067 clear_string_option(&wop->wo_briopt);
11068#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011069#ifdef FEAT_RIGHTLEFT
11070 clear_string_option(&wop->wo_rlc);
11071#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011072#ifdef FEAT_STL_OPT
11073 clear_string_option(&wop->wo_stl);
11074#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011075#ifdef FEAT_SYN_HL
11076 clear_string_option(&wop->wo_cc);
11077#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011078#ifdef FEAT_CONCEAL
11079 clear_string_option(&wop->wo_cocu);
11080#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011081#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011082 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011083 clear_string_option(&wop->wo_tms);
11084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011085}
11086
11087/*
11088 * Copy global option values to local options for one buffer.
11089 * Used when creating a new buffer and sometimes when entering a buffer.
11090 * flags:
11091 * BCO_ENTER We will enter the buf buffer.
11092 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11093 * appropriate.
11094 * BCO_NOHELP Don't copy the values to a help buffer.
11095 */
11096 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011097buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098{
11099 int should_copy = TRUE;
11100 char_u *save_p_isk = NULL; /* init for GCC */
11101 int dont_do_help;
11102 int did_isk = FALSE;
11103
11104 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011105 * Skip this when the option defaults have not been set yet. Happens when
11106 * main() allocates the first buffer.
11107 */
11108 if (p_cpo != NULL)
11109 {
11110 /*
11111 * Always copy when entering and 'cpo' contains 'S'.
11112 * Don't copy when already initialized.
11113 * Don't copy when 'cpo' contains 's' and not entering.
11114 * 'S' BCO_ENTER initialized 's' should_copy
11115 * yes yes X X TRUE
11116 * yes no yes X FALSE
11117 * no X yes X FALSE
11118 * X no no yes FALSE
11119 * X no no no TRUE
11120 * no yes no X TRUE
11121 */
11122 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11123 && (buf->b_p_initialized
11124 || (!(flags & BCO_ENTER)
11125 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11126 should_copy = FALSE;
11127
11128 if (should_copy || (flags & BCO_ALWAYS))
11129 {
11130 /* Don't copy the options specific to a help buffer when
11131 * BCO_NOHELP is given or the options were initialized already
11132 * (jumping back to a help file with CTRL-T or CTRL-O) */
11133 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11134 || buf->b_p_initialized;
11135 if (dont_do_help) /* don't free b_p_isk */
11136 {
11137 save_p_isk = buf->b_p_isk;
11138 buf->b_p_isk = NULL;
11139 }
11140 /*
11141 * Always free the allocated strings.
11142 * If not already initialized, set 'readonly' and copy 'fileformat'.
11143 */
11144 if (!buf->b_p_initialized)
11145 {
11146 free_buf_options(buf, TRUE);
11147 buf->b_p_ro = FALSE; /* don't copy readonly */
11148 buf->b_p_tx = p_tx;
11149#ifdef FEAT_MBYTE
11150 buf->b_p_fenc = vim_strsave(p_fenc);
11151#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011152 switch (*p_ffs)
11153 {
11154 case 'm':
11155 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11156 case 'd':
11157 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11158 case 'u':
11159 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11160 default:
11161 buf->b_p_ff = vim_strsave(p_ff);
11162 }
11163 if (buf->b_p_ff != NULL)
11164 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011165 buf->b_p_bh = empty_option;
11166 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011167 }
11168 else
11169 free_buf_options(buf, FALSE);
11170
11171 buf->b_p_ai = p_ai;
11172 buf->b_p_ai_nopaste = p_ai_nopaste;
11173 buf->b_p_sw = p_sw;
11174 buf->b_p_tw = p_tw;
11175 buf->b_p_tw_nopaste = p_tw_nopaste;
11176 buf->b_p_tw_nobin = p_tw_nobin;
11177 buf->b_p_wm = p_wm;
11178 buf->b_p_wm_nopaste = p_wm_nopaste;
11179 buf->b_p_wm_nobin = p_wm_nobin;
11180 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011181#ifdef FEAT_MBYTE
11182 buf->b_p_bomb = p_bomb;
11183#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011184 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185 buf->b_p_et = p_et;
11186 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011187 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188 buf->b_p_ml = p_ml;
11189 buf->b_p_ml_nobin = p_ml_nobin;
11190 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011191 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011192#ifdef FEAT_INS_EXPAND
11193 buf->b_p_cpt = vim_strsave(p_cpt);
11194#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011195#ifdef FEAT_COMPL_FUNC
11196 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011197 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011198#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011199 buf->b_p_sts = p_sts;
11200 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011201 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202#ifdef FEAT_COMMENTS
11203 buf->b_p_com = vim_strsave(p_com);
11204#endif
11205#ifdef FEAT_FOLDING
11206 buf->b_p_cms = vim_strsave(p_cms);
11207#endif
11208 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011209 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011210 buf->b_p_nf = vim_strsave(p_nf);
11211 buf->b_p_mps = vim_strsave(p_mps);
11212#ifdef FEAT_SMARTINDENT
11213 buf->b_p_si = p_si;
11214#endif
11215 buf->b_p_ci = p_ci;
11216#ifdef FEAT_CINDENT
11217 buf->b_p_cin = p_cin;
11218 buf->b_p_cink = vim_strsave(p_cink);
11219 buf->b_p_cino = vim_strsave(p_cino);
11220#endif
11221#ifdef FEAT_AUTOCMD
11222 /* Don't copy 'filetype', it must be detected */
11223 buf->b_p_ft = empty_option;
11224#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225 buf->b_p_pi = p_pi;
11226#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11227 buf->b_p_cinw = vim_strsave(p_cinw);
11228#endif
11229#ifdef FEAT_LISP
11230 buf->b_p_lisp = p_lisp;
11231#endif
11232#ifdef FEAT_SYN_HL
11233 /* Don't copy 'syntax', it must be set */
11234 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011235 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011236 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011237#endif
11238#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011239 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011240 (void)compile_cap_prog(&buf->b_s);
11241 buf->b_s.b_p_spf = vim_strsave(p_spf);
11242 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011243#endif
11244#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11245 buf->b_p_inde = vim_strsave(p_inde);
11246 buf->b_p_indk = vim_strsave(p_indk);
11247#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011248 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011249#if defined(FEAT_EVAL)
11250 buf->b_p_fex = vim_strsave(p_fex);
11251#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011252#ifdef FEAT_CRYPT
11253 buf->b_p_key = vim_strsave(p_key);
11254#endif
11255#ifdef FEAT_SEARCHPATH
11256 buf->b_p_sua = vim_strsave(p_sua);
11257#endif
11258#ifdef FEAT_KEYMAP
11259 buf->b_p_keymap = vim_strsave(p_keymap);
11260 buf->b_kmap_state |= KEYMAP_INIT;
11261#endif
11262 /* This isn't really an option, but copying the langmap and IME
11263 * state from the current buffer is better than resetting it. */
11264 buf->b_p_iminsert = p_iminsert;
11265 buf->b_p_imsearch = p_imsearch;
11266
11267 /* options that are normally global but also have a local value
11268 * are not copied, start using the global value */
11269 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011270 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011271 buf->b_p_bkc = empty_option;
11272 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011273#ifdef FEAT_QUICKFIX
11274 buf->b_p_gp = empty_option;
11275 buf->b_p_mp = empty_option;
11276 buf->b_p_efm = empty_option;
11277#endif
11278 buf->b_p_ep = empty_option;
11279 buf->b_p_kp = empty_option;
11280 buf->b_p_path = empty_option;
11281 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011282 buf->b_p_tc = empty_option;
11283 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011284#ifdef FEAT_FIND_ID
11285 buf->b_p_def = empty_option;
11286 buf->b_p_inc = empty_option;
11287# ifdef FEAT_EVAL
11288 buf->b_p_inex = vim_strsave(p_inex);
11289# endif
11290#endif
11291#ifdef FEAT_INS_EXPAND
11292 buf->b_p_dict = empty_option;
11293 buf->b_p_tsr = empty_option;
11294#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011295#ifdef FEAT_TEXTOBJ
11296 buf->b_p_qe = vim_strsave(p_qe);
11297#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011298#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11299 buf->b_p_bexpr = empty_option;
11300#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011301#if defined(FEAT_CRYPT)
11302 buf->b_p_cm = empty_option;
11303#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011304#ifdef FEAT_PERSISTENT_UNDO
11305 buf->b_p_udf = p_udf;
11306#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011307#ifdef FEAT_LISP
11308 buf->b_p_lw = empty_option;
11309#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011310#ifdef FEAT_MBYTE
11311 buf->b_p_menc = empty_option;
11312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011313
11314 /*
11315 * Don't copy the options set by ex_help(), use the saved values,
11316 * when going from a help buffer to a non-help buffer.
11317 * Don't touch these at all when BCO_NOHELP is used and going from
11318 * or to a help buffer.
11319 */
11320 if (dont_do_help)
11321 buf->b_p_isk = save_p_isk;
11322 else
11323 {
11324 buf->b_p_isk = vim_strsave(p_isk);
11325 did_isk = TRUE;
11326 buf->b_p_ts = p_ts;
11327 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011328 if (buf->b_p_bt[0] == 'h')
11329 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330 buf->b_p_ma = p_ma;
11331 }
11332 }
11333
11334 /*
11335 * When the options should be copied (ignoring BCO_ALWAYS), set the
11336 * flag that indicates that the options have been initialized.
11337 */
11338 if (should_copy)
11339 buf->b_p_initialized = TRUE;
11340 }
11341
11342 check_buf_options(buf); /* make sure we don't have NULLs */
11343 if (did_isk)
11344 (void)buf_init_chartab(buf, FALSE);
11345}
11346
11347/*
11348 * Reset the 'modifiable' option and its default value.
11349 */
11350 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011351reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011352{
11353 int opt_idx;
11354
11355 curbuf->b_p_ma = FALSE;
11356 p_ma = FALSE;
11357 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011358 if (opt_idx >= 0)
11359 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011360}
11361
11362/*
11363 * Set the global value for 'iminsert' to the local value.
11364 */
11365 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011366set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011367{
11368 p_iminsert = curbuf->b_p_iminsert;
11369}
11370
11371/*
11372 * Set the global value for 'imsearch' to the local value.
11373 */
11374 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011375set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376{
11377 p_imsearch = curbuf->b_p_imsearch;
11378}
11379
11380#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11381static int expand_option_idx = -1;
11382static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11383static int expand_option_flags = 0;
11384
11385 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011386set_context_in_set_cmd(
11387 expand_T *xp,
11388 char_u *arg,
11389 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011390{
11391 int nextchar;
11392 long_u flags = 0; /* init for GCC */
11393 int opt_idx = 0; /* init for GCC */
11394 char_u *p;
11395 char_u *s;
11396 int is_term_option = FALSE;
11397 int key;
11398
11399 expand_option_flags = opt_flags;
11400
11401 xp->xp_context = EXPAND_SETTINGS;
11402 if (*arg == NUL)
11403 {
11404 xp->xp_pattern = arg;
11405 return;
11406 }
11407 p = arg + STRLEN(arg) - 1;
11408 if (*p == ' ' && *(p - 1) != '\\')
11409 {
11410 xp->xp_pattern = p + 1;
11411 return;
11412 }
11413 while (p > arg)
11414 {
11415 s = p;
11416 /* count number of backslashes before ' ' or ',' */
11417 if (*p == ' ' || *p == ',')
11418 {
11419 while (s > arg && *(s - 1) == '\\')
11420 --s;
11421 }
11422 /* break at a space with an even number of backslashes */
11423 if (*p == ' ' && ((p - s) & 1) == 0)
11424 {
11425 ++p;
11426 break;
11427 }
11428 --p;
11429 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011430 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431 {
11432 xp->xp_context = EXPAND_BOOL_SETTINGS;
11433 p += 2;
11434 }
11435 if (STRNCMP(p, "inv", 3) == 0)
11436 {
11437 xp->xp_context = EXPAND_BOOL_SETTINGS;
11438 p += 3;
11439 }
11440 xp->xp_pattern = arg = p;
11441 if (*arg == '<')
11442 {
11443 while (*p != '>')
11444 if (*p++ == NUL) /* expand terminal option name */
11445 return;
11446 key = get_special_key_code(arg + 1);
11447 if (key == 0) /* unknown name */
11448 {
11449 xp->xp_context = EXPAND_NOTHING;
11450 return;
11451 }
11452 nextchar = *++p;
11453 is_term_option = TRUE;
11454 expand_option_name[2] = KEY2TERMCAP0(key);
11455 expand_option_name[3] = KEY2TERMCAP1(key);
11456 }
11457 else
11458 {
11459 if (p[0] == 't' && p[1] == '_')
11460 {
11461 p += 2;
11462 if (*p != NUL)
11463 ++p;
11464 if (*p == NUL)
11465 return; /* expand option name */
11466 nextchar = *++p;
11467 is_term_option = TRUE;
11468 expand_option_name[2] = p[-2];
11469 expand_option_name[3] = p[-1];
11470 }
11471 else
11472 {
11473 /* Allow * wildcard */
11474 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11475 p++;
11476 if (*p == NUL)
11477 return;
11478 nextchar = *p;
11479 *p = NUL;
11480 opt_idx = findoption(arg);
11481 *p = nextchar;
11482 if (opt_idx == -1 || options[opt_idx].var == NULL)
11483 {
11484 xp->xp_context = EXPAND_NOTHING;
11485 return;
11486 }
11487 flags = options[opt_idx].flags;
11488 if (flags & P_BOOL)
11489 {
11490 xp->xp_context = EXPAND_NOTHING;
11491 return;
11492 }
11493 }
11494 }
11495 /* handle "-=" and "+=" */
11496 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11497 {
11498 ++p;
11499 nextchar = '=';
11500 }
11501 if ((nextchar != '=' && nextchar != ':')
11502 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11503 {
11504 xp->xp_context = EXPAND_UNSUCCESSFUL;
11505 return;
11506 }
11507 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11508 {
11509 xp->xp_context = EXPAND_OLD_SETTING;
11510 if (is_term_option)
11511 expand_option_idx = -1;
11512 else
11513 expand_option_idx = opt_idx;
11514 xp->xp_pattern = p + 1;
11515 return;
11516 }
11517 xp->xp_context = EXPAND_NOTHING;
11518 if (is_term_option || (flags & P_NUM))
11519 return;
11520
11521 xp->xp_pattern = p + 1;
11522
11523 if (flags & P_EXPAND)
11524 {
11525 p = options[opt_idx].var;
11526 if (p == (char_u *)&p_bdir
11527 || p == (char_u *)&p_dir
11528 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011529 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011530 || p == (char_u *)&p_rtp
11531#ifdef FEAT_SEARCHPATH
11532 || p == (char_u *)&p_cdpath
11533#endif
11534#ifdef FEAT_SESSION
11535 || p == (char_u *)&p_vdir
11536#endif
11537 )
11538 {
11539 xp->xp_context = EXPAND_DIRECTORIES;
11540 if (p == (char_u *)&p_path
11541#ifdef FEAT_SEARCHPATH
11542 || p == (char_u *)&p_cdpath
11543#endif
11544 )
11545 xp->xp_backslash = XP_BS_THREE;
11546 else
11547 xp->xp_backslash = XP_BS_ONE;
11548 }
11549 else
11550 {
11551 xp->xp_context = EXPAND_FILES;
11552 /* for 'tags' need three backslashes for a space */
11553 if (p == (char_u *)&p_tags)
11554 xp->xp_backslash = XP_BS_THREE;
11555 else
11556 xp->xp_backslash = XP_BS_ONE;
11557 }
11558 }
11559
11560 /* For an option that is a list of file names, find the start of the
11561 * last file name. */
11562 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11563 {
11564 /* count number of backslashes before ' ' or ',' */
11565 if (*p == ' ' || *p == ',')
11566 {
11567 s = p;
11568 while (s > xp->xp_pattern && *(s - 1) == '\\')
11569 --s;
11570 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11571 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11572 {
11573 xp->xp_pattern = p + 1;
11574 break;
11575 }
11576 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011577
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011578#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011579 /* for 'spellsuggest' start at "file:" */
11580 if (options[opt_idx].var == (char_u *)&p_sps
11581 && STRNCMP(p, "file:", 5) == 0)
11582 {
11583 xp->xp_pattern = p + 5;
11584 break;
11585 }
11586#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011587 }
11588
11589 return;
11590}
11591
11592 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011593ExpandSettings(
11594 expand_T *xp,
11595 regmatch_T *regmatch,
11596 int *num_file,
11597 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011598{
11599 int num_normal = 0; /* Nr of matching non-term-code settings */
11600 int num_term = 0; /* Nr of matching terminal code settings */
11601 int opt_idx;
11602 int match;
11603 int count = 0;
11604 char_u *str;
11605 int loop;
11606 int is_term_opt;
11607 char_u name_buf[MAX_KEY_NAME_LEN];
11608 static char *(names[]) = {"all", "termcap"};
11609 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11610
11611 /* do this loop twice:
11612 * loop == 0: count the number of matching options
11613 * loop == 1: copy the matching options into allocated memory
11614 */
11615 for (loop = 0; loop <= 1; ++loop)
11616 {
11617 regmatch->rm_ic = ic;
11618 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11619 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011620 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11621 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011622 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11623 {
11624 if (loop == 0)
11625 num_normal++;
11626 else
11627 (*file)[count++] = vim_strsave((char_u *)names[match]);
11628 }
11629 }
11630 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11631 opt_idx++)
11632 {
11633 if (options[opt_idx].var == NULL)
11634 continue;
11635 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11636 && !(options[opt_idx].flags & P_BOOL))
11637 continue;
11638 is_term_opt = istermoption(&options[opt_idx]);
11639 if (is_term_opt && num_normal > 0)
11640 continue;
11641 match = FALSE;
11642 if (vim_regexec(regmatch, str, (colnr_T)0)
11643 || (options[opt_idx].shortname != NULL
11644 && vim_regexec(regmatch,
11645 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11646 match = TRUE;
11647 else if (is_term_opt)
11648 {
11649 name_buf[0] = '<';
11650 name_buf[1] = 't';
11651 name_buf[2] = '_';
11652 name_buf[3] = str[2];
11653 name_buf[4] = str[3];
11654 name_buf[5] = '>';
11655 name_buf[6] = NUL;
11656 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11657 {
11658 match = TRUE;
11659 str = name_buf;
11660 }
11661 }
11662 if (match)
11663 {
11664 if (loop == 0)
11665 {
11666 if (is_term_opt)
11667 num_term++;
11668 else
11669 num_normal++;
11670 }
11671 else
11672 (*file)[count++] = vim_strsave(str);
11673 }
11674 }
11675 /*
11676 * Check terminal key codes, these are not in the option table
11677 */
11678 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11679 {
11680 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11681 {
11682 if (!isprint(str[0]) || !isprint(str[1]))
11683 continue;
11684
11685 name_buf[0] = 't';
11686 name_buf[1] = '_';
11687 name_buf[2] = str[0];
11688 name_buf[3] = str[1];
11689 name_buf[4] = NUL;
11690
11691 match = FALSE;
11692 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11693 match = TRUE;
11694 else
11695 {
11696 name_buf[0] = '<';
11697 name_buf[1] = 't';
11698 name_buf[2] = '_';
11699 name_buf[3] = str[0];
11700 name_buf[4] = str[1];
11701 name_buf[5] = '>';
11702 name_buf[6] = NUL;
11703
11704 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11705 match = TRUE;
11706 }
11707 if (match)
11708 {
11709 if (loop == 0)
11710 num_term++;
11711 else
11712 (*file)[count++] = vim_strsave(name_buf);
11713 }
11714 }
11715
11716 /*
11717 * Check special key names.
11718 */
11719 regmatch->rm_ic = TRUE; /* ignore case here */
11720 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11721 {
11722 name_buf[0] = '<';
11723 STRCPY(name_buf + 1, str);
11724 STRCAT(name_buf, ">");
11725
11726 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11727 {
11728 if (loop == 0)
11729 num_term++;
11730 else
11731 (*file)[count++] = vim_strsave(name_buf);
11732 }
11733 }
11734 }
11735 if (loop == 0)
11736 {
11737 if (num_normal > 0)
11738 *num_file = num_normal;
11739 else if (num_term > 0)
11740 *num_file = num_term;
11741 else
11742 return OK;
11743 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11744 if (*file == NULL)
11745 {
11746 *file = (char_u **)"";
11747 return FAIL;
11748 }
11749 }
11750 }
11751 return OK;
11752}
11753
11754 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011755ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011756{
11757 char_u *var = NULL; /* init for GCC */
11758 char_u *buf;
11759
11760 *num_file = 0;
11761 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11762 if (*file == NULL)
11763 return FAIL;
11764
11765 /*
11766 * For a terminal key code expand_option_idx is < 0.
11767 */
11768 if (expand_option_idx < 0)
11769 {
11770 var = find_termcode(expand_option_name + 2);
11771 if (var == NULL)
11772 expand_option_idx = findoption(expand_option_name);
11773 }
11774
11775 if (expand_option_idx >= 0)
11776 {
11777 /* put string of option value in NameBuff */
11778 option_value2string(&options[expand_option_idx], expand_option_flags);
11779 var = NameBuff;
11780 }
11781 else if (var == NULL)
11782 var = (char_u *)"";
11783
11784 /* A backslash is required before some characters. This is the reverse of
11785 * what happens in do_set(). */
11786 buf = vim_strsave_escaped(var, escape_chars);
11787
11788 if (buf == NULL)
11789 {
11790 vim_free(*file);
11791 *file = NULL;
11792 return FAIL;
11793 }
11794
11795#ifdef BACKSLASH_IN_FILENAME
11796 /* For MS-Windows et al. we don't double backslashes at the start and
11797 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011798 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011799 if (var[0] == '\\' && var[1] == '\\'
11800 && expand_option_idx >= 0
11801 && (options[expand_option_idx].flags & P_EXPAND)
11802 && vim_isfilec(var[2])
11803 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011804 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011805#endif
11806
11807 *file[0] = buf;
11808 *num_file = 1;
11809 return OK;
11810}
11811#endif
11812
11813/*
11814 * Get the value for the numeric or string option *opp in a nice format into
11815 * NameBuff[]. Must not be called with a hidden option!
11816 */
11817 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011818option_value2string(
11819 struct vimoption *opp,
11820 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011821{
11822 char_u *varp;
11823
11824 varp = get_varp_scope(opp, opt_flags);
11825
11826 if (opp->flags & P_NUM)
11827 {
11828 long wc = 0;
11829
11830 if (wc_use_keyname(varp, &wc))
11831 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11832 else if (wc != 0)
11833 STRCPY(NameBuff, transchar((int)wc));
11834 else
11835 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11836 }
11837 else /* P_STRING */
11838 {
11839 varp = *(char_u **)(varp);
11840 if (varp == NULL) /* just in case */
11841 NameBuff[0] = NUL;
11842#ifdef FEAT_CRYPT
11843 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011844 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845 STRCPY(NameBuff, "*****");
11846#endif
11847 else if (opp->flags & P_EXPAND)
11848 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11849 /* Translate 'pastetoggle' into special key names */
11850 else if ((char_u **)opp->var == &p_pt)
11851 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11852 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011853 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011854 }
11855}
11856
11857/*
11858 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11859 * printed as a keyname.
11860 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11861 */
11862 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011863wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011864{
11865 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11866 {
11867 *wcp = *(long *)varp;
11868 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11869 return TRUE;
11870 }
11871 return FALSE;
11872}
11873
Bram Moolenaar01615492015-02-03 13:00:38 +010011874#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011875/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011876 * Any character has an equivalent 'langmap' character. This is used for
11877 * keyboards that have a special language mode that sends characters above
11878 * 128 (although other characters can be translated too). The "to" field is a
11879 * Vim command character. This avoids having to switch the keyboard back to
11880 * ASCII mode when leaving Insert mode.
11881 *
11882 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11883 * commands.
11884 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11885 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11886 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011887 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011888# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011889/*
11890 * With multi-byte support use growarray for 'langmap' chars >= 256
11891 */
11892typedef struct
11893{
11894 int from;
11895 int to;
11896} langmap_entry_T;
11897
11898static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011899static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900
11901/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011902 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11903 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011904 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011905 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011906langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011907{
11908 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011909 int a = 0;
11910 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011911
11912 /* Do a binary search for an existing entry. */
11913 while (a != b)
11914 {
11915 int i = (a + b) / 2;
11916 int d = entries[i].from - from;
11917
11918 if (d == 0)
11919 {
11920 entries[i].to = to;
11921 return;
11922 }
11923 if (d < 0)
11924 a = i + 1;
11925 else
11926 b = i;
11927 }
11928
11929 if (ga_grow(&langmap_mapga, 1) != OK)
11930 return; /* out of memory */
11931
11932 /* insert new entry at position "a" */
11933 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11934 mch_memmove(entries + 1, entries,
11935 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11936 ++langmap_mapga.ga_len;
11937 entries[0].from = from;
11938 entries[0].to = to;
11939}
11940
11941/*
11942 * Apply 'langmap' to multi-byte character "c" and return the result.
11943 */
11944 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011945langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011946{
11947 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11948 int a = 0;
11949 int b = langmap_mapga.ga_len;
11950
11951 while (a != b)
11952 {
11953 int i = (a + b) / 2;
11954 int d = entries[i].from - c;
11955
11956 if (d == 0)
11957 return entries[i].to; /* found matching entry */
11958 if (d < 0)
11959 a = i + 1;
11960 else
11961 b = i;
11962 }
11963 return c; /* no entry found, return "c" unmodified */
11964}
11965# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011966
11967 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011968langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011969{
11970 int i;
11971
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011972 for (i = 0; i < 256; i++)
11973 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11974# ifdef FEAT_MBYTE
11975 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11976# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977}
11978
11979/*
11980 * Called when langmap option is set; the language map can be
11981 * changed at any time!
11982 */
11983 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011984langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985{
11986 char_u *p;
11987 char_u *p2;
11988 int from, to;
11989
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011990#ifdef FEAT_MBYTE
11991 ga_clear(&langmap_mapga); /* clear the previous map first */
11992#endif
11993 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011994
11995 for (p = p_langmap; p[0] != NUL; )
11996 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011997 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011998 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011999 {
12000 if (p2[0] == '\\' && p2[1] != NUL)
12001 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002 }
12003 if (p2[0] == ';')
12004 ++p2; /* abcd;ABCD form, p2 points to A */
12005 else
12006 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12007 while (p[0])
12008 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012009 if (p[0] == ',')
12010 {
12011 ++p;
12012 break;
12013 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012014 if (p[0] == '\\' && p[1] != NUL)
12015 ++p;
12016#ifdef FEAT_MBYTE
12017 from = (*mb_ptr2char)(p);
12018#else
12019 from = p[0];
12020#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012021 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012022 if (p2 == NULL)
12023 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012024 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012025 if (p[0] != ',')
12026 {
12027 if (p[0] == '\\')
12028 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012030 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012031#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012032 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012033#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012034 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012035 }
12036 else
12037 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012038 if (p2[0] != ',')
12039 {
12040 if (p2[0] == '\\')
12041 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012042#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012043 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012044#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012045 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012046#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012047 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012048 }
12049 if (to == NUL)
12050 {
12051 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12052 transchar(from));
12053 return;
12054 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012055
12056#ifdef FEAT_MBYTE
12057 if (from >= 256)
12058 langmap_set_entry(from, to);
12059 else
12060#endif
12061 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012062
12063 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012064 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012065 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012066 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012067 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012068 if (*p == ';')
12069 {
12070 p = p2;
12071 if (p[0] != NUL)
12072 {
12073 if (p[0] != ',')
12074 {
12075 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12076 return;
12077 }
12078 ++p;
12079 }
12080 break;
12081 }
12082 }
12083 }
12084 }
12085}
12086#endif
12087
12088/*
12089 * Return TRUE if format option 'x' is in effect.
12090 * Take care of no formatting when 'paste' is set.
12091 */
12092 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012093has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012094{
12095 if (p_paste)
12096 return FALSE;
12097 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12098}
12099
12100/*
12101 * Return TRUE if "x" is present in 'shortmess' option, or
12102 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12103 */
12104 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012105shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012106{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012107 return p_shm != NULL &&
12108 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012109 || (vim_strchr(p_shm, 'a') != NULL
12110 && vim_strchr((char_u *)SHM_A, x) != NULL));
12111}
12112
12113/*
12114 * paste_option_changed() - Called after p_paste was set or reset.
12115 */
12116 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012117paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012118{
12119 static int old_p_paste = FALSE;
12120 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012121 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012122#ifdef FEAT_CMDL_INFO
12123 static int save_ru = 0;
12124#endif
12125#ifdef FEAT_RIGHTLEFT
12126 static int save_ri = 0;
12127 static int save_hkmap = 0;
12128#endif
12129 buf_T *buf;
12130
12131 if (p_paste)
12132 {
12133 /*
12134 * Paste switched from off to on.
12135 * Save the current values, so they can be restored later.
12136 */
12137 if (!old_p_paste)
12138 {
12139 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012140 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012141 {
12142 buf->b_p_tw_nopaste = buf->b_p_tw;
12143 buf->b_p_wm_nopaste = buf->b_p_wm;
12144 buf->b_p_sts_nopaste = buf->b_p_sts;
12145 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012146 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012147 }
12148
12149 /* save global options */
12150 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012151 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012152#ifdef FEAT_CMDL_INFO
12153 save_ru = p_ru;
12154#endif
12155#ifdef FEAT_RIGHTLEFT
12156 save_ri = p_ri;
12157 save_hkmap = p_hkmap;
12158#endif
12159 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012160 p_ai_nopaste = p_ai;
12161 p_et_nopaste = p_et;
12162 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012163 p_tw_nopaste = p_tw;
12164 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 }
12166
12167 /*
12168 * Always set the option values, also when 'paste' is set when it is
12169 * already on.
12170 */
12171 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012172 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012173 {
12174 buf->b_p_tw = 0; /* textwidth is 0 */
12175 buf->b_p_wm = 0; /* wrapmargin is 0 */
12176 buf->b_p_sts = 0; /* softtabstop is 0 */
12177 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012178 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012179 }
12180
12181 /* set global options */
12182 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012183 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012184#ifdef FEAT_CMDL_INFO
12185# ifdef FEAT_WINDOWS
12186 if (p_ru)
12187 status_redraw_all(); /* redraw to remove the ruler */
12188# endif
12189 p_ru = 0; /* no ruler */
12190#endif
12191#ifdef FEAT_RIGHTLEFT
12192 p_ri = 0; /* no reverse insert */
12193 p_hkmap = 0; /* no Hebrew keyboard */
12194#endif
12195 /* set global values for local buffer options */
12196 p_tw = 0;
12197 p_wm = 0;
12198 p_sts = 0;
12199 p_ai = 0;
12200 }
12201
12202 /*
12203 * Paste switched from on to off: Restore saved values.
12204 */
12205 else if (old_p_paste)
12206 {
12207 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012208 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209 {
12210 buf->b_p_tw = buf->b_p_tw_nopaste;
12211 buf->b_p_wm = buf->b_p_wm_nopaste;
12212 buf->b_p_sts = buf->b_p_sts_nopaste;
12213 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012214 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012215 }
12216
12217 /* restore global options */
12218 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012219 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012220#ifdef FEAT_CMDL_INFO
12221# ifdef FEAT_WINDOWS
12222 if (p_ru != save_ru)
12223 status_redraw_all(); /* redraw to draw the ruler */
12224# endif
12225 p_ru = save_ru;
12226#endif
12227#ifdef FEAT_RIGHTLEFT
12228 p_ri = save_ri;
12229 p_hkmap = save_hkmap;
12230#endif
12231 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012232 p_ai = p_ai_nopaste;
12233 p_et = p_et_nopaste;
12234 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012235 p_tw = p_tw_nopaste;
12236 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012237 }
12238
12239 old_p_paste = p_paste;
12240}
12241
12242/*
12243 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12244 *
12245 * Reset 'compatible' and set the values for options that didn't get set yet
12246 * to the Vim defaults.
12247 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012248 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249 */
12250 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012251vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012252{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012253 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012254 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012255 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012256
12257 if (!option_was_set((char_u *)"cp"))
12258 {
12259 p_cp = FALSE;
12260 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12261 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12262 set_option_default(opt_idx, OPT_FREE, FALSE);
12263 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012264 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012265 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012266
12267 if (fname != NULL)
12268 {
12269 p = vim_getenv(envname, &dofree);
12270 if (p == NULL)
12271 {
12272 /* Set $MYVIMRC to the first vimrc file found. */
12273 p = FullName_save(fname, FALSE);
12274 if (p != NULL)
12275 {
12276 vim_setenv(envname, p);
12277 vim_free(p);
12278 }
12279 }
12280 else if (dofree)
12281 vim_free(p);
12282 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012283}
12284
12285/*
12286 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12287 */
12288 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012289change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012290{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012291 int opt_idx;
12292
Bram Moolenaar071d4272004-06-13 20:20:40 +000012293 if (p_cp != on)
12294 {
12295 p_cp = on;
12296 compatible_set();
12297 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012298 opt_idx = findoption((char_u *)"cp");
12299 if (opt_idx >= 0)
12300 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012301}
12302
12303/*
12304 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012305 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306 */
12307 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012308option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012309{
12310 int idx;
12311
12312 idx = findoption(name);
12313 if (idx < 0) /* unknown option */
12314 return FALSE;
12315 if (options[idx].flags & P_WAS_SET)
12316 return TRUE;
12317 return FALSE;
12318}
12319
12320/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012321 * Reset the flag indicating option "name" was set.
12322 */
12323 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012324reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012325{
12326 int idx = findoption(name);
12327
12328 if (idx >= 0)
12329 options[idx].flags &= ~P_WAS_SET;
12330}
12331
12332/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012333 * compatible_set() - Called when 'compatible' has been set or unset.
12334 *
12335 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12336 * flag) to a Vi compatible value.
12337 * When 'compatible' is unset: Set all options that have a different default
12338 * for Vim (without the P_VI_DEF flag) to that default.
12339 */
12340 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012341compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012342{
12343 int opt_idx;
12344
12345 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12346 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12347 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12348 set_option_default(opt_idx, OPT_FREE, p_cp);
12349 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012350 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012351}
12352
12353#ifdef FEAT_LINEBREAK
12354
12355# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12356 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012357 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012358# endif
12359
12360/*
12361 * fill_breakat_flags() -- called when 'breakat' changes value.
12362 */
12363 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012364fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012365{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012366 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012367 int i;
12368
12369 for (i = 0; i < 256; i++)
12370 breakat_flags[i] = FALSE;
12371
12372 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012373 for (p = p_breakat; *p; p++)
12374 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012375}
12376
12377# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012378 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012379# endif
12380
12381#endif
12382
12383/*
12384 * Check an option that can be a range of string values.
12385 *
12386 * Return OK for correct value, FAIL otherwise.
12387 * Empty is always OK.
12388 */
12389 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012390check_opt_strings(
12391 char_u *val,
12392 char **values,
12393 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012394{
12395 return opt_strings_flags(val, values, NULL, list);
12396}
12397
12398/*
12399 * Handle an option that can be a range of string values.
12400 * Set a flag in "*flagp" for each string present.
12401 *
12402 * Return OK for correct value, FAIL otherwise.
12403 * Empty is always OK.
12404 */
12405 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012406opt_strings_flags(
12407 char_u *val, /* new value */
12408 char **values, /* array of valid string values */
12409 unsigned *flagp,
12410 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012411{
12412 int i;
12413 int len;
12414 unsigned new_flags = 0;
12415
12416 while (*val)
12417 {
12418 for (i = 0; ; ++i)
12419 {
12420 if (values[i] == NULL) /* val not found in values[] */
12421 return FAIL;
12422
12423 len = (int)STRLEN(values[i]);
12424 if (STRNCMP(values[i], val, len) == 0
12425 && ((list && val[len] == ',') || val[len] == NUL))
12426 {
12427 val += len + (val[len] == ',');
12428 new_flags |= (1 << i);
12429 break; /* check next item in val list */
12430 }
12431 }
12432 }
12433 if (flagp != NULL)
12434 *flagp = new_flags;
12435
12436 return OK;
12437}
12438
12439/*
12440 * Read the 'wildmode' option, fill wim_flags[].
12441 */
12442 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012443check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012444{
12445 char_u new_wim_flags[4];
12446 char_u *p;
12447 int i;
12448 int idx = 0;
12449
12450 for (i = 0; i < 4; ++i)
12451 new_wim_flags[i] = 0;
12452
12453 for (p = p_wim; *p; ++p)
12454 {
12455 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12456 ;
12457 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12458 return FAIL;
12459 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12460 new_wim_flags[idx] |= WIM_LONGEST;
12461 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12462 new_wim_flags[idx] |= WIM_FULL;
12463 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12464 new_wim_flags[idx] |= WIM_LIST;
12465 else
12466 return FAIL;
12467 p += i;
12468 if (*p == NUL)
12469 break;
12470 if (*p == ',')
12471 {
12472 if (idx == 3)
12473 return FAIL;
12474 ++idx;
12475 }
12476 }
12477
12478 /* fill remaining entries with last flag */
12479 while (idx < 3)
12480 {
12481 new_wim_flags[idx + 1] = new_wim_flags[idx];
12482 ++idx;
12483 }
12484
12485 /* only when there are no errors, wim_flags[] is changed */
12486 for (i = 0; i < 4; ++i)
12487 wim_flags[i] = new_wim_flags[i];
12488 return OK;
12489}
12490
12491/*
12492 * Check if backspacing over something is allowed.
12493 */
12494 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012495can_bs(
12496 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012497{
12498 switch (*p_bs)
12499 {
12500 case '2': return TRUE;
12501 case '1': return (what != BS_START);
12502 case '0': return FALSE;
12503 }
12504 return vim_strchr(p_bs, what) != NULL;
12505}
12506
12507/*
12508 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12509 * the file must be considered changed when the value is different.
12510 */
12511 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012512save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012513{
12514 buf->b_start_ffc = *buf->b_p_ff;
12515 buf->b_start_eol = buf->b_p_eol;
12516#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012517 buf->b_start_bomb = buf->b_p_bomb;
12518
Bram Moolenaar071d4272004-06-13 20:20:40 +000012519 /* Only use free/alloc when necessary, they take time. */
12520 if (buf->b_start_fenc == NULL
12521 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12522 {
12523 vim_free(buf->b_start_fenc);
12524 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12525 }
12526#endif
12527}
12528
12529/*
12530 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12531 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012532 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12533 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012534 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012535 * When "ignore_empty" is true don't consider a new, empty buffer to be
12536 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012537 */
12538 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012539file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012540{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012541 /* In a buffer that was never loaded the options are not valid. */
12542 if (buf->b_flags & BF_NEVERLOADED)
12543 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012544 if (ignore_empty
12545 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012546 && buf->b_ml.ml_line_count == 1
12547 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12548 return FALSE;
12549 if (buf->b_start_ffc != *buf->b_p_ff)
12550 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012551 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012552 return TRUE;
12553#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012554 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12555 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012556 if (buf->b_start_fenc == NULL)
12557 return (*buf->b_p_fenc != NUL);
12558 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12559#else
12560 return FALSE;
12561#endif
12562}
12563
12564/*
12565 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12566 */
12567 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012568check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012569{
12570 return check_opt_strings(p, p_ff_values, FALSE);
12571}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012572
12573/*
12574 * Return the effective shiftwidth value for current buffer, using the
12575 * 'tabstop' value when 'shiftwidth' is zero.
12576 */
12577 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012578get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012579{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012580 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012581}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012582
12583/*
12584 * Return the effective softtabstop value for the current buffer, using the
12585 * 'tabstop' value when 'softtabstop' is negative.
12586 */
12587 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012588get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012589{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012590 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012591}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012592
12593/*
12594 * Check matchpairs option for "*initc".
12595 * If there is a match set "*initc" to the matching character and "*findc" to
12596 * the opposite character. Set "*backwards" to the direction.
12597 * When "switchit" is TRUE swap the direction.
12598 */
12599 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012600find_mps_values(
12601 int *initc,
12602 int *findc,
12603 int *backwards,
12604 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012605{
12606 char_u *ptr;
12607
12608 ptr = curbuf->b_p_mps;
12609 while (*ptr != NUL)
12610 {
12611#ifdef FEAT_MBYTE
12612 if (has_mbyte)
12613 {
12614 char_u *prev;
12615
12616 if (mb_ptr2char(ptr) == *initc)
12617 {
12618 if (switchit)
12619 {
12620 *findc = *initc;
12621 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12622 *backwards = TRUE;
12623 }
12624 else
12625 {
12626 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12627 *backwards = FALSE;
12628 }
12629 return;
12630 }
12631 prev = ptr;
12632 ptr += mb_ptr2len(ptr) + 1;
12633 if (mb_ptr2char(ptr) == *initc)
12634 {
12635 if (switchit)
12636 {
12637 *findc = *initc;
12638 *initc = mb_ptr2char(prev);
12639 *backwards = FALSE;
12640 }
12641 else
12642 {
12643 *findc = mb_ptr2char(prev);
12644 *backwards = TRUE;
12645 }
12646 return;
12647 }
12648 ptr += mb_ptr2len(ptr);
12649 }
12650 else
12651#endif
12652 {
12653 if (*ptr == *initc)
12654 {
12655 if (switchit)
12656 {
12657 *backwards = TRUE;
12658 *findc = *initc;
12659 *initc = ptr[2];
12660 }
12661 else
12662 {
12663 *backwards = FALSE;
12664 *findc = ptr[2];
12665 }
12666 return;
12667 }
12668 ptr += 2;
12669 if (*ptr == *initc)
12670 {
12671 if (switchit)
12672 {
12673 *backwards = FALSE;
12674 *findc = *initc;
12675 *initc = ptr[-2];
12676 }
12677 else
12678 {
12679 *backwards = TRUE;
12680 *findc = ptr[-2];
12681 }
12682 return;
12683 }
12684 ++ptr;
12685 }
12686 if (*ptr == ',')
12687 ++ptr;
12688 }
12689}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012690
12691#if defined(FEAT_LINEBREAK) || defined(PROTO)
12692/*
12693 * This is called when 'breakindentopt' is changed and when a window is
12694 * initialized.
12695 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012696 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012697briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012698{
12699 char_u *p;
12700 int bri_shift = 0;
12701 long bri_min = 20;
12702 int bri_sbr = FALSE;
12703
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012704 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012705 while (*p != NUL)
12706 {
12707 if (STRNCMP(p, "shift:", 6) == 0
12708 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12709 {
12710 p += 6;
12711 bri_shift = getdigits(&p);
12712 }
12713 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12714 {
12715 p += 4;
12716 bri_min = getdigits(&p);
12717 }
12718 else if (STRNCMP(p, "sbr", 3) == 0)
12719 {
12720 p += 3;
12721 bri_sbr = TRUE;
12722 }
12723 if (*p != ',' && *p != NUL)
12724 return FAIL;
12725 if (*p == ',')
12726 ++p;
12727 }
12728
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012729 wp->w_p_brishift = bri_shift;
12730 wp->w_p_brimin = bri_min;
12731 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012732
12733 return OK;
12734}
12735#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012736
12737/*
12738 * Get the local or global value of 'backupcopy'.
12739 */
12740 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012741get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012742{
12743 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12744}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012745
12746#if defined(FEAT_SIGNS) || defined(PROTO)
12747/*
12748 * Return TRUE when window "wp" has a column to draw signs in.
12749 */
12750 int
12751signcolumn_on(win_T *wp)
12752{
12753 if (*wp->w_p_scl == 'n')
12754 return FALSE;
12755 if (*wp->w_p_scl == 'y')
12756 return TRUE;
12757 return (wp->w_buffer->b_signlist != NULL
12758# ifdef FEAT_NETBEANS_INTG
12759 || wp->w_buffer->b_has_sign_column
12760# endif
12761 );
12762}
12763#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012764
12765#if defined(FEAT_EVAL) || defined(PROTO)
12766/*
12767 * Get window or buffer local options.
12768 */
12769 dict_T *
12770get_winbuf_options(int bufopt)
12771{
12772 dict_T *d;
12773 int opt_idx;
12774
12775 d = dict_alloc();
12776 if (d == NULL)
12777 return NULL;
12778
12779 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12780 {
12781 struct vimoption *opt = &options[opt_idx];
12782
12783 if ((bufopt && (opt->indir & PV_BUF))
12784 || (!bufopt && (opt->indir & PV_WIN)))
12785 {
12786 char_u *varp = get_varp(opt);
12787
12788 if (varp != NULL)
12789 {
12790 if (opt->flags & P_STRING)
12791 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012792 else if (opt->flags & P_NUM)
12793 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012794 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012795 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012796 }
12797 }
12798 }
12799
12800 return d;
12801}
12802#endif